1 /* Or1k-specific support for 32-bit ELF.
2 Copyright 2001-2014 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 PLT_ENTRY_SIZE 20
32 #define PLT0_ENTRY_WORD0 0x19800000 /* l.movhi r12, 0 <- hi(.got+4) */
33 #define PLT0_ENTRY_WORD1 0xa98c0000 /* l.ori r12, r12, 0 <- lo(.got+4) */
34 #define PLT0_ENTRY_WORD2 0x85ec0004 /* l.lwz r15, 4(r12) <- *(.got+8)*/
35 #define PLT0_ENTRY_WORD3 0x44007800 /* l.jr r15 */
36 #define PLT0_ENTRY_WORD4 0x858c0000 /* l.lwz r12, 0(r12) */
38 #define PLT0_PIC_ENTRY_WORD0 0x85900004 /* l.lwz r12, 4(r16) */
39 #define PLT0_PIC_ENTRY_WORD1 0x85f00008 /* l.lwz r15, 8(r16) */
40 #define PLT0_PIC_ENTRY_WORD2 0x44007800 /* l.jr r15 */
41 #define PLT0_PIC_ENTRY_WORD3 0x15000000 /* l.nop */
42 #define PLT0_PIC_ENTRY_WORD4 0x15000000 /* l.nop */
44 #define PLT_ENTRY_WORD0 0x19800000 /* l.movhi r12, 0 <- hi(got idx addr) */
45 #define PLT_ENTRY_WORD1 0xa98c0000 /* l.ori r12, r12, 0 <- lo(got idx addr) */
46 #define PLT_ENTRY_WORD2 0x858c0000 /* l.lwz r12, 0(r12) */
47 #define PLT_ENTRY_WORD3 0x44006000 /* l.jr r12 */
48 #define PLT_ENTRY_WORD4 0xa9600000 /* l.ori r11, r0, 0 <- reloc offset */
50 #define PLT_PIC_ENTRY_WORD0 0x85900000 /* l.lwz r12, 0(r16) <- index in got */
51 #define PLT_PIC_ENTRY_WORD1 0xa9600000 /* l.ori r11, r0, 0 <- reloc offset */
52 #define PLT_PIC_ENTRY_WORD2 0x44006000 /* l.jr r12 */
53 #define PLT_PIC_ENTRY_WORD3 0x15000000 /* l.nop */
54 #define PLT_PIC_ENTRY_WORD4 0x15000000 /* l.nop */
56 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
58 static reloc_howto_type or1k_elf_howto_table
[] =
60 /* This reloc does nothing. */
61 HOWTO (R_OR1K_NONE
, /* type */
63 2, /* size (0 = byte, 1 = short, 2 = long) */
65 FALSE
, /* pc_relative */
67 complain_overflow_dont
, /* complain_on_overflow */
68 bfd_elf_generic_reloc
, /* special_function */
69 "R_OR1K_NONE", /* name */
70 FALSE
, /* partial_inplace */
73 FALSE
), /* pcrel_offset */
77 2, /* size (0 = byte, 1 = short, 2 = long) */
79 FALSE
, /* pc_relative */
81 complain_overflow_unsigned
, /* complain_on_overflow */
82 bfd_elf_generic_reloc
, /* special_function */
83 "R_OR1K_32", /* name */
84 FALSE
, /* partial_inplace */
86 0xffffffff, /* dst_mask */
87 FALSE
), /* pcrel_offset */
91 1, /* size (0 = byte, 1 = short, 2 = long) */
93 FALSE
, /* pc_relative */
95 complain_overflow_unsigned
, /* complain_on_overflow */
96 bfd_elf_generic_reloc
, /* special_function */
97 "R_OR1K_16", /* name */
98 FALSE
, /* partial_inplace */
100 0xffff, /* dst_mask */
101 FALSE
), /* pcrel_offset */
105 0, /* size (0 = byte, 1 = short, 2 = long) */
107 FALSE
, /* pc_relative */
109 complain_overflow_unsigned
, /* complain_on_overflow */
110 bfd_elf_generic_reloc
, /* special_function */
111 "R_OR1K_8", /* name */
112 FALSE
, /* partial_inplace */
115 FALSE
), /* pcrel_offset */
117 HOWTO (R_OR1K_LO_16_IN_INSN
, /* type */
119 2, /* size (0 = byte, 1 = short, 2 = long) */
121 FALSE
, /* pc_relative */
123 complain_overflow_dont
, /* complain_on_overflow */
124 bfd_elf_generic_reloc
, /* special_function */
125 "R_OR1K_LO_16_IN_INSN", /* name */
126 FALSE
, /* partial_inplace */
128 0x0000ffff, /* dst_mask */
129 FALSE
), /* pcrel_offset */
131 HOWTO (R_OR1K_HI_16_IN_INSN
, /* type */
133 2, /* size (0 = byte, 1 = short, 2 = long) */
135 FALSE
, /* pc_relative */
137 complain_overflow_dont
, /* complain_on_overflow */
138 bfd_elf_generic_reloc
, /* special_function */
139 "R_OR1K_HI_16_IN_INSN", /* name */
140 FALSE
, /* partial_inplace */
142 0x0000ffff, /* dst_mask */
143 FALSE
), /* pcrel_offset */
145 /* A PC relative 26 bit relocation, right shifted by 2. */
146 HOWTO (R_OR1K_INSN_REL_26
, /* type */
148 2, /* size (0 = byte, 1 = short, 2 = long) */
150 TRUE
, /* pc_relative */
152 complain_overflow_signed
, /* complain_on_overflow */
153 bfd_elf_generic_reloc
, /* special_function */
154 "R_OR1K_INSN_REL_26", /* name */
155 FALSE
, /* partial_inplace */
157 0x03ffffff, /* dst_mask */
158 TRUE
), /* pcrel_offset */
160 /* GNU extension to record C++ vtable hierarchy. */
161 HOWTO (R_OR1K_GNU_VTINHERIT
, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 FALSE
, /* pc_relative */
167 complain_overflow_dont
, /* complain_on_overflow */
168 NULL
, /* special_function */
169 "R_OR1K_GNU_VTINHERIT", /* name */
170 FALSE
, /* partial_inplace */
173 FALSE
), /* pcrel_offset */
175 /* GNU extension to record C++ vtable member usage. */
176 HOWTO (R_OR1K_GNU_VTENTRY
, /* type */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
180 FALSE
, /* pc_relative */
182 complain_overflow_dont
, /* complain_on_overflow */
183 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
184 "R_OR1K_GNU_VTENTRY", /* name */
185 FALSE
, /* partial_inplace */
188 FALSE
), /* pcrel_offset */
190 HOWTO (R_OR1K_32_PCREL
,
192 2, /* size (0 = byte, 1 = short, 2 = long) */
194 TRUE
, /* pc_relative */
196 complain_overflow_signed
, /* complain_on_overflow */
197 bfd_elf_generic_reloc
, /* special_function */
198 "R_OR1K_32_PCREL", /* name */
199 FALSE
, /* partial_inplace */
201 0xffffffff, /* dst_mask */
202 FALSE
), /* pcrel_offset */
204 HOWTO (R_OR1K_16_PCREL
,
206 1, /* size (0 = byte, 1 = short, 2 = long) */
208 TRUE
, /* pc_relative */
210 complain_overflow_signed
, /* complain_on_overflow */
211 bfd_elf_generic_reloc
, /* special_function */
212 "R_OR1K_16_PCREL", /* name */
213 FALSE
, /* partial_inplace */
215 0xffff, /* dst_mask */
216 FALSE
), /* pcrel_offset */
218 HOWTO (R_OR1K_8_PCREL
,
220 0, /* size (0 = byte, 1 = short, 2 = long) */
222 TRUE
, /* pc_relative */
224 complain_overflow_signed
, /* complain_on_overflow */
225 bfd_elf_generic_reloc
, /* special_function */
226 "R_OR1K_8_PCREL", /* name */
227 FALSE
, /* partial_inplace */
230 FALSE
), /* pcrel_offset */
232 HOWTO (R_OR1K_GOTPC_HI16
, /* Type. */
233 16, /* Rightshift. */
234 2, /* Size (0 = byte, 1 = short, 2 = long). */
236 TRUE
, /* PC_relative. */
238 complain_overflow_dont
, /* Complain on overflow. */
239 bfd_elf_generic_reloc
, /* Special Function. */
240 "R_OR1K_GOTPC_HI16", /* Name. */
241 FALSE
, /* Partial Inplace. */
242 0, /* Source Mask. */
243 0xffff, /* Dest Mask. */
244 TRUE
), /* PC relative offset? */
246 HOWTO (R_OR1K_GOTPC_LO16
, /* Type. */
248 2, /* Size (0 = byte, 1 = short, 2 = long). */
250 TRUE
, /* PC_relative. */
252 complain_overflow_dont
, /* Complain on overflow. */
253 bfd_elf_generic_reloc
, /* Special Function. */
254 "R_OR1K_GOTPC_LO16", /* Name. */
255 FALSE
, /* Partial Inplace. */
256 0, /* Source Mask. */
257 0xffff, /* Dest Mask. */
258 TRUE
), /* PC relative offset? */
260 HOWTO (R_OR1K_GOT16
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE
, /* pc_relative */
266 complain_overflow_signed
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_OR1K_GOT16", /* name */
269 FALSE
, /* partial_inplace */
271 0xffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
274 /* A 26 bit PLT relocation. Shifted by 2. */
275 HOWTO (R_OR1K_PLT26
, /* Type. */
277 2, /* Size (0 = byte, 1 = short, 2 = long). */
279 TRUE
, /* PC_relative. */
281 complain_overflow_dont
, /* Complain on overflow. */
282 bfd_elf_generic_reloc
,/* Special Function. */
283 "R_OR1K_PLT26", /* Name. */
284 FALSE
, /* Partial Inplace. */
285 0, /* Source Mask. */
286 0x03ffffff, /* Dest Mask. */
287 TRUE
), /* PC relative offset? */
289 HOWTO (R_OR1K_GOTOFF_HI16
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE
, /* pc_relative */
295 complain_overflow_dont
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_OR1K_GOTOFF_HI16", /* name */
298 FALSE
, /* partial_inplace */
300 0xffff, /* dst_mask */
301 FALSE
), /* pcrel_offset */
303 HOWTO (R_OR1K_GOTOFF_LO16
, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE
, /* pc_relative */
309 complain_overflow_dont
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_OR1K_GOTOFF_LO16", /* name */
312 FALSE
, /* partial_inplace */
314 0xffff, /* dst_mask */
315 FALSE
), /* pcrel_offset */
317 HOWTO (R_OR1K_COPY
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE
, /* pc_relative */
323 complain_overflow_bitfield
, /* complain_on_overflow */
324 bfd_elf_generic_reloc
, /* special_function */
325 "R_OR1K_COPY", /* name */
326 FALSE
, /* partial_inplace */
327 0xffffffff, /* src_mask */
328 0xffffffff, /* dst_mask */
329 FALSE
), /* pcrel_offset */
331 HOWTO (R_OR1K_GLOB_DAT
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_bitfield
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_OR1K_GLOB_DAT", /* name */
340 FALSE
, /* partial_inplace */
341 0xffffffff, /* src_mask */
342 0xffffffff, /* dst_mask */
343 FALSE
), /* pcrel_offset */
345 HOWTO (R_OR1K_JMP_SLOT
, /* type */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
349 FALSE
, /* pc_relative */
351 complain_overflow_bitfield
, /* complain_on_overflow */
352 bfd_elf_generic_reloc
, /* special_function */
353 "R_OR1K_JMP_SLOT", /* name */
354 FALSE
, /* partial_inplace */
355 0xffffffff, /* src_mask */
356 0xffffffff, /* dst_mask */
357 FALSE
), /* pcrel_offset */
359 HOWTO (R_OR1K_RELATIVE
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 FALSE
, /* pc_relative */
365 complain_overflow_bitfield
, /* complain_on_overflow */
366 bfd_elf_generic_reloc
, /* special_function */
367 "R_OR1K_RELATIVE", /* name */
368 FALSE
, /* partial_inplace */
369 0xffffffff, /* src_mask */
370 0xffffffff, /* dst_mask */
371 FALSE
), /* pcrel_offset */
373 HOWTO (R_OR1K_TLS_GD_HI16
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_dont
, /* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_OR1K_TLS_GD_HI16", /* name */
382 FALSE
, /* partial_inplace */
384 0xffff, /* dst_mask */
385 FALSE
), /* pcrel_offset */
387 HOWTO (R_OR1K_TLS_GD_LO16
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 FALSE
, /* pc_relative */
393 complain_overflow_dont
, /* complain_on_overflow */
394 bfd_elf_generic_reloc
, /* special_function */
395 "R_OR1K_TLS_GD_LO16", /* name */
396 FALSE
, /* partial_inplace */
398 0xffff, /* dst_mask */
399 FALSE
), /* pcrel_offset */
401 HOWTO (R_OR1K_TLS_LDM_HI16
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_dont
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_OR1K_TLS_LDM_HI16", /* name */
410 FALSE
, /* partial_inplace */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 HOWTO (R_OR1K_TLS_LDM_LO16
, /* type */
417 2, /* size (0 = byte, 1 = short, 2 = long) */
419 FALSE
, /* pc_relative */
421 complain_overflow_dont
, /* complain_on_overflow */
422 bfd_elf_generic_reloc
, /* special_function */
423 "R_OR1K_TLS_LDM_LO16", /* name */
424 FALSE
, /* partial_inplace */
426 0xffff, /* dst_mask */
427 FALSE
), /* pcrel_offset */
429 HOWTO (R_OR1K_TLS_LDO_HI16
, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 FALSE
, /* pc_relative */
435 complain_overflow_dont
, /* complain_on_overflow */
436 bfd_elf_generic_reloc
, /* special_function */
437 "R_OR1K_TLS_LDO_HI16", /* name */
438 FALSE
, /* partial_inplace */
440 0xffff, /* dst_mask */
441 FALSE
), /* pcrel_offset */
443 HOWTO (R_OR1K_TLS_LDO_LO16
, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 FALSE
, /* pc_relative */
449 complain_overflow_dont
, /* complain_on_overflow */
450 bfd_elf_generic_reloc
, /* special_function */
451 "R_OR1K_TLS_LDO_LO16", /* name */
452 FALSE
, /* partial_inplace */
454 0xffff, /* dst_mask */
455 FALSE
), /* pcrel_offset */
457 HOWTO (R_OR1K_TLS_IE_HI16
, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 FALSE
, /* pc_relative */
463 complain_overflow_dont
, /* complain_on_overflow */
464 bfd_elf_generic_reloc
, /* special_function */
465 "R_OR1K_TLS_IE_HI16", /* name */
466 FALSE
, /* partial_inplace */
468 0xffff, /* dst_mask */
469 FALSE
), /* pcrel_offset */
471 HOWTO (R_OR1K_TLS_IE_LO16
, /* type */
473 2, /* size (0 = byte, 1 = short, 2 = long) */
475 FALSE
, /* pc_relative */
477 complain_overflow_dont
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_OR1K_TLS_IE_LO16", /* name */
480 FALSE
, /* partial_inplace */
482 0xffff, /* dst_mask */
483 FALSE
), /* pcrel_offset */
485 HOWTO (R_OR1K_TLS_LE_HI16
, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE
, /* pc_relative */
491 complain_overflow_dont
, /* complain_on_overflow */
492 bfd_elf_generic_reloc
, /* special_function */
493 "R_OR1K_TLS_LE_HI16", /* name */
494 FALSE
, /* partial_inplace */
496 0xffff, /* dst_mask */
497 FALSE
), /* pcrel_offset */
499 HOWTO (R_OR1K_TLS_LE_LO16
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_dont
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 "R_OR1K_TLS_LE_LO16", /* name */
508 FALSE
, /* partial_inplace */
510 0xffff, /* dst_mask */
511 FALSE
), /* pcrel_offset */
515 /* Map BFD reloc types to Or1k ELF reloc types. */
517 struct or1k_reloc_map
519 bfd_reloc_code_real_type bfd_reloc_val
;
520 unsigned int or1k_reloc_val
;
523 static const struct or1k_reloc_map or1k_reloc_map
[] =
525 { BFD_RELOC_NONE
, R_OR1K_NONE
},
526 { BFD_RELOC_32
, R_OR1K_32
},
527 { BFD_RELOC_16
, R_OR1K_16
},
528 { BFD_RELOC_8
, R_OR1K_8
},
529 { BFD_RELOC_LO16
, R_OR1K_LO_16_IN_INSN
},
530 { BFD_RELOC_HI16
, R_OR1K_HI_16_IN_INSN
},
531 { BFD_RELOC_OR1K_REL_26
, R_OR1K_INSN_REL_26
},
532 { BFD_RELOC_VTABLE_ENTRY
, R_OR1K_GNU_VTENTRY
},
533 { BFD_RELOC_VTABLE_INHERIT
, R_OR1K_GNU_VTINHERIT
},
534 { BFD_RELOC_32_PCREL
, R_OR1K_32_PCREL
},
535 { BFD_RELOC_16_PCREL
, R_OR1K_16_PCREL
},
536 { BFD_RELOC_8_PCREL
, R_OR1K_8_PCREL
},
537 { BFD_RELOC_OR1K_GOTPC_HI16
, R_OR1K_GOTPC_HI16
},
538 { BFD_RELOC_OR1K_GOTPC_LO16
, R_OR1K_GOTPC_LO16
},
539 { BFD_RELOC_OR1K_GOT16
, R_OR1K_GOT16
},
540 { BFD_RELOC_OR1K_PLT26
, R_OR1K_PLT26
},
541 { BFD_RELOC_OR1K_GOTOFF_HI16
, R_OR1K_GOTOFF_HI16
},
542 { BFD_RELOC_OR1K_GOTOFF_LO16
, R_OR1K_GOTOFF_LO16
},
543 { BFD_RELOC_OR1K_GLOB_DAT
, R_OR1K_GLOB_DAT
},
544 { BFD_RELOC_OR1K_COPY
, R_OR1K_COPY
},
545 { BFD_RELOC_OR1K_JMP_SLOT
, R_OR1K_JMP_SLOT
},
546 { BFD_RELOC_OR1K_RELATIVE
, R_OR1K_RELATIVE
},
547 { BFD_RELOC_OR1K_TLS_GD_HI16
, R_OR1K_TLS_GD_HI16
},
548 { BFD_RELOC_OR1K_TLS_GD_LO16
, R_OR1K_TLS_GD_LO16
},
549 { BFD_RELOC_OR1K_TLS_LDM_HI16
, R_OR1K_TLS_LDM_HI16
},
550 { BFD_RELOC_OR1K_TLS_LDM_LO16
, R_OR1K_TLS_LDM_LO16
},
551 { BFD_RELOC_OR1K_TLS_LDO_HI16
, R_OR1K_TLS_LDO_HI16
},
552 { BFD_RELOC_OR1K_TLS_LDO_LO16
, R_OR1K_TLS_LDO_LO16
},
553 { BFD_RELOC_OR1K_TLS_IE_HI16
, R_OR1K_TLS_IE_HI16
},
554 { BFD_RELOC_OR1K_TLS_IE_LO16
, R_OR1K_TLS_IE_LO16
},
555 { BFD_RELOC_OR1K_TLS_LE_HI16
, R_OR1K_TLS_LE_HI16
},
556 { BFD_RELOC_OR1K_TLS_LE_LO16
, R_OR1K_TLS_LE_LO16
},
559 /* The linker needs to keep track of the number of relocs that it
560 decides to copy as dynamic relocs in check_relocs for each symbol.
561 This is so that it can later discard them if they are found to be
562 unnecessary. We store the information in a field extending the
563 regular ELF linker hash table. */
565 struct elf_or1k_dyn_relocs
567 struct elf_or1k_dyn_relocs
*next
;
569 /* The input section of the reloc. */
572 /* Total number of relocs copied for the input section. */
575 /* Number of pc-relative relocs copied for the input section. */
576 bfd_size_type pc_count
;
579 #define TLS_UNKNOWN 0
586 /* ELF linker hash entry. */
587 struct elf_or1k_link_hash_entry
589 struct elf_link_hash_entry root
;
591 /* Track dynamic relocs copied for this symbol. */
592 struct elf_or1k_dyn_relocs
*dyn_relocs
;
594 /* Track type of TLS access. */
595 unsigned char tls_type
;
598 /* ELF object data. */
599 struct elf_or1k_obj_tdata
601 struct elf_obj_tdata root
;
603 /* tls_type for each local got entry. */
604 unsigned char *local_tls_type
;
607 #define elf_or1k_tdata(abfd) \
608 ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
610 #define elf_or1k_local_tls_type(abfd) \
611 (elf_or1k_tdata (abfd)->local_tls_type)
613 /* ELF linker hash table. */
614 struct elf_or1k_link_hash_table
616 struct elf_link_hash_table root
;
618 /* Short-cuts to get to dynamic linker sections. */
627 /* Small local sym to section mapping cache. */
628 struct sym_cache sym_sec
;
631 /* Get the ELF linker hash table from a link_info structure. */
632 #define or1k_elf_hash_table(p) \
633 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
634 == OR1K_ELF_DATA ? ((struct elf_or1k_link_hash_table *) ((p)->hash)) : NULL)
637 elf_or1k_mkobject (bfd
*abfd
)
639 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_or1k_obj_tdata
),
643 /* Create an entry in an or1k ELF linker hash table. */
645 static struct bfd_hash_entry
*
646 or1k_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
647 struct bfd_hash_table
*table
,
650 struct elf_or1k_link_hash_entry
*ret
=
651 (struct elf_or1k_link_hash_entry
*) entry
;
653 /* Allocate the structure if it has not already been allocated by a
656 ret
= bfd_hash_allocate (table
,
657 sizeof (struct elf_or1k_link_hash_entry
));
661 /* Call the allocation method of the superclass. */
662 ret
= ((struct elf_or1k_link_hash_entry
*)
663 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
667 struct elf_or1k_link_hash_entry
*eh
;
669 eh
= (struct elf_or1k_link_hash_entry
*) ret
;
670 eh
->dyn_relocs
= NULL
;
671 eh
->tls_type
= TLS_UNKNOWN
;
674 return (struct bfd_hash_entry
*) ret
;
677 /* Create an or1k ELF linker hash table. */
679 static struct bfd_link_hash_table
*
680 or1k_elf_link_hash_table_create (bfd
*abfd
)
682 struct elf_or1k_link_hash_table
*ret
;
683 bfd_size_type amt
= sizeof (struct elf_or1k_link_hash_table
);
685 ret
= bfd_zmalloc (amt
);
689 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
690 or1k_elf_link_hash_newfunc
,
691 sizeof (struct elf_or1k_link_hash_entry
),
698 return &ret
->root
.root
;
701 static reloc_howto_type
*
702 or1k_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
703 bfd_reloc_code_real_type code
)
707 for (i
= ARRAY_SIZE (or1k_reloc_map
); --i
;)
708 if (or1k_reloc_map
[i
].bfd_reloc_val
== code
)
709 return & or1k_elf_howto_table
[or1k_reloc_map
[i
].or1k_reloc_val
];
714 static reloc_howto_type
*
715 or1k_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
721 i
< (sizeof (or1k_elf_howto_table
)
722 / sizeof (or1k_elf_howto_table
[0]));
724 if (or1k_elf_howto_table
[i
].name
!= NULL
725 && strcasecmp (or1k_elf_howto_table
[i
].name
, r_name
) == 0)
726 return &or1k_elf_howto_table
[i
];
731 /* Set the howto pointer for an Or1k ELF reloc. */
734 or1k_info_to_howto_rela (bfd
* abfd ATTRIBUTE_UNUSED
,
736 Elf_Internal_Rela
* dst
)
740 r_type
= ELF32_R_TYPE (dst
->r_info
);
741 BFD_ASSERT (r_type
< (unsigned int) R_OR1K_max
);
742 cache_ptr
->howto
= & or1k_elf_howto_table
[r_type
];
746 /* Return the relocation value for @tpoff relocations.. */
748 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
750 /* If tls_sec is NULL, we should have signalled an error already. */
751 if (elf_hash_table (info
)->tls_sec
== NULL
)
754 /* The thread pointer on or1k stores the address after the TCB where
755 the data is, just compute the difference. No need to compensate
756 for the size of TCB. */
757 return (address
- elf_hash_table (info
)->tls_sec
->vma
);
760 /* Relocate an Or1k ELF section.
762 The RELOCATE_SECTION function is called by the new ELF backend linker
763 to handle the relocations for a section.
765 The relocs are always passed as Rela structures; if the section
766 actually uses Rel structures, the r_addend field will always be
769 This function is responsible for adjusting the section contents as
770 necessary, and (if using Rela relocs and generating a relocatable
771 output file) adjusting the reloc addend as necessary.
773 This function does not have to worry about setting the reloc
774 address or the reloc symbol index.
776 LOCAL_SYMS is a pointer to the swapped in local symbols.
778 LOCAL_SECTIONS is an array giving the section in the input file
779 corresponding to the st_shndx field of each local symbol.
781 The global hash table entry for the global symbols can be found
782 via elf_sym_hashes (input_bfd).
784 When generating relocatable output, this function must handle
785 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
786 going to be the section symbol corresponding to the output
787 section, which means that the addend must be adjusted
791 or1k_elf_relocate_section (bfd
*output_bfd
,
792 struct bfd_link_info
*info
,
794 asection
*input_section
,
796 Elf_Internal_Rela
*relocs
,
797 Elf_Internal_Sym
*local_syms
,
798 asection
**local_sections
)
800 Elf_Internal_Shdr
*symtab_hdr
;
801 struct elf_link_hash_entry
**sym_hashes
;
802 Elf_Internal_Rela
*rel
;
803 Elf_Internal_Rela
*relend
;
804 struct elf_or1k_link_hash_table
*htab
= or1k_elf_hash_table (info
);
807 bfd_vma
*local_got_offsets
;
813 dynobj
= htab
->root
.dynobj
;
814 local_got_offsets
= elf_local_got_offsets (input_bfd
);
816 sreloc
= elf_section_data (input_section
)->sreloc
;
820 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
821 sym_hashes
= elf_sym_hashes (input_bfd
);
822 relend
= relocs
+ input_section
->reloc_count
;
824 for (rel
= relocs
; rel
< relend
; rel
++)
826 reloc_howto_type
*howto
;
827 unsigned long r_symndx
;
828 Elf_Internal_Sym
*sym
;
830 struct elf_link_hash_entry
*h
;
832 bfd_reloc_status_type r
;
833 const char *name
= NULL
;
836 r_type
= ELF32_R_TYPE (rel
->r_info
);
837 r_symndx
= ELF32_R_SYM (rel
->r_info
);
839 if (r_type
== R_OR1K_GNU_VTINHERIT
840 || r_type
== R_OR1K_GNU_VTENTRY
)
843 if (r_type
< 0 || r_type
>= (int) R_OR1K_max
)
845 bfd_set_error (bfd_error_bad_value
);
849 howto
= or1k_elf_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
854 if (r_symndx
< symtab_hdr
->sh_info
)
856 sym
= local_syms
+ r_symndx
;
857 sec
= local_sections
[r_symndx
];
858 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
860 name
= bfd_elf_string_from_elf_section
861 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
862 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
866 bfd_boolean unresolved_reloc
, warned
, ignored
;
868 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
869 r_symndx
, symtab_hdr
, sym_hashes
,
871 unresolved_reloc
, warned
, ignored
);
874 if (sec
!= NULL
&& discarded_section (sec
))
875 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
876 rel
, 1, relend
, howto
, 0, contents
);
878 if (info
->relocatable
)
885 if (htab
->splt
!= NULL
&& h
!= NULL
886 && h
->plt
.offset
!= (bfd_vma
) -1)
888 relocation
= (htab
->splt
->output_section
->vma
889 + htab
->splt
->output_offset
896 /* Relocation is to the entry for this symbol in the global
898 BFD_ASSERT (sgot
!= NULL
);
905 BFD_ASSERT (off
!= (bfd_vma
) -1);
907 dyn
= htab
->root
.dynamic_sections_created
;
908 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
910 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
912 /* This is actually a static link, or it is a
913 -Bsymbolic link and the symbol is defined
914 locally, or the symbol was forced to be local
915 because of a version file. We must initialize
916 this entry in the global offset table. Since the
917 offset must always be a multiple of 4, we use the
918 least significant bit to record whether we have
919 initialized it already.
921 When doing a dynamic link, we create a .rela.got
922 relocation entry to initialize the value. This
923 is done in the finish_dynamic_symbol routine. */
928 /* Write entry in GOT. */
929 bfd_put_32 (output_bfd
, relocation
,
930 sgot
->contents
+ off
);
931 /* Mark GOT entry as having been written. */
936 relocation
= sgot
->output_offset
+ off
;
943 BFD_ASSERT (local_got_offsets
!= NULL
944 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
946 /* Get offset into GOT table. */
947 off
= local_got_offsets
[r_symndx
];
949 /* The offset must always be a multiple of 4. We use
950 the least significant bit to record whether we have
951 already processed this entry. */
956 /* Write entry in GOT. */
957 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
961 Elf_Internal_Rela outrel
;
963 /* We need to generate a R_OR1K_RELATIVE reloc
964 for the dynamic linker. */
965 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
966 BFD_ASSERT (srelgot
!= NULL
);
968 outrel
.r_offset
= (sgot
->output_section
->vma
969 + sgot
->output_offset
971 outrel
.r_info
= ELF32_R_INFO (0, R_OR1K_RELATIVE
);
972 outrel
.r_addend
= relocation
;
973 loc
= srelgot
->contents
;
974 loc
+= srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
975 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,loc
);
976 ++srelgot
->reloc_count
;
979 local_got_offsets
[r_symndx
] |= 1;
981 relocation
= sgot
->output_offset
+ off
;
984 /* Addend should be zero. */
985 if (rel
->r_addend
!= 0)
986 (*_bfd_error_handler
)
987 (_("internal error: addend should be zero for R_OR1K_GOT16"));
991 case R_OR1K_GOTOFF_LO16
:
992 case R_OR1K_GOTOFF_HI16
:
993 /* Relocation is offset from GOT. */
994 BFD_ASSERT (sgot
!= NULL
);
995 relocation
-= sgot
->output_section
->vma
;
998 case R_OR1K_INSN_REL_26
:
999 case R_OR1K_HI_16_IN_INSN
:
1000 case R_OR1K_LO_16_IN_INSN
:
1004 /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1005 from removed linkonce sections, or sections discarded by
1007 if (r_symndx
== STN_UNDEF
1008 || (input_section
->flags
& SEC_ALLOC
) == 0)
1013 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1014 || h
->root
.type
!= bfd_link_hash_undefweak
)
1015 && (howto
->type
!= R_OR1K_INSN_REL_26
1016 || !SYMBOL_CALLS_LOCAL (info
, h
)))
1023 || h
->root
.type
== bfd_link_hash_undefweak
1024 || h
->root
.type
== bfd_link_hash_undefined
)))
1026 Elf_Internal_Rela outrel
;
1030 /* When generating a shared object, these relocations
1031 are copied into the output file to be resolved at run
1034 BFD_ASSERT (sreloc
!= NULL
);
1039 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1041 if (outrel
.r_offset
== (bfd_vma
) -1)
1043 else if (outrel
.r_offset
== (bfd_vma
) -2)
1045 outrel
.r_offset
+= (input_section
->output_section
->vma
1046 + input_section
->output_offset
);
1049 memset (&outrel
, 0, sizeof outrel
);
1050 /* h->dynindx may be -1 if the symbol was marked to
1053 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1054 || !h
->def_regular
))
1056 BFD_ASSERT (h
->dynindx
!= -1);
1057 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1058 outrel
.r_addend
= rel
->r_addend
;
1062 if (r_type
== R_OR1K_32
)
1064 outrel
.r_info
= ELF32_R_INFO (0, R_OR1K_RELATIVE
);
1065 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1070 (*_bfd_error_handler
)
1071 (_("%B: probably compiled without -fPIC?"),
1073 bfd_set_error (bfd_error_bad_value
);
1078 loc
= sreloc
->contents
;
1079 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1080 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1086 case R_OR1K_TLS_LDM_HI16
:
1087 case R_OR1K_TLS_LDM_LO16
:
1088 case R_OR1K_TLS_LDO_HI16
:
1089 case R_OR1K_TLS_LDO_LO16
:
1090 /* TODO: implement support for local dynamic. */
1092 (*_bfd_error_handler
)
1093 (_("%B: support for local dynamic not implemented"),
1095 bfd_set_error (bfd_error_bad_value
);
1099 case R_OR1K_TLS_GD_HI16
:
1100 case R_OR1K_TLS_GD_LO16
:
1101 case R_OR1K_TLS_IE_HI16
:
1102 case R_OR1K_TLS_IE_LO16
:
1105 Elf_Internal_Rela rela
;
1109 sreloc
= bfd_get_section_by_name (dynobj
, ".rela.got");
1111 /* Mark as TLS related GOT entry by setting
1112 bit 2 as well as bit 1. */
1115 gotoff
= h
->got
.offset
;
1120 gotoff
= local_got_offsets
[r_symndx
];
1121 local_got_offsets
[r_symndx
] |= 3;
1124 /* Only process the relocation once. */
1127 relocation
= sgot
->output_offset
+ (gotoff
& ~3);
1131 BFD_ASSERT (elf_hash_table (info
)->hgot
== NULL
1132 || elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0);
1134 /* Dynamic entries will require relocations. if we do not need
1135 them we will just use the default R_OR1K_NONE and
1136 not set anything. */
1137 dynamic
= info
->shared
1138 || (sec
&& (sec
->flags
& SEC_ALLOC
) != 0
1140 && (h
->root
.type
== bfd_link_hash_defweak
|| !h
->def_regular
));
1143 if (dynamic
&& (howto
->type
== R_OR1K_TLS_GD_HI16
1144 || howto
->type
== R_OR1K_TLS_GD_LO16
))
1148 /* Add DTPMOD and DTPOFF GOT and rela entries. */
1149 for (i
= 0; i
< 2; ++i
)
1151 rela
.r_offset
= sgot
->output_section
->vma
+
1152 sgot
->output_offset
+ gotoff
+ i
*4;
1153 if (h
!= NULL
&& h
->dynindx
!= -1)
1155 rela
.r_info
= ELF32_R_INFO (h
->dynindx
,
1156 (i
== 0 ? R_OR1K_TLS_DTPMOD
: R_OR1K_TLS_DTPOFF
));
1161 rela
.r_info
= ELF32_R_INFO (0,
1162 (i
== 0 ? R_OR1K_TLS_DTPMOD
: R_OR1K_TLS_DTPOFF
));
1163 rela
.r_addend
= tpoff (info
, relocation
);
1166 loc
= sreloc
->contents
;
1167 loc
+= sreloc
->reloc_count
++ *
1168 sizeof (Elf32_External_Rela
);
1170 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1171 bfd_put_32 (output_bfd
, 0, sgot
->contents
+ gotoff
+ i
*4);
1175 else if (howto
->type
== R_OR1K_TLS_GD_HI16
1176 || howto
->type
== R_OR1K_TLS_GD_LO16
)
1178 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ gotoff
);
1179 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
1180 sgot
->contents
+ gotoff
+ 4);
1185 /* Add TPOFF GOT and rela entries. */
1186 rela
.r_offset
= sgot
->output_section
->vma
+
1187 sgot
->output_offset
+ gotoff
;
1188 if (h
!= NULL
&& h
->dynindx
!= -1)
1190 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_TLS_TPOFF
);
1195 rela
.r_info
= ELF32_R_INFO (0, R_OR1K_TLS_TPOFF
);
1196 rela
.r_addend
= tpoff (info
, relocation
);
1199 loc
= sreloc
->contents
;
1200 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1202 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1203 bfd_put_32 (output_bfd
, 0, sgot
->contents
+ gotoff
);
1208 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
1209 sgot
->contents
+ gotoff
);
1211 relocation
= sgot
->output_offset
+ gotoff
;
1214 case R_OR1K_TLS_LE_HI16
:
1215 case R_OR1K_TLS_LE_LO16
:
1217 /* Relocation is offset from TP. */
1218 relocation
= tpoff (info
, relocation
);
1221 case R_OR1K_TLS_DTPMOD
:
1222 case R_OR1K_TLS_DTPOFF
:
1223 case R_OR1K_TLS_TPOFF
:
1224 /* These are resolved dynamically on load and shouldn't
1225 be used as linker input. */
1227 (*_bfd_error_handler
)
1228 (_("%B: will not resolve runtime TLS relocation"),
1230 bfd_set_error (bfd_error_bad_value
);
1236 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
1237 rel
->r_offset
, relocation
, rel
->r_addend
);
1239 if (r
!= bfd_reloc_ok
)
1241 const char *msg
= NULL
;
1245 case bfd_reloc_overflow
:
1246 r
= info
->callbacks
->reloc_overflow
1247 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1248 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
1251 case bfd_reloc_undefined
:
1252 r
= info
->callbacks
->undefined_symbol
1253 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
1256 case bfd_reloc_outofrange
:
1257 msg
= _("internal error: out of range error");
1260 case bfd_reloc_notsupported
:
1261 msg
= _("internal error: unsupported relocation error");
1264 case bfd_reloc_dangerous
:
1265 msg
= _("internal error: dangerous relocation");
1269 msg
= _("internal error: unknown error");
1274 r
= info
->callbacks
->warning
1275 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
1285 /* Return the section that should be marked against GC for a given
1289 or1k_elf_gc_mark_hook (asection
*sec
,
1290 struct bfd_link_info
*info
,
1291 Elf_Internal_Rela
*rel
,
1292 struct elf_link_hash_entry
*h
,
1293 Elf_Internal_Sym
*sym
)
1296 switch (ELF32_R_TYPE (rel
->r_info
))
1298 case R_OR1K_GNU_VTINHERIT
:
1299 case R_OR1K_GNU_VTENTRY
:
1303 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1307 or1k_elf_gc_sweep_hook (bfd
*abfd
,
1308 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1310 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
1312 /* Update the got entry reference counts for the section being removed. */
1313 Elf_Internal_Shdr
*symtab_hdr
;
1314 struct elf_link_hash_entry
**sym_hashes
;
1315 bfd_signed_vma
*local_got_refcounts
;
1316 const Elf_Internal_Rela
*rel
, *relend
;
1318 elf_section_data (sec
)->local_dynrel
= NULL
;
1320 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1321 sym_hashes
= elf_sym_hashes (abfd
);
1322 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1324 relend
= relocs
+ sec
->reloc_count
;
1325 for (rel
= relocs
; rel
< relend
; rel
++)
1327 unsigned long r_symndx
;
1328 struct elf_link_hash_entry
*h
= NULL
;
1330 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1331 if (r_symndx
>= symtab_hdr
->sh_info
)
1333 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1334 while (h
->root
.type
== bfd_link_hash_indirect
1335 || h
->root
.type
== bfd_link_hash_warning
)
1336 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1339 switch (ELF32_R_TYPE (rel
->r_info
))
1344 if (h
->got
.refcount
> 0)
1349 if (local_got_refcounts
&& local_got_refcounts
[r_symndx
] > 0)
1350 local_got_refcounts
[r_symndx
]--;
1361 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
1362 shortcuts to them in our hash table. */
1365 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
1367 struct elf_or1k_link_hash_table
*htab
;
1370 /* This function may be called more than once. */
1371 s
= bfd_get_section_by_name (dynobj
, ".got");
1372 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
1375 htab
= or1k_elf_hash_table (info
);
1379 if (! _bfd_elf_create_got_section (dynobj
, info
))
1382 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
1383 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1384 htab
->srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1386 if (! htab
->sgot
|| ! htab
->sgotplt
|| ! htab
->srelgot
)
1389 if (! bfd_set_section_flags (dynobj
, htab
->srelgot
, SEC_ALLOC
1393 | SEC_LINKER_CREATED
1395 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
1401 /* Look through the relocs for a section during the first phase. */
1404 or1k_elf_check_relocs (bfd
*abfd
,
1405 struct bfd_link_info
*info
,
1407 const Elf_Internal_Rela
*relocs
)
1409 Elf_Internal_Shdr
*symtab_hdr
;
1410 struct elf_link_hash_entry
**sym_hashes
;
1411 const Elf_Internal_Rela
*rel
;
1413 const Elf_Internal_Rela
*rel_end
;
1414 struct elf_or1k_link_hash_table
*htab
;
1416 asection
*sreloc
= NULL
;
1418 if (info
->relocatable
)
1421 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1422 sym_hashes
= elf_sym_hashes (abfd
);
1424 htab
= or1k_elf_hash_table (info
);
1428 dynobj
= htab
->root
.dynobj
;
1430 rel_end
= relocs
+ sec
->reloc_count
;
1431 for (rel
= relocs
; rel
< rel_end
; rel
++)
1433 struct elf_link_hash_entry
*h
;
1434 unsigned long r_symndx
;
1435 unsigned char tls_type
;
1437 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1438 if (r_symndx
< symtab_hdr
->sh_info
)
1442 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1443 while (h
->root
.type
== bfd_link_hash_indirect
1444 || h
->root
.type
== bfd_link_hash_warning
)
1445 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1447 /* PR15323, ref flags aren't set for references in the same
1449 h
->root
.non_ir_ref
= 1;
1452 switch (ELF32_R_TYPE (rel
->r_info
))
1454 case R_OR1K_TLS_GD_HI16
:
1455 case R_OR1K_TLS_GD_LO16
:
1458 case R_OR1K_TLS_LDM_HI16
:
1459 case R_OR1K_TLS_LDM_LO16
:
1460 case R_OR1K_TLS_LDO_HI16
:
1461 case R_OR1K_TLS_LDO_LO16
:
1464 case R_OR1K_TLS_IE_HI16
:
1465 case R_OR1K_TLS_IE_LO16
:
1468 case R_OR1K_TLS_LE_HI16
:
1469 case R_OR1K_TLS_LE_LO16
:
1473 tls_type
= TLS_NONE
;
1476 /* Record TLS type. */
1478 ((struct elf_or1k_link_hash_entry
*) h
)->tls_type
= tls_type
;
1481 unsigned char *local_tls_type
;
1483 /* This is a TLS type record for a local symbol. */
1484 local_tls_type
= (unsigned char *) elf_or1k_local_tls_type (abfd
);
1485 if (local_tls_type
== NULL
)
1489 size
= symtab_hdr
->sh_info
;
1490 local_tls_type
= bfd_zalloc (abfd
, size
);
1491 if (local_tls_type
== NULL
)
1493 elf_or1k_local_tls_type (abfd
) = local_tls_type
;
1495 local_tls_type
[r_symndx
] = tls_type
;
1498 switch (ELF32_R_TYPE (rel
->r_info
))
1500 /* This relocation describes the C++ object vtable hierarchy.
1501 Reconstruct it for later use during GC. */
1502 case R_OR1K_GNU_VTINHERIT
:
1503 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1507 /* This relocation describes which C++ vtable entries are actually
1508 used. Record for later use during GC. */
1509 case R_OR1K_GNU_VTENTRY
:
1510 BFD_ASSERT (h
!= NULL
);
1512 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1516 /* This relocation requires .plt entry. */
1521 h
->plt
.refcount
+= 1;
1526 case R_OR1K_GOTOFF_HI16
:
1527 case R_OR1K_GOTOFF_LO16
:
1528 case R_OR1K_TLS_GD_HI16
:
1529 case R_OR1K_TLS_GD_LO16
:
1530 case R_OR1K_TLS_IE_HI16
:
1531 case R_OR1K_TLS_IE_LO16
:
1532 if (htab
->sgot
== NULL
)
1535 htab
->root
.dynobj
= dynobj
= abfd
;
1536 if (! create_got_section (dynobj
, info
))
1540 if (ELF32_R_TYPE (rel
->r_info
) != R_OR1K_GOTOFF_HI16
&&
1541 ELF32_R_TYPE (rel
->r_info
) != R_OR1K_GOTOFF_LO16
)
1544 h
->got
.refcount
+= 1;
1547 bfd_signed_vma
*local_got_refcounts
;
1549 /* This is a global offset table entry for a local symbol. */
1550 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1551 if (local_got_refcounts
== NULL
)
1555 size
= symtab_hdr
->sh_info
;
1556 size
*= sizeof (bfd_signed_vma
);
1557 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1558 if (local_got_refcounts
== NULL
)
1560 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1562 local_got_refcounts
[r_symndx
] += 1;
1567 case R_OR1K_INSN_REL_26
:
1568 case R_OR1K_HI_16_IN_INSN
:
1569 case R_OR1K_LO_16_IN_INSN
:
1573 if (h
!= NULL
&& !info
->shared
)
1575 /* We may need a copy reloc. */
1578 /* We may also need a .plt entry. */
1579 h
->plt
.refcount
+= 1;
1580 if (ELF32_R_TYPE (rel
->r_info
) != R_OR1K_INSN_REL_26
)
1581 h
->pointer_equality_needed
= 1;
1584 /* If we are creating a shared library, and this is a reloc
1585 against a global symbol, or a non PC relative reloc
1586 against a local symbol, then we need to copy the reloc
1587 into the shared library. However, if we are linking with
1588 -Bsymbolic, we do not need to copy a reloc against a
1589 global symbol which is defined in an object we are
1590 including in the link (i.e., DEF_REGULAR is set). At
1591 this point we have not seen all the input files, so it is
1592 possible that DEF_REGULAR is not set now but will be set
1593 later (it is never cleared). In case of a weak definition,
1594 DEF_REGULAR may be cleared later by a strong definition in
1595 a shared library. We account for that possibility below by
1596 storing information in the relocs_copied field of the hash
1597 table entry. A similar situation occurs when creating
1598 shared libraries and symbol visibility changes render the
1601 If on the other hand, we are creating an executable, we
1602 may need to keep relocations for symbols satisfied by a
1603 dynamic library if we manage to avoid copy relocs for the
1607 && (sec
->flags
& SEC_ALLOC
) != 0
1608 && (ELF32_R_TYPE (rel
->r_info
) != R_OR1K_INSN_REL_26
1610 && (!SYMBOLIC_BIND (info
, h
)
1611 || h
->root
.type
== bfd_link_hash_defweak
1612 || !h
->def_regular
))))
1614 && (sec
->flags
& SEC_ALLOC
) != 0
1616 && (h
->root
.type
== bfd_link_hash_defweak
1617 || !h
->def_regular
)))
1619 struct elf_or1k_dyn_relocs
*p
;
1620 struct elf_or1k_dyn_relocs
**head
;
1622 /* When creating a shared object, we must copy these
1623 relocs into the output file. We create a reloc
1624 section in dynobj and make room for the reloc. */
1628 unsigned int strndx
= elf_elfheader (abfd
)->e_shstrndx
;
1629 unsigned int shnam
= _bfd_elf_single_rel_hdr (sec
)->sh_name
;
1631 name
= bfd_elf_string_from_elf_section (abfd
, strndx
, shnam
);
1635 if (strncmp (name
, ".rela", 5) != 0
1636 || strcmp (bfd_get_section_name (abfd
, sec
),
1639 (*_bfd_error_handler
)
1640 (_("%B: bad relocation section name `%s\'"),
1644 if (htab
->root
.dynobj
== NULL
)
1645 htab
->root
.dynobj
= abfd
;
1646 dynobj
= htab
->root
.dynobj
;
1648 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1651 sreloc
= _bfd_elf_make_dynamic_reloc_section
1652 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
1657 elf_section_data (sec
)->sreloc
= sreloc
;
1660 /* If this is a global symbol, we count the number of
1661 relocations we need for this symbol. */
1663 head
= &((struct elf_or1k_link_hash_entry
*) h
)->dyn_relocs
;
1666 /* Track dynamic relocs needed for local syms too.
1667 We really need local syms available to do this
1671 Elf_Internal_Sym
*isym
;
1674 isym
= bfd_sym_from_r_symndx (&htab
->sym_sec
,
1679 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1683 vpp
= &elf_section_data (s
)->local_dynrel
;
1684 head
= (struct elf_or1k_dyn_relocs
**) vpp
;
1688 if (p
== NULL
|| p
->sec
!= sec
)
1690 bfd_size_type amt
= sizeof *p
;
1691 p
= ((struct elf_or1k_dyn_relocs
*)
1692 bfd_alloc (htab
->root
.dynobj
, amt
));
1703 if (ELF32_R_TYPE (rel
->r_info
) == R_OR1K_INSN_REL_26
)
1714 /* Finish up the dynamic sections. */
1717 or1k_elf_finish_dynamic_sections (bfd
*output_bfd
,
1718 struct bfd_link_info
*info
)
1721 asection
*sdyn
, *sgot
;
1722 struct elf_or1k_link_hash_table
*htab
;
1724 htab
= or1k_elf_hash_table (info
);
1728 dynobj
= htab
->root
.dynobj
;
1730 sgot
= htab
->sgotplt
;
1731 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1733 if (htab
->root
.dynamic_sections_created
)
1736 Elf32_External_Dyn
*dyncon
, *dynconend
;
1738 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
1740 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1741 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
1743 for (; dyncon
< dynconend
; dyncon
++)
1745 Elf_Internal_Dyn dyn
;
1748 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1756 s
= htab
->sgot
->output_section
;
1757 BFD_ASSERT (s
!= NULL
);
1758 dyn
.d_un
.d_ptr
= s
->vma
;
1762 s
= htab
->srelplt
->output_section
;
1763 BFD_ASSERT (s
!= NULL
);
1764 dyn
.d_un
.d_ptr
= s
->vma
;
1768 s
= htab
->srelplt
->output_section
;
1769 BFD_ASSERT (s
!= NULL
);
1770 dyn
.d_un
.d_val
= s
->size
;
1774 /* My reading of the SVR4 ABI indicates that the
1775 procedure linkage table relocs (DT_JMPREL) should be
1776 included in the overall relocs (DT_RELA). This is
1777 what Solaris does. However, UnixWare can not handle
1778 that case. Therefore, we override the DT_RELASZ entry
1779 here to make it not include the JMPREL relocs. Since
1780 the linker script arranges for .rela.plt to follow all
1781 other relocation sections, we don't have to worry
1782 about changing the DT_RELA entry. */
1783 if (htab
->srelplt
!= NULL
)
1785 /* FIXME: this calculation sometimes produces
1786 wrong result, the problem is that the dyn.d_un.d_val
1787 is not always correct, needs investigation why
1788 that happens. In the meantime, reading the
1789 ".rela.dyn" section by name seems to yield
1792 s = htab->srelplt->output_section;
1793 dyn.d_un.d_val -= s->size;
1796 s
= bfd_get_section_by_name (output_bfd
, ".rela.dyn");
1797 dyn
.d_un
.d_val
= s
? s
->size
: 0;
1801 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1805 /* Fill in the first entry in the procedure linkage table. */
1807 if (splt
&& splt
->size
> 0)
1811 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD0
,
1813 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD1
,
1814 splt
->contents
+ 4);
1815 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD2
,
1816 splt
->contents
+ 8);
1817 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD3
,
1818 splt
->contents
+ 12);
1819 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD4
,
1820 splt
->contents
+ 16);
1825 /* addr = .got + 4 */
1826 addr
= sgot
->output_section
->vma
+ sgot
->output_offset
+ 4;
1827 bfd_put_32 (output_bfd
,
1828 PLT0_ENTRY_WORD0
| ((addr
>> 16) & 0xffff),
1830 bfd_put_32 (output_bfd
,
1831 PLT0_ENTRY_WORD1
| (addr
& 0xffff),
1832 splt
->contents
+ 4);
1833 bfd_put_32 (output_bfd
, PLT0_ENTRY_WORD2
, splt
->contents
+ 8);
1834 bfd_put_32 (output_bfd
, PLT0_ENTRY_WORD3
, splt
->contents
+ 12);
1835 bfd_put_32 (output_bfd
, PLT0_ENTRY_WORD4
, splt
->contents
+ 16);
1838 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
1842 /* Set the first entry in the global offset table to the address of
1843 the dynamic section. */
1844 if (sgot
&& sgot
->size
> 0)
1847 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1849 bfd_put_32 (output_bfd
,
1850 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1852 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1855 if (htab
->sgot
&& htab
->sgot
->size
> 0)
1856 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1861 /* Finish up dynamic symbol handling. We set the contents of various
1862 dynamic sections here. */
1865 or1k_elf_finish_dynamic_symbol (bfd
*output_bfd
,
1866 struct bfd_link_info
*info
,
1867 struct elf_link_hash_entry
*h
,
1868 Elf_Internal_Sym
*sym
)
1870 struct elf_or1k_link_hash_table
*htab
;
1873 htab
= or1k_elf_hash_table (info
);
1877 if (h
->plt
.offset
!= (bfd_vma
) -1)
1886 Elf_Internal_Rela rela
;
1888 /* This symbol has an entry in the procedure linkage table. Set
1890 BFD_ASSERT (h
->dynindx
!= -1);
1893 sgot
= htab
->sgotplt
;
1894 srela
= htab
->srelplt
;
1895 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1897 /* Get the index in the procedure linkage table which
1898 corresponds to this symbol. This is the index of this symbol
1899 in all the symbols for which we are making plt entries. The
1900 first entry in the procedure linkage table is reserved. */
1901 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1903 /* Get the offset into the .got table of the entry that
1904 corresponds to this function. Each .got entry is 4 bytes.
1905 The first three are reserved. */
1906 got_offset
= (plt_index
+ 3) * 4;
1907 got_addr
= got_offset
;
1909 /* Fill in the entry in the procedure linkage table. */
1912 got_addr
+= htab
->sgotplt
->output_section
->vma
1913 + htab
->sgotplt
->output_offset
;
1914 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD0
| ((got_addr
>> 16) & 0xffff),
1915 splt
->contents
+ h
->plt
.offset
);
1916 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD1
| (got_addr
& 0xffff),
1917 splt
->contents
+ h
->plt
.offset
+ 4);
1918 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD2
,
1919 splt
->contents
+ h
->plt
.offset
+ 8);
1920 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD3
,
1921 splt
->contents
+ h
->plt
.offset
+ 12);
1922 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD4
1923 | plt_index
* sizeof (Elf32_External_Rela
),
1924 splt
->contents
+ h
->plt
.offset
+ 16);
1928 bfd_put_32 (output_bfd
, PLT_PIC_ENTRY_WORD0
| (got_addr
& 0xffff),
1929 splt
->contents
+ h
->plt
.offset
);
1930 bfd_put_32 (output_bfd
, PLT_PIC_ENTRY_WORD1
1931 | plt_index
* sizeof (Elf32_External_Rela
),
1932 splt
->contents
+ h
->plt
.offset
+ 4);
1933 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD2
,
1934 splt
->contents
+ h
->plt
.offset
+ 8);
1935 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD3
,
1936 splt
->contents
+ h
->plt
.offset
+ 12);
1937 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD4
,
1938 splt
->contents
+ h
->plt
.offset
+ 16);
1941 /* Fill in the entry in the global offset table. */
1942 bfd_put_32 (output_bfd
,
1943 (splt
->output_section
->vma
1944 + splt
->output_offset
), /* Same offset. */
1945 sgot
->contents
+ got_offset
);
1947 /* Fill in the entry in the .rela.plt section. */
1948 rela
.r_offset
= (sgot
->output_section
->vma
1949 + sgot
->output_offset
1951 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_JMP_SLOT
);
1953 loc
= srela
->contents
;
1954 loc
+= plt_index
* sizeof (Elf32_External_Rela
);
1955 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1957 if (!h
->def_regular
)
1959 /* Mark the symbol as undefined, rather than as defined in
1960 the .plt section. Leave the value alone. */
1961 sym
->st_shndx
= SHN_UNDEF
;
1966 if (h
->got
.offset
!= (bfd_vma
) -1
1967 && (h
->got
.offset
& 2) == 0) /* Homemade TLS check. */
1971 Elf_Internal_Rela rela
;
1973 /* This symbol has an entry in the global offset table. Set it
1976 srela
= htab
->srelgot
;
1977 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1979 rela
.r_offset
= (sgot
->output_section
->vma
1980 + sgot
->output_offset
1981 + (h
->got
.offset
&~ 1));
1983 /* If this is a -Bsymbolic link, and the symbol is defined
1984 locally, we just want to emit a RELATIVE reloc. Likewise if
1985 the symbol was forced to be local because of a version file.
1986 The entry in the global offset table will already have been
1987 initialized in the relocate_section function. */
1988 if (info
->shared
&& SYMBOL_REFERENCES_LOCAL (info
, h
))
1990 rela
.r_info
= ELF32_R_INFO (0, R_OR1K_RELATIVE
);
1991 rela
.r_addend
= (h
->root
.u
.def
.value
1992 + h
->root
.u
.def
.section
->output_section
->vma
1993 + h
->root
.u
.def
.section
->output_offset
);
1997 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
1998 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
1999 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_GLOB_DAT
);
2003 loc
= srela
->contents
;
2004 loc
+= srela
->reloc_count
* sizeof (Elf32_External_Rela
);
2005 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2006 ++srela
->reloc_count
;
2012 Elf_Internal_Rela rela
;
2014 /* This symbols needs a copy reloc. Set it up. */
2015 BFD_ASSERT (h
->dynindx
!= -1
2016 && (h
->root
.type
== bfd_link_hash_defined
2017 || h
->root
.type
== bfd_link_hash_defweak
));
2019 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2021 BFD_ASSERT (s
!= NULL
);
2023 rela
.r_offset
= (h
->root
.u
.def
.value
2024 + h
->root
.u
.def
.section
->output_section
->vma
2025 + h
->root
.u
.def
.section
->output_offset
);
2026 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_OR1K_COPY
);
2029 loc
+= s
->reloc_count
* sizeof (Elf32_External_Rela
);
2030 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2034 /* Mark some specially defined symbols as absolute. */
2035 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2036 || h
== htab
->root
.hgot
)
2037 sym
->st_shndx
= SHN_ABS
;
2042 static enum elf_reloc_type_class
2043 or1k_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2044 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2045 const Elf_Internal_Rela
*rela
)
2047 switch ((int) ELF32_R_TYPE (rela
->r_info
))
2049 case R_OR1K_RELATIVE
: return reloc_class_relative
;
2050 case R_OR1K_JMP_SLOT
: return reloc_class_plt
;
2051 case R_OR1K_COPY
: return reloc_class_copy
;
2052 default: return reloc_class_normal
;
2056 /* Adjust a symbol defined by a dynamic object and referenced by a
2057 regular object. The current definition is in some section of the
2058 dynamic object, but we're not including those sections. We have to
2059 change the definition to something the rest of the link can
2063 or1k_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2064 struct elf_link_hash_entry
*h
)
2066 struct elf_or1k_link_hash_table
*htab
;
2067 struct elf_or1k_link_hash_entry
*eh
;
2068 struct elf_or1k_dyn_relocs
*p
;
2072 dynobj
= elf_hash_table (info
)->dynobj
;
2074 /* Make sure we know what is going on here. */
2075 BFD_ASSERT (dynobj
!= NULL
2077 || h
->u
.weakdef
!= NULL
2080 && !h
->def_regular
)));
2082 /* If this is a function, put it in the procedure linkage table. We
2083 will fill in the contents of the procedure linkage table later,
2084 when we know the address of the .got section. */
2085 if (h
->type
== STT_FUNC
2091 && h
->root
.type
!= bfd_link_hash_undefweak
2092 && h
->root
.type
!= bfd_link_hash_undefined
)
2094 /* This case can occur if we saw a PLT reloc in an input
2095 file, but the symbol was never referred to by a dynamic
2096 object. In such a case, we don't actually need to build
2097 a procedure linkage table, and we can just do a PCREL
2099 h
->plt
.offset
= (bfd_vma
) -1;
2106 h
->plt
.offset
= (bfd_vma
) -1;
2108 /* If this is a weak symbol, and there is a real definition, the
2109 processor independent code will have arranged for us to see the
2110 real definition first, and we can just use the same value. */
2111 if (h
->u
.weakdef
!= NULL
)
2113 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2114 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2115 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2116 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2120 /* This is a reference to a symbol defined by a dynamic object which
2121 is not a function. */
2123 /* If we are creating a shared library, we must presume that the
2124 only references to the symbol are via the global offset table.
2125 For such cases we need not do anything here; the relocations will
2126 be handled correctly by relocate_section. */
2130 /* If there are no references to this symbol that do not use the
2131 GOT, we don't need to generate a copy reloc. */
2132 if (!h
->non_got_ref
)
2135 /* If -z nocopyreloc was given, we won't generate them either. */
2136 if (info
->nocopyreloc
)
2142 eh
= (struct elf_or1k_link_hash_entry
*) h
;
2143 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2145 s
= p
->sec
->output_section
;
2146 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
2150 /* If we didn't find any dynamic relocs in sections which needs the
2151 copy reloc, then we'll be keeping the dynamic relocs and avoiding
2159 /* We must allocate the symbol in our .dynbss section, which will
2160 become part of the .bss section of the executable. There will be
2161 an entry for this symbol in the .dynsym section. The dynamic
2162 object will contain position independent code, so all references
2163 from the dynamic object to this symbol will go through the global
2164 offset table. The dynamic linker will use the .dynsym entry to
2165 determine the address it must put in the global offset table, so
2166 both the dynamic object and the regular object will refer to the
2167 same memory location for the variable. */
2169 htab
= or1k_elf_hash_table (info
);
2174 BFD_ASSERT (s
!= NULL
);
2176 /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
2177 to copy the initial value out of the dynamic object and into the
2178 runtime process image. We need to remember the offset into the
2179 .rela.bss section we are going to use. */
2180 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2184 srel
= htab
->srelbss
;
2185 BFD_ASSERT (srel
!= NULL
);
2186 srel
->size
+= sizeof (Elf32_External_Rela
);
2190 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2193 /* Allocate space in .plt, .got and associated reloc sections for
2197 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2199 struct bfd_link_info
*info
;
2200 struct elf_or1k_link_hash_table
*htab
;
2201 struct elf_or1k_link_hash_entry
*eh
;
2202 struct elf_or1k_dyn_relocs
*p
;
2204 if (h
->root
.type
== bfd_link_hash_indirect
)
2207 info
= (struct bfd_link_info
*) inf
;
2208 htab
= or1k_elf_hash_table (info
);
2212 eh
= (struct elf_or1k_link_hash_entry
*) h
;
2214 if (htab
->root
.dynamic_sections_created
2215 && h
->plt
.refcount
> 0)
2217 /* Make sure this symbol is output as a dynamic symbol.
2218 Undefined weak syms won't yet be marked as dynamic. */
2219 if (h
->dynindx
== -1
2220 && !h
->forced_local
)
2222 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2226 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
2228 asection
*s
= htab
->splt
;
2230 /* If this is the first .plt entry, make room for the special
2233 s
->size
= PLT_ENTRY_SIZE
;
2235 h
->plt
.offset
= s
->size
;
2237 /* If this symbol is not defined in a regular file, and we are
2238 not generating a shared library, then set the symbol to this
2239 location in the .plt. This is required to make function
2240 pointers compare as equal between the normal executable and
2241 the shared library. */
2245 h
->root
.u
.def
.section
= s
;
2246 h
->root
.u
.def
.value
= h
->plt
.offset
;
2249 /* Make room for this entry. */
2250 s
->size
+= PLT_ENTRY_SIZE
;
2252 /* We also need to make an entry in the .got.plt section, which
2253 will be placed in the .got section by the linker script. */
2254 htab
->sgotplt
->size
+= 4;
2256 /* We also need to make an entry in the .rel.plt section. */
2257 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
2261 h
->plt
.offset
= (bfd_vma
) -1;
2267 h
->plt
.offset
= (bfd_vma
) -1;
2271 if (h
->got
.refcount
> 0)
2275 unsigned char tls_type
;
2277 /* Make sure this symbol is output as a dynamic symbol.
2278 Undefined weak syms won't yet be marked as dynamic. */
2279 if (h
->dynindx
== -1
2280 && !h
->forced_local
)
2282 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2288 h
->got
.offset
= s
->size
;
2290 tls_type
= ((struct elf_or1k_link_hash_entry
*) h
)->tls_type
;
2292 /* TLS GD requires two GOT and two relocs. */
2293 if (tls_type
== TLS_GD
)
2297 dyn
= htab
->root
.dynamic_sections_created
;
2298 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
2300 if (tls_type
== TLS_GD
)
2301 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rela
);
2303 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
2307 h
->got
.offset
= (bfd_vma
) -1;
2309 if (eh
->dyn_relocs
== NULL
)
2312 /* In the shared -Bsymbolic case, discard space allocated for
2313 dynamic pc-relative relocs against symbols which turn out to be
2314 defined in regular objects. For the normal shared case, discard
2315 space for pc-relative relocs that have become local due to symbol
2316 visibility changes. */
2320 if (SYMBOL_CALLS_LOCAL (info
, h
))
2322 struct elf_or1k_dyn_relocs
**pp
;
2324 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
2326 p
->count
-= p
->pc_count
;
2335 /* Also discard relocs on undefined weak syms with non-default
2337 if (eh
->dyn_relocs
!= NULL
2338 && h
->root
.type
== bfd_link_hash_undefweak
)
2340 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2341 eh
->dyn_relocs
= NULL
;
2343 /* Make sure undefined weak symbols are output as a dynamic
2345 else if (h
->dynindx
== -1
2346 && !h
->forced_local
)
2348 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2355 /* For the non-shared case, discard space for relocs against
2356 symbols which turn out to need copy relocs or are not
2362 || (htab
->root
.dynamic_sections_created
2363 && (h
->root
.type
== bfd_link_hash_undefweak
2364 || h
->root
.type
== bfd_link_hash_undefined
))))
2366 /* Make sure this symbol is output as a dynamic symbol.
2367 Undefined weak syms won't yet be marked as dynamic. */
2368 if (h
->dynindx
== -1
2369 && !h
->forced_local
)
2371 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2375 /* If that succeeded, we know we'll be keeping all the
2377 if (h
->dynindx
!= -1)
2381 eh
->dyn_relocs
= NULL
;
2386 /* Finally, allocate space. */
2387 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2389 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2390 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
2396 /* Find any dynamic relocs that apply to read-only sections. */
2399 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2401 struct elf_or1k_link_hash_entry
*eh
;
2402 struct elf_or1k_dyn_relocs
*p
;
2404 eh
= (struct elf_or1k_link_hash_entry
*) h
;
2405 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2407 asection
*s
= p
->sec
->output_section
;
2409 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2411 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2413 info
->flags
|= DF_TEXTREL
;
2415 /* Not an error, just cut short the traversal. */
2422 /* Set the sizes of the dynamic sections. */
2425 or1k_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2426 struct bfd_link_info
*info
)
2428 struct elf_or1k_link_hash_table
*htab
;
2434 htab
= or1k_elf_hash_table (info
);
2438 dynobj
= htab
->root
.dynobj
;
2439 BFD_ASSERT (dynobj
!= NULL
);
2441 if (htab
->root
.dynamic_sections_created
)
2443 /* Set the contents of the .interp section to the interpreter. */
2444 if (info
->executable
)
2446 s
= bfd_get_section_by_name (dynobj
, ".interp");
2447 BFD_ASSERT (s
!= NULL
);
2448 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2449 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2453 /* Set up .got offsets for local syms, and space for local dynamic
2455 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2457 bfd_signed_vma
*local_got
;
2458 bfd_signed_vma
*end_local_got
;
2459 bfd_size_type locsymcount
;
2460 Elf_Internal_Shdr
*symtab_hdr
;
2461 unsigned char *local_tls_type
;
2464 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2467 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2469 struct elf_or1k_dyn_relocs
*p
;
2471 for (p
= ((struct elf_or1k_dyn_relocs
*)
2472 elf_section_data (s
)->local_dynrel
);
2476 if (! bfd_is_abs_section (p
->sec
)
2477 && bfd_is_abs_section (p
->sec
->output_section
))
2479 /* Input section has been discarded, either because
2480 it is a copy of a linkonce section or due to
2481 linker script /DISCARD/, so we'll be discarding
2484 else if (p
->count
!= 0)
2486 srel
= elf_section_data (p
->sec
)->sreloc
;
2487 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
2488 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2489 info
->flags
|= DF_TEXTREL
;
2494 local_got
= elf_local_got_refcounts (ibfd
);
2498 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2499 locsymcount
= symtab_hdr
->sh_info
;
2500 end_local_got
= local_got
+ locsymcount
;
2502 srel
= htab
->srelgot
;
2503 local_tls_type
= (unsigned char *) elf_or1k_local_tls_type (ibfd
);
2504 for (; local_got
< end_local_got
; ++local_got
)
2508 *local_got
= s
->size
;
2510 /* TLS GD requires two GOT and two relocs. */
2511 if (local_tls_type
!= NULL
&& *local_tls_type
== TLS_GD
)
2517 if (local_tls_type
!= NULL
&& *local_tls_type
== TLS_GD
)
2518 srel
->size
+= 2 * sizeof (Elf32_External_Rela
);
2520 srel
->size
+= sizeof (Elf32_External_Rela
);
2525 *local_got
= (bfd_vma
) -1;
2532 /* Allocate global sym .plt and .got entries, and space for global
2533 sym dynamic relocs. */
2534 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
2536 /* We now have determined the sizes of the various dynamic sections.
2537 Allocate memory for them. */
2539 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2541 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2546 || s
== htab
->sgotplt
2547 || s
== htab
->sdynbss
)
2549 /* Strip this section if we don't need it; see the
2552 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2554 if (s
->size
!= 0 && s
!= htab
->srelplt
)
2557 /* We use the reloc_count field as a counter if we need
2558 to copy relocs into the output file. */
2562 /* It's not one of our sections, so don't allocate space. */
2567 /* If we don't need this section, strip it from the
2568 output file. This is mostly to handle .rela.bss and
2569 .rela.plt. We must create both sections in
2570 create_dynamic_sections, because they must be created
2571 before the linker maps input sections to output
2572 sections. The linker does that before
2573 adjust_dynamic_symbol is called, and it is that
2574 function which decides whether anything needs to go
2575 into these sections. */
2576 s
->flags
|= SEC_EXCLUDE
;
2580 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2583 /* Allocate memory for the section contents. We use bfd_zalloc
2584 here in case unused entries are not reclaimed before the
2585 section's contents are written out. This should not happen,
2586 but this way if it does, we get a R_OR1K_NONE reloc instead
2588 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
2590 if (s
->contents
== NULL
)
2594 if (htab
->root
.dynamic_sections_created
)
2596 /* Add some entries to the .dynamic section. We fill in the
2597 values later, in or1k_elf_finish_dynamic_sections, but we
2598 must add the entries now so that we get the correct size for
2599 the .dynamic section. The DT_DEBUG entry is filled in by the
2600 dynamic linker and used by the debugger. */
2601 #define add_dynamic_entry(TAG, VAL) \
2602 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2604 if (info
->executable
)
2606 if (! add_dynamic_entry (DT_DEBUG
, 0))
2610 if (htab
->splt
->size
!= 0)
2612 if (! add_dynamic_entry (DT_PLTGOT
, 0)
2613 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
2614 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2615 || ! add_dynamic_entry (DT_JMPREL
, 0))
2621 if (! add_dynamic_entry (DT_RELA
, 0)
2622 || ! add_dynamic_entry (DT_RELASZ
, 0)
2623 || ! add_dynamic_entry (DT_RELAENT
,
2624 sizeof (Elf32_External_Rela
)))
2627 /* If any dynamic relocs apply to a read-only section,
2628 then we need a DT_TEXTREL entry. */
2629 if ((info
->flags
& DF_TEXTREL
) == 0)
2630 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
,
2633 if ((info
->flags
& DF_TEXTREL
) != 0)
2635 if (! add_dynamic_entry (DT_TEXTREL
, 0))
2641 #undef add_dynamic_entry
2645 /* Create dynamic sections when linking against a dynamic object. */
2648 or1k_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
2650 struct elf_or1k_link_hash_table
*htab
;
2652 htab
= or1k_elf_hash_table (info
);
2656 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2659 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2662 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2663 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2664 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2666 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2668 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2669 || (!info
->shared
&& !htab
->srelbss
))
2675 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2678 or1k_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2679 struct elf_link_hash_entry
*dir
,
2680 struct elf_link_hash_entry
*ind
)
2682 struct elf_or1k_link_hash_entry
* edir
;
2683 struct elf_or1k_link_hash_entry
* eind
;
2685 edir
= (struct elf_or1k_link_hash_entry
*) dir
;
2686 eind
= (struct elf_or1k_link_hash_entry
*) ind
;
2688 if (eind
->dyn_relocs
!= NULL
)
2690 if (edir
->dyn_relocs
!= NULL
)
2692 struct elf_or1k_dyn_relocs
**pp
;
2693 struct elf_or1k_dyn_relocs
*p
;
2695 /* Add reloc counts against the indirect sym to the direct sym
2696 list. Merge any entries against the same section. */
2697 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2699 struct elf_or1k_dyn_relocs
*q
;
2701 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2702 if (q
->sec
== p
->sec
)
2704 q
->pc_count
+= p
->pc_count
;
2705 q
->count
+= p
->count
;
2712 *pp
= edir
->dyn_relocs
;
2715 edir
->dyn_relocs
= eind
->dyn_relocs
;
2716 eind
->dyn_relocs
= NULL
;
2719 if (ind
->root
.type
== bfd_link_hash_indirect
)
2721 if (dir
->got
.refcount
<= 0)
2723 edir
->tls_type
= eind
->tls_type
;
2724 eind
->tls_type
= TLS_UNKNOWN
;
2728 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2731 /* Set the right machine number. */
2734 or1k_elf_object_p (bfd
*abfd
)
2736 unsigned long mach
= bfd_mach_or1k
;
2738 if (elf_elfheader (abfd
)->e_flags
& EF_OR1K_NODELAY
)
2739 mach
= bfd_mach_or1knd
;
2741 return bfd_default_set_arch_mach (abfd
, bfd_arch_or1k
, mach
);
2744 /* Store the machine number in the flags field. */
2747 or1k_elf_final_write_processing (bfd
*abfd
,
2748 bfd_boolean linker ATTRIBUTE_UNUSED
)
2750 switch (bfd_get_mach (abfd
))
2755 case bfd_mach_or1knd
:
2756 elf_elfheader (abfd
)->e_flags
|= EF_OR1K_NODELAY
;
2762 or1k_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2764 BFD_ASSERT (!elf_flags_init (abfd
)
2765 || elf_elfheader (abfd
)->e_flags
== flags
);
2767 elf_elfheader (abfd
)->e_flags
= flags
;
2768 elf_flags_init (abfd
) = TRUE
;
2772 /* Make sure all input files are consistent with respect to
2773 EF_OR1K_NODELAY flag setting. */
2776 elf32_or1k_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2781 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2782 out_flags
= elf_elfheader (obfd
)->e_flags
;
2784 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2785 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2788 if (!elf_flags_init (obfd
))
2790 elf_flags_init (obfd
) = TRUE
;
2791 elf_elfheader (obfd
)->e_flags
= in_flags
;
2796 if (in_flags
== out_flags
)
2799 if ((in_flags
& EF_OR1K_NODELAY
) != (out_flags
& EF_OR1K_NODELAY
))
2801 (*_bfd_error_handler
)
2802 (_("%B: EF_OR1K_NODELAY flag mismatch with previous modules"), ibfd
);
2804 bfd_set_error (bfd_error_bad_value
);
2812 #define ELF_ARCH bfd_arch_or1k
2813 #define ELF_MACHINE_CODE EM_OR1K
2814 #define ELF_TARGET_ID OR1K_ELF_DATA
2815 #define ELF_MAXPAGESIZE 0x2000
2817 #define TARGET_BIG_SYM or1k_elf32_vec
2818 #define TARGET_BIG_NAME "elf32-or1k"
2820 #define elf_info_to_howto_rel NULL
2821 #define elf_info_to_howto or1k_info_to_howto_rela
2822 #define elf_backend_relocate_section or1k_elf_relocate_section
2823 #define elf_backend_gc_mark_hook or1k_elf_gc_mark_hook
2824 #define elf_backend_gc_sweep_hook or1k_elf_gc_sweep_hook
2825 #define elf_backend_check_relocs or1k_elf_check_relocs
2826 #define elf_backend_reloc_type_class or1k_elf_reloc_type_class
2827 #define elf_backend_can_gc_sections 1
2828 #define elf_backend_rela_normal 1
2830 #define bfd_elf32_mkobject elf_or1k_mkobject
2832 #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
2833 #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
2834 #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
2835 #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
2837 #define elf_backend_object_p or1k_elf_object_p
2838 #define elf_backend_final_write_processing or1k_elf_final_write_processing
2839 #define elf_backend_can_refcount 1
2841 #define elf_backend_plt_readonly 1
2842 #define elf_backend_want_got_plt 1
2843 #define elf_backend_want_plt_sym 0
2844 #define elf_backend_got_header_size 12
2845 #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create
2846 #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol
2847 #define elf_backend_create_dynamic_sections or1k_elf_create_dynamic_sections
2848 #define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
2849 #define elf_backend_size_dynamic_sections or1k_elf_size_dynamic_sections
2850 #define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
2851 #define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
2853 #include "elf32-target.h"