1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "elf/dwarf2.h"
28 /* Forward declarations. */
29 static bfd_reloc_status_type elf32_frv_relocate_lo16
30 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
31 static bfd_reloc_status_type elf32_frv_relocate_hi16
32 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
33 static bfd_reloc_status_type elf32_frv_relocate_label24
34 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
35 static bfd_reloc_status_type elf32_frv_relocate_gprel12
36 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
37 bfd_byte
*, bfd_vma
));
38 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
39 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
40 bfd_byte
*, bfd_vma
));
41 static bfd_reloc_status_type elf32_frv_relocate_gprello
42 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
43 bfd_byte
*, bfd_vma
));
44 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
45 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
46 bfd_byte
*, bfd_vma
));
47 static reloc_howto_type
*frv_reloc_type_lookup
48 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
49 static void frv_info_to_howto_rela
50 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
51 static bfd_boolean elf32_frv_relocate_section
52 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
53 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
54 static bfd_boolean elf32_frv_add_symbol_hook
55 PARAMS (( bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
56 const char **, flagword
*, asection
**, bfd_vma
*));
57 static bfd_reloc_status_type frv_final_link_relocate
58 PARAMS ((reloc_howto_type
*, bfd
*, asection
*, bfd_byte
*,
59 Elf_Internal_Rela
*, bfd_vma
));
60 static bfd_boolean elf32_frv_gc_sweep_hook
61 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, const
62 Elf_Internal_Rela
*));
63 static asection
* elf32_frv_gc_mark_hook
64 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
65 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
66 static bfd_boolean elf32_frv_check_relocs
67 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
68 const Elf_Internal_Rela
*));
69 static int elf32_frv_machine
71 static bfd_boolean elf32_frv_object_p
73 static bfd_boolean frv_elf_set_private_flags
74 PARAMS ((bfd
*, flagword
));
75 static bfd_boolean frv_elf_copy_private_bfd_data
76 PARAMS ((bfd
*, bfd
*));
77 static bfd_boolean frv_elf_merge_private_bfd_data
78 PARAMS ((bfd
*, bfd
*));
79 static bfd_boolean frv_elf_print_private_bfd_data
80 PARAMS ((bfd
*, PTR
));
82 static reloc_howto_type elf32_frv_howto_table
[] =
84 /* This reloc does nothing. */
85 HOWTO (R_FRV_NONE
, /* type */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
89 FALSE
, /* pc_relative */
91 complain_overflow_bitfield
, /* complain_on_overflow */
92 bfd_elf_generic_reloc
, /* special_function */
93 "R_FRV_NONE", /* name */
94 FALSE
, /* partial_inplace */
97 FALSE
), /* pcrel_offset */
99 /* A 32 bit absolute relocation. */
100 HOWTO (R_FRV_32
, /* type */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
104 FALSE
, /* pc_relative */
106 complain_overflow_bitfield
, /* complain_on_overflow */
107 bfd_elf_generic_reloc
, /* special_function */
108 "R_FRV_32", /* name */
109 FALSE
, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE
), /* pcrel_offset */
114 /* A 16 bit pc-relative relocation. */
115 HOWTO (R_FRV_LABEL16
, /* type */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
119 TRUE
, /* pc_relative */
121 complain_overflow_signed
, /* complain_on_overflow */
122 bfd_elf_generic_reloc
, /* special_function */
123 "R_FRV_LABEL16", /* name */
124 FALSE
, /* partial_inplace */
125 0xffff, /* src_mask */
126 0xffff, /* dst_mask */
127 TRUE
), /* pcrel_offset */
129 /* A 24-bit pc-relative relocation. */
130 HOWTO (R_FRV_LABEL24
, /* type */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
134 TRUE
, /* pc_relative */
136 complain_overflow_bitfield
, /* complain_on_overflow */
137 bfd_elf_generic_reloc
, /* special_function */
138 "R_FRV_LABEL24", /* name */
139 FALSE
, /* partial_inplace */
140 0x7e03ffff, /* src_mask */
141 0x7e03ffff, /* dst_mask */
142 TRUE
), /* pcrel_offset */
144 HOWTO (R_FRV_LO16
, /* type */
146 2, /* size (0 = byte, 1 = short, 2 = long) */
148 FALSE
, /* pc_relative */
150 complain_overflow_dont
, /* complain_on_overflow */
151 bfd_elf_generic_reloc
, /* special_function */
152 "R_FRV_LO16", /* name */
153 FALSE
, /* partial_inplace */
154 0xffff, /* src_mask */
155 0xffff, /* dst_mask */
156 FALSE
), /* pcrel_offset */
158 HOWTO (R_FRV_HI16
, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 FALSE
, /* pc_relative */
164 complain_overflow_dont
, /* complain_on_overflow */
165 bfd_elf_generic_reloc
, /* special_function */
166 "R_FRV_HI16", /* name */
167 FALSE
, /* partial_inplace */
168 0xffff, /* src_mask */
169 0xffff, /* dst_mask */
170 FALSE
), /* pcrel_offset */
172 HOWTO (R_FRV_GPREL12
, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 FALSE
, /* pc_relative */
178 complain_overflow_dont
, /* complain_on_overflow */
179 bfd_elf_generic_reloc
, /* special_function */
180 "R_FRV_GPREL12", /* name */
181 FALSE
, /* partial_inplace */
182 0xfff, /* src_mask */
183 0xfff, /* dst_mask */
184 FALSE
), /* pcrel_offset */
186 HOWTO (R_FRV_GPRELU12
, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 FALSE
, /* pc_relative */
192 complain_overflow_dont
, /* complain_on_overflow */
193 bfd_elf_generic_reloc
, /* special_function */
194 "R_FRV_GPRELU12", /* name */
195 FALSE
, /* partial_inplace */
196 0xfff, /* src_mask */
197 0x3f03f, /* dst_mask */
198 FALSE
), /* pcrel_offset */
200 HOWTO (R_FRV_GPREL32
, /* type */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE
, /* pc_relative */
206 complain_overflow_dont
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_FRV_GPREL32", /* name */
209 FALSE
, /* partial_inplace */
210 0xffffffff, /* src_mask */
211 0xffffffff, /* dst_mask */
212 FALSE
), /* pcrel_offset */
214 HOWTO (R_FRV_GPRELHI
, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 FALSE
, /* pc_relative */
220 complain_overflow_dont
, /* complain_on_overflow */
221 bfd_elf_generic_reloc
, /* special_function */
222 "R_FRV_GPRELHI", /* name */
223 FALSE
, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 FALSE
), /* pcrel_offset */
228 HOWTO (R_FRV_GPRELLO
, /* type */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
232 FALSE
, /* pc_relative */
234 complain_overflow_dont
, /* complain_on_overflow */
235 bfd_elf_generic_reloc
, /* special_function */
236 "R_FRV_GPRELLO", /* name */
237 FALSE
, /* partial_inplace */
238 0xffff, /* src_mask */
239 0xffff, /* dst_mask */
240 FALSE
), /* pcrel_offset */
242 /* A 12-bit signed operand with the GOT offset for the address of
244 HOWTO (R_FRV_GOT12
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 FALSE
, /* pc_relative */
250 complain_overflow_signed
, /* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_FRV_GOT12", /* name */
253 FALSE
, /* partial_inplace */
254 0xfff, /* src_mask */
255 0xfff, /* dst_mask */
256 FALSE
), /* pcrel_offset */
258 /* The upper 16 bits of the GOT offset for the address of the
260 HOWTO (R_FRV_GOTHI
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE
, /* pc_relative */
266 complain_overflow_dont
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_FRV_GOTHI", /* name */
269 FALSE
, /* partial_inplace */
270 0xffff, /* src_mask */
271 0xffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
274 /* The lower 16 bits of the GOT offset for the address of the
276 HOWTO (R_FRV_GOTLO
, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE
, /* pc_relative */
282 complain_overflow_dont
, /* complain_on_overflow */
283 bfd_elf_generic_reloc
, /* special_function */
284 "R_FRV_GOTLO", /* name */
285 FALSE
, /* partial_inplace */
286 0xffff, /* src_mask */
287 0xffff, /* dst_mask */
288 FALSE
), /* pcrel_offset */
290 /* The 32-bit address of the canonical descriptor of a function. */
291 HOWTO (R_FRV_FUNCDESC
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE
, /* pc_relative */
297 complain_overflow_bitfield
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_FRV_FUNCDESC", /* name */
300 FALSE
, /* partial_inplace */
301 0xffffffff, /* src_mask */
302 0xffffffff, /* dst_mask */
303 FALSE
), /* pcrel_offset */
305 /* A 12-bit signed operand with the GOT offset for the address of
306 canonical descriptor of a function. */
307 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 FALSE
, /* pc_relative */
313 complain_overflow_signed
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_FRV_FUNCDESC_GOT12", /* name */
316 FALSE
, /* partial_inplace */
317 0xfff, /* src_mask */
318 0xfff, /* dst_mask */
319 FALSE
), /* pcrel_offset */
321 /* The upper 16 bits of the GOT offset for the address of the
322 canonical descriptor of a function. */
323 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_dont
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_FRV_FUNCDESC_GOTHI", /* name */
332 FALSE
, /* partial_inplace */
333 0xffff, /* src_mask */
334 0xffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* The lower 16 bits of the GOT offset for the address of the
338 canonical descriptor of a function. */
339 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE
, /* pc_relative */
345 complain_overflow_dont
, /* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_FRV_FUNCDESC_GOTLO", /* name */
348 FALSE
, /* partial_inplace */
349 0xffff, /* src_mask */
350 0xffff, /* dst_mask */
351 FALSE
), /* pcrel_offset */
353 /* The 32-bit address of the canonical descriptor of a function. */
354 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_bitfield
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_FRV_FUNCDESC_VALUE", /* name */
363 FALSE
, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* A 12-bit signed operand with the GOT offset for the address of
369 canonical descriptor of a function. */
370 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE
, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_FRV_FUNCDESC_GOTOFF12", /* name */
379 FALSE
, /* partial_inplace */
380 0xfff, /* src_mask */
381 0xfff, /* dst_mask */
382 FALSE
), /* pcrel_offset */
384 /* The upper 16 bits of the GOT offset for the address of the
385 canonical descriptor of a function. */
386 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_dont
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
395 FALSE
, /* partial_inplace */
396 0xffff, /* src_mask */
397 0xffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
400 /* The lower 16 bits of the GOT offset for the address of the
401 canonical descriptor of a function. */
402 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE
, /* pc_relative */
408 complain_overflow_dont
, /* complain_on_overflow */
409 bfd_elf_generic_reloc
, /* special_function */
410 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
411 FALSE
, /* partial_inplace */
412 0xffff, /* src_mask */
413 0xffff, /* dst_mask */
414 FALSE
), /* pcrel_offset */
416 /* A 12-bit signed operand with the GOT offset for the address of
418 HOWTO (R_FRV_GOTOFF12
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_FRV_GOTOFF12", /* name */
427 FALSE
, /* partial_inplace */
428 0xfff, /* src_mask */
429 0xfff, /* dst_mask */
430 FALSE
), /* pcrel_offset */
432 /* The upper 16 bits of the GOT offset for the address of the
434 HOWTO (R_FRV_GOTOFFHI
, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE
, /* pc_relative */
440 complain_overflow_dont
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 "R_FRV_GOTOFFHI", /* name */
443 FALSE
, /* partial_inplace */
444 0xffff, /* src_mask */
445 0xffff, /* dst_mask */
446 FALSE
), /* pcrel_offset */
448 /* The lower 16 bits of the GOT offset for the address of the
450 HOWTO (R_FRV_GOTOFFLO
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE
, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_FRV_GOTOFFLO", /* name */
459 FALSE
, /* partial_inplace */
460 0xffff, /* src_mask */
461 0xffff, /* dst_mask */
462 FALSE
), /* pcrel_offset */
466 /* GNU extension to record C++ vtable hierarchy. */
467 static reloc_howto_type elf32_frv_vtinherit_howto
=
468 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 FALSE
, /* pc_relative */
474 complain_overflow_dont
, /* complain_on_overflow */
475 NULL
, /* special_function */
476 "R_FRV_GNU_VTINHERIT", /* name */
477 FALSE
, /* partial_inplace */
480 FALSE
); /* pcrel_offset */
482 /* GNU extension to record C++ vtable member usage. */
483 static reloc_howto_type elf32_frv_vtentry_howto
=
484 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE
, /* pc_relative */
490 complain_overflow_dont
, /* complain_on_overflow */
491 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
492 "R_FRV_GNU_VTENTRY", /* name */
493 FALSE
, /* partial_inplace */
496 FALSE
); /* pcrel_offset */
498 /* The following 3 relocations are REL. The only difference to the
499 entries in the table above are that partial_inplace is TRUE. */
500 static reloc_howto_type elf32_frv_rel_32_howto
=
501 HOWTO (R_FRV_32
, /* type */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
505 FALSE
, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_FRV_32", /* name */
510 TRUE
, /* partial_inplace */
511 0xffffffff, /* src_mask */
512 0xffffffff, /* dst_mask */
513 FALSE
); /* pcrel_offset */
515 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
516 HOWTO (R_FRV_FUNCDESC
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 FALSE
, /* pc_relative */
522 complain_overflow_bitfield
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_FRV_FUNCDESC", /* name */
525 TRUE
, /* partial_inplace */
526 0xffffffff, /* src_mask */
527 0xffffffff, /* dst_mask */
528 FALSE
); /* pcrel_offset */
530 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
531 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE
, /* pc_relative */
537 complain_overflow_bitfield
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_FRV_FUNCDESC_VALUE", /* name */
540 TRUE
, /* partial_inplace */
541 0xffffffff, /* src_mask */
542 0xffffffff, /* dst_mask */
543 FALSE
); /* pcrel_offset */
546 /* Map BFD reloc types to FRV ELF reloc types. */
550 unsigned int bfd_reloc_val
;
551 unsigned int frv_reloc_val
;
554 static const struct frv_reloc_map frv_reloc_map
[] =
556 { BFD_RELOC_NONE
, R_FRV_NONE
},
557 { BFD_RELOC_32
, R_FRV_32
},
558 { BFD_RELOC_FRV_LABEL16
, R_FRV_LABEL16
},
559 { BFD_RELOC_FRV_LABEL24
, R_FRV_LABEL24
},
560 { BFD_RELOC_FRV_LO16
, R_FRV_LO16
},
561 { BFD_RELOC_FRV_HI16
, R_FRV_HI16
},
562 { BFD_RELOC_FRV_GPREL12
, R_FRV_GPREL12
},
563 { BFD_RELOC_FRV_GPRELU12
, R_FRV_GPRELU12
},
564 { BFD_RELOC_FRV_GPREL32
, R_FRV_GPREL32
},
565 { BFD_RELOC_FRV_GPRELHI
, R_FRV_GPRELHI
},
566 { BFD_RELOC_FRV_GPRELLO
, R_FRV_GPRELLO
},
567 { BFD_RELOC_FRV_GOT12
, R_FRV_GOT12
},
568 { BFD_RELOC_FRV_GOTHI
, R_FRV_GOTHI
},
569 { BFD_RELOC_FRV_GOTLO
, R_FRV_GOTLO
},
570 { BFD_RELOC_FRV_FUNCDESC
, R_FRV_FUNCDESC
},
571 { BFD_RELOC_FRV_FUNCDESC_GOT12
, R_FRV_FUNCDESC_GOT12
},
572 { BFD_RELOC_FRV_FUNCDESC_GOTHI
, R_FRV_FUNCDESC_GOTHI
},
573 { BFD_RELOC_FRV_FUNCDESC_GOTLO
, R_FRV_FUNCDESC_GOTLO
},
574 { BFD_RELOC_FRV_FUNCDESC_VALUE
, R_FRV_FUNCDESC_VALUE
},
575 { BFD_RELOC_FRV_FUNCDESC_GOTOFF12
, R_FRV_FUNCDESC_GOTOFF12
},
576 { BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
, R_FRV_FUNCDESC_GOTOFFHI
},
577 { BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
, R_FRV_FUNCDESC_GOTOFFLO
},
578 { BFD_RELOC_FRV_GOTOFF12
, R_FRV_GOTOFF12
},
579 { BFD_RELOC_FRV_GOTOFFHI
, R_FRV_GOTOFFHI
},
580 { BFD_RELOC_FRV_GOTOFFLO
, R_FRV_GOTOFFLO
},
581 { BFD_RELOC_VTABLE_INHERIT
, R_FRV_GNU_VTINHERIT
},
582 { BFD_RELOC_VTABLE_ENTRY
, R_FRV_GNU_VTENTRY
},
587 /* An extension of the elf hash table data structure, containing some
588 additional FRV-specific data. */
589 struct frv_elf_link_hash_table
591 struct elf_link_hash_table elf
;
593 /* A pointer to the .got section. */
595 /* A pointer to the .rel.got section. */
597 /* A pointer to the .rofixup section. */
599 /* A pointer to the .plt section. */
601 /* A pointer to the .rel.plt section. */
603 /* GOT base offset. */
605 /* Location of the first non-lazy PLT entry, i.e., the number of
606 bytes taken by lazy PLT entries. */
608 /* A hash table holding information about which symbols were
609 referenced with which PIC-related relocations. */
610 struct htab
*relocs_info
;
613 /* Get the FRV ELF linker hash table from a link_info structure. */
615 #define frv_hash_table(info) \
616 ((struct frv_elf_link_hash_table *) ((info)->hash))
618 #define frv_got_section(info) \
619 (frv_hash_table (info)->sgot)
620 #define frv_gotrel_section(info) \
621 (frv_hash_table (info)->sgotrel)
622 #define frv_gotfixup_section(info) \
623 (frv_hash_table (info)->sgotfixup)
624 #define frv_plt_section(info) \
625 (frv_hash_table (info)->splt)
626 #define frv_pltrel_section(info) \
627 (frv_hash_table (info)->spltrel)
628 #define frv_relocs_info(info) \
629 (frv_hash_table (info)->relocs_info)
630 #define frv_got_initial_offset(info) \
631 (frv_hash_table (info)->got0)
632 #define frv_plt_initial_offset(info) \
633 (frv_hash_table (info)->plt0)
635 /* Create an FRV ELF linker hash table. */
637 static struct bfd_link_hash_table
*
638 frv_elf_link_hash_table_create (bfd
*abfd
)
640 struct frv_elf_link_hash_table
*ret
;
641 bfd_size_type amt
= sizeof (struct frv_elf_link_hash_table
);
643 ret
= bfd_zalloc (abfd
, amt
);
647 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
648 _bfd_elf_link_hash_newfunc
))
654 return &ret
->elf
.root
;
657 /* Decide whether a reference to a symbol can be resolved locally or
658 not. If the symbol is protected, we want the local address, but
659 its function descriptor must be assigned by the dynamic linker. */
660 #define FRV_SYM_LOCAL(INFO, H) \
661 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
662 || ! elf_hash_table (INFO)->dynamic_sections_created \
663 || (/* The condition below is an ugly hack to get .scommon data to
664 be regarded as local. For some reason the
665 ELF_LINK_HASH_DEF_REGULAR bit is not set on such common
666 symbols, and the SEC_IS_COMMON bit is not set any longer
667 when we need to perform this test. Hopefully this
668 approximation is good enough. */ \
669 ((H)->root.type == bfd_link_hash_defined \
670 || (H)->root.type == bfd_link_hash_defweak) \
671 && (H)->root.u.def.section->output_section \
672 && ((H)->root.u.def.section->flags & SEC_LINKER_CREATED)))
673 #define FRV_FUNCDESC_LOCAL(INFO, H) \
674 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
676 /* This structure collects information on what kind of GOT, PLT or
677 function descriptors are required by relocations that reference a
679 struct frv_pic_relocs_info
681 /* The index of the symbol, as stored in the relocation r_info, if
682 we have a local symbol; -1 otherwise. */
686 /* The input bfd in which the symbol is defined, if it's a local
689 /* If symndx == -1, the hash table entry corresponding to a global
690 symbol (even if it turns out to bind locally, in which case it
691 should ideally be replaced with section's symndx + addend). */
692 struct elf_link_hash_entry
*h
;
694 /* The addend of the relocation that references the symbol. */
697 /* The fields above are used to identify an entry. The fields below
698 contain information on how an entry is used and, later on, which
699 locations it was assigned. */
700 /* The following 3 fields record whether the symbol+addend above was
701 ever referenced with a GOT relocation. The 12 suffix indicates a
702 GOT12 relocation; los is used for GOTLO relocations that are not
703 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
708 /* Whether a FUNCDESC relocation references symbol+addend. */
710 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
713 unsigned fdgothilo
:1;
714 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
716 unsigned fdgofflos
:1;
717 unsigned fdgoffhilo
:1;
718 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
719 GOTOFFHI relocations. The addend doesn't really matter, since we
720 envision that this will only be used to check whether the symbol
721 is mapped to the same segment as the got. */
723 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
725 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
728 /* Whether we need a PLT entry for a symbol. Should be implied by
730 (call && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)) */
732 /* Whether a function descriptor should be created in this link unit
733 for symbol+addend. Should be implied by something like:
734 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
735 || ((fd || fdgot12 || fdgotlos || fdgothilo)
736 && (symndx != -1 || FRV_FUNCDESC_LOCAL (info, d.h)))) */
738 /* Whether a lazy PLT entry is needed for this symbol+addend.
739 Should be implied by something like:
740 (privfd && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)
741 && ! (info->flags & DF_BIND_NOW)) */
743 /* Whether we've already emitted GOT relocations and PLT entries as
744 needed for this symbol. */
747 /* The number of R_FRV_32, R_FRV_FUNCDESC and R_FRV_FUNCDESC_VALUE
748 relocations referencing the symbol. */
749 unsigned relocs32
, relocsfd
, relocsfdv
;
751 /* The number of .rofixups entries and dynamic relocations allocated
752 for this symbol, minus any that might have already been used. */
753 unsigned fixups
, dynrelocs
;
755 /* The offsets of the GOT entries assigned to symbol+addend, to the
756 function descriptor's address, and to a function descriptor,
757 respectively. Should be zero if unassigned. The offsets are
758 counted from the value that will be assigned to the PIC register,
759 not from the beginning of the .got section. */
760 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
761 /* The offsets of the PLT entries assigned to symbol+addend,
762 non-lazy and lazy, respectively. If unassigned, should be
764 bfd_vma plt_entry
, lzplt_entry
;
767 /* Compute a hash with the key fields of an frv_pic_relocs_info entry. */
769 frv_pic_relocs_info_hash (const void *entry_
)
771 const struct frv_pic_relocs_info
*entry
= entry_
;
773 return (entry
->symndx
== -1
774 ? entry
->d
.h
->root
.root
.hash
775 : entry
->symndx
+ entry
->d
.abfd
->id
* 257) + entry
->addend
;
778 /* Test whether the key fields of two frv_pic_relocs_info entries are
781 frv_pic_relocs_info_eq (const void *entry1
, const void *entry2
)
783 const struct frv_pic_relocs_info
*e1
= entry1
;
784 const struct frv_pic_relocs_info
*e2
= entry2
;
786 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
787 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
790 /* Find or create an entry in a hash table HT that matches the key
791 fields of the given ENTRY. If it's not found, memory for a new
792 entry is allocated in ABFD's obstack. */
793 static struct frv_pic_relocs_info
*
794 frv_pic_relocs_info_find (struct htab
*ht
,
796 const struct frv_pic_relocs_info
*entry
,
797 enum insert_option insert
)
799 struct frv_pic_relocs_info
**loc
=
800 (struct frv_pic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
808 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
813 (*loc
)->symndx
= entry
->symndx
;
814 (*loc
)->d
= entry
->d
;
815 (*loc
)->addend
= entry
->addend
;
816 (*loc
)->plt_entry
= (bfd_vma
)-1;
817 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
822 /* Obtain the address of the entry in HT associated with H's symbol +
823 addend, creating a new entry if none existed. ABFD is only used
824 for memory allocation purposes. */
825 inline static struct frv_pic_relocs_info
*
826 frv_pic_relocs_info_for_global (struct htab
*ht
,
828 struct elf_link_hash_entry
*h
,
830 enum insert_option insert
)
832 struct frv_pic_relocs_info entry
;
836 entry
.addend
= addend
;
838 return frv_pic_relocs_info_find (ht
, abfd
, &entry
, insert
);
841 /* Obtain the address of the entry in HT associated with the SYMNDXth
842 local symbol of the input bfd ABFD, plus the addend, creating a new
843 entry if none existed. */
844 inline static struct frv_pic_relocs_info
*
845 frv_pic_relocs_info_for_local (struct htab
*ht
,
849 enum insert_option insert
)
851 struct frv_pic_relocs_info entry
;
853 entry
.symndx
= symndx
;
855 entry
.addend
= addend
;
857 return frv_pic_relocs_info_find (ht
, abfd
, &entry
, insert
);
860 /* Merge fields set by check_relocs() of two entries that end up being
861 mapped to the same (presumably global) symbol. */
864 frv_pic_merge_early_relocs_info (struct frv_pic_relocs_info
*e2
,
865 struct frv_pic_relocs_info
const *e1
)
867 e2
->got12
|= e1
->got12
;
868 e2
->gotlos
|= e1
->gotlos
;
869 e2
->gothilo
|= e1
->gothilo
;
871 e2
->fdgot12
|= e1
->fdgot12
;
872 e2
->fdgotlos
|= e1
->fdgotlos
;
873 e2
->fdgothilo
|= e1
->fdgothilo
;
874 e2
->fdgoff12
|= e1
->fdgoff12
;
875 e2
->fdgofflos
|= e1
->fdgofflos
;
876 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
877 e2
->gotoff
|= e1
->gotoff
;
878 e2
->call
|= e1
->call
;
882 /* These are set in _frv_count_got_plt_entries() or later, and this
883 function is only called in _frv_resolve_final_relocs_info(), that
884 runs just before it, so we don't have to worry about the fields
888 e2
->privfd
|= e1
->privfd
;
889 e2
->lazyplt
|= e1
->lazyplt
;
890 e2
->done
|= e1
->done
;
892 e2
->relocs32
+= e1
->relocs32
;
893 e2
->relocsfd
+= e1
->relocsfd
;
894 e2
->relocsfdv
+= e1
->relocsfdv
;
895 e2
->fixups
+= e1
->fixups
;
896 e2
->dynrelocs
+= e1
->dynrelocs
;
898 if (abs (e1
->got_entry
) < abs (e2
->got_entry
))
899 e2
->got_entry
= e1
->got_entry
;
900 if (abs (e1
->fdgot_entry
) < abs (e2
->fdgot_entry
))
901 e2
->fdgot_entry
= e1
->fdgot_entry
;
902 if (abs (e1
->fd_entry
) < abs (e2
->fd_entry
))
903 e2
->fd_entry
= e1
->fd_entry
;
905 if (e1
->plt_entry
< e2
->plt_entry
)
906 e2
->plt_entry
= e1
->plt_entry
;
907 if (e1
->lzplt_entry
< e2
->lzplt_entry
)
908 e2
->lzplt_entry
= e1
->lzplt_entry
;
912 /* Every block of 65535 lazy PLT entries shares a single call to the
913 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
914 32767, counting from 0). All other lazy PLT entries branch to it
915 in a single instruction. */
917 #define FRV_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
918 #define FRV_LZPLT_RESOLV_LOC (8 * 32767)
920 /* Add a dynamic relocation to the SRELOC section. */
922 inline static bfd_vma
923 _frv_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
924 int reloc_type
, long dynindx
, bfd_vma addend
,
925 struct frv_pic_relocs_info
*entry
)
927 Elf_Internal_Rela outrel
;
928 bfd_vma reloc_offset
;
930 outrel
.r_offset
= offset
;
931 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
932 outrel
.r_addend
= addend
;
934 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
935 BFD_ASSERT (reloc_offset
< sreloc
->_raw_size
);
936 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
937 sreloc
->contents
+ reloc_offset
);
938 sreloc
->reloc_count
++;
940 BFD_ASSERT (entry
->dynrelocs
> 0);
946 /* Add a fixup to the ROFIXUP section. */
949 _frv_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
950 struct frv_pic_relocs_info
*entry
)
952 bfd_vma fixup_offset
;
954 if (rofixup
->flags
& SEC_EXCLUDE
)
957 fixup_offset
= rofixup
->reloc_count
* 4;
958 if (rofixup
->contents
)
960 BFD_ASSERT (fixup_offset
< rofixup
->_raw_size
);
961 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
963 rofixup
->reloc_count
++;
967 BFD_ASSERT (entry
->fixups
> 0);
974 /* Find the segment number in which OSEC, and output section, is
978 _frv_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
980 struct elf_segment_map
*m
;
981 Elf_Internal_Phdr
*p
;
983 /* Find the segment that contains the output_section. */
984 for (m
= elf_tdata (output_bfd
)->segment_map
,
985 p
= elf_tdata (output_bfd
)->phdr
;
991 for (i
= m
->count
- 1; i
>= 0; i
--)
992 if (m
->sections
[i
] == osec
)
999 return p
- elf_tdata (output_bfd
)->phdr
;
1002 inline static bfd_boolean
1003 _frv_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
1005 unsigned seg
= _frv_osec_to_segment (output_bfd
, osec
);
1007 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
1010 /* Generate relocations for GOT entries, function descriptors, and
1011 code for PLT and lazy PLT entries. */
1013 inline static bfd_boolean
1014 _frv_emit_got_relocs_plt_entries (struct frv_pic_relocs_info
*entry
,
1016 struct bfd_link_info
*info
,
1018 Elf_Internal_Sym
*sym
,
1022 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
1029 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
)
1031 /* If the symbol is dynamic, consider it for dynamic
1032 relocations, otherwise decay to section + offset. */
1033 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
1034 dynindx
= entry
->d
.h
->dynindx
;
1037 if (sec
->output_section
1038 && ! bfd_is_abs_section (sec
->output_section
)
1039 && ! bfd_is_und_section (sec
->output_section
))
1040 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
1046 /* Generate relocation for GOT entry pointing to the symbol. */
1047 if (entry
->got_entry
)
1050 bfd_vma ad
= addend
;
1052 /* If the symbol is dynamic but binds locally, use
1054 if (sec
&& (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1056 if (entry
->symndx
== -1)
1057 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1059 ad
+= sym
->st_value
;
1060 ad
+= sec
->output_offset
;
1061 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1062 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1067 /* If we're linking an executable at a fixed address, we can
1068 omit the dynamic relocation as long as the symbol is local to
1070 if (info
->executable
&& !info
->pie
1071 && (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1074 ad
+= sec
->output_section
->vma
;
1075 if (entry
->symndx
!= -1
1076 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1077 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1078 frv_got_section (info
)->output_section
->vma
1079 + frv_got_section (info
)->output_offset
1080 + frv_got_initial_offset (info
)
1081 + entry
->got_entry
, entry
);
1084 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
1085 _bfd_elf_section_offset
1087 frv_got_section (info
),
1088 frv_got_initial_offset (info
)
1090 + frv_got_section (info
)->output_section
->vma
1091 + frv_got_section (info
)->output_offset
,
1092 R_FRV_32
, idx
, ad
, entry
);
1094 bfd_put_32 (output_bfd
, ad
,
1095 frv_got_section (info
)->contents
1096 + frv_got_initial_offset (info
)
1097 + entry
->got_entry
);
1100 /* Generate relocation for GOT entry pointing to a canonical
1101 function descriptor. */
1102 if (entry
->fdgot_entry
)
1107 if (! (entry
->symndx
== -1
1108 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1109 && FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1111 /* If the symbol is dynamic and there may be dynamic symbol
1112 resolution because we are, or are linked with, a shared
1113 library, emit a FUNCDESC relocation such that the dynamic
1114 linker will allocate the function descriptor. If the
1115 symbol needs a non-local function descriptor but binds
1116 locally (e.g., its visibility is protected, emit a
1117 dynamic relocation decayed to section+offset. */
1118 if (entry
->symndx
== -1 && ! FRV_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1119 && FRV_SYM_LOCAL (info
, entry
->d
.h
)
1120 && !(info
->executable
&& !info
->pie
))
1122 reloc
= R_FRV_FUNCDESC
;
1123 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1124 ->output_section
)->dynindx
;
1125 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1126 + entry
->d
.h
->root
.u
.def
.value
;
1128 else if (entry
->symndx
== -1
1129 && ! FRV_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1131 reloc
= R_FRV_FUNCDESC
;
1139 /* Otherwise, we know we have a private function descriptor,
1140 so reference it directly. */
1141 if (elf_hash_table (info
)->dynamic_sections_created
)
1142 BFD_ASSERT (entry
->privfd
);
1144 idx
= elf_section_data (frv_got_section (info
)
1145 ->output_section
)->dynindx
;
1146 ad
= frv_got_section (info
)->output_offset
1147 + frv_got_initial_offset (info
) + entry
->fd_entry
;
1150 /* If there is room for dynamic symbol resolution, emit the
1151 dynamic relocation. However, if we're linking an
1152 executable at a fixed location, we won't have emitted a
1153 dynamic symbol entry for the got section, so idx will be
1154 zero, which means we can and should compute the address
1155 of the private descriptor ourselves. */
1156 if (info
->executable
&& !info
->pie
1157 && (entry
->symndx
!= -1
1158 || FRV_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1160 ad
+= frv_got_section (info
)->output_section
->vma
;
1161 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1162 frv_got_section (info
)->output_section
->vma
1163 + frv_got_section (info
)->output_offset
1164 + frv_got_initial_offset (info
)
1165 + entry
->fdgot_entry
, entry
);
1168 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
1169 _bfd_elf_section_offset
1171 frv_got_section (info
),
1172 frv_got_initial_offset (info
)
1173 + entry
->fdgot_entry
)
1174 + frv_got_section (info
)->output_section
->vma
1175 + frv_got_section (info
)->output_offset
,
1176 reloc
, idx
, ad
, entry
);
1179 bfd_put_32 (output_bfd
, ad
,
1180 frv_got_section (info
)->contents
1181 + frv_got_initial_offset (info
)
1182 + entry
->fdgot_entry
);
1185 /* Generate relocation to fill in a private function descriptor in
1187 if (entry
->fd_entry
)
1190 bfd_vma ad
= addend
;
1192 long lowword
, highword
;
1194 /* If the symbol is dynamic but binds locally, use
1196 if (sec
&& (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1198 if (entry
->symndx
== -1)
1199 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1201 ad
+= sym
->st_value
;
1202 ad
+= sec
->output_offset
;
1203 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1204 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1209 /* If we're linking an executable at a fixed address, we can
1210 omit the dynamic relocation as long as the symbol is local to
1212 if (info
->executable
&& !info
->pie
1213 && (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1216 ad
+= sec
->output_section
->vma
;
1218 if (entry
->symndx
!= -1
1219 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1221 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1222 frv_got_section (info
)->output_section
->vma
1223 + frv_got_section (info
)->output_offset
1224 + frv_got_initial_offset (info
)
1225 + entry
->fd_entry
, entry
);
1226 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1227 frv_got_section (info
)->output_section
->vma
1228 + frv_got_section (info
)->output_offset
1229 + frv_got_initial_offset (info
)
1230 + entry
->fd_entry
+ 4, entry
);
1236 _frv_add_dyn_reloc (output_bfd
,
1237 entry
->lazyplt
? frv_pltrel_section (info
)
1238 : frv_gotrel_section (info
),
1239 _bfd_elf_section_offset
1241 frv_got_section (info
),
1242 frv_got_initial_offset (info
)
1244 + frv_got_section (info
)->output_section
->vma
1245 + frv_got_section (info
)->output_offset
,
1246 R_FRV_FUNCDESC_VALUE
, idx
, ad
, entry
);
1249 /* If we've omitted the dynamic relocation, just emit the fixed
1250 addresses of the symbol and of the local GOT base offset. */
1251 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1254 highword
= frv_got_section (info
)->output_section
->vma
1255 + frv_got_section (info
)->output_offset
1256 + frv_got_initial_offset (info
);
1258 else if (entry
->lazyplt
)
1263 fd_lazy_rel_offset
= ofst
;
1265 /* A function descriptor used for lazy or local resolving is
1266 initialized such that its high word contains the output
1267 section index in which the PLT entries are located, and
1268 the low word contains the address of the lazy PLT entry
1269 entry point, that must be within the memory region
1270 assigned to that section. */
1271 lowword
= entry
->lzplt_entry
+ 4
1272 + frv_plt_section (info
)->output_offset
1273 + frv_plt_section (info
)->output_section
->vma
;
1274 highword
= _frv_osec_to_segment
1275 (output_bfd
, frv_plt_section (info
)->output_section
);
1279 /* A function descriptor for a local function gets the index
1280 of the section. For a non-local function, it's
1283 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1284 && entry
->d
.h
->dynindx
== idx
)
1287 highword
= _frv_osec_to_segment (output_bfd
, sec
->output_section
);
1290 bfd_put_32 (output_bfd
, lowword
,
1291 frv_got_section (info
)->contents
1292 + frv_got_initial_offset (info
)
1294 bfd_put_32 (output_bfd
, highword
,
1295 frv_got_section (info
)->contents
1296 + frv_got_initial_offset (info
)
1297 + entry
->fd_entry
+ 4);
1300 /* Generate code for the PLT entry. */
1301 if (entry
->plt_entry
!= (bfd_vma
) -1)
1303 bfd_byte
*plt_code
= frv_plt_section (info
)->contents
+ entry
->plt_entry
;
1305 BFD_ASSERT (entry
->fd_entry
);
1307 /* Figure out what kind of PLT entry we need, depending on the
1308 location of the function descriptor within the GOT. */
1309 if (entry
->fd_entry
>= -(1 << (12 - 1))
1310 && entry
->fd_entry
< (1 << (12 - 1)))
1312 /* lddi @(gr15, fd_entry), gr14 */
1313 bfd_put_32 (output_bfd
,
1314 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1320 if (entry
->fd_entry
>= -(1 << (16 - 1))
1321 && entry
->fd_entry
< (1 << (16 - 1)))
1323 /* setlos lo(fd_entry), gr14 */
1324 bfd_put_32 (output_bfd
,
1326 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1332 /* sethi.p hi(fd_entry), gr14
1333 setlo lo(fd_entry), gr14 */
1334 bfd_put_32 (output_bfd
,
1336 | ((entry
->fd_entry
>> 16)
1337 & (((bfd_vma
)1 << 16) - 1)),
1339 bfd_put_32 (output_bfd
,
1341 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1345 /* ldd @(gr14,gr15),gr14 */
1346 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1349 /* jmpl @(gr14,gr0) */
1350 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1353 /* Generate code for the lazy PLT entry. */
1354 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1356 bfd_byte
*lzplt_code
= frv_plt_section (info
)->contents
1357 + entry
->lzplt_entry
;
1358 bfd_vma resolverStub_addr
;
1360 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1363 resolverStub_addr
= entry
->lzplt_entry
/ FRV_LZPLT_BLOCK_SIZE
1364 * FRV_LZPLT_BLOCK_SIZE
+ FRV_LZPLT_RESOLV_LOC
;
1365 if (resolverStub_addr
>= frv_plt_initial_offset (info
))
1366 resolverStub_addr
= frv_plt_initial_offset (info
) - 12;
1368 if (entry
->lzplt_entry
== resolverStub_addr
)
1370 /* This is a lazy PLT entry that includes a resolver call. */
1371 /* ldd @(gr15,gr0), gr4
1373 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1374 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1378 /* bra resolverStub */
1379 bfd_put_32 (output_bfd
,
1381 | (((resolverStub_addr
- entry
->lzplt_entry
)
1382 / 4) & (((bfd_vma
)1 << 16) - 1)),
1390 /* Handle an FRV small data reloc. */
1392 static bfd_reloc_status_type
1393 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
1395 struct bfd_link_info
*info
;
1397 asection
*input_section
;
1398 Elf_Internal_Rela
*relocation
;
1404 struct bfd_link_hash_entry
*h
;
1406 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1408 gp
= (h
->u
.def
.value
1409 + h
->u
.def
.section
->output_section
->vma
1410 + h
->u
.def
.section
->output_offset
);
1412 value
-= input_section
->output_section
->vma
;
1413 value
-= (gp
- input_section
->output_section
->vma
);
1415 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1417 value
+= relocation
->r_addend
;
1419 if ((long) value
> 0x7ff || (long) value
< -0x800)
1420 return bfd_reloc_overflow
;
1422 bfd_put_32 (input_bfd
,
1423 (insn
& 0xfffff000) | (value
& 0xfff),
1424 contents
+ relocation
->r_offset
);
1426 return bfd_reloc_ok
;
1429 /* Handle an FRV small data reloc. for the u12 field. */
1431 static bfd_reloc_status_type
1432 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
1434 struct bfd_link_info
*info
;
1436 asection
*input_section
;
1437 Elf_Internal_Rela
*relocation
;
1443 struct bfd_link_hash_entry
*h
;
1446 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1448 gp
= (h
->u
.def
.value
1449 + h
->u
.def
.section
->output_section
->vma
1450 + h
->u
.def
.section
->output_offset
);
1452 value
-= input_section
->output_section
->vma
;
1453 value
-= (gp
- input_section
->output_section
->vma
);
1455 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1457 value
+= relocation
->r_addend
;
1459 if ((long) value
> 0x7ff || (long) value
< -0x800)
1460 return bfd_reloc_overflow
;
1462 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
1464 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
1466 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
1468 return bfd_reloc_ok
;
1471 /* Handle an FRV ELF HI16 reloc. */
1473 static bfd_reloc_status_type
1474 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
1476 Elf_Internal_Rela
*relhi
;
1482 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
1484 value
+= relhi
->r_addend
;
1485 value
= ((value
>> 16) & 0xffff);
1487 insn
= (insn
& 0xffff0000) | value
;
1489 if ((long) value
> 0xffff || (long) value
< -0x10000)
1490 return bfd_reloc_overflow
;
1492 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
1493 return bfd_reloc_ok
;
1496 static bfd_reloc_status_type
1497 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
1499 Elf_Internal_Rela
*rello
;
1505 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
1507 value
+= rello
->r_addend
;
1508 value
= value
& 0xffff;
1510 insn
= (insn
& 0xffff0000) | value
;
1512 if ((long) value
> 0xffff || (long) value
< -0x10000)
1513 return bfd_reloc_overflow
;
1515 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
1516 return bfd_reloc_ok
;
1519 /* Perform the relocation for the CALL label24 instruction. */
1521 static bfd_reloc_status_type
1522 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
1524 asection
*input_section
;
1525 Elf_Internal_Rela
*rello
;
1533 /* The format for the call instruction is:
1535 0 000000 0001111 000000000000000000
1536 label6 opcode label18
1538 The branch calculation is: pc + (4*label24)
1539 where label24 is the concatenation of label6 and label18. */
1541 /* Grab the instruction. */
1542 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
1544 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
1545 value
-= rello
->r_offset
;
1546 value
+= rello
->r_addend
;
1550 label6
= value
& 0xfc0000;
1551 label6
= label6
<< 7;
1553 label18
= value
& 0x3ffff;
1555 insn
= insn
& 0x803c0000;
1556 insn
= insn
| label6
;
1557 insn
= insn
| label18
;
1559 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
1561 return bfd_reloc_ok
;
1564 static bfd_reloc_status_type
1565 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
1567 struct bfd_link_info
*info
;
1569 asection
*input_section
;
1570 Elf_Internal_Rela
*relocation
;
1576 struct bfd_link_hash_entry
*h
;
1578 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1580 gp
= (h
->u
.def
.value
1581 + h
->u
.def
.section
->output_section
->vma
1582 + h
->u
.def
.section
->output_offset
);
1584 value
-= input_section
->output_section
->vma
;
1585 value
-= (gp
- input_section
->output_section
->vma
);
1586 value
+= relocation
->r_addend
;
1587 value
= ((value
>> 16) & 0xffff);
1589 if ((long) value
> 0xffff || (long) value
< -0x10000)
1590 return bfd_reloc_overflow
;
1592 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1593 insn
= (insn
& 0xffff0000) | value
;
1595 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
1596 return bfd_reloc_ok
;
1599 static bfd_reloc_status_type
1600 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
1602 struct bfd_link_info
*info
;
1604 asection
*input_section
;
1605 Elf_Internal_Rela
*relocation
;
1611 struct bfd_link_hash_entry
*h
;
1613 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1615 gp
= (h
->u
.def
.value
1616 + h
->u
.def
.section
->output_section
->vma
1617 + h
->u
.def
.section
->output_offset
);
1619 value
-= input_section
->output_section
->vma
;
1620 value
-= (gp
- input_section
->output_section
->vma
);
1621 value
+= relocation
->r_addend
;
1622 value
= value
& 0xffff;
1624 if ((long) value
> 0xffff || (long) value
< -0x10000)
1625 return bfd_reloc_overflow
;
1627 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1628 insn
= (insn
& 0xffff0000) | value
;
1630 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
1632 return bfd_reloc_ok
;
1635 static reloc_howto_type
*
1636 frv_reloc_type_lookup (abfd
, code
)
1637 bfd
*abfd ATTRIBUTE_UNUSED
;
1638 bfd_reloc_code_real_type code
;
1645 case BFD_RELOC_NONE
:
1646 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
1649 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
1650 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
1651 return &elf32_frv_rel_32_howto
;
1653 case BFD_RELOC_CTOR
:
1654 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
1656 case BFD_RELOC_FRV_LABEL16
:
1657 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
1659 case BFD_RELOC_FRV_LABEL24
:
1660 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
1662 case BFD_RELOC_FRV_LO16
:
1663 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
1665 case BFD_RELOC_FRV_HI16
:
1666 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
1668 case BFD_RELOC_FRV_GPREL12
:
1669 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
1671 case BFD_RELOC_FRV_GPRELU12
:
1672 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
1674 case BFD_RELOC_FRV_GPREL32
:
1675 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
1677 case BFD_RELOC_FRV_GPRELHI
:
1678 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
1680 case BFD_RELOC_FRV_GPRELLO
:
1681 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
1683 case BFD_RELOC_FRV_GOT12
:
1684 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
1686 case BFD_RELOC_FRV_GOTHI
:
1687 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
1689 case BFD_RELOC_FRV_GOTLO
:
1690 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
1692 case BFD_RELOC_FRV_FUNCDESC
:
1693 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
1694 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
1695 return &elf32_frv_rel_funcdesc_howto
;
1696 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
1698 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
1699 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
1701 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
1702 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
1704 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
1705 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
1707 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
1708 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
1709 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
1710 return &elf32_frv_rel_funcdesc_value_howto
;
1711 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
1713 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
1714 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
1716 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
1717 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
1719 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
1720 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
1722 case BFD_RELOC_FRV_GOTOFF12
:
1723 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
1725 case BFD_RELOC_FRV_GOTOFFHI
:
1726 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
1728 case BFD_RELOC_FRV_GOTOFFLO
:
1729 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
1731 case BFD_RELOC_VTABLE_INHERIT
:
1732 return &elf32_frv_vtinherit_howto
;
1734 case BFD_RELOC_VTABLE_ENTRY
:
1735 return &elf32_frv_vtentry_howto
;
1741 /* Set the howto pointer for an FRV ELF reloc. */
1744 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1745 bfd
*abfd ATTRIBUTE_UNUSED
;
1747 Elf_Internal_Rela
*dst
;
1749 unsigned int r_type
;
1751 r_type
= ELF32_R_TYPE (dst
->r_info
);
1754 case R_FRV_GNU_VTINHERIT
:
1755 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
1758 case R_FRV_GNU_VTENTRY
:
1759 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
1763 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
1768 /* Set the howto pointer for an FRV ELF REL reloc. */
1770 frv_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
1771 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
1773 unsigned int r_type
;
1775 r_type
= ELF32_R_TYPE (dst
->r_info
);
1779 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
1782 case R_FRV_FUNCDESC
:
1783 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
1786 case R_FRV_FUNCDESC_VALUE
:
1787 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
1791 cache_ptr
->howto
= NULL
;
1796 /* Perform a single relocation. By default we use the standard BFD
1797 routines, but a few relocs, we have to do them ourselves. */
1799 static bfd_reloc_status_type
1800 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
1802 reloc_howto_type
*howto
;
1804 asection
*input_section
;
1806 Elf_Internal_Rela
*rel
;
1809 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1810 contents
, rel
->r_offset
, relocation
,
1815 /* Relocate an FRV ELF section.
1817 The RELOCATE_SECTION function is called by the new ELF backend linker
1818 to handle the relocations for a section.
1820 The relocs are always passed as Rela structures; if the section
1821 actually uses Rel structures, the r_addend field will always be
1824 This function is responsible for adjusting the section contents as
1825 necessary, and (if using Rela relocs and generating a relocatable
1826 output file) adjusting the reloc addend as necessary.
1828 This function does not have to worry about setting the reloc
1829 address or the reloc symbol index.
1831 LOCAL_SYMS is a pointer to the swapped in local symbols.
1833 LOCAL_SECTIONS is an array giving the section in the input file
1834 corresponding to the st_shndx field of each local symbol.
1836 The global hash table entry for the global symbols can be found
1837 via elf_sym_hashes (input_bfd).
1839 When generating relocatable output, this function must handle
1840 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1841 going to be the section symbol corresponding to the output
1842 section, which means that the addend must be adjusted
1846 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1847 contents
, relocs
, local_syms
, local_sections
)
1848 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1849 struct bfd_link_info
*info
;
1851 asection
*input_section
;
1853 Elf_Internal_Rela
*relocs
;
1854 Elf_Internal_Sym
*local_syms
;
1855 asection
**local_sections
;
1857 Elf_Internal_Shdr
*symtab_hdr
;
1858 struct elf_link_hash_entry
**sym_hashes
;
1859 Elf_Internal_Rela
*rel
;
1860 Elf_Internal_Rela
*relend
;
1861 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
,
1863 int silence_segment_error
= !(info
->shared
|| info
->pie
);
1865 if (info
->relocatable
)
1868 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1869 sym_hashes
= elf_sym_hashes (input_bfd
);
1870 relend
= relocs
+ input_section
->reloc_count
;
1872 isec_segment
= _frv_osec_to_segment (output_bfd
,
1873 input_section
->output_section
);
1874 if (frv_got_section (info
))
1875 got_segment
= _frv_osec_to_segment (output_bfd
,
1876 frv_got_section (info
)
1880 if (frv_gotfixup_section (info
))
1881 gprel_segment
= _frv_osec_to_segment (output_bfd
,
1882 frv_gotfixup_section (info
)
1886 if (elf_hash_table (info
)->dynamic_sections_created
)
1887 plt_segment
= _frv_osec_to_segment (output_bfd
,
1888 frv_plt_section (info
)
1893 for (rel
= relocs
; rel
< relend
; rel
++)
1895 reloc_howto_type
*howto
;
1896 unsigned long r_symndx
;
1897 Elf_Internal_Sym
*sym
;
1899 struct elf_link_hash_entry
*h
;
1901 bfd_reloc_status_type r
;
1902 const char * name
= NULL
;
1905 struct frv_pic_relocs_info
*picrel
;
1906 bfd_vma orig_addend
= rel
->r_addend
;
1908 r_type
= ELF32_R_TYPE (rel
->r_info
);
1910 if ( r_type
== R_FRV_GNU_VTINHERIT
1911 || r_type
== R_FRV_GNU_VTENTRY
)
1914 /* This is a final link. */
1915 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1916 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
1921 if (r_symndx
< symtab_hdr
->sh_info
)
1923 sym
= local_syms
+ r_symndx
;
1924 osec
= sec
= local_sections
[r_symndx
];
1925 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1927 name
= bfd_elf_string_from_elf_section
1928 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
1929 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
1933 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1935 while (h
->root
.type
== bfd_link_hash_indirect
1936 || h
->root
.type
== bfd_link_hash_warning
)
1937 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1939 name
= h
->root
.root
.string
;
1941 if ((h
->root
.type
== bfd_link_hash_defined
1942 || h
->root
.type
== bfd_link_hash_defweak
)
1943 && ! FRV_SYM_LOCAL (info
, h
))
1949 if (h
->root
.type
== bfd_link_hash_defined
1950 || h
->root
.type
== bfd_link_hash_defweak
)
1952 sec
= h
->root
.u
.def
.section
;
1953 relocation
= (h
->root
.u
.def
.value
1954 + sec
->output_section
->vma
1955 + sec
->output_offset
);
1957 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1961 else if ( ! info
->executable
1963 && info
->unresolved_syms_in_objects
== RM_IGNORE
1964 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1968 if (! ((*info
->callbacks
->undefined_symbol
)
1969 (info
, h
->root
.root
.string
, input_bfd
,
1970 input_section
, rel
->r_offset
, TRUE
)))
1984 case R_FRV_FUNCDESC_GOT12
:
1985 case R_FRV_FUNCDESC_GOTHI
:
1986 case R_FRV_FUNCDESC_GOTLO
:
1987 case R_FRV_GOTOFF12
:
1988 case R_FRV_GOTOFFHI
:
1989 case R_FRV_GOTOFFLO
:
1990 case R_FRV_FUNCDESC_GOTOFF12
:
1991 case R_FRV_FUNCDESC_GOTOFFHI
:
1992 case R_FRV_FUNCDESC_GOTOFFLO
:
1993 case R_FRV_FUNCDESC
:
1994 case R_FRV_FUNCDESC_VALUE
:
1996 picrel
= frv_pic_relocs_info_for_global (frv_relocs_info (info
),
1998 orig_addend
, INSERT
);
2000 /* In order to find the entry we created before, we must
2001 use the original addend, not the one that may have been
2002 modified by _bfd_elf_rela_local_sym(). */
2003 picrel
= frv_pic_relocs_info_for_local (frv_relocs_info (info
),
2004 input_bfd
, r_symndx
,
2005 orig_addend
, INSERT
);
2009 if (!_frv_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2010 osec
, sym
, rel
->r_addend
))
2012 info
->callbacks
->warning
2013 (info
, _("Dynamic relocation references symbol with nonzero addend"),
2014 name
, input_bfd
, input_section
, rel
->r_offset
);
2023 if (h
&& ! FRV_SYM_LOCAL (info
, h
))
2025 info
->callbacks
->warning
2026 (info
, _("relocation references symbol not defined in the module"),
2027 name
, input_bfd
, input_section
, rel
->r_offset
);
2036 check_segment
[0] = isec_segment
;
2039 relocation
= frv_plt_section (info
)->output_section
->vma
2040 + frv_plt_section (info
)->output_offset
2041 + picrel
->plt_entry
;
2042 check_segment
[1] = plt_segment
;
2044 /* We don't want to warn on calls to undefined weak symbols,
2045 as calls to them must be protected by non-NULL tests
2046 anyway, and unprotected calls would invoke undefined
2048 else if (picrel
->symndx
== -1
2049 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
2050 check_segment
[1] = check_segment
[0];
2052 check_segment
[1] = sec
2053 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2060 relocation
= picrel
->got_entry
;
2061 check_segment
[0] = check_segment
[1] = got_segment
;
2064 case R_FRV_FUNCDESC_GOT12
:
2065 case R_FRV_FUNCDESC_GOTHI
:
2066 case R_FRV_FUNCDESC_GOTLO
:
2067 relocation
= picrel
->fdgot_entry
;
2068 check_segment
[0] = check_segment
[1] = got_segment
;
2071 case R_FRV_GOTOFFHI
:
2072 case R_FRV_GOTOFF12
:
2073 case R_FRV_GOTOFFLO
:
2074 relocation
-= frv_got_section (info
)->output_section
->vma
2075 + frv_got_section (info
)->output_offset
2076 + frv_got_initial_offset (info
);
2077 check_segment
[0] = got_segment
;
2078 check_segment
[1] = sec
2079 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2083 case R_FRV_FUNCDESC_GOTOFF12
:
2084 case R_FRV_FUNCDESC_GOTOFFHI
:
2085 case R_FRV_FUNCDESC_GOTOFFLO
:
2086 relocation
= picrel
->fd_entry
;
2087 check_segment
[0] = check_segment
[1] = got_segment
;
2090 case R_FRV_FUNCDESC
:
2093 bfd_vma addend
= rel
->r_addend
;
2095 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
2096 && FRV_SYM_LOCAL (info
, h
)))
2098 /* If the symbol is dynamic and there may be dynamic
2099 symbol resolution because we are or are linked with a
2100 shared library, emit a FUNCDESC relocation such that
2101 the dynamic linker will allocate the function
2102 descriptor. If the symbol needs a non-local function
2103 descriptor but binds locally (e.g., its visibility is
2104 protected, emit a dynamic relocation decayed to
2106 if (h
&& ! FRV_FUNCDESC_LOCAL (info
, h
)
2107 && FRV_SYM_LOCAL (info
, h
)
2108 && !(info
->executable
&& !info
->pie
))
2110 dynindx
= elf_section_data (h
->root
.u
.def
.section
2111 ->output_section
)->dynindx
;
2112 addend
+= h
->root
.u
.def
.section
->output_offset
2113 + h
->root
.u
.def
.value
;
2115 else if (h
&& ! FRV_FUNCDESC_LOCAL (info
, h
))
2119 info
->callbacks
->warning
2120 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
2121 name
, input_bfd
, input_section
, rel
->r_offset
);
2124 dynindx
= h
->dynindx
;
2128 /* Otherwise, we know we have a private function
2129 descriptor, so reference it directly. */
2130 BFD_ASSERT (picrel
->privfd
);
2132 dynindx
= elf_section_data (frv_got_section (info
)
2133 ->output_section
)->dynindx
;
2134 addend
= frv_got_section (info
)->output_offset
2135 + frv_got_initial_offset (info
)
2139 /* If there is room for dynamic symbol resolution, emit
2140 the dynamic relocation. However, if we're linking an
2141 executable at a fixed location, we won't have emitted a
2142 dynamic symbol entry for the got section, so idx will
2143 be zero, which means we can and should compute the
2144 address of the private descriptor ourselves. */
2145 if (info
->executable
&& !info
->pie
2146 && (!h
|| FRV_FUNCDESC_LOCAL (info
, h
)))
2148 addend
+= frv_got_section (info
)->output_section
->vma
;
2149 if ((bfd_get_section_flags (output_bfd
,
2150 input_section
->output_section
)
2151 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2153 if (_frv_osec_readonly_p (output_bfd
,
2154 input_section
->output_section
))
2156 info
->callbacks
->warning
2158 _("cannot emit fixups in read-only section"),
2159 name
, input_bfd
, input_section
, rel
->r_offset
);
2162 _frv_add_rofixup (output_bfd
,
2163 frv_gotfixup_section (info
),
2164 _bfd_elf_section_offset
2166 input_section
, rel
->r_offset
)
2167 + input_section
->output_section
->vma
2168 + input_section
->output_offset
,
2172 else if ((bfd_get_section_flags (output_bfd
,
2173 input_section
->output_section
)
2174 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2176 if (_frv_osec_readonly_p (output_bfd
,
2177 input_section
->output_section
))
2179 info
->callbacks
->warning
2181 _("cannot emit dynamic relocations in read-only section"),
2182 name
, input_bfd
, input_section
, rel
->r_offset
);
2185 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
2186 _bfd_elf_section_offset
2188 input_section
, rel
->r_offset
)
2189 + input_section
->output_section
->vma
2190 + input_section
->output_offset
,
2191 r_type
, dynindx
, addend
, picrel
);
2195 /* We want the addend in-place because dynamic
2196 relocations are REL. Setting relocation to it should
2197 arrange for it to be installed. */
2198 relocation
= addend
- rel
->r_addend
;
2200 check_segment
[0] = check_segment
[1] = got_segment
;
2204 case R_FRV_FUNCDESC_VALUE
:
2207 bfd_vma addend
= rel
->r_addend
;
2209 /* If the symbol is dynamic but binds locally, use
2211 if (h
&& ! FRV_SYM_LOCAL (info
, h
))
2213 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
2215 info
->callbacks
->warning
2216 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2217 name
, input_bfd
, input_section
, rel
->r_offset
);
2220 dynindx
= h
->dynindx
;
2225 addend
+= h
->root
.u
.def
.value
;
2227 addend
+= sym
->st_value
;
2229 addend
+= osec
->output_offset
;
2230 if (osec
&& osec
->output_section
2231 && ! bfd_is_abs_section (osec
->output_section
)
2232 && ! bfd_is_und_section (osec
->output_section
))
2233 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
2238 /* If we're linking an executable at a fixed address, we
2239 can omit the dynamic relocation as long as the symbol
2240 is defined in the current link unit (which is implied
2241 by its output section not being NULL). */
2242 if (info
->executable
&& !info
->pie
2243 && (!h
|| FRV_SYM_LOCAL (info
, h
)))
2246 addend
+= osec
->output_section
->vma
;
2247 if ((elf_elfheader (input_bfd
)->e_flags
& EF_FRV_FDPIC
)
2248 && (bfd_get_section_flags (output_bfd
,
2249 input_section
->output_section
)
2250 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2252 if (_frv_osec_readonly_p (output_bfd
,
2253 input_section
->output_section
))
2255 info
->callbacks
->warning
2257 _("cannot emit fixups in read-only section"),
2258 name
, input_bfd
, input_section
, rel
->r_offset
);
2261 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
2263 _frv_add_rofixup (output_bfd
,
2264 frv_gotfixup_section (info
),
2265 _bfd_elf_section_offset
2267 input_section
, rel
->r_offset
)
2268 + input_section
->output_section
->vma
2269 + input_section
->output_offset
,
2271 if (r_type
== R_FRV_FUNCDESC_VALUE
)
2274 frv_gotfixup_section (info
),
2275 _bfd_elf_section_offset
2277 input_section
, rel
->r_offset
)
2278 + input_section
->output_section
->vma
2279 + input_section
->output_offset
+ 4, picrel
);
2285 if ((bfd_get_section_flags (output_bfd
,
2286 input_section
->output_section
)
2287 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2289 if (_frv_osec_readonly_p (output_bfd
,
2290 input_section
->output_section
))
2292 info
->callbacks
->warning
2294 _("cannot emit dynamic relocations in read-only section"),
2295 name
, input_bfd
, input_section
, rel
->r_offset
);
2298 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
2299 _bfd_elf_section_offset
2301 input_section
, rel
->r_offset
)
2302 + input_section
->output_section
->vma
2303 + input_section
->output_offset
,
2304 r_type
, dynindx
, addend
, picrel
);
2306 /* We want the addend in-place because dynamic
2307 relocations are REL. Setting relocation to it
2308 should arrange for it to be installed. */
2309 relocation
= addend
- rel
->r_addend
;
2312 if (r_type
== R_FRV_FUNCDESC_VALUE
)
2314 /* If we've omitted the dynamic relocation, just emit
2315 the fixed addresses of the symbol and of the local
2317 if (info
->executable
&& !info
->pie
2318 && (!h
|| FRV_SYM_LOCAL (info
, h
)))
2319 bfd_put_32 (output_bfd
,
2320 frv_got_section (info
)->output_section
->vma
2321 + frv_got_section (info
)->output_offset
2322 + frv_got_initial_offset (info
),
2323 contents
+ rel
->r_offset
+ 4);
2325 /* A function descriptor used for lazy or local
2326 resolving is initialized such that its high word
2327 contains the output section index in which the
2328 PLT entries are located, and the low word
2329 contains the offset of the lazy PLT entry entry
2330 point into that section. */
2331 bfd_put_32 (output_bfd
,
2332 h
&& ! FRV_SYM_LOCAL (info
, h
)
2334 : _frv_osec_to_segment (output_bfd
,
2335 sec
->output_section
),
2336 contents
+ rel
->r_offset
+ 4);
2339 check_segment
[0] = check_segment
[1] = got_segment
;
2343 case R_FRV_GPRELU12
:
2347 check_segment
[0] = gprel_segment
;
2348 check_segment
[1] = sec
2349 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2354 check_segment
[0] = isec_segment
;
2355 check_segment
[1] = sec
2356 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2361 if (check_segment
[0] != check_segment
[1]
2362 && (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
))
2365 /* This helps catch problems in GCC while we can't do more
2366 than static linking. The idea is to test whether the
2367 input file basename is crt0.o only once. */
2368 if (silence_segment_error
== 1)
2369 silence_segment_error
=
2370 (strlen (input_bfd
->filename
) == 6
2371 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
2372 || (strlen (input_bfd
->filename
) > 6
2373 && strcmp (input_bfd
->filename
2374 + strlen (input_bfd
->filename
) - 7,
2378 if (!silence_segment_error
2379 /* We don't want duplicate errors for undefined
2381 && !(picrel
&& picrel
->symndx
== -1
2382 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
2383 info
->callbacks
->warning
2385 (info
->shared
|| info
->pie
)
2386 ? _("relocations between different segments are not supported")
2387 : _("warning: relocation references a different segment"),
2388 name
, input_bfd
, input_section
, rel
->r_offset
);
2389 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
2391 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
2396 case R_FRV_GOTOFFHI
:
2397 /* We need the addend to be applied before we shift the
2399 relocation
+= rel
->r_addend
;
2402 case R_FRV_FUNCDESC_GOTHI
:
2403 case R_FRV_FUNCDESC_GOTOFFHI
:
2408 case R_FRV_FUNCDESC_GOTLO
:
2409 case R_FRV_GOTOFFLO
:
2410 case R_FRV_FUNCDESC_GOTOFFLO
:
2411 relocation
&= 0xffff;
2425 /* When referencing a GOT entry, a function descriptor or a
2426 PLT, we don't want the addend to apply to the reference,
2427 but rather to the referenced symbol. The actual entry
2428 will have already been created taking the addend into
2429 account, so cancel it out here. */
2433 case R_FRV_FUNCDESC_GOT12
:
2434 case R_FRV_FUNCDESC_GOTHI
:
2435 case R_FRV_FUNCDESC_GOTLO
:
2436 case R_FRV_FUNCDESC_GOTOFF12
:
2437 case R_FRV_FUNCDESC_GOTOFFHI
:
2438 case R_FRV_FUNCDESC_GOTOFFLO
:
2439 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
2440 here, since we do want to apply the addend to the others.
2441 Note that we've applied the addend to GOTOFFHI before we
2442 shifted it right. */
2443 case R_FRV_GOTOFFHI
:
2444 relocation
-= rel
->r_addend
;
2451 if (r_type
== R_FRV_HI16
)
2452 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
2454 else if (r_type
== R_FRV_LO16
)
2455 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
2457 else if (r_type
== R_FRV_LABEL24
)
2458 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
2459 contents
, relocation
);
2461 else if (r_type
== R_FRV_GPREL12
)
2462 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
2463 contents
, relocation
);
2465 else if (r_type
== R_FRV_GPRELU12
)
2466 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
2467 contents
, relocation
);
2469 else if (r_type
== R_FRV_GPRELLO
)
2470 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
2471 contents
, relocation
);
2473 else if (r_type
== R_FRV_GPRELHI
)
2474 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
2475 contents
, relocation
);
2478 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
2481 if (r
!= bfd_reloc_ok
)
2483 const char * msg
= (const char *) NULL
;
2487 case bfd_reloc_overflow
:
2488 r
= info
->callbacks
->reloc_overflow
2489 (info
, name
, howto
->name
, (bfd_vma
) 0,
2490 input_bfd
, input_section
, rel
->r_offset
);
2493 case bfd_reloc_undefined
:
2494 r
= info
->callbacks
->undefined_symbol
2495 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
2498 case bfd_reloc_outofrange
:
2499 msg
= _("internal error: out of range error");
2502 case bfd_reloc_notsupported
:
2503 msg
= _("internal error: unsupported relocation error");
2506 case bfd_reloc_dangerous
:
2507 msg
= _("internal error: dangerous relocation");
2511 msg
= _("internal error: unknown error");
2516 r
= info
->callbacks
->warning
2517 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
2527 /* Return the section that should be marked against GC for a given
2531 elf32_frv_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2533 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2534 Elf_Internal_Rela
*rel
;
2535 struct elf_link_hash_entry
*h
;
2536 Elf_Internal_Sym
*sym
;
2540 switch (ELF32_R_TYPE (rel
->r_info
))
2542 case R_FRV_GNU_VTINHERIT
:
2543 case R_FRV_GNU_VTENTRY
:
2547 switch (h
->root
.type
)
2552 case bfd_link_hash_defined
:
2553 case bfd_link_hash_defweak
:
2554 return h
->root
.u
.def
.section
;
2556 case bfd_link_hash_common
:
2557 return h
->root
.u
.c
.p
->section
;
2562 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2567 /* Update the got entry reference counts for the section being removed. */
2570 elf32_frv_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2571 bfd
*abfd ATTRIBUTE_UNUSED
;
2572 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2573 asection
*sec ATTRIBUTE_UNUSED
;
2574 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2580 /* Hook called by the linker routine which adds symbols from an object
2581 file. We use it to put .comm items in .scomm, and not .comm. */
2584 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2586 struct bfd_link_info
*info
;
2587 const Elf_Internal_Sym
*sym
;
2588 const char **namep ATTRIBUTE_UNUSED
;
2589 flagword
*flagsp ATTRIBUTE_UNUSED
;
2593 if (sym
->st_shndx
== SHN_COMMON
2594 && !info
->relocatable
2595 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
2597 /* Common symbols less than or equal to -G nn bytes are
2598 automatically put into .sbss. */
2600 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
2604 scomm
= bfd_make_section (abfd
, ".scommon");
2606 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
2608 | SEC_LINKER_CREATED
)))
2613 *valp
= sym
->st_size
;
2618 /* Create a .got section, as well as its additional info field. This
2619 is almost entirely copied from
2620 elflink.c:_bfd_elf_create_got_section(). */
2623 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
2627 struct elf_link_hash_entry
*h
;
2628 struct bfd_link_hash_entry
*bh
;
2629 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2632 /* This function may be called more than once. */
2633 s
= bfd_get_section_by_name (abfd
, ".got");
2634 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
2637 /* Machine specific: although pointers are 32-bits wide, we want the
2638 GOT to be aligned to a 64-bit boundary, such that function
2639 descriptors in it can be accessed with 64-bit loads and
2643 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2644 | SEC_LINKER_CREATED
);
2646 s
= bfd_make_section (abfd
, ".got");
2648 || !bfd_set_section_flags (abfd
, s
, flags
)
2649 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
2652 if (bed
->want_got_plt
)
2654 s
= bfd_make_section (abfd
, ".got.plt");
2656 || !bfd_set_section_flags (abfd
, s
, flags
)
2657 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
2661 if (bed
->want_got_sym
)
2663 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
2664 (or .got.plt) section. We don't do this in the linker script
2665 because we don't want to define the symbol if we are not creating
2666 a global offset table. */
2668 if (!(_bfd_generic_link_add_one_symbol
2669 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
2670 bed
->got_symbol_offset
, (const char *) NULL
, FALSE
,
2671 bed
->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 /* Machine-specific: we want the symbol for executables as
2679 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2682 elf_hash_table (info
)->hgot
= h
;
2685 /* The first bit of the global offset table is the header. */
2686 s
->_raw_size
+= bed
->got_header_size
+ bed
->got_symbol_offset
;
2688 /* This is the machine-specific part. Create and initialize section
2689 data for the got. */
2690 frv_got_section (info
) = s
;
2691 frv_relocs_info (info
) = htab_try_create (1, frv_pic_relocs_info_hash
,
2692 frv_pic_relocs_info_eq
,
2694 if (! frv_relocs_info (info
))
2697 s
= bfd_make_section (abfd
, ".rel.got");
2699 || ! bfd_set_section_flags (abfd
, s
, (flags
| SEC_READONLY
))
2700 || ! bfd_set_section_alignment (abfd
, s
, 2))
2703 frv_gotrel_section (info
) = s
;
2705 /* Machine-specific. */
2706 s
= bfd_make_section (abfd
, ".rofixup");
2708 || ! bfd_set_section_flags (abfd
, s
, (flags
| SEC_READONLY
))
2709 || ! bfd_set_section_alignment (abfd
, s
, 2))
2712 frv_gotfixup_section (info
) = s
;
2714 /* Define _gp in .rofixup, for FDPIC. If it turns out that
2715 we're linking with a different linker script, the linker script
2716 will override it. */
2718 if (!(_bfd_generic_link_add_one_symbol
2719 (info
, abfd
, "_gp", BSF_GLOBAL
, s
, -2048, (const char *) NULL
, FALSE
,
2720 bed
->collect
, &bh
)))
2722 h
= (struct elf_link_hash_entry
*) bh
;
2723 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2724 h
->type
= STT_OBJECT
;
2726 /* Machine-specific: we want the symbol for executables as well. */
2727 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2733 /* Make sure the got and plt sections exist, and that our pointers in
2734 the link hash table point to them. */
2737 elf32_frv_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2739 /* This is mostly copied from
2740 elflink.c:_bfd_elf_create_dynamic_sections(). */
2741 flagword flags
, pltflags
;
2743 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2745 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2746 .rel[a].bss sections. */
2748 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2749 | SEC_LINKER_CREATED
);
2752 pltflags
|= SEC_CODE
;
2753 if (bed
->plt_not_loaded
)
2754 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
2755 if (bed
->plt_readonly
)
2756 pltflags
|= SEC_READONLY
;
2758 s
= bfd_make_section (abfd
, ".plt");
2760 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
2761 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
2763 /* FRV-specific: remember it. */
2764 frv_plt_section (info
) = s
;
2766 if (bed
->want_plt_sym
)
2768 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2770 struct elf_link_hash_entry
*h
;
2771 struct bfd_link_hash_entry
*bh
= NULL
;
2773 if (! (_bfd_generic_link_add_one_symbol
2774 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
, 0, NULL
,
2775 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2777 h
= (struct elf_link_hash_entry
*) bh
;
2778 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2779 h
->type
= STT_OBJECT
;
2781 if (! info
->executable
2782 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2786 /* FRV-specific: we want rel relocations for the plt. */
2787 s
= bfd_make_section (abfd
, ".rel.plt");
2789 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2790 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
2792 /* FRV-specific: remember it. */
2793 frv_pltrel_section (info
) = s
;
2795 /* FRV-specific: we want to create the GOT in the FRV way. */
2796 if (! _frv_create_got_section (abfd
, info
))
2799 /* FRV-specific: make sure we created everything we wanted. */
2800 BFD_ASSERT (frv_got_section (info
) && frv_gotrel_section (info
)
2801 && frv_gotfixup_section (info
)
2802 && frv_plt_section (info
) && frv_pltrel_section (info
));
2804 if (bed
->want_dynbss
)
2806 /* The .dynbss section is a place to put symbols which are defined
2807 by dynamic objects, are referenced by regular objects, and are
2808 not functions. We must allocate space for them in the process
2809 image and use a R_*_COPY reloc to tell the dynamic linker to
2810 initialize them at run time. The linker script puts the .dynbss
2811 section into the .bss section of the final image. */
2812 s
= bfd_make_section (abfd
, ".dynbss");
2814 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
2817 /* The .rel[a].bss section holds copy relocs. This section is not
2818 normally needed. We need to create it here, though, so that the
2819 linker will map it to an output section. We can't just create it
2820 only if we need it, because we will not know whether we need it
2821 until we have seen all the input files, and the first time the
2822 main linker code calls BFD after examining all the input files
2823 (size_dynamic_sections) the input sections have already been
2824 mapped to the output sections. If the section turns out not to
2825 be needed, we can discard it later. We will never need this
2826 section when generating a shared object, since they do not use
2830 s
= bfd_make_section (abfd
,
2831 (bed
->default_use_rela_p
2832 ? ".rela.bss" : ".rel.bss"));
2834 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2835 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
2843 /* The name of the dynamic interpreter. This is put in the .interp
2846 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2848 #define DEFAULT_STACK_SIZE 0x20000
2850 /* This structure is used to collect the number of entries present in
2851 each addressable range of the got. */
2852 struct _frv_dynamic_got_info
2854 /* Several bits of information about the current link. */
2855 struct bfd_link_info
*info
;
2856 /* Total size needed for GOT entries within the 12-, 16- or 32-bit
2858 bfd_vma got12
, gotlos
, gothilo
;
2859 /* Total size needed for function descriptor entries within the 12-,
2860 16- or 32-bit ranges. */
2861 bfd_vma fd12
, fdlos
, fdhilo
;
2862 /* Total size needed function descriptor entries referenced in PLT
2863 entries, that would be profitable to place in offsets close to
2864 the PIC register. */
2866 /* Total size needed by lazy PLT entries. */
2868 /* Number of relocations carried over from input object files. */
2869 unsigned long relocs
;
2870 /* Number of fixups introduced by relocations in input object files. */
2871 unsigned long fixups
;
2874 /* Compute the total GOT size required by each symbol in each range.
2875 Symbols may require up to 4 words in the GOT: an entry pointing to
2876 the symbol, an entry pointing to its function descriptor, and a
2877 private function descriptors taking two words. */
2880 _frv_count_got_plt_entries (void **entryp
, void *dinfo_
)
2882 struct frv_pic_relocs_info
*entry
= *entryp
;
2883 struct _frv_dynamic_got_info
*dinfo
= dinfo_
;
2884 unsigned relocs
= 0, fixups
= 0;
2886 /* Allocate space for a GOT entry pointing to the symbol. */
2889 else if (entry
->gotlos
)
2891 else if (entry
->gothilo
)
2892 dinfo
->gothilo
+= 4;
2897 /* Allocate space for a GOT entry pointing to the function
2901 else if (entry
->fdgotlos
)
2903 else if (entry
->fdgothilo
)
2904 dinfo
->gothilo
+= 4;
2909 /* Decide whether we need a PLT entry, a function descriptor in the
2910 GOT, and a lazy PLT entry for this symbol. */
2911 entry
->plt
= entry
->call
2912 && entry
->symndx
== -1 && ! FRV_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
2913 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
2914 entry
->privfd
= entry
->plt
2915 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
2916 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
2917 && (entry
->symndx
!= -1
2918 || FRV_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
2919 entry
->lazyplt
= entry
->privfd
2920 && entry
->symndx
== -1 && ! FRV_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
2921 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
2922 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
2924 /* Allocate space for a function descriptor. */
2925 if (entry
->fdgoff12
)
2927 else if (entry
->fdgofflos
)
2929 else if (entry
->privfd
&& entry
->plt
)
2931 else if (entry
->privfd
)
2940 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
2941 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
;
2944 if (entry
->symndx
!= -1 || FRV_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
2946 if (entry
->symndx
!= -1
2947 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
2948 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
2951 relocs
+= entry
->relocs32
+ entry
->relocsfdv
;
2953 if (entry
->symndx
!= -1 || FRV_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
2955 if (entry
->symndx
!= -1
2956 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
2957 fixups
+= entry
->relocsfd
;
2960 relocs
+= entry
->relocsfd
;
2963 entry
->dynrelocs
+= relocs
;
2964 entry
->fixups
+= fixups
;
2965 dinfo
->relocs
+= relocs
;
2966 dinfo
->fixups
+= fixups
;
2971 /* This structure is used to assign offsets to got entries, function
2972 descriptors, plt entries and lazy plt entries. */
2974 struct _frv_dynamic_got_plt_info
2976 /* Summary information collected with _frv_count_got_plt_entries. */
2977 struct _frv_dynamic_got_info g
;
2979 /* For each addressable range, we record a MAX (positive) and MIN
2980 (negative) value. CUR is used to assign got entries, and it's
2981 incremented from an initial positive value to MAX, then from MIN
2982 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
2983 assign function descriptors, and it's decreased from an initial
2984 non-positive value to MIN, then from MAX down to CUR (unless CUR
2985 wraps around first). All of MIN, MAX, CUR and FDCUR always point
2986 to even words. ODD, if non-zero, indicates an odd word to be
2987 used for the next got entry, otherwise CUR is used and
2988 incremented by a pair of words, wrapping around when it reaches
2989 MAX. FDCUR is decremented (and wrapped) before the next function
2990 descriptor is chosen. FDPLT indicates the number of remaining
2991 slots that can be used for function descriptors used only by PLT
2993 struct _frv_dynamic_got_alloc_data
2995 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
2997 } got12
, gotlos
, gothilo
;
3000 /* Determine the positive and negative ranges to be used by each
3001 offset range in the GOT. FDCUR and CUR, that must be aligned to a
3002 double-word boundary, are the minimum (negative) and maximum
3003 (positive) GOT offsets already used by previous ranges, except for
3004 an ODD entry that may have been left behind. GOT and FD indicate
3005 the size of GOT entries and function descriptors that must be
3006 placed within the range from -WRAP to WRAP. If there's room left,
3007 up to FDPLT bytes should be reserved for additional function
3010 inline static bfd_signed_vma
3011 _frv_compute_got_alloc_data (struct _frv_dynamic_got_alloc_data
*gad
,
3012 bfd_signed_vma fdcur
,
3020 bfd_signed_vma wrapmin
= -wrap
;
3022 /* Start at the given initial points. */
3026 /* If we had an incoming odd word and we have any got entries that
3027 are going to use it, consume it, otherwise leave gad->odd at
3028 zero. We might force gad->odd to zero and return the incoming
3029 odd such that it is used by the next range, but then GOT entries
3030 might appear to be out of order and we wouldn't be able to
3031 shorten the GOT by one word if it turns out to end with an
3032 unpaired GOT entry. */
3042 /* If we're left with an unpaired GOT entry, compute its location
3043 such that we can return it. Otherwise, if got doesn't require an
3044 odd number of words here, either odd was already zero in the
3045 block above, or it was set to zero because got was non-zero, or
3046 got was already zero. In the latter case, we want the value of
3047 odd to carry over to the return statement, so we don't want to
3048 reset odd unless the condition below is true. */
3055 /* Compute the tentative boundaries of this range. */
3056 gad
->max
= cur
+ got
;
3057 gad
->min
= fdcur
- fd
;
3060 /* If function descriptors took too much space, wrap some of them
3062 if (gad
->min
< wrapmin
)
3064 gad
->max
+= wrapmin
- gad
->min
;
3067 /* If there is space left and we have function descriptors
3068 referenced in PLT entries that could take advantage of shorter
3069 offsets, place them here. */
3070 else if (fdplt
&& gad
->min
> wrapmin
)
3073 if ((bfd_vma
) (gad
->min
- wrapmin
) < fdplt
)
3074 fds
= gad
->min
- wrapmin
;
3083 /* If GOT entries took too much space, wrap some of them around.
3084 This may well cause gad->min to become lower than wrapmin. This
3085 will cause a relocation overflow later on, so we don't have to
3087 if ((bfd_vma
) gad
->max
> wrap
)
3089 gad
->min
-= gad
->max
- wrap
;
3092 /* If there is more space left, try to place some more function
3093 descriptors for PLT entries. */
3094 else if (fdplt
&& (bfd_vma
) gad
->max
< wrap
)
3097 if ((bfd_vma
) (wrap
- gad
->max
) < fdplt
)
3098 fds
= wrap
- gad
->max
;
3107 /* If odd was initially computed as an offset past the wrap point,
3110 odd
= gad
->min
+ odd
- gad
->max
;
3112 /* _frv_get_got_entry() below will always wrap gad->cur if needed
3113 before returning, so do it here too. This guarantees that,
3114 should cur and fdcur meet at the wrap point, they'll both be
3116 if (gad
->cur
== gad
->max
)
3117 gad
->cur
= gad
->min
;
3122 /* Compute the location of the next GOT entry, given the allocation
3123 data for a range. */
3125 inline static bfd_signed_vma
3126 _frv_get_got_entry (struct _frv_dynamic_got_alloc_data
*gad
)
3132 /* If there was an odd word left behind, use it. */
3138 /* Otherwise, use the word pointed to by cur, reserve the next
3139 as an odd word, and skip to the next pair of words, possibly
3142 gad
->odd
= gad
->cur
+ 4;
3144 if (gad
->cur
== gad
->max
)
3145 gad
->cur
= gad
->min
;
3151 /* Compute the location of the next function descriptor entry in the
3152 GOT, given the allocation data for a range. */
3154 inline static bfd_signed_vma
3155 _frv_get_fd_entry (struct _frv_dynamic_got_alloc_data
*gad
)
3157 /* If we're at the bottom, wrap around, and only then allocate the
3158 next pair of words. */
3159 if (gad
->fdcur
== gad
->min
)
3160 gad
->fdcur
= gad
->max
;
3161 return gad
->fdcur
-= 8;
3164 /* Assign GOT offsets for every GOT entry and function descriptor.
3165 Doing everything in a single pass is tricky. */
3168 _frv_assign_got_entries (void **entryp
, void *info_
)
3170 struct frv_pic_relocs_info
*entry
= *entryp
;
3171 struct _frv_dynamic_got_plt_info
*dinfo
= info_
;
3174 entry
->got_entry
= _frv_get_got_entry (&dinfo
->got12
);
3175 else if (entry
->gotlos
)
3176 entry
->got_entry
= _frv_get_got_entry (&dinfo
->gotlos
);
3177 else if (entry
->gothilo
)
3178 entry
->got_entry
= _frv_get_got_entry (&dinfo
->gothilo
);
3181 entry
->fdgot_entry
= _frv_get_got_entry (&dinfo
->got12
);
3182 else if (entry
->fdgotlos
)
3183 entry
->fdgot_entry
= _frv_get_got_entry (&dinfo
->gotlos
);
3184 else if (entry
->fdgothilo
)
3185 entry
->fdgot_entry
= _frv_get_got_entry (&dinfo
->gothilo
);
3187 if (entry
->fdgoff12
)
3188 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->got12
);
3189 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
3191 dinfo
->got12
.fdplt
-= 8;
3192 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->got12
);
3194 else if (entry
->fdgofflos
)
3195 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gotlos
);
3196 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
3198 dinfo
->gotlos
.fdplt
-= 8;
3199 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gotlos
);
3201 else if (entry
->plt
)
3203 dinfo
->gothilo
.fdplt
-= 8;
3204 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gothilo
);
3206 else if (entry
->privfd
)
3207 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gothilo
);
3212 /* Assign GOT offsets to private function descriptors used by PLT
3213 entries (or referenced by 32-bit offsets), as well as PLT entries
3214 and lazy PLT entries. */
3217 _frv_assign_plt_entries (void **entryp
, void *info_
)
3219 struct frv_pic_relocs_info
*entry
= *entryp
;
3220 struct _frv_dynamic_got_plt_info
*dinfo
= info_
;
3222 /* If this symbol requires a local function descriptor, allocate
3224 if (entry
->privfd
&& entry
->fd_entry
== 0)
3226 if (dinfo
->got12
.fdplt
)
3228 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->got12
);
3229 dinfo
->got12
.fdplt
-= 8;
3231 else if (dinfo
->gotlos
.fdplt
)
3233 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gotlos
);
3234 dinfo
->gotlos
.fdplt
-= 8;
3238 BFD_ASSERT (dinfo
->gothilo
.fdplt
)
3239 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gothilo
);
3240 dinfo
->gothilo
.fdplt
-= 8;
3248 /* We use the section's raw size to mark the location of the
3250 entry
->plt_entry
= frv_plt_section (dinfo
->g
.info
)->_raw_size
;
3252 /* Figure out the length of this PLT entry based on the
3253 addressing mode we need to reach the function descriptor. */
3254 BFD_ASSERT (entry
->fd_entry
);
3255 if (entry
->fd_entry
>= -(1 << (12 - 1))
3256 && entry
->fd_entry
< (1 << (12 - 1)))
3258 else if (entry
->fd_entry
>= -(1 << (16 - 1))
3259 && entry
->fd_entry
< (1 << (16 - 1)))
3264 frv_plt_section (dinfo
->g
.info
)->_raw_size
+= size
;
3269 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
3270 dinfo
->g
.lzplt
+= 8;
3271 /* If this entry is the one that gets the resolver stub, account
3272 for the additional instruction. */
3273 if (entry
->lzplt_entry
% FRV_LZPLT_BLOCK_SIZE
== FRV_LZPLT_RESOLV_LOC
)
3274 dinfo
->g
.lzplt
+= 4;
3280 /* Follow indirect and warning hash entries so that each got entry
3281 points to the final symbol definition. P must point to a pointer
3282 to the hash table we're traversing. Since this traversal may
3283 modify the hash table, we set this pointer to NULL to indicate
3284 we've made a potentially-destructive change to the hash table, so
3285 the traversal must be restarted. */
3287 _frv_resolve_final_relocs_info (void **entryp
, void *p
)
3289 struct frv_pic_relocs_info
*entry
= *entryp
;
3292 if (entry
->symndx
== -1)
3294 struct elf_link_hash_entry
*h
= entry
->d
.h
;
3295 struct frv_pic_relocs_info
*oentry
;
3297 while (h
->root
.type
== bfd_link_hash_indirect
3298 || h
->root
.type
== bfd_link_hash_warning
)
3299 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
3301 if (entry
->d
.h
== h
)
3304 oentry
= frv_pic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
3309 /* Merge the two entries. */
3310 frv_pic_merge_early_relocs_info (oentry
, entry
);
3311 htab_clear_slot (*htab
, entryp
);
3317 /* If we can't find this entry with the new bfd hash, re-insert
3318 it, and get the traversal restarted. */
3319 if (! htab_find (*htab
, entry
))
3321 htab_clear_slot (*htab
, entryp
);
3322 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
3325 /* Abort the traversal, since the whole table may have
3326 moved, and leave it up to the parent to restart the
3328 *(htab_t
*)p
= NULL
;
3336 /* Set the sizes of the dynamic sections. */
3339 elf32_frv_size_dynamic_sections (bfd
*output_bfd
,
3340 struct bfd_link_info
*info
)
3344 struct _frv_dynamic_got_plt_info gpinfo
;
3348 dynobj
= elf_hash_table (info
)->dynobj
;
3349 BFD_ASSERT (dynobj
!= NULL
);
3351 if (elf_hash_table (info
)->dynamic_sections_created
)
3353 /* Set the contents of the .interp section to the interpreter. */
3354 if (info
->executable
)
3356 s
= bfd_get_section_by_name (dynobj
, ".interp");
3357 BFD_ASSERT (s
!= NULL
);
3358 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3359 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
3363 memset (&gpinfo
, 0, sizeof (gpinfo
));
3364 gpinfo
.g
.info
= info
;
3368 htab_t relocs
= frv_relocs_info (info
);
3370 htab_traverse (relocs
, _frv_resolve_final_relocs_info
, &relocs
);
3372 if (relocs
== frv_relocs_info (info
))
3376 htab_traverse (frv_relocs_info (info
), _frv_count_got_plt_entries
,
3380 /* Compute the total size taken by entries in the 12-bit and 16-bit
3381 ranges, to tell how many PLT function descriptors we can bring
3382 into the 12-bit range without causing the 16-bit range to
3384 limit
= odd
+ gpinfo
.g
.got12
+ gpinfo
.g
.gotlos
3385 + gpinfo
.g
.fd12
+ gpinfo
.g
.fdlos
;
3386 if (limit
< (bfd_vma
)1 << 16)
3387 limit
= ((bfd_vma
)1 << 16) - limit
;
3390 if (gpinfo
.g
.fdplt
< limit
)
3391 limit
= gpinfo
.g
.fdplt
;
3393 /* Determine the ranges of GOT offsets that we can use for each
3394 range of addressing modes. */
3395 odd
= _frv_compute_got_alloc_data (&gpinfo
.got12
,
3402 (bfd_vma
)1 << (12-1));
3403 odd
= _frv_compute_got_alloc_data (&gpinfo
.gotlos
,
3409 gpinfo
.g
.fdplt
- gpinfo
.got12
.fdplt
,
3410 (bfd_vma
)1 << (16-1));
3411 odd
= _frv_compute_got_alloc_data (&gpinfo
.gothilo
,
3417 gpinfo
.g
.fdplt
- gpinfo
.got12
.fdplt
3418 - gpinfo
.gotlos
.fdplt
,
3419 (bfd_vma
)1 << (32-1));
3421 /* Now assign (most) GOT offsets. */
3422 htab_traverse (frv_relocs_info (info
), _frv_assign_got_entries
, &gpinfo
);
3424 frv_got_section (info
)->_raw_size
= gpinfo
.gothilo
.max
- gpinfo
.gothilo
.min
3425 /* If an odd word is the last word of the GOT, we don't need this
3426 word to be part of the GOT. */
3427 - (odd
+ 4 == gpinfo
.gothilo
.max
? 4 : 0);
3428 if (frv_got_section (info
)->_raw_size
== 0)
3429 frv_got_section (info
)->flags
|= SEC_EXCLUDE
;
3430 else if (frv_got_section (info
)->_raw_size
== 12
3431 && ! elf_hash_table (info
)->dynamic_sections_created
)
3433 frv_got_section (info
)->flags
|= SEC_EXCLUDE
;
3434 frv_got_section (info
)->_raw_size
= 0;
3438 frv_got_section (info
)->contents
=
3439 (bfd_byte
*) bfd_zalloc (dynobj
, frv_got_section (info
)->_raw_size
);
3440 if (frv_got_section (info
)->contents
== NULL
)
3444 if (elf_hash_table (info
)->dynamic_sections_created
)
3445 /* Subtract the number of lzplt entries, since those will generate
3446 relocations in the pltrel section. */
3447 frv_gotrel_section (info
)->_raw_size
=
3448 (gpinfo
.g
.relocs
- gpinfo
.g
.lzplt
/ 8)
3449 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
3451 BFD_ASSERT (gpinfo
.g
.relocs
== 0);
3452 if (frv_gotrel_section (info
)->_raw_size
== 0)
3453 frv_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
3456 frv_gotrel_section (info
)->contents
=
3457 (bfd_byte
*) bfd_zalloc (dynobj
, frv_gotrel_section (info
)->_raw_size
);
3458 if (frv_gotrel_section (info
)->contents
== NULL
)
3462 if (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3463 frv_gotfixup_section (info
)->_raw_size
= (gpinfo
.g
.fixups
+ 1) * 4;
3464 if (frv_gotfixup_section (info
)->_raw_size
== 0)
3465 frv_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
3468 frv_gotfixup_section (info
)->contents
=
3469 (bfd_byte
*) bfd_zalloc (dynobj
,
3470 frv_gotfixup_section (info
)->_raw_size
);
3471 if (frv_gotfixup_section (info
)->contents
== NULL
)
3475 if (elf_hash_table (info
)->dynamic_sections_created
)
3477 frv_pltrel_section (info
)->_raw_size
=
3478 gpinfo
.g
.lzplt
/ 8 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
3479 if (frv_pltrel_section (info
)->_raw_size
== 0)
3480 frv_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
3483 frv_pltrel_section (info
)->contents
=
3484 (bfd_byte
*) bfd_zalloc (dynobj
,
3485 frv_pltrel_section (info
)->_raw_size
);
3486 if (frv_pltrel_section (info
)->contents
== NULL
)
3491 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3492 such that there's room for the additional instruction needed to
3493 call the resolver. Since _frv_assign_got_entries didn't account
3494 for them, our block size is 4 bytes smaller than the real block
3496 if (elf_hash_table (info
)->dynamic_sections_created
)
3498 frv_plt_section (info
)->_raw_size
= gpinfo
.g
.lzplt
3499 + ((gpinfo
.g
.lzplt
+ (FRV_LZPLT_BLOCK_SIZE
- 4) - 8)
3500 / (FRV_LZPLT_BLOCK_SIZE
- 4) * 4);
3503 /* Reset it, such that _frv_assign_plt_entries() can use it to
3504 actually assign lazy PLT entries addresses. */
3507 /* Save information that we're going to need to generate GOT and PLT
3509 frv_got_initial_offset (info
) = -gpinfo
.gothilo
.min
;
3511 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
3512 elf_hash_table (info
)->hgot
->root
.u
.def
.value
3513 += frv_got_initial_offset (info
);
3515 if (elf_hash_table (info
)->dynamic_sections_created
)
3516 frv_plt_initial_offset (info
) = frv_plt_section (info
)->_raw_size
;
3518 htab_traverse (frv_relocs_info (info
), _frv_assign_plt_entries
, &gpinfo
);
3520 /* Allocate the PLT section contents only after
3521 _frv_assign_plt_entries has a chance to add the size of the
3522 non-lazy PLT entries. */
3523 if (elf_hash_table (info
)->dynamic_sections_created
)
3525 if (frv_plt_section (info
)->_raw_size
== 0)
3526 frv_plt_section (info
)->flags
|= SEC_EXCLUDE
;
3529 frv_plt_section (info
)->contents
=
3530 (bfd_byte
*) bfd_zalloc (dynobj
, frv_plt_section (info
)->_raw_size
);
3531 if (frv_plt_section (info
)->contents
== NULL
)
3536 if (elf_hash_table (info
)->dynamic_sections_created
)
3538 if (frv_got_section (info
)->_raw_size
)
3539 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
3542 if (frv_pltrel_section (info
)->_raw_size
)
3543 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3544 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
3545 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
3548 if (frv_gotrel_section (info
)->_raw_size
)
3549 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0)
3550 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0)
3551 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
,
3552 sizeof (Elf32_External_Rel
)))
3560 elf32_frv_always_size_sections (bfd
*output_bfd
,
3561 struct bfd_link_info
*info
)
3563 if (!info
->relocatable
3564 && elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3566 struct elf_link_hash_entry
*h
;
3569 /* Force a PT_GNU_STACK segment to be created. */
3570 if (! elf_tdata (output_bfd
)->stack_flags
)
3571 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
3573 /* Define __stacksize if it's not defined yet. */
3574 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3575 FALSE
, FALSE
, FALSE
);
3576 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
3577 || h
->type
!= STT_OBJECT
3578 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3580 struct bfd_link_hash_entry
*bh
= NULL
;
3582 if (!(_bfd_generic_link_add_one_symbol
3583 (info
, output_bfd
, "__stacksize",
3584 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
3585 (const char *) NULL
, FALSE
,
3586 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
3589 h
= (struct elf_link_hash_entry
*) bh
;
3590 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3591 h
->type
= STT_OBJECT
;
3594 /* Create a stack section, and set its alignment. */
3595 sec
= bfd_make_section (output_bfd
, ".stack");
3598 || ! bfd_set_section_alignment (output_bfd
, sec
, 3))
3606 elf32_frv_modify_segment_map (bfd
*output_bfd
,
3607 struct bfd_link_info
*info
)
3609 if (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3611 struct elf_segment_map
*m
;
3613 for (m
= elf_tdata (output_bfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3614 if (m
->p_type
== PT_GNU_STACK
)
3619 asection
*sec
= bfd_get_section_by_name (output_bfd
, ".stack");
3620 struct elf_link_hash_entry
*h
;
3624 /* Obtain the pointer to the __stacksize symbol. */
3625 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3626 FALSE
, FALSE
, FALSE
);
3627 while (h
->root
.type
== bfd_link_hash_indirect
3628 || h
->root
.type
== bfd_link_hash_warning
)
3629 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
3630 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
3632 /* Set the section size from the symbol value. We
3633 intentionally ignore the symbol section. */
3634 if (h
->root
.type
== bfd_link_hash_defined
)
3635 sec
->_raw_size
= h
->root
.u
.def
.value
;
3637 sec
->_raw_size
= DEFAULT_STACK_SIZE
;
3639 /* Add the stack section to the PT_GNU_STACK segment,
3640 such that its size and alignment requirements make it
3642 m
->sections
[m
->count
] = sec
;
3651 /* Fill in code and data in dynamic sections. */
3654 elf32_frv_finish_dynamic_sections (bfd
*output_bfd
,
3655 struct bfd_link_info
*info
)
3660 dynobj
= elf_hash_table (info
)->dynobj
;
3662 if (frv_got_section (info
))
3664 BFD_ASSERT (frv_gotrel_section (info
)->_raw_size
3665 == (frv_gotrel_section (info
)->reloc_count
3666 * sizeof (Elf32_External_Rel
)));
3668 if (frv_gotfixup_section (info
))
3670 if (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3672 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
3673 bfd_vma got_value
= hgot
->root
.u
.def
.value
3674 + hgot
->root
.u
.def
.section
->output_section
->vma
3675 + hgot
->root
.u
.def
.section
->output_offset
;
3677 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
3681 if (frv_gotfixup_section (info
)->_raw_size
3682 != (frv_gotfixup_section (info
)->reloc_count
* 4))
3684 if (frv_gotfixup_section (info
)->_raw_size
3685 < frv_gotfixup_section (info
)->reloc_count
* 4)
3687 info
->callbacks
->warning
3688 (info
, "LINKER BUG: .rofixup section size mismatch",
3689 ".rofixup", NULL
, NULL
, 0);
3693 else if (!elf_hash_table (info
)->dynamic_sections_created
)
3695 info
->callbacks
->warning
3696 (info
, "no dynamic sections, missing -melf32frvfd?",
3697 ".rofixup", NULL
, NULL
, 0);
3704 if (elf_hash_table (info
)->dynamic_sections_created
)
3706 BFD_ASSERT (frv_pltrel_section (info
)->_raw_size
3707 == (frv_pltrel_section (info
)->reloc_count
3708 * sizeof (Elf32_External_Rel
)));
3711 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3713 if (elf_hash_table (info
)->dynamic_sections_created
)
3715 Elf32_External_Dyn
* dyncon
;
3716 Elf32_External_Dyn
* dynconend
;
3718 BFD_ASSERT (sdyn
!= NULL
);
3720 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3721 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3723 for (; dyncon
< dynconend
; dyncon
++)
3725 Elf_Internal_Dyn dyn
;
3727 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3735 dyn
.d_un
.d_ptr
= frv_got_section (info
)->output_section
->vma
3736 + frv_got_section (info
)->output_offset
3737 + frv_got_initial_offset (info
);
3738 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3742 dyn
.d_un
.d_ptr
= frv_pltrel_section (info
)->output_section
->vma
3743 + frv_pltrel_section (info
)->output_offset
;
3744 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3748 if (frv_pltrel_section (info
)->_cooked_size
!= 0)
3749 dyn
.d_un
.d_val
= frv_pltrel_section (info
)->_cooked_size
;
3751 dyn
.d_un
.d_val
= frv_pltrel_section (info
)->_raw_size
;
3752 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3761 /* Adjust a symbol defined by a dynamic object and referenced by a
3765 elf32_frv_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3766 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
3770 dynobj
= elf_hash_table (info
)->dynobj
;
3772 /* Make sure we know what is going on here. */
3773 BFD_ASSERT (dynobj
!= NULL
3774 && (h
->weakdef
!= NULL
3775 || ((h
->elf_link_hash_flags
3776 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3777 && (h
->elf_link_hash_flags
3778 & ELF_LINK_HASH_REF_REGULAR
) != 0
3779 && (h
->elf_link_hash_flags
3780 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3782 /* If this is a weak symbol, and there is a real definition, the
3783 processor independent code will have arranged for us to see the
3784 real definition first, and we can just use the same value. */
3785 if (h
->weakdef
!= NULL
)
3787 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3788 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3789 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3790 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3796 /* Perform any actions needed for dynamic symbols. */
3799 elf32_frv_finish_dynamic_symbol (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3800 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3801 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
3802 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
3807 /* Decide whether to attempt to turn absptr or lsda encodings in
3808 shared libraries into pcrel within the given input section. */
3811 frv_elf_use_relative_eh_frame (bfd
*input_bfd
,
3812 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3813 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
3815 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
3816 if (elf_elfheader (input_bfd
)->e_flags
& EF_FRV_FDPIC
)
3822 /* Adjust the contents of an eh_frame_hdr section before they're output. */
3825 frv_elf_encode_eh_address (bfd
*abfd
,
3826 struct bfd_link_info
*info
,
3827 asection
*osec
, bfd_vma offset
,
3828 asection
*loc_sec
, bfd_vma loc_offset
,
3831 struct elf_link_hash_entry
*h
;
3833 /* Non-FDPIC binaries can use PC-relative encodings. */
3834 if (! (elf_elfheader (abfd
)->e_flags
& EF_FRV_FDPIC
))
3835 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
3836 loc_sec
, loc_offset
, encoded
);
3838 h
= elf_hash_table (info
)->hgot
;
3839 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
3841 if (! h
|| (_frv_osec_to_segment (abfd
, osec
)
3842 == _frv_osec_to_segment (abfd
, loc_sec
->output_section
)))
3843 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
3844 loc_sec
, loc_offset
, encoded
);
3846 BFD_ASSERT (_frv_osec_to_segment (abfd
, osec
)
3847 == _frv_osec_to_segment (abfd
,
3848 h
->root
.u
.def
.section
->output_section
));
3850 *encoded
= osec
->vma
+ offset
3851 - (h
->root
.u
.def
.value
3852 + h
->root
.u
.def
.section
->output_section
->vma
3853 + h
->root
.u
.def
.section
->output_offset
);
3855 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
3858 /* Look through the relocs for a section during the first phase.
3860 Besides handling virtual table relocs for gc, we have to deal with
3861 all sorts of PIC-related relocations. We describe below the
3862 general plan on how to handle such relocations, even though we only
3863 collect information at this point, storing them in hash tables for
3864 perusal of later passes.
3866 32 relocations are propagated to the linker output when creating
3867 position-independent output. LO16 and HI16 relocations are not
3868 supposed to be encountered in this case.
3870 LABEL16 should always be resolvable by the linker, since it's only
3873 LABEL24, on the other hand, is used by calls. If it turns out that
3874 the target of a call is a dynamic symbol, a PLT entry must be
3875 created for it, which triggers the creation of a private function
3876 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
3878 GPREL relocations require the referenced symbol to be in the same
3879 segment as _gp, but this can only be checked later.
3881 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
3882 exist. LABEL24 might as well, since it may require a PLT entry,
3883 that will require a got.
3885 Non-FUNCDESC GOT relocations require a GOT entry to be created
3886 regardless of whether the symbol is dynamic. However, since a
3887 global symbol that turns out to not be exported may have the same
3888 address of a non-dynamic symbol, we don't assign GOT entries at
3889 this point, such that we can share them in this case. A relocation
3890 for the GOT entry always has to be created, be it to offset a
3891 private symbol by the section load address, be it to get the symbol
3892 resolved dynamically.
3894 FUNCDESC GOT relocations require a GOT entry to be created, and
3895 handled as if a FUNCDESC relocation was applied to the GOT entry in
3898 FUNCDESC relocations referencing a symbol that turns out to NOT be
3899 dynamic cause a private function descriptor to be created. The
3900 FUNCDESC relocation then decays to a 32 relocation that points at
3901 the private descriptor. If the symbol is dynamic, the FUNCDESC
3902 relocation is propagated to the linker output, such that the
3903 dynamic linker creates the canonical descriptor, pointing to the
3904 dynamically-resolved definition of the function.
3906 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
3907 symbols that are assigned to the same segment as the GOT, but we
3908 can only check this later, after we know the complete set of
3909 symbols defined and/or exported.
3911 FUNCDESC GOTOFF relocations require a function descriptor to be
3912 created and, unless lazy binding is disabled or the symbol is not
3913 dynamic, a lazy PLT entry. Since we can't tell at this point
3914 whether a symbol is going to be dynamic, we have to decide later
3915 whether to create a lazy PLT entry or bind the descriptor directly
3916 to the private function.
3918 FUNCDESC_VALUE relocations are not supposed to be present in object
3919 files, but they may very well be simply propagated to the linker
3920 output, since they have no side effect.
3923 A function descriptor always requires a FUNCDESC_VALUE relocation.
3924 Whether it's in .plt.rel or not depends on whether lazy binding is
3925 enabled and on whether the referenced symbol is dynamic.
3927 The existence of a lazy PLT requires the resolverStub lazy PLT
3928 entry to be present.
3931 As for assignment of GOT, PLT and lazy PLT entries, and private
3932 descriptors, we might do them all sequentially, but we can do
3933 better than that. For example, we can place GOT entries and
3934 private function descriptors referenced using 12-bit operands
3935 closer to the PIC register value, such that these relocations don't
3936 overflow. Those that are only referenced with LO16 relocations
3937 could come next, but we may as well place PLT-required function
3938 descriptors in the 12-bit range to make them shorter. Symbols
3939 referenced with LO16/HI16 may come next, but we may place
3940 additional function descriptors in the 16-bit range if we can
3941 reliably tell that we've already placed entries that are ever
3942 referenced with only LO16. PLT entries are therefore generated as
3943 small as possible, while not introducing relocation overflows in
3944 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
3945 generated before or after PLT entries, but not intermingled with
3946 them, such that we can have more lazy PLT entries in range for a
3947 branch to the resolverStub. The resolverStub should be emitted at
3948 the most distant location from the first lazy PLT entry such that
3949 it's still in range for a branch, or closer, if there isn't a need
3950 for so many lazy PLT entries. Additional lazy PLT entries may be
3951 emitted after the resolverStub, as long as branches are still in
3952 range. If the branch goes out of range, longer lazy PLT entries
3955 We could further optimize PLT and lazy PLT entries by giving them
3956 priority in assignment to closer-to-gr17 locations depending on the
3957 number of occurrences of references to them (assuming a function
3958 that's called more often is more important for performance, so its
3959 PLT entry should be faster), or taking hints from the compiler.
3960 Given infinite time and money... :-) */
3963 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
3965 struct bfd_link_info
*info
;
3967 const Elf_Internal_Rela
*relocs
;
3969 Elf_Internal_Shdr
*symtab_hdr
;
3970 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
3971 const Elf_Internal_Rela
*rel
;
3972 const Elf_Internal_Rela
*rel_end
;
3974 struct frv_pic_relocs_info
*picrel
;
3976 if (info
->relocatable
)
3979 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3980 sym_hashes
= elf_sym_hashes (abfd
);
3981 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
3982 if (!elf_bad_symtab (abfd
))
3983 sym_hashes_end
-= symtab_hdr
->sh_info
;
3985 dynobj
= elf_hash_table (info
)->dynobj
;
3986 rel_end
= relocs
+ sec
->reloc_count
;
3987 for (rel
= relocs
; rel
< rel_end
; rel
++)
3989 struct elf_link_hash_entry
*h
;
3990 unsigned long r_symndx
;
3992 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3993 if (r_symndx
< symtab_hdr
->sh_info
)
3996 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3998 switch (ELF32_R_TYPE (rel
->r_info
))
4005 case R_FRV_FUNCDESC_GOT12
:
4006 case R_FRV_FUNCDESC_GOTHI
:
4007 case R_FRV_FUNCDESC_GOTLO
:
4008 case R_FRV_GOTOFF12
:
4009 case R_FRV_GOTOFFHI
:
4010 case R_FRV_GOTOFFLO
:
4011 case R_FRV_FUNCDESC_GOTOFF12
:
4012 case R_FRV_FUNCDESC_GOTOFFHI
:
4013 case R_FRV_FUNCDESC_GOTOFFLO
:
4014 case R_FRV_FUNCDESC
:
4015 case R_FRV_FUNCDESC_VALUE
:
4018 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4019 if (! _frv_create_got_section (abfd
, info
))
4024 if (h
->dynindx
== -1)
4025 switch (ELF_ST_VISIBILITY (h
->other
))
4031 bfd_elf32_link_record_dynamic_symbol (info
, h
);
4035 = frv_pic_relocs_info_for_global (frv_relocs_info (info
),
4037 rel
->r_addend
, INSERT
);
4040 picrel
= frv_pic_relocs_info_for_local (frv_relocs_info (info
),
4042 rel
->r_addend
, INSERT
);
4052 switch (ELF32_R_TYPE (rel
->r_info
))
4058 case R_FRV_FUNCDESC_VALUE
:
4059 picrel
->relocsfdv
++;
4060 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
4065 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
4075 picrel
->gothilo
= 1;
4078 case R_FRV_FUNCDESC_GOT12
:
4079 picrel
->fdgot12
= 1;
4082 case R_FRV_FUNCDESC_GOTHI
:
4083 case R_FRV_FUNCDESC_GOTLO
:
4084 picrel
->fdgothilo
= 1;
4087 case R_FRV_GOTOFF12
:
4088 case R_FRV_GOTOFFHI
:
4089 case R_FRV_GOTOFFLO
:
4093 case R_FRV_FUNCDESC_GOTOFF12
:
4094 picrel
->fdgoff12
= 1;
4097 case R_FRV_FUNCDESC_GOTOFFHI
:
4098 case R_FRV_FUNCDESC_GOTOFFLO
:
4099 picrel
->fdgoffhilo
= 1;
4102 case R_FRV_FUNCDESC
:
4107 /* This relocation describes the C++ object vtable hierarchy.
4108 Reconstruct it for later use during GC. */
4109 case R_FRV_GNU_VTINHERIT
:
4110 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4114 /* This relocation describes which C++ vtable entries are actually
4115 used. Record for later use during GC. */
4116 case R_FRV_GNU_VTENTRY
:
4117 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4127 /* Return the machine subcode from the ELF e_flags header. */
4130 elf32_frv_machine (abfd
)
4133 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
4136 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
4137 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
4138 case EF_FRV_CPU_FR450
: return bfd_mach_fr450
;
4139 case EF_FRV_CPU_FR405
: return bfd_mach_fr400
;
4140 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
4141 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
4142 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
4143 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
4146 return bfd_mach_frv
;
4149 /* Set the right machine number for a FRV ELF file. */
4152 elf32_frv_object_p (abfd
)
4155 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
4159 /* Function to set the ELF flag bits. */
4162 frv_elf_set_private_flags (abfd
, flags
)
4166 elf_elfheader (abfd
)->e_flags
= flags
;
4167 elf_flags_init (abfd
) = TRUE
;
4171 /* Copy backend specific data from one object module to another. */
4174 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
4178 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4179 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4182 BFD_ASSERT (!elf_flags_init (obfd
)
4183 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
4185 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
4186 elf_flags_init (obfd
) = TRUE
;
4190 /* Return true if the architecture described by elf header flag
4191 EXTENSION is an extension of the architecture described by BASE. */
4194 frv_elf_arch_extension_p (flagword base
, flagword extension
)
4196 if (base
== extension
)
4199 /* CPU_GENERIC code can be merged with code for a specific
4200 architecture, in which case the result is marked as being
4201 for the specific architecture. Everything is therefore
4202 an extension of CPU_GENERIC. */
4203 if (base
== EF_FRV_CPU_GENERIC
)
4206 if (extension
== EF_FRV_CPU_FR450
)
4207 if (base
== EF_FRV_CPU_FR400
|| base
== EF_FRV_CPU_FR405
)
4210 if (extension
== EF_FRV_CPU_FR405
)
4211 if (base
== EF_FRV_CPU_FR400
)
4217 /* Merge backend specific data from an object file to the output
4218 object file when linking. */
4221 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
4225 flagword old_flags
, old_partial
;
4226 flagword new_flags
, new_partial
;
4227 bfd_boolean error
= FALSE
;
4231 new_opt
[0] = old_opt
[0] = '\0';
4232 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4233 old_flags
= elf_elfheader (obfd
)->e_flags
;
4235 if (new_flags
& EF_FRV_FDPIC
)
4236 new_flags
&= ~EF_FRV_PIC
;
4239 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
4240 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
4241 bfd_get_filename (ibfd
));
4244 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
4246 elf_flags_init (obfd
) = TRUE
;
4247 old_flags
= new_flags
;
4250 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
4253 else /* Possibly incompatible flags. */
4255 /* Warn if different # of gprs are used. Note, 0 means nothing is
4256 said about the size of gprs. */
4257 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
4258 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
4259 if (new_partial
== old_partial
)
4262 else if (new_partial
== 0)
4265 else if (old_partial
== 0)
4266 old_flags
|= new_partial
;
4270 switch (new_partial
)
4272 default: strcat (new_opt
, " -mgpr-??"); break;
4273 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
4274 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
4277 switch (old_partial
)
4279 default: strcat (old_opt
, " -mgpr-??"); break;
4280 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
4281 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
4285 /* Warn if different # of fprs are used. Note, 0 means nothing is
4286 said about the size of fprs. */
4287 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
4288 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
4289 if (new_partial
== old_partial
)
4292 else if (new_partial
== 0)
4295 else if (old_partial
== 0)
4296 old_flags
|= new_partial
;
4300 switch (new_partial
)
4302 default: strcat (new_opt
, " -mfpr-?"); break;
4303 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
4304 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
4305 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
4308 switch (old_partial
)
4310 default: strcat (old_opt
, " -mfpr-?"); break;
4311 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
4312 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
4313 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
4317 /* Warn if different dword support was used. Note, 0 means nothing is
4318 said about the dword support. */
4319 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
4320 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
4321 if (new_partial
== old_partial
)
4324 else if (new_partial
== 0)
4327 else if (old_partial
== 0)
4328 old_flags
|= new_partial
;
4332 switch (new_partial
)
4334 default: strcat (new_opt
, " -mdword-?"); break;
4335 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
4336 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
4339 switch (old_partial
)
4341 default: strcat (old_opt
, " -mdword-?"); break;
4342 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
4343 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
4347 /* Or in flags that accumulate (ie, if one module uses it, mark that the
4349 old_flags
|= new_flags
& (EF_FRV_DOUBLE
4352 | EF_FRV_NON_PIC_RELOCS
);
4354 /* If any module was compiled without -G0, clear the G0 bit. */
4355 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
4356 | (old_flags
& new_flags
& EF_FRV_G0
));
4358 /* If any module was compiled without -mnopack, clear the mnopack bit. */
4359 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
4360 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
4362 /* We don't have to do anything if the pic flags are the same, or the new
4363 module(s) were compiled with -mlibrary-pic. */
4364 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
4365 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
4366 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
4369 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
4370 flags if any from the new module. */
4371 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
4372 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
4374 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
4375 else if (new_partial
!= 0 && old_partial
!= 0)
4376 old_flags
|= new_partial
;
4378 /* One module was compiled for pic and the other was not, see if we have
4379 had any relocations that are not pic-safe. */
4382 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
4383 old_flags
|= new_partial
;
4386 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
4387 #ifndef FRV_NO_PIC_ERROR
4389 (*_bfd_error_handler
)
4390 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
4391 bfd_get_filename (ibfd
),
4392 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
4397 /* Warn if different cpu is used (allow a specific cpu to override
4398 the generic cpu). */
4399 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
4400 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
4401 if (frv_elf_arch_extension_p (new_partial
, old_partial
))
4404 else if (frv_elf_arch_extension_p (old_partial
, new_partial
))
4405 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
4409 switch (new_partial
)
4411 default: strcat (new_opt
, " -mcpu=?"); break;
4412 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
4413 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
4414 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
4415 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
4416 case EF_FRV_CPU_FR450
: strcat (new_opt
, " -mcpu=fr450"); break;
4417 case EF_FRV_CPU_FR405
: strcat (new_opt
, " -mcpu=fr405"); break;
4418 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
4419 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
4420 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
4423 switch (old_partial
)
4425 default: strcat (old_opt
, " -mcpu=?"); break;
4426 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
4427 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
4428 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
4429 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
4430 case EF_FRV_CPU_FR450
: strcat (old_opt
, " -mcpu=fr450"); break;
4431 case EF_FRV_CPU_FR405
: strcat (old_opt
, " -mcpu=fr405"); break;
4432 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
4433 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
4434 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
4438 /* Print out any mismatches from above. */
4442 (*_bfd_error_handler
)
4443 (_("%s: compiled with %s and linked with modules compiled with %s"),
4444 bfd_get_filename (ibfd
), new_opt
, old_opt
);
4447 /* Warn about any other mismatches */
4448 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
4449 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
4450 if (new_partial
!= old_partial
)
4452 old_flags
|= new_partial
;
4454 (*_bfd_error_handler
)
4455 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
4456 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
4460 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
4461 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
4462 old_flags
|= EF_FRV_NOPACK
;
4464 /* Update the old flags now with changes made above. */
4465 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
4466 elf_elfheader (obfd
)->e_flags
= old_flags
;
4467 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
4468 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
4471 bfd_set_error (bfd_error_bad_value
);
4478 frv_elf_print_private_bfd_data (abfd
, ptr
)
4482 FILE *file
= (FILE *) ptr
;
4485 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4487 /* Print normal ELF private data. */
4488 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4490 flags
= elf_elfheader (abfd
)->e_flags
;
4491 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
4493 switch (flags
& EF_FRV_CPU_MASK
)
4496 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
4497 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
4498 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
4499 case EF_FRV_CPU_FR450
: fprintf (file
, " -mcpu=fr450"); break;
4500 case EF_FRV_CPU_FR405
: fprintf (file
, " -mcpu=fr405"); break;
4501 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
4502 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
4503 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
4506 switch (flags
& EF_FRV_GPR_MASK
)
4509 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
4510 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
4513 switch (flags
& EF_FRV_FPR_MASK
)
4516 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
4517 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
4518 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
4521 switch (flags
& EF_FRV_DWORD_MASK
)
4524 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
4525 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
4528 if (flags
& EF_FRV_DOUBLE
)
4529 fprintf (file
, " -mdouble");
4531 if (flags
& EF_FRV_MEDIA
)
4532 fprintf (file
, " -mmedia");
4534 if (flags
& EF_FRV_MULADD
)
4535 fprintf (file
, " -mmuladd");
4537 if (flags
& EF_FRV_PIC
)
4538 fprintf (file
, " -fpic");
4540 if (flags
& EF_FRV_BIGPIC
)
4541 fprintf (file
, " -fPIC");
4543 if (flags
& EF_FRV_LIBPIC
)
4544 fprintf (file
, " -mlibrary-pic");
4546 if (flags
& EF_FRV_FDPIC
)
4547 fprintf (file
, " -mfdpic");
4549 if (flags
& EF_FRV_NON_PIC_RELOCS
)
4550 fprintf (file
, " non-pic relocations");
4552 if (flags
& EF_FRV_G0
)
4553 fprintf (file
, " -G0");
4560 #define ELF_ARCH bfd_arch_frv
4561 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
4562 #define ELF_MAXPAGESIZE 0x1000
4564 #define TARGET_BIG_SYM bfd_elf32_frv_vec
4565 #define TARGET_BIG_NAME "elf32-frv"
4567 #define elf_info_to_howto_rel frv_info_to_howto_rel
4568 #define elf_info_to_howto frv_info_to_howto_rela
4569 #define elf_backend_relocate_section elf32_frv_relocate_section
4570 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
4571 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
4572 #define elf_backend_check_relocs elf32_frv_check_relocs
4573 #define elf_backend_object_p elf32_frv_object_p
4574 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
4576 #define elf_backend_can_gc_sections 1
4577 #define elf_backend_rela_normal 1
4579 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
4580 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
4581 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
4582 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
4583 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
4585 #define bfd_elf32_bfd_link_hash_table_create frv_elf_link_hash_table_create
4586 #define elf_backend_always_size_sections \
4587 elf32_frv_always_size_sections
4588 #define elf_backend_modify_segment_map \
4589 elf32_frv_modify_segment_map
4591 #define elf_backend_create_dynamic_sections \
4592 elf32_frv_create_dynamic_sections
4593 #define elf_backend_adjust_dynamic_symbol \
4594 elf32_frv_adjust_dynamic_symbol
4595 #define elf_backend_size_dynamic_sections \
4596 elf32_frv_size_dynamic_sections
4597 #define elf_backend_finish_dynamic_symbol \
4598 elf32_frv_finish_dynamic_symbol
4599 #define elf_backend_finish_dynamic_sections \
4600 elf32_frv_finish_dynamic_sections
4602 #define elf_backend_want_got_sym 1
4603 #define elf_backend_got_header_size 0
4604 #define elf_backend_want_got_plt 0
4605 #define elf_backend_plt_readonly 1
4606 #define elf_backend_want_plt_sym 0
4607 #define elf_backend_plt_header_size 0
4609 #define elf_backend_can_make_relative_eh_frame \
4610 frv_elf_use_relative_eh_frame
4611 #define elf_backend_can_make_lsda_relative_eh_frame \
4612 frv_elf_use_relative_eh_frame
4613 #define elf_backend_encode_eh_address frv_elf_encode_eh_address
4615 #define elf_backend_may_use_rel_p 1
4616 #define elf_backend_may_use_rela_p 1
4617 /* We use REL for dynamic relocations only. */
4618 #define elf_backend_default_use_rela_p 1
4620 #include "elf32-target.h"