config:
[binutils.git] / bfd / elf32-frv.c
blob6d0d7e483383906e6aeca16e58e3b3da2a5e4c27
1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include "elf-bfd.h"
25 #include "elf/frv.h"
26 #include "elf/dwarf2.h"
27 #include "hashtab.h"
29 /* Forward declarations. */
30 static bfd_reloc_status_type elf32_frv_relocate_lo16
31 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
32 static bfd_reloc_status_type elf32_frv_relocate_hi16
33 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
34 static bfd_reloc_status_type elf32_frv_relocate_label24
35 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
36 static bfd_reloc_status_type elf32_frv_relocate_gprel12
37 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
38 bfd_byte *, bfd_vma));
39 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
40 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
41 bfd_byte *, bfd_vma));
42 static bfd_reloc_status_type elf32_frv_relocate_gprello
43 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
44 bfd_byte *, bfd_vma));
45 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
46 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
47 bfd_byte *, bfd_vma));
48 static reloc_howto_type *frv_reloc_type_lookup
49 PARAMS ((bfd *, bfd_reloc_code_real_type));
50 static void frv_info_to_howto_rela
51 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
52 static bfd_boolean elf32_frv_relocate_section
53 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
54 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
55 static bfd_boolean elf32_frv_add_symbol_hook
56 PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
57 const char **, flagword *, asection **, bfd_vma *));
58 static bfd_reloc_status_type frv_final_link_relocate
59 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
60 Elf_Internal_Rela *, bfd_vma));
61 static bfd_boolean elf32_frv_check_relocs
62 PARAMS ((bfd *, struct bfd_link_info *, asection *,
63 const Elf_Internal_Rela *));
64 static int elf32_frv_machine
65 PARAMS ((bfd *));
66 static bfd_boolean elf32_frv_object_p
67 PARAMS ((bfd *));
68 static bfd_boolean frv_elf_set_private_flags
69 PARAMS ((bfd *, flagword));
70 static bfd_boolean frv_elf_copy_private_bfd_data
71 PARAMS ((bfd *, bfd *));
72 static bfd_boolean frv_elf_merge_private_bfd_data
73 PARAMS ((bfd *, bfd *));
74 static bfd_boolean frv_elf_print_private_bfd_data
75 PARAMS ((bfd *, PTR));
76 static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd,
77 Elf_Internal_Note * note);
78 static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd,
79 Elf_Internal_Note * note);
81 static reloc_howto_type elf32_frv_howto_table [] =
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
352 /* The 64-bit 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 */
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 */
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 */
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 */
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 */
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 */
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 */
463 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
464 a thread-local symbol. If the symbol number is 0, it refers to
465 the module. */
466 HOWTO (R_FRV_GETTLSOFF, /* type */
467 2, /* rightshift */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
469 26, /* bitsize */
470 TRUE, /* pc_relative */
471 0, /* bitpos */
472 complain_overflow_bitfield, /* complain_on_overflow */
473 bfd_elf_generic_reloc, /* special_function */
474 "R_FRV_GETTLSOFF", /* name */
475 FALSE, /* partial_inplace */
476 0x7e03ffff, /* src_mask */
477 0x7e03ffff, /* dst_mask */
478 TRUE), /* pcrel_offset */
480 /* A 64-bit TLS descriptor for a symbol. This relocation is only
481 valid as a REL, dynamic relocation. */
482 HOWTO (R_FRV_TLSDESC_VALUE, /* type */
483 0, /* rightshift */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
485 64, /* bitsize */
486 FALSE, /* pc_relative */
487 0, /* bitpos */
488 complain_overflow_bitfield, /* complain_on_overflow */
489 bfd_elf_generic_reloc, /* special_function */
490 "R_FRV_TLSDESC_VALUE", /* name */
491 FALSE, /* partial_inplace */
492 0xffffffff, /* src_mask */
493 0xffffffff, /* dst_mask */
494 FALSE), /* pcrel_offset */
496 /* A 12-bit signed operand with the GOT offset for the TLS
497 descriptor of the symbol. */
498 HOWTO (R_FRV_GOTTLSDESC12, /* type */
499 0, /* rightshift */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
501 12, /* bitsize */
502 FALSE, /* pc_relative */
503 0, /* bitpos */
504 complain_overflow_signed, /* complain_on_overflow */
505 bfd_elf_generic_reloc, /* special_function */
506 "R_FRV_GOTTLSDESC12", /* name */
507 FALSE, /* partial_inplace */
508 0xfff, /* src_mask */
509 0xfff, /* dst_mask */
510 FALSE), /* pcrel_offset */
512 /* The upper 16 bits of the GOT offset for the TLS descriptor of the
513 symbol. */
514 HOWTO (R_FRV_GOTTLSDESCHI, /* type */
515 0, /* rightshift */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
517 16, /* bitsize */
518 FALSE, /* pc_relative */
519 0, /* bitpos */
520 complain_overflow_dont, /* complain_on_overflow */
521 bfd_elf_generic_reloc, /* special_function */
522 "R_FRV_GOTTLSDESCHI", /* name */
523 FALSE, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE), /* pcrel_offset */
528 /* The lower 16 bits of the GOT offset for the TLS descriptor of the
529 symbol. */
530 HOWTO (R_FRV_GOTTLSDESCLO, /* type */
531 0, /* rightshift */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
533 16, /* bitsize */
534 FALSE, /* pc_relative */
535 0, /* bitpos */
536 complain_overflow_dont, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 "R_FRV_GOTTLSDESCLO", /* name */
539 FALSE, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE), /* pcrel_offset */
544 /* A 12-bit signed operand with the offset from the module base
545 address to the thread-local symbol address. */
546 HOWTO (R_FRV_TLSMOFF12, /* type */
547 0, /* rightshift */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
549 12, /* bitsize */
550 FALSE, /* pc_relative */
551 0, /* bitpos */
552 complain_overflow_signed, /* complain_on_overflow */
553 bfd_elf_generic_reloc, /* special_function */
554 "R_FRV_TLSMOFF12", /* name */
555 FALSE, /* partial_inplace */
556 0xfff, /* src_mask */
557 0xfff, /* dst_mask */
558 FALSE), /* pcrel_offset */
560 /* The upper 16 bits of the offset from the module base address to
561 the thread-local symbol address. */
562 HOWTO (R_FRV_TLSMOFFHI, /* type */
563 0, /* rightshift */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
565 16, /* bitsize */
566 FALSE, /* pc_relative */
567 0, /* bitpos */
568 complain_overflow_dont, /* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_FRV_TLSMOFFHI", /* name */
571 FALSE, /* partial_inplace */
572 0xffff, /* src_mask */
573 0xffff, /* dst_mask */
574 FALSE), /* pcrel_offset */
576 /* The lower 16 bits of the offset from the module base address to
577 the thread-local symbol address. */
578 HOWTO (R_FRV_TLSMOFFLO, /* type */
579 0, /* rightshift */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
581 16, /* bitsize */
582 FALSE, /* pc_relative */
583 0, /* bitpos */
584 complain_overflow_dont, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_FRV_TLSMOFFLO", /* name */
587 FALSE, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE), /* pcrel_offset */
592 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
593 for a symbol. */
594 HOWTO (R_FRV_GOTTLSOFF12, /* type */
595 0, /* rightshift */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
597 12, /* bitsize */
598 FALSE, /* pc_relative */
599 0, /* bitpos */
600 complain_overflow_signed, /* complain_on_overflow */
601 bfd_elf_generic_reloc, /* special_function */
602 "R_FRV_GOTTLSOFF12", /* name */
603 FALSE, /* partial_inplace */
604 0xfff, /* src_mask */
605 0xfff, /* dst_mask */
606 FALSE), /* pcrel_offset */
608 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
609 symbol. */
610 HOWTO (R_FRV_GOTTLSOFFHI, /* type */
611 0, /* rightshift */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
613 16, /* bitsize */
614 FALSE, /* pc_relative */
615 0, /* bitpos */
616 complain_overflow_dont, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_FRV_GOTTLSOFFHI", /* name */
619 FALSE, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 FALSE), /* pcrel_offset */
624 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
625 symbol. */
626 HOWTO (R_FRV_GOTTLSOFFLO, /* type */
627 0, /* rightshift */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
629 16, /* bitsize */
630 FALSE, /* pc_relative */
631 0, /* bitpos */
632 complain_overflow_dont, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 "R_FRV_GOTTLSOFFLO", /* name */
635 FALSE, /* partial_inplace */
636 0xffff, /* src_mask */
637 0xffff, /* dst_mask */
638 FALSE), /* pcrel_offset */
640 /* The 32-bit offset from the thread pointer (not the module base
641 address) to a thread-local symbol. */
642 HOWTO (R_FRV_TLSOFF, /* type */
643 0, /* rightshift */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
645 32, /* bitsize */
646 FALSE, /* pc_relative */
647 0, /* bitpos */
648 complain_overflow_dont, /* complain_on_overflow */
649 bfd_elf_generic_reloc, /* special_function */
650 "R_FRV_TLSOFF", /* name */
651 FALSE, /* partial_inplace */
652 0xffffffff, /* src_mask */
653 0xffffffff, /* dst_mask */
654 FALSE), /* pcrel_offset */
656 /* An annotation for linker relaxation, that denotes the
657 symbol+addend whose TLS descriptor is referenced by the sum of
658 the two input registers of an ldd instruction. */
659 HOWTO (R_FRV_TLSDESC_RELAX, /* type */
660 0, /* rightshift */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
662 0, /* bitsize */
663 FALSE, /* pc_relative */
664 0, /* bitpos */
665 complain_overflow_dont, /* complain_on_overflow */
666 bfd_elf_generic_reloc, /* special_function */
667 "R_FRV_TLSDESC_RELAX", /* name */
668 FALSE, /* partial_inplace */
669 0, /* src_mask */
670 0, /* dst_mask */
671 FALSE), /* pcrel_offset */
673 /* An annotation for linker relaxation, that denotes the
674 symbol+addend whose TLS resolver entry point is given by the sum
675 of the two register operands of an calll instruction. */
676 HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */
677 0, /* rightshift */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
679 0, /* bitsize */
680 FALSE, /* pc_relative */
681 0, /* bitpos */
682 complain_overflow_dont, /* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 "R_FRV_GETTLSOFF_RELAX", /* name */
685 FALSE, /* partial_inplace */
686 0, /* src_mask */
687 0, /* dst_mask */
688 FALSE), /* pcrel_offset */
690 /* An annotation for linker relaxation, that denotes the
691 symbol+addend whose TLS offset GOT entry is given by the sum of
692 the two input registers of an ld instruction. */
693 HOWTO (R_FRV_TLSOFF_RELAX, /* type */
694 0, /* rightshift */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
696 0, /* bitsize */
697 FALSE, /* pc_relative */
698 0, /* bitpos */
699 complain_overflow_bitfield, /* complain_on_overflow */
700 bfd_elf_generic_reloc, /* special_function */
701 "R_FRV_TLSOFF_RELAX", /* name */
702 FALSE, /* partial_inplace */
703 0, /* src_mask */
704 0, /* dst_mask */
705 FALSE), /* pcrel_offset */
707 /* A 32-bit offset from the module base address to
708 the thread-local symbol address. */
709 HOWTO (R_FRV_TLSMOFF, /* type */
710 0, /* rightshift */
711 2, /* size (0 = byte, 1 = short, 2 = long) */
712 32, /* bitsize */
713 FALSE, /* pc_relative */
714 0, /* bitpos */
715 complain_overflow_dont, /* complain_on_overflow */
716 bfd_elf_generic_reloc, /* special_function */
717 "R_FRV_TLSMOFF", /* name */
718 FALSE, /* partial_inplace */
719 0xffffffff, /* src_mask */
720 0xffffffff, /* dst_mask */
721 FALSE), /* pcrel_offset */
724 /* GNU extension to record C++ vtable hierarchy. */
725 static reloc_howto_type elf32_frv_vtinherit_howto =
726 HOWTO (R_FRV_GNU_VTINHERIT, /* type */
727 0, /* rightshift */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
729 0, /* bitsize */
730 FALSE, /* pc_relative */
731 0, /* bitpos */
732 complain_overflow_dont, /* complain_on_overflow */
733 NULL, /* special_function */
734 "R_FRV_GNU_VTINHERIT", /* name */
735 FALSE, /* partial_inplace */
736 0, /* src_mask */
737 0, /* dst_mask */
738 FALSE); /* pcrel_offset */
740 /* GNU extension to record C++ vtable member usage. */
741 static reloc_howto_type elf32_frv_vtentry_howto =
742 HOWTO (R_FRV_GNU_VTENTRY, /* type */
743 0, /* rightshift */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
745 0, /* bitsize */
746 FALSE, /* pc_relative */
747 0, /* bitpos */
748 complain_overflow_dont, /* complain_on_overflow */
749 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
750 "R_FRV_GNU_VTENTRY", /* name */
751 FALSE, /* partial_inplace */
752 0, /* src_mask */
753 0, /* dst_mask */
754 FALSE); /* pcrel_offset */
756 /* The following 3 relocations are REL. The only difference to the
757 entries in the table above are that partial_inplace is TRUE. */
758 static reloc_howto_type elf32_frv_rel_32_howto =
759 HOWTO (R_FRV_32, /* type */
760 0, /* rightshift */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
762 32, /* bitsize */
763 FALSE, /* pc_relative */
764 0, /* bitpos */
765 complain_overflow_bitfield, /* complain_on_overflow */
766 bfd_elf_generic_reloc, /* special_function */
767 "R_FRV_32", /* name */
768 TRUE, /* partial_inplace */
769 0xffffffff, /* src_mask */
770 0xffffffff, /* dst_mask */
771 FALSE); /* pcrel_offset */
773 static reloc_howto_type elf32_frv_rel_funcdesc_howto =
774 HOWTO (R_FRV_FUNCDESC, /* type */
775 0, /* rightshift */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
777 32, /* bitsize */
778 FALSE, /* pc_relative */
779 0, /* bitpos */
780 complain_overflow_bitfield, /* complain_on_overflow */
781 bfd_elf_generic_reloc, /* special_function */
782 "R_FRV_FUNCDESC", /* name */
783 TRUE, /* partial_inplace */
784 0xffffffff, /* src_mask */
785 0xffffffff, /* dst_mask */
786 FALSE); /* pcrel_offset */
788 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
789 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
790 0, /* rightshift */
791 2, /* size (0 = byte, 1 = short, 2 = long) */
792 64, /* bitsize */
793 FALSE, /* pc_relative */
794 0, /* bitpos */
795 complain_overflow_bitfield, /* complain_on_overflow */
796 bfd_elf_generic_reloc, /* special_function */
797 "R_FRV_FUNCDESC_VALUE", /* name */
798 TRUE, /* partial_inplace */
799 0xffffffff, /* src_mask */
800 0xffffffff, /* dst_mask */
801 FALSE); /* pcrel_offset */
803 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto =
804 /* A 64-bit TLS descriptor for a symbol. The first word resolves to
805 an entry point, and the second resolves to a special argument.
806 If the symbol turns out to be in static TLS, the entry point is a
807 return instruction, and the special argument is the TLS offset
808 for the symbol. If it's in dynamic TLS, the entry point is a TLS
809 offset resolver, and the special argument is a pointer to a data
810 structure allocated by the dynamic loader, containing the GOT
811 address for the offset resolver, the module id, the offset within
812 the module, and anything else the TLS offset resolver might need
813 to determine the TLS offset for the symbol in the running
814 thread. */
815 HOWTO (R_FRV_TLSDESC_VALUE, /* type */
816 0, /* rightshift */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
818 64, /* bitsize */
819 FALSE, /* pc_relative */
820 0, /* bitpos */
821 complain_overflow_bitfield, /* complain_on_overflow */
822 bfd_elf_generic_reloc, /* special_function */
823 "R_FRV_TLSDESC_VALUE", /* name */
824 TRUE, /* partial_inplace */
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
827 FALSE); /* pcrel_offset */
829 static reloc_howto_type elf32_frv_rel_tlsoff_howto =
830 /* The 32-bit offset from the thread pointer (not the module base
831 address) to a thread-local symbol. */
832 HOWTO (R_FRV_TLSOFF, /* type */
833 0, /* rightshift */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
835 32, /* bitsize */
836 FALSE, /* pc_relative */
837 0, /* bitpos */
838 complain_overflow_bitfield, /* complain_on_overflow */
839 bfd_elf_generic_reloc, /* special_function */
840 "R_FRV_TLSOFF", /* name */
841 TRUE, /* partial_inplace */
842 0xffffffff, /* src_mask */
843 0xffffffff, /* dst_mask */
844 FALSE); /* pcrel_offset */
848 extern const bfd_target bfd_elf32_frvfdpic_vec;
849 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
851 /* An extension of the elf hash table data structure, containing some
852 additional FRV-specific data. */
853 struct frvfdpic_elf_link_hash_table
855 struct elf_link_hash_table elf;
857 /* A pointer to the .got section. */
858 asection *sgot;
859 /* A pointer to the .rel.got section. */
860 asection *sgotrel;
861 /* A pointer to the .rofixup section. */
862 asection *sgotfixup;
863 /* A pointer to the .plt section. */
864 asection *splt;
865 /* A pointer to the .rel.plt section. */
866 asection *spltrel;
867 /* GOT base offset. */
868 bfd_vma got0;
869 /* Location of the first non-lazy PLT entry, i.e., the number of
870 bytes taken by lazy PLT entries. If locally-bound TLS
871 descriptors require a ret instruction, it will be placed at this
872 offset. */
873 bfd_vma plt0;
874 /* A hash table holding information about which symbols were
875 referenced with which PIC-related relocations. */
876 struct htab *relocs_info;
877 /* Summary reloc information collected by
878 _frvfdpic_count_got_plt_entries. */
879 struct _frvfdpic_dynamic_got_info *g;
882 /* Get the FRV ELF linker hash table from a link_info structure. */
884 #define frvfdpic_hash_table(info) \
885 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
887 #define frvfdpic_got_section(info) \
888 (frvfdpic_hash_table (info)->sgot)
889 #define frvfdpic_gotrel_section(info) \
890 (frvfdpic_hash_table (info)->sgotrel)
891 #define frvfdpic_gotfixup_section(info) \
892 (frvfdpic_hash_table (info)->sgotfixup)
893 #define frvfdpic_plt_section(info) \
894 (frvfdpic_hash_table (info)->splt)
895 #define frvfdpic_pltrel_section(info) \
896 (frvfdpic_hash_table (info)->spltrel)
897 #define frvfdpic_relocs_info(info) \
898 (frvfdpic_hash_table (info)->relocs_info)
899 #define frvfdpic_got_initial_offset(info) \
900 (frvfdpic_hash_table (info)->got0)
901 #define frvfdpic_plt_initial_offset(info) \
902 (frvfdpic_hash_table (info)->plt0)
903 #define frvfdpic_dynamic_got_plt_info(info) \
904 (frvfdpic_hash_table (info)->g)
906 /* Currently it's the same, but if some day we have a reason to change
907 it, we'd better be using a different macro.
909 FIXME: if there's any TLS PLT entry that uses local-exec or
910 initial-exec models, we could use the ret at the end of any of them
911 instead of adding one more. */
912 #define frvfdpic_plt_tls_ret_offset(info) \
913 (frvfdpic_plt_initial_offset (info))
915 /* The name of the dynamic interpreter. This is put in the .interp
916 section. */
918 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
920 #define DEFAULT_STACK_SIZE 0x20000
922 /* This structure is used to collect the number of entries present in
923 each addressable range of the got. */
924 struct _frvfdpic_dynamic_got_info
926 /* Several bits of information about the current link. */
927 struct bfd_link_info *info;
928 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
929 ranges. */
930 bfd_vma got12, gotlos, gothilo;
931 /* Total GOT size needed for function descriptor entries within the 12-,
932 16- or 32-bit ranges. */
933 bfd_vma fd12, fdlos, fdhilo;
934 /* Total GOT size needed by function descriptor entries referenced
935 in PLT entries, that would be profitable to place in offsets
936 close to the PIC register. */
937 bfd_vma fdplt;
938 /* Total PLT size needed by lazy PLT entries. */
939 bfd_vma lzplt;
940 /* Total GOT size needed for TLS descriptor entries within the 12-,
941 16- or 32-bit ranges. */
942 bfd_vma tlsd12, tlsdlos, tlsdhilo;
943 /* Total GOT size needed by TLS descriptors referenced in PLT
944 entries, that would be profitable to place in offers close to the
945 PIC register. */
946 bfd_vma tlsdplt;
947 /* Total PLT size needed by TLS lazy PLT entries. */
948 bfd_vma tlslzplt;
949 /* Number of relocations carried over from input object files. */
950 unsigned long relocs;
951 /* Number of fixups introduced by relocations in input object files. */
952 unsigned long fixups;
953 /* The number of fixups that reference the ret instruction added to
954 the PLT for locally-resolved TLS descriptors. */
955 unsigned long tls_ret_refs;
958 /* This structure is used to assign offsets to got entries, function
959 descriptors, plt entries and lazy plt entries. */
961 struct _frvfdpic_dynamic_got_plt_info
963 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
964 struct _frvfdpic_dynamic_got_info g;
966 /* For each addressable range, we record a MAX (positive) and MIN
967 (negative) value. CUR is used to assign got entries, and it's
968 incremented from an initial positive value to MAX, then from MIN
969 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
970 assign function descriptors, and it's decreased from an initial
971 non-positive value to MIN, then from MAX down to CUR (unless CUR
972 wraps around first). All of MIN, MAX, CUR and FDCUR always point
973 to even words. ODD, if non-zero, indicates an odd word to be
974 used for the next got entry, otherwise CUR is used and
975 incremented by a pair of words, wrapping around when it reaches
976 MAX. FDCUR is decremented (and wrapped) before the next function
977 descriptor is chosen. FDPLT indicates the number of remaining
978 slots that can be used for function descriptors used only by PLT
979 entries.
981 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
982 starts as MAX, and grows up to TMAX, then wraps around to TMIN
983 and grows up to MIN. TLSDPLT indicates the number of remaining
984 slots that can be used for TLS descriptors used only by TLS PLT
985 entries. */
986 struct _frvfdpic_dynamic_got_alloc_data
988 bfd_signed_vma max, cur, odd, fdcur, min;
989 bfd_signed_vma tmax, tcur, tmin;
990 bfd_vma fdplt, tlsdplt;
991 } got12, gotlos, gothilo;
994 /* Create an FRV ELF linker hash table. */
996 static struct bfd_link_hash_table *
997 frvfdpic_elf_link_hash_table_create (bfd *abfd)
999 struct frvfdpic_elf_link_hash_table *ret;
1000 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
1002 ret = bfd_zalloc (abfd, amt);
1003 if (ret == NULL)
1004 return NULL;
1006 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1007 _bfd_elf_link_hash_newfunc,
1008 sizeof (struct elf_link_hash_entry)))
1010 free (ret);
1011 return NULL;
1014 return &ret->elf.root;
1017 /* Decide whether a reference to a symbol can be resolved locally or
1018 not. If the symbol is protected, we want the local address, but
1019 its function descriptor must be assigned by the dynamic linker. */
1020 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1021 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1022 || ! elf_hash_table (INFO)->dynamic_sections_created)
1023 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1024 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1026 /* This structure collects information on what kind of GOT, PLT or
1027 function descriptors are required by relocations that reference a
1028 certain symbol. */
1029 struct frvfdpic_relocs_info
1031 /* The index of the symbol, as stored in the relocation r_info, if
1032 we have a local symbol; -1 otherwise. */
1033 long symndx;
1034 union
1036 /* The input bfd in which the symbol is defined, if it's a local
1037 symbol. */
1038 bfd *abfd;
1039 /* If symndx == -1, the hash table entry corresponding to a global
1040 symbol (even if it turns out to bind locally, in which case it
1041 should ideally be replaced with section's symndx + addend). */
1042 struct elf_link_hash_entry *h;
1043 } d;
1044 /* The addend of the relocation that references the symbol. */
1045 bfd_vma addend;
1047 /* The fields above are used to identify an entry. The fields below
1048 contain information on how an entry is used and, later on, which
1049 locations it was assigned. */
1050 /* The following 3 fields record whether the symbol+addend above was
1051 ever referenced with a GOT relocation. The 12 suffix indicates a
1052 GOT12 relocation; los is used for GOTLO relocations that are not
1053 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1054 pairs. */
1055 unsigned got12:1;
1056 unsigned gotlos:1;
1057 unsigned gothilo:1;
1058 /* Whether a FUNCDESC relocation references symbol+addend. */
1059 unsigned fd:1;
1060 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1061 unsigned fdgot12:1;
1062 unsigned fdgotlos:1;
1063 unsigned fdgothilo:1;
1064 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1065 unsigned fdgoff12:1;
1066 unsigned fdgofflos:1;
1067 unsigned fdgoffhilo:1;
1068 /* Whether a GETTLSOFF relocation references symbol+addend. */
1069 unsigned tlsplt:1;
1070 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1071 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1072 We might instead just pre-compute flags telling whether the
1073 object is suitable for local exec, initial exec or general
1074 dynamic addressing, and use that all over the place. We could
1075 also try to do a better job of merging TLSOFF and TLSDESC entries
1076 in main executables, but perhaps we can get rid of TLSDESC
1077 entirely in them instead. */
1078 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1079 unsigned tlsdesc12:1;
1080 unsigned tlsdesclos:1;
1081 unsigned tlsdeschilo:1;
1082 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1083 unsigned tlsoff12:1;
1084 unsigned tlsofflos:1;
1085 unsigned tlsoffhilo:1;
1086 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1087 GOTOFFHI relocations. The addend doesn't really matter, since we
1088 envision that this will only be used to check whether the symbol
1089 is mapped to the same segment as the got. */
1090 unsigned gotoff:1;
1091 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1092 unsigned call:1;
1093 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1094 relocation. */
1095 unsigned sym:1;
1096 /* Whether we need a PLT entry for a symbol. Should be implied by
1097 something like:
1098 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1099 unsigned plt:1;
1100 /* Whether a function descriptor should be created in this link unit
1101 for symbol+addend. Should be implied by something like:
1102 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1103 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1104 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1105 unsigned privfd:1;
1106 /* Whether a lazy PLT entry is needed for this symbol+addend.
1107 Should be implied by something like:
1108 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1109 && ! (info->flags & DF_BIND_NOW)) */
1110 unsigned lazyplt:1;
1111 /* Whether we've already emitted GOT relocations and PLT entries as
1112 needed for this symbol. */
1113 unsigned done:1;
1115 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1116 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1117 symbol+addend. */
1118 unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
1120 /* The number of .rofixups entries and dynamic relocations allocated
1121 for this symbol, minus any that might have already been used. */
1122 unsigned fixups, dynrelocs;
1124 /* The offsets of the GOT entries assigned to symbol+addend, to the
1125 function descriptor's address, and to a function descriptor,
1126 respectively. Should be zero if unassigned. The offsets are
1127 counted from the value that will be assigned to the PIC register,
1128 not from the beginning of the .got section. */
1129 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
1130 /* The offsets of the PLT entries assigned to symbol+addend,
1131 non-lazy and lazy, respectively. If unassigned, should be
1132 (bfd_vma)-1. */
1133 bfd_vma plt_entry, lzplt_entry;
1134 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1135 bfd_signed_vma tlsoff_entry, tlsdesc_entry;
1136 /* The offset of the TLS offset PLT entry. */
1137 bfd_vma tlsplt_entry;
1140 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1141 static hashval_t
1142 frvfdpic_relocs_info_hash (const void *entry_)
1144 const struct frvfdpic_relocs_info *entry = entry_;
1146 return (entry->symndx == -1
1147 ? (long) entry->d.h->root.root.hash
1148 : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
1151 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1152 identical. */
1153 static int
1154 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
1156 const struct frvfdpic_relocs_info *e1 = entry1;
1157 const struct frvfdpic_relocs_info *e2 = entry2;
1159 return e1->symndx == e2->symndx && e1->addend == e2->addend
1160 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
1163 /* Find or create an entry in a hash table HT that matches the key
1164 fields of the given ENTRY. If it's not found, memory for a new
1165 entry is allocated in ABFD's obstack. */
1166 static struct frvfdpic_relocs_info *
1167 frvfdpic_relocs_info_find (struct htab *ht,
1168 bfd *abfd,
1169 const struct frvfdpic_relocs_info *entry,
1170 enum insert_option insert)
1172 struct frvfdpic_relocs_info **loc =
1173 (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
1175 if (! loc)
1176 return NULL;
1178 if (*loc)
1179 return *loc;
1181 *loc = bfd_zalloc (abfd, sizeof (**loc));
1183 if (! *loc)
1184 return *loc;
1186 (*loc)->symndx = entry->symndx;
1187 (*loc)->d = entry->d;
1188 (*loc)->addend = entry->addend;
1189 (*loc)->plt_entry = (bfd_vma)-1;
1190 (*loc)->lzplt_entry = (bfd_vma)-1;
1191 (*loc)->tlsplt_entry = (bfd_vma)-1;
1193 return *loc;
1196 /* Obtain the address of the entry in HT associated with H's symbol +
1197 addend, creating a new entry if none existed. ABFD is only used
1198 for memory allocation purposes. */
1199 inline static struct frvfdpic_relocs_info *
1200 frvfdpic_relocs_info_for_global (struct htab *ht,
1201 bfd *abfd,
1202 struct elf_link_hash_entry *h,
1203 bfd_vma addend,
1204 enum insert_option insert)
1206 struct frvfdpic_relocs_info entry;
1208 entry.symndx = -1;
1209 entry.d.h = h;
1210 entry.addend = addend;
1212 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1215 /* Obtain the address of the entry in HT associated with the SYMNDXth
1216 local symbol of the input bfd ABFD, plus the addend, creating a new
1217 entry if none existed. */
1218 inline static struct frvfdpic_relocs_info *
1219 frvfdpic_relocs_info_for_local (struct htab *ht,
1220 bfd *abfd,
1221 long symndx,
1222 bfd_vma addend,
1223 enum insert_option insert)
1225 struct frvfdpic_relocs_info entry;
1227 entry.symndx = symndx;
1228 entry.d.abfd = abfd;
1229 entry.addend = addend;
1231 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1234 /* Merge fields set by check_relocs() of two entries that end up being
1235 mapped to the same (presumably global) symbol. */
1237 inline static void
1238 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
1239 struct frvfdpic_relocs_info const *e1)
1241 e2->got12 |= e1->got12;
1242 e2->gotlos |= e1->gotlos;
1243 e2->gothilo |= e1->gothilo;
1244 e2->fd |= e1->fd;
1245 e2->fdgot12 |= e1->fdgot12;
1246 e2->fdgotlos |= e1->fdgotlos;
1247 e2->fdgothilo |= e1->fdgothilo;
1248 e2->fdgoff12 |= e1->fdgoff12;
1249 e2->fdgofflos |= e1->fdgofflos;
1250 e2->fdgoffhilo |= e1->fdgoffhilo;
1251 e2->tlsplt |= e1->tlsplt;
1252 e2->tlsdesc12 |= e1->tlsdesc12;
1253 e2->tlsdesclos |= e1->tlsdesclos;
1254 e2->tlsdeschilo |= e1->tlsdeschilo;
1255 e2->tlsoff12 |= e1->tlsoff12;
1256 e2->tlsofflos |= e1->tlsofflos;
1257 e2->tlsoffhilo |= e1->tlsoffhilo;
1258 e2->gotoff |= e1->gotoff;
1259 e2->call |= e1->call;
1260 e2->sym |= e1->sym;
1263 /* Every block of 65535 lazy PLT entries shares a single call to the
1264 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1265 32767, counting from 0). All other lazy PLT entries branch to it
1266 in a single instruction. */
1268 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1269 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1271 /* Add a dynamic relocation to the SRELOC section. */
1273 inline static bfd_vma
1274 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
1275 int reloc_type, long dynindx, bfd_vma addend,
1276 struct frvfdpic_relocs_info *entry)
1278 Elf_Internal_Rela outrel;
1279 bfd_vma reloc_offset;
1281 outrel.r_offset = offset;
1282 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
1283 outrel.r_addend = addend;
1285 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
1286 BFD_ASSERT (reloc_offset < sreloc->size);
1287 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1288 sreloc->contents + reloc_offset);
1289 sreloc->reloc_count++;
1291 /* If the entry's index is zero, this relocation was probably to a
1292 linkonce section that got discarded. We reserved a dynamic
1293 relocation, but it was for another entry than the one we got at
1294 the time of emitting the relocation. Unfortunately there's no
1295 simple way for us to catch this situation, since the relocation
1296 is cleared right before calling relocate_section, at which point
1297 we no longer know what the relocation used to point to. */
1298 if (entry->symndx)
1300 BFD_ASSERT (entry->dynrelocs > 0);
1301 entry->dynrelocs--;
1304 return reloc_offset;
1307 /* Add a fixup to the ROFIXUP section. */
1309 static bfd_vma
1310 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
1311 struct frvfdpic_relocs_info *entry)
1313 bfd_vma fixup_offset;
1315 if (rofixup->flags & SEC_EXCLUDE)
1316 return -1;
1318 fixup_offset = rofixup->reloc_count * 4;
1319 if (rofixup->contents)
1321 BFD_ASSERT (fixup_offset < rofixup->size);
1322 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
1324 rofixup->reloc_count++;
1326 if (entry && entry->symndx)
1328 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1329 above. */
1330 BFD_ASSERT (entry->fixups > 0);
1331 entry->fixups--;
1334 return fixup_offset;
1337 /* Find the segment number in which OSEC, and output section, is
1338 located. */
1340 static unsigned
1341 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
1343 struct elf_segment_map *m;
1344 Elf_Internal_Phdr *p;
1346 /* Find the segment that contains the output_section. */
1347 for (m = elf_tdata (output_bfd)->segment_map,
1348 p = elf_tdata (output_bfd)->phdr;
1349 m != NULL;
1350 m = m->next, p++)
1352 int i;
1354 for (i = m->count - 1; i >= 0; i--)
1355 if (m->sections[i] == osec)
1356 break;
1358 if (i >= 0)
1359 break;
1362 return p - elf_tdata (output_bfd)->phdr;
1365 inline static bfd_boolean
1366 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
1368 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
1370 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
1373 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1375 /* Return the base VMA address which should be subtracted from real addresses
1376 when resolving TLSMOFF relocation.
1377 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1379 static bfd_vma
1380 tls_biased_base (struct bfd_link_info *info)
1382 /* If tls_sec is NULL, we should have signalled an error already. */
1383 if (elf_hash_table (info)->tls_sec == NULL)
1384 return FRVFDPIC_TLS_BIAS;
1385 return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
1388 /* Generate relocations for GOT entries, function descriptors, and
1389 code for PLT and lazy PLT entries. */
1391 inline static bfd_boolean
1392 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
1393 bfd *output_bfd,
1394 struct bfd_link_info *info,
1395 asection *sec,
1396 Elf_Internal_Sym *sym,
1397 bfd_vma addend)
1400 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
1401 int dynindx = -1;
1403 if (entry->done)
1404 return TRUE;
1405 entry->done = 1;
1407 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
1408 || entry->tlsoff_entry || entry->tlsdesc_entry)
1410 /* If the symbol is dynamic, consider it for dynamic
1411 relocations, otherwise decay to section + offset. */
1412 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
1413 dynindx = entry->d.h->dynindx;
1414 else
1416 if (sec->output_section
1417 && ! bfd_is_abs_section (sec->output_section)
1418 && ! bfd_is_und_section (sec->output_section))
1419 dynindx = elf_section_data (sec->output_section)->dynindx;
1420 else
1421 dynindx = 0;
1425 /* Generate relocation for GOT entry pointing to the symbol. */
1426 if (entry->got_entry)
1428 int idx = dynindx;
1429 bfd_vma ad = addend;
1431 /* If the symbol is dynamic but binds locally, use
1432 section+offset. */
1433 if (sec && (entry->symndx != -1
1434 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1436 if (entry->symndx == -1)
1437 ad += entry->d.h->root.u.def.value;
1438 else
1439 ad += sym->st_value;
1440 ad += sec->output_offset;
1441 if (sec->output_section && elf_section_data (sec->output_section))
1442 idx = elf_section_data (sec->output_section)->dynindx;
1443 else
1444 idx = 0;
1447 /* If we're linking an executable at a fixed address, we can
1448 omit the dynamic relocation as long as the symbol is local to
1449 this module. */
1450 if (info->executable && !info->pie
1451 && (entry->symndx != -1
1452 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1454 if (sec)
1455 ad += sec->output_section->vma;
1456 if (entry->symndx != -1
1457 || entry->d.h->root.type != bfd_link_hash_undefweak)
1458 _frvfdpic_add_rofixup (output_bfd,
1459 frvfdpic_gotfixup_section (info),
1460 frvfdpic_got_section (info)->output_section
1461 ->vma
1462 + frvfdpic_got_section (info)->output_offset
1463 + frvfdpic_got_initial_offset (info)
1464 + entry->got_entry, entry);
1466 else
1467 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1468 _bfd_elf_section_offset
1469 (output_bfd, info,
1470 frvfdpic_got_section (info),
1471 frvfdpic_got_initial_offset (info)
1472 + entry->got_entry)
1473 + frvfdpic_got_section (info)
1474 ->output_section->vma
1475 + frvfdpic_got_section (info)->output_offset,
1476 R_FRV_32, idx, ad, entry);
1478 bfd_put_32 (output_bfd, ad,
1479 frvfdpic_got_section (info)->contents
1480 + frvfdpic_got_initial_offset (info)
1481 + entry->got_entry);
1484 /* Generate relocation for GOT entry pointing to a canonical
1485 function descriptor. */
1486 if (entry->fdgot_entry)
1488 int reloc, idx;
1489 bfd_vma ad = 0;
1491 if (! (entry->symndx == -1
1492 && entry->d.h->root.type == bfd_link_hash_undefweak
1493 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1495 /* If the symbol is dynamic and there may be dynamic symbol
1496 resolution because we are, or are linked with, a shared
1497 library, emit a FUNCDESC relocation such that the dynamic
1498 linker will allocate the function descriptor. If the
1499 symbol needs a non-local function descriptor but binds
1500 locally (e.g., its visibility is protected, emit a
1501 dynamic relocation decayed to section+offset. */
1502 if (entry->symndx == -1
1503 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
1504 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
1505 && !(info->executable && !info->pie))
1507 reloc = R_FRV_FUNCDESC;
1508 idx = elf_section_data (entry->d.h->root.u.def.section
1509 ->output_section)->dynindx;
1510 ad = entry->d.h->root.u.def.section->output_offset
1511 + entry->d.h->root.u.def.value;
1513 else if (entry->symndx == -1
1514 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
1516 reloc = R_FRV_FUNCDESC;
1517 idx = dynindx;
1518 ad = addend;
1519 if (ad)
1521 (*info->callbacks->reloc_dangerous)
1522 (info, _("relocation requires zero addend"),
1523 elf_hash_table (info)->dynobj,
1524 frvfdpic_got_section (info),
1525 entry->fdgot_entry);
1526 return FALSE;
1529 else
1531 /* Otherwise, we know we have a private function descriptor,
1532 so reference it directly. */
1533 if (elf_hash_table (info)->dynamic_sections_created)
1534 BFD_ASSERT (entry->privfd);
1535 reloc = R_FRV_32;
1536 idx = elf_section_data (frvfdpic_got_section (info)
1537 ->output_section)->dynindx;
1538 ad = frvfdpic_got_section (info)->output_offset
1539 + frvfdpic_got_initial_offset (info) + entry->fd_entry;
1542 /* If there is room for dynamic symbol resolution, emit the
1543 dynamic relocation. However, if we're linking an
1544 executable at a fixed location, we won't have emitted a
1545 dynamic symbol entry for the got section, so idx will be
1546 zero, which means we can and should compute the address
1547 of the private descriptor ourselves. */
1548 if (info->executable && !info->pie
1549 && (entry->symndx != -1
1550 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
1552 ad += frvfdpic_got_section (info)->output_section->vma;
1553 _frvfdpic_add_rofixup (output_bfd,
1554 frvfdpic_gotfixup_section (info),
1555 frvfdpic_got_section (info)
1556 ->output_section->vma
1557 + frvfdpic_got_section (info)
1558 ->output_offset
1559 + frvfdpic_got_initial_offset (info)
1560 + entry->fdgot_entry, entry);
1562 else
1563 _frvfdpic_add_dyn_reloc (output_bfd,
1564 frvfdpic_gotrel_section (info),
1565 _bfd_elf_section_offset
1566 (output_bfd, info,
1567 frvfdpic_got_section (info),
1568 frvfdpic_got_initial_offset (info)
1569 + entry->fdgot_entry)
1570 + frvfdpic_got_section (info)
1571 ->output_section->vma
1572 + frvfdpic_got_section (info)
1573 ->output_offset,
1574 reloc, idx, ad, entry);
1577 bfd_put_32 (output_bfd, ad,
1578 frvfdpic_got_section (info)->contents
1579 + frvfdpic_got_initial_offset (info)
1580 + entry->fdgot_entry);
1583 /* Generate relocation to fill in a private function descriptor in
1584 the GOT. */
1585 if (entry->fd_entry)
1587 int idx = dynindx;
1588 bfd_vma ad = addend;
1589 bfd_vma ofst;
1590 long lowword, highword;
1592 /* If the symbol is dynamic but binds locally, use
1593 section+offset. */
1594 if (sec && (entry->symndx != -1
1595 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1597 if (entry->symndx == -1)
1598 ad += entry->d.h->root.u.def.value;
1599 else
1600 ad += sym->st_value;
1601 ad += sec->output_offset;
1602 if (sec->output_section && elf_section_data (sec->output_section))
1603 idx = elf_section_data (sec->output_section)->dynindx;
1604 else
1605 idx = 0;
1608 /* If we're linking an executable at a fixed address, we can
1609 omit the dynamic relocation as long as the symbol is local to
1610 this module. */
1611 if (info->executable && !info->pie
1612 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1614 if (sec)
1615 ad += sec->output_section->vma;
1616 ofst = 0;
1617 if (entry->symndx != -1
1618 || entry->d.h->root.type != bfd_link_hash_undefweak)
1620 _frvfdpic_add_rofixup (output_bfd,
1621 frvfdpic_gotfixup_section (info),
1622 frvfdpic_got_section (info)
1623 ->output_section->vma
1624 + frvfdpic_got_section (info)
1625 ->output_offset
1626 + frvfdpic_got_initial_offset (info)
1627 + entry->fd_entry, entry);
1628 _frvfdpic_add_rofixup (output_bfd,
1629 frvfdpic_gotfixup_section (info),
1630 frvfdpic_got_section (info)
1631 ->output_section->vma
1632 + frvfdpic_got_section (info)
1633 ->output_offset
1634 + frvfdpic_got_initial_offset (info)
1635 + entry->fd_entry + 4, entry);
1638 else
1640 ofst =
1641 _frvfdpic_add_dyn_reloc (output_bfd,
1642 entry->lazyplt
1643 ? frvfdpic_pltrel_section (info)
1644 : frvfdpic_gotrel_section (info),
1645 _bfd_elf_section_offset
1646 (output_bfd, info,
1647 frvfdpic_got_section (info),
1648 frvfdpic_got_initial_offset (info)
1649 + entry->fd_entry)
1650 + frvfdpic_got_section (info)
1651 ->output_section->vma
1652 + frvfdpic_got_section (info)
1653 ->output_offset,
1654 R_FRV_FUNCDESC_VALUE, idx, ad, entry);
1657 /* If we've omitted the dynamic relocation, just emit the fixed
1658 addresses of the symbol and of the local GOT base offset. */
1659 if (info->executable && !info->pie && sec && sec->output_section)
1661 lowword = ad;
1662 highword = frvfdpic_got_section (info)->output_section->vma
1663 + frvfdpic_got_section (info)->output_offset
1664 + frvfdpic_got_initial_offset (info);
1666 else if (entry->lazyplt)
1668 if (ad)
1670 (*info->callbacks->reloc_dangerous)
1671 (info, _("relocation requires zero addend"),
1672 elf_hash_table (info)->dynobj,
1673 frvfdpic_got_section (info),
1674 entry->fd_entry);
1675 return FALSE;
1678 fd_lazy_rel_offset = ofst;
1680 /* A function descriptor used for lazy or local resolving is
1681 initialized such that its high word contains the output
1682 section index in which the PLT entries are located, and
1683 the low word contains the address of the lazy PLT entry
1684 entry point, that must be within the memory region
1685 assigned to that section. */
1686 lowword = entry->lzplt_entry + 4
1687 + frvfdpic_plt_section (info)->output_offset
1688 + frvfdpic_plt_section (info)->output_section->vma;
1689 highword = _frvfdpic_osec_to_segment
1690 (output_bfd, frvfdpic_plt_section (info)->output_section);
1692 else
1694 /* A function descriptor for a local function gets the index
1695 of the section. For a non-local function, it's
1696 disregarded. */
1697 lowword = ad;
1698 if (entry->symndx == -1 && entry->d.h->dynindx != -1
1699 && entry->d.h->dynindx == idx)
1700 highword = 0;
1701 else
1702 highword = _frvfdpic_osec_to_segment
1703 (output_bfd, sec->output_section);
1706 bfd_put_32 (output_bfd, lowword,
1707 frvfdpic_got_section (info)->contents
1708 + frvfdpic_got_initial_offset (info)
1709 + entry->fd_entry);
1710 bfd_put_32 (output_bfd, highword,
1711 frvfdpic_got_section (info)->contents
1712 + frvfdpic_got_initial_offset (info)
1713 + entry->fd_entry + 4);
1716 /* Generate code for the PLT entry. */
1717 if (entry->plt_entry != (bfd_vma) -1)
1719 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1720 + entry->plt_entry;
1722 BFD_ASSERT (entry->fd_entry);
1724 /* Figure out what kind of PLT entry we need, depending on the
1725 location of the function descriptor within the GOT. */
1726 if (entry->fd_entry >= -(1 << (12 - 1))
1727 && entry->fd_entry < (1 << (12 - 1)))
1729 /* lddi @(gr15, fd_entry), gr14 */
1730 bfd_put_32 (output_bfd,
1731 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1732 plt_code);
1733 plt_code += 4;
1735 else
1737 if (entry->fd_entry >= -(1 << (16 - 1))
1738 && entry->fd_entry < (1 << (16 - 1)))
1740 /* setlos lo(fd_entry), gr14 */
1741 bfd_put_32 (output_bfd,
1742 0x9cfc0000
1743 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1744 plt_code);
1745 plt_code += 4;
1747 else
1749 /* sethi.p hi(fd_entry), gr14
1750 setlo lo(fd_entry), gr14 */
1751 bfd_put_32 (output_bfd,
1752 0x1cf80000
1753 | ((entry->fd_entry >> 16)
1754 & (((bfd_vma)1 << 16) - 1)),
1755 plt_code);
1756 plt_code += 4;
1757 bfd_put_32 (output_bfd,
1758 0x9cf40000
1759 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1760 plt_code);
1761 plt_code += 4;
1763 /* ldd @(gr14,gr15),gr14 */
1764 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1765 plt_code += 4;
1767 /* jmpl @(gr14,gr0) */
1768 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1771 /* Generate code for the lazy PLT entry. */
1772 if (entry->lzplt_entry != (bfd_vma) -1)
1774 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
1775 + entry->lzplt_entry;
1776 bfd_vma resolverStub_addr;
1778 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1779 lzplt_code += 4;
1781 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
1782 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
1783 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
1784 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
1786 if (entry->lzplt_entry == resolverStub_addr)
1788 /* This is a lazy PLT entry that includes a resolver call. */
1789 /* ldd @(gr15,gr0), gr4
1790 jmpl @(gr4,gr0) */
1791 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1792 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1794 else
1796 /* bra resolverStub */
1797 bfd_put_32 (output_bfd,
1798 0xc01a0000
1799 | (((resolverStub_addr - entry->lzplt_entry)
1800 / 4) & (((bfd_vma)1 << 16) - 1)),
1801 lzplt_code);
1805 /* Generate relocation for GOT entry holding the TLS offset. */
1806 if (entry->tlsoff_entry)
1808 int idx = dynindx;
1809 bfd_vma ad = addend;
1811 if (entry->symndx != -1
1812 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
1814 /* If the symbol is dynamic but binds locally, use
1815 section+offset. */
1816 if (sec)
1818 if (entry->symndx == -1)
1819 ad += entry->d.h->root.u.def.value;
1820 else
1821 ad += sym->st_value;
1822 ad += sec->output_offset;
1823 if (sec->output_section
1824 && elf_section_data (sec->output_section))
1825 idx = elf_section_data (sec->output_section)->dynindx;
1826 else
1827 idx = 0;
1831 /* *ABS*+addend is special for TLS relocations, use only the
1832 addend. */
1833 if (info->executable
1834 && idx == 0
1835 && (bfd_is_abs_section (sec)
1836 || bfd_is_und_section (sec)))
1838 /* If we're linking an executable, we can entirely omit the
1839 dynamic relocation if the symbol is local to this module. */
1840 else if (info->executable
1841 && (entry->symndx != -1
1842 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1844 if (sec)
1845 ad += sec->output_section->vma - tls_biased_base (info);
1847 else
1849 if (idx == 0
1850 && (bfd_is_abs_section (sec)
1851 || bfd_is_und_section (sec)))
1853 if (! elf_hash_table (info)->tls_sec)
1855 (*info->callbacks->undefined_symbol)
1856 (info, "TLS section", elf_hash_table (info)->dynobj,
1857 frvfdpic_got_section (info), entry->tlsoff_entry, TRUE);
1858 return FALSE;
1860 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1861 ad += FRVFDPIC_TLS_BIAS;
1863 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1864 _bfd_elf_section_offset
1865 (output_bfd, info,
1866 frvfdpic_got_section (info),
1867 frvfdpic_got_initial_offset (info)
1868 + entry->tlsoff_entry)
1869 + frvfdpic_got_section (info)
1870 ->output_section->vma
1871 + frvfdpic_got_section (info)
1872 ->output_offset,
1873 R_FRV_TLSOFF, idx, ad, entry);
1876 bfd_put_32 (output_bfd, ad,
1877 frvfdpic_got_section (info)->contents
1878 + frvfdpic_got_initial_offset (info)
1879 + entry->tlsoff_entry);
1882 if (entry->tlsdesc_entry)
1884 int idx = dynindx;
1885 bfd_vma ad = addend;
1887 /* If the symbol is dynamic but binds locally, use
1888 section+offset. */
1889 if (sec && (entry->symndx != -1
1890 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1892 if (entry->symndx == -1)
1893 ad += entry->d.h->root.u.def.value;
1894 else
1895 ad += sym->st_value;
1896 ad += sec->output_offset;
1897 if (sec->output_section && elf_section_data (sec->output_section))
1898 idx = elf_section_data (sec->output_section)->dynindx;
1899 else
1900 idx = 0;
1903 /* If we didn't set up a TLS offset entry, but we're linking an
1904 executable and the symbol binds locally, we can use the
1905 module offset in the TLS descriptor in relaxations. */
1906 if (info->executable && ! entry->tlsoff_entry)
1907 entry->tlsoff_entry = entry->tlsdesc_entry + 4;
1909 if (info->executable && !info->pie
1910 && ((idx == 0
1911 && (bfd_is_abs_section (sec)
1912 || bfd_is_und_section (sec)))
1913 || entry->symndx != -1
1914 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1916 /* *ABS*+addend is special for TLS relocations, use only the
1917 addend for the TLS offset, and take the module id as
1918 0. */
1919 if (idx == 0
1920 && (bfd_is_abs_section (sec)
1921 || bfd_is_und_section (sec)))
1923 /* For other TLS symbols that bind locally, add the section
1924 TLS offset to the addend. */
1925 else if (sec)
1926 ad += sec->output_section->vma - tls_biased_base (info);
1928 bfd_put_32 (output_bfd,
1929 frvfdpic_plt_section (info)->output_section->vma
1930 + frvfdpic_plt_section (info)->output_offset
1931 + frvfdpic_plt_tls_ret_offset (info),
1932 frvfdpic_got_section (info)->contents
1933 + frvfdpic_got_initial_offset (info)
1934 + entry->tlsdesc_entry);
1936 _frvfdpic_add_rofixup (output_bfd,
1937 frvfdpic_gotfixup_section (info),
1938 frvfdpic_got_section (info)
1939 ->output_section->vma
1940 + frvfdpic_got_section (info)
1941 ->output_offset
1942 + frvfdpic_got_initial_offset (info)
1943 + entry->tlsdesc_entry, entry);
1945 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
1947 /* We've used one of the reserved fixups, so discount it so
1948 that we can check at the end that we've used them
1949 all. */
1950 frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
1952 /* While at that, make sure the ret instruction makes to the
1953 right location in the PLT. We could do it only when we
1954 got to 0, but since the check at the end will only print
1955 a warning, make sure we have the ret in place in case the
1956 warning is missed. */
1957 bfd_put_32 (output_bfd, 0xc03a4000,
1958 frvfdpic_plt_section (info)->contents
1959 + frvfdpic_plt_tls_ret_offset (info));
1961 else
1963 if (idx == 0
1964 && (bfd_is_abs_section (sec)
1965 || bfd_is_und_section (sec)))
1967 if (! elf_hash_table (info)->tls_sec)
1969 (*info->callbacks->undefined_symbol)
1970 (info, "TLS section", elf_hash_table (info)->dynobj,
1971 frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE);
1972 return FALSE;
1974 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1975 ad += FRVFDPIC_TLS_BIAS;
1978 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1979 _bfd_elf_section_offset
1980 (output_bfd, info,
1981 frvfdpic_got_section (info),
1982 frvfdpic_got_initial_offset (info)
1983 + entry->tlsdesc_entry)
1984 + frvfdpic_got_section (info)
1985 ->output_section->vma
1986 + frvfdpic_got_section (info)
1987 ->output_offset,
1988 R_FRV_TLSDESC_VALUE, idx, ad, entry);
1990 bfd_put_32 (output_bfd, 0,
1991 frvfdpic_got_section (info)->contents
1992 + frvfdpic_got_initial_offset (info)
1993 + entry->tlsdesc_entry);
1996 bfd_put_32 (output_bfd, ad,
1997 frvfdpic_got_section (info)->contents
1998 + frvfdpic_got_initial_offset (info)
1999 + entry->tlsdesc_entry + 4);
2002 /* Generate code for the get-TLS-offset PLT entry. */
2003 if (entry->tlsplt_entry != (bfd_vma) -1)
2005 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
2006 + entry->tlsplt_entry;
2008 if (info->executable
2009 && (entry->symndx != -1
2010 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
2012 int idx = dynindx;
2013 bfd_vma ad = addend;
2015 /* sec may be NULL when referencing an undefweak symbol
2016 while linking a static executable. */
2017 if (!sec)
2019 BFD_ASSERT (entry->symndx == -1
2020 && entry->d.h->root.type == bfd_link_hash_undefweak);
2022 else
2024 if (entry->symndx == -1)
2025 ad += entry->d.h->root.u.def.value;
2026 else
2027 ad += sym->st_value;
2028 ad += sec->output_offset;
2029 if (sec->output_section
2030 && elf_section_data (sec->output_section))
2031 idx = elf_section_data (sec->output_section)->dynindx;
2032 else
2033 idx = 0;
2036 /* *ABS*+addend is special for TLS relocations, use only the
2037 addend for the TLS offset, and take the module id as
2038 0. */
2039 if (idx == 0
2040 && (bfd_is_abs_section (sec)
2041 || bfd_is_und_section (sec)))
2043 /* For other TLS symbols that bind locally, add the section
2044 TLS offset to the addend. */
2045 else if (sec)
2046 ad += sec->output_section->vma - tls_biased_base (info);
2048 if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
2049 && (bfd_signed_vma)ad < (1 << (16 - 1)))
2051 /* setlos lo(ad), gr9 */
2052 bfd_put_32 (output_bfd,
2053 0x92fc0000
2054 | (ad
2055 & (((bfd_vma)1 << 16) - 1)),
2056 plt_code);
2057 plt_code += 4;
2059 else
2061 /* sethi.p hi(ad), gr9
2062 setlo lo(ad), gr9 */
2063 bfd_put_32 (output_bfd,
2064 0x12f80000
2065 | ((ad >> 16)
2066 & (((bfd_vma)1 << 16) - 1)),
2067 plt_code);
2068 plt_code += 4;
2069 bfd_put_32 (output_bfd,
2070 0x92f40000
2071 | (ad
2072 & (((bfd_vma)1 << 16) - 1)),
2073 plt_code);
2074 plt_code += 4;
2076 /* ret */
2077 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2079 else if (entry->tlsoff_entry)
2081 /* Figure out what kind of PLT entry we need, depending on the
2082 location of the TLS descriptor within the GOT. */
2083 if (entry->tlsoff_entry >= -(1 << (12 - 1))
2084 && entry->tlsoff_entry < (1 << (12 - 1)))
2086 /* ldi @(gr15, tlsoff_entry), gr9 */
2087 bfd_put_32 (output_bfd,
2088 0x92c8f000 | (entry->tlsoff_entry
2089 & ((1 << 12) - 1)),
2090 plt_code);
2091 plt_code += 4;
2093 else
2095 if (entry->tlsoff_entry >= -(1 << (16 - 1))
2096 && entry->tlsoff_entry < (1 << (16 - 1)))
2098 /* setlos lo(tlsoff_entry), gr8 */
2099 bfd_put_32 (output_bfd,
2100 0x90fc0000
2101 | (entry->tlsoff_entry
2102 & (((bfd_vma)1 << 16) - 1)),
2103 plt_code);
2104 plt_code += 4;
2106 else
2108 /* sethi.p hi(tlsoff_entry), gr8
2109 setlo lo(tlsoff_entry), gr8 */
2110 bfd_put_32 (output_bfd,
2111 0x10f80000
2112 | ((entry->tlsoff_entry >> 16)
2113 & (((bfd_vma)1 << 16) - 1)),
2114 plt_code);
2115 plt_code += 4;
2116 bfd_put_32 (output_bfd,
2117 0x90f40000
2118 | (entry->tlsoff_entry
2119 & (((bfd_vma)1 << 16) - 1)),
2120 plt_code);
2121 plt_code += 4;
2123 /* ld @(gr15,gr8),gr9 */
2124 bfd_put_32 (output_bfd, 0x9008f108, plt_code);
2125 plt_code += 4;
2127 /* ret */
2128 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2130 else
2132 BFD_ASSERT (entry->tlsdesc_entry);
2134 /* Figure out what kind of PLT entry we need, depending on the
2135 location of the TLS descriptor within the GOT. */
2136 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
2137 && entry->tlsdesc_entry < (1 << (12 - 1)))
2139 /* lddi @(gr15, tlsdesc_entry), gr8 */
2140 bfd_put_32 (output_bfd,
2141 0x90ccf000 | (entry->tlsdesc_entry
2142 & ((1 << 12) - 1)),
2143 plt_code);
2144 plt_code += 4;
2146 else
2148 if (entry->tlsdesc_entry >= -(1 << (16 - 1))
2149 && entry->tlsdesc_entry < (1 << (16 - 1)))
2151 /* setlos lo(tlsdesc_entry), gr8 */
2152 bfd_put_32 (output_bfd,
2153 0x90fc0000
2154 | (entry->tlsdesc_entry
2155 & (((bfd_vma)1 << 16) - 1)),
2156 plt_code);
2157 plt_code += 4;
2159 else
2161 /* sethi.p hi(tlsdesc_entry), gr8
2162 setlo lo(tlsdesc_entry), gr8 */
2163 bfd_put_32 (output_bfd,
2164 0x10f80000
2165 | ((entry->tlsdesc_entry >> 16)
2166 & (((bfd_vma)1 << 16) - 1)),
2167 plt_code);
2168 plt_code += 4;
2169 bfd_put_32 (output_bfd,
2170 0x90f40000
2171 | (entry->tlsdesc_entry
2172 & (((bfd_vma)1 << 16) - 1)),
2173 plt_code);
2174 plt_code += 4;
2176 /* ldd @(gr15,gr8),gr8 */
2177 bfd_put_32 (output_bfd, 0x9008f148, plt_code);
2178 plt_code += 4;
2180 /* jmpl @(gr8,gr0) */
2181 bfd_put_32 (output_bfd, 0x80308000, plt_code);
2185 return TRUE;
2188 /* Handle an FRV small data reloc. */
2190 static bfd_reloc_status_type
2191 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
2192 contents, value)
2193 struct bfd_link_info *info;
2194 bfd *input_bfd;
2195 asection *input_section;
2196 Elf_Internal_Rela *relocation;
2197 bfd_byte *contents;
2198 bfd_vma value;
2200 bfd_vma insn;
2201 bfd_vma gp;
2202 struct bfd_link_hash_entry *h;
2204 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2206 gp = (h->u.def.value
2207 + h->u.def.section->output_section->vma
2208 + h->u.def.section->output_offset);
2210 value -= input_section->output_section->vma;
2211 value -= (gp - input_section->output_section->vma);
2213 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2215 value += relocation->r_addend;
2217 if ((long) value > 0x7ff || (long) value < -0x800)
2218 return bfd_reloc_overflow;
2220 bfd_put_32 (input_bfd,
2221 (insn & 0xfffff000) | (value & 0xfff),
2222 contents + relocation->r_offset);
2224 return bfd_reloc_ok;
2227 /* Handle an FRV small data reloc. for the u12 field. */
2229 static bfd_reloc_status_type
2230 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
2231 contents, value)
2232 struct bfd_link_info *info;
2233 bfd *input_bfd;
2234 asection *input_section;
2235 Elf_Internal_Rela *relocation;
2236 bfd_byte *contents;
2237 bfd_vma value;
2239 bfd_vma insn;
2240 bfd_vma gp;
2241 struct bfd_link_hash_entry *h;
2242 bfd_vma mask;
2244 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2246 gp = (h->u.def.value
2247 + h->u.def.section->output_section->vma
2248 + h->u.def.section->output_offset);
2250 value -= input_section->output_section->vma;
2251 value -= (gp - input_section->output_section->vma);
2253 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2255 value += relocation->r_addend;
2257 if ((long) value > 0x7ff || (long) value < -0x800)
2258 return bfd_reloc_overflow;
2260 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2261 mask = 0x3f03f;
2262 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
2264 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2266 return bfd_reloc_ok;
2269 /* Handle an FRV ELF HI16 reloc. */
2271 static bfd_reloc_status_type
2272 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
2273 bfd *input_bfd;
2274 Elf_Internal_Rela *relhi;
2275 bfd_byte *contents;
2276 bfd_vma value;
2278 bfd_vma insn;
2280 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2282 value += relhi->r_addend;
2283 value = ((value >> 16) & 0xffff);
2285 insn = (insn & 0xffff0000) | value;
2287 if ((long) value > 0xffff || (long) value < -0x10000)
2288 return bfd_reloc_overflow;
2290 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
2291 return bfd_reloc_ok;
2294 static bfd_reloc_status_type
2295 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
2296 bfd *input_bfd;
2297 Elf_Internal_Rela *rello;
2298 bfd_byte *contents;
2299 bfd_vma value;
2301 bfd_vma insn;
2303 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2305 value += rello->r_addend;
2306 value = value & 0xffff;
2308 insn = (insn & 0xffff0000) | value;
2310 if ((long) value > 0xffff || (long) value < -0x10000)
2311 return bfd_reloc_overflow;
2313 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2314 return bfd_reloc_ok;
2317 /* Perform the relocation for the CALL label24 instruction. */
2319 static bfd_reloc_status_type
2320 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
2321 bfd *input_bfd;
2322 asection *input_section;
2323 Elf_Internal_Rela *rello;
2324 bfd_byte *contents;
2325 bfd_vma value;
2327 bfd_vma insn;
2328 bfd_vma label6;
2329 bfd_vma label18;
2331 /* The format for the call instruction is:
2333 0 000000 0001111 000000000000000000
2334 label6 opcode label18
2336 The branch calculation is: pc + (4*label24)
2337 where label24 is the concatenation of label6 and label18. */
2339 /* Grab the instruction. */
2340 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2342 value -= input_section->output_section->vma + input_section->output_offset;
2343 value -= rello->r_offset;
2344 value += rello->r_addend;
2346 value = value >> 2;
2348 label6 = value & 0xfc0000;
2349 label6 = label6 << 7;
2351 label18 = value & 0x3ffff;
2353 insn = insn & 0x803c0000;
2354 insn = insn | label6;
2355 insn = insn | label18;
2357 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2359 return bfd_reloc_ok;
2362 static bfd_reloc_status_type
2363 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
2364 contents, value)
2365 struct bfd_link_info *info;
2366 bfd *input_bfd;
2367 asection *input_section;
2368 Elf_Internal_Rela *relocation;
2369 bfd_byte *contents;
2370 bfd_vma value;
2372 bfd_vma insn;
2373 bfd_vma gp;
2374 struct bfd_link_hash_entry *h;
2376 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2378 gp = (h->u.def.value
2379 + h->u.def.section->output_section->vma
2380 + h->u.def.section->output_offset);
2382 value -= input_section->output_section->vma;
2383 value -= (gp - input_section->output_section->vma);
2384 value += relocation->r_addend;
2385 value = ((value >> 16) & 0xffff);
2387 if ((long) value > 0xffff || (long) value < -0x10000)
2388 return bfd_reloc_overflow;
2390 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2391 insn = (insn & 0xffff0000) | value;
2393 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2394 return bfd_reloc_ok;
2397 static bfd_reloc_status_type
2398 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
2399 contents, value)
2400 struct bfd_link_info *info;
2401 bfd *input_bfd;
2402 asection *input_section;
2403 Elf_Internal_Rela *relocation;
2404 bfd_byte *contents;
2405 bfd_vma value;
2407 bfd_vma insn;
2408 bfd_vma gp;
2409 struct bfd_link_hash_entry *h;
2411 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2413 gp = (h->u.def.value
2414 + h->u.def.section->output_section->vma
2415 + h->u.def.section->output_offset);
2417 value -= input_section->output_section->vma;
2418 value -= (gp - input_section->output_section->vma);
2419 value += relocation->r_addend;
2420 value = value & 0xffff;
2422 if ((long) value > 0xffff || (long) value < -0x10000)
2423 return bfd_reloc_overflow;
2425 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2426 insn = (insn & 0xffff0000) | value;
2428 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2430 return bfd_reloc_ok;
2433 static reloc_howto_type *
2434 frv_reloc_type_lookup (abfd, code)
2435 bfd *abfd ATTRIBUTE_UNUSED;
2436 bfd_reloc_code_real_type code;
2438 switch (code)
2440 default:
2441 break;
2443 case BFD_RELOC_NONE:
2444 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
2446 case BFD_RELOC_32:
2447 if (elf_elfheader (abfd)->e_type == ET_EXEC
2448 || elf_elfheader (abfd)->e_type == ET_DYN)
2449 return &elf32_frv_rel_32_howto;
2450 /* Fall through. */
2451 case BFD_RELOC_CTOR:
2452 return &elf32_frv_howto_table[ (int) R_FRV_32];
2454 case BFD_RELOC_FRV_LABEL16:
2455 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
2457 case BFD_RELOC_FRV_LABEL24:
2458 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
2460 case BFD_RELOC_FRV_LO16:
2461 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
2463 case BFD_RELOC_FRV_HI16:
2464 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
2466 case BFD_RELOC_FRV_GPREL12:
2467 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
2469 case BFD_RELOC_FRV_GPRELU12:
2470 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
2472 case BFD_RELOC_FRV_GPREL32:
2473 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
2475 case BFD_RELOC_FRV_GPRELHI:
2476 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
2478 case BFD_RELOC_FRV_GPRELLO:
2479 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
2481 case BFD_RELOC_FRV_GOT12:
2482 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
2484 case BFD_RELOC_FRV_GOTHI:
2485 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
2487 case BFD_RELOC_FRV_GOTLO:
2488 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
2490 case BFD_RELOC_FRV_FUNCDESC:
2491 if (elf_elfheader (abfd)->e_type == ET_EXEC
2492 || elf_elfheader (abfd)->e_type == ET_DYN)
2493 return &elf32_frv_rel_funcdesc_howto;
2494 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
2496 case BFD_RELOC_FRV_FUNCDESC_GOT12:
2497 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
2499 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
2500 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
2502 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
2503 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
2505 case BFD_RELOC_FRV_FUNCDESC_VALUE:
2506 if (elf_elfheader (abfd)->e_type == ET_EXEC
2507 || elf_elfheader (abfd)->e_type == ET_DYN)
2508 return &elf32_frv_rel_funcdesc_value_howto;
2509 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
2511 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
2512 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
2514 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
2515 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
2517 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
2518 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
2520 case BFD_RELOC_FRV_GOTOFF12:
2521 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
2523 case BFD_RELOC_FRV_GOTOFFHI:
2524 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
2526 case BFD_RELOC_FRV_GOTOFFLO:
2527 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
2529 case BFD_RELOC_FRV_GETTLSOFF:
2530 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
2532 case BFD_RELOC_FRV_TLSDESC_VALUE:
2533 if (elf_elfheader (abfd)->e_type == ET_EXEC
2534 || elf_elfheader (abfd)->e_type == ET_DYN)
2535 return &elf32_frv_rel_tlsdesc_value_howto;
2536 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
2538 case BFD_RELOC_FRV_GOTTLSDESC12:
2539 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
2541 case BFD_RELOC_FRV_GOTTLSDESCHI:
2542 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
2544 case BFD_RELOC_FRV_GOTTLSDESCLO:
2545 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
2547 case BFD_RELOC_FRV_TLSMOFF12:
2548 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
2550 case BFD_RELOC_FRV_TLSMOFFHI:
2551 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
2553 case BFD_RELOC_FRV_TLSMOFFLO:
2554 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
2556 case BFD_RELOC_FRV_GOTTLSOFF12:
2557 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
2559 case BFD_RELOC_FRV_GOTTLSOFFHI:
2560 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
2562 case BFD_RELOC_FRV_GOTTLSOFFLO:
2563 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
2565 case BFD_RELOC_FRV_TLSOFF:
2566 if (elf_elfheader (abfd)->e_type == ET_EXEC
2567 || elf_elfheader (abfd)->e_type == ET_DYN)
2568 return &elf32_frv_rel_tlsoff_howto;
2569 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
2571 case BFD_RELOC_FRV_TLSDESC_RELAX:
2572 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
2574 case BFD_RELOC_FRV_GETTLSOFF_RELAX:
2575 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
2577 case BFD_RELOC_FRV_TLSOFF_RELAX:
2578 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
2580 case BFD_RELOC_FRV_TLSMOFF:
2581 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
2583 case BFD_RELOC_VTABLE_INHERIT:
2584 return &elf32_frv_vtinherit_howto;
2586 case BFD_RELOC_VTABLE_ENTRY:
2587 return &elf32_frv_vtentry_howto;
2590 return NULL;
2593 static reloc_howto_type *
2594 frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
2596 unsigned int i;
2598 for (i = 0;
2599 i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]);
2600 i++)
2601 if (elf32_frv_howto_table[i].name != NULL
2602 && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0)
2603 return &elf32_frv_howto_table[i];
2605 if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0)
2606 return &elf32_frv_vtinherit_howto;
2607 if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0)
2608 return &elf32_frv_vtentry_howto;
2610 return NULL;
2613 /* Set the howto pointer for an FRV ELF reloc. */
2615 static void
2616 frv_info_to_howto_rela (abfd, cache_ptr, dst)
2617 bfd *abfd ATTRIBUTE_UNUSED;
2618 arelent *cache_ptr;
2619 Elf_Internal_Rela *dst;
2621 unsigned int r_type;
2623 r_type = ELF32_R_TYPE (dst->r_info);
2624 switch (r_type)
2626 case R_FRV_GNU_VTINHERIT:
2627 cache_ptr->howto = &elf32_frv_vtinherit_howto;
2628 break;
2630 case R_FRV_GNU_VTENTRY:
2631 cache_ptr->howto = &elf32_frv_vtentry_howto;
2632 break;
2634 default:
2635 cache_ptr->howto = & elf32_frv_howto_table [r_type];
2636 break;
2640 /* Set the howto pointer for an FRV ELF REL reloc. */
2641 static void
2642 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
2643 arelent *cache_ptr, Elf_Internal_Rela *dst)
2645 unsigned int r_type;
2647 r_type = ELF32_R_TYPE (dst->r_info);
2648 switch (r_type)
2650 case R_FRV_32:
2651 cache_ptr->howto = &elf32_frv_rel_32_howto;
2652 break;
2654 case R_FRV_FUNCDESC:
2655 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
2656 break;
2658 case R_FRV_FUNCDESC_VALUE:
2659 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
2660 break;
2662 case R_FRV_TLSDESC_VALUE:
2663 cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
2664 break;
2666 case R_FRV_TLSOFF:
2667 cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
2668 break;
2670 default:
2671 cache_ptr->howto = NULL;
2672 break;
2676 /* Perform a single relocation. By default we use the standard BFD
2677 routines, but a few relocs, we have to do them ourselves. */
2679 static bfd_reloc_status_type
2680 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
2681 relocation)
2682 reloc_howto_type *howto;
2683 bfd *input_bfd;
2684 asection *input_section;
2685 bfd_byte *contents;
2686 Elf_Internal_Rela *rel;
2687 bfd_vma relocation;
2689 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2690 contents, rel->r_offset, relocation,
2691 rel->r_addend);
2695 /* Relocate an FRV ELF section.
2697 The RELOCATE_SECTION function is called by the new ELF backend linker
2698 to handle the relocations for a section.
2700 The relocs are always passed as Rela structures; if the section
2701 actually uses Rel structures, the r_addend field will always be
2702 zero.
2704 This function is responsible for adjusting the section contents as
2705 necessary, and (if using Rela relocs and generating a relocatable
2706 output file) adjusting the reloc addend as necessary.
2708 This function does not have to worry about setting the reloc
2709 address or the reloc symbol index.
2711 LOCAL_SYMS is a pointer to the swapped in local symbols.
2713 LOCAL_SECTIONS is an array giving the section in the input file
2714 corresponding to the st_shndx field of each local symbol.
2716 The global hash table entry for the global symbols can be found
2717 via elf_sym_hashes (input_bfd).
2719 When generating relocatable output, this function must handle
2720 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2721 going to be the section symbol corresponding to the output
2722 section, which means that the addend must be adjusted
2723 accordingly. */
2725 static bfd_boolean
2726 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
2727 contents, relocs, local_syms, local_sections)
2728 bfd *output_bfd ATTRIBUTE_UNUSED;
2729 struct bfd_link_info *info;
2730 bfd *input_bfd;
2731 asection *input_section;
2732 bfd_byte *contents;
2733 Elf_Internal_Rela *relocs;
2734 Elf_Internal_Sym *local_syms;
2735 asection **local_sections;
2737 Elf_Internal_Shdr *symtab_hdr;
2738 struct elf_link_hash_entry **sym_hashes;
2739 Elf_Internal_Rela *rel;
2740 Elf_Internal_Rela *relend;
2741 unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
2742 check_segment[2];
2743 int silence_segment_error = !(info->shared || info->pie);
2744 unsigned long insn;
2746 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2747 sym_hashes = elf_sym_hashes (input_bfd);
2748 relend = relocs + input_section->reloc_count;
2750 isec_segment = _frvfdpic_osec_to_segment (output_bfd,
2751 input_section->output_section);
2752 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
2753 got_segment = _frvfdpic_osec_to_segment (output_bfd,
2754 frvfdpic_got_section (info)
2755 ->output_section);
2756 else
2757 got_segment = -1;
2758 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
2759 gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
2760 frvfdpic_gotfixup_section (info)
2761 ->output_section);
2762 else
2763 gprel_segment = -1;
2764 if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
2765 plt_segment = _frvfdpic_osec_to_segment (output_bfd,
2766 frvfdpic_plt_section (info)
2767 ->output_section);
2768 else
2769 plt_segment = -1;
2770 if (elf_hash_table (info)->tls_sec)
2771 tls_segment = _frvfdpic_osec_to_segment (output_bfd,
2772 elf_hash_table (info)->tls_sec);
2773 else
2774 tls_segment = -1;
2776 for (rel = relocs; rel < relend; rel ++)
2778 reloc_howto_type *howto;
2779 unsigned long r_symndx;
2780 Elf_Internal_Sym *sym;
2781 asection *sec;
2782 struct elf_link_hash_entry *h;
2783 bfd_vma relocation;
2784 bfd_reloc_status_type r;
2785 const char * name = NULL;
2786 int r_type;
2787 asection *osec;
2788 struct frvfdpic_relocs_info *picrel;
2789 bfd_vma orig_addend = rel->r_addend;
2791 r_type = ELF32_R_TYPE (rel->r_info);
2793 if ( r_type == R_FRV_GNU_VTINHERIT
2794 || r_type == R_FRV_GNU_VTENTRY)
2795 continue;
2797 r_symndx = ELF32_R_SYM (rel->r_info);
2798 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
2799 h = NULL;
2800 sym = NULL;
2801 sec = NULL;
2803 if (r_symndx < symtab_hdr->sh_info)
2805 sym = local_syms + r_symndx;
2806 osec = sec = local_sections [r_symndx];
2807 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2809 name = bfd_elf_string_from_elf_section
2810 (input_bfd, symtab_hdr->sh_link, sym->st_name);
2811 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
2813 else
2815 bfd_boolean warned;
2816 bfd_boolean unresolved_reloc;
2818 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2819 r_symndx, symtab_hdr, sym_hashes,
2820 h, sec, relocation,
2821 unresolved_reloc, warned);
2822 osec = sec;
2825 if (sec != NULL && elf_discarded_section (sec))
2827 /* For relocs against symbols from removed linkonce sections,
2828 or sections discarded by a linker script, we just want the
2829 section contents zeroed. Avoid any special processing. */
2830 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2831 rel->r_info = 0;
2832 rel->r_addend = 0;
2833 continue;
2836 if (info->relocatable)
2837 continue;
2839 if (r_type != R_FRV_TLSMOFF
2840 && h != NULL
2841 && (h->root.type == bfd_link_hash_defined
2842 || h->root.type == bfd_link_hash_defweak)
2843 && !FRVFDPIC_SYM_LOCAL (info, h))
2845 osec = sec = NULL;
2846 relocation = 0;
2849 switch (r_type)
2851 case R_FRV_LABEL24:
2852 case R_FRV_32:
2853 if (! IS_FDPIC (output_bfd))
2854 goto non_fdpic;
2856 case R_FRV_GOT12:
2857 case R_FRV_GOTHI:
2858 case R_FRV_GOTLO:
2859 case R_FRV_FUNCDESC_GOT12:
2860 case R_FRV_FUNCDESC_GOTHI:
2861 case R_FRV_FUNCDESC_GOTLO:
2862 case R_FRV_GOTOFF12:
2863 case R_FRV_GOTOFFHI:
2864 case R_FRV_GOTOFFLO:
2865 case R_FRV_FUNCDESC_GOTOFF12:
2866 case R_FRV_FUNCDESC_GOTOFFHI:
2867 case R_FRV_FUNCDESC_GOTOFFLO:
2868 case R_FRV_FUNCDESC:
2869 case R_FRV_FUNCDESC_VALUE:
2870 case R_FRV_GETTLSOFF:
2871 case R_FRV_TLSDESC_VALUE:
2872 case R_FRV_GOTTLSDESC12:
2873 case R_FRV_GOTTLSDESCHI:
2874 case R_FRV_GOTTLSDESCLO:
2875 case R_FRV_TLSMOFF12:
2876 case R_FRV_TLSMOFFHI:
2877 case R_FRV_TLSMOFFLO:
2878 case R_FRV_GOTTLSOFF12:
2879 case R_FRV_GOTTLSOFFHI:
2880 case R_FRV_GOTTLSOFFLO:
2881 case R_FRV_TLSOFF:
2882 case R_FRV_TLSDESC_RELAX:
2883 case R_FRV_GETTLSOFF_RELAX:
2884 case R_FRV_TLSOFF_RELAX:
2885 case R_FRV_TLSMOFF:
2886 if (h != NULL)
2887 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2888 (info), input_bfd, h,
2889 orig_addend, INSERT);
2890 else
2891 /* In order to find the entry we created before, we must
2892 use the original addend, not the one that may have been
2893 modified by _bfd_elf_rela_local_sym(). */
2894 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2895 (info), input_bfd, r_symndx,
2896 orig_addend, INSERT);
2897 if (! picrel)
2898 return FALSE;
2900 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2901 osec, sym,
2902 rel->r_addend))
2904 (*_bfd_error_handler)
2905 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2906 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
2907 return FALSE;
2910 break;
2912 default:
2913 non_fdpic:
2914 picrel = NULL;
2915 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
2917 info->callbacks->warning
2918 (info, _("relocation references symbol not defined in the module"),
2919 name, input_bfd, input_section, rel->r_offset);
2920 return FALSE;
2922 break;
2925 switch (r_type)
2927 case R_FRV_GETTLSOFF:
2928 case R_FRV_TLSDESC_VALUE:
2929 case R_FRV_GOTTLSDESC12:
2930 case R_FRV_GOTTLSDESCHI:
2931 case R_FRV_GOTTLSDESCLO:
2932 case R_FRV_TLSMOFF12:
2933 case R_FRV_TLSMOFFHI:
2934 case R_FRV_TLSMOFFLO:
2935 case R_FRV_GOTTLSOFF12:
2936 case R_FRV_GOTTLSOFFHI:
2937 case R_FRV_GOTTLSOFFLO:
2938 case R_FRV_TLSOFF:
2939 case R_FRV_TLSDESC_RELAX:
2940 case R_FRV_GETTLSOFF_RELAX:
2941 case R_FRV_TLSOFF_RELAX:
2942 case R_FRV_TLSMOFF:
2943 if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
2944 relocation += tls_biased_base (info);
2945 break;
2947 default:
2948 break;
2951 /* Try to apply TLS relaxations. */
2952 if (1)
2953 switch (r_type)
2956 #define LOCAL_EXEC_P(info, picrel) \
2957 ((info)->executable \
2958 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2959 #define INITIAL_EXEC_P(info, picrel) \
2960 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2961 && (picrel)->tlsoff_entry)
2963 #define IN_RANGE_FOR_OFST12_P(value) \
2964 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2965 #define IN_RANGE_FOR_SETLOS_P(value) \
2966 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2967 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2968 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2970 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2971 (LOCAL_EXEC_P ((info), (picrel)) \
2972 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2973 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2974 (INITIAL_EXEC_P ((info), (picrel)) \
2975 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2977 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2978 (LOCAL_EXEC_P ((info), (picrel)))
2979 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2980 (INITIAL_EXEC_P ((info), (picrel)))
2982 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2983 (LOCAL_EXEC_P ((info), (picrel)) \
2984 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2986 case R_FRV_GETTLSOFF:
2987 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2989 /* Is this a call instruction? */
2990 if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
2992 r = info->callbacks->warning
2993 (info,
2994 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2995 name, input_bfd, input_section, rel->r_offset);
2996 return FALSE;
2999 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
3000 relocation + rel->r_addend))
3002 /* Replace the call instruction (except the packing bit)
3003 with setlos #tlsmofflo(symbol+offset), gr9. */
3004 insn &= (unsigned long)0x80000000;
3005 insn |= (unsigned long)0x12fc0000;
3006 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3008 r_type = R_FRV_TLSMOFFLO;
3009 howto = elf32_frv_howto_table + r_type;
3010 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3013 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
3015 /* Replace the call instruction (except the packing bit)
3016 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3017 insn &= (unsigned long)0x80000000;
3018 insn |= (unsigned long)0x12c8f000;
3019 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3021 r_type = R_FRV_GOTTLSOFF12;
3022 howto = elf32_frv_howto_table + r_type;
3023 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3026 break;
3028 case R_FRV_GOTTLSDESC12:
3029 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3031 /* Is this an lddi instruction? */
3032 if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
3034 r = info->callbacks->warning
3035 (info,
3036 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3037 name, input_bfd, input_section, rel->r_offset);
3038 return FALSE;
3041 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3042 relocation + rel->r_addend)
3043 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3044 info))
3046 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3047 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3048 Preserve the packing bit. */
3049 insn = (insn & (unsigned long)0x80000000)
3050 | ((insn + (unsigned long)0x02000000)
3051 & (unsigned long)0x7e000000);
3052 insn |= (unsigned long)0x00fc0000;
3053 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3055 r_type = R_FRV_TLSMOFFLO;
3056 howto = elf32_frv_howto_table + r_type;
3057 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3060 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3061 relocation + rel->r_addend))
3063 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3064 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3065 Preserve the packing bit. */
3066 insn = (insn & (unsigned long)0x80000000)
3067 | ((insn + (unsigned long)0x02000000)
3068 & (unsigned long)0x7e000000);
3069 insn |= (unsigned long)0x00f80000;
3070 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3072 r_type = R_FRV_TLSMOFFHI;
3073 howto = elf32_frv_howto_table + r_type;
3074 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3077 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3079 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3080 with ldi @(grB, #gottlsoff12(symbol+offset),
3081 gr<C+1>. Preserve the packing bit. If gottlsoff12
3082 overflows, we'll error out, but that's sort-of ok,
3083 since we'd started with gottlsdesc12, that's actually
3084 more demanding. Compiling with -fPIE instead of
3085 -fpie would fix it; linking with --relax should fix
3086 it as well. */
3087 insn = (insn & (unsigned long)0x80cbf000)
3088 | ((insn + (unsigned long)0x02000000)
3089 & (unsigned long)0x7e000000);
3090 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3092 r_type = R_FRV_GOTTLSOFF12;
3093 howto = elf32_frv_howto_table + r_type;
3094 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3097 break;
3099 case R_FRV_GOTTLSDESCHI:
3100 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3102 /* Is this a sethi instruction? */
3103 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3105 r = info->callbacks->warning
3106 (info,
3107 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3108 name, input_bfd, input_section, rel->r_offset);
3109 return FALSE;
3112 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3113 relocation + rel->r_addend)
3114 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3115 && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
3117 /* Replace sethi with a nop. Preserve the packing bit. */
3118 insn &= (unsigned long)0x80000000;
3119 insn |= (unsigned long)0x00880000;
3120 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3122 /* Nothing to relocate. */
3123 continue;
3126 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3128 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3129 r_type = R_FRV_GOTTLSOFFHI;
3130 howto = elf32_frv_howto_table + r_type;
3131 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3134 break;
3136 case R_FRV_GOTTLSDESCLO:
3137 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3139 /* Is this a setlo or setlos instruction? */
3140 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3142 r = info->callbacks->warning
3143 (info,
3144 _("R_FRV_GOTTLSDESCLO"
3145 " not applied to a setlo or setlos instruction"),
3146 name, input_bfd, input_section, rel->r_offset);
3147 return FALSE;
3150 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3151 relocation + rel->r_addend)
3152 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3153 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3155 /* Replace setlo/setlos with a nop. Preserve the
3156 packing bit. */
3157 insn &= (unsigned long)0x80000000;
3158 insn |= (unsigned long)0x00880000;
3159 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3161 /* Nothing to relocate. */
3162 continue;
3165 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3167 /* If the corresponding sethi (if it exists) decayed
3168 to a nop, make sure this becomes (or already is) a
3169 setlos, not setlo. */
3170 if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
3172 insn |= (unsigned long)0x00080000;
3173 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3176 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3177 r_type = R_FRV_GOTTLSOFFLO;
3178 howto = elf32_frv_howto_table + r_type;
3179 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3182 break;
3184 case R_FRV_TLSDESC_RELAX:
3185 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3187 /* Is this an ldd instruction? */
3188 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
3190 r = info->callbacks->warning
3191 (info,
3192 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3193 name, input_bfd, input_section, rel->r_offset);
3194 return FALSE;
3197 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3198 relocation + rel->r_addend)
3199 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3200 info))
3202 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3203 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3204 Preserve the packing bit. */
3205 insn = (insn & (unsigned long)0x80000000)
3206 | ((insn + (unsigned long)0x02000000)
3207 & (unsigned long)0x7e000000);
3208 insn |= (unsigned long)0x00fc0000;
3209 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3211 r_type = R_FRV_TLSMOFFLO;
3212 howto = elf32_frv_howto_table + r_type;
3213 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3216 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3217 relocation + rel->r_addend))
3219 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3220 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3221 Preserve the packing bit. */
3222 insn = (insn & (unsigned long)0x80000000)
3223 | ((insn + (unsigned long)0x02000000)
3224 & (unsigned long)0x7e000000);
3225 insn |= (unsigned long)0x00f80000;
3226 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3228 r_type = R_FRV_TLSMOFFHI;
3229 howto = elf32_frv_howto_table + r_type;
3230 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3233 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3234 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3236 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3237 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3238 Preserve the packing bit. */
3239 insn = (insn & (unsigned long)0x8003f000)
3240 | (unsigned long)0x00c80000
3241 | ((insn + (unsigned long)0x02000000)
3242 & (unsigned long)0x7e000000);
3243 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3245 r_type = R_FRV_GOTTLSOFF12;
3246 howto = elf32_frv_howto_table + r_type;
3247 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3250 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3252 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3253 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3254 Preserve the packing bit. */
3255 insn = (insn & (unsigned long)0x81ffffbf)
3256 | ((insn + (unsigned long)0x02000000)
3257 & (unsigned long)0x7e000000);
3258 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3260 /* #tlsoff(symbol+offset) is just a relaxation
3261 annotation, so there's nothing left to
3262 relocate. */
3263 continue;
3266 break;
3268 case R_FRV_GETTLSOFF_RELAX:
3269 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3271 /* Is this a calll or callil instruction? */
3272 if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
3274 r = info->callbacks->warning
3275 (info,
3276 _("R_FRV_GETTLSOFF_RELAX"
3277 " not applied to a calll instruction"),
3278 name, input_bfd, input_section, rel->r_offset);
3279 return FALSE;
3282 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3283 relocation + rel->r_addend)
3284 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3285 info))
3287 /* Replace calll with a nop. Preserve the packing bit. */
3288 insn &= (unsigned long)0x80000000;
3289 insn |= (unsigned long)0x00880000;
3290 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3292 /* Nothing to relocate. */
3293 continue;
3296 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3297 relocation + rel->r_addend))
3299 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3300 Preserve the packing bit. */
3301 insn &= (unsigned long)0x80000000;
3302 insn |= (unsigned long)0x12f40000;
3303 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3305 r_type = R_FRV_TLSMOFFLO;
3306 howto = elf32_frv_howto_table + r_type;
3307 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3310 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3312 /* Replace calll with a nop. Preserve the packing bit. */
3313 insn &= (unsigned long)0x80000000;
3314 insn |= (unsigned long)0x00880000;
3315 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3317 /* Nothing to relocate. */
3318 continue;
3321 break;
3323 case R_FRV_GOTTLSOFF12:
3324 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3326 /* Is this an ldi instruction? */
3327 if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
3329 r = info->callbacks->warning
3330 (info,
3331 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3332 name, input_bfd, input_section, rel->r_offset);
3333 return FALSE;
3336 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3337 relocation + rel->r_addend))
3339 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3340 with setlos #tlsmofflo(symbol+offset), grC.
3341 Preserve the packing bit. */
3342 insn &= (unsigned long)0xfe000000;
3343 insn |= (unsigned long)0x00fc0000;
3344 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3346 r_type = R_FRV_TLSMOFFLO;
3347 howto = elf32_frv_howto_table + r_type;
3348 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3351 break;
3353 case R_FRV_GOTTLSOFFHI:
3354 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3356 /* Is this a sethi instruction? */
3357 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3359 r = info->callbacks->warning
3360 (info,
3361 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3362 name, input_bfd, input_section, rel->r_offset);
3363 return FALSE;
3366 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3367 relocation + rel->r_addend)
3368 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3369 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3371 /* Replace sethi with a nop. Preserve the packing bit. */
3372 insn &= (unsigned long)0x80000000;
3373 insn |= (unsigned long)0x00880000;
3374 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3376 /* Nothing to relocate. */
3377 continue;
3380 break;
3382 case R_FRV_GOTTLSOFFLO:
3383 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3385 /* Is this a setlo or setlos instruction? */
3386 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3388 r = info->callbacks->warning
3389 (info,
3390 _("R_FRV_GOTTLSOFFLO"
3391 " not applied to a setlo or setlos instruction"),
3392 name, input_bfd, input_section, rel->r_offset);
3393 return FALSE;
3396 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3397 relocation + rel->r_addend)
3398 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3399 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3401 /* Replace setlo/setlos with a nop. Preserve the
3402 packing bit. */
3403 insn &= (unsigned long)0x80000000;
3404 insn |= (unsigned long)0x00880000;
3405 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3407 /* Nothing to relocate. */
3408 continue;
3411 break;
3413 case R_FRV_TLSOFF_RELAX:
3414 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3416 /* Is this an ld instruction? */
3417 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
3419 r = info->callbacks->warning
3420 (info,
3421 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3422 name, input_bfd, input_section, rel->r_offset);
3423 return FALSE;
3426 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3427 relocation + rel->r_addend))
3429 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3430 with setlos #tlsmofflo(symbol+offset), grC.
3431 Preserve the packing bit. */
3432 insn &= (unsigned long)0xfe000000;
3433 insn |= (unsigned long)0x00fc0000;
3434 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3436 r_type = R_FRV_TLSMOFFLO;
3437 howto = elf32_frv_howto_table + r_type;
3438 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3441 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3442 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3444 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3445 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3446 Preserve the packing bit. */
3447 insn = (insn & (unsigned long)0xfe03f000)
3448 | (unsigned long)0x00c80000;;
3449 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3451 r_type = R_FRV_GOTTLSOFF12;
3452 howto = elf32_frv_howto_table + r_type;
3453 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3456 break;
3458 case R_FRV_TLSMOFFHI:
3459 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3461 /* Is this a sethi instruction? */
3462 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3464 r = info->callbacks->warning
3465 (info,
3466 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3467 name, input_bfd, input_section, rel->r_offset);
3468 return FALSE;
3471 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3472 info))
3474 /* Replace sethi with a nop. Preserve the packing bit. */
3475 insn &= (unsigned long)0x80000000;
3476 insn |= (unsigned long)0x00880000;
3477 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3479 /* Nothing to relocate. */
3480 continue;
3483 break;
3485 case R_FRV_TLSMOFFLO:
3486 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3488 /* Is this a setlo or setlos instruction? */
3489 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3491 r = info->callbacks->warning
3492 (info,
3493 _("R_FRV_TLSMOFFLO"
3494 " not applied to a setlo or setlos instruction"),
3495 name, input_bfd, input_section, rel->r_offset);
3496 return FALSE;
3499 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3500 info))
3501 /* If the corresponding sethi (if it exists) decayed
3502 to a nop, make sure this becomes (or already is) a
3503 setlos, not setlo. */
3505 insn |= (unsigned long)0x00080000;
3506 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3509 break;
3512 There's nothing to relax in these:
3513 R_FRV_TLSDESC_VALUE
3514 R_FRV_TLSOFF
3515 R_FRV_TLSMOFF12
3516 R_FRV_TLSMOFFHI
3517 R_FRV_TLSMOFFLO
3518 R_FRV_TLSMOFF
3521 default:
3522 break;
3525 switch (r_type)
3527 case R_FRV_LABEL24:
3528 check_segment[0] = isec_segment;
3529 if (! IS_FDPIC (output_bfd))
3530 check_segment[1] = isec_segment;
3531 else if (picrel->plt)
3533 relocation = frvfdpic_plt_section (info)->output_section->vma
3534 + frvfdpic_plt_section (info)->output_offset
3535 + picrel->plt_entry;
3536 check_segment[1] = plt_segment;
3538 /* We don't want to warn on calls to undefined weak symbols,
3539 as calls to them must be protected by non-NULL tests
3540 anyway, and unprotected calls would invoke undefined
3541 behavior. */
3542 else if (picrel->symndx == -1
3543 && picrel->d.h->root.type == bfd_link_hash_undefweak)
3544 check_segment[1] = check_segment[0];
3545 else
3546 check_segment[1] = sec
3547 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3548 : (unsigned)-1;
3549 break;
3551 case R_FRV_GOT12:
3552 case R_FRV_GOTHI:
3553 case R_FRV_GOTLO:
3554 relocation = picrel->got_entry;
3555 check_segment[0] = check_segment[1] = got_segment;
3556 break;
3558 case R_FRV_FUNCDESC_GOT12:
3559 case R_FRV_FUNCDESC_GOTHI:
3560 case R_FRV_FUNCDESC_GOTLO:
3561 relocation = picrel->fdgot_entry;
3562 check_segment[0] = check_segment[1] = got_segment;
3563 break;
3565 case R_FRV_GOTOFFHI:
3566 case R_FRV_GOTOFF12:
3567 case R_FRV_GOTOFFLO:
3568 relocation -= frvfdpic_got_section (info)->output_section->vma
3569 + frvfdpic_got_section (info)->output_offset
3570 + frvfdpic_got_initial_offset (info);
3571 check_segment[0] = got_segment;
3572 check_segment[1] = sec
3573 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3574 : (unsigned)-1;
3575 break;
3577 case R_FRV_FUNCDESC_GOTOFF12:
3578 case R_FRV_FUNCDESC_GOTOFFHI:
3579 case R_FRV_FUNCDESC_GOTOFFLO:
3580 relocation = picrel->fd_entry;
3581 check_segment[0] = check_segment[1] = got_segment;
3582 break;
3584 case R_FRV_FUNCDESC:
3586 int dynindx;
3587 bfd_vma addend = rel->r_addend;
3589 if (! (h && h->root.type == bfd_link_hash_undefweak
3590 && FRVFDPIC_SYM_LOCAL (info, h)))
3592 /* If the symbol is dynamic and there may be dynamic
3593 symbol resolution because we are or are linked with a
3594 shared library, emit a FUNCDESC relocation such that
3595 the dynamic linker will allocate the function
3596 descriptor. If the symbol needs a non-local function
3597 descriptor but binds locally (e.g., its visibility is
3598 protected, emit a dynamic relocation decayed to
3599 section+offset. */
3600 if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
3601 && FRVFDPIC_SYM_LOCAL (info, h)
3602 && !(info->executable && !info->pie))
3604 dynindx = elf_section_data (h->root.u.def.section
3605 ->output_section)->dynindx;
3606 addend += h->root.u.def.section->output_offset
3607 + h->root.u.def.value;
3609 else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
3611 if (addend)
3613 info->callbacks->warning
3614 (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
3615 name, input_bfd, input_section, rel->r_offset);
3616 return FALSE;
3618 dynindx = h->dynindx;
3620 else
3622 /* Otherwise, we know we have a private function
3623 descriptor, so reference it directly. */
3624 BFD_ASSERT (picrel->privfd);
3625 r_type = R_FRV_32;
3626 dynindx = elf_section_data (frvfdpic_got_section (info)
3627 ->output_section)->dynindx;
3628 addend = frvfdpic_got_section (info)->output_offset
3629 + frvfdpic_got_initial_offset (info)
3630 + picrel->fd_entry;
3633 /* If there is room for dynamic symbol resolution, emit
3634 the dynamic relocation. However, if we're linking an
3635 executable at a fixed location, we won't have emitted a
3636 dynamic symbol entry for the got section, so idx will
3637 be zero, which means we can and should compute the
3638 address of the private descriptor ourselves. */
3639 if (info->executable && !info->pie
3640 && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
3642 addend += frvfdpic_got_section (info)->output_section->vma;
3643 if ((bfd_get_section_flags (output_bfd,
3644 input_section->output_section)
3645 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3647 if (_frvfdpic_osec_readonly_p (output_bfd,
3648 input_section
3649 ->output_section))
3651 info->callbacks->warning
3652 (info,
3653 _("cannot emit fixups in read-only section"),
3654 name, input_bfd, input_section, rel->r_offset);
3655 return FALSE;
3657 _frvfdpic_add_rofixup (output_bfd,
3658 frvfdpic_gotfixup_section
3659 (info),
3660 _bfd_elf_section_offset
3661 (output_bfd, info,
3662 input_section, rel->r_offset)
3663 + input_section
3664 ->output_section->vma
3665 + input_section->output_offset,
3666 picrel);
3669 else if ((bfd_get_section_flags (output_bfd,
3670 input_section->output_section)
3671 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3673 if (_frvfdpic_osec_readonly_p (output_bfd,
3674 input_section
3675 ->output_section))
3677 info->callbacks->warning
3678 (info,
3679 _("cannot emit dynamic relocations in read-only section"),
3680 name, input_bfd, input_section, rel->r_offset);
3681 return FALSE;
3683 _frvfdpic_add_dyn_reloc (output_bfd,
3684 frvfdpic_gotrel_section (info),
3685 _bfd_elf_section_offset
3686 (output_bfd, info,
3687 input_section, rel->r_offset)
3688 + input_section
3689 ->output_section->vma
3690 + input_section->output_offset,
3691 r_type, dynindx, addend, picrel);
3693 else
3694 addend += frvfdpic_got_section (info)->output_section->vma;
3697 /* We want the addend in-place because dynamic
3698 relocations are REL. Setting relocation to it should
3699 arrange for it to be installed. */
3700 relocation = addend - rel->r_addend;
3702 check_segment[0] = check_segment[1] = got_segment;
3703 break;
3705 case R_FRV_32:
3706 if (! IS_FDPIC (output_bfd))
3708 check_segment[0] = check_segment[1] = -1;
3709 break;
3711 /* Fall through. */
3712 case R_FRV_FUNCDESC_VALUE:
3714 int dynindx;
3715 bfd_vma addend = rel->r_addend;
3717 /* If the symbol is dynamic but binds locally, use
3718 section+offset. */
3719 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
3721 if (addend && r_type == R_FRV_FUNCDESC_VALUE)
3723 info->callbacks->warning
3724 (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
3725 name, input_bfd, input_section, rel->r_offset);
3726 return FALSE;
3728 dynindx = h->dynindx;
3730 else
3732 if (h)
3733 addend += h->root.u.def.value;
3734 else
3735 addend += sym->st_value;
3736 if (osec)
3737 addend += osec->output_offset;
3738 if (osec && osec->output_section
3739 && ! bfd_is_abs_section (osec->output_section)
3740 && ! bfd_is_und_section (osec->output_section))
3741 dynindx = elf_section_data (osec->output_section)->dynindx;
3742 else
3743 dynindx = 0;
3746 /* If we're linking an executable at a fixed address, we
3747 can omit the dynamic relocation as long as the symbol
3748 is defined in the current link unit (which is implied
3749 by its output section not being NULL). */
3750 if (info->executable && !info->pie
3751 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3753 if (osec)
3754 addend += osec->output_section->vma;
3755 if (IS_FDPIC (input_bfd)
3756 && (bfd_get_section_flags (output_bfd,
3757 input_section->output_section)
3758 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3760 if (_frvfdpic_osec_readonly_p (output_bfd,
3761 input_section
3762 ->output_section))
3764 info->callbacks->warning
3765 (info,
3766 _("cannot emit fixups in read-only section"),
3767 name, input_bfd, input_section, rel->r_offset);
3768 return FALSE;
3770 if (!h || h->root.type != bfd_link_hash_undefweak)
3772 _frvfdpic_add_rofixup (output_bfd,
3773 frvfdpic_gotfixup_section
3774 (info),
3775 _bfd_elf_section_offset
3776 (output_bfd, info,
3777 input_section, rel->r_offset)
3778 + input_section
3779 ->output_section->vma
3780 + input_section->output_offset,
3781 picrel);
3782 if (r_type == R_FRV_FUNCDESC_VALUE)
3783 _frvfdpic_add_rofixup
3784 (output_bfd,
3785 frvfdpic_gotfixup_section (info),
3786 _bfd_elf_section_offset
3787 (output_bfd, info,
3788 input_section, rel->r_offset)
3789 + input_section->output_section->vma
3790 + input_section->output_offset + 4, picrel);
3794 else
3796 if ((bfd_get_section_flags (output_bfd,
3797 input_section->output_section)
3798 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3800 if (_frvfdpic_osec_readonly_p (output_bfd,
3801 input_section
3802 ->output_section))
3804 info->callbacks->warning
3805 (info,
3806 _("cannot emit dynamic relocations in read-only section"),
3807 name, input_bfd, input_section, rel->r_offset);
3808 return FALSE;
3810 _frvfdpic_add_dyn_reloc (output_bfd,
3811 frvfdpic_gotrel_section (info),
3812 _bfd_elf_section_offset
3813 (output_bfd, info,
3814 input_section, rel->r_offset)
3815 + input_section
3816 ->output_section->vma
3817 + input_section->output_offset,
3818 r_type, dynindx, addend, picrel);
3820 else if (osec)
3821 addend += osec->output_section->vma;
3822 /* We want the addend in-place because dynamic
3823 relocations are REL. Setting relocation to it
3824 should arrange for it to be installed. */
3825 relocation = addend - rel->r_addend;
3828 if (r_type == R_FRV_FUNCDESC_VALUE)
3830 /* If we've omitted the dynamic relocation, just emit
3831 the fixed addresses of the symbol and of the local
3832 GOT base offset. */
3833 if (info->executable && !info->pie
3834 && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
3835 bfd_put_32 (output_bfd,
3836 frvfdpic_got_section (info)->output_section->vma
3837 + frvfdpic_got_section (info)->output_offset
3838 + frvfdpic_got_initial_offset (info),
3839 contents + rel->r_offset + 4);
3840 else
3841 /* A function descriptor used for lazy or local
3842 resolving is initialized such that its high word
3843 contains the output section index in which the
3844 PLT entries are located, and the low word
3845 contains the offset of the lazy PLT entry entry
3846 point into that section. */
3847 bfd_put_32 (output_bfd,
3848 h && ! FRVFDPIC_SYM_LOCAL (info, h)
3850 : _frvfdpic_osec_to_segment (output_bfd,
3852 ->output_section),
3853 contents + rel->r_offset + 4);
3856 check_segment[0] = check_segment[1] = got_segment;
3857 break;
3859 case R_FRV_GPREL12:
3860 case R_FRV_GPRELU12:
3861 case R_FRV_GPREL32:
3862 case R_FRV_GPRELHI:
3863 case R_FRV_GPRELLO:
3864 check_segment[0] = gprel_segment;
3865 check_segment[1] = sec
3866 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3867 : (unsigned)-1;
3868 break;
3870 case R_FRV_GETTLSOFF:
3871 relocation = frvfdpic_plt_section (info)->output_section->vma
3872 + frvfdpic_plt_section (info)->output_offset
3873 + picrel->tlsplt_entry;
3874 BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1
3875 && picrel->tlsdesc_entry);
3876 check_segment[0] = isec_segment;
3877 check_segment[1] = plt_segment;
3878 break;
3880 case R_FRV_GOTTLSDESC12:
3881 case R_FRV_GOTTLSDESCHI:
3882 case R_FRV_GOTTLSDESCLO:
3883 BFD_ASSERT (picrel->tlsdesc_entry);
3884 relocation = picrel->tlsdesc_entry;
3885 check_segment[0] = tls_segment;
3886 check_segment[1] = sec
3887 && ! bfd_is_abs_section (sec)
3888 && ! bfd_is_und_section (sec)
3889 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3890 : tls_segment;
3891 break;
3893 case R_FRV_TLSMOFF12:
3894 case R_FRV_TLSMOFFHI:
3895 case R_FRV_TLSMOFFLO:
3896 case R_FRV_TLSMOFF:
3897 check_segment[0] = tls_segment;
3898 if (! sec)
3899 check_segment[1] = -1;
3900 else if (bfd_is_abs_section (sec)
3901 || bfd_is_und_section (sec))
3903 relocation = 0;
3904 check_segment[1] = tls_segment;
3906 else if (sec->output_section)
3908 relocation -= tls_biased_base (info);
3909 check_segment[1] =
3910 _frvfdpic_osec_to_segment (output_bfd, sec->output_section);
3912 else
3913 check_segment[1] = -1;
3914 break;
3916 case R_FRV_GOTTLSOFF12:
3917 case R_FRV_GOTTLSOFFHI:
3918 case R_FRV_GOTTLSOFFLO:
3919 BFD_ASSERT (picrel->tlsoff_entry);
3920 relocation = picrel->tlsoff_entry;
3921 check_segment[0] = tls_segment;
3922 check_segment[1] = sec
3923 && ! bfd_is_abs_section (sec)
3924 && ! bfd_is_und_section (sec)
3925 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3926 : tls_segment;
3927 break;
3929 case R_FRV_TLSDESC_VALUE:
3930 case R_FRV_TLSOFF:
3931 /* These shouldn't be present in input object files. */
3932 check_segment[0] = check_segment[1] = isec_segment;
3933 break;
3935 case R_FRV_TLSDESC_RELAX:
3936 case R_FRV_GETTLSOFF_RELAX:
3937 case R_FRV_TLSOFF_RELAX:
3938 /* These are just annotations for relaxation, nothing to do
3939 here. */
3940 continue;
3942 default:
3943 check_segment[0] = isec_segment;
3944 check_segment[1] = sec
3945 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
3946 : (unsigned)-1;
3947 break;
3950 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
3952 /* If you take this out, remove the #error from fdpic-static-6.d
3953 in the ld testsuite. */
3954 /* This helps catch problems in GCC while we can't do more
3955 than static linking. The idea is to test whether the
3956 input file basename is crt0.o only once. */
3957 if (silence_segment_error == 1)
3958 silence_segment_error =
3959 (strlen (input_bfd->filename) == 6
3960 && strcmp (input_bfd->filename, "crt0.o") == 0)
3961 || (strlen (input_bfd->filename) > 6
3962 && strcmp (input_bfd->filename
3963 + strlen (input_bfd->filename) - 7,
3964 "/crt0.o") == 0)
3965 ? -1 : 0;
3966 if (!silence_segment_error
3967 /* We don't want duplicate errors for undefined
3968 symbols. */
3969 && !(picrel && picrel->symndx == -1
3970 && picrel->d.h->root.type == bfd_link_hash_undefined))
3972 if (info->shared || info->pie)
3973 (*_bfd_error_handler)
3974 (_("%B(%A+0x%lx): reloc against `%s': %s"),
3975 input_bfd, input_section, (long)rel->r_offset, name,
3976 _("relocation references a different segment"));
3977 else
3978 info->callbacks->warning
3979 (info,
3980 _("relocation references a different segment"),
3981 name, input_bfd, input_section, rel->r_offset);
3983 if (!silence_segment_error && (info->shared || info->pie))
3984 return FALSE;
3985 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
3988 switch (r_type)
3990 case R_FRV_GOTOFFHI:
3991 case R_FRV_TLSMOFFHI:
3992 /* We need the addend to be applied before we shift the
3993 value right. */
3994 relocation += rel->r_addend;
3995 /* Fall through. */
3996 case R_FRV_GOTHI:
3997 case R_FRV_FUNCDESC_GOTHI:
3998 case R_FRV_FUNCDESC_GOTOFFHI:
3999 case R_FRV_GOTTLSOFFHI:
4000 case R_FRV_GOTTLSDESCHI:
4001 relocation >>= 16;
4002 /* Fall through. */
4004 case R_FRV_GOTLO:
4005 case R_FRV_FUNCDESC_GOTLO:
4006 case R_FRV_GOTOFFLO:
4007 case R_FRV_FUNCDESC_GOTOFFLO:
4008 case R_FRV_GOTTLSOFFLO:
4009 case R_FRV_GOTTLSDESCLO:
4010 case R_FRV_TLSMOFFLO:
4011 relocation &= 0xffff;
4012 break;
4014 default:
4015 break;
4018 switch (r_type)
4020 case R_FRV_LABEL24:
4021 if (! IS_FDPIC (output_bfd) || ! picrel->plt)
4022 break;
4023 /* Fall through. */
4025 /* When referencing a GOT entry, a function descriptor or a
4026 PLT, we don't want the addend to apply to the reference,
4027 but rather to the referenced symbol. The actual entry
4028 will have already been created taking the addend into
4029 account, so cancel it out here. */
4030 case R_FRV_GOT12:
4031 case R_FRV_GOTHI:
4032 case R_FRV_GOTLO:
4033 case R_FRV_FUNCDESC_GOT12:
4034 case R_FRV_FUNCDESC_GOTHI:
4035 case R_FRV_FUNCDESC_GOTLO:
4036 case R_FRV_FUNCDESC_GOTOFF12:
4037 case R_FRV_FUNCDESC_GOTOFFHI:
4038 case R_FRV_FUNCDESC_GOTOFFLO:
4039 case R_FRV_GETTLSOFF:
4040 case R_FRV_GOTTLSDESC12:
4041 case R_FRV_GOTTLSDESCHI:
4042 case R_FRV_GOTTLSDESCLO:
4043 case R_FRV_GOTTLSOFF12:
4044 case R_FRV_GOTTLSOFFHI:
4045 case R_FRV_GOTTLSOFFLO:
4046 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
4047 here, since we do want to apply the addend to the others.
4048 Note that we've applied the addend to GOTOFFHI before we
4049 shifted it right. */
4050 case R_FRV_GOTOFFHI:
4051 case R_FRV_TLSMOFFHI:
4052 relocation -= rel->r_addend;
4053 break;
4055 default:
4056 break;
4059 if (r_type == R_FRV_HI16)
4060 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
4062 else if (r_type == R_FRV_LO16)
4063 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
4065 else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF)
4066 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
4067 contents, relocation);
4069 else if (r_type == R_FRV_GPREL12)
4070 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
4071 contents, relocation);
4073 else if (r_type == R_FRV_GPRELU12)
4074 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
4075 contents, relocation);
4077 else if (r_type == R_FRV_GPRELLO)
4078 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
4079 contents, relocation);
4081 else if (r_type == R_FRV_GPRELHI)
4082 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
4083 contents, relocation);
4085 else if (r_type == R_FRV_TLSOFF
4086 || r_type == R_FRV_TLSDESC_VALUE)
4087 r = bfd_reloc_notsupported;
4089 else
4090 r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
4091 rel, relocation);
4093 if (r != bfd_reloc_ok)
4095 const char * msg = (const char *) NULL;
4097 switch (r)
4099 case bfd_reloc_overflow:
4100 r = info->callbacks->reloc_overflow
4101 (info, (h ? &h->root : NULL), name, howto->name,
4102 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4103 break;
4105 case bfd_reloc_undefined:
4106 r = info->callbacks->undefined_symbol
4107 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
4108 break;
4110 case bfd_reloc_outofrange:
4111 msg = _("internal error: out of range error");
4112 break;
4114 case bfd_reloc_notsupported:
4115 msg = _("internal error: unsupported relocation error");
4116 break;
4118 case bfd_reloc_dangerous:
4119 msg = _("internal error: dangerous relocation");
4120 break;
4122 default:
4123 msg = _("internal error: unknown error");
4124 break;
4127 if (msg)
4129 (*_bfd_error_handler)
4130 (_("%B(%A+0x%lx): reloc against `%s': %s"),
4131 input_bfd, input_section, (long)rel->r_offset, name, msg);
4132 return FALSE;
4135 if (! r)
4136 return FALSE;
4140 return TRUE;
4143 /* Return the section that should be marked against GC for a given
4144 relocation. */
4146 static asection *
4147 elf32_frv_gc_mark_hook (asection *sec,
4148 struct bfd_link_info *info,
4149 Elf_Internal_Rela *rel,
4150 struct elf_link_hash_entry *h,
4151 Elf_Internal_Sym *sym)
4153 if (h != NULL)
4154 switch (ELF32_R_TYPE (rel->r_info))
4156 case R_FRV_GNU_VTINHERIT:
4157 case R_FRV_GNU_VTENTRY:
4158 return NULL;
4161 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
4164 /* Hook called by the linker routine which adds symbols from an object
4165 file. We use it to put .comm items in .scomm, and not .comm. */
4167 static bfd_boolean
4168 elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
4169 bfd *abfd;
4170 struct bfd_link_info *info;
4171 Elf_Internal_Sym *sym;
4172 const char **namep ATTRIBUTE_UNUSED;
4173 flagword *flagsp ATTRIBUTE_UNUSED;
4174 asection **secp;
4175 bfd_vma *valp;
4177 if (sym->st_shndx == SHN_COMMON
4178 && !info->relocatable
4179 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
4181 /* Common symbols less than or equal to -G nn bytes are
4182 automatically put into .sbss. */
4184 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
4186 if (scomm == NULL)
4188 scomm = bfd_make_section_with_flags (abfd, ".scommon",
4189 (SEC_ALLOC
4190 | SEC_IS_COMMON
4191 | SEC_LINKER_CREATED));
4192 if (scomm == NULL)
4193 return FALSE;
4196 *secp = scomm;
4197 *valp = sym->st_size;
4200 return TRUE;
4203 /* We need dynamic symbols for every section, since segments can
4204 relocate independently. */
4205 static bfd_boolean
4206 _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
4207 struct bfd_link_info *info
4208 ATTRIBUTE_UNUSED,
4209 asection *p ATTRIBUTE_UNUSED)
4211 switch (elf_section_data (p)->this_hdr.sh_type)
4213 case SHT_PROGBITS:
4214 case SHT_NOBITS:
4215 /* If sh_type is yet undecided, assume it could be
4216 SHT_PROGBITS/SHT_NOBITS. */
4217 case SHT_NULL:
4218 return FALSE;
4220 /* There shouldn't be section relative relocations
4221 against any other section. */
4222 default:
4223 return TRUE;
4227 /* Create a .got section, as well as its additional info field. This
4228 is almost entirely copied from
4229 elflink.c:_bfd_elf_create_got_section(). */
4231 static bfd_boolean
4232 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
4234 flagword flags, pltflags;
4235 asection *s;
4236 struct elf_link_hash_entry *h;
4237 struct bfd_link_hash_entry *bh;
4238 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4239 int ptralign;
4240 int offset;
4242 /* This function may be called more than once. */
4243 s = bfd_get_section_by_name (abfd, ".got");
4244 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
4245 return TRUE;
4247 /* Machine specific: although pointers are 32-bits wide, we want the
4248 GOT to be aligned to a 64-bit boundary, such that function
4249 descriptors in it can be accessed with 64-bit loads and
4250 stores. */
4251 ptralign = 3;
4253 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4254 | SEC_LINKER_CREATED);
4255 pltflags = flags;
4257 s = bfd_make_section_with_flags (abfd, ".got", flags);
4258 if (s == NULL
4259 || !bfd_set_section_alignment (abfd, s, ptralign))
4260 return FALSE;
4262 if (bed->want_got_plt)
4264 s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
4265 if (s == NULL
4266 || !bfd_set_section_alignment (abfd, s, ptralign))
4267 return FALSE;
4270 if (bed->want_got_sym)
4272 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
4273 (or .got.plt) section. We don't do this in the linker script
4274 because we don't want to define the symbol if we are not creating
4275 a global offset table. */
4276 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
4277 elf_hash_table (info)->hgot = h;
4278 if (h == NULL)
4279 return FALSE;
4281 /* Machine-specific: we want the symbol for executables as
4282 well. */
4283 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4284 return FALSE;
4287 /* The first bit of the global offset table is the header. */
4288 s->size += bed->got_header_size;
4290 /* This is the machine-specific part. Create and initialize section
4291 data for the got. */
4292 if (IS_FDPIC (abfd))
4294 frvfdpic_got_section (info) = s;
4295 frvfdpic_relocs_info (info) = htab_try_create (1,
4296 frvfdpic_relocs_info_hash,
4297 frvfdpic_relocs_info_eq,
4298 (htab_del) NULL);
4299 if (! frvfdpic_relocs_info (info))
4300 return FALSE;
4302 s = bfd_make_section_with_flags (abfd, ".rel.got",
4303 (flags | SEC_READONLY));
4304 if (s == NULL
4305 || ! bfd_set_section_alignment (abfd, s, 2))
4306 return FALSE;
4308 frvfdpic_gotrel_section (info) = s;
4310 /* Machine-specific. */
4311 s = bfd_make_section_with_flags (abfd, ".rofixup",
4312 (flags | SEC_READONLY));
4313 if (s == NULL
4314 || ! bfd_set_section_alignment (abfd, s, 2))
4315 return FALSE;
4317 frvfdpic_gotfixup_section (info) = s;
4318 offset = -2048;
4319 flags = BSF_GLOBAL;
4321 else
4323 offset = 2048;
4324 flags = BSF_GLOBAL | BSF_WEAK;
4327 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
4328 turns out that we're linking with a different linker script, the
4329 linker script will override it. */
4330 bh = NULL;
4331 if (!(_bfd_generic_link_add_one_symbol
4332 (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE,
4333 bed->collect, &bh)))
4334 return FALSE;
4335 h = (struct elf_link_hash_entry *) bh;
4336 h->def_regular = 1;
4337 h->type = STT_OBJECT;
4338 /* h->other = STV_HIDDEN; */ /* Should we? */
4340 /* Machine-specific: we want the symbol for executables as well. */
4341 if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
4342 return FALSE;
4344 if (!IS_FDPIC (abfd))
4345 return TRUE;
4347 /* FDPIC supports Thread Local Storage, and this may require a
4348 procedure linkage table for TLS PLT entries. */
4350 /* This is mostly copied from
4351 elflink.c:_bfd_elf_create_dynamic_sections(). */
4353 flags = pltflags;
4354 pltflags |= SEC_CODE;
4355 if (bed->plt_not_loaded)
4356 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
4357 if (bed->plt_readonly)
4358 pltflags |= SEC_READONLY;
4360 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
4361 if (s == NULL
4362 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
4363 return FALSE;
4364 /* FRV-specific: remember it. */
4365 frvfdpic_plt_section (info) = s;
4367 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
4368 .plt section. */
4369 if (bed->want_plt_sym)
4371 h = _bfd_elf_define_linkage_sym (abfd, info, s,
4372 "_PROCEDURE_LINKAGE_TABLE_");
4373 elf_hash_table (info)->hplt = h;
4374 if (h == NULL)
4375 return FALSE;
4378 /* FRV-specific: we want rel relocations for the plt. */
4379 s = bfd_make_section_with_flags (abfd, ".rel.plt",
4380 flags | SEC_READONLY);
4381 if (s == NULL
4382 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4383 return FALSE;
4384 /* FRV-specific: remember it. */
4385 frvfdpic_pltrel_section (info) = s;
4387 return TRUE;
4390 /* Make sure the got and plt sections exist, and that our pointers in
4391 the link hash table point to them. */
4393 static bfd_boolean
4394 elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4396 /* This is mostly copied from
4397 elflink.c:_bfd_elf_create_dynamic_sections(). */
4398 flagword flags;
4399 asection *s;
4400 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4402 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4403 | SEC_LINKER_CREATED);
4405 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4406 .rel[a].bss sections. */
4408 /* FRV-specific: we want to create the GOT and the PLT in the FRV
4409 way. */
4410 if (! _frv_create_got_section (abfd, info))
4411 return FALSE;
4413 /* FRV-specific: make sure we created everything we wanted. */
4414 BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
4415 && frvfdpic_gotfixup_section (info)
4416 && frvfdpic_plt_section (info)
4417 && frvfdpic_pltrel_section (info));
4419 if (bed->want_dynbss)
4421 /* The .dynbss section is a place to put symbols which are defined
4422 by dynamic objects, are referenced by regular objects, and are
4423 not functions. We must allocate space for them in the process
4424 image and use a R_*_COPY reloc to tell the dynamic linker to
4425 initialize them at run time. The linker script puts the .dynbss
4426 section into the .bss section of the final image. */
4427 s = bfd_make_section_with_flags (abfd, ".dynbss",
4428 SEC_ALLOC | SEC_LINKER_CREATED);
4429 if (s == NULL)
4430 return FALSE;
4432 /* The .rel[a].bss section holds copy relocs. This section is not
4433 normally needed. We need to create it here, though, so that the
4434 linker will map it to an output section. We can't just create it
4435 only if we need it, because we will not know whether we need it
4436 until we have seen all the input files, and the first time the
4437 main linker code calls BFD after examining all the input files
4438 (size_dynamic_sections) the input sections have already been
4439 mapped to the output sections. If the section turns out not to
4440 be needed, we can discard it later. We will never need this
4441 section when generating a shared object, since they do not use
4442 copy relocs. */
4443 if (! info->shared)
4445 s = bfd_make_section_with_flags (abfd,
4446 (bed->default_use_rela_p
4447 ? ".rela.bss" : ".rel.bss"),
4448 flags | SEC_READONLY);
4449 if (s == NULL
4450 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
4451 return FALSE;
4455 return TRUE;
4458 /* Compute the total GOT and PLT size required by each symbol in each
4459 range. Symbols may require up to 4 words in the GOT: an entry
4460 pointing to the symbol, an entry pointing to its function
4461 descriptor, and a private function descriptors taking two
4462 words. */
4464 static void
4465 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry,
4466 struct _frvfdpic_dynamic_got_info *dinfo)
4468 /* Allocate space for a GOT entry pointing to the symbol. */
4469 if (entry->got12)
4470 dinfo->got12 += 4;
4471 else if (entry->gotlos)
4472 dinfo->gotlos += 4;
4473 else if (entry->gothilo)
4474 dinfo->gothilo += 4;
4475 else
4476 entry->relocs32--;
4477 entry->relocs32++;
4479 /* Allocate space for a GOT entry pointing to the function
4480 descriptor. */
4481 if (entry->fdgot12)
4482 dinfo->got12 += 4;
4483 else if (entry->fdgotlos)
4484 dinfo->gotlos += 4;
4485 else if (entry->fdgothilo)
4486 dinfo->gothilo += 4;
4487 else
4488 entry->relocsfd--;
4489 entry->relocsfd++;
4491 /* Decide whether we need a PLT entry, a function descriptor in the
4492 GOT, and a lazy PLT entry for this symbol. */
4493 entry->plt = entry->call
4494 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4495 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4496 entry->privfd = entry->plt
4497 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
4498 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
4499 && (entry->symndx != -1
4500 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
4501 entry->lazyplt = entry->privfd
4502 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4503 && ! (dinfo->info->flags & DF_BIND_NOW)
4504 && elf_hash_table (dinfo->info)->dynamic_sections_created;
4506 /* Allocate space for a function descriptor. */
4507 if (entry->fdgoff12)
4508 dinfo->fd12 += 8;
4509 else if (entry->fdgofflos)
4510 dinfo->fdlos += 8;
4511 else if (entry->privfd && entry->plt)
4512 dinfo->fdplt += 8;
4513 else if (entry->privfd)
4514 dinfo->fdhilo += 8;
4515 else
4516 entry->relocsfdv--;
4517 entry->relocsfdv++;
4519 if (entry->lazyplt)
4520 dinfo->lzplt += 8;
4523 /* Compute the total GOT size required by each TLS symbol in each
4524 range. Symbols may require up to 5 words in the GOT: an entry
4525 holding the TLS offset for the symbol, and an entry with a full TLS
4526 descriptor taking 4 words. */
4528 static void
4529 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry,
4530 struct _frvfdpic_dynamic_got_info *dinfo,
4531 bfd_boolean subtract)
4533 const int l = subtract ? -1 : 1;
4535 /* Allocate space for a GOT entry with the TLS offset of the
4536 symbol. */
4537 if (entry->tlsoff12)
4538 dinfo->got12 += 4 * l;
4539 else if (entry->tlsofflos)
4540 dinfo->gotlos += 4 * l;
4541 else if (entry->tlsoffhilo)
4542 dinfo->gothilo += 4 * l;
4543 else
4544 entry->relocstlsoff -= l;
4545 entry->relocstlsoff += l;
4547 /* If there's any TLSOFF relocation, mark the output file as not
4548 suitable for dlopening. This mark will remain even if we relax
4549 all such relocations, but this is not a problem, since we'll only
4550 do so for executables, and we definitely don't want anyone
4551 dlopening executables. */
4552 if (entry->relocstlsoff)
4553 dinfo->info->flags |= DF_STATIC_TLS;
4555 /* Allocate space for a TLS descriptor. */
4556 if (entry->tlsdesc12)
4557 dinfo->tlsd12 += 8 * l;
4558 else if (entry->tlsdesclos)
4559 dinfo->tlsdlos += 8 * l;
4560 else if (entry->tlsplt)
4561 dinfo->tlsdplt += 8 * l;
4562 else if (entry->tlsdeschilo)
4563 dinfo->tlsdhilo += 8 * l;
4564 else
4565 entry->relocstlsd -= l;
4566 entry->relocstlsd += l;
4569 /* Compute the number of dynamic relocations and fixups that a symbol
4570 requires, and add (or subtract) from the grand and per-symbol
4571 totals. */
4573 static void
4574 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry,
4575 struct _frvfdpic_dynamic_got_info *dinfo,
4576 bfd_boolean subtract)
4578 bfd_vma relocs = 0, fixups = 0, tlsrets = 0;
4580 if (!dinfo->info->executable || dinfo->info->pie)
4582 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv
4583 + entry->relocstlsd;
4585 /* In the executable, TLS relocations to symbols that bind
4586 locally (including those that resolve to global TLS offsets)
4587 are resolved immediately, without any need for fixups or
4588 dynamic relocations. In shared libraries, however, we must
4589 emit dynamic relocations even for local symbols, because we
4590 don't know the module id the library is going to get at
4591 run-time, nor its TLS base offset. */
4592 if (!dinfo->info->executable
4593 || (entry->symndx == -1
4594 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4595 relocs += entry->relocstlsoff;
4597 else
4599 if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
4601 if (entry->symndx != -1
4602 || entry->d.h->root.type != bfd_link_hash_undefweak)
4603 fixups += entry->relocs32 + 2 * entry->relocsfdv;
4604 fixups += entry->relocstlsd;
4605 tlsrets += entry->relocstlsd;
4607 else
4609 relocs += entry->relocs32 + entry->relocsfdv
4610 + entry->relocstlsoff + entry->relocstlsd;
4613 if (entry->symndx != -1
4614 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
4616 if (entry->symndx != -1
4617 || entry->d.h->root.type != bfd_link_hash_undefweak)
4618 fixups += entry->relocsfd;
4620 else
4621 relocs += entry->relocsfd;
4624 if (subtract)
4626 relocs = - relocs;
4627 fixups = - fixups;
4628 tlsrets = - tlsrets;
4631 entry->dynrelocs += relocs;
4632 entry->fixups += fixups;
4633 dinfo->relocs += relocs;
4634 dinfo->fixups += fixups;
4635 dinfo->tls_ret_refs += tlsrets;
4638 /* Look for opportunities to relax TLS relocations. We can assume
4639 we're linking the main executable or a static-tls library, since
4640 otherwise we wouldn't have got here. When relaxing, we have to
4641 first undo any previous accounting of TLS uses of fixups, dynamic
4642 relocations, GOT and PLT entries. */
4644 static void
4645 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry,
4646 struct _frvfdpic_dynamic_got_info *dinfo,
4647 bfd_boolean relaxing)
4649 bfd_boolean changed = ! relaxing;
4651 BFD_ASSERT (dinfo->info->executable
4652 || (dinfo->info->flags & DF_STATIC_TLS));
4654 if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo)
4656 if (! changed)
4658 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4659 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4660 changed = TRUE;
4663 /* When linking an executable, we can always decay GOTTLSDESC to
4664 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
4665 When linking a static-tls shared library, using TLSMOFF is
4666 not an option, but we can still use GOTTLSOFF. When decaying
4667 to GOTTLSOFF, we must keep the GOT entry in range. We know
4668 it has to fit because we'll be trading the 4 words of hte TLS
4669 descriptor for a single word in the same range. */
4670 if (! dinfo->info->executable
4671 || (entry->symndx == -1
4672 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
4674 entry->tlsoff12 |= entry->tlsdesc12;
4675 entry->tlsofflos |= entry->tlsdesclos;
4676 entry->tlsoffhilo |= entry->tlsdeschilo;
4679 entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0;
4682 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
4683 main executable. We have to check whether the symbol's TLSOFF is
4684 in range for a setlos. For symbols with a hash entry, we can
4685 determine exactly what to do; for others locals, we don't have
4686 addresses handy, so we use the size of the TLS section as an
4687 approximation. If we get it wrong, we'll retain a GOT entry
4688 holding the TLS offset (without dynamic relocations or fixups),
4689 but we'll still optimize away the loads from it. Since TLS sizes
4690 are generally very small, it's probably not worth attempting to
4691 do better than this. */
4692 if ((entry->tlsplt
4693 || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo)
4694 && dinfo->info->executable && relaxing
4695 && ((entry->symndx == -1
4696 && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
4697 /* The above may hold for an undefweak TLS symbol, so make
4698 sure we don't have this case before accessing def.value
4699 and def.section. */
4700 && (entry->d.h->root.type == bfd_link_hash_undefweak
4701 || (bfd_vma)(entry->d.h->root.u.def.value
4702 + (entry->d.h->root.u.def.section
4703 ->output_section->vma)
4704 + entry->d.h->root.u.def.section->output_offset
4705 + entry->addend
4706 - tls_biased_base (dinfo->info)
4707 + 32768) < (bfd_vma)65536))
4708 || (entry->symndx != -1
4709 && (elf_hash_table (dinfo->info)->tls_sec->size
4710 + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS))))
4712 if (! changed)
4714 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4715 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4716 changed = TRUE;
4719 entry->tlsplt =
4720 entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0;
4723 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
4724 have a #gottlsoff12 relocation for this entry, or if we can fit
4725 one more in the 12-bit (and 16-bit) ranges. */
4726 if (entry->tlsplt
4727 && (entry->tlsoff12
4728 || (relaxing
4729 && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4
4730 && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12
4731 + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos
4732 <= 65536 - 12 - 4))))
4734 if (! changed)
4736 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
4737 _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
4738 changed = TRUE;
4741 entry->tlsoff12 = 1;
4742 entry->tlsplt = 0;
4745 if (changed)
4747 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4748 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4751 return;
4754 /* Compute the total GOT and PLT size required by each symbol in each range. *
4755 Symbols may require up to 4 words in the GOT: an entry pointing to
4756 the symbol, an entry pointing to its function descriptor, and a
4757 private function descriptors taking two words. */
4759 static int
4760 _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
4762 struct frvfdpic_relocs_info *entry = *entryp;
4763 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
4765 _frvfdpic_count_nontls_entries (entry, dinfo);
4767 if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS))
4768 _frvfdpic_relax_tls_entries (entry, dinfo, FALSE);
4769 else
4771 _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
4772 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
4775 return 1;
4778 /* Determine the positive and negative ranges to be used by each
4779 offset range in the GOT. FDCUR and CUR, that must be aligned to a
4780 double-word boundary, are the minimum (negative) and maximum
4781 (positive) GOT offsets already used by previous ranges, except for
4782 an ODD entry that may have been left behind. GOT and FD indicate
4783 the size of GOT entries and function descriptors that must be
4784 placed within the range from -WRAP to WRAP. If there's room left,
4785 up to FDPLT bytes should be reserved for additional function
4786 descriptors. */
4788 inline static bfd_signed_vma
4789 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
4790 bfd_signed_vma fdcur,
4791 bfd_signed_vma odd,
4792 bfd_signed_vma cur,
4793 bfd_vma got,
4794 bfd_vma fd,
4795 bfd_vma fdplt,
4796 bfd_vma tlsd,
4797 bfd_vma tlsdplt,
4798 bfd_vma wrap)
4800 bfd_signed_vma wrapmin = -wrap;
4801 const bfd_vma tdescsz = 8;
4803 /* Start at the given initial points. */
4804 gad->fdcur = fdcur;
4805 gad->cur = cur;
4807 /* If we had an incoming odd word and we have any got entries that
4808 are going to use it, consume it, otherwise leave gad->odd at
4809 zero. We might force gad->odd to zero and return the incoming
4810 odd such that it is used by the next range, but then GOT entries
4811 might appear to be out of order and we wouldn't be able to
4812 shorten the GOT by one word if it turns out to end with an
4813 unpaired GOT entry. */
4814 if (odd && got)
4816 gad->odd = odd;
4817 got -= 4;
4818 odd = 0;
4820 else
4821 gad->odd = 0;
4823 /* If we're left with an unpaired GOT entry, compute its location
4824 such that we can return it. Otherwise, if got doesn't require an
4825 odd number of words here, either odd was already zero in the
4826 block above, or it was set to zero because got was non-zero, or
4827 got was already zero. In the latter case, we want the value of
4828 odd to carry over to the return statement, so we don't want to
4829 reset odd unless the condition below is true. */
4830 if (got & 4)
4832 odd = cur + got;
4833 got += 4;
4836 /* Compute the tentative boundaries of this range. */
4837 gad->max = cur + got;
4838 gad->min = fdcur - fd;
4839 gad->fdplt = 0;
4841 /* If function descriptors took too much space, wrap some of them
4842 around. */
4843 if (gad->min < wrapmin)
4845 gad->max += wrapmin - gad->min;
4846 gad->tmin = gad->min = wrapmin;
4849 /* If GOT entries took too much space, wrap some of them around.
4850 This may well cause gad->min to become lower than wrapmin. This
4851 will cause a relocation overflow later on, so we don't have to
4852 report it here . */
4853 if ((bfd_vma) gad->max > wrap)
4855 gad->min -= gad->max - wrap;
4856 gad->max = wrap;
4859 /* Add TLS descriptors. */
4860 gad->tmax = gad->max + tlsd;
4861 gad->tmin = gad->min;
4862 gad->tlsdplt = 0;
4864 /* If TLS descriptors took too much space, wrap an integral number
4865 of them around. */
4866 if ((bfd_vma) gad->tmax > wrap)
4868 bfd_vma wrapsize = gad->tmax - wrap;
4870 wrapsize += tdescsz / 2;
4871 wrapsize &= ~ tdescsz / 2;
4873 gad->tmin -= wrapsize;
4874 gad->tmax -= wrapsize;
4877 /* If there is space left and we have function descriptors
4878 referenced in PLT entries that could take advantage of shorter
4879 offsets, place them now. */
4880 if (fdplt && gad->tmin > wrapmin)
4882 bfd_vma fds;
4884 if ((bfd_vma) (gad->tmin - wrapmin) < fdplt)
4885 fds = gad->tmin - wrapmin;
4886 else
4887 fds = fdplt;
4889 fdplt -= fds;
4890 gad->min -= fds;
4891 gad->tmin -= fds;
4892 gad->fdplt += fds;
4895 /* If there is more space left, try to place some more function
4896 descriptors for PLT entries. */
4897 if (fdplt && (bfd_vma) gad->tmax < wrap)
4899 bfd_vma fds;
4901 if ((bfd_vma) (wrap - gad->tmax) < fdplt)
4902 fds = wrap - gad->tmax;
4903 else
4904 fds = fdplt;
4906 fdplt -= fds;
4907 gad->max += fds;
4908 gad->tmax += fds;
4909 gad->fdplt += fds;
4912 /* If there is space left and we have TLS descriptors referenced in
4913 PLT entries that could take advantage of shorter offsets, place
4914 them now. */
4915 if (tlsdplt && gad->tmin > wrapmin)
4917 bfd_vma tlsds;
4919 if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt)
4920 tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2);
4921 else
4922 tlsds = tlsdplt;
4924 tlsdplt -= tlsds;
4925 gad->tmin -= tlsds;
4926 gad->tlsdplt += tlsds;
4929 /* If there is more space left, try to place some more TLS
4930 descriptors for PLT entries. Although we could try to fit an
4931 additional TLS descriptor with half of it just before before the
4932 wrap point and another right past the wrap point, this might
4933 cause us to run out of space for the next region, so don't do
4934 it. */
4935 if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2)
4937 bfd_vma tlsds;
4939 if ((bfd_vma) (wrap - gad->tmax) < tlsdplt)
4940 tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2);
4941 else
4942 tlsds = tlsdplt;
4944 tlsdplt -= tlsds;
4945 gad->tmax += tlsds;
4946 gad->tlsdplt += tlsds;
4949 /* If odd was initially computed as an offset past the wrap point,
4950 wrap it around. */
4951 if (odd > gad->max)
4952 odd = gad->min + odd - gad->max;
4954 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
4955 before returning, so do it here too. This guarantees that,
4956 should cur and fdcur meet at the wrap point, they'll both be
4957 equal to min. */
4958 if (gad->cur == gad->max)
4959 gad->cur = gad->min;
4961 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
4962 gad->tcur = gad->max;
4963 if (gad->tcur == gad->tmax)
4964 gad->tcur = gad->tmin;
4966 return odd;
4969 /* Compute the location of the next GOT entry, given the allocation
4970 data for a range. */
4972 inline static bfd_signed_vma
4973 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
4975 bfd_signed_vma ret;
4977 if (gad->odd)
4979 /* If there was an odd word left behind, use it. */
4980 ret = gad->odd;
4981 gad->odd = 0;
4983 else
4985 /* Otherwise, use the word pointed to by cur, reserve the next
4986 as an odd word, and skip to the next pair of words, possibly
4987 wrapping around. */
4988 ret = gad->cur;
4989 gad->odd = gad->cur + 4;
4990 gad->cur += 8;
4991 if (gad->cur == gad->max)
4992 gad->cur = gad->min;
4995 return ret;
4998 /* Compute the location of the next function descriptor entry in the
4999 GOT, given the allocation data for a range. */
5001 inline static bfd_signed_vma
5002 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5004 /* If we're at the bottom, wrap around, and only then allocate the
5005 next pair of words. */
5006 if (gad->fdcur == gad->min)
5007 gad->fdcur = gad->max;
5008 return gad->fdcur -= 8;
5011 /* Compute the location of the next TLS descriptor entry in the GOT,
5012 given the allocation data for a range. */
5013 inline static bfd_signed_vma
5014 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
5016 bfd_signed_vma ret;
5018 ret = gad->tcur;
5020 gad->tcur += 8;
5022 /* If we're at the top of the region, wrap around to the bottom. */
5023 if (gad->tcur == gad->tmax)
5024 gad->tcur = gad->tmin;
5026 return ret;
5029 /* Assign GOT offsets for every GOT entry and function descriptor.
5030 Doing everything in a single pass is tricky. */
5032 static int
5033 _frvfdpic_assign_got_entries (void **entryp, void *info_)
5035 struct frvfdpic_relocs_info *entry = *entryp;
5036 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5038 if (entry->got12)
5039 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5040 else if (entry->gotlos)
5041 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5042 else if (entry->gothilo)
5043 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5045 if (entry->fdgot12)
5046 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5047 else if (entry->fdgotlos)
5048 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5049 else if (entry->fdgothilo)
5050 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5052 if (entry->fdgoff12)
5053 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5054 else if (entry->plt && dinfo->got12.fdplt)
5056 dinfo->got12.fdplt -= 8;
5057 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
5059 else if (entry->fdgofflos)
5060 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5061 else if (entry->plt && dinfo->gotlos.fdplt)
5063 dinfo->gotlos.fdplt -= 8;
5064 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
5066 else if (entry->plt)
5068 dinfo->gothilo.fdplt -= 8;
5069 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5071 else if (entry->privfd)
5072 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
5074 if (entry->tlsoff12)
5075 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12);
5076 else if (entry->tlsofflos)
5077 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
5078 else if (entry->tlsoffhilo)
5079 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
5081 if (entry->tlsdesc12)
5082 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5083 else if (entry->tlsplt && dinfo->got12.tlsdplt)
5085 dinfo->got12.tlsdplt -= 8;
5086 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
5088 else if (entry->tlsdesclos)
5089 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5090 else if (entry->tlsplt && dinfo->gotlos.tlsdplt)
5092 dinfo->gotlos.tlsdplt -= 8;
5093 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
5095 else if (entry->tlsplt)
5097 dinfo->gothilo.tlsdplt -= 8;
5098 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5100 else if (entry->tlsdeschilo)
5101 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
5103 return 1;
5106 /* Assign GOT offsets to private function descriptors used by PLT
5107 entries (or referenced by 32-bit offsets), as well as PLT entries
5108 and lazy PLT entries. */
5110 static int
5111 _frvfdpic_assign_plt_entries (void **entryp, void *info_)
5113 struct frvfdpic_relocs_info *entry = *entryp;
5114 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
5116 if (entry->privfd)
5117 BFD_ASSERT (entry->fd_entry);
5119 if (entry->plt)
5121 int size;
5123 /* We use the section's raw size to mark the location of the
5124 next PLT entry. */
5125 entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
5127 /* Figure out the length of this PLT entry based on the
5128 addressing mode we need to reach the function descriptor. */
5129 BFD_ASSERT (entry->fd_entry);
5130 if (entry->fd_entry >= -(1 << (12 - 1))
5131 && entry->fd_entry < (1 << (12 - 1)))
5132 size = 8;
5133 else if (entry->fd_entry >= -(1 << (16 - 1))
5134 && entry->fd_entry < (1 << (16 - 1)))
5135 size = 12;
5136 else
5137 size = 16;
5139 frvfdpic_plt_section (dinfo->g.info)->size += size;
5142 if (entry->lazyplt)
5144 entry->lzplt_entry = dinfo->g.lzplt;
5145 dinfo->g.lzplt += 8;
5146 /* If this entry is the one that gets the resolver stub, account
5147 for the additional instruction. */
5148 if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
5149 == FRVFDPIC_LZPLT_RESOLV_LOC)
5150 dinfo->g.lzplt += 4;
5153 if (entry->tlsplt)
5155 int size;
5157 entry->tlsplt_entry
5158 = frvfdpic_plt_section (dinfo->g.info)->size;
5160 if (dinfo->g.info->executable
5161 && (entry->symndx != -1
5162 || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h)))
5164 if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1))
5165 /* FIXME: here we use the size of the TLS section
5166 as an upper bound for the value of the TLS
5167 symbol, because we may not know the exact value
5168 yet. If we get it wrong, we'll just waste a
5169 word in the PLT, and we should never get even
5170 close to 32 KiB of TLS anyway. */
5171 && elf_hash_table (dinfo->g.info)->tls_sec
5172 && (elf_hash_table (dinfo->g.info)->tls_sec->size
5173 + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1))))
5174 size = 8;
5175 else
5176 size = 12;
5178 else if (entry->tlsoff_entry)
5180 if (entry->tlsoff_entry >= -(1 << (12 - 1))
5181 && entry->tlsoff_entry < (1 << (12 - 1)))
5182 size = 8;
5183 else if (entry->tlsoff_entry >= -(1 << (16 - 1))
5184 && entry->tlsoff_entry < (1 << (16 - 1)))
5185 size = 12;
5186 else
5187 size = 16;
5189 else
5191 BFD_ASSERT (entry->tlsdesc_entry);
5193 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
5194 && entry->tlsdesc_entry < (1 << (12 - 1)))
5195 size = 8;
5196 else if (entry->tlsdesc_entry >= -(1 << (16 - 1))
5197 && entry->tlsdesc_entry < (1 << (16 - 1)))
5198 size = 12;
5199 else
5200 size = 16;
5203 frvfdpic_plt_section (dinfo->g.info)->size += size;
5206 return 1;
5209 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
5210 _frvfdpic_assign_plt_entries. */
5212 static int
5213 _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
5215 struct frvfdpic_relocs_info *entry = *entryp;
5217 entry->got_entry = 0;
5218 entry->fdgot_entry = 0;
5219 entry->fd_entry = 0;
5220 entry->plt_entry = (bfd_vma)-1;
5221 entry->lzplt_entry = (bfd_vma)-1;
5222 entry->tlsoff_entry = 0;
5223 entry->tlsdesc_entry = 0;
5224 entry->tlsplt_entry = (bfd_vma)-1;
5226 return 1;
5229 /* Follow indirect and warning hash entries so that each got entry
5230 points to the final symbol definition. P must point to a pointer
5231 to the hash table we're traversing. Since this traversal may
5232 modify the hash table, we set this pointer to NULL to indicate
5233 we've made a potentially-destructive change to the hash table, so
5234 the traversal must be restarted. */
5235 static int
5236 _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
5238 struct frvfdpic_relocs_info *entry = *entryp;
5239 htab_t *htab = p;
5241 if (entry->symndx == -1)
5243 struct elf_link_hash_entry *h = entry->d.h;
5244 struct frvfdpic_relocs_info *oentry;
5246 while (h->root.type == bfd_link_hash_indirect
5247 || h->root.type == bfd_link_hash_warning)
5248 h = (struct elf_link_hash_entry *)h->root.u.i.link;
5250 if (entry->d.h == h)
5251 return 1;
5253 oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
5254 NO_INSERT);
5256 if (oentry)
5258 /* Merge the two entries. */
5259 frvfdpic_pic_merge_early_relocs_info (oentry, entry);
5260 htab_clear_slot (*htab, entryp);
5261 return 1;
5264 entry->d.h = h;
5266 /* If we can't find this entry with the new bfd hash, re-insert
5267 it, and get the traversal restarted. */
5268 if (! htab_find (*htab, entry))
5270 htab_clear_slot (*htab, entryp);
5271 entryp = htab_find_slot (*htab, entry, INSERT);
5272 if (! *entryp)
5273 *entryp = entry;
5274 /* Abort the traversal, since the whole table may have
5275 moved, and leave it up to the parent to restart the
5276 process. */
5277 *(htab_t *)p = NULL;
5278 return 0;
5282 return 1;
5285 /* Compute the total size of the GOT, the PLT, the dynamic relocations
5286 section and the rofixup section. Assign locations for GOT and PLT
5287 entries. */
5289 static bfd_boolean
5290 _frvfdpic_size_got_plt (bfd *output_bfd,
5291 struct _frvfdpic_dynamic_got_plt_info *gpinfop)
5293 bfd_signed_vma odd;
5294 bfd_vma limit, tlslimit;
5295 struct bfd_link_info *info = gpinfop->g.info;
5296 bfd *dynobj = elf_hash_table (info)->dynobj;
5298 memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g,
5299 sizeof (gpinfop->g));
5301 odd = 12;
5302 /* Compute the total size taken by entries in the 12-bit and 16-bit
5303 ranges, to tell how many PLT function descriptors we can bring
5304 into the 12-bit range without causing the 16-bit range to
5305 overflow. */
5306 limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos
5307 + gpinfop->g.fd12 + gpinfop->g.fdlos
5308 + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos;
5309 if (limit < (bfd_vma)1 << 16)
5310 limit = ((bfd_vma)1 << 16) - limit;
5311 else
5312 limit = 0;
5313 if (gpinfop->g.fdplt < limit)
5315 tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8;
5316 limit = gpinfop->g.fdplt;
5318 else
5319 tlslimit = 0;
5320 if (gpinfop->g.tlsdplt < tlslimit)
5321 tlslimit = gpinfop->g.tlsdplt;
5323 /* Determine the ranges of GOT offsets that we can use for each
5324 range of addressing modes. */
5325 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12,
5327 odd,
5329 gpinfop->g.got12,
5330 gpinfop->g.fd12,
5331 limit,
5332 gpinfop->g.tlsd12,
5333 tlslimit,
5334 (bfd_vma)1 << (12-1));
5335 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos,
5336 gpinfop->got12.tmin,
5337 odd,
5338 gpinfop->got12.tmax,
5339 gpinfop->g.gotlos,
5340 gpinfop->g.fdlos,
5341 gpinfop->g.fdplt
5342 - gpinfop->got12.fdplt,
5343 gpinfop->g.tlsdlos,
5344 gpinfop->g.tlsdplt
5345 - gpinfop->got12.tlsdplt,
5346 (bfd_vma)1 << (16-1));
5347 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo,
5348 gpinfop->gotlos.tmin,
5349 odd,
5350 gpinfop->gotlos.tmax,
5351 gpinfop->g.gothilo,
5352 gpinfop->g.fdhilo,
5353 gpinfop->g.fdplt
5354 - gpinfop->got12.fdplt
5355 - gpinfop->gotlos.fdplt,
5356 gpinfop->g.tlsdhilo,
5357 gpinfop->g.tlsdplt
5358 - gpinfop->got12.tlsdplt
5359 - gpinfop->gotlos.tlsdplt,
5360 (bfd_vma)1 << (32-1));
5362 /* Now assign (most) GOT offsets. */
5363 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
5364 gpinfop);
5366 frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax
5367 - gpinfop->gothilo.tmin
5368 /* If an odd word is the last word of the GOT, we don't need this
5369 word to be part of the GOT. */
5370 - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0);
5371 if (frvfdpic_got_section (info)->size == 0)
5372 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5373 else if (frvfdpic_got_section (info)->size == 12
5374 && ! elf_hash_table (info)->dynamic_sections_created)
5376 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
5377 frvfdpic_got_section (info)->size = 0;
5379 /* This will be non-NULL during relaxation. The assumption is that
5380 the size of one of these sections will never grow, only shrink,
5381 so we can use the larger buffer we allocated before. */
5382 else if (frvfdpic_got_section (info)->contents == NULL)
5384 frvfdpic_got_section (info)->contents =
5385 (bfd_byte *) bfd_zalloc (dynobj,
5386 frvfdpic_got_section (info)->size);
5387 if (frvfdpic_got_section (info)->contents == NULL)
5388 return FALSE;
5391 if (frvfdpic_gotrel_section (info))
5392 /* Subtract the number of lzplt entries, since those will generate
5393 relocations in the pltrel section. */
5394 frvfdpic_gotrel_section (info)->size =
5395 (gpinfop->g.relocs - gpinfop->g.lzplt / 8)
5396 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5397 else
5398 BFD_ASSERT (gpinfop->g.relocs == 0);
5399 if (frvfdpic_gotrel_section (info)->size == 0)
5400 frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
5401 else if (frvfdpic_gotrel_section (info)->contents == NULL)
5403 frvfdpic_gotrel_section (info)->contents =
5404 (bfd_byte *) bfd_zalloc (dynobj,
5405 frvfdpic_gotrel_section (info)->size);
5406 if (frvfdpic_gotrel_section (info)->contents == NULL)
5407 return FALSE;
5410 frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
5411 if (frvfdpic_gotfixup_section (info)->size == 0)
5412 frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
5413 else if (frvfdpic_gotfixup_section (info)->contents == NULL)
5415 frvfdpic_gotfixup_section (info)->contents =
5416 (bfd_byte *) bfd_zalloc (dynobj,
5417 frvfdpic_gotfixup_section (info)->size);
5418 if (frvfdpic_gotfixup_section (info)->contents == NULL)
5419 return FALSE;
5422 if (frvfdpic_pltrel_section (info))
5424 frvfdpic_pltrel_section (info)->size =
5425 gpinfop->g.lzplt / 8
5426 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
5427 if (frvfdpic_pltrel_section (info)->size == 0)
5428 frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
5429 else if (frvfdpic_pltrel_section (info)->contents == NULL)
5431 frvfdpic_pltrel_section (info)->contents =
5432 (bfd_byte *) bfd_zalloc (dynobj,
5433 frvfdpic_pltrel_section (info)->size);
5434 if (frvfdpic_pltrel_section (info)->contents == NULL)
5435 return FALSE;
5439 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
5440 such that there's room for the additional instruction needed to
5441 call the resolver. Since _frvfdpic_assign_got_entries didn't
5442 account for them, our block size is 4 bytes smaller than the real
5443 block size. */
5444 if (frvfdpic_plt_section (info))
5446 frvfdpic_plt_section (info)->size = gpinfop->g.lzplt
5447 + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
5448 / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
5451 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
5452 actually assign lazy PLT entries addresses. */
5453 gpinfop->g.lzplt = 0;
5455 /* Save information that we're going to need to generate GOT and PLT
5456 entries. */
5457 frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin;
5459 if (get_elf_backend_data (output_bfd)->want_got_sym)
5460 elf_hash_table (info)->hgot->root.u.def.value
5461 = frvfdpic_got_initial_offset (info);
5463 if (frvfdpic_plt_section (info))
5464 frvfdpic_plt_initial_offset (info) =
5465 frvfdpic_plt_section (info)->size;
5467 /* Allocate a ret statement at plt_initial_offset, to be used by
5468 locally-resolved TLS descriptors. */
5469 if (gpinfop->g.tls_ret_refs)
5470 frvfdpic_plt_section (info)->size += 4;
5472 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
5473 gpinfop);
5475 /* Allocate the PLT section contents only after
5476 _frvfdpic_assign_plt_entries has a chance to add the size of the
5477 non-lazy PLT entries. */
5478 if (frvfdpic_plt_section (info))
5480 if (frvfdpic_plt_section (info)->size == 0)
5481 frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
5482 else if (frvfdpic_plt_section (info)->contents == NULL)
5484 frvfdpic_plt_section (info)->contents =
5485 (bfd_byte *) bfd_zalloc (dynobj,
5486 frvfdpic_plt_section (info)->size);
5487 if (frvfdpic_plt_section (info)->contents == NULL)
5488 return FALSE;
5492 return TRUE;
5495 /* Set the sizes of the dynamic sections. */
5497 static bfd_boolean
5498 elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
5499 struct bfd_link_info *info)
5501 bfd *dynobj;
5502 asection *s;
5503 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5505 dynobj = elf_hash_table (info)->dynobj;
5506 BFD_ASSERT (dynobj != NULL);
5508 if (elf_hash_table (info)->dynamic_sections_created)
5510 /* Set the contents of the .interp section to the interpreter. */
5511 if (info->executable)
5513 s = bfd_get_section_by_name (dynobj, ".interp");
5514 BFD_ASSERT (s != NULL);
5515 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5516 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
5520 memset (&gpinfo, 0, sizeof (gpinfo));
5521 gpinfo.g.info = info;
5523 for (;;)
5525 htab_t relocs = frvfdpic_relocs_info (info);
5527 htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
5529 if (relocs == frvfdpic_relocs_info (info))
5530 break;
5533 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
5534 &gpinfo.g);
5536 /* Allocate space to save the summary information, we're going to
5537 use it if we're doing relaxations. */
5538 frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
5540 if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
5541 return FALSE;
5543 if (elf_hash_table (info)->dynamic_sections_created)
5545 if (frvfdpic_got_section (info)->size)
5546 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
5547 return FALSE;
5549 if (frvfdpic_pltrel_section (info)->size)
5550 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
5551 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
5552 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
5553 return FALSE;
5555 if (frvfdpic_gotrel_section (info)->size)
5556 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
5557 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
5558 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
5559 sizeof (Elf32_External_Rel)))
5560 return FALSE;
5563 return TRUE;
5566 static bfd_boolean
5567 elf32_frvfdpic_always_size_sections (bfd *output_bfd,
5568 struct bfd_link_info *info)
5570 if (!info->relocatable)
5572 struct elf_link_hash_entry *h;
5574 /* Force a PT_GNU_STACK segment to be created. */
5575 if (! elf_tdata (output_bfd)->stack_flags)
5576 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
5578 /* Define __stacksize if it's not defined yet. */
5579 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
5580 FALSE, FALSE, FALSE);
5581 if (! h || h->root.type != bfd_link_hash_defined
5582 || h->type != STT_OBJECT
5583 || !h->def_regular)
5585 struct bfd_link_hash_entry *bh = NULL;
5587 if (!(_bfd_generic_link_add_one_symbol
5588 (info, output_bfd, "__stacksize",
5589 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
5590 (const char *) NULL, FALSE,
5591 get_elf_backend_data (output_bfd)->collect, &bh)))
5592 return FALSE;
5594 h = (struct elf_link_hash_entry *) bh;
5595 h->def_regular = 1;
5596 h->type = STT_OBJECT;
5597 /* This one must NOT be hidden. */
5601 return TRUE;
5604 /* Look for opportunities to relax TLS relocations. We can assume
5605 we're linking the main executable or a static-tls library, since
5606 otherwise we wouldn't have got here. */
5608 static int
5609 _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_)
5611 struct frvfdpic_relocs_info *entry = *entryp;
5612 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
5614 _frvfdpic_relax_tls_entries (entry, dinfo, TRUE);
5616 return 1;
5619 static bfd_boolean
5620 elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
5621 struct bfd_link_info *info, bfd_boolean *again)
5623 struct _frvfdpic_dynamic_got_plt_info gpinfo;
5625 /* If we return early, we didn't change anything. */
5626 *again = FALSE;
5628 /* We'll do our thing when requested to relax the GOT section. */
5629 if (sec != frvfdpic_got_section (info))
5630 return TRUE;
5632 /* We can only relax when linking the main executable or a library
5633 that can't be dlopened. */
5634 if (! info->executable && ! (info->flags & DF_STATIC_TLS))
5635 return TRUE;
5637 /* If there isn't a TLS section for this binary, we can't do
5638 anything about its TLS relocations (it probably doesn't have
5639 any. */
5640 if (elf_hash_table (info)->tls_sec == NULL)
5641 return TRUE;
5643 memset (&gpinfo, 0, sizeof (gpinfo));
5644 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g));
5646 /* Now look for opportunities to relax, adjusting the GOT usage
5647 as needed. */
5648 htab_traverse (frvfdpic_relocs_info (info),
5649 _frvfdpic_relax_got_plt_entries,
5650 &gpinfo.g);
5652 /* If we changed anything, reset and re-assign GOT and PLT entries. */
5653 if (memcmp (frvfdpic_dynamic_got_plt_info (info),
5654 &gpinfo.g, sizeof (gpinfo.g)) != 0)
5656 /* Clear GOT and PLT assignments. */
5657 htab_traverse (frvfdpic_relocs_info (info),
5658 _frvfdpic_reset_got_plt_entries,
5659 NULL);
5661 /* The owner of the TLS section is the output bfd. There should
5662 be a better way to get to it. */
5663 if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner,
5664 &gpinfo))
5665 return FALSE;
5667 /* Repeat until we don't make any further changes. We could fail to
5668 introduce changes in a round if, for example, the 12-bit range is
5669 full, but we later release some space by getting rid of TLS
5670 descriptors in it. We have to repeat the whole process because
5671 we might have changed the size of a section processed before this
5672 one. */
5673 *again = TRUE;
5676 return TRUE;
5679 static bfd_boolean
5680 elf32_frvfdpic_modify_program_headers (bfd *output_bfd,
5681 struct bfd_link_info *info)
5683 struct elf_obj_tdata *tdata = elf_tdata (output_bfd);
5684 struct elf_segment_map *m;
5685 Elf_Internal_Phdr *p;
5687 /* objcopy and strip preserve what's already there using
5688 elf32_frvfdpic_copy_private_bfd_data (). */
5689 if (! info)
5690 return TRUE;
5692 for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++)
5693 if (m->p_type == PT_GNU_STACK)
5694 break;
5696 if (m)
5698 struct elf_link_hash_entry *h;
5700 /* Obtain the pointer to the __stacksize symbol. */
5701 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
5702 FALSE, FALSE, FALSE);
5703 if (h)
5705 while (h->root.type == bfd_link_hash_indirect
5706 || h->root.type == bfd_link_hash_warning)
5707 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5708 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
5711 /* Set the header p_memsz from the symbol value. We
5712 intentionally ignore the symbol section. */
5713 if (h && h->root.type == bfd_link_hash_defined)
5714 p->p_memsz = h->root.u.def.value;
5715 else
5716 p->p_memsz = DEFAULT_STACK_SIZE;
5718 p->p_align = 8;
5721 return TRUE;
5724 /* Fill in code and data in dynamic sections. */
5726 static bfd_boolean
5727 elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5728 struct bfd_link_info *info ATTRIBUTE_UNUSED)
5730 /* Nothing to be done for non-FDPIC. */
5731 return TRUE;
5734 static bfd_boolean
5735 elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
5736 struct bfd_link_info *info)
5738 bfd *dynobj;
5739 asection *sdyn;
5741 dynobj = elf_hash_table (info)->dynobj;
5743 if (frvfdpic_dynamic_got_plt_info (info))
5745 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0);
5747 if (frvfdpic_got_section (info))
5749 BFD_ASSERT (frvfdpic_gotrel_section (info)->size
5750 == (frvfdpic_gotrel_section (info)->reloc_count
5751 * sizeof (Elf32_External_Rel)));
5753 if (frvfdpic_gotfixup_section (info))
5755 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
5756 bfd_vma got_value = hgot->root.u.def.value
5757 + hgot->root.u.def.section->output_section->vma
5758 + hgot->root.u.def.section->output_offset;
5759 struct bfd_link_hash_entry *hend;
5761 _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
5762 got_value, 0);
5764 if (frvfdpic_gotfixup_section (info)->size
5765 != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
5767 error:
5768 (*_bfd_error_handler)
5769 ("LINKER BUG: .rofixup section size mismatch");
5770 return FALSE;
5773 hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
5774 FALSE, FALSE, TRUE);
5775 if (hend
5776 && (hend->type == bfd_link_hash_defined
5777 || hend->type == bfd_link_hash_defweak))
5779 bfd_vma value =
5780 frvfdpic_gotfixup_section (info)->output_section->vma
5781 + frvfdpic_gotfixup_section (info)->output_offset
5782 + frvfdpic_gotfixup_section (info)->size
5783 - hend->u.def.section->output_section->vma
5784 - hend->u.def.section->output_offset;
5785 BFD_ASSERT (hend->u.def.value == value);
5786 if (hend->u.def.value != value)
5787 goto error;
5791 if (frvfdpic_pltrel_section (info))
5793 BFD_ASSERT (frvfdpic_pltrel_section (info)->size
5794 == (frvfdpic_pltrel_section (info)->reloc_count
5795 * sizeof (Elf32_External_Rel)));
5799 if (elf_hash_table (info)->dynamic_sections_created)
5801 Elf32_External_Dyn * dyncon;
5802 Elf32_External_Dyn * dynconend;
5804 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5806 BFD_ASSERT (sdyn != NULL);
5808 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5809 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5811 for (; dyncon < dynconend; dyncon++)
5813 Elf_Internal_Dyn dyn;
5815 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5817 switch (dyn.d_tag)
5819 default:
5820 break;
5822 case DT_PLTGOT:
5823 dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
5824 + frvfdpic_got_section (info)->output_offset
5825 + frvfdpic_got_initial_offset (info);
5826 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5827 break;
5829 case DT_JMPREL:
5830 dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
5831 ->output_section->vma
5832 + frvfdpic_pltrel_section (info)->output_offset;
5833 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5834 break;
5836 case DT_PLTRELSZ:
5837 dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
5838 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5839 break;
5844 return TRUE;
5847 /* Adjust a symbol defined by a dynamic object and referenced by a
5848 regular object. */
5850 static bfd_boolean
5851 elf32_frvfdpic_adjust_dynamic_symbol
5852 (struct bfd_link_info *info ATTRIBUTE_UNUSED,
5853 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
5855 bfd * dynobj;
5857 dynobj = elf_hash_table (info)->dynobj;
5859 /* Make sure we know what is going on here. */
5860 BFD_ASSERT (dynobj != NULL
5861 && (h->u.weakdef != NULL
5862 || (h->def_dynamic
5863 && h->ref_regular
5864 && !h->def_regular)));
5866 /* If this is a weak symbol, and there is a real definition, the
5867 processor independent code will have arranged for us to see the
5868 real definition first, and we can just use the same value. */
5869 if (h->u.weakdef != NULL)
5871 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5872 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5873 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5874 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5877 return TRUE;
5880 /* Perform any actions needed for dynamic symbols. */
5882 static bfd_boolean
5883 elf32_frvfdpic_finish_dynamic_symbol
5884 (bfd *output_bfd ATTRIBUTE_UNUSED,
5885 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5886 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
5887 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
5889 return TRUE;
5892 /* Decide whether to attempt to turn absptr or lsda encodings in
5893 shared libraries into pcrel within the given input section. */
5895 static bfd_boolean
5896 frvfdpic_elf_use_relative_eh_frame
5897 (bfd *input_bfd ATTRIBUTE_UNUSED,
5898 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5899 asection *eh_frame_section ATTRIBUTE_UNUSED)
5901 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
5902 return FALSE;
5905 /* Adjust the contents of an eh_frame_hdr section before they're output. */
5907 static bfd_byte
5908 frvfdpic_elf_encode_eh_address (bfd *abfd,
5909 struct bfd_link_info *info,
5910 asection *osec, bfd_vma offset,
5911 asection *loc_sec, bfd_vma loc_offset,
5912 bfd_vma *encoded)
5914 struct elf_link_hash_entry *h;
5916 h = elf_hash_table (info)->hgot;
5917 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
5919 if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
5920 == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
5921 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
5922 loc_sec, loc_offset, encoded);
5924 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
5925 == (_frvfdpic_osec_to_segment
5926 (abfd, h->root.u.def.section->output_section)));
5928 *encoded = osec->vma + offset
5929 - (h->root.u.def.value
5930 + h->root.u.def.section->output_section->vma
5931 + h->root.u.def.section->output_offset);
5933 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
5936 /* Look through the relocs for a section during the first phase.
5938 Besides handling virtual table relocs for gc, we have to deal with
5939 all sorts of PIC-related relocations. We describe below the
5940 general plan on how to handle such relocations, even though we only
5941 collect information at this point, storing them in hash tables for
5942 perusal of later passes.
5944 32 relocations are propagated to the linker output when creating
5945 position-independent output. LO16 and HI16 relocations are not
5946 supposed to be encountered in this case.
5948 LABEL16 should always be resolvable by the linker, since it's only
5949 used by branches.
5951 LABEL24, on the other hand, is used by calls. If it turns out that
5952 the target of a call is a dynamic symbol, a PLT entry must be
5953 created for it, which triggers the creation of a private function
5954 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
5956 GPREL relocations require the referenced symbol to be in the same
5957 segment as _gp, but this can only be checked later.
5959 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
5960 exist. LABEL24 might as well, since it may require a PLT entry,
5961 that will require a got.
5963 Non-FUNCDESC GOT relocations require a GOT entry to be created
5964 regardless of whether the symbol is dynamic. However, since a
5965 global symbol that turns out to not be exported may have the same
5966 address of a non-dynamic symbol, we don't assign GOT entries at
5967 this point, such that we can share them in this case. A relocation
5968 for the GOT entry always has to be created, be it to offset a
5969 private symbol by the section load address, be it to get the symbol
5970 resolved dynamically.
5972 FUNCDESC GOT relocations require a GOT entry to be created, and
5973 handled as if a FUNCDESC relocation was applied to the GOT entry in
5974 an object file.
5976 FUNCDESC relocations referencing a symbol that turns out to NOT be
5977 dynamic cause a private function descriptor to be created. The
5978 FUNCDESC relocation then decays to a 32 relocation that points at
5979 the private descriptor. If the symbol is dynamic, the FUNCDESC
5980 relocation is propagated to the linker output, such that the
5981 dynamic linker creates the canonical descriptor, pointing to the
5982 dynamically-resolved definition of the function.
5984 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
5985 symbols that are assigned to the same segment as the GOT, but we
5986 can only check this later, after we know the complete set of
5987 symbols defined and/or exported.
5989 FUNCDESC GOTOFF relocations require a function descriptor to be
5990 created and, unless lazy binding is disabled or the symbol is not
5991 dynamic, a lazy PLT entry. Since we can't tell at this point
5992 whether a symbol is going to be dynamic, we have to decide later
5993 whether to create a lazy PLT entry or bind the descriptor directly
5994 to the private function.
5996 FUNCDESC_VALUE relocations are not supposed to be present in object
5997 files, but they may very well be simply propagated to the linker
5998 output, since they have no side effect.
6001 A function descriptor always requires a FUNCDESC_VALUE relocation.
6002 Whether it's in .plt.rel or not depends on whether lazy binding is
6003 enabled and on whether the referenced symbol is dynamic.
6005 The existence of a lazy PLT requires the resolverStub lazy PLT
6006 entry to be present.
6009 As for assignment of GOT, PLT and lazy PLT entries, and private
6010 descriptors, we might do them all sequentially, but we can do
6011 better than that. For example, we can place GOT entries and
6012 private function descriptors referenced using 12-bit operands
6013 closer to the PIC register value, such that these relocations don't
6014 overflow. Those that are only referenced with LO16 relocations
6015 could come next, but we may as well place PLT-required function
6016 descriptors in the 12-bit range to make them shorter. Symbols
6017 referenced with LO16/HI16 may come next, but we may place
6018 additional function descriptors in the 16-bit range if we can
6019 reliably tell that we've already placed entries that are ever
6020 referenced with only LO16. PLT entries are therefore generated as
6021 small as possible, while not introducing relocation overflows in
6022 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
6023 generated before or after PLT entries, but not intermingled with
6024 them, such that we can have more lazy PLT entries in range for a
6025 branch to the resolverStub. The resolverStub should be emitted at
6026 the most distant location from the first lazy PLT entry such that
6027 it's still in range for a branch, or closer, if there isn't a need
6028 for so many lazy PLT entries. Additional lazy PLT entries may be
6029 emitted after the resolverStub, as long as branches are still in
6030 range. If the branch goes out of range, longer lazy PLT entries
6031 are emitted.
6033 We could further optimize PLT and lazy PLT entries by giving them
6034 priority in assignment to closer-to-gr17 locations depending on the
6035 number of occurrences of references to them (assuming a function
6036 that's called more often is more important for performance, so its
6037 PLT entry should be faster), or taking hints from the compiler.
6038 Given infinite time and money... :-) */
6040 static bfd_boolean
6041 elf32_frv_check_relocs (abfd, info, sec, relocs)
6042 bfd *abfd;
6043 struct bfd_link_info *info;
6044 asection *sec;
6045 const Elf_Internal_Rela *relocs;
6047 Elf_Internal_Shdr *symtab_hdr;
6048 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6049 const Elf_Internal_Rela *rel;
6050 const Elf_Internal_Rela *rel_end;
6051 bfd *dynobj;
6052 struct frvfdpic_relocs_info *picrel;
6054 if (info->relocatable)
6055 return TRUE;
6057 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6058 sym_hashes = elf_sym_hashes (abfd);
6059 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
6060 if (!elf_bad_symtab (abfd))
6061 sym_hashes_end -= symtab_hdr->sh_info;
6063 dynobj = elf_hash_table (info)->dynobj;
6064 rel_end = relocs + sec->reloc_count;
6065 for (rel = relocs; rel < rel_end; rel++)
6067 struct elf_link_hash_entry *h;
6068 unsigned long r_symndx;
6070 r_symndx = ELF32_R_SYM (rel->r_info);
6071 if (r_symndx < symtab_hdr->sh_info)
6072 h = NULL;
6073 else
6075 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6076 while (h->root.type == bfd_link_hash_indirect
6077 || h->root.type == bfd_link_hash_warning)
6078 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6081 switch (ELF32_R_TYPE (rel->r_info))
6083 case R_FRV_GETTLSOFF:
6084 case R_FRV_TLSDESC_VALUE:
6085 case R_FRV_GOTTLSDESC12:
6086 case R_FRV_GOTTLSDESCHI:
6087 case R_FRV_GOTTLSDESCLO:
6088 case R_FRV_GOTTLSOFF12:
6089 case R_FRV_GOTTLSOFFHI:
6090 case R_FRV_GOTTLSOFFLO:
6091 case R_FRV_TLSOFF:
6092 case R_FRV_GOT12:
6093 case R_FRV_GOTHI:
6094 case R_FRV_GOTLO:
6095 case R_FRV_FUNCDESC_GOT12:
6096 case R_FRV_FUNCDESC_GOTHI:
6097 case R_FRV_FUNCDESC_GOTLO:
6098 case R_FRV_GOTOFF12:
6099 case R_FRV_GOTOFFHI:
6100 case R_FRV_GOTOFFLO:
6101 case R_FRV_FUNCDESC_GOTOFF12:
6102 case R_FRV_FUNCDESC_GOTOFFHI:
6103 case R_FRV_FUNCDESC_GOTOFFLO:
6104 case R_FRV_FUNCDESC:
6105 case R_FRV_FUNCDESC_VALUE:
6106 case R_FRV_TLSMOFF12:
6107 case R_FRV_TLSMOFFHI:
6108 case R_FRV_TLSMOFFLO:
6109 case R_FRV_TLSMOFF:
6110 if (! IS_FDPIC (abfd))
6111 goto bad_reloc;
6112 /* Fall through. */
6113 case R_FRV_GPREL12:
6114 case R_FRV_GPRELU12:
6115 case R_FRV_GPRELHI:
6116 case R_FRV_GPRELLO:
6117 case R_FRV_LABEL24:
6118 case R_FRV_32:
6119 if (! dynobj)
6121 elf_hash_table (info)->dynobj = dynobj = abfd;
6122 if (! _frv_create_got_section (abfd, info))
6123 return FALSE;
6125 if (! IS_FDPIC (abfd))
6127 picrel = NULL;
6128 break;
6130 if (h != NULL)
6132 if (h->dynindx == -1)
6133 switch (ELF_ST_VISIBILITY (h->other))
6135 case STV_INTERNAL:
6136 case STV_HIDDEN:
6137 break;
6138 default:
6139 bfd_elf_link_record_dynamic_symbol (info, h);
6140 break;
6142 picrel
6143 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
6144 abfd, h,
6145 rel->r_addend, INSERT);
6147 else
6148 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
6149 (info), abfd, r_symndx,
6150 rel->r_addend, INSERT);
6151 if (! picrel)
6152 return FALSE;
6153 break;
6155 default:
6156 picrel = NULL;
6157 break;
6160 switch (ELF32_R_TYPE (rel->r_info))
6162 case R_FRV_LABEL24:
6163 if (IS_FDPIC (abfd))
6164 picrel->call = 1;
6165 break;
6167 case R_FRV_FUNCDESC_VALUE:
6168 picrel->relocsfdv++;
6169 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6170 picrel->relocs32--;
6171 /* Fall through. */
6173 case R_FRV_32:
6174 if (! IS_FDPIC (abfd))
6175 break;
6177 picrel->sym = 1;
6178 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
6179 picrel->relocs32++;
6180 break;
6182 case R_FRV_GOT12:
6183 picrel->got12 = 1;
6184 break;
6186 case R_FRV_GOTHI:
6187 case R_FRV_GOTLO:
6188 picrel->gothilo = 1;
6189 break;
6191 case R_FRV_FUNCDESC_GOT12:
6192 picrel->fdgot12 = 1;
6193 break;
6195 case R_FRV_FUNCDESC_GOTHI:
6196 case R_FRV_FUNCDESC_GOTLO:
6197 picrel->fdgothilo = 1;
6198 break;
6200 case R_FRV_GOTOFF12:
6201 case R_FRV_GOTOFFHI:
6202 case R_FRV_GOTOFFLO:
6203 picrel->gotoff = 1;
6204 break;
6206 case R_FRV_FUNCDESC_GOTOFF12:
6207 picrel->fdgoff12 = 1;
6208 break;
6210 case R_FRV_FUNCDESC_GOTOFFHI:
6211 case R_FRV_FUNCDESC_GOTOFFLO:
6212 picrel->fdgoffhilo = 1;
6213 break;
6215 case R_FRV_FUNCDESC:
6216 picrel->fd = 1;
6217 picrel->relocsfd++;
6218 break;
6220 case R_FRV_GETTLSOFF:
6221 picrel->tlsplt = 1;
6222 break;
6224 case R_FRV_TLSDESC_VALUE:
6225 picrel->relocstlsd++;
6226 goto bad_reloc;
6228 case R_FRV_GOTTLSDESC12:
6229 picrel->tlsdesc12 = 1;
6230 break;
6232 case R_FRV_GOTTLSDESCHI:
6233 case R_FRV_GOTTLSDESCLO:
6234 picrel->tlsdeschilo = 1;
6235 break;
6237 case R_FRV_TLSMOFF12:
6238 case R_FRV_TLSMOFFHI:
6239 case R_FRV_TLSMOFFLO:
6240 case R_FRV_TLSMOFF:
6241 break;
6243 case R_FRV_GOTTLSOFF12:
6244 picrel->tlsoff12 = 1;
6245 info->flags |= DF_STATIC_TLS;
6246 break;
6248 case R_FRV_GOTTLSOFFHI:
6249 case R_FRV_GOTTLSOFFLO:
6250 picrel->tlsoffhilo = 1;
6251 info->flags |= DF_STATIC_TLS;
6252 break;
6254 case R_FRV_TLSOFF:
6255 picrel->relocstlsoff++;
6256 info->flags |= DF_STATIC_TLS;
6257 goto bad_reloc;
6259 /* This relocation describes the C++ object vtable hierarchy.
6260 Reconstruct it for later use during GC. */
6261 case R_FRV_GNU_VTINHERIT:
6262 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6263 return FALSE;
6264 break;
6266 /* This relocation describes which C++ vtable entries are actually
6267 used. Record for later use during GC. */
6268 case R_FRV_GNU_VTENTRY:
6269 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6270 return FALSE;
6271 break;
6273 case R_FRV_LABEL16:
6274 case R_FRV_LO16:
6275 case R_FRV_HI16:
6276 case R_FRV_GPREL12:
6277 case R_FRV_GPRELU12:
6278 case R_FRV_GPREL32:
6279 case R_FRV_GPRELHI:
6280 case R_FRV_GPRELLO:
6281 case R_FRV_TLSDESC_RELAX:
6282 case R_FRV_GETTLSOFF_RELAX:
6283 case R_FRV_TLSOFF_RELAX:
6284 break;
6286 default:
6287 bad_reloc:
6288 (*_bfd_error_handler)
6289 (_("%B: unsupported relocation type %i"),
6290 abfd, ELF32_R_TYPE (rel->r_info));
6291 return FALSE;
6295 return TRUE;
6299 /* Return the machine subcode from the ELF e_flags header. */
6301 static int
6302 elf32_frv_machine (abfd)
6303 bfd *abfd;
6305 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
6307 default: break;
6308 case EF_FRV_CPU_FR550: return bfd_mach_fr550;
6309 case EF_FRV_CPU_FR500: return bfd_mach_fr500;
6310 case EF_FRV_CPU_FR450: return bfd_mach_fr450;
6311 case EF_FRV_CPU_FR405: return bfd_mach_fr400;
6312 case EF_FRV_CPU_FR400: return bfd_mach_fr400;
6313 case EF_FRV_CPU_FR300: return bfd_mach_fr300;
6314 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
6315 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
6318 return bfd_mach_frv;
6321 /* Set the right machine number for a FRV ELF file. */
6323 static bfd_boolean
6324 elf32_frv_object_p (abfd)
6325 bfd *abfd;
6327 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
6328 return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
6329 == (IS_FDPIC (abfd)));
6332 /* Function to set the ELF flag bits. */
6334 static bfd_boolean
6335 frv_elf_set_private_flags (abfd, flags)
6336 bfd *abfd;
6337 flagword flags;
6339 elf_elfheader (abfd)->e_flags = flags;
6340 elf_flags_init (abfd) = TRUE;
6341 return TRUE;
6344 /* Copy backend specific data from one object module to another. */
6346 static bfd_boolean
6347 frv_elf_copy_private_bfd_data (ibfd, obfd)
6348 bfd *ibfd;
6349 bfd *obfd;
6351 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6352 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6353 return TRUE;
6355 BFD_ASSERT (!elf_flags_init (obfd)
6356 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
6358 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6359 elf_flags_init (obfd) = TRUE;
6360 return TRUE;
6363 /* Return true if the architecture described by elf header flag
6364 EXTENSION is an extension of the architecture described by BASE. */
6366 static bfd_boolean
6367 frv_elf_arch_extension_p (flagword base, flagword extension)
6369 if (base == extension)
6370 return TRUE;
6372 /* CPU_GENERIC code can be merged with code for a specific
6373 architecture, in which case the result is marked as being
6374 for the specific architecture. Everything is therefore
6375 an extension of CPU_GENERIC. */
6376 if (base == EF_FRV_CPU_GENERIC)
6377 return TRUE;
6379 if (extension == EF_FRV_CPU_FR450)
6380 if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
6381 return TRUE;
6383 if (extension == EF_FRV_CPU_FR405)
6384 if (base == EF_FRV_CPU_FR400)
6385 return TRUE;
6387 return FALSE;
6390 static bfd_boolean
6391 elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6393 unsigned i;
6395 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6396 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6397 return TRUE;
6399 if (! frv_elf_copy_private_bfd_data (ibfd, obfd))
6400 return FALSE;
6402 if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
6403 || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
6404 return TRUE;
6406 /* Copy the stack size. */
6407 for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
6408 if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
6410 Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
6412 for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
6413 if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
6415 memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
6417 /* Rewrite the phdrs, since we're only called after they
6418 were first written. */
6419 if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd)
6420 ->s->sizeof_ehdr, SEEK_SET) != 0
6421 || get_elf_backend_data (obfd)->s
6422 ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
6423 elf_elfheader (obfd)->e_phnum) != 0)
6424 return FALSE;
6425 break;
6428 break;
6431 return TRUE;
6434 /* Merge backend specific data from an object file to the output
6435 object file when linking. */
6437 static bfd_boolean
6438 frv_elf_merge_private_bfd_data (ibfd, obfd)
6439 bfd *ibfd;
6440 bfd *obfd;
6442 flagword old_flags, old_partial;
6443 flagword new_flags, new_partial;
6444 bfd_boolean error = FALSE;
6445 char new_opt[80];
6446 char old_opt[80];
6448 new_opt[0] = old_opt[0] = '\0';
6449 new_flags = elf_elfheader (ibfd)->e_flags;
6450 old_flags = elf_elfheader (obfd)->e_flags;
6452 if (new_flags & EF_FRV_FDPIC)
6453 new_flags &= ~EF_FRV_PIC;
6455 #ifdef DEBUG
6456 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
6457 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
6458 bfd_get_filename (ibfd));
6459 #endif
6461 if (!elf_flags_init (obfd)) /* First call, no flags set. */
6463 elf_flags_init (obfd) = TRUE;
6464 old_flags = new_flags;
6467 else if (new_flags == old_flags) /* Compatible flags are ok. */
6470 else /* Possibly incompatible flags. */
6472 /* Warn if different # of gprs are used. Note, 0 means nothing is
6473 said about the size of gprs. */
6474 new_partial = (new_flags & EF_FRV_GPR_MASK);
6475 old_partial = (old_flags & EF_FRV_GPR_MASK);
6476 if (new_partial == old_partial)
6479 else if (new_partial == 0)
6482 else if (old_partial == 0)
6483 old_flags |= new_partial;
6485 else
6487 switch (new_partial)
6489 default: strcat (new_opt, " -mgpr-??"); break;
6490 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
6491 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
6494 switch (old_partial)
6496 default: strcat (old_opt, " -mgpr-??"); break;
6497 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
6498 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
6502 /* Warn if different # of fprs are used. Note, 0 means nothing is
6503 said about the size of fprs. */
6504 new_partial = (new_flags & EF_FRV_FPR_MASK);
6505 old_partial = (old_flags & EF_FRV_FPR_MASK);
6506 if (new_partial == old_partial)
6509 else if (new_partial == 0)
6512 else if (old_partial == 0)
6513 old_flags |= new_partial;
6515 else
6517 switch (new_partial)
6519 default: strcat (new_opt, " -mfpr-?"); break;
6520 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
6521 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
6522 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
6525 switch (old_partial)
6527 default: strcat (old_opt, " -mfpr-?"); break;
6528 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
6529 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
6530 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
6534 /* Warn if different dword support was used. Note, 0 means nothing is
6535 said about the dword support. */
6536 new_partial = (new_flags & EF_FRV_DWORD_MASK);
6537 old_partial = (old_flags & EF_FRV_DWORD_MASK);
6538 if (new_partial == old_partial)
6541 else if (new_partial == 0)
6544 else if (old_partial == 0)
6545 old_flags |= new_partial;
6547 else
6549 switch (new_partial)
6551 default: strcat (new_opt, " -mdword-?"); break;
6552 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
6553 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
6556 switch (old_partial)
6558 default: strcat (old_opt, " -mdword-?"); break;
6559 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
6560 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
6564 /* Or in flags that accumulate (ie, if one module uses it, mark that the
6565 feature is used. */
6566 old_flags |= new_flags & (EF_FRV_DOUBLE
6567 | EF_FRV_MEDIA
6568 | EF_FRV_MULADD
6569 | EF_FRV_NON_PIC_RELOCS);
6571 /* If any module was compiled without -G0, clear the G0 bit. */
6572 old_flags = ((old_flags & ~ EF_FRV_G0)
6573 | (old_flags & new_flags & EF_FRV_G0));
6575 /* If any module was compiled without -mnopack, clear the mnopack bit. */
6576 old_flags = ((old_flags & ~ EF_FRV_NOPACK)
6577 | (old_flags & new_flags & EF_FRV_NOPACK));
6579 /* We don't have to do anything if the pic flags are the same, or the new
6580 module(s) were compiled with -mlibrary-pic. */
6581 new_partial = (new_flags & EF_FRV_PIC_FLAGS);
6582 old_partial = (old_flags & EF_FRV_PIC_FLAGS);
6583 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
6586 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
6587 flags if any from the new module. */
6588 else if ((old_partial & EF_FRV_LIBPIC) != 0)
6589 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
6591 /* If we have mixtures of -fpic and -fPIC, or in both bits. */
6592 else if (new_partial != 0 && old_partial != 0)
6593 old_flags |= new_partial;
6595 /* One module was compiled for pic and the other was not, see if we have
6596 had any relocations that are not pic-safe. */
6597 else
6599 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
6600 old_flags |= new_partial;
6601 else
6603 old_flags &= ~ EF_FRV_PIC_FLAGS;
6604 #ifndef FRV_NO_PIC_ERROR
6605 error = TRUE;
6606 (*_bfd_error_handler)
6607 (_("%s: compiled with %s and linked with modules that use non-pic relocations"),
6608 bfd_get_filename (ibfd),
6609 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
6610 #endif
6614 /* Warn if different cpu is used (allow a specific cpu to override
6615 the generic cpu). */
6616 new_partial = (new_flags & EF_FRV_CPU_MASK);
6617 old_partial = (old_flags & EF_FRV_CPU_MASK);
6618 if (frv_elf_arch_extension_p (new_partial, old_partial))
6621 else if (frv_elf_arch_extension_p (old_partial, new_partial))
6622 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
6624 else
6626 switch (new_partial)
6628 default: strcat (new_opt, " -mcpu=?"); break;
6629 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
6630 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
6631 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
6632 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
6633 case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break;
6634 case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break;
6635 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
6636 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
6637 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
6640 switch (old_partial)
6642 default: strcat (old_opt, " -mcpu=?"); break;
6643 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
6644 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
6645 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
6646 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
6647 case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break;
6648 case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break;
6649 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
6650 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
6651 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
6655 /* Print out any mismatches from above. */
6656 if (new_opt[0])
6658 error = TRUE;
6659 (*_bfd_error_handler)
6660 (_("%s: compiled with %s and linked with modules compiled with %s"),
6661 bfd_get_filename (ibfd), new_opt, old_opt);
6664 /* Warn about any other mismatches */
6665 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
6666 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
6667 if (new_partial != old_partial)
6669 old_flags |= new_partial;
6670 error = TRUE;
6671 (*_bfd_error_handler)
6672 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
6673 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
6677 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
6678 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
6679 old_flags |= EF_FRV_NOPACK;
6681 /* Update the old flags now with changes made above. */
6682 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
6683 elf_elfheader (obfd)->e_flags = old_flags;
6684 if (old_partial != (old_flags & EF_FRV_CPU_MASK))
6685 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
6687 if (((new_flags & EF_FRV_FDPIC) == 0)
6688 != (! IS_FDPIC (ibfd)))
6690 error = TRUE;
6691 if (IS_FDPIC (obfd))
6692 (*_bfd_error_handler)
6693 (_("%s: cannot link non-fdpic object file into fdpic executable"),
6694 bfd_get_filename (ibfd));
6695 else
6696 (*_bfd_error_handler)
6697 (_("%s: cannot link fdpic object file into non-fdpic executable"),
6698 bfd_get_filename (ibfd));
6701 if (error)
6702 bfd_set_error (bfd_error_bad_value);
6704 return !error;
6708 bfd_boolean
6709 frv_elf_print_private_bfd_data (abfd, ptr)
6710 bfd *abfd;
6711 PTR ptr;
6713 FILE *file = (FILE *) ptr;
6714 flagword flags;
6716 BFD_ASSERT (abfd != NULL && ptr != NULL);
6718 /* Print normal ELF private data. */
6719 _bfd_elf_print_private_bfd_data (abfd, ptr);
6721 flags = elf_elfheader (abfd)->e_flags;
6722 fprintf (file, _("private flags = 0x%lx:"), (long)flags);
6724 switch (flags & EF_FRV_CPU_MASK)
6726 default: break;
6727 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
6728 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
6729 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
6730 case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break;
6731 case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break;
6732 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
6733 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
6734 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
6737 switch (flags & EF_FRV_GPR_MASK)
6739 default: break;
6740 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
6741 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
6744 switch (flags & EF_FRV_FPR_MASK)
6746 default: break;
6747 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
6748 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
6749 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
6752 switch (flags & EF_FRV_DWORD_MASK)
6754 default: break;
6755 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
6756 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
6759 if (flags & EF_FRV_DOUBLE)
6760 fprintf (file, " -mdouble");
6762 if (flags & EF_FRV_MEDIA)
6763 fprintf (file, " -mmedia");
6765 if (flags & EF_FRV_MULADD)
6766 fprintf (file, " -mmuladd");
6768 if (flags & EF_FRV_PIC)
6769 fprintf (file, " -fpic");
6771 if (flags & EF_FRV_BIGPIC)
6772 fprintf (file, " -fPIC");
6774 if (flags & EF_FRV_LIBPIC)
6775 fprintf (file, " -mlibrary-pic");
6777 if (flags & EF_FRV_FDPIC)
6778 fprintf (file, " -mfdpic");
6780 if (flags & EF_FRV_NON_PIC_RELOCS)
6781 fprintf (file, " non-pic relocations");
6783 if (flags & EF_FRV_G0)
6784 fprintf (file, " -G0");
6786 fputc ('\n', file);
6787 return TRUE;
6791 /* Support for core dump NOTE sections. */
6793 static bfd_boolean
6794 elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
6796 int offset;
6797 unsigned int raw_size;
6799 switch (note->descsz)
6801 default:
6802 return FALSE;
6804 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
6805 hardcoded offsets and sizes listed below (and contained within
6806 this lexical block) refer to fields in the target's elf_prstatus
6807 struct. */
6808 case 268:
6809 /* `pr_cursig' is at offset 12. */
6810 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
6812 /* `pr_pid' is at offset 24. */
6813 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
6815 /* `pr_reg' is at offset 72. */
6816 offset = 72;
6818 /* Most grok_prstatus implementations set `raw_size' to the size
6819 of the pr_reg field. For Linux/FRV, we set `raw_size' to be
6820 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
6821 and `pr_interp_fdpic_loadmap', both of which (by design)
6822 immediately follow `pr_reg'. This will allow these fields to
6823 be viewed by GDB as registers.
6825 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
6826 `pr_interp_fdpic_loadmap' are 4 bytes each. */
6827 raw_size = 184 + 4 + 4;
6829 break;
6832 /* Make a ".reg/999" section. */
6833 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
6834 note->descpos + offset);
6837 static bfd_boolean
6838 elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
6840 switch (note->descsz)
6842 default:
6843 return FALSE;
6845 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
6846 case 124:
6848 /* `pr_fname' is found at offset 28 and is 16 bytes long. */
6849 elf_tdata (abfd)->core_program
6850 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
6852 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
6853 elf_tdata (abfd)->core_command
6854 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
6857 /* Note that for some reason, a spurious space is tacked
6858 onto the end of the args in some (at least one anyway)
6859 implementations, so strip it off if it exists. */
6862 char *command = elf_tdata (abfd)->core_command;
6863 int n = strlen (command);
6865 if (0 < n && command[n - 1] == ' ')
6866 command[n - 1] = '\0';
6869 return TRUE;
6871 #define ELF_ARCH bfd_arch_frv
6872 #define ELF_MACHINE_CODE EM_CYGNUS_FRV
6873 #define ELF_MAXPAGESIZE 0x1000
6875 #define TARGET_BIG_SYM bfd_elf32_frv_vec
6876 #define TARGET_BIG_NAME "elf32-frv"
6878 #define elf_info_to_howto frv_info_to_howto_rela
6879 #define elf_backend_relocate_section elf32_frv_relocate_section
6880 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
6881 #define elf_backend_check_relocs elf32_frv_check_relocs
6882 #define elf_backend_object_p elf32_frv_object_p
6883 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
6885 #define elf_backend_can_gc_sections 1
6886 #define elf_backend_rela_normal 1
6888 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
6889 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
6890 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
6891 #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data
6892 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
6893 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
6895 #define elf_backend_want_got_sym 1
6896 #define elf_backend_got_header_size 0
6897 #define elf_backend_want_got_plt 0
6898 #define elf_backend_plt_readonly 1
6899 #define elf_backend_want_plt_sym 0
6900 #define elf_backend_plt_header_size 0
6902 #define elf_backend_finish_dynamic_sections \
6903 elf32_frv_finish_dynamic_sections
6905 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
6906 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
6908 #include "elf32-target.h"
6910 #undef ELF_MAXPAGESIZE
6911 #define ELF_MAXPAGESIZE 0x4000
6913 #undef TARGET_BIG_SYM
6914 #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec
6915 #undef TARGET_BIG_NAME
6916 #define TARGET_BIG_NAME "elf32-frvfdpic"
6917 #undef elf32_bed
6918 #define elf32_bed elf32_frvfdpic_bed
6920 #undef elf_info_to_howto_rel
6921 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
6923 #undef bfd_elf32_bfd_link_hash_table_create
6924 #define bfd_elf32_bfd_link_hash_table_create \
6925 frvfdpic_elf_link_hash_table_create
6926 #undef elf_backend_always_size_sections
6927 #define elf_backend_always_size_sections \
6928 elf32_frvfdpic_always_size_sections
6929 #undef elf_backend_modify_program_headers
6930 #define elf_backend_modify_program_headers \
6931 elf32_frvfdpic_modify_program_headers
6932 #undef bfd_elf32_bfd_copy_private_bfd_data
6933 #define bfd_elf32_bfd_copy_private_bfd_data \
6934 elf32_frvfdpic_copy_private_bfd_data
6936 #undef elf_backend_create_dynamic_sections
6937 #define elf_backend_create_dynamic_sections \
6938 elf32_frvfdpic_create_dynamic_sections
6939 #undef elf_backend_adjust_dynamic_symbol
6940 #define elf_backend_adjust_dynamic_symbol \
6941 elf32_frvfdpic_adjust_dynamic_symbol
6942 #undef elf_backend_size_dynamic_sections
6943 #define elf_backend_size_dynamic_sections \
6944 elf32_frvfdpic_size_dynamic_sections
6945 #undef bfd_elf32_bfd_relax_section
6946 #define bfd_elf32_bfd_relax_section \
6947 elf32_frvfdpic_relax_section
6948 #undef elf_backend_finish_dynamic_symbol
6949 #define elf_backend_finish_dynamic_symbol \
6950 elf32_frvfdpic_finish_dynamic_symbol
6951 #undef elf_backend_finish_dynamic_sections
6952 #define elf_backend_finish_dynamic_sections \
6953 elf32_frvfdpic_finish_dynamic_sections
6955 #undef elf_backend_can_make_relative_eh_frame
6956 #define elf_backend_can_make_relative_eh_frame \
6957 frvfdpic_elf_use_relative_eh_frame
6958 #undef elf_backend_can_make_lsda_relative_eh_frame
6959 #define elf_backend_can_make_lsda_relative_eh_frame \
6960 frvfdpic_elf_use_relative_eh_frame
6961 #undef elf_backend_encode_eh_address
6962 #define elf_backend_encode_eh_address \
6963 frvfdpic_elf_encode_eh_address
6965 #undef elf_backend_may_use_rel_p
6966 #define elf_backend_may_use_rel_p 1
6967 #undef elf_backend_may_use_rela_p
6968 #define elf_backend_may_use_rela_p 1
6969 /* We use REL for dynamic relocations only. */
6970 #undef elf_backend_default_use_rela_p
6971 #define elf_backend_default_use_rela_p 1
6973 #undef elf_backend_omit_section_dynsym
6974 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
6976 #include "elf32-target.h"