* elf32-frv.c (elf32_frv_howto_table) <R_FRV_LABEL16>: Set
[deliverable/binutils-gdb.git] / bfd / elf32-frv.c
1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
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.
10
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.
15
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. */
19
20 #include "bfd.h"
21 #include "sysdep.h"
22 #include "libbfd.h"
23 #include "elf-bfd.h"
24 #include "elf/frv.h"
25 #include "hashtab.h"
26
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
69 PARAMS ((bfd *));
70 static bfd_boolean elf32_frv_object_p
71 PARAMS ((bfd *));
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));
80
81 static reloc_howto_type elf32_frv_howto_table [] =
82 {
83 /* This reloc does nothing. */
84 HOWTO (R_FRV_NONE, /* type */
85 0, /* rightshift */
86 2, /* size (0 = byte, 1 = short, 2 = long) */
87 32, /* bitsize */
88 FALSE, /* pc_relative */
89 0, /* bitpos */
90 complain_overflow_bitfield, /* complain_on_overflow */
91 bfd_elf_generic_reloc, /* special_function */
92 "R_FRV_NONE", /* name */
93 FALSE, /* partial_inplace */
94 0, /* src_mask */
95 0, /* dst_mask */
96 FALSE), /* pcrel_offset */
97
98 /* A 32 bit absolute relocation. */
99 HOWTO (R_FRV_32, /* type */
100 0, /* rightshift */
101 2, /* size (0 = byte, 1 = short, 2 = long) */
102 32, /* bitsize */
103 FALSE, /* pc_relative */
104 0, /* bitpos */
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 */
112
113 /* A 16 bit pc-relative relocation. */
114 HOWTO (R_FRV_LABEL16, /* type */
115 2, /* rightshift */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
117 16, /* bitsize */
118 TRUE, /* pc_relative */
119 0, /* bitpos */
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 */
127
128 /* A 24-bit pc-relative relocation. */
129 HOWTO (R_FRV_LABEL24, /* type */
130 2, /* rightshift */
131 2, /* size (0 = byte, 1 = short, 2 = long) */
132 26, /* bitsize */
133 TRUE, /* pc_relative */
134 0, /* bitpos */
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 */
142
143 HOWTO (R_FRV_LO16, /* type */
144 0, /* rightshift */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
146 16, /* bitsize */
147 FALSE, /* pc_relative */
148 0, /* bitpos */
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 */
156
157 HOWTO (R_FRV_HI16, /* type */
158 0, /* rightshift */
159 2, /* size (0 = byte, 1 = short, 2 = long) */
160 16, /* bitsize */
161 FALSE, /* pc_relative */
162 0, /* bitpos */
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 */
170
171 HOWTO (R_FRV_GPREL12, /* type */
172 0, /* rightshift */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
174 12, /* bitsize */
175 FALSE, /* pc_relative */
176 0, /* bitpos */
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 */
184
185 HOWTO (R_FRV_GPRELU12, /* type */
186 0, /* rightshift */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
188 12, /* bitsize */
189 FALSE, /* pc_relative */
190 0, /* bitpos */
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 */
198
199 HOWTO (R_FRV_GPREL32, /* type */
200 0, /* rightshift */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
202 32, /* bitsize */
203 FALSE, /* pc_relative */
204 0, /* bitpos */
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 */
212
213 HOWTO (R_FRV_GPRELHI, /* type */
214 0, /* rightshift */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
216 16, /* bitsize */
217 FALSE, /* pc_relative */
218 0, /* bitpos */
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 */
226
227 HOWTO (R_FRV_GPRELLO, /* type */
228 0, /* rightshift */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
230 16, /* bitsize */
231 FALSE, /* pc_relative */
232 0, /* bitpos */
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 */
240
241 /* A 12-bit signed operand with the GOT offset for the address of
242 the symbol. */
243 HOWTO (R_FRV_GOT12, /* type */
244 0, /* rightshift */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
246 12, /* bitsize */
247 FALSE, /* pc_relative */
248 0, /* bitpos */
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 */
256
257 /* The upper 16 bits of the GOT offset for the address of the
258 symbol. */
259 HOWTO (R_FRV_GOTHI, /* type */
260 0, /* rightshift */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
262 16, /* bitsize */
263 FALSE, /* pc_relative */
264 0, /* bitpos */
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 */
272
273 /* The lower 16 bits of the GOT offset for the address of the
274 symbol. */
275 HOWTO (R_FRV_GOTLO, /* type */
276 0, /* rightshift */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
278 16, /* bitsize */
279 FALSE, /* pc_relative */
280 0, /* bitpos */
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 */
288
289 /* The 32-bit address of the canonical descriptor of a function. */
290 HOWTO (R_FRV_FUNCDESC, /* type */
291 0, /* rightshift */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
293 32, /* bitsize */
294 FALSE, /* pc_relative */
295 0, /* bitpos */
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 */
303
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 */
307 0, /* rightshift */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
309 12, /* bitsize */
310 FALSE, /* pc_relative */
311 0, /* bitpos */
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 */
319
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 */
323 0, /* rightshift */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
325 16, /* bitsize */
326 FALSE, /* pc_relative */
327 0, /* bitpos */
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 */
335
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 */
339 0, /* rightshift */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
341 16, /* bitsize */
342 FALSE, /* pc_relative */
343 0, /* bitpos */
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 */
351
352 /* The 32-bit address of the canonical descriptor of a function. */
353 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
354 0, /* rightshift */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
356 64, /* bitsize */
357 FALSE, /* pc_relative */
358 0, /* bitpos */
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 */
366
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 */
370 0, /* rightshift */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
372 12, /* bitsize */
373 FALSE, /* pc_relative */
374 0, /* bitpos */
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 */
382
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 */
386 0, /* rightshift */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
388 16, /* bitsize */
389 FALSE, /* pc_relative */
390 0, /* bitpos */
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 */
398
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 */
402 0, /* rightshift */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
404 16, /* bitsize */
405 FALSE, /* pc_relative */
406 0, /* bitpos */
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 */
414
415 /* A 12-bit signed operand with the GOT offset for the address of
416 the symbol. */
417 HOWTO (R_FRV_GOTOFF12, /* type */
418 0, /* rightshift */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
420 12, /* bitsize */
421 FALSE, /* pc_relative */
422 0, /* bitpos */
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 */
430
431 /* The upper 16 bits of the GOT offset for the address of the
432 symbol. */
433 HOWTO (R_FRV_GOTOFFHI, /* type */
434 0, /* rightshift */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
436 16, /* bitsize */
437 FALSE, /* pc_relative */
438 0, /* bitpos */
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 */
446
447 /* The lower 16 bits of the GOT offset for the address of the
448 symbol. */
449 HOWTO (R_FRV_GOTOFFLO, /* type */
450 0, /* rightshift */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
452 16, /* bitsize */
453 FALSE, /* pc_relative */
454 0, /* bitpos */
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 */
462
463 };
464
465 /* GNU extension to record C++ vtable hierarchy. */
466 static reloc_howto_type elf32_frv_vtinherit_howto =
467 HOWTO (R_FRV_GNU_VTINHERIT, /* type */
468 0, /* rightshift */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
470 0, /* bitsize */
471 FALSE, /* pc_relative */
472 0, /* bitpos */
473 complain_overflow_dont, /* complain_on_overflow */
474 NULL, /* special_function */
475 "R_FRV_GNU_VTINHERIT", /* name */
476 FALSE, /* partial_inplace */
477 0, /* src_mask */
478 0, /* dst_mask */
479 FALSE); /* pcrel_offset */
480
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 */
484 0, /* rightshift */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
486 0, /* bitsize */
487 FALSE, /* pc_relative */
488 0, /* bitpos */
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 */
493 0, /* src_mask */
494 0, /* dst_mask */
495 FALSE); /* pcrel_offset */
496
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 */
501 0, /* rightshift */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
503 32, /* bitsize */
504 FALSE, /* pc_relative */
505 0, /* bitpos */
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 */
513
514 static reloc_howto_type elf32_frv_rel_funcdesc_howto =
515 HOWTO (R_FRV_FUNCDESC, /* type */
516 0, /* rightshift */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
518 32, /* bitsize */
519 FALSE, /* pc_relative */
520 0, /* bitpos */
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 */
528
529 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
530 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
531 0, /* rightshift */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
533 64, /* bitsize */
534 FALSE, /* pc_relative */
535 0, /* bitpos */
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 */
543
544 \f
545 /* Map BFD reloc types to FRV ELF reloc types. */
546 #if 0
547 struct frv_reloc_map
548 {
549 unsigned int bfd_reloc_val;
550 unsigned int frv_reloc_val;
551 };
552
553 static const struct frv_reloc_map frv_reloc_map [] =
554 {
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 },
582 };
583 #endif
584
585
586 /* An extension of the elf hash table data structure, containing some
587 additional FRV-specific data. */
588 struct frv_elf_link_hash_table
589 {
590 struct elf_link_hash_table elf;
591
592 /* A pointer to the .got section. */
593 asection *sgot;
594 /* A pointer to the .rel.got section. */
595 asection *sgotrel;
596 /* A pointer to the .rofixup section. */
597 asection *sgotfixup;
598 /* A pointer to the .plt section. */
599 asection *splt;
600 /* A pointer to the .rel.plt section. */
601 asection *spltrel;
602 /* GOT base offset. */
603 bfd_vma got0;
604 /* Location of the first non-lazy PLT entry, i.e., the number of
605 bytes taken by lazy PLT entries. */
606 bfd_vma plt0;
607 /* A hash table holding information about which symbols were
608 referenced with which PIC-related relocations. */
609 struct htab *relocs_info;
610 };
611
612 /* Get the FRV ELF linker hash table from a link_info structure. */
613
614 #define frv_hash_table(info) \
615 ((struct frv_elf_link_hash_table *) ((info)->hash))
616
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)
633
634 /* Create an FRV ELF linker hash table. */
635
636 static struct bfd_link_hash_table *
637 frv_elf_link_hash_table_create (bfd *abfd)
638 {
639 struct frv_elf_link_hash_table *ret;
640 bfd_size_type amt = sizeof (struct frv_elf_link_hash_table);
641
642 ret = bfd_zalloc (abfd, amt);
643 if (ret == NULL)
644 return NULL;
645
646 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
647 _bfd_elf_link_hash_newfunc))
648 {
649 free (ret);
650 return NULL;
651 }
652
653 return &ret->elf.root;
654 }
655
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)
674
675 /* This structure collects information on what kind of GOT, PLT or
676 function descriptors are required by relocations that reference a
677 certain symbol. */
678 struct frv_pic_relocs_info
679 {
680 /* The index of the symbol, as stored in the relocation r_info, if
681 we have a local symbol; -1 otherwise. */
682 long symndx;
683 union
684 {
685 /* The input bfd in which the symbol is defined, if it's a local
686 symbol. */
687 bfd *abfd;
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;
692 } d;
693 /* The addend of the relocation that references the symbol. */
694 bfd_vma addend;
695
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
703 pairs. */
704 unsigned got12:1;
705 unsigned gotlos:1;
706 unsigned gothilo:1;
707 /* Whether a FUNCDESC relocation references symbol+addend. */
708 unsigned fd:1;
709 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
710 unsigned fdgot12:1;
711 unsigned fdgotlos:1;
712 unsigned fdgothilo:1;
713 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
714 unsigned fdgoff12:1;
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. */
721 unsigned gotoff:1;
722 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
723 unsigned call:1;
724 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
725 relocation. */
726 unsigned sym:1;
727 /* Whether we need a PLT entry for a symbol. Should be implied by
728 something like:
729 (call && symndx == -1 && ! FRV_SYM_LOCAL (info, d.h)) */
730 unsigned plt:1;
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)))) */
736 unsigned privfd:1;
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)) */
741 unsigned lazyplt:1;
742 /* Whether we've already emitted GOT relocations and PLT entries as
743 needed for this symbol. */
744 unsigned done:1;
745
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;
749
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
758 (bfd_vma)-1. */
759 bfd_vma plt_entry, lzplt_entry;
760 };
761
762 /* Compute a hash with the key fields of an frv_pic_relocs_info entry. */
763 static hashval_t
764 frv_pic_relocs_info_hash (const void *entry_)
765 {
766 const struct frv_pic_relocs_info *entry = entry_;
767
768 return (entry->symndx == -1
769 ? entry->d.h->root.root.hash
770 : entry->symndx + entry->d.abfd->id * 257) + entry->addend;
771 }
772
773 /* Test whether the key fields of two frv_pic_relocs_info entries are
774 identical. */
775 static int
776 frv_pic_relocs_info_eq (const void *entry1, const void *entry2)
777 {
778 const struct frv_pic_relocs_info *e1 = entry1;
779 const struct frv_pic_relocs_info *e2 = entry2;
780
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);
783 }
784
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,
790 bfd *abfd,
791 const struct frv_pic_relocs_info *entry)
792 {
793 struct frv_pic_relocs_info **loc =
794 (struct frv_pic_relocs_info **) htab_find_slot (ht, entry, INSERT);
795
796 if (*loc)
797 return *loc;
798
799 *loc = bfd_zalloc (abfd, sizeof (**loc));
800
801 if (! *loc)
802 return *loc;
803
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;
809
810 return *loc;
811 }
812
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,
818 bfd *abfd,
819 struct elf_link_hash_entry *h,
820 bfd_vma addend)
821 {
822 struct frv_pic_relocs_info entry;
823
824 entry.symndx = -1;
825 entry.d.h = h;
826 entry.addend = addend;
827
828 return frv_pic_relocs_info_find (ht, abfd, &entry);
829 }
830
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,
836 bfd *abfd,
837 long symndx,
838 bfd_vma addend)
839 {
840 struct frv_pic_relocs_info entry;
841
842 entry.symndx = symndx;
843 entry.d.abfd = abfd;
844 entry.addend = addend;
845
846 return frv_pic_relocs_info_find (ht, abfd, &entry);
847 }
848
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. */
853
854 #define FRV_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
855 #define FRV_LZPLT_RESOLV_LOC (8 * 32767)
856
857 /* Add a dynamic relocation to the SRELOC section. */
858
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)
862 {
863 Elf_Internal_Rela outrel;
864 bfd_vma reloc_offset;
865
866 outrel.r_offset = offset;
867 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
868 outrel.r_addend = addend;
869
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++;
875
876 return reloc_offset;
877 }
878
879 /* Add a fixup to the ROFIXUP section. */
880
881 static bfd_vma
882 _frv_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset)
883 {
884 bfd_vma fixup_offset;
885
886 if (rofixup->flags & SEC_EXCLUDE)
887 return -1;
888
889 fixup_offset = rofixup->reloc_count * 4;
890 if (rofixup->contents)
891 {
892 BFD_ASSERT (fixup_offset < rofixup->_raw_size);
893 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
894 }
895 rofixup->reloc_count++;
896
897 return fixup_offset;
898 }
899
900 /* Find the segment number in which OSEC, and output section, is
901 located. */
902
903 static unsigned
904 _frv_osec_to_segment (bfd *output_bfd, asection *osec)
905 {
906 struct elf_segment_map *m;
907 Elf_Internal_Phdr *p;
908
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;
912 m != NULL;
913 m = m->next, p++)
914 {
915 int i;
916
917 for (i = m->count - 1; i >= 0; i--)
918 if (m->sections[i] == osec)
919 break;
920
921 if (i >= 0)
922 break;
923 }
924
925 return p - elf_tdata (output_bfd)->phdr;
926 }
927
928 inline static bfd_boolean
929 _frv_osec_readonly_p (bfd *output_bfd, asection *osec)
930 {
931 unsigned seg = _frv_osec_to_segment (output_bfd, osec);
932
933 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
934 }
935
936 /* Generate relocations for GOT entries, function descriptors, and
937 code for PLT and lazy PLT entries. */
938
939 inline static bfd_boolean
940 _frv_emit_got_relocs_plt_entries (struct frv_pic_relocs_info *entry,
941 bfd *output_bfd,
942 struct bfd_link_info *info,
943 asection *sec,
944 Elf_Internal_Sym *sym,
945 bfd_vma addend)
946
947 {
948 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
949 int dynindx = -1;
950
951 if (entry->done)
952 return TRUE;
953 entry->done = 1;
954
955 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry)
956 {
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;
961 else
962 {
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;
967 else
968 dynindx = 0;
969 }
970 }
971
972 /* Generate relocation for GOT entry pointing to the symbol. */
973 if (entry->got_entry)
974 {
975 int idx = dynindx;
976 bfd_vma ad = addend;
977
978 /* If the symbol is dynamic but binds locally, use
979 section+offset. */
980 if (sec && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
981 {
982 if (entry->symndx == -1)
983 ad += entry->d.h->root.u.def.value;
984 else
985 ad += sym->st_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;
989 else
990 idx = 0;
991 }
992
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
995 this module. */
996 if (info->executable && !info->pie
997 && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
998 {
999 if (sec)
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);
1008 }
1009 else
1010 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
1011 _bfd_elf_section_offset
1012 (output_bfd, info,
1013 frv_got_section (info),
1014 frv_got_initial_offset (info)
1015 + entry->got_entry)
1016 + frv_got_section (info)->output_section->vma
1017 + frv_got_section (info)->output_offset,
1018 R_FRV_32, idx, ad);
1019
1020 bfd_put_32 (output_bfd, ad,
1021 frv_got_section (info)->contents
1022 + frv_got_initial_offset (info)
1023 + entry->got_entry);
1024 }
1025
1026 /* Generate relocation for GOT entry pointing to a canonical
1027 function descriptor. */
1028 if (entry->fdgot_entry)
1029 {
1030 int reloc, idx;
1031 bfd_vma ad = 0;
1032
1033 if (! (entry->symndx == -1
1034 && entry->d.h->root.type == bfd_link_hash_undefweak
1035 && FRV_SYM_LOCAL (info, entry->d.h)))
1036 {
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))
1047 {
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;
1053 }
1054 else if (entry->symndx == -1
1055 && ! FRV_FUNCDESC_LOCAL (info, entry->d.h))
1056 {
1057 reloc = R_FRV_FUNCDESC;
1058 idx = dynindx;
1059 ad = addend;
1060 if (ad)
1061 return FALSE;
1062 }
1063 else
1064 {
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);
1069 reloc = R_FRV_32;
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;
1074 }
1075
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)))
1085 {
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);
1092 }
1093 else
1094 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
1095 _bfd_elf_section_offset
1096 (output_bfd, info,
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,
1102 reloc, idx, ad);
1103 }
1104
1105 bfd_put_32 (output_bfd, ad,
1106 frv_got_section (info)->contents
1107 + frv_got_initial_offset (info)
1108 + entry->fdgot_entry);
1109 }
1110
1111 /* Generate relocation to fill in a private function descriptor in
1112 the GOT. */
1113 if (entry->fd_entry)
1114 {
1115 int idx = dynindx;
1116 bfd_vma ad = addend;
1117 bfd_vma ofst;
1118 long lowword, highword;
1119
1120 /* If the symbol is dynamic but binds locally, use
1121 section+offset. */
1122 if (sec && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1123 {
1124 if (entry->symndx == -1)
1125 ad += entry->d.h->root.u.def.value;
1126 else
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;
1131 else
1132 idx = 0;
1133 }
1134
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
1137 this module. */
1138 if (info->executable && !info->pie
1139 && (entry->symndx != -1 || FRV_SYM_LOCAL (info, entry->d.h)))
1140 {
1141 if (sec)
1142 ad += sec->output_section->vma;
1143 ofst = 0;
1144 if (entry->symndx != -1 ||
1145 entry->d.h->root.type != bfd_link_hash_undefweak)
1146 {
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)
1151 + entry->fd_entry);
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);
1157 }
1158 }
1159 else
1160 {
1161 ofst =
1162 _frv_add_dyn_reloc (output_bfd,
1163 entry->lazyplt ? frv_pltrel_section (info)
1164 : frv_gotrel_section (info),
1165 _bfd_elf_section_offset
1166 (output_bfd, info,
1167 frv_got_section (info),
1168 frv_got_initial_offset (info)
1169 + entry->fd_entry)
1170 + frv_got_section (info)->output_section->vma
1171 + frv_got_section (info)->output_offset,
1172 R_FRV_FUNCDESC_VALUE, idx, ad);
1173 }
1174
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)
1178 {
1179 lowword = ad;
1180 highword = frv_got_section (info)->output_section->vma
1181 + frv_got_section (info)->output_offset
1182 + frv_got_initial_offset (info);
1183 }
1184 else if (entry->lazyplt)
1185 {
1186 if (ad)
1187 return FALSE;
1188
1189 fd_lazy_rel_offset = ofst;
1190
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);
1202 }
1203 else
1204 {
1205 /* A function descriptor for a local function gets the index
1206 of the section. For a non-local function, it's
1207 disregarded. */
1208 lowword = ad;
1209 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1210 && entry->d.h->dynindx == idx)
1211 highword = 0;
1212 else
1213 highword = _frv_osec_to_segment (output_bfd, sec->output_section);
1214 }
1215
1216 bfd_put_32 (output_bfd, lowword,
1217 frv_got_section (info)->contents
1218 + frv_got_initial_offset (info)
1219 + entry->fd_entry);
1220 bfd_put_32 (output_bfd, highword,
1221 frv_got_section (info)->contents
1222 + frv_got_initial_offset (info)
1223 + entry->fd_entry + 4);
1224 }
1225
1226 /* Generate code for the PLT entry. */
1227 if (entry->plt_entry != (bfd_vma) -1)
1228 {
1229 bfd_byte *plt_code = frv_plt_section (info)->contents + entry->plt_entry;
1230
1231 BFD_ASSERT (entry->fd_entry);
1232
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)))
1237 {
1238 /* lddi @(gr15, fd_entry), gr14 */
1239 bfd_put_32 (output_bfd,
1240 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1241 plt_code);
1242 plt_code += 4;
1243 }
1244 else
1245 {
1246 if (entry->fd_entry >= -(1 << (16 - 1))
1247 && entry->fd_entry < (1 << (16 - 1)))
1248 {
1249 /* setlos lo(fd_entry), gr14 */
1250 bfd_put_32 (output_bfd,
1251 0x9cfc0000
1252 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1253 plt_code);
1254 plt_code += 4;
1255 }
1256 else
1257 {
1258 /* sethi.p hi(fd_entry), gr14
1259 setlo lo(fd_entry), gr14 */
1260 bfd_put_32 (output_bfd,
1261 0x1cf80000
1262 | ((entry->fd_entry >> 16)
1263 & (((bfd_vma)1 << 16) - 1)),
1264 plt_code);
1265 bfd_put_32 (output_bfd,
1266 0x9cf40000
1267 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1268 plt_code);
1269 plt_code += 8;
1270 }
1271 /* ldd @(gr14,gr15),gr14 */
1272 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1273 plt_code += 4;
1274 }
1275 /* jmpl @(gr14,gr0) */
1276 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1277 }
1278
1279 /* Generate code for the lazy PLT entry. */
1280 if (entry->lzplt_entry != (bfd_vma) -1)
1281 {
1282 bfd_byte *lzplt_code = frv_plt_section (info)->contents
1283 + entry->lzplt_entry;
1284 bfd_vma resolverStub_addr;
1285
1286 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1287 lzplt_code += 4;
1288
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;
1293
1294 if (entry->lzplt_entry == resolverStub_addr)
1295 {
1296 /* This is a lazy PLT entry that includes a resolver call. */
1297 /* ldd @(gr15,gr0), gr4
1298 jmpl @(gr4,gr0) */
1299 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1300 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1301 }
1302 else
1303 {
1304 /* bra resolverStub */
1305 bfd_put_32 (output_bfd,
1306 0xc01a0000
1307 | (((resolverStub_addr - entry->lzplt_entry)
1308 / 4) & (((bfd_vma)1 << 16) - 1)),
1309 lzplt_code);
1310 }
1311 }
1312
1313 return TRUE;
1314 }
1315
1316 /* Handle an FRV small data reloc. */
1317
1318 static bfd_reloc_status_type
1319 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
1320 contents, value)
1321 struct bfd_link_info *info;
1322 bfd *input_bfd;
1323 asection *input_section;
1324 Elf_Internal_Rela *relocation;
1325 bfd_byte *contents;
1326 bfd_vma value;
1327 {
1328 bfd_vma insn;
1329 bfd_vma gp;
1330 struct bfd_link_hash_entry *h;
1331
1332 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1333
1334 gp = (h->u.def.value
1335 + h->u.def.section->output_section->vma
1336 + h->u.def.section->output_offset);
1337
1338 value -= input_section->output_section->vma;
1339 value -= (gp - input_section->output_section->vma);
1340
1341 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1342
1343 value += relocation->r_addend;
1344
1345 if ((long) value > 0x7ff || (long) value < -0x800)
1346 return bfd_reloc_overflow;
1347
1348 bfd_put_32 (input_bfd,
1349 (insn & 0xfffff000) | (value & 0xfff),
1350 contents + relocation->r_offset);
1351
1352 return bfd_reloc_ok;
1353 }
1354
1355 /* Handle an FRV small data reloc. for the u12 field. */
1356
1357 static bfd_reloc_status_type
1358 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
1359 contents, value)
1360 struct bfd_link_info *info;
1361 bfd *input_bfd;
1362 asection *input_section;
1363 Elf_Internal_Rela *relocation;
1364 bfd_byte *contents;
1365 bfd_vma value;
1366 {
1367 bfd_vma insn;
1368 bfd_vma gp;
1369 struct bfd_link_hash_entry *h;
1370 bfd_vma mask;
1371
1372 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1373
1374 gp = (h->u.def.value
1375 + h->u.def.section->output_section->vma
1376 + h->u.def.section->output_offset);
1377
1378 value -= input_section->output_section->vma;
1379 value -= (gp - input_section->output_section->vma);
1380
1381 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1382
1383 value += relocation->r_addend;
1384
1385 if ((long) value > 0x7ff || (long) value < -0x800)
1386 return bfd_reloc_overflow;
1387
1388 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
1389 mask = 0x3f03f;
1390 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
1391
1392 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1393
1394 return bfd_reloc_ok;
1395 }
1396
1397 /* Handle an FRV ELF HI16 reloc. */
1398
1399 static bfd_reloc_status_type
1400 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
1401 bfd *input_bfd;
1402 Elf_Internal_Rela *relhi;
1403 bfd_byte *contents;
1404 bfd_vma value;
1405 {
1406 bfd_vma insn;
1407
1408 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
1409
1410 value += relhi->r_addend;
1411 value = ((value >> 16) & 0xffff);
1412
1413 insn = (insn & 0xffff0000) | value;
1414
1415 if ((long) value > 0xffff || (long) value < -0x10000)
1416 return bfd_reloc_overflow;
1417
1418 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
1419 return bfd_reloc_ok;
1420
1421 }
1422 static bfd_reloc_status_type
1423 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
1424 bfd *input_bfd;
1425 Elf_Internal_Rela *rello;
1426 bfd_byte *contents;
1427 bfd_vma value;
1428 {
1429 bfd_vma insn;
1430
1431 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1432
1433 value += rello->r_addend;
1434 value = value & 0xffff;
1435
1436 insn = (insn & 0xffff0000) | value;
1437
1438 if ((long) value > 0xffff || (long) value < -0x10000)
1439 return bfd_reloc_overflow;
1440
1441 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1442 return bfd_reloc_ok;
1443 }
1444
1445 /* Perform the relocation for the CALL label24 instruction. */
1446
1447 static bfd_reloc_status_type
1448 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
1449 bfd *input_bfd;
1450 asection *input_section;
1451 Elf_Internal_Rela *rello;
1452 bfd_byte *contents;
1453 bfd_vma value;
1454 {
1455 bfd_vma insn;
1456 bfd_vma label6;
1457 bfd_vma label18;
1458
1459 /* The format for the call instruction is:
1460
1461 0 000000 0001111 000000000000000000
1462 label6 opcode label18
1463
1464 The branch calculation is: pc + (4*label24)
1465 where label24 is the concatenation of label6 and label18. */
1466
1467 /* Grab the instruction. */
1468 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
1469
1470 value -= input_section->output_section->vma + input_section->output_offset;
1471 value -= rello->r_offset;
1472 value += rello->r_addend;
1473
1474 value = value >> 2;
1475
1476 label6 = value & 0xfc0000;
1477 label6 = label6 << 7;
1478
1479 label18 = value & 0x3ffff;
1480
1481 insn = insn & 0x803c0000;
1482 insn = insn | label6;
1483 insn = insn | label18;
1484
1485 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1486
1487 return bfd_reloc_ok;
1488 }
1489
1490 static bfd_reloc_status_type
1491 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
1492 contents, value)
1493 struct bfd_link_info *info;
1494 bfd *input_bfd;
1495 asection *input_section;
1496 Elf_Internal_Rela *relocation;
1497 bfd_byte *contents;
1498 bfd_vma value;
1499 {
1500 bfd_vma insn;
1501 bfd_vma gp;
1502 struct bfd_link_hash_entry *h;
1503
1504 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1505
1506 gp = (h->u.def.value
1507 + h->u.def.section->output_section->vma
1508 + h->u.def.section->output_offset);
1509
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);
1514
1515 if ((long) value > 0xffff || (long) value < -0x10000)
1516 return bfd_reloc_overflow;
1517
1518 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1519 insn = (insn & 0xffff0000) | value;
1520
1521 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1522 return bfd_reloc_ok;
1523 }
1524
1525 static bfd_reloc_status_type
1526 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
1527 contents, value)
1528 struct bfd_link_info *info;
1529 bfd *input_bfd;
1530 asection *input_section;
1531 Elf_Internal_Rela *relocation;
1532 bfd_byte *contents;
1533 bfd_vma value;
1534 {
1535 bfd_vma insn;
1536 bfd_vma gp;
1537 struct bfd_link_hash_entry *h;
1538
1539 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1540
1541 gp = (h->u.def.value
1542 + h->u.def.section->output_section->vma
1543 + h->u.def.section->output_offset);
1544
1545 value -= input_section->output_section->vma;
1546 value -= (gp - input_section->output_section->vma);
1547 value += relocation->r_addend;
1548 value = value & 0xffff;
1549
1550 if ((long) value > 0xffff || (long) value < -0x10000)
1551 return bfd_reloc_overflow;
1552
1553 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
1554 insn = (insn & 0xffff0000) | value;
1555
1556 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
1557
1558 return bfd_reloc_ok;
1559 }
1560
1561 static reloc_howto_type *
1562 frv_reloc_type_lookup (abfd, code)
1563 bfd *abfd ATTRIBUTE_UNUSED;
1564 bfd_reloc_code_real_type code;
1565 {
1566 switch (code)
1567 {
1568 default:
1569 break;
1570
1571 case BFD_RELOC_NONE:
1572 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
1573
1574 case BFD_RELOC_32:
1575 if (elf_elfheader (abfd)->e_type == ET_EXEC
1576 || elf_elfheader (abfd)->e_type == ET_DYN)
1577 return &elf32_frv_rel_32_howto;
1578 /* Fall through. */
1579 case BFD_RELOC_CTOR:
1580 return &elf32_frv_howto_table[ (int) R_FRV_32];
1581
1582 case BFD_RELOC_FRV_LABEL16:
1583 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
1584
1585 case BFD_RELOC_FRV_LABEL24:
1586 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
1587
1588 case BFD_RELOC_FRV_LO16:
1589 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
1590
1591 case BFD_RELOC_FRV_HI16:
1592 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
1593
1594 case BFD_RELOC_FRV_GPREL12:
1595 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
1596
1597 case BFD_RELOC_FRV_GPRELU12:
1598 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
1599
1600 case BFD_RELOC_FRV_GPREL32:
1601 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
1602
1603 case BFD_RELOC_FRV_GPRELHI:
1604 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
1605
1606 case BFD_RELOC_FRV_GPRELLO:
1607 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
1608
1609 case BFD_RELOC_FRV_GOT12:
1610 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
1611
1612 case BFD_RELOC_FRV_GOTHI:
1613 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
1614
1615 case BFD_RELOC_FRV_GOTLO:
1616 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
1617
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];
1623
1624 case BFD_RELOC_FRV_FUNCDESC_GOT12:
1625 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
1626
1627 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
1628 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
1629
1630 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
1631 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
1632
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];
1638
1639 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
1640 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
1641
1642 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
1643 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
1644
1645 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
1646 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
1647
1648 case BFD_RELOC_FRV_GOTOFF12:
1649 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
1650
1651 case BFD_RELOC_FRV_GOTOFFHI:
1652 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
1653
1654 case BFD_RELOC_FRV_GOTOFFLO:
1655 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
1656
1657 case BFD_RELOC_VTABLE_INHERIT:
1658 return &elf32_frv_vtinherit_howto;
1659
1660 case BFD_RELOC_VTABLE_ENTRY:
1661 return &elf32_frv_vtentry_howto;
1662 }
1663
1664 return NULL;
1665 }
1666
1667 /* Set the howto pointer for an FRV ELF reloc. */
1668
1669 static void
1670 frv_info_to_howto_rela (abfd, cache_ptr, dst)
1671 bfd *abfd ATTRIBUTE_UNUSED;
1672 arelent *cache_ptr;
1673 Elf_Internal_Rela *dst;
1674 {
1675 unsigned int r_type;
1676
1677 r_type = ELF32_R_TYPE (dst->r_info);
1678 switch (r_type)
1679 {
1680 case R_FRV_GNU_VTINHERIT:
1681 cache_ptr->howto = &elf32_frv_vtinherit_howto;
1682 break;
1683
1684 case R_FRV_GNU_VTENTRY:
1685 cache_ptr->howto = &elf32_frv_vtentry_howto;
1686 break;
1687
1688 default:
1689 cache_ptr->howto = & elf32_frv_howto_table [r_type];
1690 break;
1691 }
1692 }
1693
1694 /* Set the howto pointer for an FRV ELF REL reloc. */
1695 static void
1696 frv_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1697 arelent *cache_ptr, Elf_Internal_Rela *dst)
1698 {
1699 unsigned int r_type;
1700
1701 r_type = ELF32_R_TYPE (dst->r_info);
1702 switch (r_type)
1703 {
1704 case R_FRV_32:
1705 cache_ptr->howto = &elf32_frv_rel_32_howto;
1706 break;
1707
1708 case R_FRV_FUNCDESC:
1709 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
1710 break;
1711
1712 case R_FRV_FUNCDESC_VALUE:
1713 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
1714 break;
1715
1716 default:
1717 cache_ptr->howto = NULL;
1718 break;
1719 }
1720 }
1721 \f
1722 /* Perform a single relocation. By default we use the standard BFD
1723 routines, but a few relocs, we have to do them ourselves. */
1724
1725 static bfd_reloc_status_type
1726 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
1727 relocation)
1728 reloc_howto_type *howto;
1729 bfd *input_bfd;
1730 asection *input_section;
1731 bfd_byte *contents;
1732 Elf_Internal_Rela *rel;
1733 bfd_vma relocation;
1734 {
1735 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1736 contents, rel->r_offset, relocation,
1737 rel->r_addend);
1738 }
1739
1740 \f
1741 /* Relocate an FRV ELF section.
1742
1743 The RELOCATE_SECTION function is called by the new ELF backend linker
1744 to handle the relocations for a section.
1745
1746 The relocs are always passed as Rela structures; if the section
1747 actually uses Rel structures, the r_addend field will always be
1748 zero.
1749
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.
1753
1754 This function does not have to worry about setting the reloc
1755 address or the reloc symbol index.
1756
1757 LOCAL_SYMS is a pointer to the swapped in local symbols.
1758
1759 LOCAL_SECTIONS is an array giving the section in the input file
1760 corresponding to the st_shndx field of each local symbol.
1761
1762 The global hash table entry for the global symbols can be found
1763 via elf_sym_hashes (input_bfd).
1764
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
1769 accordingly. */
1770
1771 static bfd_boolean
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;
1776 bfd *input_bfd;
1777 asection *input_section;
1778 bfd_byte *contents;
1779 Elf_Internal_Rela *relocs;
1780 Elf_Internal_Sym *local_syms;
1781 asection **local_sections;
1782 {
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,
1788 check_segment[2];
1789 int silence_segment_error = !(info->shared || info->pie);
1790
1791 if (info->relocatable)
1792 return TRUE;
1793
1794 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1795 sym_hashes = elf_sym_hashes (input_bfd);
1796 relend = relocs + input_section->reloc_count;
1797
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)
1803 ->output_section);
1804 else
1805 got_segment = -1;
1806 if (frv_gotfixup_section (info))
1807 gprel_segment = _frv_osec_to_segment (output_bfd,
1808 frv_gotfixup_section (info)
1809 ->output_section);
1810 else
1811 gprel_segment = -1;
1812 if (elf_hash_table (info)->dynamic_sections_created)
1813 plt_segment = _frv_osec_to_segment (output_bfd,
1814 frv_plt_section (info)
1815 ->output_section);
1816 else
1817 plt_segment = -1;
1818
1819 for (rel = relocs; rel < relend; rel ++)
1820 {
1821 reloc_howto_type *howto;
1822 unsigned long r_symndx;
1823 Elf_Internal_Sym *sym;
1824 asection *sec;
1825 struct elf_link_hash_entry *h;
1826 bfd_vma relocation;
1827 bfd_reloc_status_type r;
1828 const char * name = NULL;
1829 int r_type;
1830 asection *osec;
1831 struct frv_pic_relocs_info *picrel;
1832 bfd_vma orig_addend = rel->r_addend;
1833
1834 r_type = ELF32_R_TYPE (rel->r_info);
1835
1836 if ( r_type == R_FRV_GNU_VTINHERIT
1837 || r_type == R_FRV_GNU_VTENTRY)
1838 continue;
1839
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);
1843 h = NULL;
1844 sym = NULL;
1845 sec = NULL;
1846
1847 if (r_symndx < symtab_hdr->sh_info)
1848 {
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);
1852
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;
1856 }
1857 else
1858 {
1859 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
1860
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;
1864
1865 name = h->root.root.string;
1866
1867 if ((h->root.type == bfd_link_hash_defined
1868 || h->root.type == bfd_link_hash_defweak)
1869 && ! FRV_SYM_LOCAL (info, h))
1870 {
1871 sec = NULL;
1872 relocation = 0;
1873 }
1874 else
1875 if (h->root.type == bfd_link_hash_defined
1876 || h->root.type == bfd_link_hash_defweak)
1877 {
1878 sec = h->root.u.def.section;
1879 relocation = (h->root.u.def.value
1880 + sec->output_section->vma
1881 + sec->output_offset);
1882 }
1883 else if (h->root.type == bfd_link_hash_undefweak)
1884 {
1885 relocation = 0;
1886 }
1887 else if ( ! info->executable
1888 && ! info->symbolic
1889 && info->unresolved_syms_in_objects == RM_IGNORE
1890 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1891 relocation = 0;
1892 else
1893 {
1894 if (! ((*info->callbacks->undefined_symbol)
1895 (info, h->root.root.string, input_bfd,
1896 input_section, rel->r_offset, TRUE)))
1897 return FALSE;
1898 relocation = 0;
1899 }
1900 osec = sec;
1901 }
1902
1903 switch (r_type)
1904 {
1905 case R_FRV_LABEL24:
1906 case R_FRV_32:
1907 case R_FRV_GOT12:
1908 case R_FRV_GOTHI:
1909 case R_FRV_GOTLO:
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:
1921 if (h != NULL)
1922 picrel = frv_pic_relocs_info_for_global (frv_relocs_info (info),
1923 input_bfd, h,
1924 orig_addend);
1925 else
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,
1931 orig_addend);
1932 if (! picrel)
1933 return FALSE;
1934
1935 if (!_frv_emit_got_relocs_plt_entries (picrel, output_bfd, info,
1936 osec, sym, rel->r_addend))
1937 {
1938 info->callbacks->warning
1939 (info, _("Dynamic relocation references symbol with nonzero addend"),
1940 name, input_bfd, input_section, rel->r_offset);
1941 return FALSE;
1942
1943 }
1944
1945 break;
1946
1947 default:
1948 picrel = NULL;
1949 if (h && ! FRV_SYM_LOCAL (info, h))
1950 {
1951 info->callbacks->warning
1952 (info, _("relocation references symbol not defined in the module"),
1953 name, input_bfd, input_section, rel->r_offset);
1954 return FALSE;
1955 }
1956 break;
1957 }
1958
1959 switch (r_type)
1960 {
1961 case R_FRV_LABEL24:
1962 check_segment[0] = isec_segment;
1963 if (picrel->plt)
1964 {
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;
1969 }
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
1973 behavior. */
1974 else if (picrel->symndx == -1
1975 && picrel->d.h->root.type == bfd_link_hash_undefweak)
1976 check_segment[1] = check_segment[0];
1977 else
1978 check_segment[1] = sec
1979 ? _frv_osec_to_segment (output_bfd, sec->output_section)
1980 : (unsigned)-1;
1981 break;
1982
1983 case R_FRV_GOT12:
1984 case R_FRV_GOTHI:
1985 case R_FRV_GOTLO:
1986 relocation = picrel->got_entry;
1987 check_segment[0] = check_segment[1] = got_segment;
1988 break;
1989
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;
1995 break;
1996
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)
2006 : (unsigned)-1;
2007 break;
2008
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;
2014 break;
2015
2016 case R_FRV_FUNCDESC:
2017 {
2018 int dynindx;
2019 bfd_vma addend = rel->r_addend;
2020
2021 if (! (h && h->root.type == bfd_link_hash_undefweak
2022 && FRV_SYM_LOCAL (info, h)))
2023 {
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
2031 section+offset. */
2032 if (h && ! FRV_FUNCDESC_LOCAL (info, h)
2033 && FRV_SYM_LOCAL (info, h)
2034 && !(info->executable && !info->pie))
2035 {
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;
2040 }
2041 else if (h && ! FRV_FUNCDESC_LOCAL (info, h))
2042 {
2043 if (addend)
2044 {
2045 info->callbacks->warning
2046 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
2047 name, input_bfd, input_section, rel->r_offset);
2048 return FALSE;
2049 }
2050 dynindx = h->dynindx;
2051 }
2052 else
2053 {
2054 /* Otherwise, we know we have a private function
2055 descriptor, so reference it directly. */
2056 BFD_ASSERT (picrel->privfd);
2057 r_type = R_FRV_32;
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)
2062 + picrel->fd_entry;
2063 }
2064
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)))
2073 {
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))
2078 {
2079 if (_frv_osec_readonly_p (output_bfd,
2080 input_section->output_section))
2081 {
2082 info->callbacks->warning
2083 (info,
2084 _("cannot emit fixups in read-only section"),
2085 name, input_bfd, input_section, rel->r_offset);
2086 return FALSE;
2087 }
2088 _frv_add_rofixup (output_bfd,
2089 frv_gotfixup_section (info),
2090 _bfd_elf_section_offset
2091 (output_bfd, info,
2092 input_section, rel->r_offset)
2093 + input_section->output_section->vma
2094 + input_section->output_offset);
2095 }
2096 }
2097 else if ((bfd_get_section_flags (output_bfd,
2098 input_section->output_section)
2099 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2100 {
2101 if (_frv_osec_readonly_p (output_bfd,
2102 input_section->output_section))
2103 {
2104 info->callbacks->warning
2105 (info,
2106 _("cannot emit dynamic relocations in read-only section"),
2107 name, input_bfd, input_section, rel->r_offset);
2108 return FALSE;
2109 }
2110 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
2111 _bfd_elf_section_offset
2112 (output_bfd, info,
2113 input_section, rel->r_offset)
2114 + input_section->output_section->vma
2115 + input_section->output_offset,
2116 r_type, dynindx, addend);
2117 }
2118 }
2119
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;
2124 }
2125 check_segment[0] = check_segment[1] = got_segment;
2126 break;
2127
2128 case R_FRV_32:
2129 case R_FRV_FUNCDESC_VALUE:
2130 {
2131 int dynindx;
2132 bfd_vma addend = rel->r_addend;
2133
2134 /* If the symbol is dynamic but binds locally, use
2135 section+offset. */
2136 if (h && ! FRV_SYM_LOCAL (info, h))
2137 {
2138 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
2139 {
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);
2143 return FALSE;
2144 }
2145 dynindx = h->dynindx;
2146 }
2147 else
2148 {
2149 if (h)
2150 addend += h->root.u.def.value;
2151 else
2152 addend += sym->st_value;
2153 if (osec)
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;
2159 else
2160 dynindx = 0;
2161 }
2162
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)))
2169 {
2170 if (osec)
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))
2176 {
2177 if (_frv_osec_readonly_p (output_bfd,
2178 input_section->output_section))
2179 {
2180 info->callbacks->warning
2181 (info,
2182 _("cannot emit fixups in read-only section"),
2183 name, input_bfd, input_section, rel->r_offset);
2184 return FALSE;
2185 }
2186 if (!h || h->root.type != bfd_link_hash_undefweak)
2187 {
2188 _frv_add_rofixup (output_bfd,
2189 frv_gotfixup_section (info),
2190 _bfd_elf_section_offset
2191 (output_bfd, info,
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)
2196 _frv_add_rofixup
2197 (output_bfd,
2198 frv_gotfixup_section (info),
2199 _bfd_elf_section_offset
2200 (output_bfd, info,
2201 input_section, rel->r_offset)
2202 + input_section->output_section->vma
2203 + input_section->output_offset + 4);
2204 }
2205 }
2206 }
2207 else
2208 {
2209 if ((bfd_get_section_flags (output_bfd,
2210 input_section->output_section)
2211 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2212 {
2213 if (_frv_osec_readonly_p (output_bfd,
2214 input_section->output_section))
2215 {
2216 info->callbacks->warning
2217 (info,
2218 _("cannot emit dynamic relocations in read-only section"),
2219 name, input_bfd, input_section, rel->r_offset);
2220 return FALSE;
2221 }
2222 _frv_add_dyn_reloc (output_bfd, frv_gotrel_section (info),
2223 _bfd_elf_section_offset
2224 (output_bfd, info,
2225 input_section, rel->r_offset)
2226 + input_section->output_section->vma
2227 + input_section->output_offset,
2228 r_type, dynindx, addend);
2229 }
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;
2234 }
2235
2236 if (r_type == R_FRV_FUNCDESC_VALUE)
2237 {
2238 /* If we've omitted the dynamic relocation, just emit
2239 the fixed addresses of the symbol and of the local
2240 GOT base offset. */
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);
2248 else
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)
2257 ? 0
2258 : _frv_osec_to_segment (output_bfd,
2259 sec->output_section),
2260 contents + rel->r_offset + 4);
2261 }
2262 }
2263 check_segment[0] = check_segment[1] = got_segment;
2264 break;
2265
2266 case R_FRV_GPREL12:
2267 case R_FRV_GPRELU12:
2268 case R_FRV_GPREL32:
2269 case R_FRV_GPRELHI:
2270 case R_FRV_GPRELLO:
2271 check_segment[0] = gprel_segment;
2272 check_segment[1] = sec
2273 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2274 : (unsigned)-1;
2275 break;
2276
2277 default:
2278 check_segment[0] = isec_segment;
2279 check_segment[1] = sec
2280 ? _frv_osec_to_segment (output_bfd, sec->output_section)
2281 : (unsigned)-1;
2282 break;
2283 }
2284
2285 if (check_segment[0] != check_segment[1]
2286 && (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC))
2287 {
2288 #if 1
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,
2299 "/crt0.o") == 0)
2300 ? -1 : 0;
2301 #endif
2302 if (!silence_segment_error
2303 /* We don't want duplicate errors for undefined
2304 symbols. */
2305 && !(picrel && picrel->symndx == -1
2306 && picrel->d.h->root.type == bfd_link_hash_undefined))
2307 info->callbacks->warning
2308 (info,
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))
2314 return FALSE;
2315 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
2316 }
2317
2318 switch (r_type)
2319 {
2320 case R_FRV_GOTOFFHI:
2321 /* We need the addend to be applied before we shift the
2322 value right. */
2323 relocation += rel->r_addend;
2324 /* Fall through. */
2325 case R_FRV_GOTHI:
2326 case R_FRV_FUNCDESC_GOTHI:
2327 case R_FRV_FUNCDESC_GOTOFFHI:
2328 relocation >>= 16;
2329 /* Fall through. */
2330
2331 case R_FRV_GOTLO:
2332 case R_FRV_FUNCDESC_GOTLO:
2333 case R_FRV_GOTOFFLO:
2334 case R_FRV_FUNCDESC_GOTOFFLO:
2335 relocation &= 0xffff;
2336 break;
2337
2338 default:
2339 break;
2340 }
2341
2342 switch (r_type)
2343 {
2344 case R_FRV_LABEL24:
2345 if (! picrel->plt)
2346 break;
2347 /* Fall through. */
2348
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. */
2354 case R_FRV_GOT12:
2355 case R_FRV_GOTHI:
2356 case R_FRV_GOTLO:
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;
2369 break;
2370
2371 default:
2372 break;
2373 }
2374
2375 if (r_type == R_FRV_HI16)
2376 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
2377
2378 else if (r_type == R_FRV_LO16)
2379 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
2380
2381 else if (r_type == R_FRV_LABEL24)
2382 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
2383 contents, relocation);
2384
2385 else if (r_type == R_FRV_GPREL12)
2386 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
2387 contents, relocation);
2388
2389 else if (r_type == R_FRV_GPRELU12)
2390 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
2391 contents, relocation);
2392
2393 else if (r_type == R_FRV_GPRELLO)
2394 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
2395 contents, relocation);
2396
2397 else if (r_type == R_FRV_GPRELHI)
2398 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
2399 contents, relocation);
2400
2401 else
2402 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
2403 rel, relocation);
2404
2405 if (r != bfd_reloc_ok)
2406 {
2407 const char * msg = (const char *) NULL;
2408
2409 switch (r)
2410 {
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);
2415 break;
2416
2417 case bfd_reloc_undefined:
2418 r = info->callbacks->undefined_symbol
2419 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
2420 break;
2421
2422 case bfd_reloc_outofrange:
2423 msg = _("internal error: out of range error");
2424 break;
2425
2426 case bfd_reloc_notsupported:
2427 msg = _("internal error: unsupported relocation error");
2428 break;
2429
2430 case bfd_reloc_dangerous:
2431 msg = _("internal error: dangerous relocation");
2432 break;
2433
2434 default:
2435 msg = _("internal error: unknown error");
2436 break;
2437 }
2438
2439 if (msg)
2440 r = info->callbacks->warning
2441 (info, msg, name, input_bfd, input_section, rel->r_offset);
2442
2443 if (! r)
2444 return FALSE;
2445 }
2446 }
2447
2448 return TRUE;
2449 }
2450 \f
2451 /* Return the section that should be marked against GC for a given
2452 relocation. */
2453
2454 static asection *
2455 elf32_frv_gc_mark_hook (sec, info, rel, h, sym)
2456 asection *sec;
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;
2461 {
2462 if (h != NULL)
2463 {
2464 switch (ELF32_R_TYPE (rel->r_info))
2465 {
2466 case R_FRV_GNU_VTINHERIT:
2467 case R_FRV_GNU_VTENTRY:
2468 break;
2469
2470 default:
2471 switch (h->root.type)
2472 {
2473 default:
2474 break;
2475
2476 case bfd_link_hash_defined:
2477 case bfd_link_hash_defweak:
2478 return h->root.u.def.section;
2479
2480 case bfd_link_hash_common:
2481 return h->root.u.c.p->section;
2482 }
2483 }
2484 }
2485 else
2486 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2487
2488 return NULL;
2489 }
2490
2491 /* Update the got entry reference counts for the section being removed. */
2492
2493 static bfd_boolean
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;
2499 {
2500 return TRUE;
2501 }
2502
2503 \f
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. */
2506
2507 static bfd_boolean
2508 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2509 bfd *abfd;
2510 struct bfd_link_info *info;
2511 const Elf_Internal_Sym *sym;
2512 const char **namep ATTRIBUTE_UNUSED;
2513 flagword *flagsp ATTRIBUTE_UNUSED;
2514 asection **secp;
2515 bfd_vma *valp;
2516 {
2517 if (sym->st_shndx == SHN_COMMON
2518 && !info->relocatable
2519 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
2520 {
2521 /* Common symbols less than or equal to -G nn bytes are
2522 automatically put into .sbss. */
2523
2524 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2525
2526 if (scomm == NULL)
2527 {
2528 scomm = bfd_make_section (abfd, ".scommon");
2529 if (scomm == NULL
2530 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2531 | SEC_IS_COMMON
2532 | SEC_LINKER_CREATED)))
2533 return FALSE;
2534 }
2535
2536 *secp = scomm;
2537 *valp = sym->st_size;
2538 }
2539
2540 return TRUE;
2541 }
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(). */
2545
2546 static bfd_boolean
2547 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
2548 {
2549 flagword flags;
2550 asection *s;
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);
2554 int ptralign;
2555
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)
2559 return TRUE;
2560
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
2564 stores. */
2565 ptralign = 3;
2566
2567 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2568 | SEC_LINKER_CREATED);
2569
2570 s = bfd_make_section (abfd, ".got");
2571 if (s == NULL
2572 || !bfd_set_section_flags (abfd, s, flags)
2573 || !bfd_set_section_alignment (abfd, s, ptralign))
2574 return FALSE;
2575
2576 if (bed->want_got_plt)
2577 {
2578 s = bfd_make_section (abfd, ".got.plt");
2579 if (s == NULL
2580 || !bfd_set_section_flags (abfd, s, flags)
2581 || !bfd_set_section_alignment (abfd, s, ptralign))
2582 return FALSE;
2583 }
2584
2585 if (bed->want_got_sym)
2586 {
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. */
2591 bh = NULL;
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)))
2596 return FALSE;
2597 h = (struct elf_link_hash_entry *) bh;
2598 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2599 h->type = STT_OBJECT;
2600
2601 /* Machine-specific: we want the symbol for executables as
2602 well. */
2603 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
2604 return FALSE;
2605
2606 elf_hash_table (info)->hgot = h;
2607 }
2608
2609 /* The first bit of the global offset table is the header. */
2610 s->_raw_size += bed->got_header_size + bed->got_symbol_offset;
2611
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,
2617 (htab_del) NULL);
2618 if (! frv_relocs_info (info))
2619 return FALSE;
2620
2621 s = bfd_make_section (abfd, ".rel.got");
2622 if (s == NULL
2623 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2624 || ! bfd_set_section_alignment (abfd, s, 2))
2625 return FALSE;
2626
2627 frv_gotrel_section (info) = s;
2628
2629 /* Machine-specific. */
2630 s = bfd_make_section (abfd, ".rofixup");
2631 if (s == NULL
2632 || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY))
2633 || ! bfd_set_section_alignment (abfd, s, 2))
2634 return FALSE;
2635
2636 frv_gotfixup_section (info) = s;
2637
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. */
2641 bh = NULL;
2642 if (!(_bfd_generic_link_add_one_symbol
2643 (info, abfd, "_gp", BSF_GLOBAL, s, -2048, (const char *) NULL, FALSE,
2644 bed->collect, &bh)))
2645 return FALSE;
2646 h = (struct elf_link_hash_entry *) bh;
2647 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2648 h->type = STT_OBJECT;
2649
2650 /* Machine-specific: we want the symbol for executables as well. */
2651 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
2652 return FALSE;
2653
2654 return TRUE;
2655 }
2656
2657 /* Make sure the got and plt sections exist, and that our pointers in
2658 the link hash table point to them. */
2659
2660 static bfd_boolean
2661 elf32_frv_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2662 {
2663 /* This is mostly copied from
2664 elflink.c:_bfd_elf_create_dynamic_sections(). */
2665 flagword flags, pltflags;
2666 asection *s;
2667 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2668
2669 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2670 .rel[a].bss sections. */
2671
2672 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2673 | SEC_LINKER_CREATED);
2674
2675 pltflags = flags;
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;
2681
2682 s = bfd_make_section (abfd, ".plt");
2683 if (s == NULL
2684 || ! bfd_set_section_flags (abfd, s, pltflags)
2685 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2686 return FALSE;
2687 /* FRV-specific: remember it. */
2688 frv_plt_section (info) = s;
2689
2690 if (bed->want_plt_sym)
2691 {
2692 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2693 .plt section. */
2694 struct elf_link_hash_entry *h;
2695 struct bfd_link_hash_entry *bh = NULL;
2696
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)))
2700 return FALSE;
2701 h = (struct elf_link_hash_entry *) bh;
2702 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2703 h->type = STT_OBJECT;
2704
2705 if (! info->executable
2706 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2707 return FALSE;
2708 }
2709
2710 /* FRV-specific: we want rel relocations for the plt. */
2711 s = bfd_make_section (abfd, ".rel.plt");
2712 if (s == NULL
2713 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2714 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2715 return FALSE;
2716 /* FRV-specific: remember it. */
2717 frv_pltrel_section (info) = s;
2718
2719 /* FRV-specific: we want to create the GOT in the FRV way. */
2720 if (! _frv_create_got_section (abfd, info))
2721 return FALSE;
2722
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));
2727
2728 if (bed->want_dynbss)
2729 {
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");
2737 if (s == NULL
2738 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
2739 return FALSE;
2740
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
2751 copy relocs. */
2752 if (! info->shared)
2753 {
2754 s = bfd_make_section (abfd,
2755 (bed->default_use_rela_p
2756 ? ".rela.bss" : ".rel.bss"));
2757 if (s == NULL
2758 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2759 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
2760 return FALSE;
2761 }
2762 }
2763
2764 return TRUE;
2765 }
2766
2767 /* The name of the dynamic interpreter. This is put in the .interp
2768 section. */
2769
2770 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2771
2772 #define DEFAULT_STACK_SIZE 0x20000
2773
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
2777 {
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
2781 ranges. */
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. */
2789 bfd_vma fdplt;
2790 /* Total size needed by lazy PLT entries. */
2791 bfd_vma lzplt;
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;
2796 };
2797
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. */
2802
2803 static int
2804 _frv_count_got_plt_entries (void **entryp, void *dinfo_)
2805 {
2806 struct frv_pic_relocs_info *entry = *entryp;
2807 struct _frv_dynamic_got_info *dinfo = dinfo_;
2808
2809 /* Allocate space for a GOT entry pointing to the symbol. */
2810 if (entry->got12)
2811 dinfo->got12 += 4;
2812 else if (entry->gotlos)
2813 dinfo->gotlos += 4;
2814 else if (entry->gothilo)
2815 dinfo->gothilo += 4;
2816 else
2817 entry->relocs32--;
2818 entry->relocs32++;
2819
2820 /* Allocate space for a GOT entry pointing to the function
2821 descriptor. */
2822 if (entry->fdgot12)
2823 dinfo->got12 += 4;
2824 else if (entry->fdgotlos)
2825 dinfo->gotlos += 4;
2826 else if (entry->fdgothilo)
2827 dinfo->gothilo += 4;
2828 else
2829 entry->relocsfd--;
2830 entry->relocsfd++;
2831
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;
2846
2847 /* Allocate space for a function descriptor. */
2848 if (entry->fdgoff12)
2849 dinfo->fd12 += 8;
2850 else if (entry->fdgofflos)
2851 dinfo->fdlos += 8;
2852 else if (entry->privfd && entry->plt)
2853 dinfo->fdplt += 8;
2854 else if (entry->privfd)
2855 dinfo->fdhilo += 8;
2856 else
2857 entry->relocsfdv--;
2858 entry->relocsfdv++;
2859
2860 if (entry->lazyplt)
2861 dinfo->lzplt += 8;
2862
2863 if (!dinfo->info->executable || dinfo->info->pie)
2864 dinfo->relocs += entry->relocs32 + entry->relocsfd + entry->relocsfdv;
2865 else
2866 {
2867 if (entry->symndx != -1 || FRV_SYM_LOCAL (dinfo->info, entry->d.h))
2868 {
2869 if (entry->symndx != -1
2870 || entry->d.h->root.type != bfd_link_hash_undefweak)
2871 dinfo->fixups += entry->relocs32 + 2 * entry->relocsfdv;
2872 }
2873 else
2874 dinfo->relocs += entry->relocs32 + entry->relocsfdv;
2875 if (entry->symndx != -1 || FRV_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
2876 {
2877 if (entry->symndx != -1
2878 || entry->d.h->root.type != bfd_link_hash_undefweak)
2879 dinfo->fixups += entry->relocsfd;
2880 }
2881 else
2882 dinfo->relocs += entry->relocsfd;
2883 }
2884
2885 return 1;
2886 }
2887
2888 /* This structure is used to assign offsets to got entries, function
2889 descriptors, plt entries and lazy plt entries. */
2890
2891 struct _frv_dynamic_got_plt_info
2892 {
2893 /* Summary information collected with _frv_count_got_plt_entries. */
2894 struct _frv_dynamic_got_info g;
2895
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
2909 entries. */
2910 struct _frv_dynamic_got_alloc_data
2911 {
2912 bfd_signed_vma max, cur, odd, fdcur, min;
2913 bfd_vma fdplt;
2914 } got12, gotlos, gothilo;
2915 };
2916
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
2925 descriptors. */
2926
2927 inline static bfd_signed_vma
2928 _frv_compute_got_alloc_data (struct _frv_dynamic_got_alloc_data *gad,
2929 bfd_signed_vma fdcur,
2930 bfd_signed_vma odd,
2931 bfd_signed_vma cur,
2932 bfd_vma got,
2933 bfd_vma fd,
2934 bfd_vma fdplt,
2935 bfd_vma wrap)
2936 {
2937 bfd_signed_vma wrapmin = -wrap;
2938
2939 /* Start at the given initial points. */
2940 gad->fdcur = fdcur;
2941 gad->cur = cur;
2942
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. */
2950 if (odd && got)
2951 {
2952 gad->odd = odd;
2953 got -= 4;
2954 odd = 0;
2955 }
2956 else
2957 gad->odd = 0;
2958
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. */
2966 if (got & 4)
2967 {
2968 odd = cur + got;
2969 got += 4;
2970 }
2971
2972 /* Compute the tentative boundaries of this range. */
2973 gad->max = cur + got;
2974 gad->min = fdcur - fd;
2975 gad->fdplt = 0;
2976
2977 /* If function descriptors took too much space, wrap some of them
2978 around. */
2979 if (gad->min < wrapmin)
2980 {
2981 gad->max += wrapmin - gad->min;
2982 gad->min = wrapmin;
2983 }
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)
2988 {
2989 bfd_vma fds;
2990 if ((bfd_vma) (gad->min - wrapmin) < fdplt)
2991 fds = gad->min - wrapmin;
2992 else
2993 fds = fdplt;
2994
2995 fdplt -= fds;
2996 gad->min -= fds;
2997 gad->fdplt += fds;
2998 }
2999
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
3003 report it here . */
3004 if ((bfd_vma) gad->max > wrap)
3005 {
3006 gad->min -= gad->max - wrap;
3007 gad->max = wrap;
3008 }
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)
3012 {
3013 bfd_vma fds;
3014 if ((bfd_vma) (wrap - gad->max) < fdplt)
3015 fds = wrap - gad->max;
3016 else
3017 fds = fdplt;
3018
3019 fdplt -= fds;
3020 gad->max += fds;
3021 gad->fdplt += fds;
3022 }
3023
3024 /* If odd was initially computed as an offset past the wrap point,
3025 wrap it around. */
3026 if (odd > gad->max)
3027 odd = gad->min + odd - gad->max;
3028
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
3032 equal to min. */
3033 if (gad->cur == gad->max)
3034 gad->cur = gad->min;
3035
3036 return odd;
3037 }
3038
3039 /* Compute the location of the next GOT entry, given the allocation
3040 data for a range. */
3041
3042 inline static bfd_signed_vma
3043 _frv_get_got_entry (struct _frv_dynamic_got_alloc_data *gad)
3044 {
3045 bfd_signed_vma ret;
3046
3047 if (gad->odd)
3048 {
3049 /* If there was an odd word left behind, use it. */
3050 ret = gad->odd;
3051 gad->odd = 0;
3052 }
3053 else
3054 {
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
3057 wrapping around. */
3058 ret = gad->cur;
3059 gad->odd = gad->cur + 4;
3060 gad->cur += 8;
3061 if (gad->cur == gad->max)
3062 gad->cur = gad->min;
3063 }
3064
3065 return ret;
3066 }
3067
3068 /* Compute the location of the next function descriptor entry in the
3069 GOT, given the allocation data for a range. */
3070
3071 inline static bfd_signed_vma
3072 _frv_get_fd_entry (struct _frv_dynamic_got_alloc_data *gad)
3073 {
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;
3079 }
3080
3081 /* Assign GOT offsets for every GOT entry and function descriptor.
3082 Doing everything in a single pass is tricky. */
3083
3084 static int
3085 _frv_assign_got_entries (void **entryp, void *info_)
3086 {
3087 struct frv_pic_relocs_info *entry = *entryp;
3088 struct _frv_dynamic_got_plt_info *dinfo = info_;
3089
3090 if (entry->got12)
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);
3096
3097 if (entry->fdgot12)
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);
3103
3104 if (entry->fdgoff12)
3105 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3106 else if (entry->plt && dinfo->got12.fdplt)
3107 {
3108 dinfo->got12.fdplt -= 8;
3109 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3110 }
3111 else if (entry->fdgofflos)
3112 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3113 else if (entry->plt && dinfo->gotlos.fdplt)
3114 {
3115 dinfo->gotlos.fdplt -= 8;
3116 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3117 }
3118 else if (entry->plt)
3119 {
3120 dinfo->gothilo.fdplt -= 8;
3121 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3122 }
3123 else if (entry->privfd)
3124 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3125
3126 return 1;
3127 }
3128
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. */
3132
3133 static int
3134 _frv_assign_plt_entries (void **entryp, void *info_)
3135 {
3136 struct frv_pic_relocs_info *entry = *entryp;
3137 struct _frv_dynamic_got_plt_info *dinfo = info_;
3138
3139 /* If this symbol requires a local function descriptor, allocate
3140 one. */
3141 if (entry->privfd && entry->fd_entry == 0)
3142 {
3143 if (dinfo->got12.fdplt)
3144 {
3145 entry->fd_entry = _frv_get_fd_entry (&dinfo->got12);
3146 dinfo->got12.fdplt -= 8;
3147 }
3148 else if (dinfo->gotlos.fdplt)
3149 {
3150 entry->fd_entry = _frv_get_fd_entry (&dinfo->gotlos);
3151 dinfo->gotlos.fdplt -= 8;
3152 }
3153 else
3154 {
3155 BFD_ASSERT (dinfo->gothilo.fdplt)
3156 entry->fd_entry = _frv_get_fd_entry (&dinfo->gothilo);
3157 dinfo->gothilo.fdplt -= 8;
3158 }
3159 }
3160
3161 if (entry->plt)
3162 {
3163 int size;
3164
3165 /* We use the section's raw size to mark the location of the
3166 next PLT entry. */
3167 entry->plt_entry = frv_plt_section (dinfo->g.info)->_raw_size;
3168
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)))
3174 size = 8;
3175 else if (entry->fd_entry >= -(1 << (16 - 1))
3176 && entry->fd_entry < (1 << (16 - 1)))
3177 size = 12;
3178 else
3179 size = 16;
3180
3181 frv_plt_section (dinfo->g.info)->_raw_size += size;
3182 }
3183
3184 if (entry->lazyplt)
3185 {
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;
3192 }
3193
3194 return 1;
3195 }
3196
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. */
3203 static int
3204 _frv_resolve_final_relocs_info (void **entryp, void *p)
3205 {
3206 struct frv_pic_relocs_info *entry = *entryp;
3207 htab_t *htab = p;
3208
3209 if (entry->symndx == -1)
3210 {
3211 struct elf_link_hash_entry *h = entry->d.h;
3212
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;
3216
3217 if (entry->d.h == h)
3218 return 1;
3219
3220 entry->d.h = h;
3221
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))
3225 {
3226 htab_clear_slot (*htab, entryp);
3227 entryp = htab_find_slot (*htab, entry, INSERT);
3228 if (! *entryp)
3229 *entryp = entry;
3230 /* Abort the traversal, since the whole table may have
3231 moved, and leave it up to the parent to restart the
3232 process. */
3233 *(htab_t *)p = NULL;
3234 return 0;
3235 }
3236 }
3237
3238 return 1;
3239 }
3240
3241 /* Set the sizes of the dynamic sections. */
3242
3243 static bfd_boolean
3244 elf32_frv_size_dynamic_sections (bfd *output_bfd,
3245 struct bfd_link_info *info)
3246 {
3247 bfd *dynobj;
3248 asection *s;
3249 struct _frv_dynamic_got_plt_info gpinfo;
3250 bfd_signed_vma odd;
3251 bfd_vma limit;
3252
3253 dynobj = elf_hash_table (info)->dynobj;
3254 BFD_ASSERT (dynobj != NULL);
3255
3256 if (elf_hash_table (info)->dynamic_sections_created)
3257 {
3258 /* Set the contents of the .interp section to the interpreter. */
3259 if (info->executable)
3260 {
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;
3265 }
3266 }
3267
3268 memset (&gpinfo, 0, sizeof (gpinfo));
3269 gpinfo.g.info = info;
3270
3271 for (;;)
3272 {
3273 htab_t relocs = frv_relocs_info (info);
3274
3275 htab_traverse (relocs, _frv_resolve_final_relocs_info, &relocs);
3276
3277 if (relocs == frv_relocs_info (info))
3278 break;
3279 }
3280
3281 htab_traverse (frv_relocs_info (info), _frv_count_got_plt_entries,
3282 &gpinfo.g);
3283
3284 odd = 12;
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
3288 overflow. */
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;
3293 else
3294 limit = 0;
3295 if (gpinfo.g.fdplt < limit)
3296 limit = gpinfo.g.fdplt;
3297
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,
3301 0,
3302 odd,
3303 16,
3304 gpinfo.g.got12,
3305 gpinfo.g.fd12,
3306 limit,
3307 (bfd_vma)1 << (12-1));
3308 odd = _frv_compute_got_alloc_data (&gpinfo.gotlos,
3309 gpinfo.got12.min,
3310 odd,
3311 gpinfo.got12.max,
3312 gpinfo.g.gotlos,
3313 gpinfo.g.fdlos,
3314 gpinfo.g.fdplt - gpinfo.got12.fdplt,
3315 (bfd_vma)1 << (16-1));
3316 odd = _frv_compute_got_alloc_data (&gpinfo.gothilo,
3317 gpinfo.gotlos.min,
3318 odd,
3319 gpinfo.gotlos.max,
3320 gpinfo.g.gothilo,
3321 gpinfo.g.fdhilo,
3322 gpinfo.g.fdplt - gpinfo.got12.fdplt
3323 - gpinfo.gotlos.fdplt,
3324 (bfd_vma)1 << (32-1));
3325
3326 /* Now assign (most) GOT offsets. */
3327 htab_traverse (frv_relocs_info (info), _frv_assign_got_entries, &gpinfo);
3328
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)
3337 {
3338 frv_got_section (info)->flags |= SEC_EXCLUDE;
3339 frv_got_section (info)->_raw_size = 0;
3340 }
3341 else
3342 {
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)
3346 return FALSE;
3347 }
3348
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;
3355 else
3356 BFD_ASSERT (gpinfo.g.relocs == 0);
3357 if (frv_gotrel_section (info)->_raw_size == 0)
3358 frv_gotrel_section (info)->flags |= SEC_EXCLUDE;
3359 else
3360 {
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)
3364 return FALSE;
3365 }
3366
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;
3371 else
3372 {
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)
3377 return FALSE;
3378 }
3379
3380 if (elf_hash_table (info)->dynamic_sections_created)
3381 {
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;
3386 else
3387 {
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)
3392 return FALSE;
3393 }
3394 }
3395
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
3400 size. */
3401 if (elf_hash_table (info)->dynamic_sections_created)
3402 {
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);
3406 }
3407
3408 /* Reset it, such that _frv_assign_plt_entries() can use it to
3409 actually assign lazy PLT entries addresses. */
3410 gpinfo.g.lzplt = 0;
3411
3412 /* Save information that we're going to need to generate GOT and PLT
3413 entries. */
3414 frv_got_initial_offset (info) = -gpinfo.gothilo.min;
3415
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);
3419
3420 if (elf_hash_table (info)->dynamic_sections_created)
3421 frv_plt_initial_offset (info) = frv_plt_section (info)->_raw_size;
3422
3423 htab_traverse (frv_relocs_info (info), _frv_assign_plt_entries, &gpinfo);
3424
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)
3429 {
3430 if (frv_plt_section (info)->_raw_size == 0)
3431 frv_plt_section (info)->flags |= SEC_EXCLUDE;
3432 else
3433 {
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)
3437 return FALSE;
3438 }
3439 }
3440
3441 if (elf_hash_table (info)->dynamic_sections_created)
3442 {
3443 if (frv_got_section (info)->_raw_size)
3444 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
3445 return FALSE;
3446
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))
3451 return FALSE;
3452
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)))
3458 return FALSE;
3459 }
3460
3461 return TRUE;
3462 }
3463
3464 static bfd_boolean
3465 elf32_frv_always_size_sections (bfd *output_bfd,
3466 struct bfd_link_info *info)
3467 {
3468 if (!info->relocatable
3469 && elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3470 {
3471 struct elf_link_hash_entry *h;
3472 asection *sec;
3473
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;
3477
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))
3484 {
3485 struct bfd_link_hash_entry *bh = NULL;
3486
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)))
3492 return FALSE;
3493
3494 h = (struct elf_link_hash_entry *) bh;
3495 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3496 h->type = STT_OBJECT;
3497 }
3498
3499 /* Create a stack section, and set its alignment. */
3500 sec = bfd_make_section (output_bfd, ".stack");
3501
3502 if (sec == NULL
3503 || ! bfd_set_section_alignment (output_bfd, sec, 3))
3504 return FALSE;
3505 }
3506
3507 return TRUE;
3508 }
3509
3510 static bfd_boolean
3511 elf32_frv_modify_segment_map (bfd *output_bfd,
3512 struct bfd_link_info *info)
3513 {
3514 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3515 {
3516 struct elf_segment_map *m;
3517
3518 for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next)
3519 if (m->p_type == PT_GNU_STACK)
3520 break;
3521
3522 if (m)
3523 {
3524 asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
3525 struct elf_link_hash_entry *h;
3526
3527 if (sec)
3528 {
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);
3536
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;
3541 else
3542 sec->_raw_size = DEFAULT_STACK_SIZE;
3543
3544 /* Add the stack section to the PT_GNU_STACK segment,
3545 such that its size and alignment requirements make it
3546 to the segment. */
3547 m->sections[m->count] = sec;
3548 m->count++;
3549 }
3550 }
3551 }
3552
3553 return TRUE;
3554 }
3555
3556 /* Fill in code and data in dynamic sections. */
3557
3558 static bfd_boolean
3559 elf32_frv_finish_dynamic_sections (bfd *output_bfd,
3560 struct bfd_link_info *info)
3561 {
3562 bfd *dynobj;
3563 asection *sdyn;
3564
3565 dynobj = elf_hash_table (info)->dynobj;
3566
3567 if (frv_got_section (info))
3568 {
3569 BFD_ASSERT (frv_gotrel_section (info)->_raw_size
3570 == (frv_gotrel_section (info)->reloc_count
3571 * sizeof (Elf32_External_Rel)));
3572
3573 if (frv_gotfixup_section (info))
3574 {
3575 if (elf_elfheader (output_bfd)->e_flags & EF_FRV_FDPIC)
3576 {
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;
3581
3582 _frv_add_rofixup (output_bfd, frv_gotfixup_section (info),
3583 got_value);
3584 }
3585
3586 if (frv_gotfixup_section (info)->_raw_size
3587 != (frv_gotfixup_section (info)->reloc_count * 4))
3588 {
3589 if (!elf_hash_table (info)->dynamic_sections_created)
3590 {
3591 info->callbacks->warning
3592 (info, "no dynamic sections, missing -melf32frvfd?",
3593 ".rofixup", NULL, NULL, 0);
3594 return FALSE;
3595 }
3596 BFD_ASSERT (0);
3597 }
3598 }
3599 }
3600 if (elf_hash_table (info)->dynamic_sections_created)
3601 {
3602 BFD_ASSERT (frv_pltrel_section (info)->_raw_size
3603 == (frv_pltrel_section (info)->reloc_count
3604 * sizeof (Elf32_External_Rel)));
3605 }
3606
3607 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3608
3609 if (elf_hash_table (info)->dynamic_sections_created)
3610 {
3611 Elf32_External_Dyn * dyncon;
3612 Elf32_External_Dyn * dynconend;
3613
3614 BFD_ASSERT (sdyn != NULL);
3615
3616 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3617 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3618
3619 for (; dyncon < dynconend; dyncon++)
3620 {
3621 Elf_Internal_Dyn dyn;
3622
3623 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3624
3625 switch (dyn.d_tag)
3626 {
3627 default:
3628 break;
3629
3630 case DT_PLTGOT:
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);
3635 break;
3636
3637 case DT_JMPREL:
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);
3641 break;
3642
3643 case DT_PLTRELSZ:
3644 if (frv_pltrel_section (info)->_cooked_size != 0)
3645 dyn.d_un.d_val = frv_pltrel_section (info)->_cooked_size;
3646 else
3647 dyn.d_un.d_val = frv_pltrel_section (info)->_raw_size;
3648 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3649 break;
3650 }
3651 }
3652 }
3653
3654 return TRUE;
3655 }
3656
3657 /* Adjust a symbol defined by a dynamic object and referenced by a
3658 regular object. */
3659
3660 static bfd_boolean
3661 elf32_frv_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3662 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3663 {
3664 bfd * dynobj;
3665
3666 dynobj = elf_hash_table (info)->dynobj;
3667
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)));
3677
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)
3682 {
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;
3687 }
3688
3689 return TRUE;
3690 }
3691
3692 /* Perform any actions needed for dynamic symbols. */
3693
3694 static bfd_boolean
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)
3699 {
3700 return TRUE;
3701 }
3702
3703 /* Look through the relocs for a section during the first phase.
3704
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.
3710
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.
3714
3715 LABEL16 should always be resolvable by the linker, since it's only
3716 used by branches.
3717
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.
3722
3723 GPREL relocations require the referenced symbol to be in the same
3724 segment as _gp, but this can only be checked later.
3725
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.
3729
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.
3738
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
3741 an object file.
3742
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.
3750
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.
3755
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.
3762
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.
3766
3767
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.
3771
3772 The existence of a lazy PLT requires the resolverStub lazy PLT
3773 entry to be present.
3774
3775
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
3798 are emitted.
3799
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... :-) */
3806
3807 static bfd_boolean
3808 elf32_frv_check_relocs (abfd, info, sec, relocs)
3809 bfd *abfd;
3810 struct bfd_link_info *info;
3811 asection *sec;
3812 const Elf_Internal_Rela *relocs;
3813 {
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;
3818 bfd *dynobj;
3819 struct frv_pic_relocs_info *picrel;
3820
3821 if (info->relocatable)
3822 return TRUE;
3823
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;
3829
3830 dynobj = elf_hash_table (info)->dynobj;
3831 rel_end = relocs + sec->reloc_count;
3832 for (rel = relocs; rel < rel_end; rel++)
3833 {
3834 struct elf_link_hash_entry *h;
3835 unsigned long r_symndx;
3836
3837 r_symndx = ELF32_R_SYM (rel->r_info);
3838 if (r_symndx < symtab_hdr->sh_info)
3839 h = NULL;
3840 else
3841 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3842
3843 switch (ELF32_R_TYPE (rel->r_info))
3844 {
3845 case R_FRV_LABEL24:
3846 case R_FRV_32:
3847 case R_FRV_GOT12:
3848 case R_FRV_GOTHI:
3849 case R_FRV_GOTLO:
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:
3861 if (! dynobj)
3862 {
3863 elf_hash_table (info)->dynobj = dynobj = abfd;
3864 if (! _frv_create_got_section (abfd, info))
3865 return FALSE;
3866 }
3867 if (h != NULL)
3868 {
3869 if (h->dynindx == -1)
3870 switch (ELF_ST_VISIBILITY (h->other))
3871 {
3872 case STV_INTERNAL:
3873 case STV_HIDDEN:
3874 break;
3875 default:
3876 bfd_elf32_link_record_dynamic_symbol (info, h);
3877 break;
3878 }
3879 picrel
3880 = frv_pic_relocs_info_for_global (frv_relocs_info (info),
3881 abfd, h,
3882 rel->r_addend);
3883 }
3884 else
3885 picrel = frv_pic_relocs_info_for_local (frv_relocs_info (info),
3886 abfd, r_symndx,
3887 rel->r_addend);
3888 if (! picrel)
3889 return FALSE;
3890 break;
3891
3892 default:
3893 picrel = NULL;
3894 break;
3895 }
3896
3897 switch (ELF32_R_TYPE (rel->r_info))
3898 {
3899 case R_FRV_LABEL24:
3900 picrel->call = 1;
3901 break;
3902
3903 case R_FRV_FUNCDESC_VALUE:
3904 picrel->relocsfdv++;
3905 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
3906 picrel->relocs32--;
3907 /* Fall through. */
3908 case R_FRV_32:
3909 picrel->sym = 1;
3910 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
3911 picrel->relocs32++;
3912 break;
3913
3914 case R_FRV_GOT12:
3915 picrel->got12 = 1;
3916 break;
3917
3918 case R_FRV_GOTHI:
3919 case R_FRV_GOTLO:
3920 picrel->gothilo = 1;
3921 break;
3922
3923 case R_FRV_FUNCDESC_GOT12:
3924 picrel->fdgot12 = 1;
3925 break;
3926
3927 case R_FRV_FUNCDESC_GOTHI:
3928 case R_FRV_FUNCDESC_GOTLO:
3929 picrel->fdgothilo = 1;
3930 break;
3931
3932 case R_FRV_GOTOFF12:
3933 case R_FRV_GOTOFFHI:
3934 case R_FRV_GOTOFFLO:
3935 picrel->gotoff = 1;
3936 break;
3937
3938 case R_FRV_FUNCDESC_GOTOFF12:
3939 picrel->fdgoff12 = 1;
3940 break;
3941
3942 case R_FRV_FUNCDESC_GOTOFFHI:
3943 case R_FRV_FUNCDESC_GOTOFFLO:
3944 picrel->fdgoffhilo = 1;
3945 break;
3946
3947 case R_FRV_FUNCDESC:
3948 picrel->fd = 1;
3949 picrel->relocsfd++;
3950 break;
3951
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))
3956 return FALSE;
3957 break;
3958
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))
3963 return FALSE;
3964 break;
3965 }
3966 }
3967
3968 return TRUE;
3969 }
3970
3971 \f
3972 /* Return the machine subcode from the ELF e_flags header. */
3973
3974 static int
3975 elf32_frv_machine (abfd)
3976 bfd *abfd;
3977 {
3978 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
3979 {
3980 default: break;
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;
3987 }
3988
3989 return bfd_mach_frv;
3990 }
3991
3992 /* Set the right machine number for a FRV ELF file. */
3993
3994 static bfd_boolean
3995 elf32_frv_object_p (abfd)
3996 bfd *abfd;
3997 {
3998 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
3999 return TRUE;
4000 }
4001 \f
4002 /* Function to set the ELF flag bits. */
4003
4004 static bfd_boolean
4005 frv_elf_set_private_flags (abfd, flags)
4006 bfd *abfd;
4007 flagword flags;
4008 {
4009 elf_elfheader (abfd)->e_flags = flags;
4010 elf_flags_init (abfd) = TRUE;
4011 return TRUE;
4012 }
4013
4014 /* Copy backend specific data from one object module to another. */
4015
4016 static bfd_boolean
4017 frv_elf_copy_private_bfd_data (ibfd, obfd)
4018 bfd *ibfd;
4019 bfd *obfd;
4020 {
4021 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4022 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4023 return TRUE;
4024
4025 BFD_ASSERT (!elf_flags_init (obfd)
4026 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
4027
4028 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
4029 elf_flags_init (obfd) = TRUE;
4030 return TRUE;
4031 }
4032
4033 /* Merge backend specific data from an object file to the output
4034 object file when linking. */
4035
4036 static bfd_boolean
4037 frv_elf_merge_private_bfd_data (ibfd, obfd)
4038 bfd *ibfd;
4039 bfd *obfd;
4040 {
4041 flagword old_flags, old_partial;
4042 flagword new_flags, new_partial;
4043 bfd_boolean error = FALSE;
4044 char new_opt[80];
4045 char old_opt[80];
4046
4047 new_opt[0] = old_opt[0] = '\0';
4048 new_flags = elf_elfheader (ibfd)->e_flags;
4049 old_flags = elf_elfheader (obfd)->e_flags;
4050
4051 if (new_flags & EF_FRV_FDPIC)
4052 new_flags &= ~EF_FRV_PIC;
4053
4054 #ifdef DEBUG
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));
4058 #endif
4059
4060 if (!elf_flags_init (obfd)) /* First call, no flags set. */
4061 {
4062 elf_flags_init (obfd) = TRUE;
4063 old_flags = new_flags;
4064 }
4065
4066 else if (new_flags == old_flags) /* Compatible flags are ok. */
4067 ;
4068
4069 else /* Possibly incompatible flags. */
4070 {
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)
4076 ;
4077
4078 else if (new_partial == 0)
4079 ;
4080
4081 else if (old_partial == 0)
4082 old_flags |= new_partial;
4083
4084 else
4085 {
4086 switch (new_partial)
4087 {
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;
4091 }
4092
4093 switch (old_partial)
4094 {
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;
4098 }
4099 }
4100
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)
4106 ;
4107
4108 else if (new_partial == 0)
4109 ;
4110
4111 else if (old_partial == 0)
4112 old_flags |= new_partial;
4113
4114 else
4115 {
4116 switch (new_partial)
4117 {
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;
4122 }
4123
4124 switch (old_partial)
4125 {
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;
4130 }
4131 }
4132
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)
4138 ;
4139
4140 else if (new_partial == 0)
4141 ;
4142
4143 else if (old_partial == 0)
4144 old_flags |= new_partial;
4145
4146 else
4147 {
4148 switch (new_partial)
4149 {
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;
4153 }
4154
4155 switch (old_partial)
4156 {
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;
4160 }
4161 }
4162
4163 /* Or in flags that accumulate (ie, if one module uses it, mark that the
4164 feature is used. */
4165 old_flags |= new_flags & (EF_FRV_DOUBLE
4166 | EF_FRV_MEDIA
4167 | EF_FRV_MULADD
4168 | EF_FRV_NON_PIC_RELOCS);
4169
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));
4173
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));
4177
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))
4183 ;
4184
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;
4189
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;
4193
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. */
4196 else
4197 {
4198 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
4199 old_flags |= new_partial;
4200 else
4201 {
4202 old_flags &= ~ EF_FRV_PIC_FLAGS;
4203 #ifndef FRV_NO_PIC_ERROR
4204 error = TRUE;
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");
4209 #endif
4210 }
4211 }
4212
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)
4218 ;
4219
4220 else if (new_partial == EF_FRV_CPU_GENERIC)
4221 ;
4222
4223 else if (old_partial == EF_FRV_CPU_GENERIC)
4224 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
4225
4226 else
4227 {
4228 switch (new_partial)
4229 {
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;
4238 }
4239
4240 switch (old_partial)
4241 {
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;
4250 }
4251 }
4252
4253 /* Print out any mismatches from above. */
4254 if (new_opt[0])
4255 {
4256 error = TRUE;
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);
4260 }
4261
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)
4266 {
4267 old_flags |= new_partial;
4268 error = TRUE;
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);
4272 }
4273 }
4274
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;
4278
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));
4284
4285 if (error)
4286 bfd_set_error (bfd_error_bad_value);
4287
4288 return !error;
4289 }
4290
4291 \f
4292 bfd_boolean
4293 frv_elf_print_private_bfd_data (abfd, ptr)
4294 bfd *abfd;
4295 PTR ptr;
4296 {
4297 FILE *file = (FILE *) ptr;
4298 flagword flags;
4299
4300 BFD_ASSERT (abfd != NULL && ptr != NULL);
4301
4302 /* Print normal ELF private data. */
4303 _bfd_elf_print_private_bfd_data (abfd, ptr);
4304
4305 flags = elf_elfheader (abfd)->e_flags;
4306 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
4307
4308 switch (flags & EF_FRV_CPU_MASK)
4309 {
4310 default: break;
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;
4317 }
4318
4319 switch (flags & EF_FRV_GPR_MASK)
4320 {
4321 default: break;
4322 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
4323 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
4324 }
4325
4326 switch (flags & EF_FRV_FPR_MASK)
4327 {
4328 default: break;
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;
4332 }
4333
4334 switch (flags & EF_FRV_DWORD_MASK)
4335 {
4336 default: break;
4337 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
4338 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
4339 }
4340
4341 if (flags & EF_FRV_DOUBLE)
4342 fprintf (file, " -mdouble");
4343
4344 if (flags & EF_FRV_MEDIA)
4345 fprintf (file, " -mmedia");
4346
4347 if (flags & EF_FRV_MULADD)
4348 fprintf (file, " -mmuladd");
4349
4350 if (flags & EF_FRV_PIC)
4351 fprintf (file, " -fpic");
4352
4353 if (flags & EF_FRV_BIGPIC)
4354 fprintf (file, " -fPIC");
4355
4356 if (flags & EF_FRV_LIBPIC)
4357 fprintf (file, " -mlibrary-pic");
4358
4359 if (flags & EF_FRV_FDPIC)
4360 fprintf (file, " -mfdpic");
4361
4362 if (flags & EF_FRV_NON_PIC_RELOCS)
4363 fprintf (file, " non-pic relocations");
4364
4365 if (flags & EF_FRV_G0)
4366 fprintf (file, " -G0");
4367
4368 fputc ('\n', file);
4369 return TRUE;
4370 }
4371
4372 \f
4373 #define ELF_ARCH bfd_arch_frv
4374 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
4375 #define ELF_MAXPAGESIZE 0x1000
4376
4377 #define TARGET_BIG_SYM bfd_elf32_frv_vec
4378 #define TARGET_BIG_NAME "elf32-frv"
4379
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
4388
4389 #define elf_backend_can_gc_sections 1
4390 #define elf_backend_rela_normal 1
4391
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
4397
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
4403
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
4414
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
4421
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
4426
4427 #include "elf32-target.h"
This page took 0.129964 seconds and 5 git commands to generate.