pre-commit: run flake8 on more Python files
[binutils-gdb.git] / bfd / elf32-or1k.c
blobbdee1f1fb99c627f214526ae976c23cfd71dc503
1 /* Or1k-specific support for 32-bit ELF.
2 Copyright (C) 2001-2025 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/>. */
23 #include "sysdep.h"
24 #include "bfd.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf/or1k.h"
28 #include "libiberty.h"
30 #define N_ONES(X) (((bfd_vma)2 << (X)) - 1)
32 #define PLT_ENTRY_SIZE 16
33 #define PLT_ENTRY_SIZE_LARGE (6*4)
34 #define PLT_MAX_INSN_COUNT 6
36 #define OR1K_MOVHI(D) (0x18000000 | (D << 21))
37 #define OR1K_ADRP(D) (0x08000000 | (D << 21))
38 #define OR1K_LWZ(D,A) (0x84000000 | (D << 21) | (A << 16))
39 #define OR1K_ADD(D,A,B) (0xE0000000 | (D << 21) | (A << 16) | (B << 11))
40 #define OR1K_ORI(D,A) (0xA8000000 | (D << 21) | (A << 16))
41 #define OR1K_ORI0(D) (0xA8000000 | (D << 21))
42 #define OR1K_JR(B) (0x44000000 | (B << 11))
43 #define OR1K_NOP 0x15000000
45 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
47 static reloc_howto_type or1k_elf_howto_table[] =
49 /* This reloc does nothing. */
50 HOWTO (R_OR1K_NONE, /* type */
51 0, /* rightshift */
52 0, /* size */
53 0, /* bitsize */
54 false, /* pc_relative */
55 0, /* bitpos */
56 complain_overflow_dont, /* complain_on_overflow */
57 bfd_elf_generic_reloc, /* special_function */
58 "R_OR1K_NONE", /* name */
59 false, /* partial_inplace */
60 0, /* src_mask */
61 0, /* dst_mask */
62 false), /* pcrel_offset */
64 HOWTO (R_OR1K_32,
65 0, /* rightshift */
66 4, /* size */
67 32, /* bitsize */
68 false, /* pc_relative */
69 0, /* bitpos */
70 complain_overflow_unsigned, /* complain_on_overflow */
71 bfd_elf_generic_reloc, /* special_function */
72 "R_OR1K_32", /* name */
73 false, /* partial_inplace */
74 0, /* src_mask */
75 0xffffffff, /* dst_mask */
76 false), /* pcrel_offset */
78 HOWTO (R_OR1K_16,
79 0, /* rightshift */
80 2, /* size */
81 16, /* bitsize */
82 false, /* pc_relative */
83 0, /* bitpos */
84 complain_overflow_unsigned, /* complain_on_overflow */
85 bfd_elf_generic_reloc, /* special_function */
86 "R_OR1K_16", /* name */
87 false, /* partial_inplace */
88 0, /* src_mask */
89 0xffff, /* dst_mask */
90 false), /* pcrel_offset */
92 HOWTO (R_OR1K_8,
93 0, /* rightshift */
94 1, /* size */
95 8, /* bitsize */
96 false, /* pc_relative */
97 0, /* bitpos */
98 complain_overflow_unsigned, /* complain_on_overflow */
99 bfd_elf_generic_reloc, /* special_function */
100 "R_OR1K_8", /* name */
101 false, /* partial_inplace */
102 0, /* src_mask */
103 0xff, /* dst_mask */
104 false), /* pcrel_offset */
106 HOWTO (R_OR1K_LO_16_IN_INSN, /* type */
107 0, /* rightshift */
108 4, /* size */
109 16, /* bitsize */
110 false, /* pc_relative */
111 0, /* bitpos */
112 complain_overflow_dont, /* complain_on_overflow */
113 bfd_elf_generic_reloc, /* special_function */
114 "R_OR1K_LO_16_IN_INSN", /* name */
115 false, /* partial_inplace */
116 0, /* src_mask */
117 0x0000ffff, /* dst_mask */
118 false), /* pcrel_offset */
120 HOWTO (R_OR1K_HI_16_IN_INSN, /* type */
121 16, /* rightshift */
122 4, /* size */
123 16, /* bitsize */
124 false, /* pc_relative */
125 0, /* bitpos */
126 complain_overflow_dont, /* complain_on_overflow */
127 bfd_elf_generic_reloc, /* special_function */
128 "R_OR1K_HI_16_IN_INSN", /* name */
129 false, /* partial_inplace */
130 0, /* src_mask */
131 0x0000ffff, /* dst_mask */
132 false), /* pcrel_offset */
134 /* A PC relative 26 bit relocation, right shifted by 2. */
135 HOWTO (R_OR1K_INSN_REL_26, /* type */
136 2, /* rightshift */
137 4, /* size */
138 26, /* bitsize */
139 true, /* pc_relative */
140 0, /* bitpos */
141 complain_overflow_signed, /* complain_on_overflow */
142 bfd_elf_generic_reloc, /* special_function */
143 "R_OR1K_INSN_REL_26", /* name */
144 false, /* partial_inplace */
145 0, /* src_mask */
146 0x03ffffff, /* dst_mask */
147 true), /* pcrel_offset */
149 /* GNU extension to record C++ vtable hierarchy. */
150 HOWTO (R_OR1K_GNU_VTINHERIT, /* type */
151 0, /* rightshift */
152 4, /* size */
153 0, /* bitsize */
154 false, /* pc_relative */
155 0, /* bitpos */
156 complain_overflow_dont, /* complain_on_overflow */
157 NULL, /* special_function */
158 "R_OR1K_GNU_VTINHERIT", /* name */
159 false, /* partial_inplace */
160 0, /* src_mask */
161 0, /* dst_mask */
162 false), /* pcrel_offset */
164 /* GNU extension to record C++ vtable member usage. */
165 HOWTO (R_OR1K_GNU_VTENTRY, /* type */
166 0, /* rightshift */
167 4, /* size */
168 0, /* bitsize */
169 false, /* pc_relative */
170 0, /* bitpos */
171 complain_overflow_dont, /* complain_on_overflow */
172 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
173 "R_OR1K_GNU_VTENTRY", /* name */
174 false, /* partial_inplace */
175 0, /* src_mask */
176 0, /* dst_mask */
177 false), /* pcrel_offset */
179 HOWTO (R_OR1K_32_PCREL,
180 0, /* rightshift */
181 4, /* size */
182 32, /* bitsize */
183 true, /* pc_relative */
184 0, /* bitpos */
185 complain_overflow_signed, /* complain_on_overflow */
186 bfd_elf_generic_reloc, /* special_function */
187 "R_OR1K_32_PCREL", /* name */
188 false, /* partial_inplace */
189 0, /* src_mask */
190 0xffffffff, /* dst_mask */
191 true), /* pcrel_offset */
193 HOWTO (R_OR1K_16_PCREL,
194 0, /* rightshift */
195 2, /* size */
196 16, /* bitsize */
197 true, /* pc_relative */
198 0, /* bitpos */
199 complain_overflow_signed, /* complain_on_overflow */
200 bfd_elf_generic_reloc, /* special_function */
201 "R_OR1K_16_PCREL", /* name */
202 false, /* partial_inplace */
203 0, /* src_mask */
204 0xffff, /* dst_mask */
205 true), /* pcrel_offset */
207 HOWTO (R_OR1K_8_PCREL,
208 0, /* rightshift */
209 1, /* size */
210 8, /* bitsize */
211 true, /* pc_relative */
212 0, /* bitpos */
213 complain_overflow_signed, /* complain_on_overflow */
214 bfd_elf_generic_reloc, /* special_function */
215 "R_OR1K_8_PCREL", /* name */
216 false, /* partial_inplace */
217 0, /* src_mask */
218 0xff, /* dst_mask */
219 true), /* pcrel_offset */
221 HOWTO (R_OR1K_GOTPC_HI16, /* Type. */
222 16, /* Rightshift. */
223 4, /* Size. */
224 16, /* Bitsize. */
225 true, /* PC_relative. */
226 0, /* Bitpos. */
227 complain_overflow_dont, /* Complain on overflow. */
228 bfd_elf_generic_reloc, /* Special Function. */
229 "R_OR1K_GOTPC_HI16", /* Name. */
230 false, /* Partial Inplace. */
231 0, /* Source Mask. */
232 0xffff, /* Dest Mask. */
233 true), /* PC relative offset? */
235 HOWTO (R_OR1K_GOTPC_LO16, /* Type. */
236 0, /* Rightshift. */
237 4, /* Size. */
238 16, /* Bitsize. */
239 true, /* PC_relative. */
240 0, /* Bitpos. */
241 complain_overflow_dont, /* Complain on overflow. */
242 bfd_elf_generic_reloc, /* Special Function. */
243 "R_OR1K_GOTPC_LO16", /* Name. */
244 false, /* Partial Inplace. */
245 0, /* Source Mask. */
246 0xffff, /* Dest Mask. */
247 true), /* PC relative offset? */
249 HOWTO (R_OR1K_GOT16, /* type */
250 0, /* rightshift */
251 4, /* size */
252 16, /* bitsize */
253 false, /* pc_relative */
254 0, /* bitpos */
255 complain_overflow_signed, /* complain_on_overflow */
256 bfd_elf_generic_reloc, /* special_function */
257 "R_OR1K_GOT16", /* name */
258 false, /* partial_inplace */
259 0, /* src_mask */
260 0xffff, /* dst_mask */
261 false), /* pcrel_offset */
263 /* A 26 bit PLT relocation. Shifted by 2. */
264 HOWTO (R_OR1K_PLT26, /* Type. */
265 2, /* Rightshift. */
266 4, /* Size. */
267 26, /* Bitsize. */
268 true, /* pc_relative. */
269 0, /* Bitpos. */
270 complain_overflow_signed, /* Complain on overflow. */
271 bfd_elf_generic_reloc, /* Special Function. */
272 "R_OR1K_PLT26", /* Name. */
273 false, /* Partial Inplace. */
274 0, /* Source Mask. */
275 0x03ffffff, /* Dest Mask. */
276 true), /* PC relative offset? */
278 HOWTO (R_OR1K_GOTOFF_HI16, /* type */
279 16, /* rightshift */
280 4, /* size */
281 16, /* bitsize */
282 false, /* pc_relative */
283 0, /* bitpos */
284 complain_overflow_dont, /* complain_on_overflow */
285 bfd_elf_generic_reloc, /* special_function */
286 "R_OR1K_GOTOFF_HI16", /* name */
287 false, /* partial_inplace */
288 0x0, /* src_mask */
289 0xffff, /* dst_mask */
290 false), /* pcrel_offset */
292 HOWTO (R_OR1K_GOTOFF_LO16, /* type */
293 0, /* rightshift */
294 4, /* size */
295 16, /* bitsize */
296 false, /* pc_relative */
297 0, /* bitpos */
298 complain_overflow_dont, /* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_OR1K_GOTOFF_LO16", /* name */
301 false, /* partial_inplace */
302 0x0, /* src_mask */
303 0xffff, /* dst_mask */
304 false), /* pcrel_offset */
306 HOWTO (R_OR1K_COPY, /* type */
307 0, /* rightshift */
308 4, /* size */
309 32, /* bitsize */
310 false, /* pc_relative */
311 0, /* bitpos */
312 complain_overflow_bitfield, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_OR1K_COPY", /* name */
315 false, /* partial_inplace */
316 0xffffffff, /* src_mask */
317 0xffffffff, /* dst_mask */
318 false), /* pcrel_offset */
320 HOWTO (R_OR1K_GLOB_DAT, /* type */
321 0, /* rightshift */
322 4, /* size */
323 32, /* bitsize */
324 false, /* pc_relative */
325 0, /* bitpos */
326 complain_overflow_bitfield, /* complain_on_overflow */
327 bfd_elf_generic_reloc, /* special_function */
328 "R_OR1K_GLOB_DAT", /* name */
329 false, /* partial_inplace */
330 0xffffffff, /* src_mask */
331 0xffffffff, /* dst_mask */
332 false), /* pcrel_offset */
334 HOWTO (R_OR1K_JMP_SLOT, /* type */
335 0, /* rightshift */
336 4, /* size */
337 32, /* bitsize */
338 false, /* pc_relative */
339 0, /* bitpos */
340 complain_overflow_bitfield, /* complain_on_overflow */
341 bfd_elf_generic_reloc, /* special_function */
342 "R_OR1K_JMP_SLOT", /* name */
343 false, /* partial_inplace */
344 0xffffffff, /* src_mask */
345 0xffffffff, /* dst_mask */
346 false), /* pcrel_offset */
348 HOWTO (R_OR1K_RELATIVE, /* type */
349 0, /* rightshift */
350 4, /* size */
351 32, /* bitsize */
352 false, /* pc_relative */
353 0, /* bitpos */
354 complain_overflow_bitfield, /* complain_on_overflow */
355 bfd_elf_generic_reloc, /* special_function */
356 "R_OR1K_RELATIVE", /* name */
357 false, /* partial_inplace */
358 0xffffffff, /* src_mask */
359 0xffffffff, /* dst_mask */
360 false), /* pcrel_offset */
362 HOWTO (R_OR1K_TLS_GD_HI16, /* type */
363 16, /* rightshift */
364 4, /* size */
365 16, /* bitsize */
366 false, /* pc_relative */
367 0, /* bitpos */
368 complain_overflow_dont, /* complain_on_overflow */
369 bfd_elf_generic_reloc, /* special_function */
370 "R_OR1K_TLS_GD_HI16", /* name */
371 false, /* partial_inplace */
372 0x0, /* src_mask */
373 0xffff, /* dst_mask */
374 false), /* pcrel_offset */
376 HOWTO (R_OR1K_TLS_GD_LO16, /* type */
377 0, /* rightshift */
378 4, /* size */
379 16, /* bitsize */
380 false, /* pc_relative */
381 0, /* bitpos */
382 complain_overflow_dont, /* complain_on_overflow */
383 bfd_elf_generic_reloc, /* special_function */
384 "R_OR1K_TLS_GD_LO16", /* name */
385 false, /* partial_inplace */
386 0x0, /* src_mask */
387 0xffff, /* dst_mask */
388 false), /* pcrel_offset */
390 HOWTO (R_OR1K_TLS_LDM_HI16, /* type */
391 16, /* rightshift */
392 4, /* size */
393 16, /* bitsize */
394 false, /* pc_relative */
395 0, /* bitpos */
396 complain_overflow_dont, /* complain_on_overflow */
397 bfd_elf_generic_reloc, /* special_function */
398 "R_OR1K_TLS_LDM_HI16", /* name */
399 false, /* partial_inplace */
400 0x0, /* src_mask */
401 0xffff, /* dst_mask */
402 false), /* pcrel_offset */
404 HOWTO (R_OR1K_TLS_LDM_LO16, /* type */
405 0, /* rightshift */
406 4, /* size */
407 16, /* bitsize */
408 false, /* pc_relative */
409 0, /* bitpos */
410 complain_overflow_dont, /* complain_on_overflow */
411 bfd_elf_generic_reloc, /* special_function */
412 "R_OR1K_TLS_LDM_LO16", /* name */
413 false, /* partial_inplace */
414 0x0, /* src_mask */
415 0xffff, /* dst_mask */
416 false), /* pcrel_offset */
418 HOWTO (R_OR1K_TLS_LDO_HI16, /* type */
419 16, /* rightshift */
420 4, /* size */
421 16, /* bitsize */
422 false, /* pc_relative */
423 0, /* bitpos */
424 complain_overflow_dont, /* complain_on_overflow */
425 bfd_elf_generic_reloc, /* special_function */
426 "R_OR1K_TLS_LDO_HI16", /* name */
427 false, /* partial_inplace */
428 0x0, /* src_mask */
429 0xffff, /* dst_mask */
430 false), /* pcrel_offset */
432 HOWTO (R_OR1K_TLS_LDO_LO16, /* type */
433 0, /* rightshift */
434 4, /* size */
435 16, /* bitsize */
436 false, /* pc_relative */
437 0, /* bitpos */
438 complain_overflow_dont, /* complain_on_overflow */
439 bfd_elf_generic_reloc, /* special_function */
440 "R_OR1K_TLS_LDO_LO16", /* name */
441 false, /* partial_inplace */
442 0x0, /* src_mask */
443 0xffff, /* dst_mask */
444 false), /* pcrel_offset */
446 HOWTO (R_OR1K_TLS_IE_HI16, /* type */
447 16, /* rightshift */
448 4, /* size */
449 16, /* bitsize */
450 false, /* pc_relative */
451 0, /* bitpos */
452 complain_overflow_dont, /* complain_on_overflow */
453 bfd_elf_generic_reloc, /* special_function */
454 "R_OR1K_TLS_IE_HI16", /* name */
455 false, /* partial_inplace */
456 0x0, /* src_mask */
457 0xffff, /* dst_mask */
458 false), /* pcrel_offset */
460 HOWTO (R_OR1K_TLS_IE_LO16, /* type */
461 0, /* rightshift */
462 4, /* size */
463 16, /* bitsize */
464 false, /* pc_relative */
465 0, /* bitpos */
466 complain_overflow_dont, /* complain_on_overflow */
467 bfd_elf_generic_reloc, /* special_function */
468 "R_OR1K_TLS_IE_LO16", /* name */
469 false, /* partial_inplace */
470 0x0, /* src_mask */
471 0xffff, /* dst_mask */
472 false), /* pcrel_offset */
474 HOWTO (R_OR1K_TLS_LE_HI16, /* type */
475 16, /* rightshift */
476 4, /* size */
477 16, /* bitsize */
478 false, /* pc_relative */
479 0, /* bitpos */
480 complain_overflow_dont, /* complain_on_overflow */
481 bfd_elf_generic_reloc, /* special_function */
482 "R_OR1K_TLS_LE_HI16", /* name */
483 false, /* partial_inplace */
484 0x0, /* src_mask */
485 0xffff, /* dst_mask */
486 false), /* pcrel_offset */
488 HOWTO (R_OR1K_TLS_LE_LO16, /* type */
489 0, /* rightshift */
490 4, /* size */
491 16, /* bitsize */
492 false, /* pc_relative */
493 0, /* bitpos */
494 complain_overflow_dont, /* complain_on_overflow */
495 bfd_elf_generic_reloc, /* special_function */
496 "R_OR1K_TLS_LE_LO16", /* name */
497 false, /* partial_inplace */
498 0x0, /* src_mask */
499 0xffff, /* dst_mask */
500 false), /* pcrel_offset */
502 HOWTO (R_OR1K_TLS_TPOFF, /* type */
503 0, /* rightshift */
504 4, /* size */
505 32, /* bitsize */
506 false, /* pc_relative */
507 0, /* bitpos */
508 complain_overflow_bitfield, /* complain_on_overflow */
509 bfd_elf_generic_reloc, /* special_function */
510 "R_OR1K_TLS_TPOFF", /* name */
511 false, /* partial_inplace */
512 0xffffffff, /* src_mask */
513 0xffffffff, /* dst_mask */
514 false), /* pcrel_offset */
516 HOWTO (R_OR1K_TLS_DTPOFF, /* type */
517 0, /* rightshift */
518 4, /* size */
519 32, /* bitsize */
520 false, /* pc_relative */
521 0, /* bitpos */
522 complain_overflow_bitfield, /* complain_on_overflow */
523 bfd_elf_generic_reloc, /* special_function */
524 "R_OR1K_TLS_DTPOFF", /* name */
525 false, /* partial_inplace */
526 0xffffffff, /* src_mask */
527 0xffffffff, /* dst_mask */
528 false), /* pcrel_offset */
530 HOWTO (R_OR1K_TLS_DTPMOD, /* type */
531 0, /* rightshift */
532 4, /* size */
533 32, /* bitsize */
534 false, /* pc_relative */
535 0, /* bitpos */
536 complain_overflow_bitfield, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 "R_OR1K_TLS_DTPMOD", /* name */
539 false, /* partial_inplace */
540 0xffffffff, /* src_mask */
541 0xffffffff, /* dst_mask */
542 false), /* pcrel_offset */
544 HOWTO (R_OR1K_AHI16, /* type */
545 16, /* rightshift */
546 4, /* size */
547 16, /* bitsize */
548 false, /* pc_relative */
549 0, /* bitpos */
550 complain_overflow_dont, /* complain_on_overflow */
551 bfd_elf_generic_reloc, /* special_function */
552 "R_OR1K_AHI16", /* name */
553 false, /* partial_inplace */
554 0x0, /* src_mask */
555 0xffff, /* dst_mask */
556 false), /* pcrel_offset */
558 HOWTO (R_OR1K_GOTOFF_AHI16, /* type */
559 16, /* rightshift */
560 4, /* size */
561 16, /* bitsize */
562 false, /* pc_relative */
563 0, /* bitpos */
564 complain_overflow_dont, /* complain_on_overflow */
565 bfd_elf_generic_reloc, /* special_function */
566 "R_OR1K_GOTOFF_AHI16", /* name */
567 false, /* partial_inplace */
568 0x0, /* src_mask */
569 0xffff, /* dst_mask */
570 false), /* pcrel_offset */
572 HOWTO (R_OR1K_TLS_IE_AHI16, /* type */
573 16, /* rightshift */
574 4, /* size */
575 16, /* bitsize */
576 false, /* pc_relative */
577 0, /* bitpos */
578 complain_overflow_dont, /* complain_on_overflow */
579 bfd_elf_generic_reloc, /* special_function */
580 "R_OR1K_TLS_IE_AHI16", /* name */
581 false, /* partial_inplace */
582 0x0, /* src_mask */
583 0xffff, /* dst_mask */
584 false), /* pcrel_offset */
586 HOWTO (R_OR1K_TLS_LE_AHI16, /* type */
587 16, /* rightshift */
588 4, /* size */
589 16, /* bitsize */
590 false, /* pc_relative */
591 0, /* bitpos */
592 complain_overflow_dont, /* complain_on_overflow */
593 bfd_elf_generic_reloc, /* special_function */
594 "R_OR1K_TLS_LE_AHI16", /* name */
595 false, /* partial_inplace */
596 0x0, /* src_mask */
597 0xffff, /* dst_mask */
598 false), /* pcrel_offset */
600 HOWTO (R_OR1K_SLO16, /* type */
601 0, /* rightshift */
602 4, /* size */
603 16, /* bitsize */
604 false, /* pc_relative */
605 0, /* bitpos */
606 complain_overflow_dont, /* complain_on_overflow */
607 bfd_elf_generic_reloc, /* special_function */
608 "R_OR1K_SLO16", /* name */
609 false, /* partial_inplace */
610 0x0, /* src_mask */
611 0xffff, /* dst_mask */
612 false), /* pcrel_offset */
614 HOWTO (R_OR1K_GOTOFF_SLO16, /* type */
615 0, /* rightshift */
616 4, /* size */
617 16, /* bitsize */
618 false, /* pc_relative */
619 0, /* bitpos */
620 complain_overflow_dont, /* complain_on_overflow */
621 bfd_elf_generic_reloc, /* special_function */
622 "R_OR1K_GOTOFF_SLO16", /* name */
623 false, /* partial_inplace */
624 0x0, /* src_mask */
625 0xffff, /* dst_mask */
626 false), /* pcrel_offset */
628 HOWTO (R_OR1K_TLS_LE_SLO16, /* type */
629 0, /* rightshift */
630 4, /* size */
631 16, /* bitsize */
632 false, /* pc_relative */
633 0, /* bitpos */
634 complain_overflow_dont, /* complain_on_overflow */
635 bfd_elf_generic_reloc, /* special_function */
636 "R_OR1K_TLS_LE_SLO16", /* name */
637 false, /* partial_inplace */
638 0x0, /* src_mask */
639 0xffff, /* dst_mask */
640 false), /* pcrel_offset */
642 /* A page relative 21 bit relocation, right shifted by 13, aligned.
643 Note that this is *page* relative, not pc relative. The idea is
644 similar, but normally the section alignment is not such that the
645 assembler can infer a final value, which it attempts to do with
646 pc-relative relocations to local symbols. */
647 HOWTO (R_OR1K_PCREL_PG21, /* type */
648 13, /* rightshift */
649 4, /* size */
650 21, /* bitsize */
651 false, /* pc_relative */
652 0, /* bitpos */
653 complain_overflow_signed, /* complain_on_overflow */
654 bfd_elf_generic_reloc, /* special_function */
655 "R_OR1K_PCREL_PG21", /* name */
656 false, /* partial_inplace */
657 0, /* src_mask */
658 0x001fffff, /* dst_mask */
659 true), /* pcrel_offset */
661 HOWTO (R_OR1K_GOT_PG21, /* type */
662 13, /* rightshift */
663 4, /* size */
664 21, /* bitsize */
665 false, /* pc_relative */
666 0, /* bitpos */
667 complain_overflow_signed, /* complain_on_overflow */
668 bfd_elf_generic_reloc, /* special_function */
669 "R_OR1K_GOT_PG21", /* name */
670 false, /* partial_inplace */
671 0, /* src_mask */
672 0x001fffff, /* dst_mask */
673 true), /* pcrel_offset */
675 HOWTO (R_OR1K_TLS_GD_PG21, /* type */
676 13, /* rightshift */
677 4, /* size */
678 21, /* bitsize */
679 false, /* pc_relative */
680 0, /* bitpos */
681 complain_overflow_signed, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_OR1K_TLS_GD_PG21", /* name */
684 false, /* partial_inplace */
685 0, /* src_mask */
686 0x001fffff, /* dst_mask */
687 true), /* pcrel_offset */
689 HOWTO (R_OR1K_TLS_LDM_PG21, /* type */
690 13, /* rightshift */
691 4, /* size */
692 21, /* bitsize */
693 false, /* pc_relative */
694 0, /* bitpos */
695 complain_overflow_signed, /* complain_on_overflow */
696 bfd_elf_generic_reloc, /* special_function */
697 "R_OR1K_TLS_LDM_PG21", /* name */
698 false, /* partial_inplace */
699 0, /* src_mask */
700 0x001fffff, /* dst_mask */
701 true), /* pcrel_offset */
703 HOWTO (R_OR1K_TLS_IE_PG21, /* type */
704 13, /* rightshift */
705 4, /* size */
706 21, /* bitsize */
707 false, /* pc_relative */
708 0, /* bitpos */
709 complain_overflow_signed, /* complain_on_overflow */
710 bfd_elf_generic_reloc, /* special_function */
711 "R_OR1K_TLS_IE_PG21", /* name */
712 false, /* partial_inplace */
713 0, /* src_mask */
714 0x001fffff, /* dst_mask */
715 true), /* pcrel_offset */
717 HOWTO (R_OR1K_LO13, /* type */
718 0, /* rightshift */
719 4, /* size */
720 16, /* bitsize */
721 false, /* pc_relative */
722 0, /* bitpos */
723 complain_overflow_dont, /* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 "R_OR1K_LO13", /* name */
726 false, /* partial_inplace */
727 0x0, /* src_mask */
728 0xffff, /* dst_mask */
729 false), /* pcrel_offset */
731 HOWTO (R_OR1K_GOT_LO13, /* type */
732 0, /* rightshift */
733 4, /* size */
734 16, /* bitsize */
735 false, /* pc_relative */
736 0, /* bitpos */
737 complain_overflow_dont, /* complain_on_overflow */
738 bfd_elf_generic_reloc, /* special_function */
739 "R_OR1K_GOT_LO13", /* name */
740 false, /* partial_inplace */
741 0x0, /* src_mask */
742 0xffff, /* dst_mask */
743 false), /* pcrel_offset */
745 HOWTO (R_OR1K_TLS_GD_LO13, /* type */
746 0, /* rightshift */
747 4, /* size */
748 16, /* bitsize */
749 false, /* pc_relative */
750 0, /* bitpos */
751 complain_overflow_dont, /* complain_on_overflow */
752 bfd_elf_generic_reloc, /* special_function */
753 "R_OR1K_TLS_GD_LO13", /* name */
754 false, /* partial_inplace */
755 0x0, /* src_mask */
756 0xffff, /* dst_mask */
757 false), /* pcrel_offset */
759 HOWTO (R_OR1K_TLS_LDM_LO13, /* type */
760 0, /* rightshift */
761 4, /* size */
762 16, /* bitsize */
763 false, /* pc_relative */
764 0, /* bitpos */
765 complain_overflow_dont, /* complain_on_overflow */
766 bfd_elf_generic_reloc, /* special_function */
767 "R_OR1K_TLD_LDM_LO13", /* name */
768 false, /* partial_inplace */
769 0x0, /* src_mask */
770 0xffff, /* dst_mask */
771 false), /* pcrel_offset */
773 HOWTO (R_OR1K_TLS_IE_LO13, /* type */
774 0, /* rightshift */
775 4, /* size */
776 16, /* bitsize */
777 false, /* pc_relative */
778 0, /* bitpos */
779 complain_overflow_dont, /* complain_on_overflow */
780 bfd_elf_generic_reloc, /* special_function */
781 "R_OR1K_TLS_IE_LO13", /* name */
782 false, /* partial_inplace */
783 0x0, /* src_mask */
784 0xffff, /* dst_mask */
785 false), /* pcrel_offset */
787 HOWTO (R_OR1K_SLO13, /* type */
788 0, /* rightshift */
789 4, /* size */
790 16, /* bitsize */
791 false, /* pc_relative */
792 0, /* bitpos */
793 complain_overflow_dont, /* complain_on_overflow */
794 bfd_elf_generic_reloc, /* special_function */
795 "R_OR1K_SLO13", /* name */
796 false, /* partial_inplace */
797 0x0, /* src_mask */
798 0xffff, /* dst_mask */
799 false), /* pcrel_offset */
801 /* A 26 bit PLT relocation, using ADRP. Shifted by 2. */
802 HOWTO (R_OR1K_PLTA26, /* Type. */
803 2, /* Rightshift. */
804 4, /* Size. */
805 26, /* Bitsize. */
806 true, /* pc_relative. */
807 0, /* Bitpos. */
808 complain_overflow_signed, /* Complain on overflow. */
809 bfd_elf_generic_reloc, /* Special Function. */
810 "R_OR1K_PLTA26", /* Name. */
811 false, /* Partial Inplace. */
812 0, /* Source Mask. */
813 0x03ffffff, /* Dest Mask. */
814 true), /* PC relative offset? */
816 HOWTO (R_OR1K_GOT_AHI16, /* type */
817 16, /* rightshift */
818 4, /* size */
819 16, /* bitsize */
820 false, /* pc_relative */
821 0, /* bitpos */
822 complain_overflow_signed, /* complain_on_overflow */
823 bfd_elf_generic_reloc, /* special_function */
824 "R_OR1K_GOT_AHI16", /* name */
825 false, /* partial_inplace */
826 0, /* src_mask */
827 0xffff, /* dst_mask */
828 false), /* pcrel_offset */
831 /* A copy of the R_OR1K_GOT16 used in the presense of R_OR1K_GOT_AHI16
832 relocations when we know we can ignore overflows. */
833 static reloc_howto_type or1k_elf_got16_no_overflow_howto =
834 HOWTO (R_OR1K_GOT16, /* type */
835 0, /* rightshift */
836 4, /* size */
837 16, /* bitsize */
838 false, /* pc_relative */
839 0, /* bitpos */
840 complain_overflow_dont, /* complain_on_overflow */
841 bfd_elf_generic_reloc, /* special_function */
842 "R_OR1K_GOT16", /* name */
843 false, /* partial_inplace */
844 0, /* src_mask */
845 0xffff, /* dst_mask */
846 false); /* pcrel_offset */
848 /* Map BFD reloc types to Or1k ELF reloc types. */
850 struct or1k_reloc_map
852 bfd_reloc_code_real_type bfd_reloc_val;
853 unsigned int or1k_reloc_val;
856 static const struct or1k_reloc_map or1k_reloc_map[] =
858 { BFD_RELOC_NONE, R_OR1K_NONE },
859 { BFD_RELOC_32, R_OR1K_32 },
860 { BFD_RELOC_16, R_OR1K_16 },
861 { BFD_RELOC_8, R_OR1K_8 },
862 { BFD_RELOC_LO16, R_OR1K_LO_16_IN_INSN },
863 { BFD_RELOC_HI16, R_OR1K_HI_16_IN_INSN },
864 { BFD_RELOC_HI16_S, R_OR1K_AHI16 },
865 { BFD_RELOC_OR1K_REL_26, R_OR1K_INSN_REL_26 },
866 { BFD_RELOC_VTABLE_ENTRY, R_OR1K_GNU_VTENTRY },
867 { BFD_RELOC_VTABLE_INHERIT, R_OR1K_GNU_VTINHERIT },
868 { BFD_RELOC_32_PCREL, R_OR1K_32_PCREL },
869 { BFD_RELOC_16_PCREL, R_OR1K_16_PCREL },
870 { BFD_RELOC_8_PCREL, R_OR1K_8_PCREL },
871 { BFD_RELOC_LO16_GOTOFF, R_OR1K_GOTOFF_LO16 },
872 { BFD_RELOC_HI16_GOTOFF, R_OR1K_GOTOFF_HI16 },
873 { BFD_RELOC_HI16_S_GOTOFF, R_OR1K_GOTOFF_AHI16 },
874 { BFD_RELOC_OR1K_GOTPC_HI16, R_OR1K_GOTPC_HI16 },
875 { BFD_RELOC_OR1K_GOTPC_LO16, R_OR1K_GOTPC_LO16 },
876 { BFD_RELOC_OR1K_GOT16, R_OR1K_GOT16 },
877 { BFD_RELOC_OR1K_PLT26, R_OR1K_PLT26 },
878 { BFD_RELOC_OR1K_GLOB_DAT, R_OR1K_GLOB_DAT },
879 { BFD_RELOC_OR1K_COPY, R_OR1K_COPY },
880 { BFD_RELOC_OR1K_JMP_SLOT, R_OR1K_JMP_SLOT },
881 { BFD_RELOC_OR1K_RELATIVE, R_OR1K_RELATIVE },
882 { BFD_RELOC_OR1K_TLS_GD_HI16, R_OR1K_TLS_GD_HI16 },
883 { BFD_RELOC_OR1K_TLS_GD_LO16, R_OR1K_TLS_GD_LO16 },
884 { BFD_RELOC_OR1K_TLS_LDM_HI16, R_OR1K_TLS_LDM_HI16 },
885 { BFD_RELOC_OR1K_TLS_LDM_LO16, R_OR1K_TLS_LDM_LO16 },
886 { BFD_RELOC_OR1K_TLS_LDO_HI16, R_OR1K_TLS_LDO_HI16 },
887 { BFD_RELOC_OR1K_TLS_LDO_LO16, R_OR1K_TLS_LDO_LO16 },
888 { BFD_RELOC_OR1K_TLS_IE_HI16, R_OR1K_TLS_IE_HI16 },
889 { BFD_RELOC_OR1K_TLS_IE_LO16, R_OR1K_TLS_IE_LO16 },
890 { BFD_RELOC_OR1K_TLS_IE_AHI16, R_OR1K_TLS_IE_AHI16 },
891 { BFD_RELOC_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_HI16 },
892 { BFD_RELOC_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_LO16 },
893 { BFD_RELOC_OR1K_TLS_LE_AHI16, R_OR1K_TLS_LE_AHI16 },
894 { BFD_RELOC_OR1K_SLO16, R_OR1K_SLO16 },
895 { BFD_RELOC_OR1K_GOTOFF_SLO16, R_OR1K_GOTOFF_SLO16 },
896 { BFD_RELOC_OR1K_TLS_LE_SLO16, R_OR1K_TLS_LE_SLO16 },
897 { BFD_RELOC_OR1K_PCREL_PG21, R_OR1K_PCREL_PG21 },
898 { BFD_RELOC_OR1K_GOT_PG21, R_OR1K_GOT_PG21 },
899 { BFD_RELOC_OR1K_TLS_GD_PG21, R_OR1K_TLS_GD_PG21 },
900 { BFD_RELOC_OR1K_TLS_LDM_PG21, R_OR1K_TLS_LDM_PG21 },
901 { BFD_RELOC_OR1K_TLS_IE_PG21, R_OR1K_TLS_IE_PG21 },
902 { BFD_RELOC_OR1K_LO13, R_OR1K_LO13 },
903 { BFD_RELOC_OR1K_GOT_LO13, R_OR1K_GOT_LO13 },
904 { BFD_RELOC_OR1K_TLS_GD_LO13, R_OR1K_TLS_GD_LO13 },
905 { BFD_RELOC_OR1K_TLS_LDM_LO13, R_OR1K_TLS_LDM_LO13 },
906 { BFD_RELOC_OR1K_TLS_IE_LO13, R_OR1K_TLS_IE_LO13 },
907 { BFD_RELOC_OR1K_SLO13, R_OR1K_SLO13 },
908 { BFD_RELOC_OR1K_PLTA26, R_OR1K_PLTA26 },
909 { BFD_RELOC_OR1K_GOT_AHI16, R_OR1K_GOT_AHI16 },
912 /* tls_type is a mask used to track how each symbol is accessed,
913 it may be accessed via multiple types of TLS access methods.
914 We track this for sizing (allocating got + relocation section space) and
915 for how to process relocations. */
916 #define TLS_UNKNOWN 0
917 #define TLS_NONE 1
918 #define TLS_GD 2
919 #define TLS_LD 4
920 #define TLS_IE 8
921 #define TLS_LE 16
923 /* The size of the TLS thread control block, used to offset LE access. */
924 #define TCB_SIZE 16
926 /* ELF linker hash entry. */
927 struct elf_or1k_link_hash_entry
929 struct elf_link_hash_entry root;
931 /* For calculating PLT size. */
932 bfd_vma plt_index;
933 /* Track type of TLS access. */
934 unsigned char tls_type;
937 /* ELF object data. */
938 struct elf_or1k_obj_tdata
940 struct elf_obj_tdata root;
942 /* tls_type for each local got entry. */
943 unsigned char *local_tls_type;
946 #define elf_or1k_tdata(abfd) \
947 ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
949 #define elf_or1k_local_tls_type(abfd) \
950 (elf_or1k_tdata (abfd)->local_tls_type)
952 /* ELF linker hash table. */
953 struct elf_or1k_link_hash_table
955 struct elf_link_hash_table root;
957 bfd_vma plt_count;
958 bool saw_plta;
961 static size_t
962 elf_or1k_plt_entry_size (bfd_vma plt_index)
964 bfd_vma plt_reloc;
966 plt_reloc = plt_index * sizeof (Elf32_External_Rela);
968 return (plt_reloc > 0xffff) ? PLT_ENTRY_SIZE_LARGE : PLT_ENTRY_SIZE;
971 /* Get the ELF linker hash table from a link_info structure. */
972 #define or1k_elf_hash_table(p) \
973 ((is_elf_hash_table ((p)->hash) \
974 && elf_hash_table_id (elf_hash_table (p)) == OR1K_ELF_DATA) \
975 ? (struct elf_or1k_link_hash_table *) (p)->hash : NULL)
977 static bool
978 elf_or1k_mkobject (bfd *abfd)
980 return bfd_elf_allocate_object (abfd, sizeof (struct elf_or1k_obj_tdata));
983 /* Create an entry in an or1k ELF linker hash table. */
985 static struct bfd_hash_entry *
986 or1k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
987 struct bfd_hash_table *table,
988 const char *string)
990 struct elf_or1k_link_hash_entry *ret =
991 (struct elf_or1k_link_hash_entry *) entry;
993 /* Allocate the structure if it has not already been allocated by a
994 subclass. */
995 if (ret == NULL)
996 ret = bfd_hash_allocate (table,
997 sizeof (struct elf_or1k_link_hash_entry));
998 if (ret == NULL)
999 return NULL;
1001 /* Call the allocation method of the superclass. */
1002 ret = ((struct elf_or1k_link_hash_entry *)
1003 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1004 table, string));
1005 if (ret != NULL)
1007 struct elf_or1k_link_hash_entry *eh;
1009 eh = (struct elf_or1k_link_hash_entry *) ret;
1010 eh->tls_type = TLS_UNKNOWN;
1013 return (struct bfd_hash_entry *) ret;
1016 /* Create an or1k ELF linker hash table. */
1018 static struct bfd_link_hash_table *
1019 or1k_elf_link_hash_table_create (bfd *abfd)
1021 struct elf_or1k_link_hash_table *ret;
1022 size_t amt = sizeof (struct elf_or1k_link_hash_table);
1024 ret = bfd_zmalloc (amt);
1025 if (ret == NULL)
1026 return NULL;
1028 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
1029 or1k_elf_link_hash_newfunc,
1030 sizeof (struct elf_or1k_link_hash_entry)))
1032 free (ret);
1033 return NULL;
1036 return &ret->root.root;
1039 static reloc_howto_type *
1040 or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
1041 bfd_reloc_code_real_type bcode)
1043 unsigned int i;
1045 for (i = 0; i < ARRAY_SIZE (or1k_reloc_map); i++)
1046 if (or1k_reloc_map[i].bfd_reloc_val == bcode)
1048 unsigned int ocode = or1k_reloc_map[i].or1k_reloc_val;
1049 if (ocode < (unsigned int) R_OR1K_max)
1050 return &or1k_elf_howto_table[ocode];
1051 else
1052 break;
1055 return NULL;
1058 static reloc_howto_type *
1059 or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1060 const char *r_name)
1062 unsigned int i;
1064 for (i = 0; i < R_OR1K_max; i++)
1065 if (or1k_elf_howto_table[i].name != NULL
1066 && strcasecmp (or1k_elf_howto_table[i].name, r_name) == 0)
1067 return &or1k_elf_howto_table[i];
1069 return NULL;
1072 /* Set the howto pointer for an Or1k ELF reloc. */
1074 static bool
1075 or1k_info_to_howto_rela (bfd * abfd,
1076 arelent * cache_ptr,
1077 Elf_Internal_Rela * dst)
1079 unsigned int r_type;
1081 r_type = ELF32_R_TYPE (dst->r_info);
1082 if (r_type >= (unsigned int) R_OR1K_max)
1084 /* xgettext:c-format */
1085 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1086 abfd, r_type);
1087 bfd_set_error (bfd_error_bad_value);
1088 return false;
1090 cache_ptr->howto = & or1k_elf_howto_table[r_type];
1091 return true;
1094 /* Return the relocation value for @tpoff relocations.. */
1095 static bfd_vma
1096 tpoff (struct bfd_link_info *info, bfd_vma address, bool dynamic)
1098 struct elf_link_hash_table *htab = elf_hash_table (info);
1099 bfd_vma base;
1101 /* If tls_sec is NULL, we should have signalled an error already. */
1102 if (htab->tls_sec == NULL)
1103 return 0;
1105 if (dynamic)
1106 return address - htab->tls_sec->vma;
1107 else
1109 /* On or1k, the tp points to just after the tcb, if we have an alignment
1110 greater than the tcb size we need to offset by the alignment difference. */
1111 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power)
1112 - TCB_SIZE;
1114 /* The thread pointer on or1k stores the address after the TCB where
1115 the data is, just compute the difference. No need to compensate
1116 for the size of TCB. */
1117 return address - htab->tls_sec->vma + base;
1121 /* If we have both IE and GD accesses to a symbol the IE relocations should be
1122 offset by 8 bytes because the got contains both GD and IE entries. */
1123 static bfd_vma
1124 or1k_initial_exec_offset (reloc_howto_type *howto, unsigned char tls_type_mask)
1126 switch (howto->type)
1128 case R_OR1K_TLS_IE_HI16:
1129 case R_OR1K_TLS_IE_LO16:
1130 case R_OR1K_TLS_IE_PG21:
1131 case R_OR1K_TLS_IE_LO13:
1132 case R_OR1K_TLS_IE_AHI16:
1133 return (tls_type_mask & TLS_GD) != 0 ? 8 : 0;
1134 default:
1135 return 0;
1139 /* Like _bfd_final_link_relocate, but handles non-contiguous fields. */
1141 static bfd_reloc_status_type
1142 or1k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
1143 asection *input_section, bfd_byte *contents,
1144 bfd_vma offset, bfd_vma value)
1146 bfd_reloc_status_type status = bfd_reloc_ok;
1147 int size = bfd_get_reloc_size (howto);
1148 bfd_vma x, place;
1150 /* Sanity check the address. */
1151 if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
1152 return bfd_reloc_outofrange;
1154 place = (input_section->output_section->vma
1155 + input_section->output_offset
1156 + (howto->pcrel_offset ? offset : 0));
1158 switch (howto->type)
1160 case R_OR1K_AHI16:
1161 case R_OR1K_GOT_AHI16:
1162 case R_OR1K_GOTOFF_AHI16:
1163 case R_OR1K_TLS_IE_AHI16:
1164 case R_OR1K_TLS_LE_AHI16:
1165 /* Adjust the operand to match with a signed LO16. */
1166 value += 0x8000;
1167 break;
1169 case R_OR1K_INSN_REL_26:
1170 value -= place;
1171 /* Diagnose mis-aligned branch targets. */
1172 if (value & 3)
1173 status = bfd_reloc_dangerous;
1174 break;
1176 case R_OR1K_PCREL_PG21:
1177 case R_OR1K_GOT_PG21:
1178 case R_OR1K_TLS_GD_PG21:
1179 case R_OR1K_TLS_LDM_PG21:
1180 case R_OR1K_TLS_IE_PG21:
1181 value = (value & -8192) - (place & -8192);
1182 break;
1184 case R_OR1K_LO13:
1185 case R_OR1K_GOT_LO13:
1186 case R_OR1K_TLS_GD_LO13:
1187 case R_OR1K_TLS_LDM_LO13:
1188 case R_OR1K_TLS_IE_LO13:
1189 case R_OR1K_SLO13:
1190 value &= 8191;
1191 break;
1193 default:
1194 if (howto->pc_relative)
1195 value -= place;
1196 break;
1199 status = bfd_check_overflow (howto->complain_on_overflow,
1200 howto->bitsize,
1201 howto->rightshift,
1202 bfd_arch_bits_per_address (input_bfd),
1203 value);
1204 value >>= howto->rightshift;
1206 /* If we're overwriting the entire destination,
1207 then no need to read the current contents. */
1208 if (size == 0 || howto->dst_mask == N_ONES (size))
1209 x = 0;
1210 else
1212 BFD_ASSERT (size == 4);
1213 x = bfd_get_32 (input_bfd, contents + offset);
1216 switch (howto->type)
1218 case R_OR1K_SLO16:
1219 case R_OR1K_GOTOFF_SLO16:
1220 case R_OR1K_TLS_LE_SLO16:
1221 case R_OR1K_SLO13:
1222 /* The split imm16 field used for stores. */
1223 x = (x & ~0x3e007ff) | ((value & 0xf800) << 10) | (value & 0x7ff);
1224 break;
1226 default:
1228 bfd_vma fieldmask = howto->dst_mask;
1229 value <<= howto->bitpos;
1230 x = (x & ~fieldmask) | (value & fieldmask);
1232 break;
1235 /* Put the relocated value back in the object file. */
1236 switch (size)
1238 case 0:
1239 break;
1240 case 1:
1241 bfd_put_8 (input_bfd, x, contents + offset);
1242 break;
1243 case 2:
1244 bfd_put_16 (input_bfd, x, contents + offset);
1245 break;
1246 case 4:
1247 bfd_put_32 (input_bfd, x, contents + offset);
1248 break;
1249 #ifdef BFD64
1250 case 8:
1251 bfd_put_64 (input_bfd, x, contents + offset);
1252 break;
1253 #endif
1254 default:
1255 _bfd_error_handler
1256 (_("%pB: Cannot handle relocation value size of %d"),
1257 input_bfd, size);
1258 abort ();
1260 return status;
1263 /* Relocate an Or1k ELF section.
1265 The RELOCATE_SECTION function is called by the new ELF backend linker
1266 to handle the relocations for a section.
1268 The relocs are always passed as Rela structures; if the section
1269 actually uses Rel structures, the r_addend field will always be
1270 zero.
1272 This function is responsible for adjusting the section contents as
1273 necessary, and (if using Rela relocs and generating a relocatable
1274 output file) adjusting the reloc addend as necessary.
1276 This function does not have to worry about setting the reloc
1277 address or the reloc symbol index.
1279 LOCAL_SYMS is a pointer to the swapped in local symbols.
1281 LOCAL_SECTIONS is an array giving the section in the input file
1282 corresponding to the st_shndx field of each local symbol.
1284 The global hash table entry for the global symbols can be found
1285 via elf_sym_hashes (input_bfd).
1287 When generating relocatable output, this function must handle
1288 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1289 going to be the section symbol corresponding to the output
1290 section, which means that the addend must be adjusted
1291 accordingly. */
1293 static int
1294 or1k_elf_relocate_section (bfd *output_bfd,
1295 struct bfd_link_info *info,
1296 bfd *input_bfd,
1297 asection *input_section,
1298 bfd_byte *contents,
1299 Elf_Internal_Rela *relocs,
1300 Elf_Internal_Sym *local_syms,
1301 asection **local_sections)
1303 Elf_Internal_Shdr *symtab_hdr;
1304 struct elf_link_hash_entry **sym_hashes;
1305 Elf_Internal_Rela *rel;
1306 Elf_Internal_Rela *relend;
1307 struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
1308 asection *sreloc;
1309 bfd_vma *local_got_offsets;
1310 asection *sgot, *splt;
1311 bfd_vma plt_base, got_base, got_sym_value;
1312 bool ret_val = true;
1313 bool saw_gotha = false;
1315 if (htab == NULL)
1316 return false;
1318 local_got_offsets = elf_local_got_offsets (input_bfd);
1320 sreloc = elf_section_data (input_section)->sreloc;
1322 splt = htab->root.splt;
1323 plt_base = 0;
1324 if (splt != NULL)
1325 plt_base = splt->output_section->vma + splt->output_offset;
1327 sgot = htab->root.sgot;
1328 got_sym_value = got_base = 0;
1329 if (sgot != NULL)
1331 struct elf_link_hash_entry *hgot = htab->root.hgot;
1332 got_sym_value = (hgot->root.u.def.value
1333 + hgot->root.u.def.section->output_section->vma
1334 + hgot->root.u.def.section->output_offset);
1335 got_base = sgot->output_section->vma + sgot->output_offset;
1338 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1339 sym_hashes = elf_sym_hashes (input_bfd);
1340 relend = relocs + input_section->reloc_count;
1342 /* Make a full scan for R_OR1K_GOT_AHI16, since it could be AFTER R_OR1K_GOT16. */
1343 for (rel = relocs; rel < relend; rel++)
1345 int r_type = ELF32_R_TYPE (rel->r_info);
1346 if (r_type==R_OR1K_GOT_AHI16)
1348 saw_gotha = true;
1349 break;
1353 for (rel = relocs; rel < relend; rel++)
1355 reloc_howto_type *howto;
1356 unsigned long r_symndx;
1357 Elf_Internal_Sym *sym;
1358 asection *sec;
1359 struct elf_link_hash_entry *h;
1360 bfd_vma relocation;
1361 bfd_reloc_status_type r;
1362 const char *name = NULL;
1363 int r_type;
1365 r_type = ELF32_R_TYPE (rel->r_info);
1366 r_symndx = ELF32_R_SYM (rel->r_info);
1368 if (r_type == R_OR1K_GNU_VTINHERIT
1369 || r_type == R_OR1K_GNU_VTENTRY)
1370 continue;
1372 if (r_type < 0 || r_type >= (int) R_OR1K_max)
1374 _bfd_error_handler
1375 (_("%pB: unknown relocation type %d"),
1376 input_bfd, (int) r_type);
1377 bfd_set_error (bfd_error_bad_value);
1378 ret_val = false;
1379 continue;
1382 howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
1383 h = NULL;
1384 sym = NULL;
1385 sec = NULL;
1387 if (r_symndx < symtab_hdr->sh_info)
1389 sym = local_syms + r_symndx;
1390 sec = local_sections[r_symndx];
1391 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1393 name = bfd_elf_string_from_elf_section
1394 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1395 name = name == NULL ? bfd_section_name (sec) : name;
1397 else
1399 bool unresolved_reloc, warned, ignored;
1401 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1402 r_symndx, symtab_hdr, sym_hashes,
1403 h, sec, relocation,
1404 unresolved_reloc, warned, ignored);
1405 name = h->root.root.string;
1408 if (sec != NULL && discarded_section (sec))
1409 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1410 rel, 1, relend, howto, 0, contents);
1412 if (bfd_link_relocatable (info))
1413 continue;
1415 switch (howto->type)
1417 case R_OR1K_PLT26:
1418 case R_OR1K_PLTA26:
1419 /* If the call is not local, redirect the branch to the PLT.
1420 Otherwise do nothing to send the branch to the symbol direct. */
1421 if (!SYMBOL_CALLS_LOCAL (info, h)
1422 && h->plt.offset != (bfd_vma) -1)
1423 relocation = plt_base + h->plt.offset;
1425 /* Addend should be zero. */
1426 if (rel->r_addend != 0)
1428 _bfd_error_handler
1429 (_("%pB: addend should be zero for plt relocations"),
1430 input_bfd);
1431 bfd_set_error (bfd_error_bad_value);
1432 ret_val = false;
1434 break;
1436 case R_OR1K_GOT_AHI16:
1437 case R_OR1K_GOT16:
1438 case R_OR1K_GOT_PG21:
1439 case R_OR1K_GOT_LO13:
1441 bfd_vma off;
1443 /* Relocation is to the entry for this symbol
1444 in the global offset table. */
1445 BFD_ASSERT (sgot != NULL);
1446 if (h != NULL)
1448 bool dyn;
1450 off = h->got.offset;
1451 BFD_ASSERT (off != (bfd_vma) -1);
1453 dyn = htab->root.dynamic_sections_created;
1454 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
1455 bfd_link_pic (info),
1457 || (bfd_link_pic (info)
1458 && SYMBOL_REFERENCES_LOCAL (info, h)))
1460 /* This is actually a static link, or it is a -Bsymbolic
1461 link and the symbol is defined locally, or the symbol
1462 was forced to be local because of a version file.
1463 We must initialize this entry in the GOT. Since the
1464 offset must always be a multiple of 4, we use the least
1465 significant bit to record whether we have initialized
1466 it already.
1468 When doing a dynamic link, we create a .rela.got
1469 relocation entry to initialize the value. This
1470 is done in the finish_dynamic_symbol routine. */
1471 if ((off & 1) != 0)
1472 off &= ~1;
1473 else
1475 /* Write entry in GOT. */
1476 bfd_put_32 (output_bfd, relocation,
1477 sgot->contents + off);
1478 /* Mark GOT entry as having been written. */
1479 h->got.offset |= 1;
1483 else
1485 bfd_byte *loc;
1487 BFD_ASSERT (local_got_offsets != NULL
1488 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1490 /* Get offset into GOT table. */
1491 off = local_got_offsets[r_symndx];
1493 /* The offset must always be a multiple of 4. We use
1494 the least significant bit to record whether we have
1495 already processed this entry. */
1496 if ((off & 1) != 0)
1497 off &= ~1;
1498 else
1500 /* Write entry in GOT. */
1501 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1502 if (bfd_link_pic (info))
1504 asection *srelgot;
1505 Elf_Internal_Rela outrel;
1507 /* We need to generate a R_OR1K_RELATIVE reloc
1508 for the dynamic linker. */
1509 srelgot = htab->root.srelgot;
1510 BFD_ASSERT (srelgot != NULL);
1512 outrel.r_offset = got_base + off;
1513 outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
1514 outrel.r_addend = relocation;
1515 loc = srelgot->contents;
1516 loc += (srelgot->reloc_count
1517 * sizeof (Elf32_External_Rela));
1518 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1519 ++srelgot->reloc_count;
1521 local_got_offsets[r_symndx] |= 1;
1525 /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
1526 while the GOT16 reloc is GOT relative. */
1527 relocation = got_base + off;
1528 if (r_type == R_OR1K_GOT16
1529 || r_type == R_OR1K_GOT_AHI16)
1530 relocation -= got_sym_value;
1532 /* If we have a R_OR1K_GOT16 following a R_OR1K_GOT_AHI16
1533 relocation we assume the code is doing the right thing to avoid
1534 overflows. */
1535 if (r_type == R_OR1K_GOT16 && saw_gotha)
1536 howto = &or1k_elf_got16_no_overflow_howto;
1538 /* Addend should be zero. */
1539 if (rel->r_addend != 0)
1541 _bfd_error_handler
1542 (_("%pB: addend should be zero for got relocations"),
1543 input_bfd);
1544 bfd_set_error (bfd_error_bad_value);
1545 ret_val = false;
1548 break;
1550 case R_OR1K_GOTOFF_LO16:
1551 case R_OR1K_GOTOFF_HI16:
1552 case R_OR1K_GOTOFF_AHI16:
1553 case R_OR1K_GOTOFF_SLO16:
1554 /* Relocation is offset from GOT. */
1555 BFD_ASSERT (sgot != NULL);
1556 if (!SYMBOL_REFERENCES_LOCAL (info, h))
1558 _bfd_error_handler
1559 (_("%pB: gotoff relocation against dynamic symbol %s"),
1560 input_bfd, h->root.root.string);
1561 ret_val = false;
1562 bfd_set_error (bfd_error_bad_value);
1564 relocation -= got_sym_value;
1565 break;
1567 case R_OR1K_INSN_REL_26:
1568 /* For a non-shared link, these will reference plt or call the
1569 version of actual object. */
1570 if (bfd_link_pic (info) && !SYMBOL_CALLS_LOCAL (info, h))
1572 _bfd_error_handler
1573 (_("%pB: pc-relative relocation against dynamic symbol %s"),
1574 input_bfd, name);
1575 ret_val = false;
1576 bfd_set_error (bfd_error_bad_value);
1578 break;
1580 case R_OR1K_PCREL_PG21:
1581 case R_OR1K_LO13:
1582 case R_OR1K_SLO13:
1583 /* For a non-shared link, these will reference either the plt
1584 or a .dynbss copy of the symbol. */
1585 if (bfd_link_pic (info) && !SYMBOL_REFERENCES_LOCAL (info, h))
1587 _bfd_error_handler
1588 (_("%pB: pc-relative relocation against dynamic symbol %s"),
1589 input_bfd, name);
1590 ret_val = false;
1591 bfd_set_error (bfd_error_bad_value);
1593 break;
1595 case R_OR1K_HI_16_IN_INSN:
1596 case R_OR1K_LO_16_IN_INSN:
1597 case R_OR1K_AHI16:
1598 case R_OR1K_SLO16:
1599 if (bfd_link_pic (info))
1601 _bfd_error_handler
1602 (_("%pB: non-pic relocation against symbol %s"),
1603 input_bfd, name);
1604 ret_val = false;
1605 bfd_set_error (bfd_error_bad_value);
1607 break;
1609 case R_OR1K_32:
1610 /* R_OR1K_16? */
1612 /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1613 from removed linkonce sections, or sections discarded by
1614 a linker script. */
1615 if (r_symndx == STN_UNDEF
1616 || (input_section->flags & SEC_ALLOC) == 0)
1617 break;
1619 /* Emit a direct relocation if the symbol is dynamic,
1620 or a RELATIVE reloc for shared objects. We can omit
1621 RELATIVE relocs to local undefweak symbols. */
1622 if (bfd_link_pic (info)
1623 ? (h == NULL
1624 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1625 || h->root.type != bfd_link_hash_undefweak)
1626 : (h != NULL
1627 && h->dynindx != -1
1628 && !h->non_got_ref
1629 && ((h->def_dynamic && !h->def_regular)
1630 || h->root.type == bfd_link_hash_undefweak
1631 || h->root.type == bfd_link_hash_undefined)))
1633 Elf_Internal_Rela outrel;
1634 bfd_byte *loc;
1635 bool skip;
1637 /* When generating a shared object, these relocations
1638 are copied into the output file to be resolved at run
1639 time. */
1641 BFD_ASSERT (sreloc != NULL);
1643 skip = false;
1645 outrel.r_offset =
1646 _bfd_elf_section_offset (output_bfd, info, input_section,
1647 rel->r_offset);
1648 if (outrel.r_offset == (bfd_vma) -1)
1649 skip = true;
1650 else if (outrel.r_offset == (bfd_vma) -2)
1651 skip = true;
1652 outrel.r_offset += (input_section->output_section->vma
1653 + input_section->output_offset);
1655 if (skip)
1656 memset (&outrel, 0, sizeof outrel);
1657 else if (SYMBOL_REFERENCES_LOCAL (info, h))
1659 outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
1660 outrel.r_addend = relocation + rel->r_addend;
1662 else
1664 BFD_ASSERT (h->dynindx != -1);
1665 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1666 outrel.r_addend = rel->r_addend;
1669 loc = sreloc->contents;
1670 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1671 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1672 break;
1674 break;
1677 case R_OR1K_TLS_LDM_HI16:
1678 case R_OR1K_TLS_LDM_LO16:
1679 case R_OR1K_TLS_LDM_PG21:
1680 case R_OR1K_TLS_LDM_LO13:
1681 case R_OR1K_TLS_LDO_HI16:
1682 case R_OR1K_TLS_LDO_LO16:
1683 /* TODO: implement support for local dynamic. */
1684 BFD_FAIL ();
1685 _bfd_error_handler
1686 (_("%pB: support for local dynamic not implemented"),
1687 input_bfd);
1688 bfd_set_error (bfd_error_bad_value);
1689 return false;
1691 case R_OR1K_TLS_GD_HI16:
1692 case R_OR1K_TLS_GD_LO16:
1693 case R_OR1K_TLS_GD_PG21:
1694 case R_OR1K_TLS_GD_LO13:
1695 case R_OR1K_TLS_IE_HI16:
1696 case R_OR1K_TLS_IE_LO16:
1697 case R_OR1K_TLS_IE_PG21:
1698 case R_OR1K_TLS_IE_LO13:
1699 case R_OR1K_TLS_IE_AHI16:
1701 bfd_vma gotoff;
1702 Elf_Internal_Rela rela;
1703 asection *srelgot;
1704 bfd_byte *loc;
1705 bool dynamic;
1706 int indx = 0;
1707 unsigned char tls_type;
1709 srelgot = htab->root.srelgot;
1711 /* Mark as TLS related GOT entry by setting
1712 bit 2 to indcate TLS and bit 1 to indicate GOT. */
1713 if (h != NULL)
1715 gotoff = h->got.offset;
1716 tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
1717 h->got.offset |= 3;
1719 else
1721 unsigned char *local_tls_type;
1723 gotoff = local_got_offsets[r_symndx];
1724 local_tls_type = (unsigned char *) elf_or1k_local_tls_type (input_bfd);
1725 tls_type = local_tls_type == NULL ? TLS_NONE
1726 : local_tls_type[r_symndx];
1727 local_got_offsets[r_symndx] |= 3;
1730 /* Only process the relocation once. */
1731 if ((gotoff & 1) != 0)
1733 gotoff += or1k_initial_exec_offset (howto, tls_type);
1735 /* The PG21 and LO13 relocs are pc-relative, while the
1736 rest are GOT relative. */
1737 relocation = got_base + (gotoff & ~3);
1738 if (!(r_type == R_OR1K_TLS_GD_PG21
1739 || r_type == R_OR1K_TLS_GD_LO13
1740 || r_type == R_OR1K_TLS_IE_PG21
1741 || r_type == R_OR1K_TLS_IE_LO13))
1742 relocation -= got_sym_value;
1743 break;
1746 BFD_ASSERT (elf_hash_table (info)->hgot == NULL
1747 || elf_hash_table (info)->hgot->root.u.def.value == 0);
1749 if (h != NULL)
1751 bool dyn = htab->root.dynamic_sections_created;
1752 bool pic = bfd_link_pic (info);
1754 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
1755 && (!pic || !SYMBOL_REFERENCES_LOCAL (info, h)))
1756 indx = h->dynindx;
1759 /* Dynamic entries will require relocations. If we do not need
1760 them we will just use the default R_OR1K_NONE and
1761 not set anything. */
1762 dynamic = (bfd_link_pic (info) || indx != 0)
1763 && (h == NULL
1764 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1765 || h->root.type != bfd_link_hash_undefweak);
1767 /* Shared GD. */
1768 if (dynamic && ((tls_type & TLS_GD) != 0))
1770 int i;
1772 /* Add DTPMOD and DTPOFF GOT and rela entries. */
1773 for (i = 0; i < 2; ++i)
1775 BFD_ASSERT (srelgot->contents != NULL);
1777 rela.r_offset = got_base + gotoff + i*4;
1778 if (h != NULL && h->dynindx != -1)
1780 rela.r_info = ELF32_R_INFO (h->dynindx,
1781 (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
1782 rela.r_addend = 0;
1784 else
1786 rela.r_info = ELF32_R_INFO (0,
1787 (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
1788 rela.r_addend =
1789 (i == 0 ? 0 : tpoff (info, relocation, dynamic));
1792 loc = srelgot->contents;
1793 loc += (srelgot->reloc_count++
1794 * sizeof (Elf32_External_Rela));
1796 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1797 bfd_put_32 (output_bfd, 0, sgot->contents + gotoff + i*4);
1800 /* Static GD. */
1801 else if ((tls_type & TLS_GD) != 0)
1803 bfd_put_32 (output_bfd, 1, sgot->contents + gotoff);
1804 bfd_put_32 (output_bfd, tpoff (info, relocation, dynamic),
1805 sgot->contents + gotoff + 4);
1808 gotoff += or1k_initial_exec_offset (howto, tls_type);
1810 /* Shared IE. */
1811 if (dynamic && ((tls_type & TLS_IE) != 0))
1813 BFD_ASSERT (srelgot->contents != NULL);
1815 /* Add TPOFF GOT and rela entries. */
1816 rela.r_offset = got_base + gotoff;
1817 if (h != NULL && h->dynindx != -1)
1819 rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
1820 rela.r_addend = 0;
1822 else
1824 rela.r_info = ELF32_R_INFO (0, R_OR1K_TLS_TPOFF);
1825 rela.r_addend = tpoff (info, relocation, dynamic);
1828 loc = srelgot->contents;
1829 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1831 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1832 bfd_put_32 (output_bfd, 0, sgot->contents + gotoff);
1834 /* Static IE. */
1835 else if ((tls_type & TLS_IE) != 0)
1836 bfd_put_32 (output_bfd, tpoff (info, relocation, dynamic),
1837 sgot->contents + gotoff);
1839 /* The PG21 and LO13 relocs are pc-relative, while the
1840 rest are GOT relative. */
1841 relocation = got_base + gotoff;
1842 if (!(r_type == R_OR1K_TLS_GD_PG21
1843 || r_type == R_OR1K_TLS_GD_LO13
1844 || r_type == R_OR1K_TLS_IE_PG21
1845 || r_type == R_OR1K_TLS_IE_LO13))
1846 relocation -= got_sym_value;
1848 break;
1850 case R_OR1K_TLS_LE_HI16:
1851 case R_OR1K_TLS_LE_LO16:
1852 case R_OR1K_TLS_LE_AHI16:
1853 case R_OR1K_TLS_LE_SLO16:
1854 /* Relocation is offset from TP. */
1855 relocation = tpoff (info, relocation, 0);
1856 break;
1858 case R_OR1K_TLS_DTPMOD:
1859 case R_OR1K_TLS_DTPOFF:
1860 case R_OR1K_TLS_TPOFF:
1861 /* These are resolved dynamically on load and shouldn't
1862 be used as linker input. */
1863 BFD_FAIL ();
1864 _bfd_error_handler
1865 (_("%pB: will not resolve runtime TLS relocation"),
1866 input_bfd);
1867 bfd_set_error (bfd_error_bad_value);
1868 return false;
1870 default:
1871 break;
1874 r = or1k_final_link_relocate (howto, input_bfd, input_section, contents,
1875 rel->r_offset, relocation + rel->r_addend);
1877 if (r != bfd_reloc_ok)
1879 const char *msg = NULL;
1881 switch (r)
1883 case bfd_reloc_overflow:
1884 (*info->callbacks->reloc_overflow)
1885 (info, (h ? &h->root : NULL), name, howto->name,
1886 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1887 break;
1889 case bfd_reloc_undefined:
1890 (*info->callbacks->undefined_symbol)
1891 (info, name, input_bfd, input_section, rel->r_offset, true);
1892 break;
1894 case bfd_reloc_outofrange:
1895 msg = _("internal error: out of range error");
1896 break;
1898 case bfd_reloc_notsupported:
1899 msg = _("internal error: unsupported relocation error");
1900 break;
1902 case bfd_reloc_dangerous:
1903 msg = _("internal error: dangerous relocation");
1904 break;
1906 default:
1907 msg = _("internal error: unknown error");
1908 break;
1911 if (msg)
1912 (*info->callbacks->warning) (info, msg, name, input_bfd,
1913 input_section, rel->r_offset);
1917 return ret_val;
1920 /* Return the section that should be marked against GC for a given
1921 relocation. */
1923 static asection *
1924 or1k_elf_gc_mark_hook (asection *sec,
1925 struct bfd_link_info *info,
1926 Elf_Internal_Rela *rel,
1927 struct elf_link_hash_entry *h,
1928 Elf_Internal_Sym *sym)
1930 if (h != NULL)
1931 switch (ELF32_R_TYPE (rel->r_info))
1933 case R_OR1K_GNU_VTINHERIT:
1934 case R_OR1K_GNU_VTENTRY:
1935 return NULL;
1938 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1941 /* Look through the relocs for a section during the first phase. */
1943 static bool
1944 or1k_elf_check_relocs (bfd *abfd,
1945 struct bfd_link_info *info,
1946 asection *sec,
1947 const Elf_Internal_Rela *relocs)
1949 Elf_Internal_Shdr *symtab_hdr;
1950 struct elf_link_hash_entry **sym_hashes;
1951 const Elf_Internal_Rela *rel;
1953 const Elf_Internal_Rela *rel_end;
1954 struct elf_or1k_link_hash_table *htab;
1955 bfd *dynobj;
1956 asection *sreloc = NULL;
1958 if (bfd_link_relocatable (info))
1959 return true;
1961 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1962 sym_hashes = elf_sym_hashes (abfd);
1964 htab = or1k_elf_hash_table (info);
1965 if (htab == NULL)
1966 return false;
1968 dynobj = htab->root.dynobj;
1970 rel_end = relocs + sec->reloc_count;
1971 for (rel = relocs; rel < rel_end; rel++)
1973 struct elf_link_hash_entry *h;
1974 unsigned long r_symndx;
1975 unsigned char tls_type;
1976 int r_type;
1978 r_symndx = ELF32_R_SYM (rel->r_info);
1979 if (r_symndx < symtab_hdr->sh_info)
1980 h = NULL;
1981 else
1983 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1984 while (h->root.type == bfd_link_hash_indirect
1985 || h->root.type == bfd_link_hash_warning)
1986 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1989 r_type = ELF32_R_TYPE (rel->r_info);
1990 switch (r_type)
1992 case R_OR1K_TLS_GD_HI16:
1993 case R_OR1K_TLS_GD_LO16:
1994 case R_OR1K_TLS_GD_PG21:
1995 case R_OR1K_TLS_GD_LO13:
1996 tls_type = TLS_GD;
1997 break;
1998 case R_OR1K_TLS_LDM_HI16:
1999 case R_OR1K_TLS_LDM_LO16:
2000 case R_OR1K_TLS_LDM_PG21:
2001 case R_OR1K_TLS_LDM_LO13:
2002 case R_OR1K_TLS_LDO_HI16:
2003 case R_OR1K_TLS_LDO_LO16:
2004 tls_type = TLS_LD;
2005 break;
2006 case R_OR1K_TLS_IE_HI16:
2007 case R_OR1K_TLS_IE_LO16:
2008 case R_OR1K_TLS_IE_PG21:
2009 case R_OR1K_TLS_IE_LO13:
2010 case R_OR1K_TLS_IE_AHI16:
2011 tls_type = TLS_IE;
2012 break;
2013 case R_OR1K_TLS_LE_HI16:
2014 case R_OR1K_TLS_LE_LO16:
2015 case R_OR1K_TLS_LE_AHI16:
2016 case R_OR1K_TLS_LE_SLO16:
2017 tls_type = TLS_LE;
2018 break;
2019 default:
2020 tls_type = TLS_NONE;
2023 /* Record TLS type. */
2024 if (h != NULL)
2025 ((struct elf_or1k_link_hash_entry *) h)->tls_type |= tls_type;
2026 else
2028 unsigned char *local_tls_type;
2030 /* This is a TLS type record for a local symbol. */
2031 local_tls_type = (unsigned char *) elf_or1k_local_tls_type (abfd);
2032 if (local_tls_type == NULL)
2034 bfd_size_type size;
2036 size = symtab_hdr->sh_info;
2037 local_tls_type = bfd_zalloc (abfd, size);
2038 if (local_tls_type == NULL)
2039 return false;
2040 elf_or1k_local_tls_type (abfd) = local_tls_type;
2042 local_tls_type[r_symndx] |= tls_type;
2045 switch (r_type)
2047 /* This relocation describes the C++ object vtable hierarchy.
2048 Reconstruct it for later use during GC. */
2049 case R_OR1K_GNU_VTINHERIT:
2050 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2051 return false;
2052 break;
2054 /* This relocation describes which C++ vtable entries are actually
2055 used. Record for later use during GC. */
2056 case R_OR1K_GNU_VTENTRY:
2057 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2058 return false;
2059 break;
2061 /* This relocation requires .plt entry. */
2062 case R_OR1K_PLTA26:
2063 htab->saw_plta = true;
2064 /* FALLTHRU */
2065 case R_OR1K_PLT26:
2066 if (h != NULL)
2068 h->needs_plt = 1;
2069 h->plt.refcount += 1;
2071 break;
2073 case R_OR1K_GOT_AHI16:
2074 case R_OR1K_GOT16:
2075 case R_OR1K_GOT_PG21:
2076 case R_OR1K_GOT_LO13:
2077 case R_OR1K_TLS_GD_HI16:
2078 case R_OR1K_TLS_GD_LO16:
2079 case R_OR1K_TLS_GD_PG21:
2080 case R_OR1K_TLS_GD_LO13:
2081 case R_OR1K_TLS_IE_HI16:
2082 case R_OR1K_TLS_IE_LO16:
2083 case R_OR1K_TLS_IE_PG21:
2084 case R_OR1K_TLS_IE_LO13:
2085 case R_OR1K_TLS_IE_AHI16:
2086 if (h != NULL)
2087 h->got.refcount += 1;
2088 else
2090 bfd_signed_vma *local_got_refcounts;
2092 /* This is a global offset table entry for a local symbol. */
2093 local_got_refcounts = elf_local_got_refcounts (abfd);
2094 if (local_got_refcounts == NULL)
2096 bfd_size_type size;
2098 size = symtab_hdr->sh_info;
2099 size *= sizeof (bfd_signed_vma);
2100 local_got_refcounts = bfd_zalloc (abfd, size);
2101 if (local_got_refcounts == NULL)
2102 return false;
2103 elf_local_got_refcounts (abfd) = local_got_refcounts;
2105 local_got_refcounts[r_symndx] += 1;
2107 /* FALLTHRU */
2109 case R_OR1K_GOTOFF_HI16:
2110 case R_OR1K_GOTOFF_LO16:
2111 case R_OR1K_GOTOFF_AHI16:
2112 case R_OR1K_GOTOFF_SLO16:
2113 if (htab->root.sgot == NULL)
2115 if (dynobj == NULL)
2116 htab->root.dynobj = dynobj = abfd;
2117 if (!_bfd_elf_create_got_section (dynobj, info))
2118 return false;
2120 break;
2122 case R_OR1K_INSN_REL_26:
2123 case R_OR1K_HI_16_IN_INSN:
2124 case R_OR1K_LO_16_IN_INSN:
2125 case R_OR1K_AHI16:
2126 case R_OR1K_SLO16:
2127 case R_OR1K_32:
2128 case R_OR1K_PCREL_PG21:
2129 case R_OR1K_LO13:
2130 case R_OR1K_SLO13:
2132 if (h != NULL && !bfd_link_pic (info))
2134 /* We may need a copy reloc. */
2135 h->non_got_ref = 1;
2137 /* We may also need a .plt entry. */
2138 h->plt.refcount += 1;
2139 if (r_type != R_OR1K_INSN_REL_26)
2140 h->pointer_equality_needed = 1;
2143 /* If we are creating a shared library, and this is a reloc
2144 against a global symbol, or a non PC relative reloc
2145 against a local symbol, then we need to copy the reloc
2146 into the shared library. However, if we are linking with
2147 -Bsymbolic, we do not need to copy a reloc against a
2148 global symbol which is defined in an object we are
2149 including in the link (i.e., DEF_REGULAR is set). At
2150 this point we have not seen all the input files, so it is
2151 possible that DEF_REGULAR is not set now but will be set
2152 later (it is never cleared). In case of a weak definition,
2153 DEF_REGULAR may be cleared later by a strong definition in
2154 a shared library. We account for that possibility below by
2155 storing information in the relocs_copied field of the hash
2156 table entry. A similar situation occurs when creating
2157 shared libraries and symbol visibility changes render the
2158 symbol local.
2160 If on the other hand, we are creating an executable, we
2161 may need to keep relocations for symbols satisfied by a
2162 dynamic library if we manage to avoid copy relocs for the
2163 symbol. */
2165 if ((bfd_link_pic (info)
2166 && (sec->flags & SEC_ALLOC) != 0
2167 && (r_type != R_OR1K_INSN_REL_26
2168 || (h != NULL
2169 && (!SYMBOLIC_BIND (info, h)
2170 || h->root.type == bfd_link_hash_defweak
2171 || !h->def_regular))))
2172 || (!bfd_link_pic (info)
2173 && (sec->flags & SEC_ALLOC) != 0
2174 && h != NULL
2175 && (h->root.type == bfd_link_hash_defweak
2176 || !h->def_regular)))
2178 struct elf_dyn_relocs *sec_relocs;
2179 struct elf_dyn_relocs **head;
2181 /* When creating a shared object, we must copy these
2182 relocs into the output file. We create a reloc
2183 section in dynobj and make room for the reloc. */
2184 if (sreloc == NULL)
2186 const char *name;
2187 unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
2188 unsigned int shnam = _bfd_elf_single_rel_hdr (sec)->sh_name;
2190 name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
2191 if (name == NULL)
2192 return false;
2194 if (!startswith (name, ".rela")
2195 || strcmp (bfd_section_name (sec), name + 5) != 0)
2197 _bfd_error_handler
2198 /* xgettext:c-format */
2199 (_("%pB: bad relocation section name `%s\'"),
2200 abfd, name);
2203 if (htab->root.dynobj == NULL)
2204 htab->root.dynobj = abfd;
2205 dynobj = htab->root.dynobj;
2207 sreloc = bfd_get_section_by_name (dynobj, name);
2208 if (sreloc == NULL)
2210 sreloc = _bfd_elf_make_dynamic_reloc_section
2211 (sec, dynobj, 2, abfd, /*rela?*/ true);
2213 if (sreloc == NULL)
2214 return false;
2216 elf_section_data (sec)->sreloc = sreloc;
2219 /* If this is a global symbol, we count the number of
2220 relocations we need for this symbol. */
2221 if (h != NULL)
2222 head = &h->dyn_relocs;
2223 else
2225 /* Track dynamic relocs needed for local syms too.
2226 We really need local syms available to do this
2227 easily. Oh well. */
2229 asection *s;
2230 Elf_Internal_Sym *isym;
2231 void *vpp;
2233 isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
2234 abfd, r_symndx);
2235 if (isym == NULL)
2236 return false;
2238 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2239 if (s == NULL)
2240 return false;
2242 vpp = &elf_section_data (s)->local_dynrel;
2243 head = (struct elf_dyn_relocs **) vpp;
2246 sec_relocs = *head;
2247 /* Allocate this sections dynamic reolcations structure if this
2248 is a new section. */
2249 if (sec_relocs == NULL || sec_relocs->sec != sec)
2251 size_t amt = sizeof *sec_relocs;
2252 sec_relocs = ((struct elf_dyn_relocs *)
2253 bfd_alloc (htab->root.dynobj, amt));
2254 if (sec_relocs == NULL)
2255 return false;
2256 sec_relocs->next = *head;
2257 *head = sec_relocs;
2258 sec_relocs->sec = sec;
2259 sec_relocs->count = 0;
2260 sec_relocs->pc_count = 0;
2263 sec_relocs->count += 1;
2264 if (r_type == R_OR1K_INSN_REL_26)
2265 sec_relocs->pc_count += 1;
2268 break;
2272 return true;
2275 static void
2276 or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
2277 unsigned insns[], size_t insn_count)
2279 unsigned nodelay = elf_elfheader (output_bfd)->e_flags & EF_OR1K_NODELAY;
2280 unsigned output_insns[PLT_MAX_INSN_COUNT];
2282 /* Copy instructions into the output buffer. */
2283 for (size_t i = 0; i < insn_count; i++)
2284 output_insns[i] = insns[i];
2286 /* Honor the no-delay-slot setting. */
2287 if (insns[insn_count-1] == OR1K_NOP)
2289 unsigned slot1, slot2;
2291 if (nodelay)
2292 slot1 = insns[insn_count-2], slot2 = insnj;
2293 else
2294 slot1 = insnj, slot2 = insns[insn_count-2];
2296 output_insns[insn_count-2] = slot1;
2297 output_insns[insn_count-1] = slot2;
2298 output_insns[insn_count] = OR1K_NOP;
2300 else
2302 unsigned slot1, slot2;
2304 if (nodelay)
2305 slot1 = insns[insn_count-1], slot2 = insnj;
2306 else
2307 slot1 = insnj, slot2 = insns[insn_count-1];
2309 output_insns[insn_count-1] = slot1;
2310 output_insns[insn_count] = slot2;
2313 /* Write out the output buffer. */
2314 for (size_t i = 0; i < (insn_count+1); i++)
2315 bfd_put_32 (output_bfd, output_insns[i], contents + (i*4));
2318 /* Finish up the dynamic sections. */
2320 static bool
2321 or1k_elf_finish_dynamic_sections (bfd *output_bfd,
2322 struct bfd_link_info *info)
2324 bfd *dynobj;
2325 asection *sdyn, *sgot;
2326 struct elf_or1k_link_hash_table *htab;
2328 htab = or1k_elf_hash_table (info);
2329 if (htab == NULL)
2330 return false;
2332 dynobj = htab->root.dynobj;
2334 sgot = htab->root.sgotplt;
2335 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2337 if (htab->root.dynamic_sections_created)
2339 asection *splt;
2340 Elf32_External_Dyn *dyncon, *dynconend;
2342 BFD_ASSERT (sgot != NULL && sdyn != NULL);
2344 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2345 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
2347 for (; dyncon < dynconend; dyncon++)
2349 Elf_Internal_Dyn dyn;
2350 asection *s;
2352 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2354 switch (dyn.d_tag)
2356 default:
2357 continue;
2359 case DT_PLTGOT:
2360 s = htab->root.sgotplt;
2361 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2362 break;
2364 case DT_JMPREL:
2365 s = htab->root.srelplt;
2366 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2367 break;
2369 case DT_PLTRELSZ:
2370 s = htab->root.srelplt;
2371 dyn.d_un.d_val = s->size;
2372 break;
2374 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2378 /* Fill in the first entry in the procedure linkage table. */
2379 splt = htab->root.splt;
2380 if (splt && splt->size > 0)
2382 unsigned plt[PLT_MAX_INSN_COUNT];
2383 size_t plt_insn_count = 3;
2384 bfd_vma got_addr = sgot->output_section->vma + sgot->output_offset;
2386 /* Note we force 16 byte alignment on the .got, so that
2387 the movhi/adrp can be shared between the two loads. */
2389 if (htab->saw_plta)
2391 bfd_vma pc = splt->output_section->vma + splt->output_offset;
2392 unsigned pa = ((got_addr >> 13) - (pc >> 13)) & 0x1fffff;
2393 unsigned po = got_addr & 0x1fff;
2394 plt[0] = OR1K_ADRP(12) | pa;
2395 plt[1] = OR1K_LWZ(15,12) | (po + 8);
2396 plt[2] = OR1K_LWZ(12,12) | (po + 4);
2398 else if (bfd_link_pic (info))
2400 plt[0] = OR1K_LWZ(15, 16) | 8; /* .got+8 */
2401 plt[1] = OR1K_LWZ(12, 16) | 4; /* .got+4 */
2402 plt[2] = OR1K_NOP;
2404 else
2406 unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
2407 unsigned lo = got_addr & 0xffff;
2408 plt[0] = OR1K_MOVHI(12) | ha;
2409 plt[1] = OR1K_LWZ(15,12) | (lo + 8);
2410 plt[2] = OR1K_LWZ(12,12) | (lo + 4);
2413 or1k_write_plt_entry (output_bfd, splt->contents, OR1K_JR(15),
2414 plt, plt_insn_count);
2416 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
2420 /* Set the first entry in the global offset table to the address of
2421 the dynamic section. */
2422 if (sgot && sgot->size > 0)
2424 if (sdyn == NULL)
2425 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2426 else
2427 bfd_put_32 (output_bfd,
2428 sdyn->output_section->vma + sdyn->output_offset,
2429 sgot->contents);
2430 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2433 if (htab->root.sgot && htab->root.sgot->size > 0)
2434 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize = 4;
2436 return true;
2439 /* Finish up dynamic symbol handling. We set the contents of various
2440 dynamic sections here. */
2442 static bool
2443 or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
2444 struct bfd_link_info *info,
2445 struct elf_link_hash_entry *h,
2446 Elf_Internal_Sym *sym)
2448 struct elf_or1k_link_hash_table *htab;
2449 bfd_byte *loc;
2451 htab = or1k_elf_hash_table (info);
2453 if (h->plt.offset != (bfd_vma) -1)
2455 unsigned int plt[PLT_MAX_INSN_COUNT];
2456 size_t plt_insn_count = 3;
2457 asection *splt;
2458 asection *sgot;
2459 asection *srela;
2460 bfd_vma plt_base_addr;
2461 bfd_vma plt_addr;
2462 bfd_vma plt_index;
2463 bfd_vma plt_reloc;
2464 bfd_vma got_base_addr;
2465 bfd_vma got_offset;
2466 bfd_vma got_addr;
2467 Elf_Internal_Rela rela;
2468 bool large_plt_entry;
2470 /* This symbol has an entry in the procedure linkage table. Set
2471 it up. */
2472 BFD_ASSERT (h->dynindx != -1);
2474 splt = htab->root.splt;
2475 sgot = htab->root.sgotplt;
2476 srela = htab->root.srelplt;
2477 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
2479 plt_base_addr = splt->output_section->vma + splt->output_offset;
2480 got_base_addr = sgot->output_section->vma + sgot->output_offset;
2482 /* Get the index in the procedure linkage table which
2483 corresponds to this symbol. This is the index of this symbol
2484 in all the symbols for which we are making plt entries. The
2485 first entry in the procedure linkage table is reserved. */
2486 plt_index = ((struct elf_or1k_link_hash_entry *) h)->plt_index;
2487 plt_addr = plt_base_addr + h->plt.offset;
2488 plt_reloc = plt_index * sizeof (Elf32_External_Rela);
2490 large_plt_entry = (elf_or1k_plt_entry_size (plt_index)
2491 == PLT_ENTRY_SIZE_LARGE);
2493 /* Get the offset into the .got table of the entry that
2494 corresponds to this function. Each .got entry is 4 bytes.
2495 The first three are reserved. */
2496 got_offset = (plt_index + 3) * 4;
2497 got_addr = got_base_addr + got_offset;
2499 /* Fill in the entry in the procedure linkage table. */
2500 if (htab->saw_plta)
2502 unsigned pa = ((got_addr >> 13) - (plt_addr >> 13)) & 0x1fffff;
2503 unsigned po = (got_addr & 0x1fff);
2504 plt[0] = OR1K_ADRP(12) | pa;
2505 plt[1] = OR1K_LWZ(12,12) | po;
2506 plt[2] = OR1K_ORI0(11) | plt_reloc;
2508 else if (bfd_link_pic (info))
2510 if (large_plt_entry)
2512 unsigned gotha = ((got_offset + 0x8000) >> 16) & 0xffff;
2513 unsigned got = got_offset & 0xffff;
2514 unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
2515 unsigned pltrello = plt_reloc & 0xffff;
2517 plt[0] = OR1K_MOVHI(12) | gotha;
2518 plt[1] = OR1K_ADD(12,12,16);
2519 plt[2] = OR1K_LWZ(12,12) | got;
2520 plt[3] = OR1K_MOVHI(11) | pltrelhi;
2521 plt[4] = OR1K_ORI(11,11) | pltrello;
2522 plt_insn_count = 5;
2524 else
2526 plt[0] = OR1K_LWZ(12,16) | got_offset;
2527 plt[1] = OR1K_ORI0(11) | plt_reloc;
2528 plt[2] = OR1K_NOP;
2531 else
2533 unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
2534 unsigned lo = got_addr & 0xffff;
2535 plt[0] = OR1K_MOVHI(12) | ha;
2536 plt[1] = OR1K_LWZ(12,12) | lo;
2537 plt[2] = OR1K_ORI0(11) | plt_reloc;
2540 /* For large code model we fixup the non-PIC PLT relocation instructions
2541 here. */
2542 if (large_plt_entry && !bfd_link_pic (info))
2544 unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
2545 unsigned pltrello = plt_reloc & 0xffff;
2547 plt[2] = OR1K_MOVHI(11) | pltrelhi;
2548 plt[3] = OR1K_ORI(11,11) | pltrello;
2549 plt[4] = OR1K_NOP;
2550 plt_insn_count = 5;
2553 or1k_write_plt_entry (output_bfd, splt->contents + h->plt.offset,
2554 OR1K_JR(12), plt, plt_insn_count);
2556 /* Fill in the entry in the global offset table. We initialize it to
2557 point to the top of the plt. This is done to lazy lookup the actual
2558 symbol as the first plt entry will be setup by libc to call the
2559 runtime dynamic linker. */
2560 bfd_put_32 (output_bfd, plt_base_addr, sgot->contents + got_offset);
2562 /* Fill in the entry in the .rela.plt section. */
2563 rela.r_offset = got_addr;
2564 rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_JMP_SLOT);
2565 rela.r_addend = 0;
2566 loc = srela->contents;
2567 loc += plt_index * sizeof (Elf32_External_Rela);
2568 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2570 if (!h->def_regular)
2572 /* Mark the symbol as undefined, rather than as defined in
2573 the .plt section. Leave the value alone. */
2574 sym->st_shndx = SHN_UNDEF;
2578 if (h->got.offset != (bfd_vma) -1
2579 && (h->got.offset & 2) == 0) /* Homemade TLS check. */
2581 asection *sgot;
2582 asection *srelgot;
2583 Elf_Internal_Rela rela;
2585 /* This symbol has an entry in the global offset table. Set it
2586 up. */
2587 sgot = htab->root.sgot;
2588 srelgot = htab->root.srelgot;
2589 BFD_ASSERT (sgot != NULL && srelgot != NULL);
2591 rela.r_offset = (sgot->output_section->vma
2592 + sgot->output_offset
2593 + (h->got.offset &~ 1));
2595 /* If this is a -Bsymbolic link, and the symbol is defined
2596 locally, we just want to emit a RELATIVE reloc. Likewise if
2597 the symbol was forced to be local because of a version file.
2598 The entry in the global offset table will already have been
2599 initialized in the relocate_section function. */
2600 if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
2602 rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
2603 rela.r_addend = (h->root.u.def.value
2604 + h->root.u.def.section->output_section->vma
2605 + h->root.u.def.section->output_offset);
2607 else
2609 BFD_ASSERT ((h->got.offset & 1) == 0);
2610 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
2611 rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_GLOB_DAT);
2612 rela.r_addend = 0;
2615 loc = srelgot->contents;
2616 loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
2617 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2618 ++srelgot->reloc_count;
2621 if (h->needs_copy)
2623 asection *s;
2624 Elf_Internal_Rela rela;
2626 /* This symbols needs a copy reloc. Set it up. */
2627 BFD_ASSERT (h->dynindx != -1
2628 && (h->root.type == bfd_link_hash_defined
2629 || h->root.type == bfd_link_hash_defweak));
2631 rela.r_offset = (h->root.u.def.value
2632 + h->root.u.def.section->output_section->vma
2633 + h->root.u.def.section->output_offset);
2634 rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
2635 rela.r_addend = 0;
2636 if (h->root.u.def.section == htab->root.sdynrelro)
2637 s = htab->root.sreldynrelro;
2638 else
2639 s = htab->root.srelbss;
2640 loc = s->contents + s->reloc_count * sizeof (Elf32_External_Rela);
2641 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2642 ++s->reloc_count;
2645 /* Mark some specially defined symbols as absolute. */
2646 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2647 || h == htab->root.hgot)
2648 sym->st_shndx = SHN_ABS;
2650 return true;
2653 static enum elf_reloc_type_class
2654 or1k_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
2655 const asection *rel_sec ATTRIBUTE_UNUSED,
2656 const Elf_Internal_Rela *rela)
2658 switch ((int) ELF32_R_TYPE (rela->r_info))
2660 case R_OR1K_RELATIVE: return reloc_class_relative;
2661 case R_OR1K_JMP_SLOT: return reloc_class_plt;
2662 case R_OR1K_COPY: return reloc_class_copy;
2663 default: return reloc_class_normal;
2667 /* Adjust a symbol defined by a dynamic object and referenced by a
2668 regular object. The current definition is in some section of the
2669 dynamic object, but we're not including those sections. We have to
2670 change the definition to something the rest of the link can
2671 understand. */
2673 static bool
2674 or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2675 struct elf_link_hash_entry *h)
2677 struct elf_or1k_link_hash_table *htab;
2678 bfd *dynobj;
2679 asection *s, *srel;
2681 dynobj = elf_hash_table (info)->dynobj;
2683 /* Make sure we know what is going on here. */
2684 BFD_ASSERT (dynobj != NULL
2685 && (h->needs_plt
2686 || h->is_weakalias
2687 || (h->def_dynamic
2688 && h->ref_regular
2689 && !h->def_regular)));
2691 /* If this is a function, put it in the procedure linkage table. We
2692 will fill in the contents of the procedure linkage table later,
2693 when we know the address of the .got section. */
2694 if (h->type == STT_FUNC
2695 || h->needs_plt)
2697 if (h->plt.refcount <= 0
2698 || (SYMBOL_CALLS_LOCAL (info, h)
2699 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2700 && h->root.type == bfd_link_hash_undefweak)))
2702 /* This case can occur if we saw a PLT reloc in an input
2703 file, but the symbol was never referred to by a dynamic
2704 object. In such a case, we don't actually need to build
2705 a procedure linkage table, and we can just do a PCREL
2706 reloc instead. */
2707 h->plt.offset = (bfd_vma) -1;
2708 h->needs_plt = 0;
2711 return true;
2713 else
2714 h->plt.offset = (bfd_vma) -1;
2716 /* If this is a weak symbol, and there is a real definition, the
2717 processor independent code will have arranged for us to see the
2718 real definition first, and we can just use the same value. */
2719 if (h->is_weakalias)
2721 struct elf_link_hash_entry *def = weakdef (h);
2722 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2723 h->root.u.def.section = def->root.u.def.section;
2724 h->root.u.def.value = def->root.u.def.value;
2725 return true;
2728 /* This is a reference to a symbol defined by a dynamic object which
2729 is not a function. */
2731 /* If we are creating a shared library, we must presume that the
2732 only references to the symbol are via the global offset table.
2733 For such cases we need not do anything here; the relocations will
2734 be handled correctly by relocate_section. */
2735 if (bfd_link_pic (info))
2736 return true;
2738 /* If there are no references to this symbol that do not use the
2739 GOT, we don't need to generate a copy reloc. */
2740 if (!h->non_got_ref)
2741 return true;
2743 /* If -z nocopyreloc was given, we won't generate them either. */
2744 if (info->nocopyreloc)
2746 h->non_got_ref = 0;
2747 return true;
2750 /* If we don't find any dynamic relocs in read-only sections, then
2751 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2752 if (!_bfd_elf_readonly_dynrelocs (h))
2754 h->non_got_ref = 0;
2755 return true;
2758 /* We must allocate the symbol in our .dynbss section, which will
2759 become part of the .bss section of the executable. There will be
2760 an entry for this symbol in the .dynsym section. The dynamic
2761 object will contain position independent code, so all references
2762 from the dynamic object to this symbol will go through the global
2763 offset table. The dynamic linker will use the .dynsym entry to
2764 determine the address it must put in the global offset table, so
2765 both the dynamic object and the regular object will refer to the
2766 same memory location for the variable. */
2768 htab = or1k_elf_hash_table (info);
2769 if (htab == NULL)
2770 return false;
2772 /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
2773 to copy the initial value out of the dynamic object and into the
2774 runtime process image. We need to remember the offset into the
2775 .rela.bss section we are going to use. */
2776 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2778 s = htab->root.sdynrelro;
2779 srel = htab->root.sreldynrelro;
2781 else
2783 s = htab->root.sdynbss;
2784 srel = htab->root.srelbss;
2786 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2788 srel->size += sizeof (Elf32_External_Rela);
2789 h->needs_copy = 1;
2792 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2795 /* Caclulate an update the sizes required for a symbol in the GOT and
2796 RELA relocation section based on the TLS_TYPE and whether or not the symbol
2797 is DYNAMIC.
2799 Symbols with TLS_GD access require 8 bytes in the GOT and, if dynamic,
2800 require two relocation entries. Symbols with TLS_IE access require 4 bytes
2801 in the GOT and, if dynamic, require one relocation entry. Symbols may have
2802 both TLS_GD and TLS_IE access to be accounted for.
2804 Other symbols require 4 bytes in the GOT table and, if dynamic, require one
2805 relocation entry. */
2807 static void
2808 or1k_set_got_and_rela_sizes (const unsigned char tls_type,
2809 const bool dynamic,
2810 bfd_vma *got_size,
2811 bfd_vma *rela_size)
2813 bool is_tls_entry = false;
2815 /* TLS GD requires two GOT entries and two relocs. */
2816 if ((tls_type & TLS_GD) != 0)
2818 *got_size += 8;
2819 is_tls_entry = true;
2822 if ((tls_type & TLS_IE) != 0)
2824 *got_size += 4;
2825 is_tls_entry = true;
2828 if (!is_tls_entry)
2829 *got_size += 4;
2831 if (dynamic)
2833 if ((tls_type & TLS_GD) != 0)
2834 *rela_size += 2 * sizeof (Elf32_External_Rela);
2836 if ((tls_type & TLS_IE) != 0)
2837 *rela_size += sizeof (Elf32_External_Rela);
2839 if (!is_tls_entry)
2840 *rela_size += sizeof (Elf32_External_Rela);
2845 /* Allocate space in .plt, .got and associated reloc sections for
2846 dynamic relocs. */
2848 static bool
2849 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2851 struct bfd_link_info *info;
2852 struct elf_or1k_link_hash_table *htab;
2853 struct elf_dyn_relocs *sec_relocs;
2855 if (h->root.type == bfd_link_hash_indirect)
2856 return true;
2858 info = (struct bfd_link_info *) inf;
2859 htab = or1k_elf_hash_table (info);
2860 if (htab == NULL)
2861 return false;
2863 if (htab->root.dynamic_sections_created
2864 && h->plt.refcount > 0)
2866 /* Make sure this symbol is output as a dynamic symbol.
2867 Undefined weak syms won't yet be marked as dynamic. */
2868 if (h->dynindx == -1
2869 && !h->forced_local)
2871 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2872 return false;
2875 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
2877 asection *splt = htab->root.splt;
2878 bfd_vma plt_index;
2880 /* Track the index of our plt entry for use in calculating size. */
2881 plt_index = htab->plt_count++;
2882 ((struct elf_or1k_link_hash_entry *) h)->plt_index = plt_index;
2884 /* If this is the first .plt entry, make room for the special
2885 first entry. */
2886 if (splt->size == 0)
2887 splt->size = elf_or1k_plt_entry_size (plt_index);
2889 h->plt.offset = splt->size;
2891 /* If this symbol is not defined in a regular file, and we are
2892 not generating a shared library, then set the symbol to this
2893 location in the .plt. This is required to make function
2894 pointers compare as equal between the normal executable and
2895 the shared library. */
2896 if (! bfd_link_pic (info)
2897 && !h->def_regular)
2899 h->root.u.def.section = splt;
2900 h->root.u.def.value = h->plt.offset;
2903 /* Make room for this entry. */
2904 splt->size += elf_or1k_plt_entry_size (plt_index);
2906 /* We also need to make an entry in the .got.plt section, which
2907 will be placed in the .got section by the linker script. */
2908 htab->root.sgotplt->size += 4;
2910 /* We also need to make an entry in the .rel.plt section. */
2911 htab->root.srelplt->size += sizeof (Elf32_External_Rela);
2913 else
2915 h->plt.offset = (bfd_vma) -1;
2916 h->needs_plt = 0;
2919 else
2921 h->plt.offset = (bfd_vma) -1;
2922 h->needs_plt = 0;
2925 if (h->got.refcount > 0)
2927 asection *sgot;
2928 bool dyn;
2929 unsigned char tls_type;
2931 /* Make sure this symbol is output as a dynamic symbol.
2932 Undefined weak syms won't yet be marked as dynamic. */
2933 if (h->dynindx == -1
2934 && !h->forced_local)
2936 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2937 return false;
2940 sgot = htab->root.sgot;
2942 h->got.offset = sgot->size;
2944 tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
2946 dyn = htab->root.dynamic_sections_created;
2947 dyn = WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h);
2948 or1k_set_got_and_rela_sizes (tls_type, dyn,
2949 &sgot->size, &htab->root.srelgot->size);
2951 else
2952 h->got.offset = (bfd_vma) -1;
2954 if (h->dyn_relocs == NULL)
2955 return true;
2957 /* In the shared -Bsymbolic case, discard space allocated for
2958 dynamic pc-relative relocs against symbols which turn out to be
2959 defined in regular objects. For the normal shared case, discard
2960 space for pc-relative relocs that have become local due to symbol
2961 visibility changes. */
2963 if (bfd_link_pic (info))
2965 if (SYMBOL_CALLS_LOCAL (info, h))
2967 struct elf_dyn_relocs **pp;
2969 for (pp = &h->dyn_relocs; (sec_relocs = *pp) != NULL;)
2971 sec_relocs->count -= sec_relocs->pc_count;
2972 sec_relocs->pc_count = 0;
2973 if (sec_relocs->count == 0)
2974 *pp = sec_relocs->next;
2975 else
2976 pp = &sec_relocs->next;
2980 /* Also discard relocs on undefined weak syms with non-default
2981 visibility. */
2982 if (h->dyn_relocs != NULL
2983 && h->root.type == bfd_link_hash_undefweak)
2985 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2986 h->dyn_relocs = NULL;
2988 /* Make sure undefined weak symbols are output as a dynamic
2989 symbol in PIEs. */
2990 else if (h->dynindx == -1
2991 && !h->forced_local)
2993 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2994 return false;
2998 else
3000 /* For the non-shared case, discard space for relocs against
3001 symbols which turn out to need copy relocs or are not
3002 dynamic. */
3004 if (!h->non_got_ref
3005 && ((h->def_dynamic
3006 && !h->def_regular)
3007 || (htab->root.dynamic_sections_created
3008 && (h->root.type == bfd_link_hash_undefweak
3009 || h->root.type == bfd_link_hash_undefined))))
3011 /* Make sure this symbol is output as a dynamic symbol.
3012 Undefined weak syms won't yet be marked as dynamic. */
3013 if (h->dynindx == -1
3014 && !h->forced_local)
3016 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3017 return false;
3020 /* If that succeeded, we know we'll be keeping all the
3021 relocs. */
3022 if (h->dynindx != -1)
3023 goto keep;
3026 h->dyn_relocs = NULL;
3028 keep: ;
3031 /* Finally, allocate space. */
3032 for (sec_relocs = h->dyn_relocs;
3033 sec_relocs != NULL;
3034 sec_relocs = sec_relocs->next)
3036 asection *sreloc = elf_section_data (sec_relocs->sec)->sreloc;
3037 sreloc->size += sec_relocs->count * sizeof (Elf32_External_Rela);
3040 return true;
3043 /* Set the sizes of the dynamic sections. */
3045 static bool
3046 or1k_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3047 struct bfd_link_info *info)
3049 struct elf_or1k_link_hash_table *htab;
3050 bfd *dynobj;
3051 asection *s;
3052 bool relocs;
3053 bfd *ibfd;
3055 htab = or1k_elf_hash_table (info);
3056 if (htab == NULL)
3057 return false;
3059 dynobj = htab->root.dynobj;
3060 if (dynobj == NULL)
3061 return true;
3063 if (htab->root.dynamic_sections_created)
3065 /* Set the contents of the .interp section to the interpreter. */
3066 if (bfd_link_executable (info) && !info->nointerp)
3068 s = bfd_get_section_by_name (dynobj, ".interp");
3069 BFD_ASSERT (s != NULL);
3070 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3071 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3072 s->alloced = 1;
3076 /* Set up .got offsets for local syms, and space for local dynamic
3077 relocs. */
3078 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3080 bfd_signed_vma *local_got;
3081 bfd_signed_vma *end_local_got;
3082 bfd_size_type locsymcount;
3083 Elf_Internal_Shdr *symtab_hdr;
3084 unsigned char *local_tls_type;
3085 asection *srel;
3087 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3088 continue;
3090 for (s = ibfd->sections; s != NULL; s = s->next)
3092 struct elf_dyn_relocs *sec_relocs;
3094 for (sec_relocs = ((struct elf_dyn_relocs *)
3095 elf_section_data (s)->local_dynrel);
3096 sec_relocs != NULL;
3097 sec_relocs = sec_relocs->next)
3099 if (! bfd_is_abs_section (sec_relocs->sec)
3100 && bfd_is_abs_section (sec_relocs->sec->output_section))
3102 /* Input section has been discarded, either because
3103 it is a copy of a linkonce section or due to
3104 linker script /DISCARD/, so we'll be discarding
3105 the relocs too. */
3107 else if (sec_relocs->count != 0)
3109 srel = elf_section_data (sec_relocs->sec)->sreloc;
3110 srel->size += sec_relocs->count
3111 * sizeof (Elf32_External_Rela);
3112 if ((sec_relocs->sec->output_section->flags & SEC_READONLY)
3113 != 0)
3114 info->flags |= DF_TEXTREL;
3119 local_got = elf_local_got_refcounts (ibfd);
3120 if (!local_got)
3121 continue;
3123 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3124 locsymcount = symtab_hdr->sh_info;
3125 end_local_got = local_got + locsymcount;
3126 s = htab->root.sgot;
3127 srel = htab->root.srelgot;
3128 local_tls_type = (unsigned char *) elf_or1k_local_tls_type (ibfd);
3129 for (; local_got < end_local_got; ++local_got)
3131 if (*local_got > 0)
3133 unsigned char tls_type = (local_tls_type == NULL)
3134 ? TLS_UNKNOWN
3135 : *local_tls_type;
3137 *local_got = s->size;
3138 or1k_set_got_and_rela_sizes (tls_type, bfd_link_pic (info),
3139 &s->size, &srel->size);
3141 else
3143 *local_got = (bfd_vma) -1;
3145 if (local_tls_type)
3146 ++local_tls_type;
3150 /* Allocate global sym .plt and .got entries, and space for global
3151 sym dynamic relocs. */
3152 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
3154 /* We now have determined the sizes of the various dynamic sections.
3155 Allocate memory for them. */
3156 relocs = false;
3157 for (s = dynobj->sections; s != NULL; s = s->next)
3159 if ((s->flags & SEC_LINKER_CREATED) == 0)
3160 continue;
3162 if (s == htab->root.splt
3163 || s == htab->root.sgot
3164 || s == htab->root.sgotplt
3165 || s == htab->root.sdynbss
3166 || s == htab->root.sdynrelro)
3168 /* Strip this section if we don't need it; see the
3169 comment below. */
3171 else if (startswith (bfd_section_name (s), ".rela"))
3173 if (s->size != 0 && s != htab->root.srelplt)
3174 relocs = true;
3176 /* We use the reloc_count field as a counter if we need
3177 to copy relocs into the output file. */
3178 s->reloc_count = 0;
3180 else
3181 /* It's not one of our sections, so don't allocate space. */
3182 continue;
3184 if (s->size == 0)
3186 /* If we don't need this section, strip it from the
3187 output file. This is mostly to handle .rela.bss and
3188 .rela.plt. We must create both sections in
3189 create_dynamic_sections, because they must be created
3190 before the linker maps input sections to output
3191 sections. The linker does that before
3192 adjust_dynamic_symbol is called, and it is that
3193 function which decides whether anything needs to go
3194 into these sections. */
3195 s->flags |= SEC_EXCLUDE;
3196 continue;
3199 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3200 continue;
3202 /* Allocate memory for the section contents. We use bfd_zalloc
3203 here in case unused entries are not reclaimed before the
3204 section's contents are written out. This should not happen,
3205 but this way if it does, we get a R_OR1K_NONE reloc instead
3206 of garbage. */
3207 s->contents = bfd_zalloc (dynobj, s->size);
3208 if (s->contents == NULL)
3209 return false;
3210 s->alloced = 1;
3213 return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
3216 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3218 static void
3219 or1k_elf_copy_indirect_symbol (struct bfd_link_info *info,
3220 struct elf_link_hash_entry *dir,
3221 struct elf_link_hash_entry *ind)
3223 struct elf_or1k_link_hash_entry * edir;
3224 struct elf_or1k_link_hash_entry * eind;
3226 edir = (struct elf_or1k_link_hash_entry *) dir;
3227 eind = (struct elf_or1k_link_hash_entry *) ind;
3229 if (ind->root.type == bfd_link_hash_indirect)
3231 if (dir->got.refcount <= 0)
3233 edir->tls_type = eind->tls_type;
3234 eind->tls_type = TLS_UNKNOWN;
3238 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3241 /* Set the right machine number. */
3243 static bool
3244 or1k_elf_object_p (bfd *abfd)
3246 unsigned long mach = bfd_mach_or1k;
3248 if (elf_elfheader (abfd)->e_flags & EF_OR1K_NODELAY)
3249 mach = bfd_mach_or1knd;
3251 return bfd_default_set_arch_mach (abfd, bfd_arch_or1k, mach);
3254 /* Store the machine number in the flags field. */
3256 static bool
3257 or1k_elf_final_write_processing (bfd *abfd)
3259 switch (bfd_get_mach (abfd))
3261 default:
3262 case bfd_mach_or1k:
3263 break;
3264 case bfd_mach_or1knd:
3265 elf_elfheader (abfd)->e_flags |= EF_OR1K_NODELAY;
3266 break;
3268 return _bfd_elf_final_write_processing (abfd);
3271 static bool
3272 or1k_elf_set_private_flags (bfd *abfd, flagword flags)
3274 BFD_ASSERT (!elf_flags_init (abfd)
3275 || elf_elfheader (abfd)->e_flags == flags);
3277 elf_elfheader (abfd)->e_flags = flags;
3278 elf_flags_init (abfd) = true;
3279 return true;
3282 /* Make sure all input files are consistent with respect to
3283 EF_OR1K_NODELAY flag setting. */
3285 static bool
3286 elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
3288 bfd *obfd = info->output_bfd;
3289 flagword out_flags;
3290 flagword in_flags;
3292 in_flags = elf_elfheader (ibfd)->e_flags;
3293 out_flags = elf_elfheader (obfd)->e_flags;
3295 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3296 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3297 return true;
3299 if (!elf_flags_init (obfd))
3301 elf_flags_init (obfd) = true;
3302 elf_elfheader (obfd)->e_flags = in_flags;
3304 return true;
3307 if (in_flags == out_flags)
3308 return true;
3310 if ((in_flags & EF_OR1K_NODELAY) != (out_flags & EF_OR1K_NODELAY))
3312 _bfd_error_handler
3313 (_("%pB: %s flag mismatch with previous modules"),
3314 ibfd, "EF_OR1K_NODELAY");
3316 bfd_set_error (bfd_error_bad_value);
3317 return false;
3320 return true;
3324 /* Implement elf_backend_grok_prstatus:
3325 Support for core dump NOTE sections. */
3326 static bool
3327 or1k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3329 int offset;
3330 size_t size;
3332 switch (note->descsz)
3334 default:
3335 return false;
3337 case 212: /* Linux/OpenRISC */
3338 /* pr_cursig */
3339 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
3341 /* pr_pid */
3342 elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
3344 /* pr_reg */
3345 offset = 72;
3346 size = 132;
3348 break;
3351 /* Make a ".reg/999" section. */
3352 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
3353 size, note->descpos + offset);
3356 /* Implement elf_backend_grok_psinfo. */
3357 static bool
3358 or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3360 switch (note->descsz)
3362 default:
3363 return false;
3365 case 128: /* Linux/OpenRISC elf_prpsinfo */
3366 elf_tdata (abfd)->core->program
3367 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
3368 elf_tdata (abfd)->core->command
3369 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
3372 return true;
3376 #define ELF_ARCH bfd_arch_or1k
3377 #define ELF_MACHINE_CODE EM_OR1K
3378 #define ELF_TARGET_ID OR1K_ELF_DATA
3379 #define ELF_MAXPAGESIZE 0x2000
3381 #define TARGET_BIG_SYM or1k_elf32_vec
3382 #define TARGET_BIG_NAME "elf32-or1k"
3384 #define elf_info_to_howto_rel NULL
3385 #define elf_info_to_howto or1k_info_to_howto_rela
3386 #define elf_backend_relocate_section or1k_elf_relocate_section
3387 #define elf_backend_gc_mark_hook or1k_elf_gc_mark_hook
3388 #define elf_backend_check_relocs or1k_elf_check_relocs
3389 #define elf_backend_reloc_type_class or1k_elf_reloc_type_class
3390 #define elf_backend_can_gc_sections 1
3391 #define elf_backend_rela_normal 1
3393 #define bfd_elf32_mkobject elf_or1k_mkobject
3395 #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
3396 #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
3397 #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
3398 #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
3400 #define elf_backend_object_p or1k_elf_object_p
3401 #define elf_backend_final_write_processing or1k_elf_final_write_processing
3402 #define elf_backend_can_refcount 1
3404 #define elf_backend_plt_readonly 1
3405 #define elf_backend_want_got_plt 1
3406 #define elf_backend_want_plt_sym 0
3407 #define elf_backend_got_header_size 12
3408 #define elf_backend_dtrel_excludes_plt 1
3409 #define elf_backend_want_dynrelro 1
3411 #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create
3412 #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol
3413 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3414 #define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
3415 #define elf_backend_late_size_sections or1k_elf_late_size_sections
3416 #define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
3417 #define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
3419 #define elf_backend_grok_prstatus or1k_grok_prstatus
3420 #define elf_backend_grok_psinfo or1k_grok_psinfo
3422 #include "elf32-target.h"