1 /* Or1k-specific support for 32-bit ELF.
2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 Contributed for OR32 by Johan Rydberg, jrydberg@opencores.org
5 PIC parts added by Stefan Kristiansson, stefan.kristiansson@saunalahti.fi,
6 largely based on elf32-m32r.c and elf32-microblaze.c.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, see <http://www.gnu.org/licenses/>. */
28 #include "libiberty.h"
30 #define N_ONES(X) (((bfd_vma)2 << (X)) - 1)
32 #define PLT_ENTRY_SIZE 16
34 #define OR1K_MOVHI(D) (0x18000000 | (D << 21))
35 #define OR1K_ADRP(D) (0x08000000 | (D << 21))
36 #define OR1K_LWZ(D,A) (0x84000000 | (D << 21) | (A << 16))
37 #define OR1K_ORI0(D) (0xA8000000 | (D << 21))
38 #define OR1K_JR(B) (0x44000000 | (B << 11))
39 #define OR1K_NOP 0x15000000
41 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
43 static reloc_howto_type or1k_elf_howto_table
[] =
45 /* This reloc does nothing. */
46 HOWTO (R_OR1K_NONE
, /* type */
48 3, /* size (0 = byte, 1 = short, 2 = long) */
50 FALSE
, /* pc_relative */
52 complain_overflow_dont
, /* complain_on_overflow */
53 bfd_elf_generic_reloc
, /* special_function */
54 "R_OR1K_NONE", /* name */
55 FALSE
, /* partial_inplace */
58 FALSE
), /* pcrel_offset */
62 2, /* size (0 = byte, 1 = short, 2 = long) */
64 FALSE
, /* pc_relative */
66 complain_overflow_unsigned
, /* complain_on_overflow */
67 bfd_elf_generic_reloc
, /* special_function */
68 "R_OR1K_32", /* name */
69 FALSE
, /* partial_inplace */
71 0xffffffff, /* dst_mask */
72 FALSE
), /* pcrel_offset */
76 1, /* size (0 = byte, 1 = short, 2 = long) */
78 FALSE
, /* pc_relative */
80 complain_overflow_unsigned
, /* complain_on_overflow */
81 bfd_elf_generic_reloc
, /* special_function */
82 "R_OR1K_16", /* name */
83 FALSE
, /* partial_inplace */
85 0xffff, /* dst_mask */
86 FALSE
), /* pcrel_offset */
90 0, /* size (0 = byte, 1 = short, 2 = long) */
92 FALSE
, /* pc_relative */
94 complain_overflow_unsigned
, /* complain_on_overflow */
95 bfd_elf_generic_reloc
, /* special_function */
96 "R_OR1K_8", /* name */
97 FALSE
, /* partial_inplace */
100 FALSE
), /* pcrel_offset */
102 HOWTO (R_OR1K_LO_16_IN_INSN
, /* type */
104 2, /* size (0 = byte, 1 = short, 2 = long) */
106 FALSE
, /* pc_relative */
108 complain_overflow_dont
, /* complain_on_overflow */
109 bfd_elf_generic_reloc
, /* special_function */
110 "R_OR1K_LO_16_IN_INSN", /* name */
111 FALSE
, /* partial_inplace */
113 0x0000ffff, /* dst_mask */
114 FALSE
), /* pcrel_offset */
116 HOWTO (R_OR1K_HI_16_IN_INSN
, /* type */
118 2, /* size (0 = byte, 1 = short, 2 = long) */
120 FALSE
, /* pc_relative */
122 complain_overflow_dont
, /* complain_on_overflow */
123 bfd_elf_generic_reloc
, /* special_function */
124 "R_OR1K_HI_16_IN_INSN", /* name */
125 FALSE
, /* partial_inplace */
127 0x0000ffff, /* dst_mask */
128 FALSE
), /* pcrel_offset */
130 /* A PC relative 26 bit relocation, right shifted by 2. */
131 HOWTO (R_OR1K_INSN_REL_26
, /* type */
133 2, /* size (0 = byte, 1 = short, 2 = long) */
135 TRUE
, /* pc_relative */
137 complain_overflow_signed
, /* complain_on_overflow */
138 bfd_elf_generic_reloc
, /* special_function */
139 "R_OR1K_INSN_REL_26", /* name */
140 FALSE
, /* partial_inplace */
142 0x03ffffff, /* dst_mask */
143 TRUE
), /* pcrel_offset */
145 /* GNU extension to record C++ vtable hierarchy. */
146 HOWTO (R_OR1K_GNU_VTINHERIT
, /* type */
148 2, /* size (0 = byte, 1 = short, 2 = long) */
150 FALSE
, /* pc_relative */
152 complain_overflow_dont
, /* complain_on_overflow */
153 NULL
, /* special_function */
154 "R_OR1K_GNU_VTINHERIT", /* name */
155 FALSE
, /* partial_inplace */
158 FALSE
), /* pcrel_offset */
160 /* GNU extension to record C++ vtable member usage. */
161 HOWTO (R_OR1K_GNU_VTENTRY
, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 FALSE
, /* pc_relative */
167 complain_overflow_dont
, /* complain_on_overflow */
168 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
169 "R_OR1K_GNU_VTENTRY", /* name */
170 FALSE
, /* partial_inplace */
173 FALSE
), /* pcrel_offset */
175 HOWTO (R_OR1K_32_PCREL
,
177 2, /* size (0 = byte, 1 = short, 2 = long) */
179 TRUE
, /* pc_relative */
181 complain_overflow_signed
, /* complain_on_overflow */
182 bfd_elf_generic_reloc
, /* special_function */
183 "R_OR1K_32_PCREL", /* name */
184 FALSE
, /* partial_inplace */
186 0xffffffff, /* dst_mask */
187 TRUE
), /* pcrel_offset */
189 HOWTO (R_OR1K_16_PCREL
,
191 1, /* size (0 = byte, 1 = short, 2 = long) */
193 TRUE
, /* pc_relative */
195 complain_overflow_signed
, /* complain_on_overflow */
196 bfd_elf_generic_reloc
, /* special_function */
197 "R_OR1K_16_PCREL", /* name */
198 FALSE
, /* partial_inplace */
200 0xffff, /* dst_mask */
201 TRUE
), /* pcrel_offset */
203 HOWTO (R_OR1K_8_PCREL
,
205 0, /* size (0 = byte, 1 = short, 2 = long) */
207 TRUE
, /* pc_relative */
209 complain_overflow_signed
, /* complain_on_overflow */
210 bfd_elf_generic_reloc
, /* special_function */
211 "R_OR1K_8_PCREL", /* name */
212 FALSE
, /* partial_inplace */
215 TRUE
), /* pcrel_offset */
217 HOWTO (R_OR1K_GOTPC_HI16
, /* Type. */
218 16, /* Rightshift. */
219 2, /* Size (0 = byte, 1 = short, 2 = long). */
221 TRUE
, /* PC_relative. */
223 complain_overflow_dont
, /* Complain on overflow. */
224 bfd_elf_generic_reloc
, /* Special Function. */
225 "R_OR1K_GOTPC_HI16", /* Name. */
226 FALSE
, /* Partial Inplace. */
227 0, /* Source Mask. */
228 0xffff, /* Dest Mask. */
229 TRUE
), /* PC relative offset? */
231 HOWTO (R_OR1K_GOTPC_LO16
, /* Type. */
233 2, /* Size (0 = byte, 1 = short, 2 = long). */
235 TRUE
, /* PC_relative. */
237 complain_overflow_dont
, /* Complain on overflow. */
238 bfd_elf_generic_reloc
, /* Special Function. */
239 "R_OR1K_GOTPC_LO16", /* Name. */
240 FALSE
, /* Partial Inplace. */
241 0, /* Source Mask. */
242 0xffff, /* Dest Mask. */
243 TRUE
), /* PC relative offset? */
245 HOWTO (R_OR1K_GOT16
, /* type */
247 2, /* size (0 = byte, 1 = short, 2 = long) */
249 FALSE
, /* pc_relative */
251 complain_overflow_signed
, /* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_OR1K_GOT16", /* name */
254 FALSE
, /* partial_inplace */
256 0xffff, /* dst_mask */
257 FALSE
), /* pcrel_offset */
259 /* A 26 bit PLT relocation. Shifted by 2. */
260 HOWTO (R_OR1K_PLT26
, /* Type. */
262 2, /* Size (0 = byte, 1 = short, 2 = long). */
264 TRUE
, /* pc_relative. */
266 complain_overflow_signed
, /* Complain on overflow. */
267 bfd_elf_generic_reloc
, /* Special Function. */
268 "R_OR1K_PLT26", /* Name. */
269 FALSE
, /* Partial Inplace. */
270 0, /* Source Mask. */
271 0x03ffffff, /* Dest Mask. */
272 TRUE
), /* PC relative offset? */
274 HOWTO (R_OR1K_GOTOFF_HI16
, /* type */
276 2, /* size (0 = byte, 1 = short, 2 = long) */
278 FALSE
, /* pc_relative */
280 complain_overflow_dont
, /* complain_on_overflow */
281 bfd_elf_generic_reloc
, /* special_function */
282 "R_OR1K_GOTOFF_HI16", /* name */
283 FALSE
, /* partial_inplace */
285 0xffff, /* dst_mask */
286 FALSE
), /* pcrel_offset */
288 HOWTO (R_OR1K_GOTOFF_LO16
, /* type */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
292 FALSE
, /* pc_relative */
294 complain_overflow_dont
, /* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_OR1K_GOTOFF_LO16", /* name */
297 FALSE
, /* partial_inplace */
299 0xffff, /* dst_mask */
300 FALSE
), /* pcrel_offset */
302 HOWTO (R_OR1K_COPY
, /* type */
304 2, /* size (0 = byte, 1 = short, 2 = long) */
306 FALSE
, /* pc_relative */
308 complain_overflow_bitfield
, /* complain_on_overflow */
309 bfd_elf_generic_reloc
, /* special_function */
310 "R_OR1K_COPY", /* name */
311 FALSE
, /* partial_inplace */
312 0xffffffff, /* src_mask */
313 0xffffffff, /* dst_mask */
314 FALSE
), /* pcrel_offset */
316 HOWTO (R_OR1K_GLOB_DAT
, /* type */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
320 FALSE
, /* pc_relative */
322 complain_overflow_bitfield
, /* complain_on_overflow */
323 bfd_elf_generic_reloc
, /* special_function */
324 "R_OR1K_GLOB_DAT", /* name */
325 FALSE
, /* partial_inplace */
326 0xffffffff, /* src_mask */
327 0xffffffff, /* dst_mask */
328 FALSE
), /* pcrel_offset */
330 HOWTO (R_OR1K_JMP_SLOT
, /* type */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
334 FALSE
, /* pc_relative */
336 complain_overflow_bitfield
, /* complain_on_overflow */
337 bfd_elf_generic_reloc
, /* special_function */
338 "R_OR1K_JMP_SLOT", /* name */
339 FALSE
, /* partial_inplace */
340 0xffffffff, /* src_mask */
341 0xffffffff, /* dst_mask */
342 FALSE
), /* pcrel_offset */
344 HOWTO (R_OR1K_RELATIVE
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 FALSE
, /* pc_relative */
350 complain_overflow_bitfield
, /* complain_on_overflow */
351 bfd_elf_generic_reloc
, /* special_function */
352 "R_OR1K_RELATIVE", /* name */
353 FALSE
, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 FALSE
), /* pcrel_offset */
358 HOWTO (R_OR1K_TLS_GD_HI16
, /* type */
360 2, /* size (0 = byte, 1 = short, 2 = long) */
362 FALSE
, /* pc_relative */
364 complain_overflow_dont
, /* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 "R_OR1K_TLS_GD_HI16", /* name */
367 FALSE
, /* partial_inplace */
369 0xffff, /* dst_mask */
370 FALSE
), /* pcrel_offset */
372 HOWTO (R_OR1K_TLS_GD_LO16
, /* type */
374 2, /* size (0 = byte, 1 = short, 2 = long) */
376 FALSE
, /* pc_relative */
378 complain_overflow_dont
, /* complain_on_overflow */
379 bfd_elf_generic_reloc
, /* special_function */
380 "R_OR1K_TLS_GD_LO16", /* name */
381 FALSE
, /* partial_inplace */
383 0xffff, /* dst_mask */
384 FALSE
), /* pcrel_offset */
386 HOWTO (R_OR1K_TLS_LDM_HI16
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_dont
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_OR1K_TLS_LDM_HI16", /* name */
395 FALSE
, /* partial_inplace */
397 0xffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
400 HOWTO (R_OR1K_TLS_LDM_LO16
, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE
, /* pc_relative */
406 complain_overflow_dont
, /* complain_on_overflow */
407 bfd_elf_generic_reloc
, /* special_function */
408 "R_OR1K_TLS_LDM_LO16", /* name */
409 FALSE
, /* partial_inplace */
411 0xffff, /* dst_mask */
412 FALSE
), /* pcrel_offset */
414 HOWTO (R_OR1K_TLS_LDO_HI16
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 FALSE
, /* pc_relative */
420 complain_overflow_dont
, /* complain_on_overflow */
421 bfd_elf_generic_reloc
, /* special_function */
422 "R_OR1K_TLS_LDO_HI16", /* name */
423 FALSE
, /* partial_inplace */
425 0xffff, /* dst_mask */
426 FALSE
), /* pcrel_offset */
428 HOWTO (R_OR1K_TLS_LDO_LO16
, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE
, /* pc_relative */
434 complain_overflow_dont
, /* complain_on_overflow */
435 bfd_elf_generic_reloc
, /* special_function */
436 "R_OR1K_TLS_LDO_LO16", /* name */
437 FALSE
, /* partial_inplace */
439 0xffff, /* dst_mask */
440 FALSE
), /* pcrel_offset */
442 HOWTO (R_OR1K_TLS_IE_HI16
, /* type */
444 2, /* size (0 = byte, 1 = short, 2 = long) */
446 FALSE
, /* pc_relative */
448 complain_overflow_dont
, /* complain_on_overflow */
449 bfd_elf_generic_reloc
, /* special_function */
450 "R_OR1K_TLS_IE_HI16", /* name */
451 FALSE
, /* partial_inplace */
453 0xffff, /* dst_mask */
454 FALSE
), /* pcrel_offset */
456 HOWTO (R_OR1K_TLS_IE_LO16
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 FALSE
, /* pc_relative */
462 complain_overflow_dont
, /* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_OR1K_TLS_IE_LO16", /* name */
465 FALSE
, /* partial_inplace */
467 0xffff, /* dst_mask */
468 FALSE
), /* pcrel_offset */
470 HOWTO (R_OR1K_TLS_LE_HI16
, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 FALSE
, /* pc_relative */
476 complain_overflow_dont
, /* complain_on_overflow */
477 bfd_elf_generic_reloc
, /* special_function */
478 "R_OR1K_TLS_LE_HI16", /* name */
479 FALSE
, /* partial_inplace */
481 0xffff, /* dst_mask */
482 FALSE
), /* pcrel_offset */
484 HOWTO (R_OR1K_TLS_LE_LO16
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE
, /* pc_relative */
490 complain_overflow_dont
, /* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 "R_OR1K_TLS_LE_LO16", /* name */
493 FALSE
, /* partial_inplace */
495 0xffff, /* dst_mask */
496 FALSE
), /* pcrel_offset */
498 HOWTO (R_OR1K_TLS_TPOFF
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
504 complain_overflow_bitfield
, /* complain_on_overflow */
505 bfd_elf_generic_reloc
, /* special_function */
506 "R_OR1K_TLS_TPOFF", /* name */
507 FALSE
, /* partial_inplace */
508 0xffffffff, /* src_mask */
509 0xffffffff, /* dst_mask */
510 FALSE
), /* pcrel_offset */
512 HOWTO (R_OR1K_TLS_DTPOFF
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE
, /* pc_relative */
518 complain_overflow_bitfield
, /* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 "R_OR1K_TLS_DTPOFF", /* name */
521 FALSE
, /* partial_inplace */
522 0xffffffff, /* src_mask */
523 0xffffffff, /* dst_mask */
524 FALSE
), /* pcrel_offset */
526 HOWTO (R_OR1K_TLS_DTPMOD
, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE
, /* pc_relative */
532 complain_overflow_bitfield
, /* complain_on_overflow */
533 bfd_elf_generic_reloc
, /* special_function */
534 "R_OR1K_TLS_DTPMOD", /* name */
535 FALSE
, /* partial_inplace */
536 0xffffffff, /* src_mask */
537 0xffffffff, /* dst_mask */
538 FALSE
), /* pcrel_offset */
540 HOWTO (R_OR1K_AHI16
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 FALSE
, /* pc_relative */
546 complain_overflow_dont
, /* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_OR1K_AHI16", /* name */
549 FALSE
, /* partial_inplace */
551 0xffff, /* dst_mask */
552 FALSE
), /* pcrel_offset */
554 HOWTO (R_OR1K_GOTOFF_AHI16
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 FALSE
, /* pc_relative */
560 complain_overflow_dont
, /* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 "R_OR1K_GOTOFF_AHI16", /* name */
563 FALSE
, /* partial_inplace */
565 0xffff, /* dst_mask */
566 FALSE
), /* pcrel_offset */
568 HOWTO (R_OR1K_TLS_IE_AHI16
, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 FALSE
, /* pc_relative */
574 complain_overflow_dont
, /* complain_on_overflow */
575 bfd_elf_generic_reloc
, /* special_function */
576 "R_OR1K_TLS_IE_AHI16", /* name */
577 FALSE
, /* partial_inplace */
579 0xffff, /* dst_mask */
580 FALSE
), /* pcrel_offset */
582 HOWTO (R_OR1K_TLS_LE_AHI16
, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 FALSE
, /* pc_relative */
588 complain_overflow_dont
, /* complain_on_overflow */
589 bfd_elf_generic_reloc
, /* special_function */
590 "R_OR1K_TLS_LE_AHI16", /* name */
591 FALSE
, /* partial_inplace */
593 0xffff, /* dst_mask */
594 FALSE
), /* pcrel_offset */
596 HOWTO (R_OR1K_SLO16
, /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE
, /* pc_relative */
602 complain_overflow_dont
, /* complain_on_overflow */
603 bfd_elf_generic_reloc
, /* special_function */
604 "R_OR1K_SLO16", /* name */
605 FALSE
, /* partial_inplace */
607 0xffff, /* dst_mask */
608 FALSE
), /* pcrel_offset */
610 HOWTO (R_OR1K_GOTOFF_SLO16
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE
, /* pc_relative */
616 complain_overflow_dont
, /* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_OR1K_GOTOFF_SLO16", /* name */
619 FALSE
, /* partial_inplace */
621 0xffff, /* dst_mask */
622 FALSE
), /* pcrel_offset */
624 HOWTO (R_OR1K_TLS_LE_SLO16
, /* type */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
628 FALSE
, /* pc_relative */
630 complain_overflow_dont
, /* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 "R_OR1K_TLS_LE_SLO16", /* name */
633 FALSE
, /* partial_inplace */
635 0xffff, /* dst_mask */
636 FALSE
), /* pcrel_offset */
638 /* A page relative 21 bit relocation, right shifted by 13, aligned.
639 Note that this is *page* relative, not pc relative. The idea is
640 similar, but normally the section alignment is not such that the
641 assembler can infer a final value, which it attempts to do with
642 pc-relative relocations to local symbols. */
643 HOWTO (R_OR1K_PCREL_PG21
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_signed
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_OR1K_PCREL_PG21", /* name */
652 FALSE
, /* partial_inplace */
654 0x001fffff, /* dst_mask */
655 TRUE
), /* pcrel_offset */
657 HOWTO (R_OR1K_GOT_PG21
, /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 FALSE
, /* pc_relative */
663 complain_overflow_signed
, /* complain_on_overflow */
664 bfd_elf_generic_reloc
, /* special_function */
665 "R_OR1K_GOT_PG21", /* name */
666 FALSE
, /* partial_inplace */
668 0x001fffff, /* dst_mask */
669 TRUE
), /* pcrel_offset */
671 HOWTO (R_OR1K_TLS_GD_PG21
, /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 FALSE
, /* pc_relative */
677 complain_overflow_signed
, /* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 "R_OR1K_TLS_GD_PG21", /* name */
680 FALSE
, /* partial_inplace */
682 0x001fffff, /* dst_mask */
683 TRUE
), /* pcrel_offset */
685 HOWTO (R_OR1K_TLS_LDM_PG21
, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 FALSE
, /* pc_relative */
691 complain_overflow_signed
, /* complain_on_overflow */
692 bfd_elf_generic_reloc
, /* special_function */
693 "R_OR1K_TLS_LDM_PG21", /* name */
694 FALSE
, /* partial_inplace */
696 0x001fffff, /* dst_mask */
697 TRUE
), /* pcrel_offset */
699 HOWTO (R_OR1K_TLS_IE_PG21
, /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 FALSE
, /* pc_relative */
705 complain_overflow_signed
, /* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 "R_OR1K_TLS_IE_PG21", /* name */
708 FALSE
, /* partial_inplace */
710 0x001fffff, /* dst_mask */
711 TRUE
), /* pcrel_offset */
713 HOWTO (R_OR1K_LO13
, /* type */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
717 FALSE
, /* pc_relative */
719 complain_overflow_dont
, /* complain_on_overflow */
720 bfd_elf_generic_reloc
, /* special_function */
721 "R_OR1K_LO13", /* name */
722 FALSE
, /* partial_inplace */
724 0xffff, /* dst_mask */
725 FALSE
), /* pcrel_offset */
727 HOWTO (R_OR1K_GOT_LO13
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_dont
, /* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_OR1K_GOT_LO13", /* name */
736 FALSE
, /* partial_inplace */
738 0xffff, /* dst_mask */
739 FALSE
), /* pcrel_offset */
741 HOWTO (R_OR1K_TLS_GD_LO13
, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 FALSE
, /* pc_relative */
747 complain_overflow_dont
, /* complain_on_overflow */
748 bfd_elf_generic_reloc
, /* special_function */
749 "R_OR1K_TLS_GD_LO13", /* name */
750 FALSE
, /* partial_inplace */
752 0xffff, /* dst_mask */
753 FALSE
), /* pcrel_offset */
755 HOWTO (R_OR1K_TLS_LDM_LO13
, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_dont
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_OR1K_TLD_LDM_LO13", /* name */
764 FALSE
, /* partial_inplace */
766 0xffff, /* dst_mask */
767 FALSE
), /* pcrel_offset */
769 HOWTO (R_OR1K_TLS_IE_LO13
, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 FALSE
, /* pc_relative */
775 complain_overflow_dont
, /* complain_on_overflow */
776 bfd_elf_generic_reloc
, /* special_function */
777 "R_OR1K_TLS_IE_LO13", /* name */
778 FALSE
, /* partial_inplace */
780 0xffff, /* dst_mask */
781 FALSE
), /* pcrel_offset */
783 HOWTO (R_OR1K_SLO13
, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 FALSE
, /* pc_relative */
789 complain_overflow_dont
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_OR1K_SLO13", /* name */
792 FALSE
, /* partial_inplace */
794 0xffff, /* dst_mask */
795 FALSE
), /* pcrel_offset */
797 /* A 26 bit PLT relocation, using ADRP. Shifted by 2. */
798 HOWTO (R_OR1K_PLTA26
, /* Type. */
800 2, /* Size (0 = byte, 1 = short, 2 = long). */
802 TRUE
, /* pc_relative. */
804 complain_overflow_signed
, /* Complain on overflow. */
805 bfd_elf_generic_reloc
, /* Special Function. */
806 "R_OR1K_PLTA26", /* Name. */
807 FALSE
, /* Partial Inplace. */
808 0, /* Source Mask. */
809 0x03ffffff, /* Dest Mask. */
810 TRUE
), /* PC relative offset? */
813 /* Map BFD reloc types to Or1k ELF reloc types. */
815 struct or1k_reloc_map
817 bfd_reloc_code_real_type bfd_reloc_val
;
818 unsigned int or1k_reloc_val
;
821 static const struct or1k_reloc_map or1k_reloc_map
[] =
823 { BFD_RELOC_NONE
, R_OR1K_NONE
},
824 { BFD_RELOC_32
, R_OR1K_32
},
825 { BFD_RELOC_16
, R_OR1K_16
},
826 { BFD_RELOC_8
, R_OR1K_8
},
827 { BFD_RELOC_LO16
, R_OR1K_LO_16_IN_INSN
},
828 { BFD_RELOC_HI16
, R_OR1K_HI_16_IN_INSN
},
829 { BFD_RELOC_HI16_S
, R_OR1K_AHI16
},
830 { BFD_RELOC_OR1K_REL_26
, R_OR1K_INSN_REL_26
},
831 { BFD_RELOC_VTABLE_ENTRY
, R_OR1K_GNU_VTENTRY
},
832 { BFD_RELOC_VTABLE_INHERIT
, R_OR1K_GNU_VTINHERIT
},
833 { BFD_RELOC_32_PCREL
, R_OR1K_32_PCREL
},
834 { BFD_RELOC_16_PCREL
, R_OR1K_16_PCREL
},
835 { BFD_RELOC_8_PCREL
, R_OR1K_8_PCREL
},
836 { BFD_RELOC_LO16_GOTOFF
, R_OR1K_GOTOFF_LO16
},
837 { BFD_RELOC_HI16_GOTOFF
, R_OR1K_GOTOFF_HI16
},
838 { BFD_RELOC_HI16_S_GOTOFF
, R_OR1K_GOTOFF_AHI16
},
839 { BFD_RELOC_OR1K_GOTPC_HI16
, R_OR1K_GOTPC_HI16
},
840 { BFD_RELOC_OR1K_GOTPC_LO16
, R_OR1K_GOTPC_LO16
},
841 { BFD_RELOC_OR1K_GOT16
, R_OR1K_GOT16
},
842 { BFD_RELOC_OR1K_PLT26
, R_OR1K_PLT26
},
843 { BFD_RELOC_OR1K_GLOB_DAT
, R_OR1K_GLOB_DAT
},
844 { BFD_RELOC_OR1K_COPY
, R_OR1K_COPY
},
845 { BFD_RELOC_OR1K_JMP_SLOT
, R_OR1K_JMP_SLOT
},
846 { BFD_RELOC_OR1K_RELATIVE
, R_OR1K_RELATIVE
},
847 { BFD_RELOC_OR1K_TLS_GD_HI16
, R_OR1K_TLS_GD_HI16
},
848 { BFD_RELOC_OR1K_TLS_GD_LO16
, R_OR1K_TLS_GD_LO16
},
849 { BFD_RELOC_OR1K_TLS_LDM_HI16
, R_OR1K_TLS_LDM_HI16
},
850 { BFD_RELOC_OR1K_TLS_LDM_LO16
, R_OR1K_TLS_LDM_LO16
},
851 { BFD_RELOC_OR1K_TLS_LDO_HI16
, R_OR1K_TLS_LDO_HI16
},
852 { BFD_RELOC_OR1K_TLS_LDO_LO16
, R_OR1K_TLS_LDO_LO16
},
853 { BFD_RELOC_OR1K_TLS_IE_HI16
, R_OR1K_TLS_IE_HI16
},
854 { BFD_RELOC_OR1K_TLS_IE_LO16
, R_OR1K_TLS_IE_LO16
},
855 { BFD_RELOC_OR1K_TLS_IE_AHI16
, R_OR1K_TLS_IE_AHI16
},
856 { BFD_RELOC_OR1K_TLS_LE_HI16
, R_OR1K_TLS_LE_HI16
},
857 { BFD_RELOC_OR1K_TLS_LE_LO16
, R_OR1K_TLS_LE_LO16
},
858 { BFD_RELOC_OR1K_TLS_LE_AHI16
, R_OR1K_TLS_LE_AHI16
},
859 { BFD_RELOC_OR1K_SLO16
, R_OR1K_SLO16
},
860 { BFD_RELOC_OR1K_GOTOFF_SLO16
, R_OR1K_GOTOFF_SLO16
},
861 { BFD_RELOC_OR1K_TLS_LE_SLO16
, R_OR1K_TLS_LE_SLO16
},
862 { BFD_RELOC_OR1K_PCREL_PG21
, R_OR1K_PCREL_PG21
},
863 { BFD_RELOC_OR1K_GOT_PG21
, R_OR1K_GOT_PG21
},
864 { BFD_RELOC_OR1K_TLS_GD_PG21
, R_OR1K_TLS_GD_PG21
},
865 { BFD_RELOC_OR1K_TLS_LDM_PG21
, R_OR1K_TLS_LDM_PG21
},
866 { BFD_RELOC_OR1K_TLS_IE_PG21
, R_OR1K_TLS_IE_PG21
},
867 { BFD_RELOC_OR1K_LO13
, R_OR1K_LO13
},
868 { BFD_RELOC_OR1K_GOT_LO13
, R_OR1K_GOT_LO13
},
869 { BFD_RELOC_OR1K_TLS_GD_LO13
, R_OR1K_TLS_GD_LO13
},
870 { BFD_RELOC_OR1K_TLS_LDM_LO13
, R_OR1K_TLS_LDM_LO13
},
871 { BFD_RELOC_OR1K_TLS_IE_LO13
, R_OR1K_TLS_IE_LO13
},
872 { BFD_RELOC_OR1K_SLO13
, R_OR1K_SLO13
},
873 { BFD_RELOC_OR1K_PLTA26
, R_OR1K_PLTA26
},
876 /* tls_type is a mask used to track how each symbol is accessed,
877 it may be accessed via multiple types of TLS access methods.
878 We track this for sizing (allocating got + relocation section space) and
879 for how to process relocations. */
880 #define TLS_UNKNOWN 0
887 /* The size of the TLS thread control block, used to offset LE access. */
890 /* ELF linker hash entry. */
891 struct elf_or1k_link_hash_entry
893 struct elf_link_hash_entry root
;
895 /* Track type of TLS access. */
896 unsigned char tls_type
;
899 /* ELF object data. */
900 struct elf_or1k_obj_tdata
902 struct elf_obj_tdata root
;
904 /* tls_type for each local got entry. */
905 unsigned char *local_tls_type
;
908 #define elf_or1k_tdata(abfd) \
909 ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
911 #define elf_or1k_local_tls_type(abfd) \
912 (elf_or1k_tdata (abfd)->local_tls_type)
914 /* ELF linker hash table. */
915 struct elf_or1k_link_hash_table
917 struct elf_link_hash_table root
;
919 bfd_boolean saw_plta
;
922 /* Get the ELF linker hash table from a link_info structure. */
923 #define or1k_elf_hash_table(p) \
924 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
925 == OR1K_ELF_DATA ? ((struct elf_or1k_link_hash_table *) ((p)->hash)) : NULL)
928 elf_or1k_mkobject (bfd
*abfd
)
930 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_or1k_obj_tdata
),
934 /* Create an entry in an or1k ELF linker hash table. */
936 static struct bfd_hash_entry
*
937 or1k_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
938 struct bfd_hash_table
*table
,
941 struct elf_or1k_link_hash_entry
*ret
=
942 (struct elf_or1k_link_hash_entry
*) entry
;
944 /* Allocate the structure if it has not already been allocated by a
947 ret
= bfd_hash_allocate (table
,
948 sizeof (struct elf_or1k_link_hash_entry
));
952 /* Call the allocation method of the superclass. */
953 ret
= ((struct elf_or1k_link_hash_entry
*)
954 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
958 struct elf_or1k_link_hash_entry
*eh
;
960 eh
= (struct elf_or1k_link_hash_entry
*) ret
;
961 eh
->tls_type
= TLS_UNKNOWN
;
964 return (struct bfd_hash_entry
*) ret
;
967 /* Create an or1k ELF linker hash table. */
969 static struct bfd_link_hash_table
*
970 or1k_elf_link_hash_table_create (bfd
*abfd
)
972 struct elf_or1k_link_hash_table
*ret
;
973 size_t amt
= sizeof (struct elf_or1k_link_hash_table
);
975 ret
= bfd_zmalloc (amt
);
979 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
980 or1k_elf_link_hash_newfunc
,
981 sizeof (struct elf_or1k_link_hash_entry
),
988 return &ret
->root
.root
;
991 static reloc_howto_type
*
992 or1k_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
993 bfd_reloc_code_real_type bcode
)
997 for (i
= 0; i
< ARRAY_SIZE (or1k_reloc_map
); i
++)
998 if (or1k_reloc_map
[i
].bfd_reloc_val
== bcode
)
1000 unsigned int ocode
= or1k_reloc_map
[i
].or1k_reloc_val
;
1001 if (ocode
< (unsigned int) R_OR1K_max
)
1002 return &or1k_elf_howto_table
[ocode
];
1010 static reloc_howto_type
*
1011 or1k_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1016 for (i
= 0; i
< R_OR1K_max
; i
++)
1017 if (or1k_elf_howto_table
[i
].name
!= NULL
1018 && strcasecmp (or1k_elf_howto_table
[i
].name
, r_name
) == 0)
1019 return &or1k_elf_howto_table
[i
];
1024 /* Set the howto pointer for an Or1k ELF reloc. */
1027 or1k_info_to_howto_rela (bfd
* abfd
,
1028 arelent
* cache_ptr
,
1029 Elf_Internal_Rela
* dst
)
1031 unsigned int r_type
;
1033 r_type
= ELF32_R_TYPE (dst
->r_info
);
1034 if (r_type
>= (unsigned int) R_OR1K_max
)
1036 /* xgettext:c-format */
1037 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1039 bfd_set_error (bfd_error_bad_value
);
1042 cache_ptr
->howto
= & or1k_elf_howto_table
[r_type
];
1046 /* Return the relocation value for @tpoff relocations.. */
1048 tpoff (struct bfd_link_info
*info
, bfd_vma address
, bfd_boolean dynamic
)
1050 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1053 /* If tls_sec is NULL, we should have signalled an error already. */
1054 if (htab
->tls_sec
== NULL
)
1058 return address
- htab
->tls_sec
->vma
;
1061 /* On or1k, the tp points to just after the tcb, if we have an alignment
1062 greater than the tcb size we need to offset by the alignment difference. */
1063 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
)
1066 /* The thread pointer on or1k stores the address after the TCB where
1067 the data is, just compute the difference. No need to compensate
1068 for the size of TCB. */
1069 return address
- htab
->tls_sec
->vma
+ base
;
1073 /* If we have both IE and GD accesses to a symbol the IE relocations should be
1074 offset by 8 bytes because the got contains both GD and IE entries. */
1076 or1k_initial_exec_offset (reloc_howto_type
*howto
, unsigned char tls_type_mask
)
1078 switch (howto
->type
)
1080 case R_OR1K_TLS_IE_HI16
:
1081 case R_OR1K_TLS_IE_LO16
:
1082 case R_OR1K_TLS_IE_PG21
:
1083 case R_OR1K_TLS_IE_LO13
:
1084 case R_OR1K_TLS_IE_AHI16
:
1085 return (tls_type_mask
& TLS_GD
) != 0 ? 8 : 0;
1091 /* Like _bfd_final_link_relocate, but handles non-contiguous fields. */
1093 static bfd_reloc_status_type
1094 or1k_final_link_relocate (reloc_howto_type
*howto
, bfd
*input_bfd
,
1095 asection
*input_section
, bfd_byte
*contents
,
1096 bfd_vma offset
, bfd_vma value
)
1098 bfd_reloc_status_type status
= bfd_reloc_ok
;
1099 int size
= bfd_get_reloc_size (howto
);
1102 /* Sanity check the address. */
1103 if (offset
+ size
> bfd_get_section_limit_octets (input_bfd
, input_section
))
1104 return bfd_reloc_outofrange
;
1106 place
= (input_section
->output_section
->vma
1107 + input_section
->output_offset
1108 + (howto
->pcrel_offset
? offset
: 0));
1110 switch (howto
->type
)
1113 case R_OR1K_GOTOFF_AHI16
:
1114 case R_OR1K_TLS_IE_AHI16
:
1115 case R_OR1K_TLS_LE_AHI16
:
1116 /* Adjust the operand to match with a signed LO16. */
1120 case R_OR1K_INSN_REL_26
:
1122 /* Diagnose mis-aligned branch targets. */
1124 status
= bfd_reloc_dangerous
;
1127 case R_OR1K_PCREL_PG21
:
1128 case R_OR1K_GOT_PG21
:
1129 case R_OR1K_TLS_GD_PG21
:
1130 case R_OR1K_TLS_LDM_PG21
:
1131 case R_OR1K_TLS_IE_PG21
:
1132 value
= (value
& -8192) - (place
& -8192);
1136 case R_OR1K_GOT_LO13
:
1137 case R_OR1K_TLS_GD_LO13
:
1138 case R_OR1K_TLS_LDM_LO13
:
1139 case R_OR1K_TLS_IE_LO13
:
1145 if (howto
->pc_relative
)
1150 status
= bfd_check_overflow (howto
->complain_on_overflow
,
1153 bfd_arch_bits_per_address (input_bfd
),
1155 value
>>= howto
->rightshift
;
1157 /* If we're overwriting the entire destination,
1158 then no need to read the current contents. */
1159 if (size
== 0 || howto
->dst_mask
== N_ONES (size
))
1163 BFD_ASSERT (size
== 4);
1164 x
= bfd_get_32 (input_bfd
, contents
+ offset
);
1167 switch (howto
->type
)
1170 case R_OR1K_GOTOFF_SLO16
:
1171 case R_OR1K_TLS_LE_SLO16
:
1173 /* The split imm16 field used for stores. */
1174 x
= (x
& ~0x3e007ff) | ((value
& 0xf800) << 10) | (value
& 0x7ff);
1179 bfd_vma fieldmask
= howto
->dst_mask
;
1180 value
<<= howto
->bitpos
;
1181 x
= (x
& ~fieldmask
) | (value
& fieldmask
);
1186 /* Put the relocated value back in the object file. */
1192 bfd_put_8 (input_bfd
, x
, contents
+ offset
);
1195 bfd_put_16 (input_bfd
, x
, contents
+ offset
);
1198 bfd_put_32 (input_bfd
, x
, contents
+ offset
);
1202 bfd_put_64 (input_bfd
, x
, contents
+ offset
);
1207 (_("%pB: Cannot handle relocation value size of %d"),
1214 /* Relocate an Or1k ELF section.
1216 The RELOCATE_SECTION function is called by the new ELF backend linker
1217 to handle the relocations for a section.
1219 The relocs are always passed as Rela structures; if the section
1220 actually uses Rel structures, the r_addend field will always be
1223 This function is responsible for adjusting the section contents as
1224 necessary, and (if using Rela relocs and generating a relocatable
1225 output file) adjusting the reloc addend as necessary.
1227 This function does not have to worry about setting the reloc
1228 address or the reloc symbol index.
1230 LOCAL_SYMS is a pointer to the swapped in local symbols.
1232 LOCAL_SECTIONS is an array giving the section in the input file
1233 corresponding to the st_shndx field of each local symbol.
1235 The global hash table entry for the global symbols can be found
1236 via elf_sym_hashes (input_bfd).
1238 When generating relocatable output, this function must handle
1239 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1240 going to be the section symbol corresponding to the output
1241 section, which means that the addend must be adjusted
1245 or1k_elf_relocate_section (bfd
*output_bfd
,
1246 struct bfd_link_info
*info
,
1248 asection
*input_section
,
1250 Elf_Internal_Rela
*relocs
,
1251 Elf_Internal_Sym
*local_syms
,
1252 asection
**local_sections
)
1254 Elf_Internal_Shdr
*symtab_hdr
;
1255 struct elf_link_hash_entry
**sym_hashes
;
1256 Elf_Internal_Rela
*rel
;
1257 Elf_Internal_Rela
*relend
;
1258 struct elf_or1k_link_hash_table
*htab
= or1k_elf_hash_table (info
);
1260 bfd_vma
*local_got_offsets
;
1261 asection
*sgot
, *splt
;
1262 bfd_vma plt_base
, got_base
, got_sym_value
;
1263 bfd_boolean ret_val
= TRUE
;
1268 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1270 sreloc
= elf_section_data (input_section
)->sreloc
;
1272 splt
= htab
->root
.splt
;
1275 plt_base
= splt
->output_section
->vma
+ splt
->output_offset
;
1277 sgot
= htab
->root
.sgot
;
1278 got_sym_value
= got_base
= 0;
1281 struct elf_link_hash_entry
*hgot
= htab
->root
.hgot
;
1282 got_sym_value
= (hgot
->root
.u
.def
.value
1283 + hgot
->root
.u
.def
.section
->output_section
->vma
1284 + hgot
->root
.u
.def
.section
->output_offset
);
1285 got_base
= sgot
->output_section
->vma
+ sgot
->output_offset
;
1288 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1289 sym_hashes
= elf_sym_hashes (input_bfd
);
1290 relend
= relocs
+ input_section
->reloc_count
;
1292 for (rel
= relocs
; rel
< relend
; rel
++)
1294 reloc_howto_type
*howto
;
1295 unsigned long r_symndx
;
1296 Elf_Internal_Sym
*sym
;
1298 struct elf_link_hash_entry
*h
;
1300 bfd_reloc_status_type r
;
1301 const char *name
= NULL
;
1304 r_type
= ELF32_R_TYPE (rel
->r_info
);
1305 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1307 if (r_type
== R_OR1K_GNU_VTINHERIT
1308 || r_type
== R_OR1K_GNU_VTENTRY
)
1311 if (r_type
< 0 || r_type
>= (int) R_OR1K_max
)
1314 (_("%pB: unknown relocation type %d"),
1315 input_bfd
, (int) r_type
);
1316 bfd_set_error (bfd_error_bad_value
);
1321 howto
= or1k_elf_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
1326 if (r_symndx
< symtab_hdr
->sh_info
)
1328 sym
= local_syms
+ r_symndx
;
1329 sec
= local_sections
[r_symndx
];
1330 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1332 name
= bfd_elf_string_from_elf_section
1333 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
1334 name
= name
== NULL
? bfd_section_name (sec
) : name
;
1338 bfd_boolean unresolved_reloc
, warned
, ignored
;
1340 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1341 r_symndx
, symtab_hdr
, sym_hashes
,
1343 unresolved_reloc
, warned
, ignored
);
1344 name
= h
->root
.root
.string
;
1347 if (sec
!= NULL
&& discarded_section (sec
))
1348 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
1349 rel
, 1, relend
, howto
, 0, contents
);
1351 if (bfd_link_relocatable (info
))
1354 switch (howto
->type
)
1358 /* If the call is not local, redirect the branch to the PLT.
1359 Otherwise do nothing to send the branch to the symbol direct. */
1360 if (!SYMBOL_CALLS_LOCAL (info
, h
)
1361 && h
->plt
.offset
!= (bfd_vma
) -1)
1362 relocation
= plt_base
+ h
->plt
.offset
;
1364 /* Addend should be zero. */
1365 if (rel
->r_addend
!= 0)
1368 (_("%pB: addend should be zero for plt relocations"),
1370 bfd_set_error (bfd_error_bad_value
);
1376 case R_OR1K_GOT_PG21
:
1377 case R_OR1K_GOT_LO13
:
1381 /* Relocation is to the entry for this symbol
1382 in the global offset table. */
1383 BFD_ASSERT (sgot
!= NULL
);
1388 off
= h
->got
.offset
;
1389 BFD_ASSERT (off
!= (bfd_vma
) -1);
1391 dyn
= htab
->root
.dynamic_sections_created
;
1392 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
1393 bfd_link_pic (info
),
1395 || (bfd_link_pic (info
)
1396 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
1398 /* This is actually a static link, or it is a -Bsymbolic
1399 link and the symbol is defined locally, or the symbol
1400 was forced to be local because of a version file.
1401 We must initialize this entry in the GOT. Since the
1402 offset must always be a multiple of 4, we use the least
1403 significant bit to record whether we have initialized
1406 When doing a dynamic link, we create a .rela.got
1407 relocation entry to initialize the value. This
1408 is done in the finish_dynamic_symbol routine. */
1413 /* Write entry in GOT. */
1414 bfd_put_32 (output_bfd
, relocation
,
1415 sgot
->contents
+ off
);
1416 /* Mark GOT entry as having been written. */
1425 BFD_ASSERT (local_got_offsets
!= NULL
1426 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1428 /* Get offset into GOT table. */
1429 off
= local_got_offsets
[r_symndx
];
1431 /* The offset must always be a multiple of 4. We use
1432 the least significant bit to record whether we have
1433 already processed this entry. */
1438 /* Write entry in GOT. */
1439 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1440 if (bfd_link_pic (info
))
1443 Elf_Internal_Rela outrel
;
1445 /* We need to generate a R_OR1K_RELATIVE reloc
1446 for the dynamic linker. */
1447 srelgot
= htab
->root
.srelgot
;
1448 BFD_ASSERT (srelgot
!= NULL
);
1450 outrel
.r_offset
= got_base
+ off
;
1451 outrel
.r_info
= ELF32_R_INFO (0, R_OR1K_RELATIVE
);
1452 outrel
.r_addend
= relocation
;
1453 loc
= srelgot
->contents
;
1454 loc
+= (srelgot
->reloc_count
1455 * sizeof (Elf32_External_Rela
));
1456 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1457 ++srelgot
->reloc_count
;
1459 local_got_offsets
[r_symndx
] |= 1;
1463 /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
1464 while the GOT16 reloc is GOT relative. */
1465 relocation
= got_base
+ off
;
1466 if (r_type
== R_OR1K_GOT16
)
1467 relocation
-= got_sym_value
;
1469 /* Addend should be zero. */
1470 if (rel
->r_addend
!= 0)
1473 (_("%pB: addend should be zero for got relocations"),
1475 bfd_set_error (bfd_error_bad_value
);
1481 case R_OR1K_GOTOFF_LO16
:
1482 case R_OR1K_GOTOFF_HI16
:
1483 case R_OR1K_GOTOFF_AHI16
:
1484 case R_OR1K_GOTOFF_SLO16
:
1485 /* Relocation is offset from GOT. */
1486 BFD_ASSERT (sgot
!= NULL
);
1487 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
1490 (_("%pB: gotoff relocation against dynamic symbol %s"),
1491 input_bfd
, h
->root
.root
.string
);
1493 bfd_set_error (bfd_error_bad_value
);
1495 relocation
-= got_sym_value
;
1498 case R_OR1K_INSN_REL_26
:
1499 case R_OR1K_PCREL_PG21
:
1502 /* For a non-shared link, these will reference either the plt
1503 or a .dynbss copy of the symbol. */
1504 if (bfd_link_pic (info
) && !SYMBOL_REFERENCES_LOCAL (info
, h
))
1507 (_("%pB: pc-relative relocation against dynamic symbol %s"),
1510 bfd_set_error (bfd_error_bad_value
);
1514 case R_OR1K_HI_16_IN_INSN
:
1515 case R_OR1K_LO_16_IN_INSN
:
1518 if (bfd_link_pic (info
))
1521 (_("%pB: non-pic relocation against symbol %s"),
1524 bfd_set_error (bfd_error_bad_value
);
1531 /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1532 from removed linkonce sections, or sections discarded by
1534 if (r_symndx
== STN_UNDEF
1535 || (input_section
->flags
& SEC_ALLOC
) == 0)
1538 /* Emit a direct relocation if the symbol is dynamic,
1539 or a RELATIVE reloc for shared objects. We can omit
1540 RELATIVE relocs to local undefweak symbols. */
1541 if (bfd_link_pic (info
)
1543 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1544 || h
->root
.type
!= bfd_link_hash_undefweak
)
1548 && ((h
->def_dynamic
&& !h
->def_regular
)
1549 || h
->root
.type
== bfd_link_hash_undefweak
1550 || h
->root
.type
== bfd_link_hash_undefined
)))
1552 Elf_Internal_Rela outrel
;
1556 /* When generating a shared object, these relocations
1557 are copied into the output file to be resolved at run
1560 BFD_ASSERT (sreloc
!= NULL
);
1565 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1567 if (outrel
.r_offset
== (bfd_vma
) -1)
1569 else if (outrel
.r_offset
== (bfd_vma
) -2)
1571 outrel
.r_offset
+= (input_section
->output_section
->vma
1572 + input_section
->output_offset
);
1575 memset (&outrel
, 0, sizeof outrel
);
1576 else if (SYMBOL_REFERENCES_LOCAL (info
, h
))
1578 outrel
.r_info
= ELF32_R_INFO (0, R_OR1K_RELATIVE
);
1579 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1583 BFD_ASSERT (h
->dynindx
!= -1);
1584 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1585 outrel
.r_addend
= rel
->r_addend
;
1588 loc
= sreloc
->contents
;
1589 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1590 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1596 case R_OR1K_TLS_LDM_HI16
:
1597 case R_OR1K_TLS_LDM_LO16
:
1598 case R_OR1K_TLS_LDM_PG21
:
1599 case R_OR1K_TLS_LDM_LO13
:
1600 case R_OR1K_TLS_LDO_HI16
:
1601 case R_OR1K_TLS_LDO_LO16
:
1602 /* TODO: implement support for local dynamic. */
1605 (_("%pB: support for local dynamic not implemented"),
1607 bfd_set_error (bfd_error_bad_value
);
1610 case R_OR1K_TLS_GD_HI16
:
1611 case R_OR1K_TLS_GD_LO16
:
1612 case R_OR1K_TLS_GD_PG21
:
1613 case R_OR1K_TLS_GD_LO13
:
1614 case R_OR1K_TLS_IE_HI16
:
1615 case R_OR1K_TLS_IE_LO16
:
1616 case R_OR1K_TLS_IE_PG21
:
1617 case R_OR1K_TLS_IE_LO13
:
1618 case R_OR1K_TLS_IE_AHI16
:
1621 Elf_Internal_Rela rela
;
1624 bfd_boolean dynamic
;
1626 unsigned char tls_type
;
1628 srelgot
= htab
->root
.srelgot
;
1630 /* Mark as TLS related GOT entry by setting
1631 bit 2 to indcate TLS and bit 1 to indicate GOT. */
1634 gotoff
= h
->got
.offset
;
1635 tls_type
= ((struct elf_or1k_link_hash_entry
*) h
)->tls_type
;
1640 unsigned char *local_tls_type
;
1642 gotoff
= local_got_offsets
[r_symndx
];
1643 local_tls_type
= (unsigned char *) elf_or1k_local_tls_type (input_bfd
);
1644 tls_type
= local_tls_type
== NULL
? TLS_NONE
1645 : local_tls_type
[r_symndx
];
1646 local_got_offsets
[r_symndx
] |= 3;
1649 /* Only process the relocation once. */
1650 if ((gotoff
& 1) != 0)
1652 gotoff
+= or1k_initial_exec_offset (howto
, tls_type
);
1654 /* The PG21 and LO13 relocs are pc-relative, while the
1655 rest are GOT relative. */
1656 relocation
= got_base
+ (gotoff
& ~3);
1657 if (!(r_type
== R_OR1K_TLS_GD_PG21
1658 || r_type
== R_OR1K_TLS_GD_LO13
1659 || r_type
== R_OR1K_TLS_IE_PG21
1660 || r_type
== R_OR1K_TLS_IE_LO13
))
1661 relocation
-= got_sym_value
;
1665 BFD_ASSERT (elf_hash_table (info
)->hgot
== NULL
1666 || elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0);
1670 bfd_boolean dyn
= htab
->root
.dynamic_sections_created
;
1671 bfd_boolean pic
= bfd_link_pic (info
);
1673 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, pic
, h
)
1674 && (!pic
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
1678 /* Dynamic entries will require relocations. If we do not need
1679 them we will just use the default R_OR1K_NONE and
1680 not set anything. */
1681 dynamic
= (bfd_link_pic (info
) || indx
!= 0)
1683 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1684 || h
->root
.type
!= bfd_link_hash_undefweak
);
1687 if (dynamic
&& ((tls_type
& TLS_GD
) != 0))
1691 /* Add DTPMOD and DTPOFF GOT and rela entries. */
1692 for (i
= 0; i
< 2; ++i
)
1694 BFD_ASSERT (srelgot
->contents
!= NULL
);
1696 rela
.r_offset
= got_base
+ gotoff
+ i
*4;
1697 if (h
!= NULL
&& h
->dynindx
!= -1)
1699 rela
.r_info
= ELF32_R_INFO (h
->dynindx
,
1700 (i
== 0 ? R_OR1K_TLS_DTPMOD
: R_OR1K_TLS_DTPOFF
));
1705 rela
.r_info
= ELF32_R_INFO (0,
1706 (i
== 0 ? R_OR1K_TLS_DTPMOD
: R_OR1K_TLS_DTPOFF
));
1708 (i
== 0 ? 0 : tpoff (info
, relocation
, dynamic
));
1711 loc
= srelgot
->contents
;
1712 loc
+= (srelgot
->reloc_count
++
1713 * sizeof (Elf32_External_Rela
));
1715 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1716 bfd_put_32 (output_bfd
, 0, sgot
->contents
+ gotoff
+ i
*4);
1720 else if ((tls_type
& TLS_GD
) != 0)
1722 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ gotoff
);
1723 bfd_put_32 (output_bfd
, tpoff (info
, relocation
, dynamic
),
1724 sgot
->contents
+ gotoff
+ 4);
1727 gotoff
+= or1k_initial_exec_offset (howto
, tls_type
);
1730 if (dynamic
&& ((tls_type
& TLS_IE
) != 0))
1732 BFD_ASSERT (srelgot
->contents
!= NULL
);
1734 /* Add TPOFF GOT and rela entries. */
1735 rela
.r_offset
= got_base
+ gotoff
;
1736 if (h
!= NULL
&& h
->dynindx
!= -1)
1738 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_TLS_TPOFF
);
1743 rela
.r_info
= ELF32_R_INFO (0, R_OR1K_TLS_TPOFF
);
1744 rela
.r_addend
= tpoff (info
, relocation
, dynamic
);
1747 loc
= srelgot
->contents
;
1748 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1750 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1751 bfd_put_32 (output_bfd
, 0, sgot
->contents
+ gotoff
);
1754 else if ((tls_type
& TLS_IE
) != 0)
1755 bfd_put_32 (output_bfd
, tpoff (info
, relocation
, dynamic
),
1756 sgot
->contents
+ gotoff
);
1758 /* The PG21 and LO13 relocs are pc-relative, while the
1759 rest are GOT relative. */
1760 relocation
= got_base
+ gotoff
;
1761 if (!(r_type
== R_OR1K_TLS_GD_PG21
1762 || r_type
== R_OR1K_TLS_GD_LO13
1763 || r_type
== R_OR1K_TLS_IE_PG21
1764 || r_type
== R_OR1K_TLS_IE_LO13
))
1765 relocation
-= got_sym_value
;
1769 case R_OR1K_TLS_LE_HI16
:
1770 case R_OR1K_TLS_LE_LO16
:
1771 case R_OR1K_TLS_LE_AHI16
:
1772 case R_OR1K_TLS_LE_SLO16
:
1773 /* Relocation is offset from TP. */
1774 relocation
= tpoff (info
, relocation
, 0);
1777 case R_OR1K_TLS_DTPMOD
:
1778 case R_OR1K_TLS_DTPOFF
:
1779 case R_OR1K_TLS_TPOFF
:
1780 /* These are resolved dynamically on load and shouldn't
1781 be used as linker input. */
1784 (_("%pB: will not resolve runtime TLS relocation"),
1786 bfd_set_error (bfd_error_bad_value
);
1793 r
= or1k_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
1794 rel
->r_offset
, relocation
+ rel
->r_addend
);
1796 if (r
!= bfd_reloc_ok
)
1798 const char *msg
= NULL
;
1802 case bfd_reloc_overflow
:
1803 (*info
->callbacks
->reloc_overflow
)
1804 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1805 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
1808 case bfd_reloc_undefined
:
1809 (*info
->callbacks
->undefined_symbol
)
1810 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
1813 case bfd_reloc_outofrange
:
1814 msg
= _("internal error: out of range error");
1817 case bfd_reloc_notsupported
:
1818 msg
= _("internal error: unsupported relocation error");
1821 case bfd_reloc_dangerous
:
1822 msg
= _("internal error: dangerous relocation");
1826 msg
= _("internal error: unknown error");
1831 (*info
->callbacks
->warning
) (info
, msg
, name
, input_bfd
,
1832 input_section
, rel
->r_offset
);
1839 /* Return the section that should be marked against GC for a given
1843 or1k_elf_gc_mark_hook (asection
*sec
,
1844 struct bfd_link_info
*info
,
1845 Elf_Internal_Rela
*rel
,
1846 struct elf_link_hash_entry
*h
,
1847 Elf_Internal_Sym
*sym
)
1850 switch (ELF32_R_TYPE (rel
->r_info
))
1852 case R_OR1K_GNU_VTINHERIT
:
1853 case R_OR1K_GNU_VTENTRY
:
1857 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1860 /* Look through the relocs for a section during the first phase. */
1863 or1k_elf_check_relocs (bfd
*abfd
,
1864 struct bfd_link_info
*info
,
1866 const Elf_Internal_Rela
*relocs
)
1868 Elf_Internal_Shdr
*symtab_hdr
;
1869 struct elf_link_hash_entry
**sym_hashes
;
1870 const Elf_Internal_Rela
*rel
;
1872 const Elf_Internal_Rela
*rel_end
;
1873 struct elf_or1k_link_hash_table
*htab
;
1875 asection
*sreloc
= NULL
;
1877 if (bfd_link_relocatable (info
))
1880 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1881 sym_hashes
= elf_sym_hashes (abfd
);
1883 htab
= or1k_elf_hash_table (info
);
1887 dynobj
= htab
->root
.dynobj
;
1889 rel_end
= relocs
+ sec
->reloc_count
;
1890 for (rel
= relocs
; rel
< rel_end
; rel
++)
1892 struct elf_link_hash_entry
*h
;
1893 unsigned long r_symndx
;
1894 unsigned char tls_type
;
1897 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1898 if (r_symndx
< symtab_hdr
->sh_info
)
1902 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1903 while (h
->root
.type
== bfd_link_hash_indirect
1904 || h
->root
.type
== bfd_link_hash_warning
)
1905 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1908 r_type
= ELF32_R_TYPE (rel
->r_info
);
1911 case R_OR1K_TLS_GD_HI16
:
1912 case R_OR1K_TLS_GD_LO16
:
1913 case R_OR1K_TLS_GD_PG21
:
1914 case R_OR1K_TLS_GD_LO13
:
1917 case R_OR1K_TLS_LDM_HI16
:
1918 case R_OR1K_TLS_LDM_LO16
:
1919 case R_OR1K_TLS_LDM_PG21
:
1920 case R_OR1K_TLS_LDM_LO13
:
1921 case R_OR1K_TLS_LDO_HI16
:
1922 case R_OR1K_TLS_LDO_LO16
:
1925 case R_OR1K_TLS_IE_HI16
:
1926 case R_OR1K_TLS_IE_LO16
:
1927 case R_OR1K_TLS_IE_PG21
:
1928 case R_OR1K_TLS_IE_LO13
:
1929 case R_OR1K_TLS_IE_AHI16
:
1932 case R_OR1K_TLS_LE_HI16
:
1933 case R_OR1K_TLS_LE_LO16
:
1934 case R_OR1K_TLS_LE_AHI16
:
1935 case R_OR1K_TLS_LE_SLO16
:
1939 tls_type
= TLS_NONE
;
1942 /* Record TLS type. */
1944 ((struct elf_or1k_link_hash_entry
*) h
)->tls_type
|= tls_type
;
1947 unsigned char *local_tls_type
;
1949 /* This is a TLS type record for a local symbol. */
1950 local_tls_type
= (unsigned char *) elf_or1k_local_tls_type (abfd
);
1951 if (local_tls_type
== NULL
)
1955 size
= symtab_hdr
->sh_info
;
1956 local_tls_type
= bfd_zalloc (abfd
, size
);
1957 if (local_tls_type
== NULL
)
1959 elf_or1k_local_tls_type (abfd
) = local_tls_type
;
1961 local_tls_type
[r_symndx
] |= tls_type
;
1966 /* This relocation describes the C++ object vtable hierarchy.
1967 Reconstruct it for later use during GC. */
1968 case R_OR1K_GNU_VTINHERIT
:
1969 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1973 /* This relocation describes which C++ vtable entries are actually
1974 used. Record for later use during GC. */
1975 case R_OR1K_GNU_VTENTRY
:
1976 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1980 /* This relocation requires .plt entry. */
1982 htab
->saw_plta
= TRUE
;
1988 h
->plt
.refcount
+= 1;
1993 case R_OR1K_GOT_PG21
:
1994 case R_OR1K_GOT_LO13
:
1995 case R_OR1K_TLS_GD_HI16
:
1996 case R_OR1K_TLS_GD_LO16
:
1997 case R_OR1K_TLS_GD_PG21
:
1998 case R_OR1K_TLS_GD_LO13
:
1999 case R_OR1K_TLS_IE_HI16
:
2000 case R_OR1K_TLS_IE_LO16
:
2001 case R_OR1K_TLS_IE_PG21
:
2002 case R_OR1K_TLS_IE_LO13
:
2003 case R_OR1K_TLS_IE_AHI16
:
2005 h
->got
.refcount
+= 1;
2008 bfd_signed_vma
*local_got_refcounts
;
2010 /* This is a global offset table entry for a local symbol. */
2011 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2012 if (local_got_refcounts
== NULL
)
2016 size
= symtab_hdr
->sh_info
;
2017 size
*= sizeof (bfd_signed_vma
);
2018 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2019 if (local_got_refcounts
== NULL
)
2021 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2023 local_got_refcounts
[r_symndx
] += 1;
2027 case R_OR1K_GOTOFF_HI16
:
2028 case R_OR1K_GOTOFF_LO16
:
2029 case R_OR1K_GOTOFF_AHI16
:
2030 case R_OR1K_GOTOFF_SLO16
:
2031 if (htab
->root
.sgot
== NULL
)
2034 htab
->root
.dynobj
= dynobj
= abfd
;
2035 if (!_bfd_elf_create_got_section (dynobj
, info
))
2040 case R_OR1K_INSN_REL_26
:
2041 case R_OR1K_HI_16_IN_INSN
:
2042 case R_OR1K_LO_16_IN_INSN
:
2046 case R_OR1K_PCREL_PG21
:
2050 if (h
!= NULL
&& !bfd_link_pic (info
))
2052 /* We may need a copy reloc. */
2055 /* We may also need a .plt entry. */
2056 h
->plt
.refcount
+= 1;
2057 if (r_type
!= R_OR1K_INSN_REL_26
)
2058 h
->pointer_equality_needed
= 1;
2061 /* If we are creating a shared library, and this is a reloc
2062 against a global symbol, or a non PC relative reloc
2063 against a local symbol, then we need to copy the reloc
2064 into the shared library. However, if we are linking with
2065 -Bsymbolic, we do not need to copy a reloc against a
2066 global symbol which is defined in an object we are
2067 including in the link (i.e., DEF_REGULAR is set). At
2068 this point we have not seen all the input files, so it is
2069 possible that DEF_REGULAR is not set now but will be set
2070 later (it is never cleared). In case of a weak definition,
2071 DEF_REGULAR may be cleared later by a strong definition in
2072 a shared library. We account for that possibility below by
2073 storing information in the relocs_copied field of the hash
2074 table entry. A similar situation occurs when creating
2075 shared libraries and symbol visibility changes render the
2078 If on the other hand, we are creating an executable, we
2079 may need to keep relocations for symbols satisfied by a
2080 dynamic library if we manage to avoid copy relocs for the
2083 if ((bfd_link_pic (info
)
2084 && (sec
->flags
& SEC_ALLOC
) != 0
2085 && (r_type
!= R_OR1K_INSN_REL_26
2087 && (!SYMBOLIC_BIND (info
, h
)
2088 || h
->root
.type
== bfd_link_hash_defweak
2089 || !h
->def_regular
))))
2090 || (!bfd_link_pic (info
)
2091 && (sec
->flags
& SEC_ALLOC
) != 0
2093 && (h
->root
.type
== bfd_link_hash_defweak
2094 || !h
->def_regular
)))
2096 struct elf_dyn_relocs
*sec_relocs
;
2097 struct elf_dyn_relocs
**head
;
2099 /* When creating a shared object, we must copy these
2100 relocs into the output file. We create a reloc
2101 section in dynobj and make room for the reloc. */
2105 unsigned int strndx
= elf_elfheader (abfd
)->e_shstrndx
;
2106 unsigned int shnam
= _bfd_elf_single_rel_hdr (sec
)->sh_name
;
2108 name
= bfd_elf_string_from_elf_section (abfd
, strndx
, shnam
);
2112 if (strncmp (name
, ".rela", 5) != 0
2113 || strcmp (bfd_section_name (sec
), name
+ 5) != 0)
2116 /* xgettext:c-format */
2117 (_("%pB: bad relocation section name `%s\'"),
2121 if (htab
->root
.dynobj
== NULL
)
2122 htab
->root
.dynobj
= abfd
;
2123 dynobj
= htab
->root
.dynobj
;
2125 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2128 sreloc
= _bfd_elf_make_dynamic_reloc_section
2129 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
2134 elf_section_data (sec
)->sreloc
= sreloc
;
2137 /* If this is a global symbol, we count the number of
2138 relocations we need for this symbol. */
2140 head
= &h
->dyn_relocs
;
2143 /* Track dynamic relocs needed for local syms too.
2144 We really need local syms available to do this
2148 Elf_Internal_Sym
*isym
;
2151 isym
= bfd_sym_from_r_symndx (&htab
->root
.sym_cache
,
2156 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2160 vpp
= &elf_section_data (s
)->local_dynrel
;
2161 head
= (struct elf_dyn_relocs
**) vpp
;
2165 /* Allocate this sections dynamic reolcations structure if this
2166 is a new section. */
2167 if (sec_relocs
== NULL
|| sec_relocs
->sec
!= sec
)
2169 size_t amt
= sizeof *sec_relocs
;
2170 sec_relocs
= ((struct elf_dyn_relocs
*)
2171 bfd_alloc (htab
->root
.dynobj
, amt
));
2172 if (sec_relocs
== NULL
)
2174 sec_relocs
->next
= *head
;
2176 sec_relocs
->sec
= sec
;
2177 sec_relocs
->count
= 0;
2178 sec_relocs
->pc_count
= 0;
2181 sec_relocs
->count
+= 1;
2182 if (r_type
== R_OR1K_INSN_REL_26
)
2183 sec_relocs
->pc_count
+= 1;
2194 or1k_write_plt_entry (bfd
*output_bfd
, bfd_byte
*contents
, unsigned insn1
,
2195 unsigned insn2
, unsigned insn3
, unsigned insnj
)
2197 unsigned nodelay
= elf_elfheader (output_bfd
)->e_flags
& EF_OR1K_NODELAY
;
2200 /* Honor the no-delay-slot setting. */
2201 if (insn3
== OR1K_NOP
)
2207 insn3
= insn2
, insn2
= insnj
;
2214 insn4
= insn3
, insn3
= insnj
;
2217 bfd_put_32 (output_bfd
, insn1
, contents
);
2218 bfd_put_32 (output_bfd
, insn2
, contents
+ 4);
2219 bfd_put_32 (output_bfd
, insn3
, contents
+ 8);
2220 bfd_put_32 (output_bfd
, insn4
, contents
+ 12);
2223 /* Finish up the dynamic sections. */
2226 or1k_elf_finish_dynamic_sections (bfd
*output_bfd
,
2227 struct bfd_link_info
*info
)
2230 asection
*sdyn
, *sgot
;
2231 struct elf_or1k_link_hash_table
*htab
;
2233 htab
= or1k_elf_hash_table (info
);
2237 dynobj
= htab
->root
.dynobj
;
2239 sgot
= htab
->root
.sgotplt
;
2240 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2242 if (htab
->root
.dynamic_sections_created
)
2245 Elf32_External_Dyn
*dyncon
, *dynconend
;
2247 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
2249 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2250 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2252 for (; dyncon
< dynconend
; dyncon
++)
2254 Elf_Internal_Dyn dyn
;
2257 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2265 s
= htab
->root
.sgotplt
;
2266 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2270 s
= htab
->root
.srelplt
;
2271 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2275 s
= htab
->root
.srelplt
;
2276 dyn
.d_un
.d_val
= s
->size
;
2279 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2283 /* Fill in the first entry in the procedure linkage table. */
2284 splt
= htab
->root
.splt
;
2285 if (splt
&& splt
->size
> 0)
2287 unsigned plt0
, plt1
, plt2
;
2288 bfd_vma got_addr
= sgot
->output_section
->vma
+ sgot
->output_offset
;
2290 /* Note we force 16 byte alignment on the .got, so that
2291 the movhi/adrp can be shared between the two loads. */
2295 bfd_vma pc
= splt
->output_section
->vma
+ splt
->output_offset
;
2296 unsigned pa
= ((got_addr
>> 13) - (pc
>> 13)) & 0x1fffff;
2297 unsigned po
= got_addr
& 0x1fff;
2298 plt0
= OR1K_ADRP(12) | pa
;
2299 plt1
= OR1K_LWZ(15,12) | (po
+ 8);
2300 plt2
= OR1K_LWZ(12,12) | (po
+ 4);
2302 else if (bfd_link_pic (info
))
2304 plt0
= OR1K_LWZ(15, 16) | 8; /* .got+8 */
2305 plt1
= OR1K_LWZ(12, 16) | 4; /* .got+4 */
2310 unsigned ha
= ((got_addr
+ 0x8000) >> 16) & 0xffff;
2311 unsigned lo
= got_addr
& 0xffff;
2312 plt0
= OR1K_MOVHI(12) | ha
;
2313 plt1
= OR1K_LWZ(15,12) | (lo
+ 8);
2314 plt2
= OR1K_LWZ(12,12) | (lo
+ 4);
2317 or1k_write_plt_entry (output_bfd
, splt
->contents
,
2318 plt0
, plt1
, plt2
, OR1K_JR(15));
2320 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
2324 /* Set the first entry in the global offset table to the address of
2325 the dynamic section. */
2326 if (sgot
&& sgot
->size
> 0)
2329 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2331 bfd_put_32 (output_bfd
,
2332 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2334 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2337 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
2338 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2343 /* Finish up dynamic symbol handling. We set the contents of various
2344 dynamic sections here. */
2347 or1k_elf_finish_dynamic_symbol (bfd
*output_bfd
,
2348 struct bfd_link_info
*info
,
2349 struct elf_link_hash_entry
*h
,
2350 Elf_Internal_Sym
*sym
)
2352 struct elf_or1k_link_hash_table
*htab
;
2355 htab
= or1k_elf_hash_table (info
);
2359 if (h
->plt
.offset
!= (bfd_vma
) -1)
2361 unsigned int plt0
, plt1
, plt2
;
2365 bfd_vma plt_base_addr
;
2369 bfd_vma got_base_addr
;
2372 Elf_Internal_Rela rela
;
2374 /* This symbol has an entry in the procedure linkage table. Set
2376 BFD_ASSERT (h
->dynindx
!= -1);
2378 splt
= htab
->root
.splt
;
2379 sgot
= htab
->root
.sgotplt
;
2380 srela
= htab
->root
.srelplt
;
2381 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
2383 plt_base_addr
= splt
->output_section
->vma
+ splt
->output_offset
;
2384 got_base_addr
= sgot
->output_section
->vma
+ sgot
->output_offset
;
2386 /* Get the index in the procedure linkage table which
2387 corresponds to this symbol. This is the index of this symbol
2388 in all the symbols for which we are making plt entries. The
2389 first entry in the procedure linkage table is reserved. */
2390 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2391 plt_addr
= plt_base_addr
+ h
->plt
.offset
;
2392 plt_reloc
= plt_index
* sizeof (Elf32_External_Rela
);
2394 /* Get the offset into the .got table of the entry that
2395 corresponds to this function. Each .got entry is 4 bytes.
2396 The first three are reserved. */
2397 got_offset
= (plt_index
+ 3) * 4;
2398 got_addr
= got_base_addr
+ got_offset
;
2400 /* Fill in the entry in the procedure linkage table. */
2403 unsigned pa
= ((got_addr
>> 13) - (plt_addr
>> 13)) & 0x1fffff;
2404 unsigned po
= (got_addr
& 0x1fff);
2405 plt0
= OR1K_ADRP(12) | pa
;
2406 plt1
= OR1K_LWZ(12,12) | po
;
2407 plt2
= OR1K_ORI0(11) | plt_reloc
;
2409 else if (bfd_link_pic (info
))
2411 plt0
= OR1K_LWZ(12,16) | got_offset
;
2412 plt1
= OR1K_ORI0(11) | plt_reloc
;
2417 unsigned ha
= ((got_addr
+ 0x8000) >> 16) & 0xffff;
2418 unsigned lo
= got_addr
& 0xffff;
2419 plt0
= OR1K_MOVHI(12) | ha
;
2420 plt1
= OR1K_LWZ(12,12) | lo
;
2421 plt2
= OR1K_ORI0(11) | plt_reloc
;
2424 or1k_write_plt_entry (output_bfd
, splt
->contents
+ h
->plt
.offset
,
2425 plt0
, plt1
, plt2
, OR1K_JR(12));
2427 /* Fill in the entry in the global offset table. We initialize it to
2428 point to the top of the plt. This is done to lazy lookup the actual
2429 symbol as the first plt entry will be setup by libc to call the
2430 runtime dynamic linker. */
2431 bfd_put_32 (output_bfd
, plt_base_addr
, sgot
->contents
+ got_offset
);
2433 /* Fill in the entry in the .rela.plt section. */
2434 rela
.r_offset
= got_addr
;
2435 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_JMP_SLOT
);
2437 loc
= srela
->contents
;
2438 loc
+= plt_index
* sizeof (Elf32_External_Rela
);
2439 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2441 if (!h
->def_regular
)
2443 /* Mark the symbol as undefined, rather than as defined in
2444 the .plt section. Leave the value alone. */
2445 sym
->st_shndx
= SHN_UNDEF
;
2449 if (h
->got
.offset
!= (bfd_vma
) -1
2450 && (h
->got
.offset
& 2) == 0) /* Homemade TLS check. */
2454 Elf_Internal_Rela rela
;
2456 /* This symbol has an entry in the global offset table. Set it
2458 sgot
= htab
->root
.sgot
;
2459 srelgot
= htab
->root
.srelgot
;
2460 BFD_ASSERT (sgot
!= NULL
&& srelgot
!= NULL
);
2462 rela
.r_offset
= (sgot
->output_section
->vma
2463 + sgot
->output_offset
2464 + (h
->got
.offset
&~ 1));
2466 /* If this is a -Bsymbolic link, and the symbol is defined
2467 locally, we just want to emit a RELATIVE reloc. Likewise if
2468 the symbol was forced to be local because of a version file.
2469 The entry in the global offset table will already have been
2470 initialized in the relocate_section function. */
2471 if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
2473 rela
.r_info
= ELF32_R_INFO (0, R_OR1K_RELATIVE
);
2474 rela
.r_addend
= (h
->root
.u
.def
.value
2475 + h
->root
.u
.def
.section
->output_section
->vma
2476 + h
->root
.u
.def
.section
->output_offset
);
2480 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
2481 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
2482 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_GLOB_DAT
);
2486 loc
= srelgot
->contents
;
2487 loc
+= srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
2488 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2489 ++srelgot
->reloc_count
;
2495 Elf_Internal_Rela rela
;
2497 /* This symbols needs a copy reloc. Set it up. */
2498 BFD_ASSERT (h
->dynindx
!= -1
2499 && (h
->root
.type
== bfd_link_hash_defined
2500 || h
->root
.type
== bfd_link_hash_defweak
));
2502 rela
.r_offset
= (h
->root
.u
.def
.value
2503 + h
->root
.u
.def
.section
->output_section
->vma
2504 + h
->root
.u
.def
.section
->output_offset
);
2505 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_COPY
);
2507 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
2508 s
= htab
->root
.sreldynrelro
;
2510 s
= htab
->root
.srelbss
;
2511 loc
= s
->contents
+ s
->reloc_count
* sizeof (Elf32_External_Rela
);
2512 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2516 /* Mark some specially defined symbols as absolute. */
2517 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2518 || h
== htab
->root
.hgot
)
2519 sym
->st_shndx
= SHN_ABS
;
2524 static enum elf_reloc_type_class
2525 or1k_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2526 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2527 const Elf_Internal_Rela
*rela
)
2529 switch ((int) ELF32_R_TYPE (rela
->r_info
))
2531 case R_OR1K_RELATIVE
: return reloc_class_relative
;
2532 case R_OR1K_JMP_SLOT
: return reloc_class_plt
;
2533 case R_OR1K_COPY
: return reloc_class_copy
;
2534 default: return reloc_class_normal
;
2538 /* Adjust a symbol defined by a dynamic object and referenced by a
2539 regular object. The current definition is in some section of the
2540 dynamic object, but we're not including those sections. We have to
2541 change the definition to something the rest of the link can
2545 or1k_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2546 struct elf_link_hash_entry
*h
)
2548 struct elf_or1k_link_hash_table
*htab
;
2552 dynobj
= elf_hash_table (info
)->dynobj
;
2554 /* Make sure we know what is going on here. */
2555 BFD_ASSERT (dynobj
!= NULL
2560 && !h
->def_regular
)));
2562 /* If this is a function, put it in the procedure linkage table. We
2563 will fill in the contents of the procedure linkage table later,
2564 when we know the address of the .got section. */
2565 if (h
->type
== STT_FUNC
2568 if (! bfd_link_pic (info
)
2571 && h
->root
.type
!= bfd_link_hash_undefweak
2572 && h
->root
.type
!= bfd_link_hash_undefined
)
2574 /* This case can occur if we saw a PLT reloc in an input
2575 file, but the symbol was never referred to by a dynamic
2576 object. In such a case, we don't actually need to build
2577 a procedure linkage table, and we can just do a PCREL
2579 h
->plt
.offset
= (bfd_vma
) -1;
2586 h
->plt
.offset
= (bfd_vma
) -1;
2588 /* If this is a weak symbol, and there is a real definition, the
2589 processor independent code will have arranged for us to see the
2590 real definition first, and we can just use the same value. */
2591 if (h
->is_weakalias
)
2593 struct elf_link_hash_entry
*def
= weakdef (h
);
2594 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
2595 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
2596 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
2600 /* This is a reference to a symbol defined by a dynamic object which
2601 is not a function. */
2603 /* If we are creating a shared library, we must presume that the
2604 only references to the symbol are via the global offset table.
2605 For such cases we need not do anything here; the relocations will
2606 be handled correctly by relocate_section. */
2607 if (bfd_link_pic (info
))
2610 /* If there are no references to this symbol that do not use the
2611 GOT, we don't need to generate a copy reloc. */
2612 if (!h
->non_got_ref
)
2615 /* If -z nocopyreloc was given, we won't generate them either. */
2616 if (info
->nocopyreloc
)
2622 /* If we don't find any dynamic relocs in read-only sections, then
2623 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2624 if (!_bfd_elf_readonly_dynrelocs (h
))
2630 /* We must allocate the symbol in our .dynbss section, which will
2631 become part of the .bss section of the executable. There will be
2632 an entry for this symbol in the .dynsym section. The dynamic
2633 object will contain position independent code, so all references
2634 from the dynamic object to this symbol will go through the global
2635 offset table. The dynamic linker will use the .dynsym entry to
2636 determine the address it must put in the global offset table, so
2637 both the dynamic object and the regular object will refer to the
2638 same memory location for the variable. */
2640 htab
= or1k_elf_hash_table (info
);
2644 /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
2645 to copy the initial value out of the dynamic object and into the
2646 runtime process image. We need to remember the offset into the
2647 .rela.bss section we are going to use. */
2648 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2650 s
= htab
->root
.sdynrelro
;
2651 srel
= htab
->root
.sreldynrelro
;
2655 s
= htab
->root
.sdynbss
;
2656 srel
= htab
->root
.srelbss
;
2658 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2660 srel
->size
+= sizeof (Elf32_External_Rela
);
2664 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2667 /* Caclulate an update the sizes required for a symbol in the GOT and
2668 RELA relocation section based on the TLS_TYPE and whether or not the symbol
2671 Symbols with TLS_GD access require 8 bytes in the GOT and, if dynamic,
2672 require two relocation entries. Symbols with TLS_IE access require 4 bytes
2673 in the GOT and, if dynamic, require one relocation entry. Symbols may have
2674 both TLS_GD and TLS_IE access to be accounted for.
2676 Other symbols require 4 bytes in the GOT table and, if dynamic, require one
2677 relocation entry. */
2680 or1k_set_got_and_rela_sizes (const unsigned char tls_type
,
2681 const bfd_boolean dynamic
,
2685 bfd_boolean is_tls_entry
= FALSE
;
2687 /* TLS GD requires two GOT entries and two relocs. */
2688 if ((tls_type
& TLS_GD
) != 0)
2691 is_tls_entry
= TRUE
;
2694 if ((tls_type
& TLS_IE
) != 0)
2697 is_tls_entry
= TRUE
;
2700 if (is_tls_entry
== FALSE
)
2705 if ((tls_type
& TLS_GD
) != 0)
2706 *rela_size
+= 2 * sizeof (Elf32_External_Rela
);
2708 if ((tls_type
& TLS_IE
) != 0)
2709 *rela_size
+= sizeof (Elf32_External_Rela
);
2711 if (is_tls_entry
== FALSE
)
2712 *rela_size
+= sizeof (Elf32_External_Rela
);
2717 /* Allocate space in .plt, .got and associated reloc sections for
2721 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2723 struct bfd_link_info
*info
;
2724 struct elf_or1k_link_hash_table
*htab
;
2725 struct elf_dyn_relocs
*sec_relocs
;
2727 if (h
->root
.type
== bfd_link_hash_indirect
)
2730 info
= (struct bfd_link_info
*) inf
;
2731 htab
= or1k_elf_hash_table (info
);
2735 if (htab
->root
.dynamic_sections_created
2736 && h
->plt
.refcount
> 0)
2738 /* Make sure this symbol is output as a dynamic symbol.
2739 Undefined weak syms won't yet be marked as dynamic. */
2740 if (h
->dynindx
== -1
2741 && !h
->forced_local
)
2743 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2747 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info
), h
))
2749 asection
*splt
= htab
->root
.splt
;
2751 /* If this is the first .plt entry, make room for the special
2753 if (splt
->size
== 0)
2754 splt
->size
= PLT_ENTRY_SIZE
;
2756 h
->plt
.offset
= splt
->size
;
2758 /* If this symbol is not defined in a regular file, and we are
2759 not generating a shared library, then set the symbol to this
2760 location in the .plt. This is required to make function
2761 pointers compare as equal between the normal executable and
2762 the shared library. */
2763 if (! bfd_link_pic (info
)
2766 h
->root
.u
.def
.section
= splt
;
2767 h
->root
.u
.def
.value
= h
->plt
.offset
;
2770 /* Make room for this entry. */
2771 splt
->size
+= PLT_ENTRY_SIZE
;
2773 /* We also need to make an entry in the .got.plt section, which
2774 will be placed in the .got section by the linker script. */
2775 htab
->root
.sgotplt
->size
+= 4;
2777 /* We also need to make an entry in the .rel.plt section. */
2778 htab
->root
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
2782 h
->plt
.offset
= (bfd_vma
) -1;
2788 h
->plt
.offset
= (bfd_vma
) -1;
2792 if (h
->got
.refcount
> 0)
2796 unsigned char tls_type
;
2798 /* Make sure this symbol is output as a dynamic symbol.
2799 Undefined weak syms won't yet be marked as dynamic. */
2800 if (h
->dynindx
== -1
2801 && !h
->forced_local
)
2803 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2807 sgot
= htab
->root
.sgot
;
2809 h
->got
.offset
= sgot
->size
;
2811 tls_type
= ((struct elf_or1k_link_hash_entry
*) h
)->tls_type
;
2813 dyn
= htab
->root
.dynamic_sections_created
;
2814 dyn
= WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
);
2815 or1k_set_got_and_rela_sizes (tls_type
, dyn
,
2816 &sgot
->size
, &htab
->root
.srelgot
->size
);
2819 h
->got
.offset
= (bfd_vma
) -1;
2821 if (h
->dyn_relocs
== NULL
)
2824 /* In the shared -Bsymbolic case, discard space allocated for
2825 dynamic pc-relative relocs against symbols which turn out to be
2826 defined in regular objects. For the normal shared case, discard
2827 space for pc-relative relocs that have become local due to symbol
2828 visibility changes. */
2830 if (bfd_link_pic (info
))
2832 if (SYMBOL_CALLS_LOCAL (info
, h
))
2834 struct elf_dyn_relocs
**pp
;
2836 for (pp
= &h
->dyn_relocs
; (sec_relocs
= *pp
) != NULL
;)
2838 sec_relocs
->count
-= sec_relocs
->pc_count
;
2839 sec_relocs
->pc_count
= 0;
2840 if (sec_relocs
->count
== 0)
2841 *pp
= sec_relocs
->next
;
2843 pp
= &sec_relocs
->next
;
2847 /* Also discard relocs on undefined weak syms with non-default
2849 if (h
->dyn_relocs
!= NULL
2850 && h
->root
.type
== bfd_link_hash_undefweak
)
2852 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2853 h
->dyn_relocs
= NULL
;
2855 /* Make sure undefined weak symbols are output as a dynamic
2857 else if (h
->dynindx
== -1
2858 && !h
->forced_local
)
2860 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2867 /* For the non-shared case, discard space for relocs against
2868 symbols which turn out to need copy relocs or are not
2874 || (htab
->root
.dynamic_sections_created
2875 && (h
->root
.type
== bfd_link_hash_undefweak
2876 || h
->root
.type
== bfd_link_hash_undefined
))))
2878 /* Make sure this symbol is output as a dynamic symbol.
2879 Undefined weak syms won't yet be marked as dynamic. */
2880 if (h
->dynindx
== -1
2881 && !h
->forced_local
)
2883 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2887 /* If that succeeded, we know we'll be keeping all the
2889 if (h
->dynindx
!= -1)
2893 h
->dyn_relocs
= NULL
;
2898 /* Finally, allocate space. */
2899 for (sec_relocs
= h
->dyn_relocs
;
2901 sec_relocs
= sec_relocs
->next
)
2903 asection
*sreloc
= elf_section_data (sec_relocs
->sec
)->sreloc
;
2904 sreloc
->size
+= sec_relocs
->count
* sizeof (Elf32_External_Rela
);
2910 /* Set the sizes of the dynamic sections. */
2913 or1k_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2914 struct bfd_link_info
*info
)
2916 struct elf_or1k_link_hash_table
*htab
;
2922 htab
= or1k_elf_hash_table (info
);
2926 dynobj
= htab
->root
.dynobj
;
2927 BFD_ASSERT (dynobj
!= NULL
);
2929 if (htab
->root
.dynamic_sections_created
)
2931 /* Set the contents of the .interp section to the interpreter. */
2932 if (bfd_link_executable (info
) && !info
->nointerp
)
2934 s
= bfd_get_section_by_name (dynobj
, ".interp");
2935 BFD_ASSERT (s
!= NULL
);
2936 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2937 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2941 /* Set up .got offsets for local syms, and space for local dynamic
2943 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2945 bfd_signed_vma
*local_got
;
2946 bfd_signed_vma
*end_local_got
;
2947 bfd_size_type locsymcount
;
2948 Elf_Internal_Shdr
*symtab_hdr
;
2949 unsigned char *local_tls_type
;
2952 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2955 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2957 struct elf_dyn_relocs
*sec_relocs
;
2959 for (sec_relocs
= ((struct elf_dyn_relocs
*)
2960 elf_section_data (s
)->local_dynrel
);
2962 sec_relocs
= sec_relocs
->next
)
2964 if (! bfd_is_abs_section (sec_relocs
->sec
)
2965 && bfd_is_abs_section (sec_relocs
->sec
->output_section
))
2967 /* Input section has been discarded, either because
2968 it is a copy of a linkonce section or due to
2969 linker script /DISCARD/, so we'll be discarding
2972 else if (sec_relocs
->count
!= 0)
2974 srel
= elf_section_data (sec_relocs
->sec
)->sreloc
;
2975 srel
->size
+= sec_relocs
->count
2976 * sizeof (Elf32_External_Rela
);
2977 if ((sec_relocs
->sec
->output_section
->flags
& SEC_READONLY
)
2979 info
->flags
|= DF_TEXTREL
;
2984 local_got
= elf_local_got_refcounts (ibfd
);
2988 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2989 locsymcount
= symtab_hdr
->sh_info
;
2990 end_local_got
= local_got
+ locsymcount
;
2991 s
= htab
->root
.sgot
;
2992 srel
= htab
->root
.srelgot
;
2993 local_tls_type
= (unsigned char *) elf_or1k_local_tls_type (ibfd
);
2994 for (; local_got
< end_local_got
; ++local_got
)
2998 unsigned char tls_type
= (local_tls_type
== NULL
)
3002 *local_got
= s
->size
;
3003 or1k_set_got_and_rela_sizes (tls_type
, bfd_link_pic (info
),
3004 &s
->size
, &srel
->size
);
3008 *local_got
= (bfd_vma
) -1;
3015 /* Allocate global sym .plt and .got entries, and space for global
3016 sym dynamic relocs. */
3017 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
3019 /* We now have determined the sizes of the various dynamic sections.
3020 Allocate memory for them. */
3022 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3024 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3027 if (s
== htab
->root
.splt
3028 || s
== htab
->root
.sgot
3029 || s
== htab
->root
.sgotplt
3030 || s
== htab
->root
.sdynbss
3031 || s
== htab
->root
.sdynrelro
)
3033 /* Strip this section if we don't need it; see the
3036 else if (CONST_STRNEQ (bfd_section_name (s
), ".rela"))
3038 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
3041 /* We use the reloc_count field as a counter if we need
3042 to copy relocs into the output file. */
3046 /* It's not one of our sections, so don't allocate space. */
3051 /* If we don't need this section, strip it from the
3052 output file. This is mostly to handle .rela.bss and
3053 .rela.plt. We must create both sections in
3054 create_dynamic_sections, because they must be created
3055 before the linker maps input sections to output
3056 sections. The linker does that before
3057 adjust_dynamic_symbol is called, and it is that
3058 function which decides whether anything needs to go
3059 into these sections. */
3060 s
->flags
|= SEC_EXCLUDE
;
3064 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3067 /* Allocate memory for the section contents. We use bfd_zalloc
3068 here in case unused entries are not reclaimed before the
3069 section's contents are written out. This should not happen,
3070 but this way if it does, we get a R_OR1K_NONE reloc instead
3072 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3074 if (s
->contents
== NULL
)
3078 return _bfd_elf_add_dynamic_tags (output_bfd
, info
, relocs
);
3081 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3084 or1k_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3085 struct elf_link_hash_entry
*dir
,
3086 struct elf_link_hash_entry
*ind
)
3088 struct elf_or1k_link_hash_entry
* edir
;
3089 struct elf_or1k_link_hash_entry
* eind
;
3091 edir
= (struct elf_or1k_link_hash_entry
*) dir
;
3092 eind
= (struct elf_or1k_link_hash_entry
*) ind
;
3094 if (ind
->root
.type
== bfd_link_hash_indirect
)
3096 if (dir
->got
.refcount
<= 0)
3098 edir
->tls_type
= eind
->tls_type
;
3099 eind
->tls_type
= TLS_UNKNOWN
;
3103 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3106 /* Set the right machine number. */
3109 or1k_elf_object_p (bfd
*abfd
)
3111 unsigned long mach
= bfd_mach_or1k
;
3113 if (elf_elfheader (abfd
)->e_flags
& EF_OR1K_NODELAY
)
3114 mach
= bfd_mach_or1knd
;
3116 return bfd_default_set_arch_mach (abfd
, bfd_arch_or1k
, mach
);
3119 /* Store the machine number in the flags field. */
3122 or1k_elf_final_write_processing (bfd
*abfd
)
3124 switch (bfd_get_mach (abfd
))
3129 case bfd_mach_or1knd
:
3130 elf_elfheader (abfd
)->e_flags
|= EF_OR1K_NODELAY
;
3133 return _bfd_elf_final_write_processing (abfd
);
3137 or1k_elf_set_private_flags (bfd
*abfd
, flagword flags
)
3139 BFD_ASSERT (!elf_flags_init (abfd
)
3140 || elf_elfheader (abfd
)->e_flags
== flags
);
3142 elf_elfheader (abfd
)->e_flags
= flags
;
3143 elf_flags_init (abfd
) = TRUE
;
3147 /* Make sure all input files are consistent with respect to
3148 EF_OR1K_NODELAY flag setting. */
3151 elf32_or1k_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3153 bfd
*obfd
= info
->output_bfd
;
3157 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3158 out_flags
= elf_elfheader (obfd
)->e_flags
;
3160 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3161 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3164 if (!elf_flags_init (obfd
))
3166 elf_flags_init (obfd
) = TRUE
;
3167 elf_elfheader (obfd
)->e_flags
= in_flags
;
3172 if (in_flags
== out_flags
)
3175 if ((in_flags
& EF_OR1K_NODELAY
) != (out_flags
& EF_OR1K_NODELAY
))
3178 (_("%pB: %s flag mismatch with previous modules"),
3179 ibfd
, "EF_OR1K_NODELAY");
3181 bfd_set_error (bfd_error_bad_value
);
3189 /* Implement elf_backend_grok_prstatus:
3190 Support for core dump NOTE sections. */
3192 or1k_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
3197 switch (note
->descsz
)
3202 case 212: /* Linux/OpenRISC */
3204 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3207 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3216 /* Make a ".reg/999" section. */
3217 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3218 size
, note
->descpos
+ offset
);
3221 /* Implement elf_backend_grok_psinfo. */
3223 or1k_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
3225 switch (note
->descsz
)
3230 case 128: /* Linux/OpenRISC elf_prpsinfo */
3231 elf_tdata (abfd
)->core
->program
3232 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
3233 elf_tdata (abfd
)->core
->command
3234 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
3241 #define ELF_ARCH bfd_arch_or1k
3242 #define ELF_MACHINE_CODE EM_OR1K
3243 #define ELF_TARGET_ID OR1K_ELF_DATA
3244 #define ELF_MAXPAGESIZE 0x2000
3246 #define TARGET_BIG_SYM or1k_elf32_vec
3247 #define TARGET_BIG_NAME "elf32-or1k"
3249 #define elf_info_to_howto_rel NULL
3250 #define elf_info_to_howto or1k_info_to_howto_rela
3251 #define elf_backend_relocate_section or1k_elf_relocate_section
3252 #define elf_backend_gc_mark_hook or1k_elf_gc_mark_hook
3253 #define elf_backend_check_relocs or1k_elf_check_relocs
3254 #define elf_backend_reloc_type_class or1k_elf_reloc_type_class
3255 #define elf_backend_can_gc_sections 1
3256 #define elf_backend_rela_normal 1
3258 #define bfd_elf32_mkobject elf_or1k_mkobject
3260 #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
3261 #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
3262 #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
3263 #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
3265 #define elf_backend_object_p or1k_elf_object_p
3266 #define elf_backend_final_write_processing or1k_elf_final_write_processing
3267 #define elf_backend_can_refcount 1
3269 #define elf_backend_plt_readonly 1
3270 #define elf_backend_want_got_plt 1
3271 #define elf_backend_want_plt_sym 0
3272 #define elf_backend_got_header_size 12
3273 #define elf_backend_dtrel_excludes_plt 1
3274 #define elf_backend_want_dynrelro 1
3276 #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create
3277 #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol
3278 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3279 #define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
3280 #define elf_backend_size_dynamic_sections or1k_elf_size_dynamic_sections
3281 #define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
3282 #define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
3284 #define elf_backend_grok_prstatus or1k_grok_prstatus
3285 #define elf_backend_grok_psinfo or1k_grok_psinfo
3287 #include "elf32-target.h"