1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 /* Forward declarations. */
28 static bfd_reloc_status_type elf32_frv_relocate_lo16
29 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
30 static bfd_reloc_status_type elf32_frv_relocate_hi16
31 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
32 static bfd_reloc_status_type elf32_frv_relocate_label24
33 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
34 static bfd_reloc_status_type elf32_frv_relocate_gprel12
35 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
36 bfd_byte
*, bfd_vma
));
37 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
38 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
39 bfd_byte
*, bfd_vma
));
40 static bfd_reloc_status_type elf32_frv_relocate_gprello
41 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
42 bfd_byte
*, bfd_vma
));
43 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
44 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, Elf_Internal_Rela
*,
45 bfd_byte
*, bfd_vma
));
46 static reloc_howto_type
*frv_reloc_type_lookup
47 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
48 static void frv_info_to_howto_rela
49 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
50 static bfd_boolean elf32_frv_relocate_section
51 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
52 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
53 static bfd_boolean elf32_frv_add_symbol_hook
54 PARAMS (( bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
55 const char **, flagword
*, asection
**, bfd_vma
*));
56 static bfd_reloc_status_type frv_final_link_relocate
57 PARAMS ((reloc_howto_type
*, bfd
*, asection
*, bfd_byte
*,
58 Elf_Internal_Rela
*, bfd_vma
));
59 static bfd_boolean elf32_frv_gc_sweep_hook
60 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, const
61 Elf_Internal_Rela
*));
62 static asection
* elf32_frv_gc_mark_hook
63 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
64 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
65 static bfd_boolean elf32_frv_check_relocs
66 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
67 const Elf_Internal_Rela
*));
68 static int elf32_frv_machine
70 static bfd_boolean elf32_frv_object_p
72 static bfd_boolean frv_elf_set_private_flags
73 PARAMS ((bfd
*, flagword
));
74 static bfd_boolean frv_elf_copy_private_bfd_data
75 PARAMS ((bfd
*, bfd
*));
76 static bfd_boolean frv_elf_merge_private_bfd_data
77 PARAMS ((bfd
*, bfd
*));
78 static bfd_boolean frv_elf_print_private_bfd_data
79 PARAMS ((bfd
*, PTR
));
81 static reloc_howto_type elf32_frv_howto_table
[] =
83 /* This reloc does nothing. */
84 HOWTO (R_FRV_NONE
, /* type */
86 2, /* size (0 = byte, 1 = short, 2 = long) */
88 FALSE
, /* pc_relative */
90 complain_overflow_bitfield
, /* complain_on_overflow */
91 bfd_elf_generic_reloc
, /* special_function */
92 "R_FRV_NONE", /* name */
93 FALSE
, /* partial_inplace */
96 FALSE
), /* pcrel_offset */
98 /* A 32 bit absolute relocation. */
99 HOWTO (R_FRV_32
, /* type */
101 2, /* size (0 = byte, 1 = short, 2 = long) */
103 FALSE
, /* pc_relative */
105 complain_overflow_bitfield
, /* complain_on_overflow */
106 bfd_elf_generic_reloc
, /* special_function */
107 "R_FRV_32", /* name */
108 FALSE
, /* partial_inplace */
109 0xffffffff, /* src_mask */
110 0xffffffff, /* dst_mask */
111 FALSE
), /* pcrel_offset */
113 /* A 16 bit pc-relative relocation. */
114 HOWTO (R_FRV_LABEL16
, /* type */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
118 TRUE
, /* pc_relative */
120 complain_overflow_signed
, /* complain_on_overflow */
121 bfd_elf_generic_reloc
, /* special_function */
122 "R_FRV_LABEL16", /* name */
123 FALSE
, /* partial_inplace */
124 0xffff, /* src_mask */
125 0xffff, /* dst_mask */
126 TRUE
), /* pcrel_offset */
128 /* A 24-bit pc-relative relocation. */
129 HOWTO (R_FRV_LABEL24
, /* type */
131 2, /* size (0 = byte, 1 = short, 2 = long) */
133 TRUE
, /* pc_relative */
135 complain_overflow_bitfield
, /* complain_on_overflow */
136 bfd_elf_generic_reloc
, /* special_function */
137 "R_FRV_LABEL24", /* name */
138 FALSE
, /* partial_inplace */
139 0x7e03ffff, /* src_mask */
140 0x7e03ffff, /* dst_mask */
141 TRUE
), /* pcrel_offset */
143 HOWTO (R_FRV_LO16
, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 FALSE
, /* pc_relative */
149 complain_overflow_dont
, /* complain_on_overflow */
150 bfd_elf_generic_reloc
, /* special_function */
151 "R_FRV_LO16", /* name */
152 FALSE
, /* partial_inplace */
153 0xffff, /* src_mask */
154 0xffff, /* dst_mask */
155 FALSE
), /* pcrel_offset */
157 HOWTO (R_FRV_HI16
, /* type */
159 2, /* size (0 = byte, 1 = short, 2 = long) */
161 FALSE
, /* pc_relative */
163 complain_overflow_dont
, /* complain_on_overflow */
164 bfd_elf_generic_reloc
, /* special_function */
165 "R_FRV_HI16", /* name */
166 FALSE
, /* partial_inplace */
167 0xffff, /* src_mask */
168 0xffff, /* dst_mask */
169 FALSE
), /* pcrel_offset */
171 HOWTO (R_FRV_GPREL12
, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 FALSE
, /* pc_relative */
177 complain_overflow_dont
, /* complain_on_overflow */
178 bfd_elf_generic_reloc
, /* special_function */
179 "R_FRV_GPREL12", /* name */
180 FALSE
, /* partial_inplace */
181 0xfff, /* src_mask */
182 0xfff, /* dst_mask */
183 FALSE
), /* pcrel_offset */
185 HOWTO (R_FRV_GPRELU12
, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE
, /* pc_relative */
191 complain_overflow_dont
, /* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_FRV_GPRELU12", /* name */
194 FALSE
, /* partial_inplace */
195 0xfff, /* src_mask */
196 0x3f03f, /* dst_mask */
197 FALSE
), /* pcrel_offset */
199 HOWTO (R_FRV_GPREL32
, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 FALSE
, /* pc_relative */
205 complain_overflow_dont
, /* complain_on_overflow */
206 bfd_elf_generic_reloc
, /* special_function */
207 "R_FRV_GPREL32", /* name */
208 FALSE
, /* partial_inplace */
209 0xffffffff, /* src_mask */
210 0xffffffff, /* dst_mask */
211 FALSE
), /* pcrel_offset */
213 HOWTO (R_FRV_GPRELHI
, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 FALSE
, /* pc_relative */
219 complain_overflow_dont
, /* complain_on_overflow */
220 bfd_elf_generic_reloc
, /* special_function */
221 "R_FRV_GPRELHI", /* name */
222 FALSE
, /* partial_inplace */
223 0xffff, /* src_mask */
224 0xffff, /* dst_mask */
225 FALSE
), /* pcrel_offset */
227 HOWTO (R_FRV_GPRELLO
, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE
, /* pc_relative */
233 complain_overflow_dont
, /* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_FRV_GPRELLO", /* name */
236 FALSE
, /* partial_inplace */
237 0xffff, /* src_mask */
238 0xffff, /* dst_mask */
239 FALSE
), /* pcrel_offset */
241 /* A 12-bit signed operand with the GOT offset for the address of
243 HOWTO (R_FRV_GOT12
, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE
, /* pc_relative */
249 complain_overflow_signed
, /* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_FRV_GOT12", /* name */
252 FALSE
, /* partial_inplace */
253 0xfff, /* src_mask */
254 0xfff, /* dst_mask */
255 FALSE
), /* pcrel_offset */
257 /* The upper 16 bits of the GOT offset for the address of the
259 HOWTO (R_FRV_GOTHI
, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE
, /* pc_relative */
265 complain_overflow_dont
, /* complain_on_overflow */
266 bfd_elf_generic_reloc
, /* special_function */
267 "R_FRV_GOTHI", /* name */
268 FALSE
, /* partial_inplace */
269 0xffff, /* src_mask */
270 0xffff, /* dst_mask */
271 FALSE
), /* pcrel_offset */
273 /* The lower 16 bits of the GOT offset for the address of the
275 HOWTO (R_FRV_GOTLO
, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE
, /* pc_relative */
281 complain_overflow_dont
, /* complain_on_overflow */
282 bfd_elf_generic_reloc
, /* special_function */
283 "R_FRV_GOTLO", /* name */
284 FALSE
, /* partial_inplace */
285 0xffff, /* src_mask */
286 0xffff, /* dst_mask */
287 FALSE
), /* pcrel_offset */
289 /* The 32-bit address of the canonical descriptor of a function. */
290 HOWTO (R_FRV_FUNCDESC
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE
, /* pc_relative */
296 complain_overflow_bitfield
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_FRV_FUNCDESC", /* name */
299 FALSE
, /* partial_inplace */
300 0xffffffff, /* src_mask */
301 0xffffffff, /* dst_mask */
302 FALSE
), /* pcrel_offset */
304 /* A 12-bit signed operand with the GOT offset for the address of
305 canonical descriptor of a function. */
306 HOWTO (R_FRV_FUNCDESC_GOT12
, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE
, /* pc_relative */
312 complain_overflow_signed
, /* complain_on_overflow */
313 bfd_elf_generic_reloc
, /* special_function */
314 "R_FRV_FUNCDESC_GOT12", /* name */
315 FALSE
, /* partial_inplace */
316 0xfff, /* src_mask */
317 0xfff, /* dst_mask */
318 FALSE
), /* pcrel_offset */
320 /* The upper 16 bits of the GOT offset for the address of the
321 canonical descriptor of a function. */
322 HOWTO (R_FRV_FUNCDESC_GOTHI
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE
, /* pc_relative */
328 complain_overflow_dont
, /* complain_on_overflow */
329 bfd_elf_generic_reloc
, /* special_function */
330 "R_FRV_FUNCDESC_GOTHI", /* name */
331 FALSE
, /* partial_inplace */
332 0xffff, /* src_mask */
333 0xffff, /* dst_mask */
334 FALSE
), /* pcrel_offset */
336 /* The lower 16 bits of the GOT offset for the address of the
337 canonical descriptor of a function. */
338 HOWTO (R_FRV_FUNCDESC_GOTLO
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_dont
, /* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_FRV_FUNCDESC_GOTLO", /* name */
347 FALSE
, /* partial_inplace */
348 0xffff, /* src_mask */
349 0xffff, /* dst_mask */
350 FALSE
), /* pcrel_offset */
352 /* The 32-bit address of the canonical descriptor of a function. */
353 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE
, /* pc_relative */
359 complain_overflow_bitfield
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_FRV_FUNCDESC_VALUE", /* name */
362 FALSE
, /* partial_inplace */
363 0xffffffff, /* src_mask */
364 0xffffffff, /* dst_mask */
365 FALSE
), /* pcrel_offset */
367 /* A 12-bit signed operand with the GOT offset for the address of
368 canonical descriptor of a function. */
369 HOWTO (R_FRV_FUNCDESC_GOTOFF12
, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE
, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_FRV_FUNCDESC_GOTOFF12", /* name */
378 FALSE
, /* partial_inplace */
379 0xfff, /* src_mask */
380 0xfff, /* dst_mask */
381 FALSE
), /* pcrel_offset */
383 /* The upper 16 bits of the GOT offset for the address of the
384 canonical descriptor of a function. */
385 HOWTO (R_FRV_FUNCDESC_GOTOFFHI
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE
, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
394 FALSE
, /* partial_inplace */
395 0xffff, /* src_mask */
396 0xffff, /* dst_mask */
397 FALSE
), /* pcrel_offset */
399 /* The lower 16 bits of the GOT offset for the address of the
400 canonical descriptor of a function. */
401 HOWTO (R_FRV_FUNCDESC_GOTOFFLO
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_dont
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
410 FALSE
, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* A 12-bit signed operand with the GOT offset for the address of
417 HOWTO (R_FRV_GOTOFF12
, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE
, /* pc_relative */
423 complain_overflow_signed
, /* complain_on_overflow */
424 bfd_elf_generic_reloc
, /* special_function */
425 "R_FRV_GOTOFF12", /* name */
426 FALSE
, /* partial_inplace */
427 0xfff, /* src_mask */
428 0xfff, /* dst_mask */
429 FALSE
), /* pcrel_offset */
431 /* The upper 16 bits of the GOT offset for the address of the
433 HOWTO (R_FRV_GOTOFFHI
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE
, /* pc_relative */
439 complain_overflow_dont
, /* complain_on_overflow */
440 bfd_elf_generic_reloc
, /* special_function */
441 "R_FRV_GOTOFFHI", /* name */
442 FALSE
, /* partial_inplace */
443 0xffff, /* src_mask */
444 0xffff, /* dst_mask */
445 FALSE
), /* pcrel_offset */
447 /* The lower 16 bits of the GOT offset for the address of the
449 HOWTO (R_FRV_GOTOFFLO
, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE
, /* pc_relative */
455 complain_overflow_dont
, /* complain_on_overflow */
456 bfd_elf_generic_reloc
, /* special_function */
457 "R_FRV_GOTOFFLO", /* name */
458 FALSE
, /* partial_inplace */
459 0xffff, /* src_mask */
460 0xffff, /* dst_mask */
461 FALSE
), /* pcrel_offset */
465 /* GNU extension to record C++ vtable hierarchy. */
466 static reloc_howto_type elf32_frv_vtinherit_howto
=
467 HOWTO (R_FRV_GNU_VTINHERIT
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 FALSE
, /* pc_relative */
473 complain_overflow_dont
, /* complain_on_overflow */
474 NULL
, /* special_function */
475 "R_FRV_GNU_VTINHERIT", /* name */
476 FALSE
, /* partial_inplace */
479 FALSE
); /* pcrel_offset */
481 /* GNU extension to record C++ vtable member usage. */
482 static reloc_howto_type elf32_frv_vtentry_howto
=
483 HOWTO (R_FRV_GNU_VTENTRY
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE
, /* pc_relative */
489 complain_overflow_dont
, /* complain_on_overflow */
490 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
491 "R_FRV_GNU_VTENTRY", /* name */
492 FALSE
, /* partial_inplace */
495 FALSE
); /* pcrel_offset */
497 /* The following 3 relocations are REL. The only difference to the
498 entries in the table above are that partial_inplace is TRUE. */
499 static reloc_howto_type elf32_frv_rel_32_howto
=
500 HOWTO (R_FRV_32
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE
, /* pc_relative */
506 complain_overflow_bitfield
, /* complain_on_overflow */
507 bfd_elf_generic_reloc
, /* special_function */
508 "R_FRV_32", /* name */
509 TRUE
, /* partial_inplace */
510 0xffffffff, /* src_mask */
511 0xffffffff, /* dst_mask */
512 FALSE
); /* pcrel_offset */
514 static reloc_howto_type elf32_frv_rel_funcdesc_howto
=
515 HOWTO (R_FRV_FUNCDESC
, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE
, /* pc_relative */
521 complain_overflow_bitfield
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 "R_FRV_FUNCDESC", /* name */
524 TRUE
, /* partial_inplace */
525 0xffffffff, /* src_mask */
526 0xffffffff, /* dst_mask */
527 FALSE
); /* pcrel_offset */
529 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto
=
530 HOWTO (R_FRV_FUNCDESC_VALUE
, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE
, /* pc_relative */
536 complain_overflow_bitfield
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 "R_FRV_FUNCDESC_VALUE", /* name */
539 TRUE
, /* partial_inplace */
540 0xffffffff, /* src_mask */
541 0xffffffff, /* dst_mask */
542 FALSE
); /* pcrel_offset */
545 /* Map BFD reloc types to FRV ELF reloc types. */
549 unsigned int bfd_reloc_val
;
550 unsigned int frv_reloc_val
;
553 static const struct frv_reloc_map frv_reloc_map
[] =
555 { BFD_RELOC_NONE
, R_FRV_NONE
},
556 { BFD_RELOC_32
, R_FRV_32
},
557 { BFD_RELOC_FRV_LABEL16
, R_FRV_LABEL16
},
558 { BFD_RELOC_FRV_LABEL24
, R_FRV_LABEL24
},
559 { BFD_RELOC_FRV_LO16
, R_FRV_LO16
},
560 { BFD_RELOC_FRV_HI16
, R_FRV_HI16
},
561 { BFD_RELOC_FRV_GPREL12
, R_FRV_GPREL12
},
562 { BFD_RELOC_FRV_GPRELU12
, R_FRV_GPRELU12
},
563 { BFD_RELOC_FRV_GPREL32
, R_FRV_GPREL32
},
564 { BFD_RELOC_FRV_GPRELHI
, R_FRV_GPRELHI
},
565 { BFD_RELOC_FRV_GPRELLO
, R_FRV_GPRELLO
},
566 { BFD_RELOC_FRV_GOT12
, R_FRV_GOT12
},
567 { BFD_RELOC_FRV_GOTHI
, R_FRV_GOTHI
},
568 { BFD_RELOC_FRV_GOTLO
, R_FRV_GOTLO
},
569 { BFD_RELOC_FRV_FUNCDESC
, R_FRV_FUNCDESC
},
570 { BFD_RELOC_FRV_FUNCDESC_GOT12
, R_FRV_FUNCDESC_GOT12
},
571 { BFD_RELOC_FRV_FUNCDESC_GOTHI
, R_FRV_FUNCDESC_GOTHI
},
572 { BFD_RELOC_FRV_FUNCDESC_GOTLO
, R_FRV_FUNCDESC_GOTLO
},
573 { BFD_RELOC_FRV_FUNCDESC_VALUE
, R_FRV_FUNCDESC_VALUE
},
574 { BFD_RELOC_FRV_FUNCDESC_GOTOFF12
, R_FRV_FUNCDESC_GOTOFF12
},
575 { BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
, R_FRV_FUNCDESC_GOTOFFHI
},
576 { BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
, R_FRV_FUNCDESC_GOTOFFLO
},
577 { BFD_RELOC_FRV_GOTOFF12
, R_FRV_GOTOFF12
},
578 { BFD_RELOC_FRV_GOTOFFHI
, R_FRV_GOTOFFHI
},
579 { BFD_RELOC_FRV_GOTOFFLO
, R_FRV_GOTOFFLO
},
580 { BFD_RELOC_VTABLE_INHERIT
, R_FRV_GNU_VTINHERIT
},
581 { BFD_RELOC_VTABLE_ENTRY
, R_FRV_GNU_VTENTRY
},
586 /* An extension of the elf hash table data structure, containing some
587 additional FRV-specific data. */
588 struct frv_elf_link_hash_table
590 struct elf_link_hash_table elf
;
592 /* A pointer to the .got section. */
594 /* A pointer to the .rel.got section. */
596 /* A pointer to the .rofixup section. */
598 /* A pointer to the .plt section. */
600 /* A pointer to the .rel.plt section. */
602 /* GOT base offset. */
604 /* Location of the first non-lazy PLT entry, i.e., the number of
605 bytes taken by lazy PLT entries. */
607 /* A hash table holding information about which symbols were
608 referenced with which PIC-related relocations. */
609 struct htab
*relocs_info
;
612 /* Get the FRV ELF linker hash table from a link_info structure. */
614 #define frv_hash_table(info) \
615 ((struct frv_elf_link_hash_table *) ((info)->hash))
617 #define frv_got_section(info) \
618 (frv_hash_table (info)->sgot)
619 #define frv_gotrel_section(info) \
620 (frv_hash_table (info)->sgotrel)
621 #define frv_gotfixup_section(info) \
622 (frv_hash_table (info)->sgotfixup)
623 #define frv_plt_section(info) \
624 (frv_hash_table (info)->splt)
625 #define frv_pltrel_section(info) \
626 (frv_hash_table (info)->spltrel)
627 #define frv_relocs_info(info) \
628 (frv_hash_table (info)->relocs_info)
629 #define frv_got_initial_offset(info) \
630 (frv_hash_table (info)->got0)
631 #define frv_plt_initial_offset(info) \
632 (frv_hash_table (info)->plt0)
634 /* Create an FRV ELF linker hash table. */
636 static struct bfd_link_hash_table
*
637 frv_elf_link_hash_table_create (bfd
*abfd
)
639 struct frv_elf_link_hash_table
*ret
;
640 bfd_size_type amt
= sizeof (struct frv_elf_link_hash_table
);
642 ret
= bfd_zalloc (abfd
, amt
);
646 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
647 _bfd_elf_link_hash_newfunc
))
653 return &ret
->elf
.root
;
656 /* Decide whether a reference to a symbol can be resolved locally or
657 not. If the symbol is protected, we want the local address, but
658 its function descriptor must be assigned by the dynamic linker. */
659 #define FRV_SYM_LOCAL(INFO, H) \
660 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
661 || ! elf_hash_table (INFO)->dynamic_sections_created \
662 || (/* The condition below is an ugly hack to get .scommon data to
663 be regarded as local. For some reason the
664 ELF_LINK_HASH_DEF_REGULAR bit is not set on such common
665 symbols, and the SEC_IS_COMMON bit is not set any longer
666 when we need to perform this test. Hopefully this
667 approximation is good enough. */ \
668 ((H)->root.type == bfd_link_hash_defined \
669 || (H)->root.type == bfd_link_hash_defweak) \
670 && (H)->root.u.def.section->output_section \
671 && ((H)->root.u.def.section->flags & SEC_LINKER_CREATED)))
672 #define FRV_FUNCDESC_LOCAL(INFO, H) \
673 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
675 /* This structure collects information on what kind of GOT, PLT or
676 function descriptors are required by relocations that reference a
678 struct frv_pic_relocs_info
680 /* The index of the symbol, as stored in the relocation r_info, if
681 we have a local symbol; -1 otherwise. */
685 /* The input bfd in which the symbol is defined, if it's a local
688 /* If symndx == -1, the hash table entry corresponding to a global
689 symbol (even if it turns out to bind locally, in which case it
690 should ideally be replaced with section's symndx + addend). */
691 struct elf_link_hash_entry
*h
;
693 /* The addend of the relocation that references the symbol. */
696 /* The fields above are used to identify an entry. The fields below
697 contain information on how an entry is used and, later on, which
698 locations it was assigned. */
699 /* The following 3 fields record whether the symbol+addend above was
700 ever referenced with a GOT relocation. The 12 suffix indicates a
701 GOT12 relocation; los is used for GOTLO relocations that are not
702 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
707 /* Whether a FUNCDESC relocation references symbol+addend. */
709 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
712 unsigned fdgothilo
:1;
713 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
715 unsigned fdgofflos
:1;
716 unsigned fdgoffhilo
:1;
717 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
718 GOTOFFHI relocations. The addend doesn't really matter, since we
719 envision that this will only be used to check whether the symbol
720 is mapped to the same segment as the got. */
722 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
724 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
727 /* Whether we need a PLT entry for a symbol. Should be implied by
729 (call && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)) */
731 /* Whether a function descriptor should be created in this link unit
732 for symbol+addend. Should be implied by something like:
733 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
734 || ((fd || fdgot12 || fdgotlos || fdgothilo)
735 && (symndx != -1 || FRV_FUNCDESC_LOCAL (info, d.h)))) */
737 /* Whether a lazy PLT entry is needed for this symbol+addend.
738 Should be implied by something like:
739 (privfd && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)
740 && ! (info->flags & DF_BIND_NOW)) */
742 /* Whether we've already emitted GOT relocations and PLT entries as
743 needed for this symbol. */
746 /* The number of R_FRV_32, R_FRV_FUNCDESC and R_FRV_FUNCDESC_VALUE
747 relocations referencing the symbol. */
748 unsigned relocs32
, relocsfd
, relocsfdv
;
750 /* The offsets of the GOT entries assigned to symbol+addend, to the
751 function descriptor's address, and to a function descriptor,
752 respectively. Should be zero if unassigned. The offsets are
753 counted from the value that will be assigned to the PIC register,
754 not from the beginning of the .got section. */
755 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
756 /* The offsets of the PLT entries assigned to symbol+addend,
757 non-lazy and lazy, respectively. If unassigned, should be
759 bfd_vma plt_entry
, lzplt_entry
;
762 /* Compute a hash with the key fields of an frv_pic_relocs_info entry. */
764 frv_pic_relocs_info_hash (const void *entry_
)
766 const struct frv_pic_relocs_info
*entry
= entry_
;
768 return (entry
->symndx
== -1
769 ? entry
->d
.h
->root
.root
.hash
770 : entry
->symndx
+ entry
->d
.abfd
->id
* 257) + entry
->addend
;
773 /* Test whether the key fields of two frv_pic_relocs_info entries are
776 frv_pic_relocs_info_eq (const void *entry1
, const void *entry2
)
778 const struct frv_pic_relocs_info
*e1
= entry1
;
779 const struct frv_pic_relocs_info
*e2
= entry2
;
781 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
782 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
785 /* Find or create an entry in a hash table HT that matches the key
786 fields of the given ENTRY. If it's not found, memory for a new
787 entry is allocated in ABFD's obstack. */
788 static struct frv_pic_relocs_info
*
789 frv_pic_relocs_info_find (struct htab
*ht
,
791 const struct frv_pic_relocs_info
*entry
)
793 struct frv_pic_relocs_info
**loc
=
794 (struct frv_pic_relocs_info
**) htab_find_slot (ht
, entry
, INSERT
);
799 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
804 (*loc
)->symndx
= entry
->symndx
;
805 (*loc
)->d
= entry
->d
;
806 (*loc
)->addend
= entry
->addend
;
807 (*loc
)->plt_entry
= (bfd_vma
)-1;
808 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
813 /* Obtain the address of the entry in HT associated with H's symbol +
814 addend, creating a new entry if none existed. ABFD is only used
815 for memory allocation purposes. */
816 inline static struct frv_pic_relocs_info
*
817 frv_pic_relocs_info_for_global (struct htab
*ht
,
819 struct elf_link_hash_entry
*h
,
822 struct frv_pic_relocs_info entry
;
826 entry
.addend
= addend
;
828 return frv_pic_relocs_info_find (ht
, abfd
, &entry
);
831 /* Obtain the address of the entry in HT associated with the SYMNDXth
832 local symbol of the input bfd ABFD, plus the addend, creating a new
833 entry if none existed. */
834 inline static struct frv_pic_relocs_info
*
835 frv_pic_relocs_info_for_local (struct htab
*ht
,
840 struct frv_pic_relocs_info entry
;
842 entry
.symndx
= symndx
;
844 entry
.addend
= addend
;
846 return frv_pic_relocs_info_find (ht
, abfd
, &entry
);
849 /* Every block of 65535 lazy PLT entries shares a single call to the
850 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
851 32767, counting from 0). All other lazy PLT entries branch to it
852 in a single instruction. */
854 #define FRV_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
855 #define FRV_LZPLT_RESOLV_LOC (8 * 32767)
857 /* Add a dynamic relocation to the SRELOC section. */
859 inline static bfd_vma
860 _frv_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
861 int reloc_type
, long dynindx
, bfd_vma addend
)
863 Elf_Internal_Rela outrel
;
864 bfd_vma reloc_offset
;
866 outrel
.r_offset
= offset
;
867 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
868 outrel
.r_addend
= addend
;
870 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
871 BFD_ASSERT (reloc_offset
< sreloc
->_raw_size
);
872 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
873 sreloc
->contents
+ reloc_offset
);
874 sreloc
->reloc_count
++;
879 /* Add a fixup to the ROFIXUP section. */
882 _frv_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
)
884 bfd_vma fixup_offset
;
886 if (rofixup
->flags
& SEC_EXCLUDE
)
889 fixup_offset
= rofixup
->reloc_count
* 4;
890 if (rofixup
->contents
)
892 BFD_ASSERT (fixup_offset
< rofixup
->_raw_size
);
893 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
895 rofixup
->reloc_count
++;
900 /* Find the segment number in which OSEC, and output section, is
904 _frv_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
906 struct elf_segment_map
*m
;
907 Elf_Internal_Phdr
*p
;
909 /* Find the segment that contains the output_section. */
910 for (m
= elf_tdata (output_bfd
)->segment_map
,
911 p
= elf_tdata (output_bfd
)->phdr
;
917 for (i
= m
->count
- 1; i
>= 0; i
--)
918 if (m
->sections
[i
] == osec
)
925 return p
- elf_tdata (output_bfd
)->phdr
;
928 inline static bfd_boolean
929 _frv_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
931 unsigned seg
= _frv_osec_to_segment (output_bfd
, osec
);
933 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
936 /* Generate relocations for GOT entries, function descriptors, and
937 code for PLT and lazy PLT entries. */
939 inline static bfd_boolean
940 _frv_emit_got_relocs_plt_entries (struct frv_pic_relocs_info
*entry
,
942 struct bfd_link_info
*info
,
944 Elf_Internal_Sym
*sym
,
948 bfd_vma fd_lazy_rel_offset
= (bfd_vma
)-1;
955 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
)
957 /* If the symbol is dynamic, consider it for dynamic
958 relocations, otherwise decay to section + offset. */
959 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
960 dynindx
= entry
->d
.h
->dynindx
;
963 if (sec
->output_section
964 && ! bfd_is_abs_section (sec
->output_section
)
965 && ! bfd_is_und_section (sec
->output_section
))
966 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
972 /* Generate relocation for GOT entry pointing to the symbol. */
973 if (entry
->got_entry
)
978 /* If the symbol is dynamic but binds locally, use
980 if (sec
&& (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
982 if (entry
->symndx
== -1)
983 ad
+= entry
->d
.h
->root
.u
.def
.value
;
986 ad
+= sec
->output_offset
;
987 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
988 idx
= elf_section_data (sec
->output_section
)->dynindx
;
993 /* If we're linking an executable at a fixed address, we can
994 omit the dynamic relocation as long as the symbol is local to
996 if (info
->executable
&& !info
->pie
997 && (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1000 ad
+= sec
->output_section
->vma
;
1001 if (entry
->symndx
!= -1 ||
1002 entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1003 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1004 frv_got_section (info
)->output_section
->vma
1005 + frv_got_section (info
)->output_offset
1006 + frv_got_initial_offset (info
)
1007 + entry
->got_entry
);
1010 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
1011 _bfd_elf_section_offset
1013 frv_got_section (info
),
1014 frv_got_initial_offset (info
)
1016 + frv_got_section (info
)->output_section
->vma
1017 + frv_got_section (info
)->output_offset
,
1020 bfd_put_32 (output_bfd
, ad
,
1021 frv_got_section (info
)->contents
1022 + frv_got_initial_offset (info
)
1023 + entry
->got_entry
);
1026 /* Generate relocation for GOT entry pointing to a canonical
1027 function descriptor. */
1028 if (entry
->fdgot_entry
)
1033 if (! (entry
->symndx
== -1
1034 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
1035 && FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1037 /* If the symbol is dynamic and there may be dynamic symbol
1038 resolution because we are, or are linked with, a shared
1039 library, emit a FUNCDESC relocation such that the dynamic
1040 linker will allocate the function descriptor. If the
1041 symbol needs a non-local function descriptor but binds
1042 locally (e.g., its visibility is protected, emit a
1043 dynamic relocation decayed to section+offset. */
1044 if (entry
->symndx
== -1 && ! FRV_FUNCDESC_LOCAL (info
, entry
->d
.h
)
1045 && FRV_SYM_LOCAL (info
, entry
->d
.h
)
1046 && !(info
->executable
&& !info
->pie
))
1048 reloc
= R_FRV_FUNCDESC
;
1049 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
1050 ->output_section
)->dynindx
;
1051 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
1052 + entry
->d
.h
->root
.u
.def
.value
;
1054 else if (entry
->symndx
== -1
1055 && ! FRV_FUNCDESC_LOCAL (info
, entry
->d
.h
))
1057 reloc
= R_FRV_FUNCDESC
;
1065 /* Otherwise, we know we have a private function descriptor,
1066 so reference it directly. */
1067 if (elf_hash_table (info
)->dynamic_sections_created
)
1068 BFD_ASSERT (entry
->privfd
);
1070 idx
= elf_section_data (frv_got_section (info
)
1071 ->output_section
)->dynindx
;
1072 ad
= frv_got_section (info
)->output_offset
1073 + frv_got_initial_offset (info
) + entry
->fd_entry
;
1076 /* If there is room for dynamic symbol resolution, emit the
1077 dynamic relocation. However, if we're linking an
1078 executable at a fixed location, we won't have emitted a
1079 dynamic symbol entry for the got section, so idx will be
1080 zero, which means we can and should compute the address
1081 of the private descriptor ourselves. */
1082 if (info
->executable
&& !info
->pie
1083 && (entry
->symndx
!= -1
1084 || FRV_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
1086 ad
+= frv_got_section (info
)->output_section
->vma
;
1087 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1088 frv_got_section (info
)->output_section
->vma
1089 + frv_got_section (info
)->output_offset
1090 + frv_got_initial_offset (info
)
1091 + entry
->fdgot_entry
);
1094 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
1095 _bfd_elf_section_offset
1097 frv_got_section (info
),
1098 frv_got_initial_offset (info
)
1099 + entry
->fdgot_entry
)
1100 + frv_got_section (info
)->output_section
->vma
1101 + frv_got_section (info
)->output_offset
,
1105 bfd_put_32 (output_bfd
, ad
,
1106 frv_got_section (info
)->contents
1107 + frv_got_initial_offset (info
)
1108 + entry
->fdgot_entry
);
1111 /* Generate relocation to fill in a private function descriptor in
1113 if (entry
->fd_entry
)
1116 bfd_vma ad
= addend
;
1118 long lowword
, highword
;
1120 /* If the symbol is dynamic but binds locally, use
1122 if (sec
&& (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1124 if (entry
->symndx
== -1)
1125 ad
+= entry
->d
.h
->root
.u
.def
.value
;
1127 ad
+= sym
->st_value
;
1128 ad
+= sec
->output_offset
;
1129 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
1130 idx
= elf_section_data (sec
->output_section
)->dynindx
;
1135 /* If we're linking an executable at a fixed address, we can
1136 omit the dynamic relocation as long as the symbol is local to
1138 if (info
->executable
&& !info
->pie
1139 && (entry
->symndx
!= -1 || FRV_SYM_LOCAL (info
, entry
->d
.h
)))
1142 ad
+= sec
->output_section
->vma
;
1144 if (entry
->symndx
!= -1 ||
1145 entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
1147 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1148 frv_got_section (info
)->output_section
->vma
1149 + frv_got_section (info
)->output_offset
1150 + frv_got_initial_offset (info
)
1152 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
1153 frv_got_section (info
)->output_section
->vma
1154 + frv_got_section (info
)->output_offset
1155 + frv_got_initial_offset (info
)
1156 + entry
->fd_entry
+ 4);
1162 _frv_add_dyn_reloc (output_bfd
,
1163 entry
->lazyplt
? frv_pltrel_section (info
)
1164 : frv_gotrel_section (info
),
1165 _bfd_elf_section_offset
1167 frv_got_section (info
),
1168 frv_got_initial_offset (info
)
1170 + frv_got_section (info
)->output_section
->vma
1171 + frv_got_section (info
)->output_offset
,
1172 R_FRV_FUNCDESC_VALUE
, idx
, ad
);
1175 /* If we've omitted the dynamic relocation, just emit the fixed
1176 addresses of the symbol and of the local GOT base offset. */
1177 if (info
->executable
&& !info
->pie
&& sec
&& sec
->output_section
)
1180 highword
= frv_got_section (info
)->output_section
->vma
1181 + frv_got_section (info
)->output_offset
1182 + frv_got_initial_offset (info
);
1184 else if (entry
->lazyplt
)
1189 fd_lazy_rel_offset
= ofst
;
1191 /* A function descriptor used for lazy or local resolving is
1192 initialized such that its high word contains the output
1193 section index in which the PLT entries are located, and
1194 the low word contains the address of the lazy PLT entry
1195 entry point, that must be within the memory region
1196 assigned to that section. */
1197 lowword
= entry
->lzplt_entry
+ 4
1198 + frv_plt_section (info
)->output_offset
1199 + frv_plt_section (info
)->output_section
->vma
;
1200 highword
= _frv_osec_to_segment
1201 (output_bfd
, frv_plt_section (info
)->output_section
);
1205 /* A function descriptor for a local function gets the index
1206 of the section. For a non-local function, it's
1209 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
1210 && entry
->d
.h
->dynindx
== idx
)
1213 highword
= _frv_osec_to_segment (output_bfd
, sec
->output_section
);
1216 bfd_put_32 (output_bfd
, lowword
,
1217 frv_got_section (info
)->contents
1218 + frv_got_initial_offset (info
)
1220 bfd_put_32 (output_bfd
, highword
,
1221 frv_got_section (info
)->contents
1222 + frv_got_initial_offset (info
)
1223 + entry
->fd_entry
+ 4);
1226 /* Generate code for the PLT entry. */
1227 if (entry
->plt_entry
!= (bfd_vma
) -1)
1229 bfd_byte
*plt_code
= frv_plt_section (info
)->contents
+ entry
->plt_entry
;
1231 BFD_ASSERT (entry
->fd_entry
);
1233 /* Figure out what kind of PLT entry we need, depending on the
1234 location of the function descriptor within the GOT. */
1235 if (entry
->fd_entry
>= -(1 << (12 - 1))
1236 && entry
->fd_entry
< (1 << (12 - 1)))
1238 /* lddi @(gr15, fd_entry), gr14 */
1239 bfd_put_32 (output_bfd
,
1240 0x9cccf000 | (entry
->fd_entry
& ((1 << 12) - 1)),
1246 if (entry
->fd_entry
>= -(1 << (16 - 1))
1247 && entry
->fd_entry
< (1 << (16 - 1)))
1249 /* setlos lo(fd_entry), gr14 */
1250 bfd_put_32 (output_bfd
,
1252 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1258 /* sethi.p hi(fd_entry), gr14
1259 setlo lo(fd_entry), gr14 */
1260 bfd_put_32 (output_bfd
,
1262 | ((entry
->fd_entry
>> 16)
1263 & (((bfd_vma
)1 << 16) - 1)),
1265 bfd_put_32 (output_bfd
,
1267 | (entry
->fd_entry
& (((bfd_vma
)1 << 16) - 1)),
1271 /* ldd @(gr14,gr15),gr14 */
1272 bfd_put_32 (output_bfd
, 0x9c08e14f, plt_code
);
1275 /* jmpl @(gr14,gr0) */
1276 bfd_put_32 (output_bfd
, 0x8030e000, plt_code
);
1279 /* Generate code for the lazy PLT entry. */
1280 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
1282 bfd_byte
*lzplt_code
= frv_plt_section (info
)->contents
1283 + entry
->lzplt_entry
;
1284 bfd_vma resolverStub_addr
;
1286 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
1289 resolverStub_addr
= entry
->lzplt_entry
/ FRV_LZPLT_BLOCK_SIZE
1290 * FRV_LZPLT_BLOCK_SIZE
+ FRV_LZPLT_RESOLV_LOC
;
1291 if (resolverStub_addr
>= frv_plt_initial_offset (info
))
1292 resolverStub_addr
= frv_plt_initial_offset (info
) - 12;
1294 if (entry
->lzplt_entry
== resolverStub_addr
)
1296 /* This is a lazy PLT entry that includes a resolver call. */
1297 /* ldd @(gr15,gr0), gr4
1299 bfd_put_32 (output_bfd
, 0x8808f140, lzplt_code
);
1300 bfd_put_32 (output_bfd
, 0x80304000, lzplt_code
+ 4);
1304 /* bra resolverStub */
1305 bfd_put_32 (output_bfd
,
1307 | (((resolverStub_addr
- entry
->lzplt_entry
)
1308 / 4) & (((bfd_vma
)1 << 16) - 1)),
1316 /* Handle an FRV small data reloc. */
1318 static bfd_reloc_status_type
1319 elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, relocation
,
1321 struct bfd_link_info
*info
;
1323 asection
*input_section
;
1324 Elf_Internal_Rela
*relocation
;
1330 struct bfd_link_hash_entry
*h
;
1332 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1334 gp
= (h
->u
.def
.value
1335 + h
->u
.def
.section
->output_section
->vma
1336 + h
->u
.def
.section
->output_offset
);
1338 value
-= input_section
->output_section
->vma
;
1339 value
-= (gp
- input_section
->output_section
->vma
);
1341 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1343 value
+= relocation
->r_addend
;
1345 if ((long) value
> 0x7ff || (long) value
< -0x800)
1346 return bfd_reloc_overflow
;
1348 bfd_put_32 (input_bfd
,
1349 (insn
& 0xfffff000) | (value
& 0xfff),
1350 contents
+ relocation
->r_offset
);
1352 return bfd_reloc_ok
;
1355 /* Handle an FRV small data reloc. for the u12 field. */
1357 static bfd_reloc_status_type
1358 elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, relocation
,
1360 struct bfd_link_info
*info
;
1362 asection
*input_section
;
1363 Elf_Internal_Rela
*relocation
;
1369 struct bfd_link_hash_entry
*h
;
1372 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1374 gp
= (h
->u
.def
.value
1375 + h
->u
.def
.section
->output_section
->vma
1376 + h
->u
.def
.section
->output_offset
);
1378 value
-= input_section
->output_section
->vma
;
1379 value
-= (gp
- input_section
->output_section
->vma
);
1381 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1383 value
+= relocation
->r_addend
;
1385 if ((long) value
> 0x7ff || (long) value
< -0x800)
1386 return bfd_reloc_overflow
;
1388 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
1390 insn
= (insn
& ~mask
) | ((value
& 0xfc0) << 12) | (value
& 0x3f);
1392 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
1394 return bfd_reloc_ok
;
1397 /* Handle an FRV ELF HI16 reloc. */
1399 static bfd_reloc_status_type
1400 elf32_frv_relocate_hi16 (input_bfd
, relhi
, contents
, value
)
1402 Elf_Internal_Rela
*relhi
;
1408 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
1410 value
+= relhi
->r_addend
;
1411 value
= ((value
>> 16) & 0xffff);
1413 insn
= (insn
& 0xffff0000) | value
;
1415 if ((long) value
> 0xffff || (long) value
< -0x10000)
1416 return bfd_reloc_overflow
;
1418 bfd_put_32 (input_bfd
, insn
, contents
+ relhi
->r_offset
);
1419 return bfd_reloc_ok
;
1422 static bfd_reloc_status_type
1423 elf32_frv_relocate_lo16 (input_bfd
, rello
, contents
, value
)
1425 Elf_Internal_Rela
*rello
;
1431 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
1433 value
+= rello
->r_addend
;
1434 value
= value
& 0xffff;
1436 insn
= (insn
& 0xffff0000) | value
;
1438 if ((long) value
> 0xffff || (long) value
< -0x10000)
1439 return bfd_reloc_overflow
;
1441 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
1442 return bfd_reloc_ok
;
1445 /* Perform the relocation for the CALL label24 instruction. */
1447 static bfd_reloc_status_type
1448 elf32_frv_relocate_label24 (input_bfd
, input_section
, rello
, contents
, value
)
1450 asection
*input_section
;
1451 Elf_Internal_Rela
*rello
;
1459 /* The format for the call instruction is:
1461 0 000000 0001111 000000000000000000
1462 label6 opcode label18
1464 The branch calculation is: pc + (4*label24)
1465 where label24 is the concatenation of label6 and label18. */
1467 /* Grab the instruction. */
1468 insn
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
1470 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
1471 value
-= rello
->r_offset
;
1472 value
+= rello
->r_addend
;
1476 label6
= value
& 0xfc0000;
1477 label6
= label6
<< 7;
1479 label18
= value
& 0x3ffff;
1481 insn
= insn
& 0x803c0000;
1482 insn
= insn
| label6
;
1483 insn
= insn
| label18
;
1485 bfd_put_32 (input_bfd
, insn
, contents
+ rello
->r_offset
);
1487 return bfd_reloc_ok
;
1490 static bfd_reloc_status_type
1491 elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, relocation
,
1493 struct bfd_link_info
*info
;
1495 asection
*input_section
;
1496 Elf_Internal_Rela
*relocation
;
1502 struct bfd_link_hash_entry
*h
;
1504 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1506 gp
= (h
->u
.def
.value
1507 + h
->u
.def
.section
->output_section
->vma
1508 + h
->u
.def
.section
->output_offset
);
1510 value
-= input_section
->output_section
->vma
;
1511 value
-= (gp
- input_section
->output_section
->vma
);
1512 value
+= relocation
->r_addend
;
1513 value
= ((value
>> 16) & 0xffff);
1515 if ((long) value
> 0xffff || (long) value
< -0x10000)
1516 return bfd_reloc_overflow
;
1518 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1519 insn
= (insn
& 0xffff0000) | value
;
1521 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
1522 return bfd_reloc_ok
;
1525 static bfd_reloc_status_type
1526 elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, relocation
,
1528 struct bfd_link_info
*info
;
1530 asection
*input_section
;
1531 Elf_Internal_Rela
*relocation
;
1537 struct bfd_link_hash_entry
*h
;
1539 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
1541 gp
= (h
->u
.def
.value
1542 + h
->u
.def
.section
->output_section
->vma
1543 + h
->u
.def
.section
->output_offset
);
1545 value
-= input_section
->output_section
->vma
;
1546 value
-= (gp
- input_section
->output_section
->vma
);
1547 value
+= relocation
->r_addend
;
1548 value
= value
& 0xffff;
1550 if ((long) value
> 0xffff || (long) value
< -0x10000)
1551 return bfd_reloc_overflow
;
1553 insn
= bfd_get_32 (input_bfd
, contents
+ relocation
->r_offset
);
1554 insn
= (insn
& 0xffff0000) | value
;
1556 bfd_put_32 (input_bfd
, insn
, contents
+ relocation
->r_offset
);
1558 return bfd_reloc_ok
;
1561 static reloc_howto_type
*
1562 frv_reloc_type_lookup (abfd
, code
)
1563 bfd
*abfd ATTRIBUTE_UNUSED
;
1564 bfd_reloc_code_real_type code
;
1571 case BFD_RELOC_NONE
:
1572 return &elf32_frv_howto_table
[ (int) R_FRV_NONE
];
1575 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
1576 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
1577 return &elf32_frv_rel_32_howto
;
1579 case BFD_RELOC_CTOR
:
1580 return &elf32_frv_howto_table
[ (int) R_FRV_32
];
1582 case BFD_RELOC_FRV_LABEL16
:
1583 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL16
];
1585 case BFD_RELOC_FRV_LABEL24
:
1586 return &elf32_frv_howto_table
[ (int) R_FRV_LABEL24
];
1588 case BFD_RELOC_FRV_LO16
:
1589 return &elf32_frv_howto_table
[ (int) R_FRV_LO16
];
1591 case BFD_RELOC_FRV_HI16
:
1592 return &elf32_frv_howto_table
[ (int) R_FRV_HI16
];
1594 case BFD_RELOC_FRV_GPREL12
:
1595 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL12
];
1597 case BFD_RELOC_FRV_GPRELU12
:
1598 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELU12
];
1600 case BFD_RELOC_FRV_GPREL32
:
1601 return &elf32_frv_howto_table
[ (int) R_FRV_GPREL32
];
1603 case BFD_RELOC_FRV_GPRELHI
:
1604 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELHI
];
1606 case BFD_RELOC_FRV_GPRELLO
:
1607 return &elf32_frv_howto_table
[ (int) R_FRV_GPRELLO
];
1609 case BFD_RELOC_FRV_GOT12
:
1610 return &elf32_frv_howto_table
[ (int) R_FRV_GOT12
];
1612 case BFD_RELOC_FRV_GOTHI
:
1613 return &elf32_frv_howto_table
[ (int) R_FRV_GOTHI
];
1615 case BFD_RELOC_FRV_GOTLO
:
1616 return &elf32_frv_howto_table
[ (int) R_FRV_GOTLO
];
1618 case BFD_RELOC_FRV_FUNCDESC
:
1619 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
1620 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
1621 return &elf32_frv_rel_funcdesc_howto
;
1622 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC
];
1624 case BFD_RELOC_FRV_FUNCDESC_GOT12
:
1625 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOT12
];
1627 case BFD_RELOC_FRV_FUNCDESC_GOTHI
:
1628 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTHI
];
1630 case BFD_RELOC_FRV_FUNCDESC_GOTLO
:
1631 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTLO
];
1633 case BFD_RELOC_FRV_FUNCDESC_VALUE
:
1634 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
1635 || elf_elfheader (abfd
)->e_type
== ET_DYN
)
1636 return &elf32_frv_rel_funcdesc_value_howto
;
1637 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_VALUE
];
1639 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12
:
1640 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFF12
];
1642 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI
:
1643 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFHI
];
1645 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO
:
1646 return &elf32_frv_howto_table
[ (int) R_FRV_FUNCDESC_GOTOFFLO
];
1648 case BFD_RELOC_FRV_GOTOFF12
:
1649 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFF12
];
1651 case BFD_RELOC_FRV_GOTOFFHI
:
1652 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFHI
];
1654 case BFD_RELOC_FRV_GOTOFFLO
:
1655 return &elf32_frv_howto_table
[ (int) R_FRV_GOTOFFLO
];
1657 case BFD_RELOC_VTABLE_INHERIT
:
1658 return &elf32_frv_vtinherit_howto
;
1660 case BFD_RELOC_VTABLE_ENTRY
:
1661 return &elf32_frv_vtentry_howto
;
1667 /* Set the howto pointer for an FRV ELF reloc. */
1670 frv_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1671 bfd
*abfd ATTRIBUTE_UNUSED
;
1673 Elf_Internal_Rela
*dst
;
1675 unsigned int r_type
;
1677 r_type
= ELF32_R_TYPE (dst
->r_info
);
1680 case R_FRV_GNU_VTINHERIT
:
1681 cache_ptr
->howto
= &elf32_frv_vtinherit_howto
;
1684 case R_FRV_GNU_VTENTRY
:
1685 cache_ptr
->howto
= &elf32_frv_vtentry_howto
;
1689 cache_ptr
->howto
= & elf32_frv_howto_table
[r_type
];
1694 /* Set the howto pointer for an FRV ELF REL reloc. */
1696 frv_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
,
1697 arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
1699 unsigned int r_type
;
1701 r_type
= ELF32_R_TYPE (dst
->r_info
);
1705 cache_ptr
->howto
= &elf32_frv_rel_32_howto
;
1708 case R_FRV_FUNCDESC
:
1709 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_howto
;
1712 case R_FRV_FUNCDESC_VALUE
:
1713 cache_ptr
->howto
= &elf32_frv_rel_funcdesc_value_howto
;
1717 cache_ptr
->howto
= NULL
;
1722 /* Perform a single relocation. By default we use the standard BFD
1723 routines, but a few relocs, we have to do them ourselves. */
1725 static bfd_reloc_status_type
1726 frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
, rel
,
1728 reloc_howto_type
*howto
;
1730 asection
*input_section
;
1732 Elf_Internal_Rela
*rel
;
1735 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1736 contents
, rel
->r_offset
, relocation
,
1741 /* Relocate an FRV ELF section.
1743 The RELOCATE_SECTION function is called by the new ELF backend linker
1744 to handle the relocations for a section.
1746 The relocs are always passed as Rela structures; if the section
1747 actually uses Rel structures, the r_addend field will always be
1750 This function is responsible for adjusting the section contents as
1751 necessary, and (if using Rela relocs and generating a relocatable
1752 output file) adjusting the reloc addend as necessary.
1754 This function does not have to worry about setting the reloc
1755 address or the reloc symbol index.
1757 LOCAL_SYMS is a pointer to the swapped in local symbols.
1759 LOCAL_SECTIONS is an array giving the section in the input file
1760 corresponding to the st_shndx field of each local symbol.
1762 The global hash table entry for the global symbols can be found
1763 via elf_sym_hashes (input_bfd).
1765 When generating relocatable output, this function must handle
1766 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1767 going to be the section symbol corresponding to the output
1768 section, which means that the addend must be adjusted
1772 elf32_frv_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1773 contents
, relocs
, local_syms
, local_sections
)
1774 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1775 struct bfd_link_info
*info
;
1777 asection
*input_section
;
1779 Elf_Internal_Rela
*relocs
;
1780 Elf_Internal_Sym
*local_syms
;
1781 asection
**local_sections
;
1783 Elf_Internal_Shdr
*symtab_hdr
;
1784 struct elf_link_hash_entry
**sym_hashes
;
1785 Elf_Internal_Rela
*rel
;
1786 Elf_Internal_Rela
*relend
;
1787 unsigned isec_segment
, got_segment
, plt_segment
, gprel_segment
,
1789 int silence_segment_error
= !(info
->shared
|| info
->pie
);
1791 if (info
->relocatable
)
1794 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1795 sym_hashes
= elf_sym_hashes (input_bfd
);
1796 relend
= relocs
+ input_section
->reloc_count
;
1798 isec_segment
= _frv_osec_to_segment (output_bfd
,
1799 input_section
->output_section
);
1800 if (frv_got_section (info
))
1801 got_segment
= _frv_osec_to_segment (output_bfd
,
1802 frv_got_section (info
)
1806 if (frv_gotfixup_section (info
))
1807 gprel_segment
= _frv_osec_to_segment (output_bfd
,
1808 frv_gotfixup_section (info
)
1812 if (elf_hash_table (info
)->dynamic_sections_created
)
1813 plt_segment
= _frv_osec_to_segment (output_bfd
,
1814 frv_plt_section (info
)
1819 for (rel
= relocs
; rel
< relend
; rel
++)
1821 reloc_howto_type
*howto
;
1822 unsigned long r_symndx
;
1823 Elf_Internal_Sym
*sym
;
1825 struct elf_link_hash_entry
*h
;
1827 bfd_reloc_status_type r
;
1828 const char * name
= NULL
;
1831 struct frv_pic_relocs_info
*picrel
;
1832 bfd_vma orig_addend
= rel
->r_addend
;
1834 r_type
= ELF32_R_TYPE (rel
->r_info
);
1836 if ( r_type
== R_FRV_GNU_VTINHERIT
1837 || r_type
== R_FRV_GNU_VTENTRY
)
1840 /* This is a final link. */
1841 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1842 howto
= elf32_frv_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
1847 if (r_symndx
< symtab_hdr
->sh_info
)
1849 sym
= local_syms
+ r_symndx
;
1850 osec
= sec
= local_sections
[r_symndx
];
1851 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1853 name
= bfd_elf_string_from_elf_section
1854 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
1855 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
1859 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1861 while (h
->root
.type
== bfd_link_hash_indirect
1862 || h
->root
.type
== bfd_link_hash_warning
)
1863 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1865 name
= h
->root
.root
.string
;
1867 if ((h
->root
.type
== bfd_link_hash_defined
1868 || h
->root
.type
== bfd_link_hash_defweak
)
1869 && ! FRV_SYM_LOCAL (info
, h
))
1875 if (h
->root
.type
== bfd_link_hash_defined
1876 || h
->root
.type
== bfd_link_hash_defweak
)
1878 sec
= h
->root
.u
.def
.section
;
1879 relocation
= (h
->root
.u
.def
.value
1880 + sec
->output_section
->vma
1881 + sec
->output_offset
);
1883 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1887 else if ( ! info
->executable
1889 && info
->unresolved_syms_in_objects
== RM_IGNORE
1890 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1894 if (! ((*info
->callbacks
->undefined_symbol
)
1895 (info
, h
->root
.root
.string
, input_bfd
,
1896 input_section
, rel
->r_offset
, TRUE
)))
1910 case R_FRV_FUNCDESC_GOT12
:
1911 case R_FRV_FUNCDESC_GOTHI
:
1912 case R_FRV_FUNCDESC_GOTLO
:
1913 case R_FRV_GOTOFF12
:
1914 case R_FRV_GOTOFFHI
:
1915 case R_FRV_GOTOFFLO
:
1916 case R_FRV_FUNCDESC_GOTOFF12
:
1917 case R_FRV_FUNCDESC_GOTOFFHI
:
1918 case R_FRV_FUNCDESC_GOTOFFLO
:
1919 case R_FRV_FUNCDESC
:
1920 case R_FRV_FUNCDESC_VALUE
:
1922 picrel
= frv_pic_relocs_info_for_global (frv_relocs_info (info
),
1926 /* In order to find the entry we created before, we must
1927 use the original addend, not the one that may have been
1928 modified by _bfd_elf_rela_local_sym(). */
1929 picrel
= frv_pic_relocs_info_for_local (frv_relocs_info (info
),
1930 input_bfd
, r_symndx
,
1935 if (!_frv_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
1936 osec
, sym
, rel
->r_addend
))
1938 info
->callbacks
->warning
1939 (info
, _("Dynamic relocation references symbol with nonzero addend"),
1940 name
, input_bfd
, input_section
, rel
->r_offset
);
1949 if (h
&& ! FRV_SYM_LOCAL (info
, h
))
1951 info
->callbacks
->warning
1952 (info
, _("relocation references symbol not defined in the module"),
1953 name
, input_bfd
, input_section
, rel
->r_offset
);
1962 check_segment
[0] = isec_segment
;
1965 relocation
= frv_plt_section (info
)->output_section
->vma
1966 + frv_plt_section (info
)->output_offset
1967 + picrel
->plt_entry
;
1968 check_segment
[1] = plt_segment
;
1970 /* We don't want to warn on calls to undefined weak symbols,
1971 as calls to them must be protected by non-NULL tests
1972 anyway, and unprotected calls would invoke undefined
1974 else if (picrel
->symndx
== -1
1975 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
1976 check_segment
[1] = check_segment
[0];
1978 check_segment
[1] = sec
1979 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
1986 relocation
= picrel
->got_entry
;
1987 check_segment
[0] = check_segment
[1] = got_segment
;
1990 case R_FRV_FUNCDESC_GOT12
:
1991 case R_FRV_FUNCDESC_GOTHI
:
1992 case R_FRV_FUNCDESC_GOTLO
:
1993 relocation
= picrel
->fdgot_entry
;
1994 check_segment
[0] = check_segment
[1] = got_segment
;
1997 case R_FRV_GOTOFFHI
:
1998 case R_FRV_GOTOFF12
:
1999 case R_FRV_GOTOFFLO
:
2000 relocation
-= frv_got_section (info
)->output_section
->vma
2001 + frv_got_section (info
)->output_offset
2002 + frv_got_initial_offset (info
);
2003 check_segment
[0] = got_segment
;
2004 check_segment
[1] = sec
2005 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2009 case R_FRV_FUNCDESC_GOTOFF12
:
2010 case R_FRV_FUNCDESC_GOTOFFHI
:
2011 case R_FRV_FUNCDESC_GOTOFFLO
:
2012 relocation
= picrel
->fd_entry
;
2013 check_segment
[0] = check_segment
[1] = got_segment
;
2016 case R_FRV_FUNCDESC
:
2019 bfd_vma addend
= rel
->r_addend
;
2021 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
2022 && FRV_SYM_LOCAL (info
, h
)))
2024 /* If the symbol is dynamic and there may be dynamic
2025 symbol resolution because we are or are linked with a
2026 shared library, emit a FUNCDESC relocation such that
2027 the dynamic linker will allocate the function
2028 descriptor. If the symbol needs a non-local function
2029 descriptor but binds locally (e.g., its visibility is
2030 protected, emit a dynamic relocation decayed to
2032 if (h
&& ! FRV_FUNCDESC_LOCAL (info
, h
)
2033 && FRV_SYM_LOCAL (info
, h
)
2034 && !(info
->executable
&& !info
->pie
))
2036 dynindx
= elf_section_data (h
->root
.u
.def
.section
2037 ->output_section
)->dynindx
;
2038 addend
+= h
->root
.u
.def
.section
->output_offset
2039 + h
->root
.u
.def
.value
;
2041 else if (h
&& ! FRV_FUNCDESC_LOCAL (info
, h
))
2045 info
->callbacks
->warning
2046 (info
, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
2047 name
, input_bfd
, input_section
, rel
->r_offset
);
2050 dynindx
= h
->dynindx
;
2054 /* Otherwise, we know we have a private function
2055 descriptor, so reference it directly. */
2056 BFD_ASSERT (picrel
->privfd
);
2058 dynindx
= elf_section_data (frv_got_section (info
)
2059 ->output_section
)->dynindx
;
2060 addend
= frv_got_section (info
)->output_offset
2061 + frv_got_initial_offset (info
)
2065 /* If there is room for dynamic symbol resolution, emit
2066 the dynamic relocation. However, if we're linking an
2067 executable at a fixed location, we won't have emitted a
2068 dynamic symbol entry for the got section, so idx will
2069 be zero, which means we can and should compute the
2070 address of the private descriptor ourselves. */
2071 if (info
->executable
&& !info
->pie
2072 && (!h
|| FRV_FUNCDESC_LOCAL (info
, h
)))
2074 addend
+= frv_got_section (info
)->output_section
->vma
;
2075 if ((bfd_get_section_flags (output_bfd
,
2076 input_section
->output_section
)
2077 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2079 if (_frv_osec_readonly_p (output_bfd
,
2080 input_section
->output_section
))
2082 info
->callbacks
->warning
2084 _("cannot emit fixups in read-only section"),
2085 name
, input_bfd
, input_section
, rel
->r_offset
);
2088 _frv_add_rofixup (output_bfd
,
2089 frv_gotfixup_section (info
),
2090 _bfd_elf_section_offset
2092 input_section
, rel
->r_offset
)
2093 + input_section
->output_section
->vma
2094 + input_section
->output_offset
);
2097 else if ((bfd_get_section_flags (output_bfd
,
2098 input_section
->output_section
)
2099 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2101 if (_frv_osec_readonly_p (output_bfd
,
2102 input_section
->output_section
))
2104 info
->callbacks
->warning
2106 _("cannot emit dynamic relocations in read-only section"),
2107 name
, input_bfd
, input_section
, rel
->r_offset
);
2110 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
2111 _bfd_elf_section_offset
2113 input_section
, rel
->r_offset
)
2114 + input_section
->output_section
->vma
2115 + input_section
->output_offset
,
2116 r_type
, dynindx
, addend
);
2120 /* We want the addend in-place because dynamic
2121 relocations are REL. Setting relocation to it should
2122 arrange for it to be installed. */
2123 relocation
= addend
- rel
->r_addend
;
2125 check_segment
[0] = check_segment
[1] = got_segment
;
2129 case R_FRV_FUNCDESC_VALUE
:
2132 bfd_vma addend
= rel
->r_addend
;
2134 /* If the symbol is dynamic but binds locally, use
2136 if (h
&& ! FRV_SYM_LOCAL (info
, h
))
2138 if (addend
&& r_type
== R_FRV_FUNCDESC_VALUE
)
2140 info
->callbacks
->warning
2141 (info
, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2142 name
, input_bfd
, input_section
, rel
->r_offset
);
2145 dynindx
= h
->dynindx
;
2150 addend
+= h
->root
.u
.def
.value
;
2152 addend
+= sym
->st_value
;
2154 addend
+= osec
->output_offset
;
2155 if (osec
&& osec
->output_section
2156 && ! bfd_is_abs_section (osec
->output_section
)
2157 && ! bfd_is_und_section (osec
->output_section
))
2158 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
2163 /* If we're linking an executable at a fixed address, we
2164 can omit the dynamic relocation as long as the symbol
2165 is defined in the current link unit (which is implied
2166 by its output section not being NULL). */
2167 if (info
->executable
&& !info
->pie
2168 && (!h
|| FRV_SYM_LOCAL (info
, h
)))
2171 addend
+= osec
->output_section
->vma
;
2172 if ((elf_elfheader (input_bfd
)->e_flags
& EF_FRV_FDPIC
)
2173 && (bfd_get_section_flags (output_bfd
,
2174 input_section
->output_section
)
2175 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2177 if (_frv_osec_readonly_p (output_bfd
,
2178 input_section
->output_section
))
2180 info
->callbacks
->warning
2182 _("cannot emit fixups in read-only section"),
2183 name
, input_bfd
, input_section
, rel
->r_offset
);
2186 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
2188 _frv_add_rofixup (output_bfd
,
2189 frv_gotfixup_section (info
),
2190 _bfd_elf_section_offset
2192 input_section
, rel
->r_offset
)
2193 + input_section
->output_section
->vma
2194 + input_section
->output_offset
);
2195 if (r_type
== R_FRV_FUNCDESC_VALUE
)
2198 frv_gotfixup_section (info
),
2199 _bfd_elf_section_offset
2201 input_section
, rel
->r_offset
)
2202 + input_section
->output_section
->vma
2203 + input_section
->output_offset
+ 4);
2209 if ((bfd_get_section_flags (output_bfd
,
2210 input_section
->output_section
)
2211 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2213 if (_frv_osec_readonly_p (output_bfd
,
2214 input_section
->output_section
))
2216 info
->callbacks
->warning
2218 _("cannot emit dynamic relocations in read-only section"),
2219 name
, input_bfd
, input_section
, rel
->r_offset
);
2222 _frv_add_dyn_reloc (output_bfd
, frv_gotrel_section (info
),
2223 _bfd_elf_section_offset
2225 input_section
, rel
->r_offset
)
2226 + input_section
->output_section
->vma
2227 + input_section
->output_offset
,
2228 r_type
, dynindx
, addend
);
2230 /* We want the addend in-place because dynamic
2231 relocations are REL. Setting relocation to it
2232 should arrange for it to be installed. */
2233 relocation
= addend
- rel
->r_addend
;
2236 if (r_type
== R_FRV_FUNCDESC_VALUE
)
2238 /* If we've omitted the dynamic relocation, just emit
2239 the fixed addresses of the symbol and of the local
2241 if (info
->executable
&& !info
->pie
2242 && (!h
|| FRV_SYM_LOCAL (info
, h
)))
2243 bfd_put_32 (output_bfd
,
2244 frv_got_section (info
)->output_section
->vma
2245 + frv_got_section (info
)->output_offset
2246 + frv_got_initial_offset (info
),
2247 contents
+ rel
->r_offset
+ 4);
2249 /* A function descriptor used for lazy or local
2250 resolving is initialized such that its high word
2251 contains the output section index in which the
2252 PLT entries are located, and the low word
2253 contains the offset of the lazy PLT entry entry
2254 point into that section. */
2255 bfd_put_32 (output_bfd
,
2256 h
&& ! FRV_SYM_LOCAL (info
, h
)
2258 : _frv_osec_to_segment (output_bfd
,
2259 sec
->output_section
),
2260 contents
+ rel
->r_offset
+ 4);
2263 check_segment
[0] = check_segment
[1] = got_segment
;
2267 case R_FRV_GPRELU12
:
2271 check_segment
[0] = gprel_segment
;
2272 check_segment
[1] = sec
2273 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2278 check_segment
[0] = isec_segment
;
2279 check_segment
[1] = sec
2280 ? _frv_osec_to_segment (output_bfd
, sec
->output_section
)
2285 if (check_segment
[0] != check_segment
[1]
2286 && (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
))
2289 /* This helps catch problems in GCC while we can't do more
2290 than static linking. The idea is to test whether the
2291 input file basename is crt0.o only once. */
2292 if (silence_segment_error
== 1)
2293 silence_segment_error
=
2294 (strlen (input_bfd
->filename
) == 6
2295 && strcmp (input_bfd
->filename
, "crt0.o") == 0)
2296 || (strlen (input_bfd
->filename
) > 6
2297 && strcmp (input_bfd
->filename
2298 + strlen (input_bfd
->filename
) - 7,
2302 if (!silence_segment_error
2303 /* We don't want duplicate errors for undefined
2305 && !(picrel
&& picrel
->symndx
== -1
2306 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
2307 info
->callbacks
->warning
2309 (info
->shared
|| info
->pie
)
2310 ? _("relocations between different segments are not supported")
2311 : _("warning: relocation references a different segment"),
2312 name
, input_bfd
, input_section
, rel
->r_offset
);
2313 if (!silence_segment_error
&& (info
->shared
|| info
->pie
))
2315 elf_elfheader (output_bfd
)->e_flags
|= EF_FRV_PIC
;
2320 case R_FRV_GOTOFFHI
:
2321 /* We need the addend to be applied before we shift the
2323 relocation
+= rel
->r_addend
;
2326 case R_FRV_FUNCDESC_GOTHI
:
2327 case R_FRV_FUNCDESC_GOTOFFHI
:
2332 case R_FRV_FUNCDESC_GOTLO
:
2333 case R_FRV_GOTOFFLO
:
2334 case R_FRV_FUNCDESC_GOTOFFLO
:
2335 relocation
&= 0xffff;
2349 /* When referencing a GOT entry, a function descriptor or a
2350 PLT, we don't want the addend to apply to the reference,
2351 but rather to the referenced symbol. The actual entry
2352 will have already been created taking the addend into
2353 account, so cancel it out here. */
2357 case R_FRV_FUNCDESC_GOT12
:
2358 case R_FRV_FUNCDESC_GOTHI
:
2359 case R_FRV_FUNCDESC_GOTLO
:
2360 case R_FRV_FUNCDESC_GOTOFF12
:
2361 case R_FRV_FUNCDESC_GOTOFFHI
:
2362 case R_FRV_FUNCDESC_GOTOFFLO
:
2363 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
2364 here, since we do want to apply the addend to the others.
2365 Note that we've applied the addend to GOTOFFHI before we
2366 shifted it right. */
2367 case R_FRV_GOTOFFHI
:
2368 relocation
-= rel
->r_addend
;
2375 if (r_type
== R_FRV_HI16
)
2376 r
= elf32_frv_relocate_hi16 (input_bfd
, rel
, contents
, relocation
);
2378 else if (r_type
== R_FRV_LO16
)
2379 r
= elf32_frv_relocate_lo16 (input_bfd
, rel
, contents
, relocation
);
2381 else if (r_type
== R_FRV_LABEL24
)
2382 r
= elf32_frv_relocate_label24 (input_bfd
, input_section
, rel
,
2383 contents
, relocation
);
2385 else if (r_type
== R_FRV_GPREL12
)
2386 r
= elf32_frv_relocate_gprel12 (info
, input_bfd
, input_section
, rel
,
2387 contents
, relocation
);
2389 else if (r_type
== R_FRV_GPRELU12
)
2390 r
= elf32_frv_relocate_gprelu12 (info
, input_bfd
, input_section
, rel
,
2391 contents
, relocation
);
2393 else if (r_type
== R_FRV_GPRELLO
)
2394 r
= elf32_frv_relocate_gprello (info
, input_bfd
, input_section
, rel
,
2395 contents
, relocation
);
2397 else if (r_type
== R_FRV_GPRELHI
)
2398 r
= elf32_frv_relocate_gprelhi (info
, input_bfd
, input_section
, rel
,
2399 contents
, relocation
);
2402 r
= frv_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
2405 if (r
!= bfd_reloc_ok
)
2407 const char * msg
= (const char *) NULL
;
2411 case bfd_reloc_overflow
:
2412 r
= info
->callbacks
->reloc_overflow
2413 (info
, name
, howto
->name
, (bfd_vma
) 0,
2414 input_bfd
, input_section
, rel
->r_offset
);
2417 case bfd_reloc_undefined
:
2418 r
= info
->callbacks
->undefined_symbol
2419 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
2422 case bfd_reloc_outofrange
:
2423 msg
= _("internal error: out of range error");
2426 case bfd_reloc_notsupported
:
2427 msg
= _("internal error: unsupported relocation error");
2430 case bfd_reloc_dangerous
:
2431 msg
= _("internal error: dangerous relocation");
2435 msg
= _("internal error: unknown error");
2440 r
= info
->callbacks
->warning
2441 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
2451 /* Return the section that should be marked against GC for a given
2455 elf32_frv_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2457 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2458 Elf_Internal_Rela
*rel
;
2459 struct elf_link_hash_entry
*h
;
2460 Elf_Internal_Sym
*sym
;
2464 switch (ELF32_R_TYPE (rel
->r_info
))
2466 case R_FRV_GNU_VTINHERIT
:
2467 case R_FRV_GNU_VTENTRY
:
2471 switch (h
->root
.type
)
2476 case bfd_link_hash_defined
:
2477 case bfd_link_hash_defweak
:
2478 return h
->root
.u
.def
.section
;
2480 case bfd_link_hash_common
:
2481 return h
->root
.u
.c
.p
->section
;
2486 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2491 /* Update the got entry reference counts for the section being removed. */
2494 elf32_frv_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2495 bfd
*abfd ATTRIBUTE_UNUSED
;
2496 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2497 asection
*sec ATTRIBUTE_UNUSED
;
2498 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2504 /* Hook called by the linker routine which adds symbols from an object
2505 file. We use it to put .comm items in .scomm, and not .comm. */
2508 elf32_frv_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2510 struct bfd_link_info
*info
;
2511 const Elf_Internal_Sym
*sym
;
2512 const char **namep ATTRIBUTE_UNUSED
;
2513 flagword
*flagsp ATTRIBUTE_UNUSED
;
2517 if (sym
->st_shndx
== SHN_COMMON
2518 && !info
->relocatable
2519 && (int)sym
->st_size
<= (int)bfd_get_gp_size (abfd
))
2521 /* Common symbols less than or equal to -G nn bytes are
2522 automatically put into .sbss. */
2524 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
2528 scomm
= bfd_make_section (abfd
, ".scommon");
2530 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
2532 | SEC_LINKER_CREATED
)))
2537 *valp
= sym
->st_size
;
2542 /* Create a .got section, as well as its additional info field. This
2543 is almost entirely copied from
2544 elflink.c:_bfd_elf_create_got_section(). */
2547 _frv_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
2551 struct elf_link_hash_entry
*h
;
2552 struct bfd_link_hash_entry
*bh
;
2553 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2556 /* This function may be called more than once. */
2557 s
= bfd_get_section_by_name (abfd
, ".got");
2558 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
2561 /* Machine specific: although pointers are 32-bits wide, we want the
2562 GOT to be aligned to a 64-bit boundary, such that function
2563 descriptors in it can be accessed with 64-bit loads and
2567 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2568 | SEC_LINKER_CREATED
);
2570 s
= bfd_make_section (abfd
, ".got");
2572 || !bfd_set_section_flags (abfd
, s
, flags
)
2573 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
2576 if (bed
->want_got_plt
)
2578 s
= bfd_make_section (abfd
, ".got.plt");
2580 || !bfd_set_section_flags (abfd
, s
, flags
)
2581 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
2585 if (bed
->want_got_sym
)
2587 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
2588 (or .got.plt) section. We don't do this in the linker script
2589 because we don't want to define the symbol if we are not creating
2590 a global offset table. */
2592 if (!(_bfd_generic_link_add_one_symbol
2593 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
2594 bed
->got_symbol_offset
, (const char *) NULL
, FALSE
,
2595 bed
->collect
, &bh
)))
2597 h
= (struct elf_link_hash_entry
*) bh
;
2598 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2599 h
->type
= STT_OBJECT
;
2601 /* Machine-specific: we want the symbol for executables as
2603 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2606 elf_hash_table (info
)->hgot
= h
;
2609 /* The first bit of the global offset table is the header. */
2610 s
->_raw_size
+= bed
->got_header_size
+ bed
->got_symbol_offset
;
2612 /* This is the machine-specific part. Create and initialize section
2613 data for the got. */
2614 frv_got_section (info
) = s
;
2615 frv_relocs_info (info
) = htab_try_create (1, frv_pic_relocs_info_hash
,
2616 frv_pic_relocs_info_eq
,
2618 if (! frv_relocs_info (info
))
2621 s
= bfd_make_section (abfd
, ".rel.got");
2623 || ! bfd_set_section_flags (abfd
, s
, (flags
| SEC_READONLY
))
2624 || ! bfd_set_section_alignment (abfd
, s
, 2))
2627 frv_gotrel_section (info
) = s
;
2629 /* Machine-specific. */
2630 s
= bfd_make_section (abfd
, ".rofixup");
2632 || ! bfd_set_section_flags (abfd
, s
, (flags
| SEC_READONLY
))
2633 || ! bfd_set_section_alignment (abfd
, s
, 2))
2636 frv_gotfixup_section (info
) = s
;
2638 /* Define _gp in .rofixup, for FDPIC. If it turns out that
2639 we're linking with a different linker script, the linker script
2640 will override it. */
2642 if (!(_bfd_generic_link_add_one_symbol
2643 (info
, abfd
, "_gp", BSF_GLOBAL
, s
, -2048, (const char *) NULL
, FALSE
,
2644 bed
->collect
, &bh
)))
2646 h
= (struct elf_link_hash_entry
*) bh
;
2647 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2648 h
->type
= STT_OBJECT
;
2650 /* Machine-specific: we want the symbol for executables as well. */
2651 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2657 /* Make sure the got and plt sections exist, and that our pointers in
2658 the link hash table point to them. */
2661 elf32_frv_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2663 /* This is mostly copied from
2664 elflink.c:_bfd_elf_create_dynamic_sections(). */
2665 flagword flags
, pltflags
;
2667 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2669 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2670 .rel[a].bss sections. */
2672 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2673 | SEC_LINKER_CREATED
);
2676 pltflags
|= SEC_CODE
;
2677 if (bed
->plt_not_loaded
)
2678 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
2679 if (bed
->plt_readonly
)
2680 pltflags
|= SEC_READONLY
;
2682 s
= bfd_make_section (abfd
, ".plt");
2684 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
2685 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
2687 /* FRV-specific: remember it. */
2688 frv_plt_section (info
) = s
;
2690 if (bed
->want_plt_sym
)
2692 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2694 struct elf_link_hash_entry
*h
;
2695 struct bfd_link_hash_entry
*bh
= NULL
;
2697 if (! (_bfd_generic_link_add_one_symbol
2698 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
, 0, NULL
,
2699 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2701 h
= (struct elf_link_hash_entry
*) bh
;
2702 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2703 h
->type
= STT_OBJECT
;
2705 if (! info
->executable
2706 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2710 /* FRV-specific: we want rel relocations for the plt. */
2711 s
= bfd_make_section (abfd
, ".rel.plt");
2713 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2714 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
2716 /* FRV-specific: remember it. */
2717 frv_pltrel_section (info
) = s
;
2719 /* FRV-specific: we want to create the GOT in the FRV way. */
2720 if (! _frv_create_got_section (abfd
, info
))
2723 /* FRV-specific: make sure we created everything we wanted. */
2724 BFD_ASSERT (frv_got_section (info
) && frv_gotrel_section (info
)
2725 && frv_gotfixup_section (info
)
2726 && frv_plt_section (info
) && frv_pltrel_section (info
));
2728 if (bed
->want_dynbss
)
2730 /* The .dynbss section is a place to put symbols which are defined
2731 by dynamic objects, are referenced by regular objects, and are
2732 not functions. We must allocate space for them in the process
2733 image and use a R_*_COPY reloc to tell the dynamic linker to
2734 initialize them at run time. The linker script puts the .dynbss
2735 section into the .bss section of the final image. */
2736 s
= bfd_make_section (abfd
, ".dynbss");
2738 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
2741 /* The .rel[a].bss section holds copy relocs. This section is not
2742 normally needed. We need to create it here, though, so that the
2743 linker will map it to an output section. We can't just create it
2744 only if we need it, because we will not know whether we need it
2745 until we have seen all the input files, and the first time the
2746 main linker code calls BFD after examining all the input files
2747 (size_dynamic_sections) the input sections have already been
2748 mapped to the output sections. If the section turns out not to
2749 be needed, we can discard it later. We will never need this
2750 section when generating a shared object, since they do not use
2754 s
= bfd_make_section (abfd
,
2755 (bed
->default_use_rela_p
2756 ? ".rela.bss" : ".rel.bss"));
2758 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2759 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
2767 /* The name of the dynamic interpreter. This is put in the .interp
2770 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2772 #define DEFAULT_STACK_SIZE 0x20000
2774 /* This structure is used to collect the number of entries present in
2775 each addressable range of the got. */
2776 struct _frv_dynamic_got_info
2778 /* Several bits of information about the current link. */
2779 struct bfd_link_info
*info
;
2780 /* Total size needed for GOT entries within the 12-, 16- or 32-bit
2782 bfd_vma got12
, gotlos
, gothilo
;
2783 /* Total size needed for function descriptor entries within the 12-,
2784 16- or 32-bit ranges. */
2785 bfd_vma fd12
, fdlos
, fdhilo
;
2786 /* Total size needed function descriptor entries referenced in PLT
2787 entries, that would be profitable to place in offsets close to
2788 the PIC register. */
2790 /* Total size needed by lazy PLT entries. */
2792 /* Number of relocations carried over from input object files. */
2793 unsigned long relocs
;
2794 /* Number of fixups introduced by relocations in input object files. */
2795 unsigned long fixups
;
2798 /* Compute the total GOT size required by each symbol in each range.
2799 Symbols may require up to 4 words in the GOT: an entry pointing to
2800 the symbol, an entry pointing to its function descriptor, and a
2801 private function descriptors taking two words. */
2804 _frv_count_got_plt_entries (void **entryp
, void *dinfo_
)
2806 struct frv_pic_relocs_info
*entry
= *entryp
;
2807 struct _frv_dynamic_got_info
*dinfo
= dinfo_
;
2809 /* Allocate space for a GOT entry pointing to the symbol. */
2812 else if (entry
->gotlos
)
2814 else if (entry
->gothilo
)
2815 dinfo
->gothilo
+= 4;
2820 /* Allocate space for a GOT entry pointing to the function
2824 else if (entry
->fdgotlos
)
2826 else if (entry
->fdgothilo
)
2827 dinfo
->gothilo
+= 4;
2832 /* Decide whether we need a PLT entry, a function descriptor in the
2833 GOT, and a lazy PLT entry for this symbol. */
2834 entry
->plt
= entry
->call
2835 && entry
->symndx
== -1 && ! FRV_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
2836 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
2837 entry
->privfd
= entry
->plt
2838 || entry
->fdgoff12
|| entry
->fdgofflos
|| entry
->fdgoffhilo
2839 || ((entry
->fd
|| entry
->fdgot12
|| entry
->fdgotlos
|| entry
->fdgothilo
)
2840 && (entry
->symndx
!= -1
2841 || FRV_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
2842 entry
->lazyplt
= entry
->privfd
2843 && entry
->symndx
== -1 && ! FRV_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
2844 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
2845 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
2847 /* Allocate space for a function descriptor. */
2848 if (entry
->fdgoff12
)
2850 else if (entry
->fdgofflos
)
2852 else if (entry
->privfd
&& entry
->plt
)
2854 else if (entry
->privfd
)
2863 if (!dinfo
->info
->executable
|| dinfo
->info
->pie
)
2864 dinfo
->relocs
+= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
;
2867 if (entry
->symndx
!= -1 || FRV_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
2869 if (entry
->symndx
!= -1
2870 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
2871 dinfo
->fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
2874 dinfo
->relocs
+= entry
->relocs32
+ entry
->relocsfdv
;
2875 if (entry
->symndx
!= -1 || FRV_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
2877 if (entry
->symndx
!= -1
2878 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
2879 dinfo
->fixups
+= entry
->relocsfd
;
2882 dinfo
->relocs
+= entry
->relocsfd
;
2888 /* This structure is used to assign offsets to got entries, function
2889 descriptors, plt entries and lazy plt entries. */
2891 struct _frv_dynamic_got_plt_info
2893 /* Summary information collected with _frv_count_got_plt_entries. */
2894 struct _frv_dynamic_got_info g
;
2896 /* For each addressable range, we record a MAX (positive) and MIN
2897 (negative) value. CUR is used to assign got entries, and it's
2898 incremented from an initial positive value to MAX, then from MIN
2899 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
2900 assign function descriptors, and it's decreased from an initial
2901 non-positive value to MIN, then from MAX down to CUR (unless CUR
2902 wraps around first). All of MIN, MAX, CUR and FDCUR always point
2903 to even words. ODD, if non-zero, indicates an odd word to be
2904 used for the next got entry, otherwise CUR is used and
2905 incremented by a pair of words, wrapping around when it reaches
2906 MAX. FDCUR is decremented (and wrapped) before the next function
2907 descriptor is chosen. FDPLT indicates the number of remaining
2908 slots that can be used for function descriptors used only by PLT
2910 struct _frv_dynamic_got_alloc_data
2912 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
2914 } got12
, gotlos
, gothilo
;
2917 /* Determine the positive and negative ranges to be used by each
2918 offset range in the GOT. FDCUR and CUR, that must be aligned to a
2919 double-word boundary, are the minimum (negative) and maximum
2920 (positive) GOT offsets already used by previous ranges, except for
2921 an ODD entry that may have been left behind. GOT and FD indicate
2922 the size of GOT entries and function descriptors that must be
2923 placed within the range from -WRAP to WRAP. If there's room left,
2924 up to FDPLT bytes should be reserved for additional function
2927 inline static bfd_signed_vma
2928 _frv_compute_got_alloc_data (struct _frv_dynamic_got_alloc_data
*gad
,
2929 bfd_signed_vma fdcur
,
2937 bfd_signed_vma wrapmin
= -wrap
;
2939 /* Start at the given initial points. */
2943 /* If we had an incoming odd word and we have any got entries that
2944 are going to use it, consume it, otherwise leave gad->odd at
2945 zero. We might force gad->odd to zero and return the incoming
2946 odd such that it is used by the next range, but then GOT entries
2947 might appear to be out of order and we wouldn't be able to
2948 shorten the GOT by one word if it turns out to end with an
2949 unpaired GOT entry. */
2959 /* If we're left with an unpaired GOT entry, compute its location
2960 such that we can return it. Otherwise, if got doesn't require an
2961 odd number of words here, either odd was already zero in the
2962 block above, or it was set to zero because got was non-zero, or
2963 got was already zero. In the latter case, we want the value of
2964 odd to carry over to the return statement, so we don't want to
2965 reset odd unless the condition below is true. */
2972 /* Compute the tentative boundaries of this range. */
2973 gad
->max
= cur
+ got
;
2974 gad
->min
= fdcur
- fd
;
2977 /* If function descriptors took too much space, wrap some of them
2979 if (gad
->min
< wrapmin
)
2981 gad
->max
+= wrapmin
- gad
->min
;
2984 /* If there is space left and we have function descriptors
2985 referenced in PLT entries that could take advantage of shorter
2986 offsets, place them here. */
2987 else if (fdplt
&& gad
->min
> wrapmin
)
2990 if ((bfd_vma
) (gad
->min
- wrapmin
) < fdplt
)
2991 fds
= gad
->min
- wrapmin
;
3000 /* If GOT entries took too much space, wrap some of them around.
3001 This may well cause gad->min to become lower than wrapmin. This
3002 will cause a relocation overflow later on, so we don't have to
3004 if ((bfd_vma
) gad
->max
> wrap
)
3006 gad
->min
-= gad
->max
- wrap
;
3009 /* If there is more space left, try to place some more function
3010 descriptors for PLT entries. */
3011 else if (fdplt
&& (bfd_vma
) gad
->max
< wrap
)
3014 if ((bfd_vma
) (wrap
- gad
->max
) < fdplt
)
3015 fds
= wrap
- gad
->max
;
3024 /* If odd was initially computed as an offset past the wrap point,
3027 odd
= gad
->min
+ odd
- gad
->max
;
3029 /* _frv_get_got_entry() below will always wrap gad->cur if needed
3030 before returning, so do it here too. This guarantees that,
3031 should cur and fdcur meet at the wrap point, they'll both be
3033 if (gad
->cur
== gad
->max
)
3034 gad
->cur
= gad
->min
;
3039 /* Compute the location of the next GOT entry, given the allocation
3040 data for a range. */
3042 inline static bfd_signed_vma
3043 _frv_get_got_entry (struct _frv_dynamic_got_alloc_data
*gad
)
3049 /* If there was an odd word left behind, use it. */
3055 /* Otherwise, use the word pointed to by cur, reserve the next
3056 as an odd word, and skip to the next pair of words, possibly
3059 gad
->odd
= gad
->cur
+ 4;
3061 if (gad
->cur
== gad
->max
)
3062 gad
->cur
= gad
->min
;
3068 /* Compute the location of the next function descriptor entry in the
3069 GOT, given the allocation data for a range. */
3071 inline static bfd_signed_vma
3072 _frv_get_fd_entry (struct _frv_dynamic_got_alloc_data
*gad
)
3074 /* If we're at the bottom, wrap around, and only then allocate the
3075 next pair of words. */
3076 if (gad
->fdcur
== gad
->min
)
3077 gad
->fdcur
= gad
->max
;
3078 return gad
->fdcur
-= 8;
3081 /* Assign GOT offsets for every GOT entry and function descriptor.
3082 Doing everything in a single pass is tricky. */
3085 _frv_assign_got_entries (void **entryp
, void *info_
)
3087 struct frv_pic_relocs_info
*entry
= *entryp
;
3088 struct _frv_dynamic_got_plt_info
*dinfo
= info_
;
3091 entry
->got_entry
= _frv_get_got_entry (&dinfo
->got12
);
3092 else if (entry
->gotlos
)
3093 entry
->got_entry
= _frv_get_got_entry (&dinfo
->gotlos
);
3094 else if (entry
->gothilo
)
3095 entry
->got_entry
= _frv_get_got_entry (&dinfo
->gothilo
);
3098 entry
->fdgot_entry
= _frv_get_got_entry (&dinfo
->got12
);
3099 else if (entry
->fdgotlos
)
3100 entry
->fdgot_entry
= _frv_get_got_entry (&dinfo
->gotlos
);
3101 else if (entry
->fdgothilo
)
3102 entry
->fdgot_entry
= _frv_get_got_entry (&dinfo
->gothilo
);
3104 if (entry
->fdgoff12
)
3105 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->got12
);
3106 else if (entry
->plt
&& dinfo
->got12
.fdplt
)
3108 dinfo
->got12
.fdplt
-= 8;
3109 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->got12
);
3111 else if (entry
->fdgofflos
)
3112 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gotlos
);
3113 else if (entry
->plt
&& dinfo
->gotlos
.fdplt
)
3115 dinfo
->gotlos
.fdplt
-= 8;
3116 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gotlos
);
3118 else if (entry
->plt
)
3120 dinfo
->gothilo
.fdplt
-= 8;
3121 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gothilo
);
3123 else if (entry
->privfd
)
3124 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gothilo
);
3129 /* Assign GOT offsets to private function descriptors used by PLT
3130 entries (or referenced by 32-bit offsets), as well as PLT entries
3131 and lazy PLT entries. */
3134 _frv_assign_plt_entries (void **entryp
, void *info_
)
3136 struct frv_pic_relocs_info
*entry
= *entryp
;
3137 struct _frv_dynamic_got_plt_info
*dinfo
= info_
;
3139 /* If this symbol requires a local function descriptor, allocate
3141 if (entry
->privfd
&& entry
->fd_entry
== 0)
3143 if (dinfo
->got12
.fdplt
)
3145 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->got12
);
3146 dinfo
->got12
.fdplt
-= 8;
3148 else if (dinfo
->gotlos
.fdplt
)
3150 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gotlos
);
3151 dinfo
->gotlos
.fdplt
-= 8;
3155 BFD_ASSERT (dinfo
->gothilo
.fdplt
)
3156 entry
->fd_entry
= _frv_get_fd_entry (&dinfo
->gothilo
);
3157 dinfo
->gothilo
.fdplt
-= 8;
3165 /* We use the section's raw size to mark the location of the
3167 entry
->plt_entry
= frv_plt_section (dinfo
->g
.info
)->_raw_size
;
3169 /* Figure out the length of this PLT entry based on the
3170 addressing mode we need to reach the function descriptor. */
3171 BFD_ASSERT (entry
->fd_entry
);
3172 if (entry
->fd_entry
>= -(1 << (12 - 1))
3173 && entry
->fd_entry
< (1 << (12 - 1)))
3175 else if (entry
->fd_entry
>= -(1 << (16 - 1))
3176 && entry
->fd_entry
< (1 << (16 - 1)))
3181 frv_plt_section (dinfo
->g
.info
)->_raw_size
+= size
;
3186 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
3187 dinfo
->g
.lzplt
+= 8;
3188 /* If this entry is the one that gets the resolver stub, account
3189 for the additional instruction. */
3190 if (entry
->lzplt_entry
% FRV_LZPLT_BLOCK_SIZE
== FRV_LZPLT_RESOLV_LOC
)
3191 dinfo
->g
.lzplt
+= 4;
3197 /* Follow indirect and warning hash entries so that each got entry
3198 points to the final symbol definition. P must point to a pointer
3199 to the hash table we're traversing. Since this traversal may
3200 modify the hash table, we set this pointer to NULL to indicate
3201 we've made a potentially-destructive change to the hash table, so
3202 the traversal must be restarted. */
3204 _frv_resolve_final_relocs_info (void **entryp
, void *p
)
3206 struct frv_pic_relocs_info
*entry
= *entryp
;
3209 if (entry
->symndx
== -1)
3211 struct elf_link_hash_entry
*h
= entry
->d
.h
;
3213 while (h
->root
.type
== bfd_link_hash_indirect
3214 || h
->root
.type
== bfd_link_hash_warning
)
3215 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
3217 if (entry
->d
.h
== h
)
3222 /* If we can't find this entry with the new bfd hash, re-insert
3223 it, and get the traversal restarted. */
3224 if (! htab_find (*htab
, entry
))
3226 htab_clear_slot (*htab
, entryp
);
3227 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
3230 /* Abort the traversal, since the whole table may have
3231 moved, and leave it up to the parent to restart the
3233 *(htab_t
*)p
= NULL
;
3241 /* Set the sizes of the dynamic sections. */
3244 elf32_frv_size_dynamic_sections (bfd
*output_bfd
,
3245 struct bfd_link_info
*info
)
3249 struct _frv_dynamic_got_plt_info gpinfo
;
3253 dynobj
= elf_hash_table (info
)->dynobj
;
3254 BFD_ASSERT (dynobj
!= NULL
);
3256 if (elf_hash_table (info
)->dynamic_sections_created
)
3258 /* Set the contents of the .interp section to the interpreter. */
3259 if (info
->executable
)
3261 s
= bfd_get_section_by_name (dynobj
, ".interp");
3262 BFD_ASSERT (s
!= NULL
);
3263 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3264 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
3268 memset (&gpinfo
, 0, sizeof (gpinfo
));
3269 gpinfo
.g
.info
= info
;
3273 htab_t relocs
= frv_relocs_info (info
);
3275 htab_traverse (relocs
, _frv_resolve_final_relocs_info
, &relocs
);
3277 if (relocs
== frv_relocs_info (info
))
3281 htab_traverse (frv_relocs_info (info
), _frv_count_got_plt_entries
,
3285 /* Compute the total size taken by entries in the 12-bit and 16-bit
3286 ranges, to tell how many PLT function descriptors we can bring
3287 into the 12-bit range without causing the 16-bit range to
3289 limit
= odd
+ gpinfo
.g
.got12
+ gpinfo
.g
.gotlos
3290 + gpinfo
.g
.fd12
+ gpinfo
.g
.fdlos
;
3291 if (limit
< (bfd_vma
)1 << 16)
3292 limit
= ((bfd_vma
)1 << 16) - limit
;
3295 if (gpinfo
.g
.fdplt
< limit
)
3296 limit
= gpinfo
.g
.fdplt
;
3298 /* Determine the ranges of GOT offsets that we can use for each
3299 range of addressing modes. */
3300 odd
= _frv_compute_got_alloc_data (&gpinfo
.got12
,
3307 (bfd_vma
)1 << (12-1));
3308 odd
= _frv_compute_got_alloc_data (&gpinfo
.gotlos
,
3314 gpinfo
.g
.fdplt
- gpinfo
.got12
.fdplt
,
3315 (bfd_vma
)1 << (16-1));
3316 odd
= _frv_compute_got_alloc_data (&gpinfo
.gothilo
,
3322 gpinfo
.g
.fdplt
- gpinfo
.got12
.fdplt
3323 - gpinfo
.gotlos
.fdplt
,
3324 (bfd_vma
)1 << (32-1));
3326 /* Now assign (most) GOT offsets. */
3327 htab_traverse (frv_relocs_info (info
), _frv_assign_got_entries
, &gpinfo
);
3329 frv_got_section (info
)->_raw_size
= gpinfo
.gothilo
.max
- gpinfo
.gothilo
.min
3330 /* If an odd word is the last word of the GOT, we don't need this
3331 word to be part of the GOT. */
3332 - (odd
+ 4 == gpinfo
.gothilo
.max
? 4 : 0);
3333 if (frv_got_section (info
)->_raw_size
== 0)
3334 frv_got_section (info
)->flags
|= SEC_EXCLUDE
;
3335 else if (frv_got_section (info
)->_raw_size
== 12
3336 && ! elf_hash_table (info
)->dynamic_sections_created
)
3338 frv_got_section (info
)->flags
|= SEC_EXCLUDE
;
3339 frv_got_section (info
)->_raw_size
= 0;
3343 frv_got_section (info
)->contents
=
3344 (bfd_byte
*) bfd_zalloc (dynobj
, frv_got_section (info
)->_raw_size
);
3345 if (frv_got_section (info
)->contents
== NULL
)
3349 if (elf_hash_table (info
)->dynamic_sections_created
)
3350 /* Subtract the number of lzplt entries, since those will generate
3351 relocations in the pltrel section. */
3352 frv_gotrel_section (info
)->_raw_size
=
3353 (gpinfo
.g
.relocs
- gpinfo
.g
.lzplt
/ 8)
3354 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
3356 BFD_ASSERT (gpinfo
.g
.relocs
== 0);
3357 if (frv_gotrel_section (info
)->_raw_size
== 0)
3358 frv_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
3361 frv_gotrel_section (info
)->contents
=
3362 (bfd_byte
*) bfd_zalloc (dynobj
, frv_gotrel_section (info
)->_raw_size
);
3363 if (frv_gotrel_section (info
)->contents
== NULL
)
3367 if (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3368 frv_gotfixup_section (info
)->_raw_size
= (gpinfo
.g
.fixups
+ 1) * 4;
3369 if (frv_gotfixup_section (info
)->_raw_size
== 0)
3370 frv_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
3373 frv_gotfixup_section (info
)->contents
=
3374 (bfd_byte
*) bfd_zalloc (dynobj
,
3375 frv_gotfixup_section (info
)->_raw_size
);
3376 if (frv_gotfixup_section (info
)->contents
== NULL
)
3380 if (elf_hash_table (info
)->dynamic_sections_created
)
3382 frv_pltrel_section (info
)->_raw_size
=
3383 gpinfo
.g
.lzplt
/ 8 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
3384 if (frv_pltrel_section (info
)->_raw_size
== 0)
3385 frv_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
3388 frv_pltrel_section (info
)->contents
=
3389 (bfd_byte
*) bfd_zalloc (dynobj
,
3390 frv_pltrel_section (info
)->_raw_size
);
3391 if (frv_pltrel_section (info
)->contents
== NULL
)
3396 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3397 such that there's room for the additional instruction needed to
3398 call the resolver. Since _frv_assign_got_entries didn't account
3399 for them, our block size is 4 bytes smaller than the real block
3401 if (elf_hash_table (info
)->dynamic_sections_created
)
3403 frv_plt_section (info
)->_raw_size
= gpinfo
.g
.lzplt
3404 + ((gpinfo
.g
.lzplt
+ (FRV_LZPLT_BLOCK_SIZE
- 4) - 8)
3405 / (FRV_LZPLT_BLOCK_SIZE
- 4) * 4);
3408 /* Reset it, such that _frv_assign_plt_entries() can use it to
3409 actually assign lazy PLT entries addresses. */
3412 /* Save information that we're going to need to generate GOT and PLT
3414 frv_got_initial_offset (info
) = -gpinfo
.gothilo
.min
;
3416 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
3417 elf_hash_table (info
)->hgot
->root
.u
.def
.value
3418 += frv_got_initial_offset (info
);
3420 if (elf_hash_table (info
)->dynamic_sections_created
)
3421 frv_plt_initial_offset (info
) = frv_plt_section (info
)->_raw_size
;
3423 htab_traverse (frv_relocs_info (info
), _frv_assign_plt_entries
, &gpinfo
);
3425 /* Allocate the PLT section contents only after
3426 _frv_assign_plt_entries has a chance to add the size of the
3427 non-lazy PLT entries. */
3428 if (elf_hash_table (info
)->dynamic_sections_created
)
3430 if (frv_plt_section (info
)->_raw_size
== 0)
3431 frv_plt_section (info
)->flags
|= SEC_EXCLUDE
;
3434 frv_plt_section (info
)->contents
=
3435 (bfd_byte
*) bfd_zalloc (dynobj
, frv_plt_section (info
)->_raw_size
);
3436 if (frv_plt_section (info
)->contents
== NULL
)
3441 if (elf_hash_table (info
)->dynamic_sections_created
)
3443 if (frv_got_section (info
)->_raw_size
)
3444 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
3447 if (frv_pltrel_section (info
)->_raw_size
)
3448 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3449 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
3450 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
3453 if (frv_gotrel_section (info
)->_raw_size
)
3454 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0)
3455 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0)
3456 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
,
3457 sizeof (Elf32_External_Rel
)))
3465 elf32_frv_always_size_sections (bfd
*output_bfd
,
3466 struct bfd_link_info
*info
)
3468 if (!info
->relocatable
3469 && elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3471 struct elf_link_hash_entry
*h
;
3474 /* Force a PT_GNU_STACK segment to be created. */
3475 if (! elf_tdata (output_bfd
)->stack_flags
)
3476 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
3478 /* Define __stacksize if it's not defined yet. */
3479 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3480 FALSE
, FALSE
, FALSE
);
3481 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
3482 || h
->type
!= STT_OBJECT
3483 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3485 struct bfd_link_hash_entry
*bh
= NULL
;
3487 if (!(_bfd_generic_link_add_one_symbol
3488 (info
, output_bfd
, "__stacksize",
3489 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
3490 (const char *) NULL
, FALSE
,
3491 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
3494 h
= (struct elf_link_hash_entry
*) bh
;
3495 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3496 h
->type
= STT_OBJECT
;
3499 /* Create a stack section, and set its alignment. */
3500 sec
= bfd_make_section (output_bfd
, ".stack");
3503 || ! bfd_set_section_alignment (output_bfd
, sec
, 3))
3511 elf32_frv_modify_segment_map (bfd
*output_bfd
,
3512 struct bfd_link_info
*info
)
3514 if (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3516 struct elf_segment_map
*m
;
3518 for (m
= elf_tdata (output_bfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
3519 if (m
->p_type
== PT_GNU_STACK
)
3524 asection
*sec
= bfd_get_section_by_name (output_bfd
, ".stack");
3525 struct elf_link_hash_entry
*h
;
3529 /* Obtain the pointer to the __stacksize symbol. */
3530 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3531 FALSE
, FALSE
, FALSE
);
3532 while (h
->root
.type
== bfd_link_hash_indirect
3533 || h
->root
.type
== bfd_link_hash_warning
)
3534 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
3535 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
3537 /* Set the section size from the symbol value. We
3538 intentionally ignore the symbol section. */
3539 if (h
->root
.type
== bfd_link_hash_defined
)
3540 sec
->_raw_size
= h
->root
.u
.def
.value
;
3542 sec
->_raw_size
= DEFAULT_STACK_SIZE
;
3544 /* Add the stack section to the PT_GNU_STACK segment,
3545 such that its size and alignment requirements make it
3547 m
->sections
[m
->count
] = sec
;
3556 /* Fill in code and data in dynamic sections. */
3559 elf32_frv_finish_dynamic_sections (bfd
*output_bfd
,
3560 struct bfd_link_info
*info
)
3565 dynobj
= elf_hash_table (info
)->dynobj
;
3567 if (frv_got_section (info
))
3569 BFD_ASSERT (frv_gotrel_section (info
)->_raw_size
3570 == (frv_gotrel_section (info
)->reloc_count
3571 * sizeof (Elf32_External_Rel
)));
3573 if (frv_gotfixup_section (info
))
3575 if (elf_elfheader (output_bfd
)->e_flags
& EF_FRV_FDPIC
)
3577 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
3578 bfd_vma got_value
= hgot
->root
.u
.def
.value
3579 + hgot
->root
.u
.def
.section
->output_section
->vma
3580 + hgot
->root
.u
.def
.section
->output_offset
;
3582 _frv_add_rofixup (output_bfd
, frv_gotfixup_section (info
),
3586 if (frv_gotfixup_section (info
)->_raw_size
3587 != (frv_gotfixup_section (info
)->reloc_count
* 4))
3589 if (!elf_hash_table (info
)->dynamic_sections_created
)
3591 info
->callbacks
->warning
3592 (info
, "no dynamic sections, missing -melf32frvfd?",
3593 ".rofixup", NULL
, NULL
, 0);
3600 if (elf_hash_table (info
)->dynamic_sections_created
)
3602 BFD_ASSERT (frv_pltrel_section (info
)->_raw_size
3603 == (frv_pltrel_section (info
)->reloc_count
3604 * sizeof (Elf32_External_Rel
)));
3607 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3609 if (elf_hash_table (info
)->dynamic_sections_created
)
3611 Elf32_External_Dyn
* dyncon
;
3612 Elf32_External_Dyn
* dynconend
;
3614 BFD_ASSERT (sdyn
!= NULL
);
3616 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3617 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3619 for (; dyncon
< dynconend
; dyncon
++)
3621 Elf_Internal_Dyn dyn
;
3623 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3631 dyn
.d_un
.d_ptr
= frv_got_section (info
)->output_section
->vma
3632 + frv_got_section (info
)->output_offset
3633 + frv_got_initial_offset (info
);
3634 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3638 dyn
.d_un
.d_ptr
= frv_pltrel_section (info
)->output_section
->vma
3639 + frv_pltrel_section (info
)->output_offset
;
3640 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3644 if (frv_pltrel_section (info
)->_cooked_size
!= 0)
3645 dyn
.d_un
.d_val
= frv_pltrel_section (info
)->_cooked_size
;
3647 dyn
.d_un
.d_val
= frv_pltrel_section (info
)->_raw_size
;
3648 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3657 /* Adjust a symbol defined by a dynamic object and referenced by a
3661 elf32_frv_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3662 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
3666 dynobj
= elf_hash_table (info
)->dynobj
;
3668 /* Make sure we know what is going on here. */
3669 BFD_ASSERT (dynobj
!= NULL
3670 && (h
->weakdef
!= NULL
3671 || ((h
->elf_link_hash_flags
3672 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3673 && (h
->elf_link_hash_flags
3674 & ELF_LINK_HASH_REF_REGULAR
) != 0
3675 && (h
->elf_link_hash_flags
3676 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3678 /* If this is a weak symbol, and there is a real definition, the
3679 processor independent code will have arranged for us to see the
3680 real definition first, and we can just use the same value. */
3681 if (h
->weakdef
!= NULL
)
3683 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3684 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3685 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3686 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3692 /* Perform any actions needed for dynamic symbols. */
3695 elf32_frv_finish_dynamic_symbol (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3696 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3697 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
3698 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
3703 /* Look through the relocs for a section during the first phase.
3705 Besides handling virtual table relocs for gc, we have to deal with
3706 all sorts of PIC-related relocations. We describe below the
3707 general plan on how to handle such relocations, even though we only
3708 collect information at this point, storing them in hash tables for
3709 perusal of later passes.
3711 32 relocations are propagated to the linker output when creating
3712 position-independent output. LO16 and HI16 relocations are not
3713 supposed to be encountered in this case.
3715 LABEL16 should always be resolvable by the linker, since it's only
3718 LABEL24, on the other hand, is used by calls. If it turns out that
3719 the target of a call is a dynamic symbol, a PLT entry must be
3720 created for it, which triggers the creation of a private function
3721 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
3723 GPREL relocations require the referenced symbol to be in the same
3724 segment as _gp, but this can only be checked later.
3726 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
3727 exist. LABEL24 might as well, since it may require a PLT entry,
3728 that will require a got.
3730 Non-FUNCDESC GOT relocations require a GOT entry to be created
3731 regardless of whether the symbol is dynamic. However, since a
3732 global symbol that turns out to not be exported may have the same
3733 address of a non-dynamic symbol, we don't assign GOT entries at
3734 this point, such that we can share them in this case. A relocation
3735 for the GOT entry always has to be created, be it to offset a
3736 private symbol by the section load address, be it to get the symbol
3737 resolved dynamically.
3739 FUNCDESC GOT relocations require a GOT entry to be created, and
3740 handled as if a FUNCDESC relocation was applied to the GOT entry in
3743 FUNCDESC relocations referencing a symbol that turns out to NOT be
3744 dynamic cause a private function descriptor to be created. The
3745 FUNCDESC relocation then decays to a 32 relocation that points at
3746 the private descriptor. If the symbol is dynamic, the FUNCDESC
3747 relocation is propagated to the linker output, such that the
3748 dynamic linker creates the canonical descriptor, pointing to the
3749 dynamically-resolved definition of the function.
3751 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
3752 symbols that are assigned to the same segment as the GOT, but we
3753 can only check this later, after we know the complete set of
3754 symbols defined and/or exported.
3756 FUNCDESC GOTOFF relocations require a function descriptor to be
3757 created and, unless lazy binding is disabled or the symbol is not
3758 dynamic, a lazy PLT entry. Since we can't tell at this point
3759 whether a symbol is going to be dynamic, we have to decide later
3760 whether to create a lazy PLT entry or bind the descriptor directly
3761 to the private function.
3763 FUNCDESC_VALUE relocations are not supposed to be present in object
3764 files, but they may very well be simply propagated to the linker
3765 output, since they have no side effect.
3768 A function descriptor always requires a FUNCDESC_VALUE relocation.
3769 Whether it's in .plt.rel or not depends on whether lazy binding is
3770 enabled and on whether the referenced symbol is dynamic.
3772 The existence of a lazy PLT requires the resolverStub lazy PLT
3773 entry to be present.
3776 As for assignment of GOT, PLT and lazy PLT entries, and private
3777 descriptors, we might do them all sequentially, but we can do
3778 better than that. For example, we can place GOT entries and
3779 private function descriptors referenced using 12-bit operands
3780 closer to the PIC register value, such that these relocations don't
3781 overflow. Those that are only referenced with LO16 relocations
3782 could come next, but we may as well place PLT-required function
3783 descriptors in the 12-bit range to make them shorter. Symbols
3784 referenced with LO16/HI16 may come next, but we may place
3785 additional function descriptors in the 16-bit range if we can
3786 reliably tell that we've already placed entries that are ever
3787 referenced with only LO16. PLT entries are therefore generated as
3788 small as possible, while not introducing relocation overflows in
3789 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
3790 generated before or after PLT entries, but not intermingled with
3791 them, such that we can have more lazy PLT entries in range for a
3792 branch to the resolverStub. The resolverStub should be emitted at
3793 the most distant location from the first lazy PLT entry such that
3794 it's still in range for a branch, or closer, if there isn't a need
3795 for so many lazy PLT entries. Additional lazy PLT entries may be
3796 emitted after the resolverStub, as long as branches are still in
3797 range. If the branch goes out of range, longer lazy PLT entries
3800 We could further optimize PLT and lazy PLT entries by giving them
3801 priority in assignment to closer-to-gr17 locations depending on the
3802 number of occurrences of references to them (assuming a function
3803 that's called more often is more important for performance, so its
3804 PLT entry should be faster), or taking hints from the compiler.
3805 Given infinite time and money... :-) */
3808 elf32_frv_check_relocs (abfd
, info
, sec
, relocs
)
3810 struct bfd_link_info
*info
;
3812 const Elf_Internal_Rela
*relocs
;
3814 Elf_Internal_Shdr
*symtab_hdr
;
3815 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
3816 const Elf_Internal_Rela
*rel
;
3817 const Elf_Internal_Rela
*rel_end
;
3819 struct frv_pic_relocs_info
*picrel
;
3821 if (info
->relocatable
)
3824 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3825 sym_hashes
= elf_sym_hashes (abfd
);
3826 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
3827 if (!elf_bad_symtab (abfd
))
3828 sym_hashes_end
-= symtab_hdr
->sh_info
;
3830 dynobj
= elf_hash_table (info
)->dynobj
;
3831 rel_end
= relocs
+ sec
->reloc_count
;
3832 for (rel
= relocs
; rel
< rel_end
; rel
++)
3834 struct elf_link_hash_entry
*h
;
3835 unsigned long r_symndx
;
3837 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3838 if (r_symndx
< symtab_hdr
->sh_info
)
3841 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3843 switch (ELF32_R_TYPE (rel
->r_info
))
3850 case R_FRV_FUNCDESC_GOT12
:
3851 case R_FRV_FUNCDESC_GOTHI
:
3852 case R_FRV_FUNCDESC_GOTLO
:
3853 case R_FRV_GOTOFF12
:
3854 case R_FRV_GOTOFFHI
:
3855 case R_FRV_GOTOFFLO
:
3856 case R_FRV_FUNCDESC_GOTOFF12
:
3857 case R_FRV_FUNCDESC_GOTOFFHI
:
3858 case R_FRV_FUNCDESC_GOTOFFLO
:
3859 case R_FRV_FUNCDESC
:
3860 case R_FRV_FUNCDESC_VALUE
:
3863 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
3864 if (! _frv_create_got_section (abfd
, info
))
3869 if (h
->dynindx
== -1)
3870 switch (ELF_ST_VISIBILITY (h
->other
))
3876 bfd_elf32_link_record_dynamic_symbol (info
, h
);
3880 = frv_pic_relocs_info_for_global (frv_relocs_info (info
),
3885 picrel
= frv_pic_relocs_info_for_local (frv_relocs_info (info
),
3897 switch (ELF32_R_TYPE (rel
->r_info
))
3903 case R_FRV_FUNCDESC_VALUE
:
3904 picrel
->relocsfdv
++;
3905 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
3910 if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
3920 picrel
->gothilo
= 1;
3923 case R_FRV_FUNCDESC_GOT12
:
3924 picrel
->fdgot12
= 1;
3927 case R_FRV_FUNCDESC_GOTHI
:
3928 case R_FRV_FUNCDESC_GOTLO
:
3929 picrel
->fdgothilo
= 1;
3932 case R_FRV_GOTOFF12
:
3933 case R_FRV_GOTOFFHI
:
3934 case R_FRV_GOTOFFLO
:
3938 case R_FRV_FUNCDESC_GOTOFF12
:
3939 picrel
->fdgoff12
= 1;
3942 case R_FRV_FUNCDESC_GOTOFFHI
:
3943 case R_FRV_FUNCDESC_GOTOFFLO
:
3944 picrel
->fdgoffhilo
= 1;
3947 case R_FRV_FUNCDESC
:
3952 /* This relocation describes the C++ object vtable hierarchy.
3953 Reconstruct it for later use during GC. */
3954 case R_FRV_GNU_VTINHERIT
:
3955 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3959 /* This relocation describes which C++ vtable entries are actually
3960 used. Record for later use during GC. */
3961 case R_FRV_GNU_VTENTRY
:
3962 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3972 /* Return the machine subcode from the ELF e_flags header. */
3975 elf32_frv_machine (abfd
)
3978 switch (elf_elfheader (abfd
)->e_flags
& EF_FRV_CPU_MASK
)
3981 case EF_FRV_CPU_FR550
: return bfd_mach_fr550
;
3982 case EF_FRV_CPU_FR500
: return bfd_mach_fr500
;
3983 case EF_FRV_CPU_FR400
: return bfd_mach_fr400
;
3984 case EF_FRV_CPU_FR300
: return bfd_mach_fr300
;
3985 case EF_FRV_CPU_SIMPLE
: return bfd_mach_frvsimple
;
3986 case EF_FRV_CPU_TOMCAT
: return bfd_mach_frvtomcat
;
3989 return bfd_mach_frv
;
3992 /* Set the right machine number for a FRV ELF file. */
3995 elf32_frv_object_p (abfd
)
3998 bfd_default_set_arch_mach (abfd
, bfd_arch_frv
, elf32_frv_machine (abfd
));
4002 /* Function to set the ELF flag bits. */
4005 frv_elf_set_private_flags (abfd
, flags
)
4009 elf_elfheader (abfd
)->e_flags
= flags
;
4010 elf_flags_init (abfd
) = TRUE
;
4014 /* Copy backend specific data from one object module to another. */
4017 frv_elf_copy_private_bfd_data (ibfd
, obfd
)
4021 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4022 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4025 BFD_ASSERT (!elf_flags_init (obfd
)
4026 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
4028 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
4029 elf_flags_init (obfd
) = TRUE
;
4033 /* Merge backend specific data from an object file to the output
4034 object file when linking. */
4037 frv_elf_merge_private_bfd_data (ibfd
, obfd
)
4041 flagword old_flags
, old_partial
;
4042 flagword new_flags
, new_partial
;
4043 bfd_boolean error
= FALSE
;
4047 new_opt
[0] = old_opt
[0] = '\0';
4048 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4049 old_flags
= elf_elfheader (obfd
)->e_flags
;
4051 if (new_flags
& EF_FRV_FDPIC
)
4052 new_flags
&= ~EF_FRV_PIC
;
4055 (*_bfd_error_handler
) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
4056 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no",
4057 bfd_get_filename (ibfd
));
4060 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
4062 elf_flags_init (obfd
) = TRUE
;
4063 old_flags
= new_flags
;
4066 else if (new_flags
== old_flags
) /* Compatible flags are ok. */
4069 else /* Possibly incompatible flags. */
4071 /* Warn if different # of gprs are used. Note, 0 means nothing is
4072 said about the size of gprs. */
4073 new_partial
= (new_flags
& EF_FRV_GPR_MASK
);
4074 old_partial
= (old_flags
& EF_FRV_GPR_MASK
);
4075 if (new_partial
== old_partial
)
4078 else if (new_partial
== 0)
4081 else if (old_partial
== 0)
4082 old_flags
|= new_partial
;
4086 switch (new_partial
)
4088 default: strcat (new_opt
, " -mgpr-??"); break;
4089 case EF_FRV_GPR_32
: strcat (new_opt
, " -mgpr-32"); break;
4090 case EF_FRV_GPR_64
: strcat (new_opt
, " -mgpr-64"); break;
4093 switch (old_partial
)
4095 default: strcat (old_opt
, " -mgpr-??"); break;
4096 case EF_FRV_GPR_32
: strcat (old_opt
, " -mgpr-32"); break;
4097 case EF_FRV_GPR_64
: strcat (old_opt
, " -mgpr-64"); break;
4101 /* Warn if different # of fprs are used. Note, 0 means nothing is
4102 said about the size of fprs. */
4103 new_partial
= (new_flags
& EF_FRV_FPR_MASK
);
4104 old_partial
= (old_flags
& EF_FRV_FPR_MASK
);
4105 if (new_partial
== old_partial
)
4108 else if (new_partial
== 0)
4111 else if (old_partial
== 0)
4112 old_flags
|= new_partial
;
4116 switch (new_partial
)
4118 default: strcat (new_opt
, " -mfpr-?"); break;
4119 case EF_FRV_FPR_32
: strcat (new_opt
, " -mfpr-32"); break;
4120 case EF_FRV_FPR_64
: strcat (new_opt
, " -mfpr-64"); break;
4121 case EF_FRV_FPR_NONE
: strcat (new_opt
, " -msoft-float"); break;
4124 switch (old_partial
)
4126 default: strcat (old_opt
, " -mfpr-?"); break;
4127 case EF_FRV_FPR_32
: strcat (old_opt
, " -mfpr-32"); break;
4128 case EF_FRV_FPR_64
: strcat (old_opt
, " -mfpr-64"); break;
4129 case EF_FRV_FPR_NONE
: strcat (old_opt
, " -msoft-float"); break;
4133 /* Warn if different dword support was used. Note, 0 means nothing is
4134 said about the dword support. */
4135 new_partial
= (new_flags
& EF_FRV_DWORD_MASK
);
4136 old_partial
= (old_flags
& EF_FRV_DWORD_MASK
);
4137 if (new_partial
== old_partial
)
4140 else if (new_partial
== 0)
4143 else if (old_partial
== 0)
4144 old_flags
|= new_partial
;
4148 switch (new_partial
)
4150 default: strcat (new_opt
, " -mdword-?"); break;
4151 case EF_FRV_DWORD_YES
: strcat (new_opt
, " -mdword"); break;
4152 case EF_FRV_DWORD_NO
: strcat (new_opt
, " -mno-dword"); break;
4155 switch (old_partial
)
4157 default: strcat (old_opt
, " -mdword-?"); break;
4158 case EF_FRV_DWORD_YES
: strcat (old_opt
, " -mdword"); break;
4159 case EF_FRV_DWORD_NO
: strcat (old_opt
, " -mno-dword"); break;
4163 /* Or in flags that accumulate (ie, if one module uses it, mark that the
4165 old_flags
|= new_flags
& (EF_FRV_DOUBLE
4168 | EF_FRV_NON_PIC_RELOCS
);
4170 /* If any module was compiled without -G0, clear the G0 bit. */
4171 old_flags
= ((old_flags
& ~ EF_FRV_G0
)
4172 | (old_flags
& new_flags
& EF_FRV_G0
));
4174 /* If any module was compiled without -mnopack, clear the mnopack bit. */
4175 old_flags
= ((old_flags
& ~ EF_FRV_NOPACK
)
4176 | (old_flags
& new_flags
& EF_FRV_NOPACK
));
4178 /* We don't have to do anything if the pic flags are the same, or the new
4179 module(s) were compiled with -mlibrary-pic. */
4180 new_partial
= (new_flags
& EF_FRV_PIC_FLAGS
);
4181 old_partial
= (old_flags
& EF_FRV_PIC_FLAGS
);
4182 if ((new_partial
== old_partial
) || ((new_partial
& EF_FRV_LIBPIC
) != 0))
4185 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
4186 flags if any from the new module. */
4187 else if ((old_partial
& EF_FRV_LIBPIC
) != 0)
4188 old_flags
= (old_flags
& ~ EF_FRV_PIC_FLAGS
) | new_partial
;
4190 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
4191 else if (new_partial
!= 0 && old_partial
!= 0)
4192 old_flags
|= new_partial
;
4194 /* One module was compiled for pic and the other was not, see if we have
4195 had any relocations that are not pic-safe. */
4198 if ((old_flags
& EF_FRV_NON_PIC_RELOCS
) == 0)
4199 old_flags
|= new_partial
;
4202 old_flags
&= ~ EF_FRV_PIC_FLAGS
;
4203 #ifndef FRV_NO_PIC_ERROR
4205 (*_bfd_error_handler
)
4206 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
4207 bfd_get_filename (ibfd
),
4208 (new_flags
& EF_FRV_BIGPIC
) ? "-fPIC" : "-fpic");
4213 /* Warn if different cpu is used (allow a specific cpu to override
4214 the generic cpu). */
4215 new_partial
= (new_flags
& EF_FRV_CPU_MASK
);
4216 old_partial
= (old_flags
& EF_FRV_CPU_MASK
);
4217 if (new_partial
== old_partial
)
4220 else if (new_partial
== EF_FRV_CPU_GENERIC
)
4223 else if (old_partial
== EF_FRV_CPU_GENERIC
)
4224 old_flags
= (old_flags
& ~EF_FRV_CPU_MASK
) | new_partial
;
4228 switch (new_partial
)
4230 default: strcat (new_opt
, " -mcpu=?"); break;
4231 case EF_FRV_CPU_GENERIC
: strcat (new_opt
, " -mcpu=frv"); break;
4232 case EF_FRV_CPU_SIMPLE
: strcat (new_opt
, " -mcpu=simple"); break;
4233 case EF_FRV_CPU_FR550
: strcat (new_opt
, " -mcpu=fr550"); break;
4234 case EF_FRV_CPU_FR500
: strcat (new_opt
, " -mcpu=fr500"); break;
4235 case EF_FRV_CPU_FR400
: strcat (new_opt
, " -mcpu=fr400"); break;
4236 case EF_FRV_CPU_FR300
: strcat (new_opt
, " -mcpu=fr300"); break;
4237 case EF_FRV_CPU_TOMCAT
: strcat (new_opt
, " -mcpu=tomcat"); break;
4240 switch (old_partial
)
4242 default: strcat (old_opt
, " -mcpu=?"); break;
4243 case EF_FRV_CPU_GENERIC
: strcat (old_opt
, " -mcpu=frv"); break;
4244 case EF_FRV_CPU_SIMPLE
: strcat (old_opt
, " -mcpu=simple"); break;
4245 case EF_FRV_CPU_FR550
: strcat (old_opt
, " -mcpu=fr550"); break;
4246 case EF_FRV_CPU_FR500
: strcat (old_opt
, " -mcpu=fr500"); break;
4247 case EF_FRV_CPU_FR400
: strcat (old_opt
, " -mcpu=fr400"); break;
4248 case EF_FRV_CPU_FR300
: strcat (old_opt
, " -mcpu=fr300"); break;
4249 case EF_FRV_CPU_TOMCAT
: strcat (old_opt
, " -mcpu=tomcat"); break;
4253 /* Print out any mismatches from above. */
4257 (*_bfd_error_handler
)
4258 (_("%s: compiled with %s and linked with modules compiled with %s"),
4259 bfd_get_filename (ibfd
), new_opt
, old_opt
);
4262 /* Warn about any other mismatches */
4263 new_partial
= (new_flags
& ~ EF_FRV_ALL_FLAGS
);
4264 old_partial
= (old_flags
& ~ EF_FRV_ALL_FLAGS
);
4265 if (new_partial
!= old_partial
)
4267 old_flags
|= new_partial
;
4269 (*_bfd_error_handler
)
4270 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
4271 bfd_get_filename (ibfd
), (long)new_partial
, (long)old_partial
);
4275 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
4276 if ((old_flags
& EF_FRV_CPU_MASK
) == EF_FRV_CPU_SIMPLE
)
4277 old_flags
|= EF_FRV_NOPACK
;
4279 /* Update the old flags now with changes made above. */
4280 old_partial
= elf_elfheader (obfd
)->e_flags
& EF_FRV_CPU_MASK
;
4281 elf_elfheader (obfd
)->e_flags
= old_flags
;
4282 if (old_partial
!= (old_flags
& EF_FRV_CPU_MASK
))
4283 bfd_default_set_arch_mach (obfd
, bfd_arch_frv
, elf32_frv_machine (obfd
));
4286 bfd_set_error (bfd_error_bad_value
);
4293 frv_elf_print_private_bfd_data (abfd
, ptr
)
4297 FILE *file
= (FILE *) ptr
;
4300 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4302 /* Print normal ELF private data. */
4303 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4305 flags
= elf_elfheader (abfd
)->e_flags
;
4306 fprintf (file
, _("private flags = 0x%lx:"), (long)flags
);
4308 switch (flags
& EF_FRV_CPU_MASK
)
4311 case EF_FRV_CPU_SIMPLE
: fprintf (file
, " -mcpu=simple"); break;
4312 case EF_FRV_CPU_FR550
: fprintf (file
, " -mcpu=fr550"); break;
4313 case EF_FRV_CPU_FR500
: fprintf (file
, " -mcpu=fr500"); break;
4314 case EF_FRV_CPU_FR400
: fprintf (file
, " -mcpu=fr400"); break;
4315 case EF_FRV_CPU_FR300
: fprintf (file
, " -mcpu=fr300"); break;
4316 case EF_FRV_CPU_TOMCAT
: fprintf (file
, " -mcpu=tomcat"); break;
4319 switch (flags
& EF_FRV_GPR_MASK
)
4322 case EF_FRV_GPR_32
: fprintf (file
, " -mgpr-32"); break;
4323 case EF_FRV_GPR_64
: fprintf (file
, " -mgpr-64"); break;
4326 switch (flags
& EF_FRV_FPR_MASK
)
4329 case EF_FRV_FPR_32
: fprintf (file
, " -mfpr-32"); break;
4330 case EF_FRV_FPR_64
: fprintf (file
, " -mfpr-64"); break;
4331 case EF_FRV_FPR_NONE
: fprintf (file
, " -msoft-float"); break;
4334 switch (flags
& EF_FRV_DWORD_MASK
)
4337 case EF_FRV_DWORD_YES
: fprintf (file
, " -mdword"); break;
4338 case EF_FRV_DWORD_NO
: fprintf (file
, " -mno-dword"); break;
4341 if (flags
& EF_FRV_DOUBLE
)
4342 fprintf (file
, " -mdouble");
4344 if (flags
& EF_FRV_MEDIA
)
4345 fprintf (file
, " -mmedia");
4347 if (flags
& EF_FRV_MULADD
)
4348 fprintf (file
, " -mmuladd");
4350 if (flags
& EF_FRV_PIC
)
4351 fprintf (file
, " -fpic");
4353 if (flags
& EF_FRV_BIGPIC
)
4354 fprintf (file
, " -fPIC");
4356 if (flags
& EF_FRV_LIBPIC
)
4357 fprintf (file
, " -mlibrary-pic");
4359 if (flags
& EF_FRV_FDPIC
)
4360 fprintf (file
, " -mfdpic");
4362 if (flags
& EF_FRV_NON_PIC_RELOCS
)
4363 fprintf (file
, " non-pic relocations");
4365 if (flags
& EF_FRV_G0
)
4366 fprintf (file
, " -G0");
4373 #define ELF_ARCH bfd_arch_frv
4374 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
4375 #define ELF_MAXPAGESIZE 0x1000
4377 #define TARGET_BIG_SYM bfd_elf32_frv_vec
4378 #define TARGET_BIG_NAME "elf32-frv"
4380 #define elf_info_to_howto_rel frv_info_to_howto_rel
4381 #define elf_info_to_howto frv_info_to_howto_rela
4382 #define elf_backend_relocate_section elf32_frv_relocate_section
4383 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
4384 #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook
4385 #define elf_backend_check_relocs elf32_frv_check_relocs
4386 #define elf_backend_object_p elf32_frv_object_p
4387 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
4389 #define elf_backend_can_gc_sections 1
4390 #define elf_backend_rela_normal 1
4392 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
4393 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
4394 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
4395 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
4396 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
4398 #define bfd_elf32_bfd_link_hash_table_create frv_elf_link_hash_table_create
4399 #define elf_backend_always_size_sections \
4400 elf32_frv_always_size_sections
4401 #define elf_backend_modify_segment_map \
4402 elf32_frv_modify_segment_map
4404 #define elf_backend_create_dynamic_sections \
4405 elf32_frv_create_dynamic_sections
4406 #define elf_backend_adjust_dynamic_symbol \
4407 elf32_frv_adjust_dynamic_symbol
4408 #define elf_backend_size_dynamic_sections \
4409 elf32_frv_size_dynamic_sections
4410 #define elf_backend_finish_dynamic_symbol \
4411 elf32_frv_finish_dynamic_symbol
4412 #define elf_backend_finish_dynamic_sections \
4413 elf32_frv_finish_dynamic_sections
4415 #define elf_backend_want_got_sym 1
4416 #define elf_backend_got_header_size 0
4417 #define elf_backend_want_got_plt 0
4418 #define elf_backend_plt_readonly 1
4419 #define elf_backend_want_plt_sym 0
4420 #define elf_backend_plt_header_size 0
4422 #define elf_backend_may_use_rel_p 1
4423 #define elf_backend_may_use_rela_p 1
4424 /* We use REL for dynamic relocations only. */
4425 #define elf_backend_default_use_rela_p 1
4427 #include "elf32-target.h"