1 /* MMIX-specific support for 64-bit ELF.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson <hp@bitrange.com>
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* No specific ABI or "processor-specific supplement" defined. */
25 - On-demand register allocation (from R_MMIX_BASE_PLUS_OFFSET). */
32 #include "opcode/mmix.h"
34 #define MINUS_ONE (((bfd_vma) 0) - 1)
36 /* Put these everywhere in new code. */
38 _bfd_abort (__FILE__, __LINE__, \
39 "Internal: Non-debugged code (test-case missing)")
42 _bfd_abort (__FILE__, __LINE__, \
45 static boolean mmix_elf_link_output_symbol_hook
46 PARAMS ((bfd
*, struct bfd_link_info
*, const char *,
47 Elf_Internal_Sym
*, asection
*));
49 static bfd_reloc_status_type mmix_elf_reloc
50 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
52 static reloc_howto_type
*bfd_elf64_bfd_reloc_type_lookup
53 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
55 static void mmix_info_to_howto_rela
56 PARAMS ((bfd
*, arelent
*, Elf64_Internal_Rela
*));
58 static int mmix_elf_sort_relocs
PARAMS ((const PTR
, const PTR
));
60 static boolean mmix_elf_check_relocs
61 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
62 const Elf_Internal_Rela
*));
64 static boolean mmix_elf_relocate_section
65 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
66 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
68 static asection
* mmix_elf_gc_mark_hook
69 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
70 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
72 static bfd_reloc_status_type mmix_final_link_relocate
73 PARAMS ((reloc_howto_type
*, asection
*, bfd_byte
*,
74 bfd_vma
, bfd_signed_vma
, bfd_vma
, const char *, asection
*));
76 static bfd_reloc_status_type mmix_elf_perform_relocation
77 PARAMS ((asection
*, reloc_howto_type
*, PTR
, bfd_vma
, bfd_vma
));
79 static boolean mmix_elf_section_from_bfd_section
80 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*, int *));
82 static boolean mmix_elf_add_symbol_hook
83 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
84 const char **, flagword
*, asection
**, bfd_vma
*));
86 static boolean mmix_elf_is_local_label_name
87 PARAMS ((bfd
*, const char *));
89 extern boolean mmix_elf_final_link
PARAMS ((bfd
*, struct bfd_link_info
*));
91 extern void mmix_elf_symbol_processing
PARAMS ((bfd
*, asymbol
*));
93 /* Watch out: this currently needs to have elements with the same index as
94 their R_MMIX_ number. */
95 static reloc_howto_type elf_mmix_howto_table
[] =
97 /* This reloc does nothing. */
98 HOWTO (R_MMIX_NONE
, /* type */
100 2, /* size (0 = byte, 1 = short, 2 = long) */
102 false, /* pc_relative */
104 complain_overflow_bitfield
, /* complain_on_overflow */
105 bfd_elf_generic_reloc
, /* special_function */
106 "R_MMIX_NONE", /* name */
107 false, /* partial_inplace */
110 false), /* pcrel_offset */
112 /* An 8 bit absolute relocation. */
113 HOWTO (R_MMIX_8
, /* type */
115 0, /* size (0 = byte, 1 = short, 2 = long) */
117 false, /* pc_relative */
119 complain_overflow_bitfield
, /* complain_on_overflow */
120 bfd_elf_generic_reloc
, /* special_function */
121 "R_MMIX_8", /* name */
122 false, /* partial_inplace */
125 false), /* pcrel_offset */
127 /* An 16 bit absolute relocation. */
128 HOWTO (R_MMIX_16
, /* type */
130 1, /* size (0 = byte, 1 = short, 2 = long) */
132 false, /* pc_relative */
134 complain_overflow_bitfield
, /* complain_on_overflow */
135 bfd_elf_generic_reloc
, /* special_function */
136 "R_MMIX_16", /* name */
137 false, /* partial_inplace */
138 0xffff, /* src_mask */
139 0xffff, /* dst_mask */
140 false), /* pcrel_offset */
142 /* An 24 bit absolute relocation. */
143 HOWTO (R_MMIX_24
, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 false, /* pc_relative */
149 complain_overflow_bitfield
, /* complain_on_overflow */
150 bfd_elf_generic_reloc
, /* special_function */
151 "R_MMIX_24", /* name */
152 false, /* partial_inplace */
153 0xffffff, /* src_mask */
154 0xffffff, /* dst_mask */
155 false), /* pcrel_offset */
157 /* A 32 bit absolute relocation. */
158 HOWTO (R_MMIX_32
, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 false, /* pc_relative */
164 complain_overflow_bitfield
, /* complain_on_overflow */
165 bfd_elf_generic_reloc
, /* special_function */
166 "R_MMIX_32", /* name */
167 false, /* partial_inplace */
168 0xffffffff, /* src_mask */
169 0xffffffff, /* dst_mask */
170 false), /* pcrel_offset */
172 /* 64 bit relocation. */
173 HOWTO (R_MMIX_64
, /* type */
175 4, /* size (0 = byte, 1 = short, 2 = long) */
177 false, /* pc_relative */
179 complain_overflow_bitfield
, /* complain_on_overflow */
180 bfd_elf_generic_reloc
, /* special_function */
181 "R_MMIX_64", /* name */
182 false, /* partial_inplace */
183 MINUS_ONE
, /* src_mask */
184 MINUS_ONE
, /* dst_mask */
185 false), /* pcrel_offset */
187 /* An 8 bit PC-relative relocation. */
188 HOWTO (R_MMIX_PC_8
, /* type */
190 0, /* size (0 = byte, 1 = short, 2 = long) */
192 true, /* pc_relative */
194 complain_overflow_bitfield
, /* complain_on_overflow */
195 bfd_elf_generic_reloc
, /* special_function */
196 "R_MMIX_PC_8", /* name */
197 false, /* partial_inplace */
200 true), /* pcrel_offset */
202 /* An 16 bit PC-relative relocation. */
203 HOWTO (R_MMIX_PC_16
, /* type */
205 1, /* size (0 = byte, 1 = short, 2 = long) */
207 true, /* pc_relative */
209 complain_overflow_bitfield
, /* complain_on_overflow */
210 bfd_elf_generic_reloc
, /* special_function */
211 "R_MMIX_PC_16", /* name */
212 false, /* partial_inplace */
213 0xffff, /* src_mask */
214 0xffff, /* dst_mask */
215 true), /* pcrel_offset */
217 /* An 24 bit PC-relative relocation. */
218 HOWTO (R_MMIX_PC_24
, /* type */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 true, /* pc_relative */
224 complain_overflow_bitfield
, /* complain_on_overflow */
225 bfd_elf_generic_reloc
, /* special_function */
226 "R_MMIX_PC_24", /* name */
227 false, /* partial_inplace */
228 0xffffff, /* src_mask */
229 0xffffff, /* dst_mask */
230 true), /* pcrel_offset */
232 /* A 32 bit absolute PC-relative relocation. */
233 HOWTO (R_MMIX_PC_32
, /* type */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 true, /* pc_relative */
239 complain_overflow_bitfield
, /* complain_on_overflow */
240 bfd_elf_generic_reloc
, /* special_function */
241 "R_MMIX_PC_32", /* name */
242 false, /* partial_inplace */
243 0xffffffff, /* src_mask */
244 0xffffffff, /* dst_mask */
245 true), /* pcrel_offset */
247 /* 64 bit PC-relative relocation. */
248 HOWTO (R_MMIX_PC_64
, /* type */
250 4, /* size (0 = byte, 1 = short, 2 = long) */
252 true, /* pc_relative */
254 complain_overflow_bitfield
, /* complain_on_overflow */
255 bfd_elf_generic_reloc
, /* special_function */
256 "R_MMIX_PC_64", /* name */
257 false, /* partial_inplace */
258 MINUS_ONE
, /* src_mask */
259 MINUS_ONE
, /* dst_mask */
260 true), /* pcrel_offset */
262 /* GNU extension to record C++ vtable hierarchy. */
263 HOWTO (R_MMIX_GNU_VTINHERIT
, /* type */
265 0, /* size (0 = byte, 1 = short, 2 = long) */
267 false, /* pc_relative */
269 complain_overflow_dont
, /* complain_on_overflow */
270 NULL
, /* special_function */
271 "R_MMIX_GNU_VTINHERIT", /* name */
272 false, /* partial_inplace */
275 true), /* pcrel_offset */
277 /* GNU extension to record C++ vtable member usage. */
278 HOWTO (R_MMIX_GNU_VTENTRY
, /* type */
280 0, /* size (0 = byte, 1 = short, 2 = long) */
282 false, /* pc_relative */
284 complain_overflow_dont
, /* complain_on_overflow */
285 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
286 "R_MMIX_GNU_VTENTRY", /* name */
287 false, /* partial_inplace */
290 false), /* pcrel_offset */
292 /* The GETA relocation is supposed to get any address that could
293 possibly be reached by the GETA instruction. It can silently expand
294 to get a 64-bit operand, but will complain if any of the two least
295 significant bits are set. The howto members reflect a simple GETA. */
296 HOWTO (R_MMIX_GETA
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 true, /* pc_relative */
302 complain_overflow_signed
, /* complain_on_overflow */
303 mmix_elf_reloc
, /* special_function */
304 "R_MMIX_GETA", /* name */
305 false, /* partial_inplace */
306 0x0100ffff, /* src_mask */
307 0x0100ffff, /* dst_mask */
308 true), /* pcrel_offset */
310 HOWTO (R_MMIX_GETA_1
, /* type */
312 2, /* size (0 = byte, 1 = short, 2 = long) */
314 true, /* pc_relative */
316 complain_overflow_signed
, /* complain_on_overflow */
317 mmix_elf_reloc
, /* special_function */
318 "R_MMIX_GETA_1", /* name */
319 false, /* partial_inplace */
320 0x0100ffff, /* src_mask */
321 0x0100ffff, /* dst_mask */
322 true), /* pcrel_offset */
324 HOWTO (R_MMIX_GETA_2
, /* type */
326 2, /* size (0 = byte, 1 = short, 2 = long) */
328 true, /* pc_relative */
330 complain_overflow_signed
, /* complain_on_overflow */
331 mmix_elf_reloc
, /* special_function */
332 "R_MMIX_GETA_2", /* name */
333 false, /* partial_inplace */
334 0x0100ffff, /* src_mask */
335 0x0100ffff, /* dst_mask */
336 true), /* pcrel_offset */
338 HOWTO (R_MMIX_GETA_3
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 true, /* pc_relative */
344 complain_overflow_signed
, /* complain_on_overflow */
345 mmix_elf_reloc
, /* special_function */
346 "R_MMIX_GETA_3", /* name */
347 false, /* partial_inplace */
348 0x0100ffff, /* src_mask */
349 0x0100ffff, /* dst_mask */
350 true), /* pcrel_offset */
352 /* The conditional branches are supposed to reach any (code) address.
353 It can silently expand to a 64-bit operand, but will emit an error if
354 any of the two least significant bits are set. The howto members
355 reflect a simple branch. */
356 HOWTO (R_MMIX_CBRANCH
, /* type */
358 2, /* size (0 = byte, 1 = short, 2 = long) */
360 true, /* pc_relative */
362 complain_overflow_signed
, /* complain_on_overflow */
363 mmix_elf_reloc
, /* special_function */
364 "R_MMIX_CBRANCH", /* name */
365 false, /* partial_inplace */
366 0x0100ffff, /* src_mask */
367 0x0100ffff, /* dst_mask */
368 true), /* pcrel_offset */
370 HOWTO (R_MMIX_CBRANCH_J
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 true, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 mmix_elf_reloc
, /* special_function */
378 "R_MMIX_CBRANCH_J", /* name */
379 false, /* partial_inplace */
380 0x0100ffff, /* src_mask */
381 0x0100ffff, /* dst_mask */
382 true), /* pcrel_offset */
384 HOWTO (R_MMIX_CBRANCH_1
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 true, /* pc_relative */
390 complain_overflow_signed
, /* complain_on_overflow */
391 mmix_elf_reloc
, /* special_function */
392 "R_MMIX_CBRANCH_1", /* name */
393 false, /* partial_inplace */
394 0x0100ffff, /* src_mask */
395 0x0100ffff, /* dst_mask */
396 true), /* pcrel_offset */
398 HOWTO (R_MMIX_CBRANCH_2
, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 true, /* pc_relative */
404 complain_overflow_signed
, /* complain_on_overflow */
405 mmix_elf_reloc
, /* special_function */
406 "R_MMIX_CBRANCH_2", /* name */
407 false, /* partial_inplace */
408 0x0100ffff, /* src_mask */
409 0x0100ffff, /* dst_mask */
410 true), /* pcrel_offset */
412 HOWTO (R_MMIX_CBRANCH_3
, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 true, /* pc_relative */
418 complain_overflow_signed
, /* complain_on_overflow */
419 mmix_elf_reloc
, /* special_function */
420 "R_MMIX_CBRANCH_3", /* name */
421 false, /* partial_inplace */
422 0x0100ffff, /* src_mask */
423 0x0100ffff, /* dst_mask */
424 true), /* pcrel_offset */
426 /* The PUSHJ instruction can reach any (code) address, as long as it's
427 the beginning of a function (no usable restriction). It can silently
428 expand to a 64-bit operand, but will emit an error if any of the two
429 least significant bits are set. The howto members reflect a simple
431 HOWTO (R_MMIX_PUSHJ
, /* type */
433 2, /* size (0 = byte, 1 = short, 2 = long) */
435 true, /* pc_relative */
437 complain_overflow_signed
, /* complain_on_overflow */
438 mmix_elf_reloc
, /* special_function */
439 "R_MMIX_PUSHJ", /* name */
440 false, /* partial_inplace */
441 0x0100ffff, /* src_mask */
442 0x0100ffff, /* dst_mask */
443 true), /* pcrel_offset */
445 HOWTO (R_MMIX_PUSHJ_1
, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 true, /* pc_relative */
451 complain_overflow_signed
, /* complain_on_overflow */
452 mmix_elf_reloc
, /* special_function */
453 "R_MMIX_PUSHJ_1", /* name */
454 false, /* partial_inplace */
455 0x0100ffff, /* src_mask */
456 0x0100ffff, /* dst_mask */
457 true), /* pcrel_offset */
459 HOWTO (R_MMIX_PUSHJ_2
, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 true, /* pc_relative */
465 complain_overflow_signed
, /* complain_on_overflow */
466 mmix_elf_reloc
, /* special_function */
467 "R_MMIX_PUSHJ_2", /* name */
468 false, /* partial_inplace */
469 0x0100ffff, /* src_mask */
470 0x0100ffff, /* dst_mask */
471 true), /* pcrel_offset */
473 HOWTO (R_MMIX_PUSHJ_3
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 true, /* pc_relative */
479 complain_overflow_signed
, /* complain_on_overflow */
480 mmix_elf_reloc
, /* special_function */
481 "R_MMIX_PUSHJ_3", /* name */
482 false, /* partial_inplace */
483 0x0100ffff, /* src_mask */
484 0x0100ffff, /* dst_mask */
485 true), /* pcrel_offset */
487 /* A JMP is supposed to reach any (code) address. By itself, it can
488 reach +-64M; the expansion can reach all 64 bits. Note that the 64M
489 limit is soon reached if you link the program in wildly different
490 memory segments. The howto members reflect a trivial JMP. */
491 HOWTO (R_MMIX_JMP
, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 true, /* pc_relative */
497 complain_overflow_signed
, /* complain_on_overflow */
498 mmix_elf_reloc
, /* special_function */
499 "R_MMIX_JMP", /* name */
500 false, /* partial_inplace */
501 0x1ffffff, /* src_mask */
502 0x1ffffff, /* dst_mask */
503 true), /* pcrel_offset */
505 HOWTO (R_MMIX_JMP_1
, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 true, /* pc_relative */
511 complain_overflow_signed
, /* complain_on_overflow */
512 mmix_elf_reloc
, /* special_function */
513 "R_MMIX_JMP_1", /* name */
514 false, /* partial_inplace */
515 0x1ffffff, /* src_mask */
516 0x1ffffff, /* dst_mask */
517 true), /* pcrel_offset */
519 HOWTO (R_MMIX_JMP_2
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 true, /* pc_relative */
525 complain_overflow_signed
, /* complain_on_overflow */
526 mmix_elf_reloc
, /* special_function */
527 "R_MMIX_JMP_2", /* name */
528 false, /* partial_inplace */
529 0x1ffffff, /* src_mask */
530 0x1ffffff, /* dst_mask */
531 true), /* pcrel_offset */
533 HOWTO (R_MMIX_JMP_3
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 true, /* pc_relative */
539 complain_overflow_signed
, /* complain_on_overflow */
540 mmix_elf_reloc
, /* special_function */
541 "R_MMIX_JMP_3", /* name */
542 false, /* partial_inplace */
543 0x1ffffff, /* src_mask */
544 0x1ffffff, /* dst_mask */
545 true), /* pcrel_offset */
547 /* When we don't emit link-time-relaxable code from the assembler, or
548 when relaxation has done all it can do, these relocs are used. For
549 GETA/PUSHJ/branches. */
550 HOWTO (R_MMIX_ADDR19
, /* type */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 true, /* pc_relative */
556 complain_overflow_signed
, /* complain_on_overflow */
557 mmix_elf_reloc
, /* special_function */
558 "R_MMIX_ADDR19", /* name */
559 false, /* partial_inplace */
560 0x0100ffff, /* src_mask */
561 0x0100ffff, /* dst_mask */
562 true), /* pcrel_offset */
565 HOWTO (R_MMIX_ADDR27
, /* type */
567 2, /* size (0 = byte, 1 = short, 2 = long) */
569 true, /* pc_relative */
571 complain_overflow_signed
, /* complain_on_overflow */
572 mmix_elf_reloc
, /* special_function */
573 "R_MMIX_ADDR27", /* name */
574 false, /* partial_inplace */
575 0x1ffffff, /* src_mask */
576 0x1ffffff, /* dst_mask */
577 true), /* pcrel_offset */
579 /* A general register or the value 0..255. If a value, then the
580 instruction (offset -3) needs adjusting. */
581 HOWTO (R_MMIX_REG_OR_BYTE
, /* type */
583 1, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_bitfield
, /* complain_on_overflow */
588 mmix_elf_reloc
, /* special_function */
589 "R_MMIX_REG_OR_BYTE", /* name */
590 false, /* partial_inplace */
593 false), /* pcrel_offset */
595 /* A general register. */
596 HOWTO (R_MMIX_REG
, /* type */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
600 false, /* pc_relative */
602 complain_overflow_bitfield
, /* complain_on_overflow */
603 mmix_elf_reloc
, /* special_function */
604 "R_MMIX_REG", /* name */
605 false, /* partial_inplace */
608 false), /* pcrel_offset */
610 /* A register plus an index, corresponding to the relocation expression.
611 The sizes must correspond to the valid range of the expression, while
612 the bitmasks correspond to what we store in the image. */
613 HOWTO (R_MMIX_BASE_PLUS_OFFSET
, /* type */
615 4, /* size (0 = byte, 1 = short, 2 = long) */
617 false, /* pc_relative */
619 complain_overflow_bitfield
, /* complain_on_overflow */
620 mmix_elf_reloc
, /* special_function */
621 "R_MMIX_BASE_PLUS_OFFSET", /* name */
622 false, /* partial_inplace */
623 0xffff, /* src_mask */
624 0xffff, /* dst_mask */
625 false), /* pcrel_offset */
627 /* A "magic" relocation for a LOCAL expression, asserting that the
628 expression is less than the number of global registers. No actual
629 modification of the contents is done. Implementing this as a
630 relocation was less intrusive than e.g. putting such expressions in a
631 section to discard *after* relocation. */
632 HOWTO (R_MMIX_LOCAL
, /* type */
634 0, /* size (0 = byte, 1 = short, 2 = long) */
636 false, /* pc_relative */
638 complain_overflow_dont
, /* complain_on_overflow */
639 mmix_elf_reloc
, /* special_function */
640 "R_MMIX_LOCAL", /* name */
641 false, /* partial_inplace */
644 false), /* pcrel_offset */
648 /* Map BFD reloc types to MMIX ELF reloc types. */
650 struct mmix_reloc_map
652 bfd_reloc_code_real_type bfd_reloc_val
;
653 enum elf_mmix_reloc_type elf_reloc_val
;
657 static const struct mmix_reloc_map mmix_reloc_map
[] =
659 {BFD_RELOC_NONE
, R_MMIX_NONE
},
660 {BFD_RELOC_8
, R_MMIX_8
},
661 {BFD_RELOC_16
, R_MMIX_16
},
662 {BFD_RELOC_24
, R_MMIX_24
},
663 {BFD_RELOC_32
, R_MMIX_32
},
664 {BFD_RELOC_64
, R_MMIX_64
},
665 {BFD_RELOC_8_PCREL
, R_MMIX_PC_8
},
666 {BFD_RELOC_16_PCREL
, R_MMIX_PC_16
},
667 {BFD_RELOC_24_PCREL
, R_MMIX_PC_24
},
668 {BFD_RELOC_32_PCREL
, R_MMIX_PC_32
},
669 {BFD_RELOC_64_PCREL
, R_MMIX_PC_64
},
670 {BFD_RELOC_VTABLE_INHERIT
, R_MMIX_GNU_VTINHERIT
},
671 {BFD_RELOC_VTABLE_ENTRY
, R_MMIX_GNU_VTENTRY
},
672 {BFD_RELOC_MMIX_GETA
, R_MMIX_GETA
},
673 {BFD_RELOC_MMIX_CBRANCH
, R_MMIX_CBRANCH
},
674 {BFD_RELOC_MMIX_PUSHJ
, R_MMIX_PUSHJ
},
675 {BFD_RELOC_MMIX_JMP
, R_MMIX_JMP
},
676 {BFD_RELOC_MMIX_ADDR19
, R_MMIX_ADDR19
},
677 {BFD_RELOC_MMIX_ADDR27
, R_MMIX_ADDR27
},
678 {BFD_RELOC_MMIX_REG_OR_BYTE
, R_MMIX_REG_OR_BYTE
},
679 {BFD_RELOC_MMIX_REG
, R_MMIX_REG
},
680 {BFD_RELOC_MMIX_BASE_PLUS_OFFSET
, R_MMIX_BASE_PLUS_OFFSET
},
681 {BFD_RELOC_MMIX_LOCAL
, R_MMIX_LOCAL
}
684 static reloc_howto_type
*
685 bfd_elf64_bfd_reloc_type_lookup (abfd
, code
)
686 bfd
*abfd ATTRIBUTE_UNUSED
;
687 bfd_reloc_code_real_type code
;
692 i
< sizeof (mmix_reloc_map
) / sizeof (mmix_reloc_map
[0]);
695 if (mmix_reloc_map
[i
].bfd_reloc_val
== code
)
696 return &elf_mmix_howto_table
[mmix_reloc_map
[i
].elf_reloc_val
];
703 /* This function performs the actual bitfiddling and sanity check for a
704 final relocation. Each relocation gets its *worst*-case expansion
705 in size when it arrives here; any reduction in size should have been
706 caught in linker relaxation earlier. When we get here, the relocation
707 looks like the smallest instruction with SWYM:s (nop:s) appended to the
708 max size. We fill in those nop:s.
710 R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
714 INCML $N,(foo >> 16) & 0xffff
715 INCMH $N,(foo >> 32) & 0xffff
716 INCH $N,(foo >> 48) & 0xffff
718 R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
719 condbranches needing relaxation might be rare enough to not be
730 R_MMIX_PUSHJ: (FIXME: Relaxation...)
739 R_MMIX_JMP: (FIXME: Relaxation...)
748 R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
750 static bfd_reloc_status_type
751 mmix_elf_perform_relocation (isec
, howto
, datap
, addr
, value
)
753 reloc_howto_type
*howto
;
755 bfd_vma addr ATTRIBUTE_UNUSED
;
758 bfd
*abfd
= isec
->owner
;
759 bfd_reloc_status_type flag
= bfd_reloc_ok
;
760 bfd_reloc_status_type r
;
764 /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
765 We handle the differences here and the common sequence later. */
770 reg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
772 /* We change to an absolute value. */
778 int in1
= bfd_get_16 (abfd
, (bfd_byte
*) datap
) << 16;
780 /* Invert the condition and prediction bit, and set the offset
781 to five instructions ahead.
783 We *can* do better if we want to. If the branch is found to be
784 within limits, we could leave the branch as is; there'll just
785 be a bunch of NOP:s after it. But we shouldn't see this
786 sequence often enough that it's worth doing it. */
789 (((in1
^ ((PRED_INV_BIT
| COND_INV_BIT
) << 24)) & ~0xffff)
793 /* Put a "GO $255,$255,0" after the common sequence. */
795 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24) | 0xffff00,
796 (bfd_byte
*) datap
+ 20);
798 /* Common sequence starts at offset 4. */
801 /* We change to an absolute value. */
808 int inreg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
810 /* Put a "PUSHGO $N,$255,0" after the common sequence. */
812 ((PUSHGO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
815 (bfd_byte
*) datap
+ 16);
817 /* We change to an absolute value. */
823 /* This one is a little special. If we get here on a non-relaxing
824 link, and the destination is actually in range, we don't need to
826 If so, we fall through to the bit-fiddling relocs.
828 FIXME: bfd_check_overflow seems broken; the relocation is
829 rightshifted before testing, so supply a zero rightshift. */
831 if (! ((value
& 3) == 0
832 && (r
= bfd_check_overflow (complain_overflow_signed
,
835 bfd_arch_bits_per_address (abfd
),
836 value
)) == bfd_reloc_ok
))
838 /* If the relocation doesn't fit in a JMP, we let the NOP:s be
839 modified below, and put a "GO $255,$255,0" after the
840 address-loading sequence. */
842 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
844 (bfd_byte
*) datap
+ 16);
846 /* We change to an absolute value. */
853 /* These must be in range, or else we emit an error. */
855 /* Note rightshift 0; see above. */
856 && (r
= bfd_check_overflow (complain_overflow_signed
,
859 bfd_arch_bits_per_address (abfd
),
860 value
)) == bfd_reloc_ok
)
863 = bfd_get_32 (abfd
, (bfd_byte
*) datap
);
866 if ((bfd_signed_vma
) value
< 0)
869 value
+= (1 << (howto
->bitsize
- 1));
877 (in1
& ~howto
->src_mask
)
879 | (value
& howto
->dst_mask
),
885 return bfd_reloc_overflow
;
887 case R_MMIX_REG_OR_BYTE
:
890 return bfd_reloc_overflow
;
891 bfd_put_8 (abfd
, value
, datap
);
895 BAD_CASE (howto
->type
);
898 /* This code adds the common SETL/INCML/INCMH/INCH worst-case
901 /* Lowest two bits must be 0. We return bfd_reloc_overflow for
902 everything that looks strange. */
904 flag
= bfd_reloc_overflow
;
907 (SETL_INSN_BYTE
<< 24) | (value
& 0xffff) | (reg
<< 16),
908 (bfd_byte
*) datap
+ offs
);
910 (INCML_INSN_BYTE
<< 24) | ((value
>> 16) & 0xffff) | (reg
<< 16),
911 (bfd_byte
*) datap
+ offs
+ 4);
913 (INCMH_INSN_BYTE
<< 24) | ((value
>> 32) & 0xffff) | (reg
<< 16),
914 (bfd_byte
*) datap
+ offs
+ 8);
916 (INCH_INSN_BYTE
<< 24) | ((value
>> 48) & 0xffff) | (reg
<< 16),
917 (bfd_byte
*) datap
+ offs
+ 12);
922 /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
925 mmix_info_to_howto_rela (abfd
, cache_ptr
, dst
)
926 bfd
*abfd ATTRIBUTE_UNUSED
;
928 Elf64_Internal_Rela
*dst
;
932 r_type
= ELF64_R_TYPE (dst
->r_info
);
933 BFD_ASSERT (r_type
< (unsigned int) R_MMIX_max
);
934 cache_ptr
->howto
= &elf_mmix_howto_table
[r_type
];
937 /* Any MMIX-specific relocation gets here at assembly time or when linking
938 to other formats (such as mmo); this is the relocation function from
939 the reloc_table. We don't get here for final pure ELF linking. */
941 static bfd_reloc_status_type
942 mmix_elf_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
943 output_bfd
, error_message
)
945 arelent
*reloc_entry
;
948 asection
*input_section
;
950 char **error_message ATTRIBUTE_UNUSED
;
953 bfd_reloc_status_type r
;
954 asection
*reloc_target_output_section
;
955 bfd_reloc_status_type flag
= bfd_reloc_ok
;
956 bfd_vma output_base
= 0;
959 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
960 input_section
, output_bfd
, error_message
);
962 /* If that was all that was needed (i.e. this isn't a final link, only
963 some segment adjustments), we're done. */
964 if (r
!= bfd_reloc_continue
)
967 if (bfd_is_und_section (symbol
->section
)
968 && (symbol
->flags
& BSF_WEAK
) == 0
969 && output_bfd
== (bfd
*) NULL
)
970 return bfd_reloc_undefined
;
972 /* Is the address of the relocation really within the section? */
973 if (reloc_entry
->address
> input_section
->_cooked_size
)
974 return bfd_reloc_outofrange
;
976 /* Work out which section the relocation is targetted at and the
977 initial relocation command value. */
979 /* Get symbol value. (Common symbols are special.) */
980 if (bfd_is_com_section (symbol
->section
))
983 relocation
= symbol
->value
;
985 reloc_target_output_section
= bfd_get_output_section (symbol
);
987 /* Here the variable relocation holds the final address of the symbol we
988 are relocating against, plus any addend. */
992 output_base
= reloc_target_output_section
->vma
;
994 relocation
+= output_base
+ symbol
->section
->output_offset
;
996 /* Get position of relocation. */
997 addr
= (reloc_entry
->address
+ input_section
->output_section
->vma
998 + input_section
->output_offset
);
999 if (output_bfd
!= (bfd
*) NULL
)
1001 /* Add in supplied addend. */
1002 relocation
+= reloc_entry
->addend
;
1004 /* This is a partial relocation, and we want to apply the
1005 relocation to the reloc entry rather than the raw data.
1006 Modify the reloc inplace to reflect what we now know. */
1007 reloc_entry
->addend
= relocation
;
1008 reloc_entry
->address
+= input_section
->output_offset
;
1012 return mmix_final_link_relocate (reloc_entry
->howto
, input_section
,
1013 data
, reloc_entry
->address
,
1014 reloc_entry
->addend
, relocation
,
1015 bfd_asymbol_name (symbol
),
1016 reloc_target_output_section
);
1019 /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
1020 for guidance if you're thinking of copying this. */
1023 mmix_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1024 contents
, relocs
, local_syms
, local_sections
)
1025 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1026 struct bfd_link_info
*info
;
1028 asection
*input_section
;
1030 Elf_Internal_Rela
*relocs
;
1031 Elf_Internal_Sym
*local_syms
;
1032 asection
**local_sections
;
1034 Elf_Internal_Shdr
*symtab_hdr
;
1035 struct elf_link_hash_entry
**sym_hashes
;
1036 Elf_Internal_Rela
*rel
;
1037 Elf_Internal_Rela
*relend
;
1039 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1040 sym_hashes
= elf_sym_hashes (input_bfd
);
1041 relend
= relocs
+ input_section
->reloc_count
;
1043 for (rel
= relocs
; rel
< relend
; rel
++)
1045 reloc_howto_type
*howto
;
1046 unsigned long r_symndx
;
1047 Elf_Internal_Sym
*sym
;
1049 struct elf_link_hash_entry
*h
;
1051 bfd_reloc_status_type r
;
1052 const char *name
= NULL
;
1054 boolean undefined_signalled
= false;
1056 r_type
= ELF64_R_TYPE (rel
->r_info
);
1058 if (r_type
== R_MMIX_GNU_VTINHERIT
1059 || r_type
== R_MMIX_GNU_VTENTRY
)
1062 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1064 if (info
->relocateable
)
1066 /* This is a relocateable link. We don't have to change
1067 anything, unless the reloc is against a section symbol,
1068 in which case we have to adjust according to where the
1069 section symbol winds up in the output section. */
1070 if (r_symndx
< symtab_hdr
->sh_info
)
1072 sym
= local_syms
+ r_symndx
;
1074 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1076 sec
= local_sections
[r_symndx
];
1077 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1084 /* This is a final link. */
1085 howto
= elf_mmix_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
1090 if (r_symndx
< symtab_hdr
->sh_info
)
1092 sym
= local_syms
+ r_symndx
;
1093 sec
= local_sections
[r_symndx
];
1094 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
1096 name
= bfd_elf_string_from_elf_section
1097 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
1098 name
= (name
== NULL
) ? bfd_section_name (input_bfd
, sec
) : name
;
1102 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1104 while (h
->root
.type
== bfd_link_hash_indirect
1105 || h
->root
.type
== bfd_link_hash_warning
)
1106 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1108 name
= h
->root
.root
.string
;
1110 if (h
->root
.type
== bfd_link_hash_defined
1111 || h
->root
.type
== bfd_link_hash_defweak
)
1113 sec
= h
->root
.u
.def
.section
;
1114 relocation
= (h
->root
.u
.def
.value
1115 + sec
->output_section
->vma
1116 + sec
->output_offset
);
1118 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1120 else if (info
->shared
1121 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1125 /* The test on undefined_signalled is redundant at the
1126 moment, but kept for symmetry. */
1127 if (! undefined_signalled
1128 && ! ((*info
->callbacks
->undefined_symbol
)
1129 (info
, h
->root
.root
.string
, input_bfd
,
1130 input_section
, rel
->r_offset
, true)))
1132 undefined_signalled
= true;
1137 r
= mmix_final_link_relocate (howto
, input_section
,
1138 contents
, rel
->r_offset
,
1139 rel
->r_addend
, relocation
, name
, sec
);
1141 if (r
!= bfd_reloc_ok
)
1143 boolean check_ok
= true;
1144 const char * msg
= (const char *) NULL
;
1148 case bfd_reloc_overflow
:
1149 check_ok
= info
->callbacks
->reloc_overflow
1150 (info
, name
, howto
->name
, (bfd_vma
) 0,
1151 input_bfd
, input_section
, rel
->r_offset
);
1154 case bfd_reloc_undefined
:
1155 /* We may have sent this message above. */
1156 if (! undefined_signalled
)
1157 check_ok
= info
->callbacks
->undefined_symbol
1158 (info
, name
, input_bfd
, input_section
, rel
->r_offset
,
1160 undefined_signalled
= true;
1163 case bfd_reloc_outofrange
:
1164 msg
= _("internal error: out of range error");
1167 case bfd_reloc_notsupported
:
1168 msg
= _("internal error: unsupported relocation error");
1171 case bfd_reloc_dangerous
:
1172 msg
= _("internal error: dangerous relocation");
1176 msg
= _("internal error: unknown error");
1181 check_ok
= info
->callbacks
->warning
1182 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
1192 /* Perform a single relocation. By default we use the standard BFD
1193 routines. A few relocs we have to do ourselves. */
1195 static bfd_reloc_status_type
1196 mmix_final_link_relocate (howto
, input_section
, contents
,
1197 r_offset
, r_addend
, relocation
, symname
, symsec
)
1198 reloc_howto_type
*howto
;
1199 asection
*input_section
;
1202 bfd_signed_vma r_addend
;
1204 const char *symname
;
1207 bfd_reloc_status_type r
= bfd_reloc_ok
;
1209 = (input_section
->output_section
->vma
1210 + input_section
->output_offset
1213 = (bfd_signed_vma
) relocation
+ r_addend
;
1215 switch (howto
->type
)
1217 /* All these are PC-relative. */
1219 case R_MMIX_CBRANCH
:
1224 contents
+= r_offset
;
1226 srel
-= (input_section
->output_section
->vma
1227 + input_section
->output_offset
1230 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1234 case R_MMIX_REG_OR_BYTE
:
1236 /* For now, we handle these alike. They must refer to an register
1237 symbol, which is either relative to the register section and in
1238 the range 0..255, or is in the register contents section with vma
1241 /* FIXME: A better way to check for reg contents section?
1242 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
1244 return bfd_reloc_undefined
;
1246 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1247 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1249 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1251 /* The bfd_reloc_outofrange return value, though intuitively
1252 a better value, will not get us an error. */
1253 return bfd_reloc_overflow
;
1257 else if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1258 MMIX_REG_SECTION_NAME
) == 0)
1260 if (srel
< 0 || srel
> 255)
1261 /* The bfd_reloc_outofrange return value, though intuitively a
1262 better value, will not get us an error. */
1263 return bfd_reloc_overflow
;
1267 (*_bfd_error_handler
)
1268 (_("%s: register relocation against non-register symbol: %s in %s"),
1269 bfd_get_filename (input_section
->owner
),
1270 symname
== NULL
|| *symname
== 0 ? _("(unknown)") : symname
,
1271 bfd_get_section_name (symsec
->owner
, symsec
));
1273 /* The bfd_reloc_outofrange return value, though intuitively a
1274 better value, will not get us an error. */
1275 return bfd_reloc_overflow
;
1277 contents
+= r_offset
;
1278 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1283 /* This isn't a real relocation, it's just an assertion that the
1284 final relocation value corresponds to a local register. We
1285 ignore the actual relocation; nothing is changed. */
1288 = bfd_get_section_by_name (input_section
->output_section
->owner
,
1289 MMIX_REG_CONTENTS_SECTION_NAME
);
1290 bfd_vma first_global
;
1292 /* Check that this is an absolute value, or a reference to the
1293 register contents section or the register (symbol) section.
1294 Absolute numbers can get here as undefined section. Undefined
1295 symbols are signalled elsewhere, so there's no conflict in us
1296 accidentally handling it. */
1297 if (!bfd_is_abs_section (symsec
)
1298 && !bfd_is_und_section (symsec
)
1299 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1300 MMIX_REG_CONTENTS_SECTION_NAME
) != 0
1301 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1302 MMIX_REG_SECTION_NAME
) != 0)
1304 (*_bfd_error_handler
)
1305 (_("%s: directive LOCAL valid only with a register or absolute value"),
1306 bfd_get_filename (input_section
->owner
));
1308 return bfd_reloc_overflow
;
1311 /* If we don't have a register contents section, then $255 is the
1312 first global register. */
1317 first_global
= bfd_get_section_vma (abfd
, regsec
) / 8;
1318 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1319 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1321 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1322 /* The bfd_reloc_outofrange return value, though
1323 intuitively a better value, will not get us an error. */
1324 return bfd_reloc_overflow
;
1329 if ((bfd_vma
) srel
>= first_global
)
1331 /* FIXME: Better error message. */
1332 (*_bfd_error_handler
)
1333 (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."),
1334 bfd_get_filename (input_section
->owner
), (long) srel
, (long) first_global
);
1336 return bfd_reloc_overflow
;
1343 r
= _bfd_final_link_relocate (howto
, input_section
->owner
, input_section
,
1345 relocation
, r_addend
);
1351 /* Return the section that should be marked against GC for a given
1355 mmix_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1357 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1358 Elf_Internal_Rela
*rel
;
1359 struct elf_link_hash_entry
*h
;
1360 Elf_Internal_Sym
*sym
;
1364 switch (ELF64_R_TYPE (rel
->r_info
))
1366 case R_MMIX_GNU_VTINHERIT
:
1367 case R_MMIX_GNU_VTENTRY
:
1371 switch (h
->root
.type
)
1373 case bfd_link_hash_defined
:
1374 case bfd_link_hash_defweak
:
1375 return h
->root
.u
.def
.section
;
1377 case bfd_link_hash_common
:
1378 return h
->root
.u
.c
.p
->section
;
1387 if (!(elf_bad_symtab (abfd
)
1388 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1389 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1390 && sym
->st_shndx
!= SHN_COMMON
))
1392 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1399 /* Sort register relocs to come before expanding relocs. */
1402 mmix_elf_sort_relocs (p1
, p2
)
1406 const Elf_Internal_Rela
*r1
= (const Elf_Internal_Rela
*) p1
;
1407 const Elf_Internal_Rela
*r2
= (const Elf_Internal_Rela
*) p2
;
1408 int r1_is_reg
, r2_is_reg
;
1410 /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1412 if ((r1
->r_offset
& ~(bfd_vma
) 3) > (r2
->r_offset
& ~(bfd_vma
) 3))
1414 else if ((r1
->r_offset
& ~(bfd_vma
) 3) < (r2
->r_offset
& ~(bfd_vma
) 3))
1418 = (ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG_OR_BYTE
1419 || ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG
);
1421 = (ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG_OR_BYTE
1422 || ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG
);
1423 if (r1_is_reg
!= r2_is_reg
)
1424 return r2_is_reg
- r1_is_reg
;
1426 /* Neither or both are register relocs. Then sort on full offset. */
1427 if (r1
->r_offset
> r2
->r_offset
)
1429 else if (r1
->r_offset
< r2
->r_offset
)
1434 /* Look through the relocs for a section during the first phase. */
1437 mmix_elf_check_relocs (abfd
, info
, sec
, relocs
)
1439 struct bfd_link_info
*info
;
1441 const Elf_Internal_Rela
*relocs
;
1443 Elf_Internal_Shdr
*symtab_hdr
;
1444 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1445 const Elf_Internal_Rela
*rel
;
1446 const Elf_Internal_Rela
*rel_end
;
1448 if (info
->relocateable
)
1451 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1452 sym_hashes
= elf_sym_hashes (abfd
);
1453 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf64_External_Sym
);
1454 if (!elf_bad_symtab (abfd
))
1455 sym_hashes_end
-= symtab_hdr
->sh_info
;
1457 /* First we sort the relocs so that any register relocs come before
1458 expansion-relocs to the same insn. FIXME: Not done for mmo. */
1459 qsort ((PTR
) relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
1460 mmix_elf_sort_relocs
);
1462 rel_end
= relocs
+ sec
->reloc_count
;
1463 for (rel
= relocs
; rel
< rel_end
; rel
++)
1465 struct elf_link_hash_entry
*h
;
1466 unsigned long r_symndx
;
1468 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1469 if (r_symndx
< symtab_hdr
->sh_info
)
1472 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1474 switch (ELF64_R_TYPE (rel
->r_info
))
1476 /* This relocation describes the C++ object vtable hierarchy.
1477 Reconstruct it for later use during GC. */
1478 case R_MMIX_GNU_VTINHERIT
:
1479 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1483 /* This relocation describes which C++ vtable entries are actually
1484 used. Record for later use during GC. */
1485 case R_MMIX_GNU_VTENTRY
:
1486 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1495 /* Change symbols relative to the reg contents section to instead be to
1496 the register section, and scale them down to correspond to the register
1500 mmix_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
1501 bfd
*abfd ATTRIBUTE_UNUSED
;
1502 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1503 const char *name ATTRIBUTE_UNUSED
;
1504 Elf_Internal_Sym
*sym
;
1505 asection
*input_sec
;
1507 if (input_sec
!= NULL
1508 && input_sec
->name
!= NULL
1509 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
1510 && strcmp (input_sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1513 sym
->st_shndx
= SHN_REGISTER
;
1519 /* We fake a register section that holds values that are register numbers.
1520 Having a SHN_REGISTER and register section translates better to other
1521 formats (e.g. mmo) than for example a STT_REGISTER attribute.
1522 This section faking is based on a construct in elf32-mips.c. */
1523 static asection mmix_elf_reg_section
;
1524 static asymbol mmix_elf_reg_section_symbol
;
1525 static asymbol
*mmix_elf_reg_section_symbol_ptr
;
1527 /* Handle the special MIPS section numbers that a symbol may use.
1528 This is used for both the 32-bit and the 64-bit ABI. */
1531 mmix_elf_symbol_processing (abfd
, asym
)
1532 bfd
*abfd ATTRIBUTE_UNUSED
;
1535 elf_symbol_type
*elfsym
;
1537 elfsym
= (elf_symbol_type
*) asym
;
1538 switch (elfsym
->internal_elf_sym
.st_shndx
)
1541 if (mmix_elf_reg_section
.name
== NULL
)
1543 /* Initialize the register section. */
1544 mmix_elf_reg_section
.name
= MMIX_REG_SECTION_NAME
;
1545 mmix_elf_reg_section
.flags
= SEC_NO_FLAGS
;
1546 mmix_elf_reg_section
.output_section
= &mmix_elf_reg_section
;
1547 mmix_elf_reg_section
.symbol
= &mmix_elf_reg_section_symbol
;
1548 mmix_elf_reg_section
.symbol_ptr_ptr
= &mmix_elf_reg_section_symbol_ptr
;
1549 mmix_elf_reg_section_symbol
.name
= MMIX_REG_SECTION_NAME
;
1550 mmix_elf_reg_section_symbol
.flags
= BSF_SECTION_SYM
;
1551 mmix_elf_reg_section_symbol
.section
= &mmix_elf_reg_section
;
1552 mmix_elf_reg_section_symbol_ptr
= &mmix_elf_reg_section_symbol
;
1554 asym
->section
= &mmix_elf_reg_section
;
1562 /* Given a BFD section, try to locate the corresponding ELF section
1566 mmix_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1567 bfd
* abfd ATTRIBUTE_UNUSED
;
1568 Elf64_Internal_Shdr
* hdr ATTRIBUTE_UNUSED
;
1572 if (strcmp (bfd_get_section_name (abfd
, sec
), MMIX_REG_SECTION_NAME
) == 0)
1573 *retval
= SHN_REGISTER
;
1580 /* Hook called by the linker routine which adds symbols from an object
1581 file. We must handle the special SHN_REGISTER section number here.
1583 We also check that we only have *one* each of the section-start
1584 symbols, since otherwise having two with the same value would cause
1585 them to be "merged", but with the contents serialized. */
1588 mmix_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1590 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1591 const Elf_Internal_Sym
*sym
;
1592 const char **namep ATTRIBUTE_UNUSED
;
1593 flagword
*flagsp ATTRIBUTE_UNUSED
;
1595 bfd_vma
*valp ATTRIBUTE_UNUSED
;
1597 if (sym
->st_shndx
== SHN_REGISTER
)
1598 *secp
= bfd_make_section_old_way (abfd
, MMIX_REG_SECTION_NAME
);
1599 else if ((*namep
)[0] == '_' && (*namep
)[1] == '_' && (*namep
)[2] == '.'
1600 && strncmp (*namep
, MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
1601 strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
)) == 0)
1603 /* See if we have another one. */
1604 struct elf_link_hash_entry
*h
1605 = (struct elf_link_hash_entry
*) bfd_link_hash_lookup (info
->hash
,
1610 if (h
!= NULL
&& h
->root
.type
!= bfd_link_hash_undefined
)
1612 /* How do we get the asymbol (or really: the filename) from h?
1613 h->root.u.def.section->owner is NULL. */
1614 ((*_bfd_error_handler
)
1615 (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
1616 bfd_get_filename (abfd
), *namep
,
1617 *namep
+ strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
)));
1618 bfd_set_error (bfd_error_bad_value
);
1626 /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
1629 mmix_elf_is_local_label_name (abfd
, name
)
1636 /* Also include the default local-label definition. */
1637 if (_bfd_elf_is_local_label_name (abfd
, name
))
1643 /* If there's no ":", or more than one, it's not a local symbol. */
1644 colpos
= strchr (name
, ':');
1645 if (colpos
== NULL
|| strchr (colpos
+ 1, ':') != NULL
)
1648 /* Check that there are remaining characters and that they are digits. */
1652 digits
= strspn (colpos
+ 1, "0123456789");
1653 return digits
!= 0 && colpos
[1 + digits
] == 0;
1656 /* We get rid of the register section here. */
1659 mmix_elf_final_link (abfd
, info
)
1661 struct bfd_link_info
*info
;
1663 /* We never output a register section, though we create one for
1664 temporary measures. Check that nobody entered contents into it. */
1665 asection
*reg_section
;
1668 reg_section
= bfd_get_section_by_name (abfd
, MMIX_REG_SECTION_NAME
);
1670 if (reg_section
!= NULL
)
1672 /* FIXME: Pass error state gracefully. */
1673 if (bfd_get_section_flags (abfd
, reg_section
) & SEC_HAS_CONTENTS
)
1674 _bfd_abort (__FILE__
, __LINE__
, _("Register section has contents\n"));
1676 /* FIXME: This does not seem like the proper way to kill a section,
1677 but it's the way it's done elsewhere, like elf64-alpha.c. */
1678 /* Really remove the section. */
1679 for (secpp
= &abfd
->sections
;
1680 *secpp
!= reg_section
;
1681 secpp
= &(*secpp
)->next
)
1683 *secpp
= (*secpp
)->next
;
1684 --abfd
->section_count
;
1687 if (! bfd_elf64_bfd_final_link (abfd
, info
))
1693 #define ELF_ARCH bfd_arch_mmix
1694 #define ELF_MACHINE_CODE EM_MMIX
1696 /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
1697 However, that's too much for something somewhere in the linker part of
1698 BFD; perhaps the start-address has to be a non-zero multiple of this
1699 number, or larger than this number. The symptom is that the linker
1700 complains: "warning: allocated section `.text' not in segment". We
1701 settle for 64k; the page-size used in examples is 8k.
1702 #define ELF_MAXPAGESIZE 0x10000
1704 Unfortunately, this causes excessive padding in the supposedly small
1705 for-education programs that are the expected usage (where people would
1706 inspect output). We stick to 256 bytes just to have *some* default
1708 #define ELF_MAXPAGESIZE 0x100
1710 #define TARGET_BIG_SYM bfd_elf64_mmix_vec
1711 #define TARGET_BIG_NAME "elf64-mmix"
1713 #define elf_info_to_howto_rel NULL
1714 #define elf_info_to_howto mmix_info_to_howto_rela
1715 #define elf_backend_relocate_section mmix_elf_relocate_section
1716 #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
1717 #define elf_backend_link_output_symbol_hook \
1718 mmix_elf_link_output_symbol_hook
1719 #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
1721 #define elf_backend_check_relocs mmix_elf_check_relocs
1722 #define elf_backend_symbol_processing mmix_elf_symbol_processing
1724 #define bfd_elf64_bfd_is_local_label_name \
1725 mmix_elf_is_local_label_name
1727 #define elf_backend_may_use_rel_p 0
1728 #define elf_backend_may_use_rela_p 1
1729 #define elf_backend_default_use_rela_p 1
1731 #define elf_backend_can_gc_sections 1
1732 #define elf_backend_section_from_bfd_section \
1733 mmix_elf_section_from_bfd_section
1735 #define bfd_elf64_bfd_final_link mmix_elf_final_link
1737 #include "elf64-target.h"