1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 /* Forward declarations. */
28 static bfd_reloc_status_type elf32_frv_relocate_lo16
29 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
30 static bfd_reloc_status_type elf32_frv_relocate_hi16
31 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
32 static bfd_reloc_status_type elf32_frv_relocate_label24
33 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
34 static bfd_reloc_status_type elf32_frv_relocate_gprel12
35 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
36 bfd_byte *, bfd_vma));
37 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
38 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
39 bfd_byte *, bfd_vma));
40 static bfd_reloc_status_type elf32_frv_relocate_gprello
41 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
42 bfd_byte *, bfd_vma));
43 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
44 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
45 bfd_byte *, bfd_vma));
46 static reloc_howto_type *frv_reloc_type_lookup
47 PARAMS ((bfd *, bfd_reloc_code_real_type));
48 static void frv_info_to_howto_rela
49 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
50 static bfd_boolean elf32_frv_relocate_section
51 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
52 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
53 static bfd_boolean elf32_frv_add_symbol_hook
54 PARAMS (( bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
55 const char **, flagword *, asection **, bfd_vma *));
56 static bfd_reloc_status_type frv_final_link_relocate
57 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
58 Elf_Internal_Rela *, bfd_vma));
59 static bfd_boolean elf32_frv_gc_sweep_hook
60 PARAMS ((bfd *, struct bfd_link_info *, asection *, const
61 Elf_Internal_Rela *));
62 static asection * elf32_frv_gc_mark_hook
63 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
64 struct elf_link_hash_entry *, Elf_Internal_Sym *));
65 static bfd_boolean elf32_frv_check_relocs
66 PARAMS ((bfd *, struct bfd_link_info *, asection *,
67 const Elf_Internal_Rela *));
68 static int elf32_frv_machine
70 static bfd_boolean elf32_frv_object_p
72 static bfd_boolean frv_elf_set_private_flags
73 PARAMS ((bfd *, flagword));
74 static bfd_boolean frv_elf_copy_private_bfd_data
75 PARAMS ((bfd *, bfd *));
76 static bfd_boolean frv_elf_merge_private_bfd_data
77 PARAMS ((bfd *, bfd *));
78 static bfd_boolean frv_elf_print_private_bfd_data
79 PARAMS ((bfd *, PTR));
81 static reloc_howto_type elf32_frv_howto_table [] =
83 /* This reloc does nothing. */
84 HOWTO (R_FRV_NONE, /* type */
86 2, /* size (0 = byte, 1 = short, 2 = long) */
88 FALSE, /* pc_relative */
90 complain_overflow_bitfield, /* complain_on_overflow */
91 bfd_elf_generic_reloc, /* special_function */
92 "R_FRV_NONE", /* name */
93 FALSE, /* partial_inplace */
96 FALSE), /* pcrel_offset */
98 /* A 32 bit absolute relocation. */
99 HOWTO (R_FRV_32, /* type */
101 2, /* size (0 = byte, 1 = short, 2 = long) */
103 FALSE, /* pc_relative */
105 complain_overflow_bitfield, /* complain_on_overflow */
106 bfd_elf_generic_reloc, /* special_function */
107 "R_FRV_32", /* name */
108 FALSE, /* partial_inplace */
109 0xffffffff, /* src_mask */
110 0xffffffff, /* dst_mask */
111 FALSE), /* pcrel_offset */
113 /* A 16 bit pc-relative relocation. */
114 HOWTO (R_FRV_LABEL16, /* type */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
118 TRUE, /* pc_relative */
120 complain_overflow_bitfield, /* complain_on_overflow */
121 bfd_elf_generic_reloc, /* special_function */
122 "R_FRV_LABEL16", /* name */
123 FALSE, /* partial_inplace */
124 0xffff, /* src_mask */
125 0xffff, /* dst_mask */
126 TRUE), /* pcrel_offset */
128 /* A 24-bit pc-relative relocation. */
129 HOWTO (R_FRV_LABEL24, /* type */
131 2, /* size (0 = byte, 1 = short, 2 = long) */
133 TRUE, /* pc_relative */
135 complain_overflow_bitfield, /* complain_on_overflow */
136 bfd_elf_generic_reloc, /* special_function */
137 "R_FRV_LABEL24", /* name */
138 FALSE, /* partial_inplace */
139 0x7e03ffff, /* src_mask */
140 0x7e03ffff, /* dst_mask */
141 TRUE), /* pcrel_offset */
143 HOWTO (R_FRV_LO16, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 FALSE, /* pc_relative */
149 complain_overflow_dont, /* complain_on_overflow */
150 bfd_elf_generic_reloc, /* special_function */
151 "R_FRV_LO16", /* name */
152 FALSE, /* partial_inplace */
153 0xffff, /* src_mask */
154 0xffff, /* dst_mask */
155 FALSE), /* pcrel_offset */
157 HOWTO (R_FRV_HI16, /* type */
159 2, /* size (0 = byte, 1 = short, 2 = long) */
161 FALSE, /* pc_relative */
163 complain_overflow_dont, /* complain_on_overflow */
164 bfd_elf_generic_reloc, /* special_function */
165 "R_FRV_HI16", /* name */
166 FALSE, /* partial_inplace */
167 0xffff, /* src_mask */
168 0xffff, /* dst_mask */
169 FALSE), /* pcrel_offset */
171 HOWTO (R_FRV_GPREL12, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 FALSE, /* pc_relative */
177 complain_overflow_dont, /* complain_on_overflow */
178 bfd_elf_generic_reloc, /* special_function */
179 "R_FRV_GPREL12", /* name */
180 FALSE, /* partial_inplace */
181 0xfff, /* src_mask */
182 0xfff, /* dst_mask */
183 FALSE), /* pcrel_offset */
185 HOWTO (R_FRV_GPRELU12, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE, /* pc_relative */
191 complain_overflow_dont, /* complain_on_overflow */
192 bfd_elf_generic_reloc, /* special_function */
193 "R_FRV_GPRELU12", /* name */
194 FALSE, /* partial_inplace */
195 0xfff, /* src_mask */
196 0x3f03f, /* dst_mask */
197 FALSE), /* pcrel_offset */
199 HOWTO (R_FRV_GPREL32, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 FALSE, /* pc_relative */
205 complain_overflow_dont, /* complain_on_overflow */
206 bfd_elf_generic_reloc, /* special_function */
207 "R_FRV_GPREL32", /* name */
208 FALSE, /* partial_inplace */
209 0xffffffff, /* src_mask */
210 0xffffffff, /* dst_mask */
211 FALSE), /* pcrel_offset */
213 HOWTO (R_FRV_GPRELHI, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 FALSE, /* pc_relative */
219 complain_overflow_dont, /* complain_on_overflow */
220 bfd_elf_generic_reloc, /* special_function */
221 "R_FRV_GPRELHI", /* name */
222 FALSE, /* partial_inplace */
223 0xffff, /* src_mask */
224 0xffff, /* dst_mask */
225 FALSE), /* pcrel_offset */
227 HOWTO (R_FRV_GPRELLO, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE, /* pc_relative */
233 complain_overflow_dont, /* complain_on_overflow */
234 bfd_elf_generic_reloc, /* special_function */
235 "R_FRV_GPRELLO", /* name */
236 FALSE, /* partial_inplace */
237 0xffff, /* src_mask */
238 0xffff, /* dst_mask */
239 FALSE), /* pcrel_offset */
241 /* A 12-bit signed operand with the GOT offset for the address of
243 HOWTO (R_FRV_GOT12, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE, /* pc_relative */
249 complain_overflow_signed, /* complain_on_overflow */
250 bfd_elf_generic_reloc, /* special_function */
251 "R_FRV_GOT12", /* name */
252 FALSE, /* partial_inplace */
253 0xfff, /* src_mask */
254 0xfff, /* dst_mask */
255 FALSE), /* pcrel_offset */
257 /* The upper 16 bits of the GOT offset for the address of the
259 HOWTO (R_FRV_GOTHI, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE, /* pc_relative */
265 complain_overflow_dont, /* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_FRV_GOTHI", /* name */
268 FALSE, /* partial_inplace */
269 0xffff, /* src_mask */
270 0xffff, /* dst_mask */
271 FALSE), /* pcrel_offset */
273 /* The lower 16 bits of the GOT offset for the address of the
275 HOWTO (R_FRV_GOTLO, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE, /* pc_relative */
281 complain_overflow_dont, /* complain_on_overflow */
282 bfd_elf_generic_reloc, /* special_function */
283 "R_FRV_GOTLO", /* name */
284 FALSE, /* partial_inplace */
285 0xffff, /* src_mask */
286 0xffff, /* dst_mask */
287 FALSE), /* pcrel_offset */
289 /* The 32-bit address of the canonical descriptor of a function. */
290 HOWTO (R_FRV_FUNCDESC, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE, /* pc_relative */
296 complain_overflow_bitfield, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_FRV_FUNCDESC", /* name */
299 FALSE, /* partial_inplace */
300 0xffffffff, /* src_mask */
301 0xffffffff, /* dst_mask */
302 FALSE), /* pcrel_offset */
304 /* A 12-bit signed operand with the GOT offset for the address of
305 canonical descriptor of a function. */
306 HOWTO (R_FRV_FUNCDESC_GOT12, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE, /* pc_relative */
312 complain_overflow_signed, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_FRV_FUNCDESC_GOT12", /* name */
315 FALSE, /* partial_inplace */
316 0xfff, /* src_mask */
317 0xfff, /* dst_mask */
318 FALSE), /* pcrel_offset */
320 /* The upper 16 bits of the GOT offset for the address of the
321 canonical descriptor of a function. */
322 HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE, /* pc_relative */
328 complain_overflow_dont, /* complain_on_overflow */
329 bfd_elf_generic_reloc, /* special_function */
330 "R_FRV_FUNCDESC_GOTHI", /* name */
331 FALSE, /* partial_inplace */
332 0xffff, /* src_mask */
333 0xffff, /* dst_mask */
334 FALSE), /* pcrel_offset */
336 /* The lower 16 bits of the GOT offset for the address of the
337 canonical descriptor of a function. */
338 HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE, /* pc_relative */
344 complain_overflow_dont, /* complain_on_overflow */
345 bfd_elf_generic_reloc, /* special_function */
346 "R_FRV_FUNCDESC_GOTLO", /* name */
347 FALSE, /* partial_inplace */
348 0xffff, /* src_mask */
349 0xffff, /* dst_mask */
350 FALSE), /* pcrel_offset */
352 /* The 32-bit address of the canonical descriptor of a function. */
353 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE, /* pc_relative */
359 complain_overflow_bitfield, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_FRV_FUNCDESC_VALUE", /* name */
362 FALSE, /* partial_inplace */
363 0xffffffff, /* src_mask */
364 0xffffffff, /* dst_mask */
365 FALSE), /* pcrel_offset */
367 /* A 12-bit signed operand with the GOT offset for the address of
368 canonical descriptor of a function. */
369 HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE, /* pc_relative */
375 complain_overflow_signed, /* complain_on_overflow */
376 bfd_elf_generic_reloc, /* special_function */
377 "R_FRV_FUNCDESC_GOTOFF12", /* name */
378 FALSE, /* partial_inplace */
379 0xfff, /* src_mask */
380 0xfff, /* dst_mask */
381 FALSE), /* pcrel_offset */
383 /* The upper 16 bits of the GOT offset for the address of the
384 canonical descriptor of a function. */
385 HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE, /* pc_relative */
391 complain_overflow_dont, /* complain_on_overflow */
392 bfd_elf_generic_reloc, /* special_function */
393 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
394 FALSE, /* partial_inplace */
395 0xffff, /* src_mask */
396 0xffff, /* dst_mask */
397 FALSE), /* pcrel_offset */
399 /* The lower 16 bits of the GOT offset for the address of the
400 canonical descriptor of a function. */
401 HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE, /* pc_relative */
407 complain_overflow_dont, /* complain_on_overflow */
408 bfd_elf_generic_reloc, /* special_function */
409 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
410 FALSE, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 FALSE), /* pcrel_offset */
415 /* A 12-bit signed operand with the GOT offset for the address of
417 HOWTO (R_FRV_GOTOFF12, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE, /* pc_relative */
423 complain_overflow_signed, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_FRV_GOTOFF12", /* name */
426 FALSE, /* partial_inplace */
427 0xfff, /* src_mask */
428 0xfff, /* dst_mask */
429 FALSE), /* pcrel_offset */
431 /* The upper 16 bits of the GOT offset for the address of the
433 HOWTO (R_FRV_GOTOFFHI, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE, /* pc_relative */
439 complain_overflow_dont, /* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_FRV_GOTOFFHI", /* name */
442 FALSE, /* partial_inplace */
443 0xffff, /* src_mask */
444 0xffff, /* dst_mask */
445 FALSE), /* pcrel_offset */
447 /* The lower 16 bits of the GOT offset for the address of the
449 HOWTO (R_FRV_GOTOFFLO, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE, /* pc_relative */
455 complain_overflow_dont, /* complain_on_overflow */
456 bfd_elf_generic_reloc, /* special_function */
457 "R_FRV_GOTOFFLO", /* name */
458 FALSE, /* partial_inplace */
459 0xffff, /* src_mask */
460 0xffff, /* dst_mask */
461 FALSE), /* pcrel_offset */
465 /* GNU extension to record C++ vtable hierarchy. */
466 static reloc_howto_type elf32_frv_vtinherit_howto =
467 HOWTO (R_FRV_GNU_VTINHERIT, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 FALSE, /* pc_relative */
473 complain_overflow_dont, /* complain_on_overflow */
474 NULL, /* special_function */
475 "R_FRV_GNU_VTINHERIT", /* name */
476 FALSE, /* partial_inplace */
479 FALSE); /* pcrel_offset */
481 /* GNU extension to record C++ vtable member usage. */
482 static reloc_howto_type elf32_frv_vtentry_howto =
483 HOWTO (R_FRV_GNU_VTENTRY, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE, /* pc_relative */
489 complain_overflow_dont, /* complain_on_overflow */
490 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
491 "R_FRV_GNU_VTENTRY", /* name */
492 FALSE, /* partial_inplace */
495 FALSE); /* pcrel_offset */
497 /* The following 3 relocations are REL. The only difference to the
498 entries in the table above are that partial_inplace is TRUE. */
499 static reloc_howto_type elf32_frv_rel_32_howto =
500 HOWTO (R_FRV_32, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE, /* pc_relative */
506 complain_overflow_bitfield, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 "R_FRV_32", /* name */
509 TRUE, /* partial_inplace */
510 0xffffffff, /* src_mask */
511 0xffffffff, /* dst_mask */
512 FALSE); /* pcrel_offset */
514 static reloc_howto_type elf32_frv_rel_funcdesc_howto =
515 HOWTO (R_FRV_FUNCDESC, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE, /* pc_relative */
521 complain_overflow_bitfield, /* complain_on_overflow */
522 bfd_elf_generic_reloc, /* special_function */
523 "R_FRV_FUNCDESC", /* name */
524 TRUE, /* partial_inplace */
525 0xffffffff, /* src_mask */
526 0xffffffff, /* dst_mask */
527 FALSE); /* pcrel_offset */
529 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
530 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE, /* pc_relative */
536 complain_overflow_bitfield, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 "R_FRV_FUNCDESC_VALUE", /* name */
539 TRUE, /* partial_inplace */
540 0xffffffff, /* src_mask */
541 0xffffffff, /* dst_mask */
542 FALSE); /* pcrel_offset */
545 /* Map BFD reloc types to FRV ELF reloc types. */
549 unsigned int bfd_reloc_val;
550 unsigned int frv_reloc_val;
553 static const struct frv_reloc_map frv_reloc_map [] =
555 { BFD_RELOC_NONE, R_FRV_NONE },
556 { BFD_RELOC_32, R_FRV_32 },
557 { BFD_RELOC_FRV_LABEL16, R_FRV_LABEL16 },
558 { BFD_RELOC_FRV_LABEL24, R_FRV_LABEL24 },
559 { BFD_RELOC_FRV_LO16, R_FRV_LO16 },
560 { BFD_RELOC_FRV_HI16, R_FRV_HI16 },
561 { BFD_RELOC_FRV_GPREL12, R_FRV_GPREL12 },
562 { BFD_RELOC_FRV_GPRELU12, R_FRV_GPRELU12 },
563 { BFD_RELOC_FRV_GPREL32, R_FRV_GPREL32 },
564 { BFD_RELOC_FRV_GPRELHI, R_FRV_GPRELHI },
565 { BFD_RELOC_FRV_GPRELLO, R_FRV_GPRELLO },
566 { BFD_RELOC_FRV_GOT12, R_FRV_GOT12 },
567 { BFD_RELOC_FRV_GOTHI, R_FRV_GOTHI },
568 { BFD_RELOC_FRV_GOTLO, R_FRV_GOTLO },
569 { BFD_RELOC_FRV_FUNCDESC, R_FRV_FUNCDESC },
570 { BFD_RELOC_FRV_FUNCDESC_GOT12, R_FRV_FUNCDESC_GOT12 },
571 { BFD_RELOC_FRV_FUNCDESC_GOTHI, R_FRV_FUNCDESC_GOTHI },
572 { BFD_RELOC_FRV_FUNCDESC_GOTLO, R_FRV_FUNCDESC_GOTLO },
573 { BFD_RELOC_FRV_FUNCDESC_VALUE, R_FRV_FUNCDESC_VALUE },
574 { BFD_RELOC_FRV_FUNCDESC_GOTOFF12, R_FRV_FUNCDESC_GOTOFF12 },
575 { BFD_RELOC_FRV_FUNCDESC_GOTOFFHI, R_FRV_FUNCDESC_GOTOFFHI },
576 { BFD_RELOC_FRV_FUNCDESC_GOTOFFLO, R_FRV_FUNCDESC_GOTOFFLO },
577 { BFD_RELOC_FRV_GOTOFF12, R_FRV_GOTOFF12 },
578 { BFD_RELOC_FRV_GOTOFFHI, R_FRV_GOTOFFHI },
579 { BFD_RELOC_FRV_GOTOFFLO, R_FRV_GOTOFFLO },
580 { BFD_RELOC_VTABLE_INHERIT, R_FRV_GNU_VTINHERIT },
581 { BFD_RELOC_VTABLE_ENTRY, R_FRV_GNU_VTENTRY },
586 /* An extension of the elf hash table data structure, containing some
587 additional FRV-specific data. */
588 struct frv_elf_link_hash_table
590 struct elf_link_hash_table elf;
592 /* A pointer to the .got section. */
594 /* A pointer to the .rel.got section. */
596 /* A pointer to the .rofixup section. */
598 /* A pointer to the .plt section. */
600 /* A pointer to the .rel.plt section. */
602 /* GOT base offset. */
604 /* Location of the first non-lazy PLT entry, i.e., the number of
605 bytes taken by lazy PLT entries. */
607 /* A hash table holding information about which symbols were
608 referenced with which PIC-related relocations. */
609 struct htab *relocs_info;
612 /* Get the FRV ELF linker hash table from a link_info structure. */
614 #define frv_hash_table(info) \
615 ((struct frv_elf_link_hash_table *) ((info)->hash))
617 #define frv_got_section(info) \
618 (frv_hash_table (info)->sgot)
619 #define frv_gotrel_section(info) \
620 (frv_hash_table (info)->sgotrel)
621 #define frv_gotfixup_section(info) \
622 (frv_hash_table (info)->sgotfixup)
623 #define frv_plt_section(info) \
624 (frv_hash_table (info)->splt)
625 #define frv_pltrel_section(info) \
626 (frv_hash_table (info)->spltrel)
627 #define frv_relocs_info(info) \
628 (frv_hash_table (info)->relocs_info)
629 #define frv_got_initial_offset(info) \
630 (frv_hash_table (info)->got0)
631 #define frv_plt_initial_offset(info) \
632 (frv_hash_table (info)->plt0)
634 /* Create an FRV ELF linker hash table. */
636 static struct bfd_link_hash_table *
637 frv_elf_link_hash_table_create (bfd *abfd)
639 struct frv_elf_link_hash_table *ret;
640 bfd_size_type amt = sizeof (struct frv_elf_link_hash_table);
642 ret = bfd_zalloc (abfd, amt);
646 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
647 _bfd_elf_link_hash_newfunc))
653 return &ret->elf.root;
656 /* Decide whether a reference to a symbol can be resolved locally or
657 not. If the symbol is protected, we want the local address, but
658 its function descriptor must be assigned by the dynamic linker. */
659 #define FRV_SYM_LOCAL(INFO, H) \
660 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
661 || ! elf_hash_table (INFO)->dynamic_sections_created \
662 || (H)->root.type == bfd_link_hash_undefweak \
663 || (/* The condition below is an ugly hack to get .scommon data to
664 be regarded as local. For some reason the
665 ELF_LINK_HASH_DEF_REGULAR bit is not set on such common
666 symbols, and the SEC_IS_COMMON bit is not set any longer
667 when we need to perform this test. Hopefully this
668 approximation is good enough. */ \
669 ((H)->root.type == bfd_link_hash_defined \
670 || (H)->root.type == bfd_link_hash_defweak) \
671 && (H)->root.u.def.section->output_section \
672 && ((H)->root.u.def.section->flags & SEC_LINKER_CREATED)))
673 #define FRV_FUNCDESC_LOCAL(INFO, H) \
674 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
676 /* This structure collects information on what kind of GOT, PLT or
677 function descriptors are required by relocations that reference a
679 struct frv_pic_relocs_info
681 /* The index of the symbol, as stored in the relocation r_info, if
682 we have a local symbol; -1 otherwise. */
686 /* The input bfd in which the symbol is defined, if it's a local
689 /* If symndx == -1, the hash table entry corresponding to a global
690 symbol (even if it turns out to bind locally, in which case it
691 should ideally be replaced with section's symndx + addend). */
692 struct elf_link_hash_entry *h;
694 /* The addend of the relocation that references the symbol. */
697 /* The fields above are used to identify an entry. The fields below
698 contain information on how an entry is used and, later on, which
699 locations it was assigned. */
700 /* The following 3 fields record whether the symbol+addend above was
701 ever referenced with a GOT relocation. The 12 suffix indicates a
702 GOT12 relocation; los is used for GOTLO relocations that are not
703 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
708 /* Whether a FUNCDESC relocation references symbol+addend. */
710 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
713 unsigned fdgothilo:1;
714 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
716 unsigned fdgofflos:1;
717 unsigned fdgoffhilo:1;
718 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
719 GOTOFFHI relocations. The addend doesn't really matter, since we
720 envision that this will only be used to check whether the symbol
721 is mapped to the same segment as the got. */
723 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
725 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
728 /* Whether we need a PLT entry for a symbol. Should be implied by
730 (call && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)) */
732 /* Whether a function descriptor should be created in this link unit
733 for symbol+addend. Should be implied by something like:
734 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
735 || ((fd || fdgot12 || fdgotlos || fdgothilo)
736 && (symndx != -1 || FRV_FUNCDESC_LOCAL (info, d.h)))) */
738 /* Whether a lazy PLT entry is needed for this symbol+addend.
739 Should be implied by something like:
740 (privfd && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)
741 && ! (info->flags & DF_BIND_NOW)) */
743 /* Whether we've already emitted GOT relocations and PLT entries as
744 needed for this symbol. */
747 /* The number of R_FRV_32, R_FRV_FUNCDESC and R_FRV_FUNCDESC_VALUE
748 relocations referencing the symbol. */
749 unsigned relocs32, relocsfd, relocsfdv;
751 /* The offsets of the GOT entries assigned to symbol+addend, to the
752 function descriptor's address, and to a function descriptor,
753 respectively. Should be zero if unassigned. The offsets are
754 counted from the value that will be assigned to the PIC register,
755 not from the beginning of the .got section. */
756 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
757 /* The offsets of the PLT entries assigned to symbol+addend,
758 non-lazy and lazy, respectively. If unassigned, should be
760 bfd_vma plt_entry, lzplt_entry;
763 /* Compute a hash with the key fields of an frv_pic_relocs_info entry. */
765 frv_pic_relocs_info_hash (const void *entry_)
767 const struct frv_pic_relocs_info *entry = entry_;
769 return (entry->symndx == -1
770 ? entry->d.h->root.root.hash
771 : entry->symndx + entry->d.abfd->id * 257) + entry->addend;
774 /* Test whether the key fields of two frv_pic_relocs_info entries are
777 frv_pic_relocs_info_eq (const void *entry1, const void *entry2)
779 const struct frv_pic_relocs_info *e1 = entry1;
780 const struct frv_pic_relocs_info *e2 = entry2;
782 return e1->symndx == e2->symndx && e1->addend == e2->addend
783 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
786 /* Find or create an entry in a hash table HT that matches the key
787 fields of the given ENTRY. If it's not found, memory for a new
788 entry is allocated in ABFD's obstack. */
789 static struct frv_pic_relocs_info *
790 frv_pic_relocs_info_find (struct htab *ht,
792 const struct frv_pic_relocs_info *entry)
794 struct frv_pic_relocs_info **loc =
795 (struct frv_pic_relocs_info **) htab_find_slot (ht, entry, INSERT);
800 *loc = bfd_zalloc (abfd, sizeof (**loc));
805 (*loc)->symndx = entry->symndx;
806 (*loc)->d = entry->d;
807 (*loc)->addend = entry->addend;
808 (*loc)->plt_entry = (bfd_vma)-1;
809 (*loc)->lzplt_entry = (bfd_vma)-1;
814 /* Obtain the address of the entry in HT associated with H's symbol +
815 addend, creating a new entry if none existed. ABFD is only used
816 for memory allocation purposes. */
817 inline static struct frv_pic_relocs_info *
818 frv_pic_relocs_info_for_global (struct htab *ht,
820 struct elf_link_hash_entry *h,
823 struct frv_pic_relocs_info entry;
827 entry.addend = addend;
829 return frv_pic_relocs_info_find (ht, abfd, &entry);
832 /* Obtain the address of the entry in HT associated with the SYMNDXth
833 local symbol of the input bfd ABFD, plus the addend, creating a new
834 entry if none existed. */
835 inline static struct frv_pic_relocs_info *
836 frv_pic_relocs_info_for_local (struct htab *ht,
841 struct frv_pic_relocs_info entry;
843 entry.symndx = symndx;
845 entry.addend = addend;
847 return frv_pic_relocs_info_find (ht, abfd, &entry);
850 /* Every block of 65535 lazy PLT entries shares a single call to the
851 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
852 32767, counting from 0). All other lazy PLT entries branch to it
853 in a single instruction. */
855 #define FRV_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
856 #define FRV_LZPLT_RESOLV_LOC (8 * 32767)
858 /* Add a dynamic relocation to the SRELOC section. */
860 inline static bfd_vma
861 _frv_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
862 int reloc_type, long dynindx, bfd_vma addend)
864 Elf_Internal_Rela outrel;
865 bfd_vma reloc_offset;
867 outrel.r_offset = offset;
868 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
869 outrel.r_addend = addend;
871 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
872 BFD_ASSERT (reloc_offset < sreloc->_raw_size);
873 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
874 sreloc->contents + reloc_offset);
875 sreloc->reloc_count++;
880 /* Add a fixup to the ROFIXUP section. */
883 _frv_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset)
885 bfd_vma fixup_offset;
887 if (rofixup->flags & SEC_EXCLUDE)
890 fixup_offset = rofixup->reloc_count * 4;
891 if (rofixup->contents)
893 BFD_ASSERT (fixup_offset < rofixup->_raw_size);
894 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
896 rofixup->reloc_count++;
901 /* Find the segment number in which OSEC, and output section, is
905 _frv_osec_to_segment (bfd *output_bfd, asection *osec)
907 struct elf_segment_map *m;
908 Elf_Internal_Phdr *p;
910 /* Find the segment that contains the output_section. */
911 for (m = elf_tdata (output_bfd)->segment_map,
912 p = elf_tdata (output_bfd)->phdr;
918 for (i = m->count - 1; i >= 0; i--)
919 if (m->sections[i] == osec)
926 return p - elf_tdata (output_bfd)->phdr;
929 inline static bfd_boolean
930 _frv_osec_readonly_p (bfd *output_bfd, asection *osec)
932 unsigned seg = _frv_osec_to_segment (output_bfd, osec);
934 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
937 /* Generate relocations for GOT entries, function descriptors, and
938 code for PLT and lazy PLT entries. */
940 inline static bfd_boolean
941 _frv_emit_got_relocs_plt_entries (struct frv_pic_relocs_info *entry,
943 struct bfd_link_info *info,
945 Elf_Internal_Sym *sym,
949 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
956 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry)
958 /* If the symbol is dynamic, consider it for dynamic
959 relocations, otherwise decay to section + offset. */
960 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
961 dynindx = entry->d.h->dynindx;
964 if (sec->output_section
965 && ! bfd_is_abs_section (sec->output_section)
966 && ! bfd_is_und_section (sec->output_section))
967 dynindx = elf_section_data (sec->output_section)->dynindx;
973 /* Generate relocation for GOT entry pointing to the symbol. */
974 if (entry->got_entry)
979 /* If the symbol is dynamic but binds locally, use
981 if (sec && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
983 if (entry->symndx == -1)
984 ad += entry->d.h->root.u.def.value;
987 ad += sec->output_offset;
988 if (sec->output_section && elf_section_data (sec->output_section))
989 idx = elf_section_data (sec->output_section)->dynindx;
994 /* If we're linking an executable at a fixed address, we can
995 omit the dynamic relocation as long as the symbol is local to
997 if (info->executable && !info->pie
998 && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1001 ad += sec->output_section->vma;
1002 if (entry->symndx != -1 ||
1003 entry->d.h->root.type != bfd_link_hash_undefweak)
1004 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1005 frv_got_section (info)->output_section->vma
1006 + frv_got_section (info)->output_offset
1007 + frv_got_initial_offset (info)
1008 + entry->got_entry);
1011 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
1012 _bfd_elf_section_offset
1014 frv_got_section (info),
1015 frv_got_initial_offset (info)
1017 + frv_got_section (info)->output_section->vma
1018 + frv_got_section (info)->output_offset,
1021 bfd_put_32 (output_bfd, ad,
1022 frv_got_section (info)->contents
1023 + frv_got_initial_offset (info)
1024 + entry->got_entry);
1027 /* Generate relocation for GOT entry pointing to a canonical
1028 function descriptor. */
1029 if (entry->fdgot_entry)
1034 /* If the symbol is dynamic and there may be dynamic symbol
1035 resolution because we are or are linked with a shared
1036 library, emit a FUNCDESC relocation such that the dynamic
1037 linker will allocate the function descriptor. */
1038 if (entry->symndx == -1 && ! FRV_FUNCDESC_LOCAL (info, entry->d.h))
1040 reloc = R_FRV_FUNCDESC;
1048 /* Otherwise, we know we have a private function descriptor,
1049 so reference it directly. */
1050 if (elf_hash_table (info)->dynamic_sections_created)
1051 BFD_ASSERT (entry->privfd);
1053 idx = elf_section_data (frv_got_section (info)->output_section)
1055 ad = frv_got_section (info)->output_offset +
1056 frv_got_initial_offset (info) + entry->fd_entry;
1059 /* If there is room for dynamic symbol resolution, emit the
1060 dynamic relocation. However, if we're linking an executable
1061 at a fixed location, we won't have emitted a dynamic symbol
1062 entry for the got section, so idx will be zero, which means
1063 we can and should compute the address of the private
1064 descriptor ourselves. */
1065 if (info->executable && !info->pie
1066 && (entry->symndx != -1 || FRV_FUNCDESC_LOCAL (info, entry->d.h)))
1068 if (entry->symndx == -1
1069 && entry->d.h->root.type == bfd_link_hash_undefweak)
1073 ad += frv_got_section (info)->output_section->vma;
1074 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1075 frv_got_section (info)->output_section->vma
1076 + frv_got_section (info)->output_offset
1077 + frv_got_initial_offset (info)
1078 + entry->fdgot_entry);
1082 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
1083 _bfd_elf_section_offset
1085 frv_got_section (info),
1086 frv_got_initial_offset (info)
1087 + entry->fdgot_entry)
1088 + frv_got_section (info)->output_section->vma
1089 + frv_got_section (info)->output_offset,
1092 bfd_put_32 (output_bfd, ad,
1093 frv_got_section (info)->contents
1094 + frv_got_initial_offset (info)
1095 + entry->fdgot_entry);
1098 /* Generate relocation to fill in a private function descriptor in
1100 if (entry->fd_entry)
1103 bfd_vma ad = addend;
1105 long lowword, highword;
1107 /* If the symbol is dynamic but binds locally, use
1109 if (sec && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1111 if (entry->symndx == -1)
1112 ad += entry->d.h->root.u.def.value;
1114 ad += sym->st_value;
1115 ad += sec->output_offset;
1116 if (sec->output_section && elf_section_data (sec->output_section))
1117 idx = elf_section_data (sec->output_section)->dynindx;
1122 /* If we're linking an executable at a fixed address, we can
1123 omit the dynamic relocation as long as the symbol is local to
1125 if (info->executable && !info->pie
1126 && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1129 ad += sec->output_section->vma;
1131 if (entry->symndx != -1 ||
1132 entry->d.h->root.type != bfd_link_hash_undefweak)
1134 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1135 frv_got_section (info)->output_section->vma
1136 + frv_got_section (info)->output_offset
1137 + frv_got_initial_offset (info)
1139 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
1140 frv_got_section (info)->output_section->vma
1141 + frv_got_section (info)->output_offset
1142 + frv_got_initial_offset (info)
1143 + entry->fd_entry + 4);
1149 _frv_add_dyn_reloc (output_bfd,
1150 entry->lazyplt ? frv_pltrel_section (info)
1151 : frv_gotrel_section (info),
1152 _bfd_elf_section_offset
1154 frv_got_section (info),
1155 frv_got_initial_offset (info)
1157 + frv_got_section (info)->output_section->vma
1158 + frv_got_section (info)->output_offset,
1159 R_FRV_FUNCDESC_VALUE, idx, ad);
1162 /* If we've omitted the dynamic relocation, just emit the fixed
1163 addresses of the symbol and of the local GOT base offset. */
1164 if (info->executable && !info->pie && sec && sec->output_section)
1167 highword = frv_got_section (info)->output_section->vma
1168 + frv_got_section (info)->output_offset
1169 + frv_got_initial_offset (info);
1171 else if (entry->lazyplt)
1176 fd_lazy_rel_offset = ofst;
1178 /* A function descriptor used for lazy or local resolving is
1179 initialized such that its high word contains the output
1180 section index in which the PLT entries are located, and
1181 the low word contains the address of the lazy PLT entry
1182 entry point, that must be within the memory region
1183 assigned to that section. */
1184 lowword = entry->lzplt_entry + 4
1185 + frv_plt_section (info)->output_offset
1186 + frv_plt_section (info)->output_section->vma;
1187 highword = _frv_osec_to_segment
1188 (output_bfd, frv_plt_section (info)->output_section);
1192 /* A function descriptor for a local function gets the index
1193 of the section. For a non-local function, it's
1196 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1197 && entry->d.h->dynindx == idx)
1200 highword = _frv_osec_to_segment (output_bfd, sec->output_section);
1203 bfd_put_32 (output_bfd, lowword,
1204 frv_got_section (info)->contents
1205 + frv_got_initial_offset (info)
1207 bfd_put_32 (output_bfd, highword,
1208 frv_got_section (info)->contents
1209 + frv_got_initial_offset (info)
1210 + entry->fd_entry + 4);
1213 /* Generate code for the PLT entry. */
1214 if (entry->plt_entry != (bfd_vma) -1)
1216 bfd_byte *plt_code = frv_plt_section (info)->contents + entry->plt_entry;
1218 BFD_ASSERT (entry->fd_entry);
1220 /* Figure out what kind of PLT entry we need, depending on the
1221 location of the function descriptor within the GOT. */
1222 if (entry->fd_entry >= -(1 << (12 - 1))
1223 && entry->fd_entry < (1 << (12 - 1)))
1225 /* lddi @(gr15, fd_entry), gr14 */
1226 bfd_put_32 (output_bfd,
1227 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1233 if (entry->fd_entry >= -(1 << (16 - 1))
1234 && entry->fd_entry < (1 << (16 - 1)))
1236 /* setlos lo(fd_entry), gr14 */
1237 bfd_put_32 (output_bfd,
1239 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1245 /* sethi.p hi(fd_entry), gr14
1246 setlo lo(fd_entry), gr14 */
1247 bfd_put_32 (output_bfd,
1249 | ((entry->fd_entry >> 16)
1250 & (((bfd_vma)1 << 16) - 1)),
1252 bfd_put_32 (output_bfd,
1254 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1258 /* ldd @(gr14,gr15),gr14 */
1259 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1262 /* jmpl @(gr14,gr0) */
1263 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1266 /* Generate code for the lazy PLT entry. */
1267 if (entry->lzplt_entry != (bfd_vma) -1)
1269 bfd_byte *lzplt_code = frv_plt_section (info)->contents
1270 + entry->lzplt_entry;
1271 bfd_vma resolverStub_addr;
1273 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1276 resolverStub_addr = entry->lzplt_entry / FRV_LZPLT_BLOCK_SIZE
1277 * FRV_LZPLT_BLOCK_SIZE + FRV_LZPLT_RESOLV_LOC;
1278 if (resolverStub_addr >= frv_plt_initial_offset (info))
1279 resolverStub_addr = frv_plt_initial_offset (info) - 12;
1281 if (entry->lzplt_entry == resolverStub_addr)
1283 /* This is a lazy PLT entry that includes a resolver call. */
1284 /* ldd @(gr15,gr0), gr4
1286 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1287 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1291 /* bra resolverStub */
1292 bfd_put_32 (output_bfd,
1294 | (((resolverStub_addr - entry->lzplt_entry)
1295 / 4) & (((bfd_vma)1 << 16) - 1)),
1303 /* Handle an FRV small data reloc. */
1305 static bfd_reloc_status_type
1306 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
1308 struct bfd_link_info *info;
1310 asection *input_section;
1311 Elf_Internal_Rela *relocation;
1317 struct bfd_link_hash_entry *h;
1319 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1321 gp = (h->u.def.value
1322 + h->u.def.section->output_section->vma
1323 + h->u.def.section->output_offset);
1325 value -= input_section->output_section->vma;
1326 value -= (gp - input_section->output_section->vma);
1328 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1330 value += relocation->r_addend;
1332 if ((long) value > 0x7ff || (long) value < -0x800)
1333 return bfd_reloc_overflow;
1335 bfd_put_32 (input_bfd,
1336 (insn & 0xfffff000) | (value & 0xfff),
1337 contents + relocation->r_offset);
1339 return bfd_reloc_ok;
1342 /* Handle an FRV small data reloc. for the u12 field. */
1344 static bfd_reloc_status_type
1345 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
1347 struct bfd_link_info *info;
1349 asection *input_section;
1350 Elf_Internal_Rela *relocation;
1356 struct bfd_link_hash_entry *h;
1359 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1361 gp = (h->u.def.value
1362 + h->u.def.section->output_section->vma
1363 + h->u.def.section->output_offset);
1365 value -= input_section->output_section->vma;
1366 value -= (gp - input_section->output_section->vma);
1368 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1370 value += relocation->r_addend;
1372 if ((long) value > 0x7ff || (long) value < -0x800)
1373 return bfd_reloc_overflow;
1375 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
1377 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
1379 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1381 return bfd_reloc_ok;
1384 /* Handle an FRV ELF HI16 reloc. */
1386 static bfd_reloc_status_type
1387 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
1389 Elf_Internal_Rela *relhi;
1395 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
1397 value += relhi->r_addend;
1398 value = ((value >> 16) & 0xffff);
1400 insn = (insn & 0xffff0000) | value;
1402 if ((long) value > 0xffff || (long) value < -0x10000)
1403 return bfd_reloc_overflow;
1405 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
1406 return bfd_reloc_ok;
1409 static bfd_reloc_status_type
1410 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
1412 Elf_Internal_Rela *rello;
1418 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1420 value += rello->r_addend;
1421 value = value & 0xffff;
1423 insn = (insn & 0xffff0000) | value;
1425 if ((long) value > 0xffff || (long) value < -0x10000)
1426 return bfd_reloc_overflow;
1428 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1429 return bfd_reloc_ok;
1432 /* Perform the relocation for the CALL label24 instruction. */
1434 static bfd_reloc_status_type
1435 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
1437 asection *input_section;
1438 Elf_Internal_Rela *rello;
1446 /* The format for the call instruction is:
1448 0 000000 0001111 000000000000000000
1449 label6 opcode label18
1451 The branch calculation is: pc + (4*label24)
1452 where label24 is the concatenation of label6 and label18. */
1454 /* Grab the instruction. */
1455 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1457 value -= input_section->output_section->vma + input_section->output_offset;
1458 value -= rello->r_offset;
1459 value += rello->r_addend;
1463 label6 = value & 0xfc0000;
1464 label6 = label6 << 7;
1466 label18 = value & 0x3ffff;
1468 insn = insn & 0x803c0000;
1469 insn = insn | label6;
1470 insn = insn | label18;
1472 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1474 return bfd_reloc_ok;
1477 static bfd_reloc_status_type
1478 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
1480 struct bfd_link_info *info;
1482 asection *input_section;
1483 Elf_Internal_Rela *relocation;
1489 struct bfd_link_hash_entry *h;
1491 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1493 gp = (h->u.def.value
1494 + h->u.def.section->output_section->vma
1495 + h->u.def.section->output_offset);
1497 value -= input_section->output_section->vma;
1498 value -= (gp - input_section->output_section->vma);
1499 value += relocation->r_addend;
1500 value = ((value >> 16) & 0xffff);
1502 if ((long) value > 0xffff || (long) value < -0x10000)
1503 return bfd_reloc_overflow;
1505 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1506 insn = (insn & 0xffff0000) | value;
1508 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1509 return bfd_reloc_ok;
1512 static bfd_reloc_status_type
1513 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
1515 struct bfd_link_info *info;
1517 asection *input_section;
1518 Elf_Internal_Rela *relocation;
1524 struct bfd_link_hash_entry *h;
1526 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1528 gp = (h->u.def.value
1529 + h->u.def.section->output_section->vma
1530 + h->u.def.section->output_offset);
1532 value -= input_section->output_section->vma;
1533 value -= (gp - input_section->output_section->vma);
1534 value += relocation->r_addend;
1535 value = value & 0xffff;
1537 if ((long) value > 0xffff || (long) value < -0x10000)
1538 return bfd_reloc_overflow;
1540 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1541 insn = (insn & 0xffff0000) | value;
1543 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1545 return bfd_reloc_ok;
1548 static reloc_howto_type *
1549 frv_reloc_type_lookup (abfd, code)
1550 bfd *abfd ATTRIBUTE_UNUSED;
1551 bfd_reloc_code_real_type code;
1558 case BFD_RELOC_NONE:
1559 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
1562 if (elf_elfheader (abfd)->e_type == ET_EXEC
1563 || elf_elfheader (abfd)->e_type == ET_DYN)
1564 return &elf32_frv_rel_32_howto;
1566 case BFD_RELOC_CTOR:
1567 return &elf32_frv_howto_table[ (int) R_FRV_32];
1569 case BFD_RELOC_FRV_LABEL16:
1570 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
1572 case BFD_RELOC_FRV_LABEL24:
1573 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
1575 case BFD_RELOC_FRV_LO16:
1576 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
1578 case BFD_RELOC_FRV_HI16:
1579 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
1581 case BFD_RELOC_FRV_GPREL12:
1582 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
1584 case BFD_RELOC_FRV_GPRELU12:
1585 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
1587 case BFD_RELOC_FRV_GPREL32:
1588 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
1590 case BFD_RELOC_FRV_GPRELHI:
1591 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
1593 case BFD_RELOC_FRV_GPRELLO:
1594 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
1596 case BFD_RELOC_FRV_GOT12:
1597 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
1599 case BFD_RELOC_FRV_GOTHI:
1600 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
1602 case BFD_RELOC_FRV_GOTLO:
1603 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
1605 case BFD_RELOC_FRV_FUNCDESC:
1606 if (elf_elfheader (abfd)->e_type == ET_EXEC
1607 || elf_elfheader (abfd)->e_type == ET_DYN)
1608 return &elf32_frv_rel_funcdesc_howto;
1609 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
1611 case BFD_RELOC_FRV_FUNCDESC_GOT12:
1612 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
1614 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
1615 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
1617 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
1618 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
1620 case BFD_RELOC_FRV_FUNCDESC_VALUE:
1621 if (elf_elfheader (abfd)->e_type == ET_EXEC
1622 || elf_elfheader (abfd)->e_type == ET_DYN)
1623 return &elf32_frv_rel_funcdesc_value_howto;
1624 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
1626 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
1627 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
1629 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
1630 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
1632 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
1633 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
1635 case BFD_RELOC_FRV_GOTOFF12:
1636 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
1638 case BFD_RELOC_FRV_GOTOFFHI:
1639 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
1641 case BFD_RELOC_FRV_GOTOFFLO:
1642 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
1644 case BFD_RELOC_VTABLE_INHERIT:
1645 return &elf32_frv_vtinherit_howto;
1647 case BFD_RELOC_VTABLE_ENTRY:
1648 return &elf32_frv_vtentry_howto;
1654 /* Set the howto pointer for an FRV ELF reloc. */
1657 frv_info_to_howto_rela (abfd, cache_ptr, dst)
1658 bfd *abfd ATTRIBUTE_UNUSED;
1660 Elf_Internal_Rela *dst;
1662 unsigned int r_type;
1664 r_type = ELF32_R_TYPE (dst->r_info);
1667 case R_FRV_GNU_VTINHERIT:
1668 cache_ptr->howto = &elf32_frv_vtinherit_howto;
1671 case R_FRV_GNU_VTENTRY:
1672 cache_ptr->howto = &elf32_frv_vtentry_howto;
1676 cache_ptr->howto = & elf32_frv_howto_table [r_type];
1681 /* Set the howto pointer for an FRV ELF REL reloc. */
1683 frv_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1684 arelent *cache_ptr, Elf_Internal_Rela *dst)
1686 unsigned int r_type;
1688 r_type = ELF32_R_TYPE (dst->r_info);
1692 cache_ptr->howto = &elf32_frv_rel_32_howto;
1695 case R_FRV_FUNCDESC:
1696 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
1699 case R_FRV_FUNCDESC_VALUE:
1700 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
1704 cache_ptr->howto = NULL;
1709 /* Perform a single relocation. By default we use the standard BFD
1710 routines, but a few relocs, we have to do them ourselves. */
1712 static bfd_reloc_status_type
1713 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
1715 reloc_howto_type *howto;
1717 asection *input_section;
1719 Elf_Internal_Rela *rel;
1722 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1723 contents, rel->r_offset, relocation,
1728 /* Relocate an FRV ELF section.
1730 The RELOCATE_SECTION function is called by the new ELF backend linker
1731 to handle the relocations for a section.
1733 The relocs are always passed as Rela structures; if the section
1734 actually uses Rel structures, the r_addend field will always be
1737 This function is responsible for adjusting the section contents as
1738 necessary, and (if using Rela relocs and generating a relocatable
1739 output file) adjusting the reloc addend as necessary.
1741 This function does not have to worry about setting the reloc
1742 address or the reloc symbol index.
1744 LOCAL_SYMS is a pointer to the swapped in local symbols.
1746 LOCAL_SECTIONS is an array giving the section in the input file
1747 corresponding to the st_shndx field of each local symbol.
1749 The global hash table entry for the global symbols can be found
1750 via elf_sym_hashes (input_bfd).
1752 When generating relocatable output, this function must handle
1753 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1754 going to be the section symbol corresponding to the output
1755 section, which means that the addend must be adjusted
1759 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
1760 contents, relocs, local_syms, local_sections)
1761 bfd *output_bfd ATTRIBUTE_UNUSED;
1762 struct bfd_link_info *info;
1764 asection *input_section;
1766 Elf_Internal_Rela *relocs;
1767 Elf_Internal_Sym *local_syms;
1768 asection **local_sections;
1770 Elf_Internal_Shdr *symtab_hdr;
1771 struct elf_link_hash_entry **sym_hashes;
1772 Elf_Internal_Rela *rel;
1773 Elf_Internal_Rela *relend;
1774 unsigned isec_segment, got_segment, plt_segment, gprel_segment,
1776 int silence_segment_error = !(info->shared || info->pie);
1778 if (info->relocatable)
1781 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1782 sym_hashes = elf_sym_hashes (input_bfd);
1783 relend = relocs + input_section->reloc_count;
1785 isec_segment = _frv_osec_to_segment (output_bfd,
1786 input_section->output_section);
1787 if (frv_got_section (info))
1788 got_segment = _frv_osec_to_segment (output_bfd,
1789 frv_got_section (info)
1793 if (frv_gotfixup_section (info))
1794 gprel_segment = _frv_osec_to_segment (output_bfd,
1795 frv_gotfixup_section (info)
1799 if (elf_hash_table (info)->dynamic_sections_created)
1800 plt_segment = _frv_osec_to_segment (output_bfd,
1801 frv_plt_section (info)
1806 for (rel = relocs; rel < relend; rel ++)
1808 reloc_howto_type *howto;
1809 unsigned long r_symndx;
1810 Elf_Internal_Sym *sym;
1812 struct elf_link_hash_entry *h;
1814 bfd_reloc_status_type r;
1815 const char * name = NULL;
1818 struct frv_pic_relocs_info *picrel;
1819 bfd_vma orig_addend = rel->r_addend;
1821 r_type = ELF32_R_TYPE (rel->r_info);
1823 if ( r_type == R_FRV_GNU_VTINHERIT
1824 || r_type == R_FRV_GNU_VTENTRY)
1827 /* This is a final link. */
1828 r_symndx = ELF32_R_SYM (rel->r_info);
1829 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
1834 if (r_symndx < symtab_hdr->sh_info)
1836 sym = local_syms + r_symndx;
1837 osec = sec = local_sections [r_symndx];
1838 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1840 name = bfd_elf_string_from_elf_section
1841 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1842 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1846 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
1848 while (h->root.type == bfd_link_hash_indirect
1849 || h->root.type == bfd_link_hash_warning)
1850 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1852 name = h->root.root.string;
1854 if ((h->root.type == bfd_link_hash_defined
1855 || h->root.type == bfd_link_hash_defweak)
1856 && ! FRV_SYM_LOCAL (info, h))
1862 if (h->root.type == bfd_link_hash_defined
1863 || h->root.type == bfd_link_hash_defweak)
1865 sec = h->root.u.def.section;
1866 relocation = (h->root.u.def.value
1867 + sec->output_section->vma
1868 + sec->output_offset);
1870 else if (h->root.type == bfd_link_hash_undefweak)
1874 else if ( ! info->executable
1876 && info->unresolved_syms_in_objects == RM_IGNORE
1877 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1881 if (! ((*info->callbacks->undefined_symbol)
1882 (info, h->root.root.string, input_bfd,
1883 input_section, rel->r_offset, TRUE)))
1897 case R_FRV_FUNCDESC_GOT12:
1898 case R_FRV_FUNCDESC_GOTHI:
1899 case R_FRV_FUNCDESC_GOTLO:
1900 case R_FRV_GOTOFF12:
1901 case R_FRV_GOTOFFHI:
1902 case R_FRV_GOTOFFLO:
1903 case R_FRV_FUNCDESC_GOTOFF12:
1904 case R_FRV_FUNCDESC_GOTOFFHI:
1905 case R_FRV_FUNCDESC_GOTOFFLO:
1906 case R_FRV_FUNCDESC:
1907 case R_FRV_FUNCDESC_VALUE:
1909 picrel = frv_pic_relocs_info_for_global (frv_relocs_info (info),
1913 /* In order to find the entry we created before, we must
1914 use the original addend, not the one that may have been
1915 modified by _bfd_elf_rela_local_sym(). */
1916 picrel = frv_pic_relocs_info_for_local (frv_relocs_info (info),
1917 input_bfd, r_symndx,
1922 if (!_frv_emit_got_relocs_plt_entries (picrel, output_bfd, info,
1923 osec, sym, rel->r_addend))
1925 info->callbacks->warning
1926 (info, _("Dynamic relocation references symbol with nonzero addend"),
1927 name, input_bfd, input_section, rel->r_offset);
1936 if (h && ! FRV_SYM_LOCAL (info, h))
1938 info->callbacks->warning
1939 (info, _("relocation references symbol not defined in the module"),
1940 name, input_bfd, input_section, rel->r_offset);
1949 check_segment[0] = isec_segment;
1952 relocation = frv_plt_section (info)->output_section->vma
1953 + frv_plt_section (info)->output_offset
1954 + picrel->plt_entry;
1955 check_segment[1] = plt_segment;
1957 /* We don't want to warn on calls to undefined weak symbols,
1958 as calls to them must be protected by non-NULL tests
1959 anyway, and unprotected calls would invoke undefined
1961 else if (picrel->symndx == -1
1962 && picrel->d.h->root.type == bfd_link_hash_undefweak)
1963 check_segment[1] = check_segment[0];
1965 check_segment[1] = sec
1966 ? _frv_osec_to_segment (output_bfd, sec->output_section)
1973 relocation = picrel->got_entry;
1974 check_segment[0] = check_segment[1] = got_segment;
1977 case R_FRV_FUNCDESC_GOT12:
1978 case R_FRV_FUNCDESC_GOTHI:
1979 case R_FRV_FUNCDESC_GOTLO:
1980 relocation = picrel->fdgot_entry;
1981 check_segment[0] = check_segment[1] = got_segment;
1984 case R_FRV_GOTOFFHI:
1985 case R_FRV_GOTOFF12:
1986 case R_FRV_GOTOFFLO:
1987 relocation -= frv_got_section (info)->output_section->vma
1988 + frv_got_section (info)->output_offset
1989 + frv_got_initial_offset (info);
1990 check_segment[0] = got_segment;
1991 check_segment[1] = sec
1992 ? _frv_osec_to_segment (output_bfd, sec->output_section)
1996 case R_FRV_FUNCDESC_GOTOFF12:
1997 case R_FRV_FUNCDESC_GOTOFFHI:
1998 case R_FRV_FUNCDESC_GOTOFFLO:
1999 relocation = picrel->fd_entry;
2000 check_segment[0] = check_segment[1] = got_segment;
2003 case R_FRV_FUNCDESC:
2006 bfd_vma addend = rel->r_addend;
2008 /* If the symbol is dynamic and there may be dynamic
2009 symbol resolution because we are or are linked with a
2010 shared library, emit a FUNCDESC relocation such that
2011 the dynamic linker will allocate the function
2013 if (h && ! FRV_FUNCDESC_LOCAL (info, h))
2017 info->callbacks->warning
2018 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
2019 name, input_bfd, input_section, rel->r_offset);
2022 dynindx = h->dynindx;
2026 /* Otherwise, we know we have a private function
2027 descriptor, so reference it directly. */
2028 BFD_ASSERT (picrel->privfd);
2030 dynindx = elf_section_data (frv_got_section
2031 (info)->output_section)->dynindx;
2032 addend = frv_got_section (info)->output_offset
2033 + frv_got_initial_offset (info)
2037 /* If there is room for dynamic symbol resolution, emit
2038 the dynamic relocation. However, if we're linking an
2039 executable at a fixed location, we won't have emitted a
2040 dynamic symbol entry for the got section, so idx will
2041 be zero, which means we can and should compute the
2042 address of the private descriptor ourselves. */
2043 if (info->executable && !info->pie
2044 && (!h || FRV_FUNCDESC_LOCAL (info, h)))
2046 addend += frv_got_section (info)->output_section->vma;
2047 if ((bfd_get_section_flags (output_bfd,
2048 input_section->output_section)
2049 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2051 if (_frv_osec_readonly_p (output_bfd,
2052 input_section->output_section))
2054 info->callbacks->warning
2056 _("cannot emit fixups in read-only section"),
2057 name, input_bfd, input_section, rel->r_offset);
2060 if (! h || h->root.type != bfd_link_hash_undefweak)
2061 _frv_add_rofixup (output_bfd,
2062 frv_gotfixup_section (info),
2063 _bfd_elf_section_offset
2065 input_section, rel->r_offset)
2066 + input_section->output_section->vma
2067 + input_section->output_offset);
2070 else if ((bfd_get_section_flags (output_bfd,
2071 input_section->output_section)
2072 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2074 if (_frv_osec_readonly_p (output_bfd,
2075 input_section->output_section))
2077 info->callbacks->warning
2079 _("cannot emit dynamic relocations in read-only section"),
2080 name, input_bfd, input_section, rel->r_offset);
2083 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
2084 _bfd_elf_section_offset
2086 input_section, rel->r_offset)
2087 + input_section->output_section->vma
2088 + input_section->output_offset,
2089 r_type, dynindx, addend);
2092 /* We want the addend in-place because dynamic
2093 relocations are REL. Setting relocation to it should
2094 arrange for it to be installed. */
2095 relocation = addend - rel->r_addend;
2097 check_segment[0] = check_segment[1] = got_segment;
2101 case R_FRV_FUNCDESC_VALUE:
2104 bfd_vma addend = rel->r_addend;
2106 /* If the symbol is dynamic but binds locally, use
2108 if (h && ! FRV_SYM_LOCAL (info, h))
2110 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
2112 info->callbacks->warning
2113 (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2114 name, input_bfd, input_section, rel->r_offset);
2117 dynindx = h->dynindx;
2122 addend += h->root.u.def.value;
2124 addend += sym->st_value;
2126 addend += osec->output_offset;
2127 if (osec && osec->output_section
2128 && ! bfd_is_abs_section (osec->output_section)
2129 && ! bfd_is_und_section (osec->output_section))
2130 dynindx = elf_section_data (osec->output_section)->dynindx;
2135 /* If we're linking an executable at a fixed address, we
2136 can omit the dynamic relocation as long as the symbol
2137 is defined in the current link unit (which is implied
2138 by its output section not being NULL). */
2139 if (info->executable && !info->pie
2140 && (!h || FRV_SYM_LOCAL (info, h)))
2143 addend += osec->output_section->vma;
2144 if ((elf_elfheader (input_bfd)->e_flags & EF_FRV_FDPIC)
2145 && (bfd_get_section_flags (output_bfd,
2146 input_section->output_section)
2147 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2149 if (_frv_osec_readonly_p (output_bfd,
2150 input_section->output_section))
2152 info->callbacks->warning
2154 _("cannot emit fixups in read-only section"),
2155 name, input_bfd, input_section, rel->r_offset);
2158 if (!h || h->root.type != bfd_link_hash_undefweak)
2160 _frv_add_rofixup (output_bfd,
2161 frv_gotfixup_section (info),
2162 _bfd_elf_section_offset
2164 input_section, rel->r_offset)
2165 + input_section->output_section->vma
2166 + input_section->output_offset);
2167 if (r_type == R_FRV_FUNCDESC_VALUE)
2170 frv_gotfixup_section (info),
2171 _bfd_elf_section_offset
2173 input_section, rel->r_offset)
2174 + input_section->output_section->vma
2175 + input_section->output_offset + 4);
2181 if ((bfd_get_section_flags (output_bfd,
2182 input_section->output_section)
2183 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2185 if (_frv_osec_readonly_p (output_bfd,
2186 input_section->output_section))
2188 info->callbacks->warning
2190 _("cannot emit dynamic relocations in read-only section"),
2191 name, input_bfd, input_section, rel->r_offset);
2194 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
2195 _bfd_elf_section_offset
2197 input_section, rel->r_offset)
2198 + input_section->output_section->vma
2199 + input_section->output_offset,
2200 r_type, dynindx, addend);
2202 /* We want the addend in-place because dynamic
2203 relocations are REL. Setting relocation to it
2204 should arrange for it to be installed. */
2205 relocation = addend - rel->r_addend;
2208 if (r_type == R_FRV_FUNCDESC_VALUE)
2210 /* If we've omitted the dynamic relocation, just emit
2211 the fixed addresses of the symbol and of the local
2213 if (info->executable && !info->pie
2214 && (!h || FRV_SYM_LOCAL (info, h)))
2215 bfd_put_32 (output_bfd,
2216 frv_got_section (info)->output_section->vma
2217 + frv_got_section (info)->output_offset
2218 + frv_got_initial_offset (info),
2219 contents + rel->r_offset + 4);
2221 /* A function descriptor used for lazy or local
2222 resolving is initialized such that its high word
2223 contains the output section index in which the
2224 PLT entries are located, and the low word
2225 contains the offset of the lazy PLT entry entry
2226 point into that section. */
2227 bfd_put_32 (output_bfd,
2228 h && ! FRV_SYM_LOCAL (info, h)
2230 : _frv_osec_to_segment (output_bfd,
2231 sec->output_section),
2232 contents + rel->r_offset + 4);
2235 check_segment[0] = check_segment[1] = got_segment;
2239 case R_FRV_GPRELU12:
2243 check_segment[0] = gprel_segment;
2244 check_segment[1] = sec
2245 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2250 check_segment[0] = isec_segment;
2251 check_segment[1] = sec
2252 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2257 if (check_segment[0] != check_segment[1]
2258 && (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC))
2261 /* This helps catch problems in GCC while we can't do more
2262 than static linking. The idea is to test whether the
2263 input file basename is crt0.o only once. */
2264 if (silence_segment_error == 1)
2265 silence_segment_error =
2266 (strlen (input_bfd->filename) == 6
2267 && strcmp (input_bfd->filename, "crt0.o") == 0)
2268 || (strlen (input_bfd->filename) > 6
2269 && strcmp (input_bfd->filename
2270 + strlen (input_bfd->filename) - 7,
2274 if (!silence_segment_error
2275 /* We don't want duplicate errors for undefined
2277 && !(picrel && picrel->symndx == -1
2278 && picrel->d.h->root.type == bfd_link_hash_undefined))
2279 info->callbacks->warning
2281 (info->shared || info->pie)
2282 ? _("relocations between different segments are not supported")
2283 : _("warning: relocation references a different segment"),
2284 name, input_bfd, input_section, rel->r_offset);
2285 if (!silence_segment_error && (info->shared || info->pie))
2287 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
2292 case R_FRV_GOTOFFHI:
2293 /* We need the addend to be applied before we shift the
2295 relocation += rel->r_addend;
2298 case R_FRV_FUNCDESC_GOTHI:
2299 case R_FRV_FUNCDESC_GOTOFFHI:
2304 case R_FRV_FUNCDESC_GOTLO:
2305 case R_FRV_GOTOFFLO:
2306 case R_FRV_FUNCDESC_GOTOFFLO:
2307 relocation &= 0xffff;
2321 /* When referencing a GOT entry, a function descriptor or a
2322 PLT, we don't want the addend to apply to the reference,
2323 but rather to the referenced symbol. The actual entry
2324 will have already been created taking the addend into
2325 account, so cancel it out here. */
2329 case R_FRV_FUNCDESC_GOT12:
2330 case R_FRV_FUNCDESC_GOTHI:
2331 case R_FRV_FUNCDESC_GOTLO:
2332 case R_FRV_FUNCDESC_GOTOFF12:
2333 case R_FRV_FUNCDESC_GOTOFFHI:
2334 case R_FRV_FUNCDESC_GOTOFFLO:
2335 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
2336 here, since we do want to apply the addend to the others.
2337 Note that we've applied the addend to GOTOFFHI before we
2338 shifted it right. */
2339 case R_FRV_GOTOFFHI:
2340 relocation -= rel->r_addend;
2347 if (r_type == R_FRV_HI16)
2348 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
2350 else if (r_type == R_FRV_LO16)
2351 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
2353 else if (r_type == R_FRV_LABEL24)
2354 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
2355 contents, relocation);
2357 else if (r_type == R_FRV_GPREL12)
2358 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
2359 contents, relocation);
2361 else if (r_type == R_FRV_GPRELU12)
2362 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
2363 contents, relocation);
2365 else if (r_type == R_FRV_GPRELLO)
2366 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
2367 contents, relocation);
2369 else if (r_type == R_FRV_GPRELHI)
2370 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
2371 contents, relocation);
2374 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
2377 if (r != bfd_reloc_ok)
2379 const char * msg = (const char *) NULL;
2383 case bfd_reloc_overflow:
2384 r = info->callbacks->reloc_overflow
2385 (info, name, howto->name, (bfd_vma) 0,
2386 input_bfd, input_section, rel->r_offset);
2389 case bfd_reloc_undefined:
2390 r = info->callbacks->undefined_symbol
2391 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
2394 case bfd_reloc_outofrange:
2395 msg = _("internal error: out of range error");
2398 case bfd_reloc_notsupported:
2399 msg = _("internal error: unsupported relocation error");
2402 case bfd_reloc_dangerous:
2403 msg = _("internal error: dangerous relocation");
2407 msg = _("internal error: unknown error");
2412 r = info->callbacks->warning
2413 (info, msg, name, input_bfd, input_section, rel->r_offset);
2423 /* Return the section that should be marked against GC for a given
2427 elf32_frv_gc_mark_hook (sec, info, rel, h, sym)
2429 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2430 Elf_Internal_Rela *rel;
2431 struct elf_link_hash_entry *h;
2432 Elf_Internal_Sym *sym;
2436 switch (ELF32_R_TYPE (rel->r_info))
2438 case R_FRV_GNU_VTINHERIT:
2439 case R_FRV_GNU_VTENTRY:
2443 switch (h->root.type)
2448 case bfd_link_hash_defined:
2449 case bfd_link_hash_defweak:
2450 return h->root.u.def.section;
2452 case bfd_link_hash_common:
2453 return h->root.u.c.p->section;
2458 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2463 /* Update the got entry reference counts for the section being removed. */
2466 elf32_frv_gc_sweep_hook (abfd, info, sec, relocs)
2467 bfd *abfd ATTRIBUTE_UNUSED;
2468 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2469 asection *sec ATTRIBUTE_UNUSED;
2470 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
2476 /* Hook called by the linker routine which adds symbols from an object
2477 file. We use it to put .comm items in .scomm, and not .comm. */
2480 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2482 struct bfd_link_info *info;
2483 const Elf_Internal_Sym *sym;
2484 const char **namep ATTRIBUTE_UNUSED;
2485 flagword *flagsp ATTRIBUTE_UNUSED;
2489 if (sym->st_shndx == SHN_COMMON
2490 && !info->relocatable
2491 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
2493 /* Common symbols less than or equal to -G nn bytes are
2494 automatically put into .sbss. */
2496 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2500 scomm = bfd_make_section (abfd, ".scommon");
2502 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2504 | SEC_LINKER_CREATED)))
2509 *valp = sym->st_size;
2514 /* Create a .got section, as well as its additional info field. This
2515 is almost entirely copied from
2516 elflink.c:_bfd_elf_create_got_section(). */
2519 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
2523 struct elf_link_hash_entry *h;
2524 struct bfd_link_hash_entry *bh;
2525 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2528 /* This function may be called more than once. */
2529 s = bfd_get_section_by_name (abfd, ".got");
2530 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
2533 /* Machine specific: although pointers are 32-bits wide, we want the
2534 GOT to be aligned to a 64-bit boundary, such that function
2535 descriptors in it can be accessed with 64-bit loads and
2539 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2540 | SEC_LINKER_CREATED);
2542 s = bfd_make_section (abfd, ".got");
2544 || !bfd_set_section_flags (abfd, s, flags)
2545 || !bfd_set_section_alignment (abfd, s, ptralign))
2548 if (bed->want_got_plt)
2550 s = bfd_make_section (abfd, ".got.plt");
2552 || !bfd_set_section_flags (abfd, s, flags)
2553 || !bfd_set_section_alignment (abfd, s, ptralign))
2557 if (bed->want_got_sym)
2559 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
2560 (or .got.plt) section. We don't do this in the linker script
2561 because we don't want to define the symbol if we are not creating
2562 a global offset table. */
2564 if (!(_bfd_generic_link_add_one_symbol
2565 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
2566 bed->got_symbol_offset, (const char *) NULL, FALSE,
2567 bed->collect, &bh)))
2569 h = (struct elf_link_hash_entry *) bh;
2570 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2571 h->type = STT_OBJECT;
2573 /* Machine-specific: we want the symbol for executables as
2575 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
2578 elf_hash_table (info)->hgot = h;
2581 /* The first bit of the global offset table is the header. */
2582 s->_raw_size += bed->got_header_size + bed->got_symbol_offset;
2584 /* This is the machine-specific part. Create and initialize section
2585 data for the got. */
2586 frv_got_section (info) = s;
2587 frv_relocs_info (info) = htab_try_create (1, frv_pic_relocs_info_hash,
2588 frv_pic_relocs_info_eq,
2590 if (! frv_relocs_info (info))
2593 s = bfd_make_section (abfd, ".rel.got");
2595 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2596 || ! bfd_set_section_alignment (abfd, s, 2))
2599 frv_gotrel_section (info) = s;
2601 /* Machine-specific. */
2602 s = bfd_make_section (abfd, ".rofixup");
2604 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2605 || ! bfd_set_section_alignment (abfd, s, 2))
2608 frv_gotfixup_section (info) = s;
2610 /* Define _gp in .rofixup, for FDPIC. If it turns out that
2611 we're linking with a different linker script, the linker script
2612 will override it. */
2614 if (!(_bfd_generic_link_add_one_symbol
2615 (info, abfd, "_gp", BSF_GLOBAL, s, -2048, (const char *) NULL, FALSE,
2616 bed->collect, &bh)))
2618 h = (struct elf_link_hash_entry *) bh;
2619 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2620 h->type = STT_OBJECT;
2622 /* Machine-specific: we want the symbol for executables as well. */
2623 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
2629 /* Make sure the got and plt sections exist, and that our pointers in
2630 the link hash table point to them. */
2633 elf32_frv_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2635 /* This is mostly copied from
2636 elflink.c:_bfd_elf_create_dynamic_sections(). */
2637 flagword flags, pltflags;
2639 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2641 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2642 .rel[a].bss sections. */
2644 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2645 | SEC_LINKER_CREATED);
2648 pltflags |= SEC_CODE;
2649 if (bed->plt_not_loaded)
2650 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
2651 if (bed->plt_readonly)
2652 pltflags |= SEC_READONLY;
2654 s = bfd_make_section (abfd, ".plt");
2656 || ! bfd_set_section_flags (abfd, s, pltflags)
2657 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2659 /* FRV-specific: remember it. */
2660 frv_plt_section (info) = s;
2662 if (bed->want_plt_sym)
2664 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2666 struct elf_link_hash_entry *h;
2667 struct bfd_link_hash_entry *bh = NULL;
2669 if (! (_bfd_generic_link_add_one_symbol
2670 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL,
2671 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2673 h = (struct elf_link_hash_entry *) bh;
2674 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2675 h->type = STT_OBJECT;
2677 if (! info->executable
2678 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2682 /* FRV-specific: we want rel relocations for the plt. */
2683 s = bfd_make_section (abfd, ".rel.plt");
2685 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2686 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2688 /* FRV-specific: remember it. */
2689 frv_pltrel_section (info) = s;
2691 /* FRV-specific: we want to create the GOT in the FRV way. */
2692 if (! _frv_create_got_section (abfd, info))
2695 /* FRV-specific: make sure we created everything we wanted. */
2696 BFD_ASSERT (frv_got_section (info) && frv_gotrel_section (info)
2697 && frv_gotfixup_section (info)
2698 && frv_plt_section (info) && frv_pltrel_section (info));
2700 if (bed->want_dynbss)
2702 /* The .dynbss section is a place to put symbols which are defined
2703 by dynamic objects, are referenced by regular objects, and are
2704 not functions. We must allocate space for them in the process
2705 image and use a R_*_COPY reloc to tell the dynamic linker to
2706 initialize them at run time. The linker script puts the .dynbss
2707 section into the .bss section of the final image. */
2708 s = bfd_make_section (abfd, ".dynbss");
2710 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
2713 /* The .rel[a].bss section holds copy relocs. This section is not
2714 normally needed. We need to create it here, though, so that the
2715 linker will map it to an output section. We can't just create it
2716 only if we need it, because we will not know whether we need it
2717 until we have seen all the input files, and the first time the
2718 main linker code calls BFD after examining all the input files
2719 (size_dynamic_sections) the input sections have already been
2720 mapped to the output sections. If the section turns out not to
2721 be needed, we can discard it later. We will never need this
2722 section when generating a shared object, since they do not use
2726 s = bfd_make_section (abfd,
2727 (bed->default_use_rela_p
2728 ? ".rela.bss" : ".rel.bss"));
2730 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2731 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2739 /* The name of the dynamic interpreter. This is put in the .interp
2742 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2744 #define DEFAULT_STACK_SIZE 0x20000
2746 /* This structure is used to collect the number of entries present in
2747 each addressable range of the got. */
2748 struct _frv_dynamic_got_info
2750 /* Several bits of information about the current link. */
2751 struct bfd_link_info *info;
2752 /* Total size needed for GOT entries within the 12-, 16- or 32-bit
2754 bfd_vma got12, gotlos, gothilo;
2755 /* Total size needed for function descriptor entries within the 12-,
2756 16- or 32-bit ranges. */
2757 bfd_vma fd12, fdlos, fdhilo;
2758 /* Total size needed function descriptor entries referenced in PLT
2759 entries, that would be profitable to place in offsets close to
2760 the PIC register. */
2762 /* Total size needed by lazy PLT entries. */
2764 /* Number of relocations carried over from input object files. */
2765 unsigned long relocs;
2766 /* Number of fixups introduced by relocations in input object files. */
2767 unsigned long fixups;
2770 /* Compute the total GOT size required by each symbol in each range.
2771 Symbols may require up to 4 words in the GOT: an entry pointing to
2772 the symbol, an entry pointing to its function descriptor, and a
2773 private function descriptors taking two words. */
2776 _frv_count_got_plt_entries (void **entryp, void *dinfo_)
2778 struct frv_pic_relocs_info *entry = *entryp;
2779 struct _frv_dynamic_got_info *dinfo = dinfo_;
2781 /* Allocate space for a GOT entry pointing to the symbol. */
2784 else if (entry->gotlos)
2786 else if (entry->gothilo)
2787 dinfo->gothilo += 4;
2792 /* Allocate space for a GOT entry pointing to the function
2796 else if (entry->fdgotlos)
2798 else if (entry->fdgothilo)
2799 dinfo->gothilo += 4;
2804 /* Decide whether we need a PLT entry, a function descriptor in the
2805 GOT, and a lazy PLT entry for this symbol. */
2806 entry->plt = entry->call
2807 && entry->symndx == -1 && ! FRV_SYM_LOCAL (dinfo->info, entry->d.h)
2808 && elf_hash_table (dinfo->info)->dynamic_sections_created;
2809 entry->privfd = entry->plt
2810 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
2811 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
2812 && (entry->symndx != -1
2813 || FRV_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
2814 entry->lazyplt = entry->privfd
2815 && entry->symndx == -1 && ! FRV_SYM_LOCAL (dinfo->info, entry->d.h)
2816 && ! (dinfo->info->flags & DF_BIND_NOW)
2817 && elf_hash_table (dinfo->info)->dynamic_sections_created;
2819 /* Allocate space for a function descriptor. */
2820 if (entry->fdgoff12)
2822 else if (entry->fdgofflos)
2824 else if (entry->privfd && entry->plt)
2826 else if (entry->privfd)
2835 if (!dinfo->info->executable || dinfo->info->pie)
2836 dinfo->relocs += entry->relocs32 + entry->relocsfd + entry->relocsfdv;
2839 if (entry->symndx != -1 || FRV_SYM_LOCAL (dinfo->info, entry->d.h))
2841 if (entry->symndx != -1
2842 || entry->d.h->root.type != bfd_link_hash_undefweak)
2843 dinfo->fixups += entry->relocs32 + 2 * entry->relocsfdv;
2846 dinfo->relocs += entry->relocs32 + entry->relocsfdv;
2847 if (entry->symndx != -1 || FRV_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
2849 if (entry->symndx != -1
2850 || entry->d.h->root.type != bfd_link_hash_undefweak)
2851 dinfo->fixups += entry->relocsfd;
2854 dinfo->relocs += entry->relocsfd;
2860 /* This structure is used to assign offsets to got entries, function
2861 descriptors, plt entries and lazy plt entries. */
2863 struct _frv_dynamic_got_plt_info
2865 /* Summary information collected with _frv_count_got_plt_entries. */
2866 struct _frv_dynamic_got_info g;
2868 /* For each addressable range, we record a MAX (positive) and MIN
2869 (negative) value. CUR is used to assign got entries, and it's
2870 incremented from an initial positive value to MAX, then from MIN
2871 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
2872 assign function descriptors, and it's decreased from an initial
2873 non-positive value to MIN, then from MAX down to CUR (unless CUR
2874 wraps around first). All of MIN, MAX, CUR and FDCUR always point
2875 to even words. ODD, if non-zero, indicates an odd word to be
2876 used for the next got entry, otherwise CUR is used and
2877 incremented by a pair of words, wrapping around when it reaches
2878 MAX. FDCUR is decremented (and wrapped) before the next function
2879 descriptor is chosen. FDPLT indicates the number of remaining
2880 slots that can be used for function descriptors used only by PLT
2882 struct _frv_dynamic_got_alloc_data
2884 bfd_signed_vma max, cur, odd, fdcur, min;
2886 } got12, gotlos, gothilo;
2889 /* Determine the positive and negative ranges to be used by each
2890 offset range in the GOT. FDCUR and CUR, that must be aligned to a
2891 double-word boundary, are the minimum (negative) and maximum
2892 (positive) GOT offsets already used by previous ranges, except for
2893 an ODD entry that may have been left behind. GOT and FD indicate
2894 the size of GOT entries and function descriptors that must be
2895 placed within the range from -WRAP to WRAP. If there's room left,
2896 up to FDPLT bytes should be reserved for additional function
2899 inline static bfd_signed_vma
2900 _frv_compute_got_alloc_data (struct _frv_dynamic_got_alloc_data *gad,
2901 bfd_signed_vma fdcur,
2909 bfd_signed_vma wrapmin = -wrap;
2911 /* Start at the given initial points. */
2915 /* If we had an incoming odd word and we have any got entries that
2916 are going to use it, consume it, otherwise leave gad->odd at
2917 zero. We might force gad->odd to zero and return the incoming
2918 odd such that it is used by the next range, but then GOT entries
2919 might appear to be out of order and we wouldn't be able to
2920 shorten the GOT by one word if it turns out to end with an
2921 unpaired GOT entry. */
2931 /* If we're left with an unpaired GOT entry, compute its location
2932 such that we can return it. Otherwise, if got doesn't require an
2933 odd number of words here, either odd was already zero in the
2934 block above, or it was set to zero because got was non-zero, or
2935 got was already zero. In the latter case, we want the value of
2936 odd to carry over to the return statement, so we don't want to
2937 reset odd unless the condition below is true. */
2944 /* Compute the tentative boundaries of this range. */
2945 gad->max = cur + got;
2946 gad->min = fdcur - fd;
2949 /* If function descriptors took too much space, wrap some of them
2951 if (gad->min < wrapmin)
2953 gad->max += wrapmin - gad->min;
2956 /* If there is space left and we have function descriptors
2957 referenced in PLT entries that could take advantage of shorter
2958 offsets, place them here. */
2959 else if (fdplt && gad->min > wrapmin)
2962 if ((bfd_vma) (gad->min - wrapmin) < fdplt)
2963 fds = gad->min - wrapmin;
2972 /* If GOT entries took too much space, wrap some of them around.
2973 This may well cause gad->min to become lower than wrapmin. This
2974 will cause a relocation overflow later on, so we don't have to
2976 if ((bfd_vma) gad->max > wrap)
2978 gad->min -= gad->max - wrap;
2981 /* If there is more space left, try to place some more function
2982 descriptors for PLT entries. */
2983 else if (fdplt && (bfd_vma) gad->max < wrap)
2986 if ((bfd_vma) (wrap - gad->max) < fdplt)
2987 fds = wrap - gad->max;
2996 /* If odd was initially computed as an offset past the wrap point,
2999 odd = gad->min + odd - gad->max;
3001 /* _frv_get_got_entry() below will always wrap gad->cur if needed
3002 before returning, so do it here too. This guarantees that,
3003 should cur and fdcur meet at the wrap point, they'll both be
3005 if (gad->cur == gad->max)
3006 gad->cur = gad->min;
3011 /* Compute the location of the next GOT entry, given the allocation
3012 data for a range. */
3014 inline static bfd_signed_vma
3015 _frv_get_got_entry (struct _frv_dynamic_got_alloc_data *gad)
3021 /* If there was an odd word left behind, use it. */
3027 /* Otherwise, use the word pointed to by cur, reserve the next
3028 as an odd word, and skip to the next pair of words, possibly
3031 gad->odd = gad->cur + 4;
3033 if (gad->cur == gad->max)
3034 gad->cur = gad->min;
3040 /* Compute the location of the next function descriptor entry in the
3041 GOT, given the allocation data for a range. */
3043 inline static bfd_signed_vma
3044 _frv_get_fd_entry (struct _frv_dynamic_got_alloc_data *gad)
3046 /* If we're at the bottom, wrap around, and only then allocate the
3047 next pair of words. */
3048 if (gad->fdcur == gad->min)
3049 gad->fdcur = gad->max;
3050 return gad->fdcur -= 8;
3053 /* Assign GOT offsets for every GOT entry and function descriptor.
3054 Doing everything in a single pass is tricky. */
3057 _frv_assign_got_entries (void **entryp, void *info_)
3059 struct frv_pic_relocs_info *entry = *entryp;
3060 struct _frv_dynamic_got_plt_info *dinfo = info_;
3063 entry->got_entry = _frv_get_got_entry (&dinfo->got12);
3064 else if (entry->gotlos)
3065 entry->got_entry = _frv_get_got_entry (&dinfo->gotlos);
3066 else if (entry->gothilo)
3067 entry->got_entry = _frv_get_got_entry (&dinfo->gothilo);
3070 entry->fdgot_entry = _frv_get_got_entry (&dinfo->got12);
3071 else if (entry->fdgotlos)
3072 entry->fdgot_entry = _frv_get_got_entry (&dinfo->gotlos);
3073 else if (entry->fdgothilo)
3074 entry->fdgot_entry = _frv_get_got_entry (&dinfo->gothilo);
3076 if (entry->fdgoff12)
3077 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3078 else if (entry->plt && dinfo->got12.fdplt)
3080 dinfo->got12.fdplt -= 8;
3081 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3083 else if (entry->fdgofflos)
3084 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3085 else if (entry->plt && dinfo->gotlos.fdplt)
3087 dinfo->gotlos.fdplt -= 8;
3088 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3090 else if (entry->plt)
3092 dinfo->gothilo.fdplt -= 8;
3093 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3095 else if (entry->privfd)
3096 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3101 /* Assign GOT offsets to private function descriptors used by PLT
3102 entries (or referenced by 32-bit offsets), as well as PLT entries
3103 and lazy PLT entries. */
3106 _frv_assign_plt_entries (void **entryp, void *info_)
3108 struct frv_pic_relocs_info *entry = *entryp;
3109 struct _frv_dynamic_got_plt_info *dinfo = info_;
3111 /* If this symbol requires a local function descriptor, allocate
3113 if (entry->privfd && entry->fd_entry == 0)
3115 if (dinfo->got12.fdplt)
3117 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3118 dinfo->got12.fdplt -= 8;
3120 else if (dinfo->gotlos.fdplt)
3122 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3123 dinfo->gotlos.fdplt -= 8;
3127 BFD_ASSERT (dinfo->gothilo.fdplt)
3128 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3129 dinfo->gothilo.fdplt -= 8;
3137 /* We use the section's raw size to mark the location of the
3139 entry->plt_entry = frv_plt_section (dinfo->g.info)->_raw_size;
3141 /* Figure out the length of this PLT entry based on the
3142 addressing mode we need to reach the function descriptor. */
3143 BFD_ASSERT (entry->fd_entry);
3144 if (entry->fd_entry >= -(1 << (12 - 1))
3145 && entry->fd_entry < (1 << (12 - 1)))
3147 else if (entry->fd_entry >= -(1 << (16 - 1))
3148 && entry->fd_entry < (1 << (16 - 1)))
3153 frv_plt_section (dinfo->g.info)->_raw_size += size;
3158 entry->lzplt_entry = dinfo->g.lzplt;
3159 dinfo->g.lzplt += 8;
3160 /* If this entry is the one that gets the resolver stub, account
3161 for the additional instruction. */
3162 if (entry->lzplt_entry % FRV_LZPLT_BLOCK_SIZE == FRV_LZPLT_RESOLV_LOC)
3163 dinfo->g.lzplt += 4;
3169 /* Follow indirect and warning hash entries so that each got entry
3170 points to the final symbol definition. P must point to a pointer
3171 to the hash table we're traversing. Since this traversal may
3172 modify the hash table, we set this pointer to NULL to indicate
3173 we've made a potentially-destructive change to the hash table, so
3174 the traversal must be restarted. */
3176 _frv_resolve_final_relocs_info (void **entryp, void *p)
3178 struct frv_pic_relocs_info *entry = *entryp;
3181 if (entry->symndx == -1)
3183 struct elf_link_hash_entry *h = entry->d.h;
3185 while (h->root.type == bfd_link_hash_indirect
3186 || h->root.type == bfd_link_hash_warning)
3187 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3189 if (entry->d.h == h)
3194 /* If we can't find this entry with the new bfd hash, re-insert
3195 it, and get the traversal restarted. */
3196 if (! htab_find (*htab, entry))
3198 htab_clear_slot (*htab, entryp);
3199 entryp = htab_find_slot (*htab, entry, INSERT);
3202 /* Abort the traversal, since the whole table may have
3203 moved, and leave it up to the parent to restart the
3205 *(htab_t *)p = NULL;
3213 /* Set the sizes of the dynamic sections. */
3216 elf32_frv_size_dynamic_sections (bfd *output_bfd,
3217 struct bfd_link_info *info)
3221 struct _frv_dynamic_got_plt_info gpinfo;
3225 dynobj = elf_hash_table (info)->dynobj;
3226 BFD_ASSERT (dynobj != NULL);
3228 if (elf_hash_table (info)->dynamic_sections_created)
3230 /* Set the contents of the .interp section to the interpreter. */
3231 if (info->executable)
3233 s = bfd_get_section_by_name (dynobj, ".interp");
3234 BFD_ASSERT (s != NULL);
3235 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3236 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3240 memset (&gpinfo, 0, sizeof (gpinfo));
3241 gpinfo.g.info = info;
3245 htab_t relocs = frv_relocs_info (info);
3247 htab_traverse (relocs, _frv_resolve_final_relocs_info, &relocs);
3249 if (relocs == frv_relocs_info (info))
3253 htab_traverse (frv_relocs_info (info), _frv_count_got_plt_entries,
3257 /* Compute the total size taken by entries in the 12-bit and 16-bit
3258 ranges, to tell how many PLT function descriptors we can bring
3259 into the 12-bit range without causing the 16-bit range to
3261 limit = odd + gpinfo.g.got12 + gpinfo.g.gotlos
3262 + gpinfo.g.fd12 + gpinfo.g.fdlos;
3263 if (limit < (bfd_vma)1 << 16)
3264 limit = ((bfd_vma)1 << 16) - limit;
3267 if (gpinfo.g.fdplt < limit)
3268 limit = gpinfo.g.fdplt;
3270 /* Determine the ranges of GOT offsets that we can use for each
3271 range of addressing modes. */
3272 odd = _frv_compute_got_alloc_data (&gpinfo.got12,
3279 (bfd_vma)1 << (12-1));
3280 odd = _frv_compute_got_alloc_data (&gpinfo.gotlos,
3286 gpinfo.g.fdplt - gpinfo.got12.fdplt,
3287 (bfd_vma)1 << (16-1));
3288 odd = _frv_compute_got_alloc_data (&gpinfo.gothilo,
3294 gpinfo.g.fdplt - gpinfo.got12.fdplt
3295 - gpinfo.gotlos.fdplt,
3296 (bfd_vma)1 << (32-1));
3298 /* Now assign (most) GOT offsets. */
3299 htab_traverse (frv_relocs_info (info), _frv_assign_got_entries, &gpinfo);
3301 frv_got_section (info)->_raw_size = gpinfo.gothilo.max - gpinfo.gothilo.min
3302 /* If an odd word is the last word of the GOT, we don't need this
3303 word to be part of the GOT. */
3304 - (odd + 4 == gpinfo.gothilo.max ? 4 : 0);
3305 if (frv_got_section (info)->_raw_size == 0)
3306 frv_got_section (info)->flags |= SEC_EXCLUDE;
3307 else if (frv_got_section (info)->_raw_size == 12
3308 && ! elf_hash_table (info)->dynamic_sections_created)
3310 frv_got_section (info)->flags |= SEC_EXCLUDE;
3311 frv_got_section (info)->_raw_size = 0;
3315 frv_got_section (info)->contents =
3316 (bfd_byte *) bfd_zalloc (dynobj, frv_got_section (info)->_raw_size);
3317 if (frv_got_section (info)->contents == NULL)
3321 if (elf_hash_table (info)->dynamic_sections_created)
3322 /* Subtract the number of lzplt entries, since those will generate
3323 relocations in the pltrel section. */
3324 frv_gotrel_section (info)->_raw_size =
3325 (gpinfo.g.relocs - gpinfo.g.lzplt / 8)
3326 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3328 BFD_ASSERT (gpinfo.g.relocs == 0);
3329 if (frv_gotrel_section (info)->_raw_size == 0)
3330 frv_gotrel_section (info)->flags |= SEC_EXCLUDE;
3333 frv_gotrel_section (info)->contents =
3334 (bfd_byte *) bfd_zalloc (dynobj, frv_gotrel_section (info)->_raw_size);
3335 if (frv_gotrel_section (info)->contents == NULL)
3339 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3340 frv_gotfixup_section (info)->_raw_size = (gpinfo.g.fixups + 1) * 4;
3341 if (frv_gotfixup_section (info)->_raw_size == 0)
3342 frv_gotfixup_section (info)->flags |= SEC_EXCLUDE;
3345 frv_gotfixup_section (info)->contents =
3346 (bfd_byte *) bfd_zalloc (dynobj,
3347 frv_gotfixup_section (info)->_raw_size);
3348 if (frv_gotfixup_section (info)->contents == NULL)
3352 if (elf_hash_table (info)->dynamic_sections_created)
3354 frv_pltrel_section (info)->_raw_size =
3355 gpinfo.g.lzplt / 8 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3356 if (frv_pltrel_section (info)->_raw_size == 0)
3357 frv_pltrel_section (info)->flags |= SEC_EXCLUDE;
3360 frv_pltrel_section (info)->contents =
3361 (bfd_byte *) bfd_zalloc (dynobj,
3362 frv_pltrel_section (info)->_raw_size);
3363 if (frv_pltrel_section (info)->contents == NULL)
3368 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3369 such that there's room for the additional instruction needed to
3370 call the resolver. Since _frv_assign_got_entries didn't account
3371 for them, our block size is 4 bytes smaller than the real block
3373 if (elf_hash_table (info)->dynamic_sections_created)
3375 frv_plt_section (info)->_raw_size = gpinfo.g.lzplt
3376 + ((gpinfo.g.lzplt + (FRV_LZPLT_BLOCK_SIZE - 4) - 8)
3377 / (FRV_LZPLT_BLOCK_SIZE - 4) * 4);
3380 /* Reset it, such that _frv_assign_plt_entries() can use it to
3381 actually assign lazy PLT entries addresses. */
3384 /* Save information that we're going to need to generate GOT and PLT
3386 frv_got_initial_offset (info) = -gpinfo.gothilo.min;
3388 if (get_elf_backend_data (output_bfd)->want_got_sym)
3389 elf_hash_table (info)->hgot->root.u.def.value
3390 += frv_got_initial_offset (info);
3392 if (elf_hash_table (info)->dynamic_sections_created)
3393 frv_plt_initial_offset (info) = frv_plt_section (info)->_raw_size;
3395 htab_traverse (frv_relocs_info (info), _frv_assign_plt_entries, &gpinfo);
3397 /* Allocate the PLT section contents only after
3398 _frv_assign_plt_entries has a chance to add the size of the
3399 non-lazy PLT entries. */
3400 if (elf_hash_table (info)->dynamic_sections_created)
3402 if (frv_plt_section (info)->_raw_size == 0)
3403 frv_plt_section (info)->flags |= SEC_EXCLUDE;
3406 frv_plt_section (info)->contents =
3407 (bfd_byte *) bfd_zalloc (dynobj, frv_plt_section (info)->_raw_size);
3408 if (frv_plt_section (info)->contents == NULL)
3413 if (elf_hash_table (info)->dynamic_sections_created)
3415 if (frv_got_section (info)->_raw_size)
3416 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
3419 if (frv_pltrel_section (info)->_raw_size)
3420 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3421 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_REL)
3422 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
3425 if (frv_gotrel_section (info)->_raw_size)
3426 if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0)
3427 || ! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0)
3428 || ! bfd_elf32_add_dynamic_entry (info, DT_RELENT,
3429 sizeof (Elf32_External_Rel)))
3437 elf32_frv_always_size_sections (bfd *output_bfd,
3438 struct bfd_link_info *info)
3440 if (!info->relocatable
3441 && elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3443 struct elf_link_hash_entry *h;
3446 /* Force a PT_GNU_STACK segment to be created. */
3447 if (! elf_tdata (output_bfd)->stack_flags)
3448 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
3450 /* Define __stacksize if it's not defined yet. */
3451 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3452 FALSE, FALSE, FALSE);
3453 if (! h || h->root.type != bfd_link_hash_defined
3454 || h->type != STT_OBJECT
3455 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
3457 struct bfd_link_hash_entry *bh;
3459 if (!(_bfd_generic_link_add_one_symbol
3460 (info, output_bfd, "__stacksize",
3461 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
3462 (const char *) NULL, FALSE,
3463 get_elf_backend_data (output_bfd)->collect, &bh)))
3466 h = (struct elf_link_hash_entry *) bh;
3467 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3468 h->type = STT_OBJECT;
3471 /* Create a stack section, and set its alignment. */
3472 sec = bfd_make_section (output_bfd, ".stack");
3475 || ! bfd_set_section_alignment (output_bfd, sec, 3))
3483 elf32_frv_modify_segment_map (bfd *output_bfd,
3484 struct bfd_link_info *info)
3486 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3488 struct elf_segment_map *m;
3490 for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next)
3491 if (m->p_type == PT_GNU_STACK)
3496 asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
3497 struct elf_link_hash_entry *h;
3501 /* Obtain the pointer to the __stacksize symbol. */
3502 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3503 FALSE, FALSE, FALSE);
3504 while (h->root.type == bfd_link_hash_indirect
3505 || h->root.type == bfd_link_hash_warning)
3506 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3507 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
3509 /* Set the section size from the symbol value. We
3510 intentionally ignore the symbol section. */
3511 if (h->root.type == bfd_link_hash_defined)
3512 sec->_raw_size = h->root.u.def.value;
3514 sec->_raw_size = DEFAULT_STACK_SIZE;
3516 /* Add the stack section to the PT_GNU_STACK segment,
3517 such that its size and alignment requirements make it
3519 m->sections[m->count] = sec;
3528 /* Fill in code and data in dynamic sections. */
3531 elf32_frv_finish_dynamic_sections (bfd *output_bfd,
3532 struct bfd_link_info *info)
3537 dynobj = elf_hash_table (info)->dynobj;
3539 if (frv_got_section (info))
3541 BFD_ASSERT (frv_gotrel_section (info)->_raw_size
3542 == (frv_gotrel_section (info)->reloc_count
3543 * sizeof (Elf32_External_Rel)));
3545 if (frv_gotfixup_section (info))
3547 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3549 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
3550 bfd_vma got_value = hgot->root.u.def.value
3551 + hgot->root.u.def.section->output_section->vma
3552 + hgot->root.u.def.section->output_offset;
3554 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
3558 if (frv_gotfixup_section (info)->_raw_size
3559 != (frv_gotfixup_section (info)->reloc_count * 4))
3561 if (!elf_hash_table (info)->dynamic_sections_created)
3563 info->callbacks->warning
3564 (info, "no dynamic sections, missing -melf32frvfd?",
3565 ".rofixup", NULL, NULL, 0);
3572 if (elf_hash_table (info)->dynamic_sections_created)
3574 BFD_ASSERT (frv_pltrel_section (info)->_raw_size
3575 == (frv_pltrel_section (info)->reloc_count
3576 * sizeof (Elf32_External_Rel)));
3579 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3581 if (elf_hash_table (info)->dynamic_sections_created)
3583 Elf32_External_Dyn * dyncon;
3584 Elf32_External_Dyn * dynconend;
3586 BFD_ASSERT (sdyn != NULL);
3588 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3589 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3591 for (; dyncon < dynconend; dyncon++)
3593 Elf_Internal_Dyn dyn;
3595 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3603 dyn.d_un.d_ptr = frv_got_section (info)->output_section->vma
3604 + frv_got_section (info)->output_offset
3605 + frv_got_initial_offset (info);
3606 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3610 dyn.d_un.d_ptr = frv_pltrel_section (info)->output_section->vma
3611 + frv_pltrel_section (info)->output_offset;
3612 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3616 if (frv_pltrel_section (info)->_cooked_size != 0)
3617 dyn.d_un.d_val = frv_pltrel_section (info)->_cooked_size;
3619 dyn.d_un.d_val = frv_pltrel_section (info)->_raw_size;
3620 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3629 /* Adjust a symbol defined by a dynamic object and referenced by a
3633 elf32_frv_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3634 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3638 dynobj = elf_hash_table (info)->dynobj;
3640 /* Make sure we know what is going on here. */
3641 BFD_ASSERT (dynobj != NULL
3642 && (h->weakdef != NULL
3643 || ((h->elf_link_hash_flags
3644 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3645 && (h->elf_link_hash_flags
3646 & ELF_LINK_HASH_REF_REGULAR) != 0
3647 && (h->elf_link_hash_flags
3648 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3650 /* If this is a weak symbol, and there is a real definition, the
3651 processor independent code will have arranged for us to see the
3652 real definition first, and we can just use the same value. */
3653 if (h->weakdef != NULL)
3655 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3656 || h->weakdef->root.type == bfd_link_hash_defweak);
3657 h->root.u.def.section = h->weakdef->root.u.def.section;
3658 h->root.u.def.value = h->weakdef->root.u.def.value;
3664 /* Perform any actions needed for dynamic symbols. */
3667 elf32_frv_finish_dynamic_symbol (bfd *output_bfd ATTRIBUTE_UNUSED,
3668 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3669 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
3670 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
3675 /* Look through the relocs for a section during the first phase.
3677 Besides handling virtual table relocs for gc, we have to deal with
3678 all sorts of PIC-related relocations. We describe below the
3679 general plan on how to handle such relocations, even though we only
3680 collect information at this point, storing them in hash tables for
3681 perusal of later passes.
3683 32 relocations are propagated to the linker output when creating
3684 position-independent output. LO16 and HI16 relocations are not
3685 supposed to be encountered in this case.
3687 LABEL16 should always be resolvable by the linker, since it's only
3690 LABEL24, on the other hand, is used by calls. If it turns out that
3691 the target of a call is a dynamic symbol, a PLT entry must be
3692 created for it, which triggers the creation of a private function
3693 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
3695 GPREL relocations require the referenced symbol to be in the same
3696 segment as _gp, but this can only be checked later.
3698 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
3699 exist. LABEL24 might as well, since it may require a PLT entry,
3700 that will require a got.
3702 Non-FUNCDESC GOT relocations require a GOT entry to be created
3703 regardless of whether the symbol is dynamic. However, since a
3704 global symbol that turns out to not be exported may have the same
3705 address of a non-dynamic symbol, we don't assign GOT entries at
3706 this point, such that we can share them in this case. A relocation
3707 for the GOT entry always has to be created, be it to offset a
3708 private symbol by the section load address, be it to get the symbol
3709 resolved dynamically.
3711 FUNCDESC GOT relocations require a GOT entry to be created, and
3712 handled as if a FUNCDESC relocation was applied to the GOT entry in
3715 FUNCDESC relocations referencing a symbol that turns out to NOT be
3716 dynamic cause a private function descriptor to be created. The
3717 FUNCDESC relocation then decays to a 32 relocation that points at
3718 the private descriptor. If the symbol is dynamic, the FUNCDESC
3719 relocation is propagated to the linker output, such that the
3720 dynamic linker creates the canonical descriptor, pointing to the
3721 dynamically-resolved definition of the function.
3723 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
3724 symbols that are assigned to the same segment as the GOT, but we
3725 can only check this later, after we know the complete set of
3726 symbols defined and/or exported.
3728 FUNCDESC GOTOFF relocations require a function descriptor to be
3729 created and, unless lazy binding is disabled or the symbol is not
3730 dynamic, a lazy PLT entry. Since we can't tell at this point
3731 whether a symbol is going to be dynamic, we have to decide later
3732 whether to create a lazy PLT entry or bind the descriptor directly
3733 to the private function.
3735 FUNCDESC_VALUE relocations are not supposed to be present in object
3736 files, but they may very well be simply propagated to the linker
3737 output, since they have no side effect.
3740 A function descriptor always requires a FUNCDESC_VALUE relocation.
3741 Whether it's in .plt.rel or not depends on whether lazy binding is
3742 enabled and on whether the referenced symbol is dynamic.
3744 The existence of a lazy PLT requires the resolverStub lazy PLT
3745 entry to be present.
3748 As for assignment of GOT, PLT and lazy PLT entries, and private
3749 descriptors, we might do them all sequentially, but we can do
3750 better than that. For example, we can place GOT entries and
3751 private function descriptors referenced using 12-bit operands
3752 closer to the PIC register value, such that these relocations don't
3753 overflow. Those that are only referenced with LO16 relocations
3754 could come next, but we may as well place PLT-required function
3755 descriptors in the 12-bit range to make them shorter. Symbols
3756 referenced with LO16/HI16 may come next, but we may place
3757 additional function descriptors in the 16-bit range if we can
3758 reliably tell that we've already placed entries that are ever
3759 referenced with only LO16. PLT entries are therefore generated as
3760 small as possible, while not introducing relocation overflows in
3761 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
3762 generated before or after PLT entries, but not intermingled with
3763 them, such that we can have more lazy PLT entries in range for a
3764 branch to the resolverStub. The resolverStub should be emitted at
3765 the most distant location from the first lazy PLT entry such that
3766 it's still in range for a branch, or closer, if there isn't a need
3767 for so many lazy PLT entries. Additional lazy PLT entries may be
3768 emitted after the resolverStub, as long as branches are still in
3769 range. If the branch goes out of range, longer lazy PLT entries
3772 We could further optimize PLT and lazy PLT entries by giving them
3773 priority in assignment to closer-to-gr17 locations depending on the
3774 number of occurrences of references to them (assuming a function
3775 that's called more often is more important for performance, so its
3776 PLT entry should be faster), or taking hints from the compiler.
3777 Given infinite time and money... :-) */
3780 elf32_frv_check_relocs (abfd, info, sec, relocs)
3782 struct bfd_link_info *info;
3784 const Elf_Internal_Rela *relocs;
3786 Elf_Internal_Shdr *symtab_hdr;
3787 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
3788 const Elf_Internal_Rela *rel;
3789 const Elf_Internal_Rela *rel_end;
3791 struct frv_pic_relocs_info *picrel;
3793 if (info->relocatable)
3796 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3797 sym_hashes = elf_sym_hashes (abfd);
3798 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
3799 if (!elf_bad_symtab (abfd))
3800 sym_hashes_end -= symtab_hdr->sh_info;
3802 dynobj = elf_hash_table (info)->dynobj;
3803 rel_end = relocs + sec->reloc_count;
3804 for (rel = relocs; rel < rel_end; rel++)
3806 struct elf_link_hash_entry *h;
3807 unsigned long r_symndx;
3809 r_symndx = ELF32_R_SYM (rel->r_info);
3810 if (r_symndx < symtab_hdr->sh_info)
3813 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3815 switch (ELF32_R_TYPE (rel->r_info))
3822 case R_FRV_FUNCDESC_GOT12:
3823 case R_FRV_FUNCDESC_GOTHI:
3824 case R_FRV_FUNCDESC_GOTLO:
3825 case R_FRV_GOTOFF12:
3826 case R_FRV_GOTOFFHI:
3827 case R_FRV_GOTOFFLO:
3828 case R_FRV_FUNCDESC_GOTOFF12:
3829 case R_FRV_FUNCDESC_GOTOFFHI:
3830 case R_FRV_FUNCDESC_GOTOFFLO:
3831 case R_FRV_FUNCDESC:
3832 case R_FRV_FUNCDESC_VALUE:
3835 elf_hash_table (info)->dynobj = dynobj = abfd;
3836 if (! _frv_create_got_section (abfd, info))
3841 if (h->dynindx == -1)
3842 switch (ELF_ST_VISIBILITY (h->other))
3848 bfd_elf32_link_record_dynamic_symbol (info, h);
3852 = frv_pic_relocs_info_for_global (frv_relocs_info (info),
3857 picrel = frv_pic_relocs_info_for_local (frv_relocs_info (info),
3869 switch (ELF32_R_TYPE (rel->r_info))
3875 case R_FRV_FUNCDESC_VALUE:
3876 picrel->relocsfdv++;
3877 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
3882 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
3892 picrel->gothilo = 1;
3895 case R_FRV_FUNCDESC_GOT12:
3896 picrel->fdgot12 = 1;
3899 case R_FRV_FUNCDESC_GOTHI:
3900 case R_FRV_FUNCDESC_GOTLO:
3901 picrel->fdgothilo = 1;
3904 case R_FRV_GOTOFF12:
3905 case R_FRV_GOTOFFHI:
3906 case R_FRV_GOTOFFLO:
3910 case R_FRV_FUNCDESC_GOTOFF12:
3911 picrel->fdgoff12 = 1;
3914 case R_FRV_FUNCDESC_GOTOFFHI:
3915 case R_FRV_FUNCDESC_GOTOFFLO:
3916 picrel->fdgoffhilo = 1;
3919 case R_FRV_FUNCDESC:
3924 /* This relocation describes the C++ object vtable hierarchy.
3925 Reconstruct it for later use during GC. */
3926 case R_FRV_GNU_VTINHERIT:
3927 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3931 /* This relocation describes which C++ vtable entries are actually
3932 used. Record for later use during GC. */
3933 case R_FRV_GNU_VTENTRY:
3934 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3944 /* Return the machine subcode from the ELF e_flags header. */
3947 elf32_frv_machine (abfd)
3950 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
3953 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
3954 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
3955 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
3956 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
3957 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
3958 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
3961 return bfd_mach_frv;
3964 /* Set the right machine number for a FRV ELF file. */
3967 elf32_frv_object_p (abfd)
3970 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
3974 /* Function to set the ELF flag bits. */
3977 frv_elf_set_private_flags (abfd, flags)
3981 elf_elfheader (abfd)->e_flags = flags;
3982 elf_flags_init (abfd) = TRUE;
3986 /* Copy backend specific data from one object module to another. */
3989 frv_elf_copy_private_bfd_data (ibfd, obfd)
3993 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3994 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3997 BFD_ASSERT (!elf_flags_init (obfd)
3998 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
4000 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
4001 elf_flags_init (obfd) = TRUE;
4005 /* Merge backend specific data from an object file to the output
4006 object file when linking. */
4009 frv_elf_merge_private_bfd_data (ibfd, obfd)
4013 flagword old_flags, old_partial;
4014 flagword new_flags, new_partial;
4015 bfd_boolean error = FALSE;
4019 new_opt[0] = old_opt[0] = '\0';
4020 new_flags = elf_elfheader (ibfd)->e_flags;
4021 old_flags = elf_elfheader (obfd)->e_flags;
4023 if (new_flags & EF_FRV_FDPIC)
4024 new_flags &= ~EF_FRV_PIC;
4027 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
4028 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
4029 bfd_get_filename (ibfd));
4032 if (!elf_flags_init (obfd)) /* First call, no flags set. */
4034 elf_flags_init (obfd) = TRUE;
4035 old_flags = new_flags;
4038 else if (new_flags == old_flags) /* Compatible flags are ok. */
4041 else /* Possibly incompatible flags. */
4043 /* Warn if different # of gprs are used. Note, 0 means nothing is
4044 said about the size of gprs. */
4045 new_partial = (new_flags & EF_FRV_GPR_MASK);
4046 old_partial = (old_flags & EF_FRV_GPR_MASK);
4047 if (new_partial == old_partial)
4050 else if (new_partial == 0)
4053 else if (old_partial == 0)
4054 old_flags |= new_partial;
4058 switch (new_partial)
4060 default: strcat (new_opt, " -mgpr-??"); break;
4061 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
4062 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
4065 switch (old_partial)
4067 default: strcat (old_opt, " -mgpr-??"); break;
4068 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
4069 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
4073 /* Warn if different # of fprs are used. Note, 0 means nothing is
4074 said about the size of fprs. */
4075 new_partial = (new_flags & EF_FRV_FPR_MASK);
4076 old_partial = (old_flags & EF_FRV_FPR_MASK);
4077 if (new_partial == old_partial)
4080 else if (new_partial == 0)
4083 else if (old_partial == 0)
4084 old_flags |= new_partial;
4088 switch (new_partial)
4090 default: strcat (new_opt, " -mfpr-?"); break;
4091 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
4092 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
4093 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
4096 switch (old_partial)
4098 default: strcat (old_opt, " -mfpr-?"); break;
4099 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
4100 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
4101 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
4105 /* Warn if different dword support was used. Note, 0 means nothing is
4106 said about the dword support. */
4107 new_partial = (new_flags & EF_FRV_DWORD_MASK);
4108 old_partial = (old_flags & EF_FRV_DWORD_MASK);
4109 if (new_partial == old_partial)
4112 else if (new_partial == 0)
4115 else if (old_partial == 0)
4116 old_flags |= new_partial;
4120 switch (new_partial)
4122 default: strcat (new_opt, " -mdword-?"); break;
4123 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
4124 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
4127 switch (old_partial)
4129 default: strcat (old_opt, " -mdword-?"); break;
4130 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
4131 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
4135 /* Or in flags that accumulate (ie, if one module uses it, mark that the
4137 old_flags |= new_flags & (EF_FRV_DOUBLE
4140 | EF_FRV_NON_PIC_RELOCS);
4142 /* If any module was compiled without -G0, clear the G0 bit. */
4143 old_flags = ((old_flags & ~ EF_FRV_G0)
4144 | (old_flags & new_flags & EF_FRV_G0));
4146 /* If any module was compiled without -mnopack, clear the mnopack bit. */
4147 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
4148 | (old_flags & new_flags & EF_FRV_NOPACK));
4150 /* We don't have to do anything if the pic flags are the same, or the new
4151 module(s) were compiled with -mlibrary-pic. */
4152 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
4153 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
4154 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
4157 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
4158 flags if any from the new module. */
4159 else if ((old_partial & EF_FRV_LIBPIC) != 0)
4160 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
4162 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
4163 else if (new_partial != 0 && old_partial != 0)
4164 old_flags |= new_partial;
4166 /* One module was compiled for pic and the other was not, see if we have
4167 had any relocations that are not pic-safe. */
4170 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
4171 old_flags |= new_partial;
4174 old_flags &= ~ EF_FRV_PIC_FLAGS;
4175 #ifndef FRV_NO_PIC_ERROR
4177 (*_bfd_error_handler)
4178 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
4179 bfd_get_filename (ibfd),
4180 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
4185 /* Warn if different cpu is used (allow a specific cpu to override
4186 the generic cpu). */
4187 new_partial = (new_flags & EF_FRV_CPU_MASK);
4188 old_partial = (old_flags & EF_FRV_CPU_MASK);
4189 if (new_partial == old_partial)
4192 else if (new_partial == EF_FRV_CPU_GENERIC)
4195 else if (old_partial == EF_FRV_CPU_GENERIC)
4196 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
4200 switch (new_partial)
4202 default: strcat (new_opt, " -mcpu=?"); break;
4203 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
4204 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
4205 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
4206 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
4207 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
4208 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
4209 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
4212 switch (old_partial)
4214 default: strcat (old_opt, " -mcpu=?"); break;
4215 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
4216 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
4217 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
4218 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
4219 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
4220 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
4221 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
4225 /* Print out any mismatches from above. */
4229 (*_bfd_error_handler)
4230 (_("%s: compiled with %s and linked with modules compiled with %s"),
4231 bfd_get_filename (ibfd), new_opt, old_opt);
4234 /* Warn about any other mismatches */
4235 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
4236 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
4237 if (new_partial != old_partial)
4239 old_flags |= new_partial;
4241 (*_bfd_error_handler)
4242 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
4243 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
4247 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
4248 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
4249 old_flags |= EF_FRV_NOPACK;
4251 /* Update the old flags now with changes made above. */
4252 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
4253 elf_elfheader (obfd)->e_flags = old_flags;
4254 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
4255 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
4258 bfd_set_error (bfd_error_bad_value);
4265 frv_elf_print_private_bfd_data (abfd, ptr)
4269 FILE *file = (FILE *) ptr;
4272 BFD_ASSERT (abfd != NULL && ptr != NULL);
4274 /* Print normal ELF private data. */
4275 _bfd_elf_print_private_bfd_data (abfd, ptr);
4277 flags = elf_elfheader (abfd)->e_flags;
4278 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
4280 switch (flags & EF_FRV_CPU_MASK)
4283 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
4284 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
4285 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
4286 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
4287 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
4288 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
4291 switch (flags & EF_FRV_GPR_MASK)
4294 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
4295 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
4298 switch (flags & EF_FRV_FPR_MASK)
4301 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
4302 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
4303 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
4306 switch (flags & EF_FRV_DWORD_MASK)
4309 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
4310 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
4313 if (flags & EF_FRV_DOUBLE)
4314 fprintf (file, " -mdouble");
4316 if (flags & EF_FRV_MEDIA)
4317 fprintf (file, " -mmedia");
4319 if (flags & EF_FRV_MULADD)
4320 fprintf (file, " -mmuladd");
4322 if (flags & EF_FRV_PIC)
4323 fprintf (file, " -fpic");
4325 if (flags & EF_FRV_BIGPIC)
4326 fprintf (file, " -fPIC");
4328 if (flags & EF_FRV_LIBPIC)
4329 fprintf (file, " -mlibrary-pic");
4331 if (flags & EF_FRV_FDPIC)
4332 fprintf (file, " -mfdpic");
4334 if (flags & EF_FRV_NON_PIC_RELOCS)
4335 fprintf (file, " non-pic relocations");
4337 if (flags & EF_FRV_G0)
4338 fprintf (file, " -G0");
4345 #define ELF_ARCH bfd_arch_frv
4346 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
4347 #define ELF_MAXPAGESIZE 0x1000
4349 #define TARGET_BIG_SYM bfd_elf32_frv_vec
4350 #define TARGET_BIG_NAME "elf32-frv"
4352 #define elf_info_to_howto_rel frv_info_to_howto_rel
4353 #define elf_info_to_howto frv_info_to_howto_rela
4354 #define elf_backend_relocate_section elf32_frv_relocate_section
4355 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
4356 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
4357 #define elf_backend_check_relocs elf32_frv_check_relocs
4358 #define elf_backend_object_p elf32_frv_object_p
4359 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
4361 #define elf_backend_can_gc_sections 1
4362 #define elf_backend_rela_normal 1
4364 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
4365 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
4366 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
4367 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
4368 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
4370 #define bfd_elf32_bfd_link_hash_table_create frv_elf_link_hash_table_create
4371 #define elf_backend_always_size_sections \
4372 elf32_frv_always_size_sections
4373 #define elf_backend_modify_segment_map \
4374 elf32_frv_modify_segment_map
4376 #define elf_backend_create_dynamic_sections \
4377 elf32_frv_create_dynamic_sections
4378 #define elf_backend_adjust_dynamic_symbol \
4379 elf32_frv_adjust_dynamic_symbol
4380 #define elf_backend_size_dynamic_sections \
4381 elf32_frv_size_dynamic_sections
4382 #define elf_backend_finish_dynamic_symbol \
4383 elf32_frv_finish_dynamic_symbol
4384 #define elf_backend_finish_dynamic_sections \
4385 elf32_frv_finish_dynamic_sections
4387 #define elf_backend_want_got_sym 1
4388 #define elf_backend_got_header_size 0
4389 #define elf_backend_want_got_plt 0
4390 #define elf_backend_plt_readonly 1
4391 #define elf_backend_want_plt_sym 0
4392 #define elf_backend_plt_header_size 0
4394 #define elf_backend_may_use_rel_p 1
4395 #define elf_backend_may_use_rela_p 1
4396 /* We use REL for dynamic relocations only. */
4397 #define elf_backend_default_use_rela_p 1
4399 #include "elf32-target.h"