1 /* MMIX-specific support for 64-bit ELF.
2 Copyright (C) 2001-2018 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 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
23 /* No specific ABI or "processor-specific supplement" defined. */
26 - "Traditional" linker relaxation (shrinking whole sections).
27 - Merge reloc stubs jumping to same location.
28 - GETA stub relaxation (call a stub for out of range new
29 R_MMIX_GETA_STUBBABLE). */
36 #include "opcode/mmix.h"
38 #define MINUS_ONE (((bfd_vma) 0) - 1)
40 #define MAX_PUSHJ_STUB_SIZE (5 * 4)
42 /* Put these everywhere in new code. */
44 _bfd_abort (__FILE__, __LINE__, \
45 "Internal: Non-debugged code (test-case missing)")
48 _bfd_abort (__FILE__, __LINE__, \
51 struct _mmix_elf_section_data
53 struct bfd_elf_section_data elf
;
56 struct bpo_reloc_section_info
*reloc
;
57 struct bpo_greg_section_info
*greg
;
60 struct pushj_stub_info
62 /* Maximum number of stubs needed for this section. */
63 bfd_size_type n_pushj_relocs
;
65 /* Size of stubs after a mmix_elf_relax_section round. */
66 bfd_size_type stubs_size_sum
;
68 /* Per-reloc stubs_size_sum information. The stubs_size_sum member is the sum
69 of these. Allocated in mmix_elf_check_common_relocs. */
70 bfd_size_type
*stub_size
;
72 /* Offset of next stub during relocation. Somewhat redundant with the
73 above: error coverage is easier and we don't have to reset the
74 stubs_size_sum for relocation. */
75 bfd_size_type stub_offset
;
78 /* Whether there has been a warning that this section could not be
79 linked due to a specific cause. FIXME: a way to access the
80 linker info or output section, then stuff the limiter guard
82 bfd_boolean has_warned_bpo
;
83 bfd_boolean has_warned_pushj
;
86 #define mmix_elf_section_data(sec) \
87 ((struct _mmix_elf_section_data *) elf_section_data (sec))
89 /* For each section containing a base-plus-offset (BPO) reloc, we attach
90 this struct as mmix_elf_section_data (section)->bpo, which is otherwise
92 struct bpo_reloc_section_info
94 /* The base is 1; this is the first number in this section. */
95 size_t first_base_plus_offset_reloc
;
97 /* Number of BPO-relocs in this section. */
98 size_t n_bpo_relocs_this_section
;
100 /* Running index, used at relocation time. */
103 /* We don't have access to the bfd_link_info struct in
104 mmix_final_link_relocate. What we really want to get at is the
105 global single struct greg_relocation, so we stash it here. */
106 asection
*bpo_greg_section
;
109 /* Helper struct (in global context) for the one below.
110 There's one of these created for every BPO reloc. */
111 struct bpo_reloc_request
115 /* Valid after relaxation. The base is 0; the first register number
116 must be added. The offset is in range 0..255. */
120 /* The order number for this BPO reloc, corresponding to the order in
121 which BPO relocs were found. Used to create an index after reloc
122 requests are sorted. */
125 /* Set when the value is computed. Better than coding "guard values"
126 into the other members. Is FALSE only for BPO relocs in a GC:ed
131 /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
132 greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
133 which is linked into the register contents section
134 (MMIX_REG_CONTENTS_SECTION_NAME). This section is created by the
135 linker; using the same hook as for usual with BPO relocs does not
137 struct bpo_greg_section_info
139 /* After GC, this reflects the number of remaining, non-excluded
143 /* This is the number of allocated bpo_reloc_requests; the size of
144 sorted_indexes. Valid after the check.*relocs functions are called
145 for all incoming sections. It includes the number of BPO relocs in
146 sections that were GC:ed. */
147 size_t n_max_bpo_relocs
;
149 /* A counter used to find out when to fold the BPO gregs, since we
150 don't have a single "after-relaxation" hook. */
151 size_t n_remaining_bpo_relocs_this_relaxation_round
;
153 /* The number of linker-allocated GREGs resulting from BPO relocs.
154 This is an approximation after _bfd_mmix_before_linker_allocation
155 and supposedly accurate after mmix_elf_relax_section is called for
156 all incoming non-collected sections. */
157 size_t n_allocated_bpo_gregs
;
159 /* Index into reloc_request[], sorted on increasing "value", secondary
160 by increasing index for strict sorting order. */
161 size_t *bpo_reloc_indexes
;
163 /* An array of all relocations, with the "value" member filled in by
164 the relaxation function. */
165 struct bpo_reloc_request
*reloc_request
;
169 extern bfd_boolean
mmix_elf_final_link (bfd
*, struct bfd_link_info
*);
171 extern void mmix_elf_symbol_processing (bfd
*, asymbol
*);
173 /* Only intended to be called from a debugger. */
174 extern void mmix_dump_bpo_gregs
175 (struct bfd_link_info
*, void (*) (const char *, ...));
178 mmix_set_relaxable_size (bfd
*, asection
*, void *);
179 static bfd_reloc_status_type
180 mmix_elf_reloc (bfd
*, arelent
*, asymbol
*, void *,
181 asection
*, bfd
*, char **);
182 static bfd_reloc_status_type
183 mmix_final_link_relocate (reloc_howto_type
*, asection
*, bfd_byte
*, bfd_vma
,
184 bfd_signed_vma
, bfd_vma
, const char *, asection
*,
188 /* Watch out: this currently needs to have elements with the same index as
189 their R_MMIX_ number. */
190 static reloc_howto_type elf_mmix_howto_table
[] =
192 /* This reloc does nothing. */
193 HOWTO (R_MMIX_NONE
, /* type */
195 3, /* size (0 = byte, 1 = short, 2 = long) */
197 FALSE
, /* pc_relative */
199 complain_overflow_dont
, /* complain_on_overflow */
200 bfd_elf_generic_reloc
, /* special_function */
201 "R_MMIX_NONE", /* name */
202 FALSE
, /* partial_inplace */
205 FALSE
), /* pcrel_offset */
207 /* An 8 bit absolute relocation. */
208 HOWTO (R_MMIX_8
, /* type */
210 0, /* size (0 = byte, 1 = short, 2 = long) */
212 FALSE
, /* pc_relative */
214 complain_overflow_bitfield
, /* complain_on_overflow */
215 bfd_elf_generic_reloc
, /* special_function */
216 "R_MMIX_8", /* name */
217 FALSE
, /* partial_inplace */
220 FALSE
), /* pcrel_offset */
222 /* An 16 bit absolute relocation. */
223 HOWTO (R_MMIX_16
, /* type */
225 1, /* size (0 = byte, 1 = short, 2 = long) */
227 FALSE
, /* pc_relative */
229 complain_overflow_bitfield
, /* complain_on_overflow */
230 bfd_elf_generic_reloc
, /* special_function */
231 "R_MMIX_16", /* name */
232 FALSE
, /* partial_inplace */
234 0xffff, /* dst_mask */
235 FALSE
), /* pcrel_offset */
237 /* An 24 bit absolute relocation. */
238 HOWTO (R_MMIX_24
, /* type */
240 2, /* size (0 = byte, 1 = short, 2 = long) */
242 FALSE
, /* pc_relative */
244 complain_overflow_bitfield
, /* complain_on_overflow */
245 bfd_elf_generic_reloc
, /* special_function */
246 "R_MMIX_24", /* name */
247 FALSE
, /* partial_inplace */
248 ~0xffffff, /* src_mask */
249 0xffffff, /* dst_mask */
250 FALSE
), /* pcrel_offset */
252 /* A 32 bit absolute relocation. */
253 HOWTO (R_MMIX_32
, /* type */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_bitfield
, /* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_MMIX_32", /* name */
262 FALSE
, /* partial_inplace */
264 0xffffffff, /* dst_mask */
265 FALSE
), /* pcrel_offset */
267 /* 64 bit relocation. */
268 HOWTO (R_MMIX_64
, /* type */
270 4, /* size (0 = byte, 1 = short, 2 = long) */
272 FALSE
, /* pc_relative */
274 complain_overflow_bitfield
, /* complain_on_overflow */
275 bfd_elf_generic_reloc
, /* special_function */
276 "R_MMIX_64", /* name */
277 FALSE
, /* partial_inplace */
279 MINUS_ONE
, /* dst_mask */
280 FALSE
), /* pcrel_offset */
282 /* An 8 bit PC-relative relocation. */
283 HOWTO (R_MMIX_PC_8
, /* type */
285 0, /* size (0 = byte, 1 = short, 2 = long) */
287 TRUE
, /* pc_relative */
289 complain_overflow_bitfield
, /* complain_on_overflow */
290 bfd_elf_generic_reloc
, /* special_function */
291 "R_MMIX_PC_8", /* name */
292 FALSE
, /* partial_inplace */
295 TRUE
), /* pcrel_offset */
297 /* An 16 bit PC-relative relocation. */
298 HOWTO (R_MMIX_PC_16
, /* type */
300 1, /* size (0 = byte, 1 = short, 2 = long) */
302 TRUE
, /* pc_relative */
304 complain_overflow_bitfield
, /* complain_on_overflow */
305 bfd_elf_generic_reloc
, /* special_function */
306 "R_MMIX_PC_16", /* name */
307 FALSE
, /* partial_inplace */
309 0xffff, /* dst_mask */
310 TRUE
), /* pcrel_offset */
312 /* An 24 bit PC-relative relocation. */
313 HOWTO (R_MMIX_PC_24
, /* type */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
317 TRUE
, /* pc_relative */
319 complain_overflow_bitfield
, /* complain_on_overflow */
320 bfd_elf_generic_reloc
, /* special_function */
321 "R_MMIX_PC_24", /* name */
322 FALSE
, /* partial_inplace */
323 ~0xffffff, /* src_mask */
324 0xffffff, /* dst_mask */
325 TRUE
), /* pcrel_offset */
327 /* A 32 bit absolute PC-relative relocation. */
328 HOWTO (R_MMIX_PC_32
, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 TRUE
, /* pc_relative */
334 complain_overflow_bitfield
, /* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 "R_MMIX_PC_32", /* name */
337 FALSE
, /* partial_inplace */
339 0xffffffff, /* dst_mask */
340 TRUE
), /* pcrel_offset */
342 /* 64 bit PC-relative relocation. */
343 HOWTO (R_MMIX_PC_64
, /* type */
345 4, /* size (0 = byte, 1 = short, 2 = long) */
347 TRUE
, /* pc_relative */
349 complain_overflow_bitfield
, /* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 "R_MMIX_PC_64", /* name */
352 FALSE
, /* partial_inplace */
354 MINUS_ONE
, /* dst_mask */
355 TRUE
), /* pcrel_offset */
357 /* GNU extension to record C++ vtable hierarchy. */
358 HOWTO (R_MMIX_GNU_VTINHERIT
, /* type */
360 0, /* size (0 = byte, 1 = short, 2 = long) */
362 FALSE
, /* pc_relative */
364 complain_overflow_dont
, /* complain_on_overflow */
365 NULL
, /* special_function */
366 "R_MMIX_GNU_VTINHERIT", /* name */
367 FALSE
, /* partial_inplace */
370 TRUE
), /* pcrel_offset */
372 /* GNU extension to record C++ vtable member usage. */
373 HOWTO (R_MMIX_GNU_VTENTRY
, /* type */
375 0, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_dont
, /* complain_on_overflow */
380 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
381 "R_MMIX_GNU_VTENTRY", /* name */
382 FALSE
, /* partial_inplace */
385 FALSE
), /* pcrel_offset */
387 /* The GETA relocation is supposed to get any address that could
388 possibly be reached by the GETA instruction. It can silently expand
389 to get a 64-bit operand, but will complain if any of the two least
390 significant bits are set. The howto members reflect a simple GETA. */
391 HOWTO (R_MMIX_GETA
, /* type */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
395 TRUE
, /* pc_relative */
397 complain_overflow_signed
, /* complain_on_overflow */
398 mmix_elf_reloc
, /* special_function */
399 "R_MMIX_GETA", /* name */
400 FALSE
, /* partial_inplace */
401 ~0x0100ffff, /* src_mask */
402 0x0100ffff, /* dst_mask */
403 TRUE
), /* pcrel_offset */
405 HOWTO (R_MMIX_GETA_1
, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 TRUE
, /* pc_relative */
411 complain_overflow_signed
, /* complain_on_overflow */
412 mmix_elf_reloc
, /* special_function */
413 "R_MMIX_GETA_1", /* name */
414 FALSE
, /* partial_inplace */
415 ~0x0100ffff, /* src_mask */
416 0x0100ffff, /* dst_mask */
417 TRUE
), /* pcrel_offset */
419 HOWTO (R_MMIX_GETA_2
, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 TRUE
, /* pc_relative */
425 complain_overflow_signed
, /* complain_on_overflow */
426 mmix_elf_reloc
, /* special_function */
427 "R_MMIX_GETA_2", /* name */
428 FALSE
, /* partial_inplace */
429 ~0x0100ffff, /* src_mask */
430 0x0100ffff, /* dst_mask */
431 TRUE
), /* pcrel_offset */
433 HOWTO (R_MMIX_GETA_3
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 TRUE
, /* pc_relative */
439 complain_overflow_signed
, /* complain_on_overflow */
440 mmix_elf_reloc
, /* special_function */
441 "R_MMIX_GETA_3", /* name */
442 FALSE
, /* partial_inplace */
443 ~0x0100ffff, /* src_mask */
444 0x0100ffff, /* dst_mask */
445 TRUE
), /* pcrel_offset */
447 /* The conditional branches are supposed to reach any (code) address.
448 It can silently expand to a 64-bit operand, but will emit an error if
449 any of the two least significant bits are set. The howto members
450 reflect a simple branch. */
451 HOWTO (R_MMIX_CBRANCH
, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 TRUE
, /* pc_relative */
457 complain_overflow_signed
, /* complain_on_overflow */
458 mmix_elf_reloc
, /* special_function */
459 "R_MMIX_CBRANCH", /* name */
460 FALSE
, /* partial_inplace */
461 ~0x0100ffff, /* src_mask */
462 0x0100ffff, /* dst_mask */
463 TRUE
), /* pcrel_offset */
465 HOWTO (R_MMIX_CBRANCH_J
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_signed
, /* complain_on_overflow */
472 mmix_elf_reloc
, /* special_function */
473 "R_MMIX_CBRANCH_J", /* name */
474 FALSE
, /* partial_inplace */
475 ~0x0100ffff, /* src_mask */
476 0x0100ffff, /* dst_mask */
477 TRUE
), /* pcrel_offset */
479 HOWTO (R_MMIX_CBRANCH_1
, /* type */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
483 TRUE
, /* pc_relative */
485 complain_overflow_signed
, /* complain_on_overflow */
486 mmix_elf_reloc
, /* special_function */
487 "R_MMIX_CBRANCH_1", /* name */
488 FALSE
, /* partial_inplace */
489 ~0x0100ffff, /* src_mask */
490 0x0100ffff, /* dst_mask */
491 TRUE
), /* pcrel_offset */
493 HOWTO (R_MMIX_CBRANCH_2
, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 TRUE
, /* pc_relative */
499 complain_overflow_signed
, /* complain_on_overflow */
500 mmix_elf_reloc
, /* special_function */
501 "R_MMIX_CBRANCH_2", /* name */
502 FALSE
, /* partial_inplace */
503 ~0x0100ffff, /* src_mask */
504 0x0100ffff, /* dst_mask */
505 TRUE
), /* pcrel_offset */
507 HOWTO (R_MMIX_CBRANCH_3
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 TRUE
, /* pc_relative */
513 complain_overflow_signed
, /* complain_on_overflow */
514 mmix_elf_reloc
, /* special_function */
515 "R_MMIX_CBRANCH_3", /* name */
516 FALSE
, /* partial_inplace */
517 ~0x0100ffff, /* src_mask */
518 0x0100ffff, /* dst_mask */
519 TRUE
), /* pcrel_offset */
521 /* The PUSHJ instruction can reach any (code) address, as long as it's
522 the beginning of a function (no usable restriction). It can silently
523 expand to a 64-bit operand, but will emit an error if any of the two
524 least significant bits are set. It can also expand into a call to a
525 stub; see R_MMIX_PUSHJ_STUBBABLE. The howto members reflect a simple
527 HOWTO (R_MMIX_PUSHJ
, /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 TRUE
, /* pc_relative */
533 complain_overflow_signed
, /* complain_on_overflow */
534 mmix_elf_reloc
, /* special_function */
535 "R_MMIX_PUSHJ", /* name */
536 FALSE
, /* partial_inplace */
537 ~0x0100ffff, /* src_mask */
538 0x0100ffff, /* dst_mask */
539 TRUE
), /* pcrel_offset */
541 HOWTO (R_MMIX_PUSHJ_1
, /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 TRUE
, /* pc_relative */
547 complain_overflow_signed
, /* complain_on_overflow */
548 mmix_elf_reloc
, /* special_function */
549 "R_MMIX_PUSHJ_1", /* name */
550 FALSE
, /* partial_inplace */
551 ~0x0100ffff, /* src_mask */
552 0x0100ffff, /* dst_mask */
553 TRUE
), /* pcrel_offset */
555 HOWTO (R_MMIX_PUSHJ_2
, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 TRUE
, /* pc_relative */
561 complain_overflow_signed
, /* complain_on_overflow */
562 mmix_elf_reloc
, /* special_function */
563 "R_MMIX_PUSHJ_2", /* name */
564 FALSE
, /* partial_inplace */
565 ~0x0100ffff, /* src_mask */
566 0x0100ffff, /* dst_mask */
567 TRUE
), /* pcrel_offset */
569 HOWTO (R_MMIX_PUSHJ_3
, /* type */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
573 TRUE
, /* pc_relative */
575 complain_overflow_signed
, /* complain_on_overflow */
576 mmix_elf_reloc
, /* special_function */
577 "R_MMIX_PUSHJ_3", /* name */
578 FALSE
, /* partial_inplace */
579 ~0x0100ffff, /* src_mask */
580 0x0100ffff, /* dst_mask */
581 TRUE
), /* pcrel_offset */
583 /* A JMP is supposed to reach any (code) address. By itself, it can
584 reach +-64M; the expansion can reach all 64 bits. Note that the 64M
585 limit is soon reached if you link the program in wildly different
586 memory segments. The howto members reflect a trivial JMP. */
587 HOWTO (R_MMIX_JMP
, /* type */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
591 TRUE
, /* pc_relative */
593 complain_overflow_signed
, /* complain_on_overflow */
594 mmix_elf_reloc
, /* special_function */
595 "R_MMIX_JMP", /* name */
596 FALSE
, /* partial_inplace */
597 ~0x1ffffff, /* src_mask */
598 0x1ffffff, /* dst_mask */
599 TRUE
), /* pcrel_offset */
601 HOWTO (R_MMIX_JMP_1
, /* type */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
605 TRUE
, /* pc_relative */
607 complain_overflow_signed
, /* complain_on_overflow */
608 mmix_elf_reloc
, /* special_function */
609 "R_MMIX_JMP_1", /* name */
610 FALSE
, /* partial_inplace */
611 ~0x1ffffff, /* src_mask */
612 0x1ffffff, /* dst_mask */
613 TRUE
), /* pcrel_offset */
615 HOWTO (R_MMIX_JMP_2
, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 TRUE
, /* pc_relative */
621 complain_overflow_signed
, /* complain_on_overflow */
622 mmix_elf_reloc
, /* special_function */
623 "R_MMIX_JMP_2", /* name */
624 FALSE
, /* partial_inplace */
625 ~0x1ffffff, /* src_mask */
626 0x1ffffff, /* dst_mask */
627 TRUE
), /* pcrel_offset */
629 HOWTO (R_MMIX_JMP_3
, /* type */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
633 TRUE
, /* pc_relative */
635 complain_overflow_signed
, /* complain_on_overflow */
636 mmix_elf_reloc
, /* special_function */
637 "R_MMIX_JMP_3", /* name */
638 FALSE
, /* partial_inplace */
639 ~0x1ffffff, /* src_mask */
640 0x1ffffff, /* dst_mask */
641 TRUE
), /* pcrel_offset */
643 /* When we don't emit link-time-relaxable code from the assembler, or
644 when relaxation has done all it can do, these relocs are used. For
645 GETA/PUSHJ/branches. */
646 HOWTO (R_MMIX_ADDR19
, /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 TRUE
, /* pc_relative */
652 complain_overflow_signed
, /* complain_on_overflow */
653 mmix_elf_reloc
, /* special_function */
654 "R_MMIX_ADDR19", /* name */
655 FALSE
, /* partial_inplace */
656 ~0x0100ffff, /* src_mask */
657 0x0100ffff, /* dst_mask */
658 TRUE
), /* pcrel_offset */
661 HOWTO (R_MMIX_ADDR27
, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 TRUE
, /* pc_relative */
667 complain_overflow_signed
, /* complain_on_overflow */
668 mmix_elf_reloc
, /* special_function */
669 "R_MMIX_ADDR27", /* name */
670 FALSE
, /* partial_inplace */
671 ~0x1ffffff, /* src_mask */
672 0x1ffffff, /* dst_mask */
673 TRUE
), /* pcrel_offset */
675 /* A general register or the value 0..255. If a value, then the
676 instruction (offset -3) needs adjusting. */
677 HOWTO (R_MMIX_REG_OR_BYTE
, /* type */
679 1, /* size (0 = byte, 1 = short, 2 = long) */
681 FALSE
, /* pc_relative */
683 complain_overflow_bitfield
, /* complain_on_overflow */
684 mmix_elf_reloc
, /* special_function */
685 "R_MMIX_REG_OR_BYTE", /* name */
686 FALSE
, /* partial_inplace */
689 FALSE
), /* pcrel_offset */
691 /* A general register. */
692 HOWTO (R_MMIX_REG
, /* type */
694 1, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE
, /* pc_relative */
698 complain_overflow_bitfield
, /* complain_on_overflow */
699 mmix_elf_reloc
, /* special_function */
700 "R_MMIX_REG", /* name */
701 FALSE
, /* partial_inplace */
704 FALSE
), /* pcrel_offset */
706 /* A register plus an index, corresponding to the relocation expression.
707 The sizes must correspond to the valid range of the expression, while
708 the bitmasks correspond to what we store in the image. */
709 HOWTO (R_MMIX_BASE_PLUS_OFFSET
, /* type */
711 4, /* size (0 = byte, 1 = short, 2 = long) */
713 FALSE
, /* pc_relative */
715 complain_overflow_bitfield
, /* complain_on_overflow */
716 mmix_elf_reloc
, /* special_function */
717 "R_MMIX_BASE_PLUS_OFFSET", /* name */
718 FALSE
, /* partial_inplace */
720 0xffff, /* dst_mask */
721 FALSE
), /* pcrel_offset */
723 /* A "magic" relocation for a LOCAL expression, asserting that the
724 expression is less than the number of global registers. No actual
725 modification of the contents is done. Implementing this as a
726 relocation was less intrusive than e.g. putting such expressions in a
727 section to discard *after* relocation. */
728 HOWTO (R_MMIX_LOCAL
, /* type */
730 0, /* size (0 = byte, 1 = short, 2 = long) */
732 FALSE
, /* pc_relative */
734 complain_overflow_dont
, /* complain_on_overflow */
735 mmix_elf_reloc
, /* special_function */
736 "R_MMIX_LOCAL", /* name */
737 FALSE
, /* partial_inplace */
740 FALSE
), /* pcrel_offset */
742 HOWTO (R_MMIX_PUSHJ_STUBBABLE
, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 TRUE
, /* pc_relative */
748 complain_overflow_signed
, /* complain_on_overflow */
749 mmix_elf_reloc
, /* special_function */
750 "R_MMIX_PUSHJ_STUBBABLE", /* name */
751 FALSE
, /* partial_inplace */
752 ~0x0100ffff, /* src_mask */
753 0x0100ffff, /* dst_mask */
754 TRUE
) /* pcrel_offset */
758 /* Map BFD reloc types to MMIX ELF reloc types. */
760 struct mmix_reloc_map
762 bfd_reloc_code_real_type bfd_reloc_val
;
763 enum elf_mmix_reloc_type elf_reloc_val
;
767 static const struct mmix_reloc_map mmix_reloc_map
[] =
769 {BFD_RELOC_NONE
, R_MMIX_NONE
},
770 {BFD_RELOC_8
, R_MMIX_8
},
771 {BFD_RELOC_16
, R_MMIX_16
},
772 {BFD_RELOC_24
, R_MMIX_24
},
773 {BFD_RELOC_32
, R_MMIX_32
},
774 {BFD_RELOC_64
, R_MMIX_64
},
775 {BFD_RELOC_8_PCREL
, R_MMIX_PC_8
},
776 {BFD_RELOC_16_PCREL
, R_MMIX_PC_16
},
777 {BFD_RELOC_24_PCREL
, R_MMIX_PC_24
},
778 {BFD_RELOC_32_PCREL
, R_MMIX_PC_32
},
779 {BFD_RELOC_64_PCREL
, R_MMIX_PC_64
},
780 {BFD_RELOC_VTABLE_INHERIT
, R_MMIX_GNU_VTINHERIT
},
781 {BFD_RELOC_VTABLE_ENTRY
, R_MMIX_GNU_VTENTRY
},
782 {BFD_RELOC_MMIX_GETA
, R_MMIX_GETA
},
783 {BFD_RELOC_MMIX_CBRANCH
, R_MMIX_CBRANCH
},
784 {BFD_RELOC_MMIX_PUSHJ
, R_MMIX_PUSHJ
},
785 {BFD_RELOC_MMIX_JMP
, R_MMIX_JMP
},
786 {BFD_RELOC_MMIX_ADDR19
, R_MMIX_ADDR19
},
787 {BFD_RELOC_MMIX_ADDR27
, R_MMIX_ADDR27
},
788 {BFD_RELOC_MMIX_REG_OR_BYTE
, R_MMIX_REG_OR_BYTE
},
789 {BFD_RELOC_MMIX_REG
, R_MMIX_REG
},
790 {BFD_RELOC_MMIX_BASE_PLUS_OFFSET
, R_MMIX_BASE_PLUS_OFFSET
},
791 {BFD_RELOC_MMIX_LOCAL
, R_MMIX_LOCAL
},
792 {BFD_RELOC_MMIX_PUSHJ_STUBBABLE
, R_MMIX_PUSHJ_STUBBABLE
}
795 static reloc_howto_type
*
796 bfd_elf64_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
797 bfd_reloc_code_real_type code
)
802 i
< sizeof (mmix_reloc_map
) / sizeof (mmix_reloc_map
[0]);
805 if (mmix_reloc_map
[i
].bfd_reloc_val
== code
)
806 return &elf_mmix_howto_table
[mmix_reloc_map
[i
].elf_reloc_val
];
812 static reloc_howto_type
*
813 bfd_elf64_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
819 i
< sizeof (elf_mmix_howto_table
) / sizeof (elf_mmix_howto_table
[0]);
821 if (elf_mmix_howto_table
[i
].name
!= NULL
822 && strcasecmp (elf_mmix_howto_table
[i
].name
, r_name
) == 0)
823 return &elf_mmix_howto_table
[i
];
829 mmix_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
831 if (!sec
->used_by_bfd
)
833 struct _mmix_elf_section_data
*sdata
;
834 bfd_size_type amt
= sizeof (*sdata
);
836 sdata
= bfd_zalloc (abfd
, amt
);
839 sec
->used_by_bfd
= sdata
;
842 return _bfd_elf_new_section_hook (abfd
, sec
);
846 /* This function performs the actual bitfiddling and sanity check for a
847 final relocation. Each relocation gets its *worst*-case expansion
848 in size when it arrives here; any reduction in size should have been
849 caught in linker relaxation earlier. When we get here, the relocation
850 looks like the smallest instruction with SWYM:s (nop:s) appended to the
851 max size. We fill in those nop:s.
853 R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
857 INCML $N,(foo >> 16) & 0xffff
858 INCMH $N,(foo >> 32) & 0xffff
859 INCH $N,(foo >> 48) & 0xffff
861 R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
862 condbranches needing relaxation might be rare enough to not be
873 R_MMIX_PUSHJ: (FIXME: Relaxation...)
882 R_MMIX_JMP: (FIXME: Relaxation...)
891 R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
893 static bfd_reloc_status_type
894 mmix_elf_perform_relocation (asection
*isec
, reloc_howto_type
*howto
,
895 void *datap
, bfd_vma addr
, bfd_vma value
,
896 char **error_message
)
898 bfd
*abfd
= isec
->owner
;
899 bfd_reloc_status_type flag
= bfd_reloc_ok
;
900 bfd_reloc_status_type r
;
904 /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
905 We handle the differences here and the common sequence later. */
910 reg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
912 /* We change to an absolute value. */
918 int in1
= bfd_get_16 (abfd
, (bfd_byte
*) datap
) << 16;
920 /* Invert the condition and prediction bit, and set the offset
921 to five instructions ahead.
923 We *can* do better if we want to. If the branch is found to be
924 within limits, we could leave the branch as is; there'll just
925 be a bunch of NOP:s after it. But we shouldn't see this
926 sequence often enough that it's worth doing it. */
929 (((in1
^ ((PRED_INV_BIT
| COND_INV_BIT
) << 24)) & ~0xffff)
933 /* Put a "GO $255,$255,0" after the common sequence. */
935 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24) | 0xffff00,
936 (bfd_byte
*) datap
+ 20);
938 /* Common sequence starts at offset 4. */
941 /* We change to an absolute value. */
946 case R_MMIX_PUSHJ_STUBBABLE
:
947 /* If the address fits, we're fine. */
949 /* Note rightshift 0; see R_MMIX_JMP case below. */
950 && (r
= bfd_check_overflow (complain_overflow_signed
,
953 bfd_arch_bits_per_address (abfd
),
954 value
)) == bfd_reloc_ok
)
955 goto pcrel_mmix_reloc_fits
;
958 bfd_size_type size
= isec
->rawsize
? isec
->rawsize
: isec
->size
;
960 /* We have the bytes at the PUSHJ insn and need to get the
961 position for the stub. There's supposed to be room allocated
963 bfd_byte
*stubcontents
964 = ((bfd_byte
*) datap
965 - (addr
- (isec
->output_section
->vma
+ isec
->output_offset
))
967 + mmix_elf_section_data (isec
)->pjs
.stub_offset
);
970 if (mmix_elf_section_data (isec
)->pjs
.n_pushj_relocs
== 0)
972 /* This shouldn't happen when linking to ELF or mmo, so
973 this is an attempt to link to "binary", right? We
974 can't access the output bfd, so we can't verify that
975 assumption. We only know that the critical
976 mmix_elf_check_common_relocs has not been called,
977 which happens when the output format is different
978 from the input format (and is not mmo). */
979 if (! mmix_elf_section_data (isec
)->has_warned_pushj
)
981 /* For the first such error per input section, produce
982 a verbose message. */
984 = _("invalid input relocation when producing"
985 " non-ELF, non-mmo format output."
986 "\n Please use the objcopy program to convert from"
988 "\n or assemble using"
989 " \"-no-expand\" (for gcc, \"-Wa,-no-expand\"");
990 mmix_elf_section_data (isec
)->has_warned_pushj
= TRUE
;
991 return bfd_reloc_dangerous
;
994 /* For subsequent errors, return this one, which is
995 rate-limited but looks a little bit different,
996 hopefully without affecting user-friendliness. */
997 return bfd_reloc_overflow
;
1000 /* The address doesn't fit, so redirect the PUSHJ to the
1001 location of the stub. */
1002 r
= mmix_elf_perform_relocation (isec
,
1003 &elf_mmix_howto_table
1007 isec
->output_section
->vma
1008 + isec
->output_offset
1010 + (mmix_elf_section_data (isec
)
1014 if (r
!= bfd_reloc_ok
)
1018 = (isec
->output_section
->vma
1019 + isec
->output_offset
1021 + mmix_elf_section_data (isec
)->pjs
.stub_offset
);
1023 /* We generate a simple JMP if that suffices, else the whole 5
1025 if (bfd_check_overflow (complain_overflow_signed
,
1026 elf_mmix_howto_table
[R_MMIX_ADDR27
].bitsize
,
1028 bfd_arch_bits_per_address (abfd
),
1029 addr
+ value
- stubaddr
) == bfd_reloc_ok
)
1031 bfd_put_32 (abfd
, JMP_INSN_BYTE
<< 24, stubcontents
);
1032 r
= mmix_elf_perform_relocation (isec
,
1033 &elf_mmix_howto_table
1037 value
+ addr
- stubaddr
,
1039 mmix_elf_section_data (isec
)->pjs
.stub_offset
+= 4;
1041 if (size
+ mmix_elf_section_data (isec
)->pjs
.stub_offset
1049 /* Put a "GO $255,0" after the common sequence. */
1051 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1052 | 0xff00, (bfd_byte
*) stubcontents
+ 16);
1054 /* Prepare for the general code to set the first part of the
1057 datap
= stubcontents
;
1058 mmix_elf_section_data (isec
)->pjs
.stub_offset
1059 += MAX_PUSHJ_STUB_SIZE
;
1066 int inreg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
1068 /* Put a "PUSHGO $N,$255,0" after the common sequence. */
1070 ((PUSHGO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1073 (bfd_byte
*) datap
+ 16);
1075 /* We change to an absolute value. */
1081 /* This one is a little special. If we get here on a non-relaxing
1082 link, and the destination is actually in range, we don't need to
1084 If so, we fall through to the bit-fiddling relocs.
1086 FIXME: bfd_check_overflow seems broken; the relocation is
1087 rightshifted before testing, so supply a zero rightshift. */
1089 if (! ((value
& 3) == 0
1090 && (r
= bfd_check_overflow (complain_overflow_signed
,
1093 bfd_arch_bits_per_address (abfd
),
1094 value
)) == bfd_reloc_ok
))
1096 /* If the relocation doesn't fit in a JMP, we let the NOP:s be
1097 modified below, and put a "GO $255,$255,0" after the
1098 address-loading sequence. */
1100 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1102 (bfd_byte
*) datap
+ 16);
1104 /* We change to an absolute value. */
1111 pcrel_mmix_reloc_fits
:
1112 /* These must be in range, or else we emit an error. */
1113 if ((value
& 3) == 0
1114 /* Note rightshift 0; see above. */
1115 && (r
= bfd_check_overflow (complain_overflow_signed
,
1118 bfd_arch_bits_per_address (abfd
),
1119 value
)) == bfd_reloc_ok
)
1122 = bfd_get_32 (abfd
, (bfd_byte
*) datap
);
1125 if ((bfd_signed_vma
) value
< 0)
1128 value
+= (1 << (howto
->bitsize
- 1));
1136 (in1
& howto
->src_mask
)
1138 | (value
& howto
->dst_mask
),
1139 (bfd_byte
*) datap
);
1141 return bfd_reloc_ok
;
1144 return bfd_reloc_overflow
;
1146 case R_MMIX_BASE_PLUS_OFFSET
:
1148 struct bpo_reloc_section_info
*bpodata
1149 = mmix_elf_section_data (isec
)->bpo
.reloc
;
1150 asection
*bpo_greg_section
;
1151 struct bpo_greg_section_info
*gregdata
;
1154 if (bpodata
== NULL
)
1156 /* This shouldn't happen when linking to ELF or mmo, so
1157 this is an attempt to link to "binary", right? We
1158 can't access the output bfd, so we can't verify that
1159 assumption. We only know that the critical
1160 mmix_elf_check_common_relocs has not been called, which
1161 happens when the output format is different from the
1162 input format (and is not mmo). */
1163 if (! mmix_elf_section_data (isec
)->has_warned_bpo
)
1165 /* For the first such error per input section, produce
1166 a verbose message. */
1168 = _("invalid input relocation when producing"
1169 " non-ELF, non-mmo format output."
1170 "\n Please use the objcopy program to convert from"
1172 "\n or compile using the gcc-option"
1173 " \"-mno-base-addresses\".");
1174 mmix_elf_section_data (isec
)->has_warned_bpo
= TRUE
;
1175 return bfd_reloc_dangerous
;
1178 /* For subsequent errors, return this one, which is
1179 rate-limited but looks a little bit different,
1180 hopefully without affecting user-friendliness. */
1181 return bfd_reloc_overflow
;
1184 bpo_greg_section
= bpodata
->bpo_greg_section
;
1185 gregdata
= mmix_elf_section_data (bpo_greg_section
)->bpo
.greg
;
1186 bpo_index
= gregdata
->bpo_reloc_indexes
[bpodata
->bpo_index
++];
1188 /* A consistency check: The value we now have in "relocation" must
1189 be the same as the value we stored for that relocation. It
1190 doesn't cost much, so can be left in at all times. */
1191 if (value
!= gregdata
->reloc_request
[bpo_index
].value
)
1194 /* xgettext:c-format */
1195 (_("%B: Internal inconsistency error for value for\n\
1196 linker-allocated global register: linked: %#Lx != relaxed: %#Lx"),
1199 gregdata
->reloc_request
[bpo_index
].value
);
1200 bfd_set_error (bfd_error_bad_value
);
1201 return bfd_reloc_overflow
;
1204 /* Then store the register number and offset for that register
1205 into datap and datap + 1 respectively. */
1207 gregdata
->reloc_request
[bpo_index
].regindex
1208 + bpo_greg_section
->output_section
->vma
/ 8,
1211 gregdata
->reloc_request
[bpo_index
].offset
,
1212 ((unsigned char *) datap
) + 1);
1213 return bfd_reloc_ok
;
1216 case R_MMIX_REG_OR_BYTE
:
1219 return bfd_reloc_overflow
;
1220 bfd_put_8 (abfd
, value
, datap
);
1221 return bfd_reloc_ok
;
1224 BAD_CASE (howto
->type
);
1227 /* This code adds the common SETL/INCML/INCMH/INCH worst-case
1230 /* Lowest two bits must be 0. We return bfd_reloc_overflow for
1231 everything that looks strange. */
1233 flag
= bfd_reloc_overflow
;
1236 (SETL_INSN_BYTE
<< 24) | (value
& 0xffff) | (reg
<< 16),
1237 (bfd_byte
*) datap
+ offs
);
1239 (INCML_INSN_BYTE
<< 24) | ((value
>> 16) & 0xffff) | (reg
<< 16),
1240 (bfd_byte
*) datap
+ offs
+ 4);
1242 (INCMH_INSN_BYTE
<< 24) | ((value
>> 32) & 0xffff) | (reg
<< 16),
1243 (bfd_byte
*) datap
+ offs
+ 8);
1245 (INCH_INSN_BYTE
<< 24) | ((value
>> 48) & 0xffff) | (reg
<< 16),
1246 (bfd_byte
*) datap
+ offs
+ 12);
1251 /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
1254 mmix_info_to_howto_rela (bfd
*abfd ATTRIBUTE_UNUSED
,
1256 Elf_Internal_Rela
*dst
)
1258 unsigned int r_type
;
1260 r_type
= ELF64_R_TYPE (dst
->r_info
);
1261 if (r_type
>= (unsigned int) R_MMIX_max
)
1263 /* xgettext:c-format */
1264 _bfd_error_handler (_("%B: invalid MMIX reloc number: %d"), abfd
, r_type
);
1267 cache_ptr
->howto
= &elf_mmix_howto_table
[r_type
];
1270 /* Any MMIX-specific relocation gets here at assembly time or when linking
1271 to other formats (such as mmo); this is the relocation function from
1272 the reloc_table. We don't get here for final pure ELF linking. */
1274 static bfd_reloc_status_type
1275 mmix_elf_reloc (bfd
*abfd
,
1276 arelent
*reloc_entry
,
1279 asection
*input_section
,
1281 char **error_message
)
1284 bfd_reloc_status_type r
;
1285 asection
*reloc_target_output_section
;
1286 bfd_reloc_status_type flag
= bfd_reloc_ok
;
1287 bfd_vma output_base
= 0;
1289 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1290 input_section
, output_bfd
, error_message
);
1292 /* If that was all that was needed (i.e. this isn't a final link, only
1293 some segment adjustments), we're done. */
1294 if (r
!= bfd_reloc_continue
)
1297 if (bfd_is_und_section (symbol
->section
)
1298 && (symbol
->flags
& BSF_WEAK
) == 0
1299 && output_bfd
== (bfd
*) NULL
)
1300 return bfd_reloc_undefined
;
1302 /* Is the address of the relocation really within the section? */
1303 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1304 return bfd_reloc_outofrange
;
1306 /* Work out which section the relocation is targeted at and the
1307 initial relocation command value. */
1309 /* Get symbol value. (Common symbols are special.) */
1310 if (bfd_is_com_section (symbol
->section
))
1313 relocation
= symbol
->value
;
1315 reloc_target_output_section
= bfd_get_output_section (symbol
);
1317 /* Here the variable relocation holds the final address of the symbol we
1318 are relocating against, plus any addend. */
1322 output_base
= reloc_target_output_section
->vma
;
1324 relocation
+= output_base
+ symbol
->section
->output_offset
;
1326 if (output_bfd
!= (bfd
*) NULL
)
1328 /* Add in supplied addend. */
1329 relocation
+= reloc_entry
->addend
;
1331 /* This is a partial relocation, and we want to apply the
1332 relocation to the reloc entry rather than the raw data.
1333 Modify the reloc inplace to reflect what we now know. */
1334 reloc_entry
->addend
= relocation
;
1335 reloc_entry
->address
+= input_section
->output_offset
;
1339 return mmix_final_link_relocate (reloc_entry
->howto
, input_section
,
1340 data
, reloc_entry
->address
,
1341 reloc_entry
->addend
, relocation
,
1342 bfd_asymbol_name (symbol
),
1343 reloc_target_output_section
,
1347 /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
1348 for guidance if you're thinking of copying this. */
1351 mmix_elf_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1352 struct bfd_link_info
*info
,
1354 asection
*input_section
,
1356 Elf_Internal_Rela
*relocs
,
1357 Elf_Internal_Sym
*local_syms
,
1358 asection
**local_sections
)
1360 Elf_Internal_Shdr
*symtab_hdr
;
1361 struct elf_link_hash_entry
**sym_hashes
;
1362 Elf_Internal_Rela
*rel
;
1363 Elf_Internal_Rela
*relend
;
1367 size
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
1368 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1369 sym_hashes
= elf_sym_hashes (input_bfd
);
1370 relend
= relocs
+ input_section
->reloc_count
;
1372 /* Zero the stub area before we start. */
1373 if (input_section
->rawsize
!= 0
1374 && input_section
->size
> input_section
->rawsize
)
1375 memset (contents
+ input_section
->rawsize
, 0,
1376 input_section
->size
- input_section
->rawsize
);
1378 for (rel
= relocs
; rel
< relend
; rel
++)
1380 reloc_howto_type
*howto
;
1381 unsigned long r_symndx
;
1382 Elf_Internal_Sym
*sym
;
1384 struct elf_link_hash_entry
*h
;
1386 bfd_reloc_status_type r
;
1387 const char *name
= NULL
;
1389 bfd_boolean undefined_signalled
= FALSE
;
1391 r_type
= ELF64_R_TYPE (rel
->r_info
);
1393 if (r_type
== R_MMIX_GNU_VTINHERIT
1394 || r_type
== R_MMIX_GNU_VTENTRY
)
1397 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1399 howto
= elf_mmix_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
1404 if (r_symndx
< symtab_hdr
->sh_info
)
1406 sym
= local_syms
+ r_symndx
;
1407 sec
= local_sections
[r_symndx
];
1408 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1410 name
= bfd_elf_string_from_elf_section (input_bfd
,
1411 symtab_hdr
->sh_link
,
1414 name
= bfd_section_name (input_bfd
, sec
);
1418 bfd_boolean unresolved_reloc
, ignored
;
1420 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1421 r_symndx
, symtab_hdr
, sym_hashes
,
1423 unresolved_reloc
, undefined_signalled
,
1425 name
= h
->root
.root
.string
;
1428 if (sec
!= NULL
&& discarded_section (sec
))
1429 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
1430 rel
, 1, relend
, howto
, 0, contents
);
1432 if (bfd_link_relocatable (info
))
1434 /* This is a relocatable link. For most relocs we don't have to
1435 change anything, unless the reloc is against a section
1436 symbol, in which case we have to adjust according to where
1437 the section symbol winds up in the output section. */
1438 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1439 rel
->r_addend
+= sec
->output_offset
;
1441 /* For PUSHJ stub relocs however, we may need to change the
1442 reloc and the section contents, if the reloc doesn't reach
1443 beyond the end of the output section and previous stubs.
1444 Then we change the section contents to be a PUSHJ to the end
1445 of the input section plus stubs (we can do that without using
1446 a reloc), and then we change the reloc to be a R_MMIX_PUSHJ
1447 at the stub location. */
1448 if (r_type
== R_MMIX_PUSHJ_STUBBABLE
)
1450 /* We've already checked whether we need a stub; use that
1452 if (mmix_elf_section_data (input_section
)->pjs
.stub_size
[pjsno
]
1455 Elf_Internal_Rela relcpy
;
1457 if (mmix_elf_section_data (input_section
)
1458 ->pjs
.stub_size
[pjsno
] != MAX_PUSHJ_STUB_SIZE
)
1461 /* There's already a PUSHJ insn there, so just fill in
1462 the offset bits to the stub. */
1463 if (mmix_final_link_relocate (elf_mmix_howto_table
1470 ->output_section
->vma
1471 + input_section
->output_offset
1473 + mmix_elf_section_data (input_section
)
1475 NULL
, NULL
, NULL
) != bfd_reloc_ok
)
1478 /* Put a JMP insn at the stub; it goes with the
1479 R_MMIX_JMP reloc. */
1480 bfd_put_32 (output_bfd
, JMP_INSN_BYTE
<< 24,
1483 + mmix_elf_section_data (input_section
)
1486 /* Change the reloc to be at the stub, and to a full
1487 R_MMIX_JMP reloc. */
1488 rel
->r_info
= ELF64_R_INFO (r_symndx
, R_MMIX_JMP
);
1491 + mmix_elf_section_data (input_section
)
1494 mmix_elf_section_data (input_section
)->pjs
.stub_offset
1495 += MAX_PUSHJ_STUB_SIZE
;
1497 /* Shift this reloc to the end of the relocs to maintain
1498 the r_offset sorted reloc order. */
1500 memmove (rel
, rel
+ 1, (char *) relend
- (char *) rel
);
1501 relend
[-1] = relcpy
;
1503 /* Back up one reloc, or else we'd skip the next reloc
1513 r
= mmix_final_link_relocate (howto
, input_section
,
1514 contents
, rel
->r_offset
,
1515 rel
->r_addend
, relocation
, name
, sec
, NULL
);
1517 if (r
!= bfd_reloc_ok
)
1519 const char * msg
= (const char *) NULL
;
1523 case bfd_reloc_overflow
:
1524 info
->callbacks
->reloc_overflow
1525 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1526 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
1529 case bfd_reloc_undefined
:
1530 /* We may have sent this message above. */
1531 if (! undefined_signalled
)
1532 info
->callbacks
->undefined_symbol
1533 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
1534 undefined_signalled
= TRUE
;
1537 case bfd_reloc_outofrange
:
1538 msg
= _("internal error: out of range error");
1541 case bfd_reloc_notsupported
:
1542 msg
= _("internal error: unsupported relocation error");
1545 case bfd_reloc_dangerous
:
1546 msg
= _("internal error: dangerous relocation");
1550 msg
= _("internal error: unknown error");
1555 (*info
->callbacks
->warning
) (info
, msg
, name
, input_bfd
,
1556 input_section
, rel
->r_offset
);
1563 /* Perform a single relocation. By default we use the standard BFD
1564 routines. A few relocs we have to do ourselves. */
1566 static bfd_reloc_status_type
1567 mmix_final_link_relocate (reloc_howto_type
*howto
, asection
*input_section
,
1568 bfd_byte
*contents
, bfd_vma r_offset
,
1569 bfd_signed_vma r_addend
, bfd_vma relocation
,
1570 const char *symname
, asection
*symsec
,
1571 char **error_message
)
1573 bfd_reloc_status_type r
= bfd_reloc_ok
;
1575 = (input_section
->output_section
->vma
1576 + input_section
->output_offset
1579 = (bfd_signed_vma
) relocation
+ r_addend
;
1581 switch (howto
->type
)
1583 /* All these are PC-relative. */
1584 case R_MMIX_PUSHJ_STUBBABLE
:
1586 case R_MMIX_CBRANCH
:
1591 contents
+= r_offset
;
1593 srel
-= (input_section
->output_section
->vma
1594 + input_section
->output_offset
1597 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1598 addr
, srel
, error_message
);
1601 case R_MMIX_BASE_PLUS_OFFSET
:
1603 return bfd_reloc_undefined
;
1605 /* Check that we're not relocating against a register symbol. */
1606 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1607 MMIX_REG_CONTENTS_SECTION_NAME
) == 0
1608 || strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1609 MMIX_REG_SECTION_NAME
) == 0)
1611 /* Note: This is separated out into two messages in order
1612 to ease the translation into other languages. */
1613 if (symname
== NULL
|| *symname
== 0)
1615 /* xgettext:c-format */
1616 (_("%B: base-plus-offset relocation against register symbol:"
1617 " (unknown) in %A"),
1618 input_section
->owner
, symsec
);
1621 /* xgettext:c-format */
1622 (_("%B: base-plus-offset relocation against register symbol:"
1624 input_section
->owner
, symname
, symsec
);
1625 return bfd_reloc_overflow
;
1629 case R_MMIX_REG_OR_BYTE
:
1631 /* For now, we handle these alike. They must refer to an register
1632 symbol, which is either relative to the register section and in
1633 the range 0..255, or is in the register contents section with vma
1636 /* FIXME: A better way to check for reg contents section?
1637 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
1639 return bfd_reloc_undefined
;
1641 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1642 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1644 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1646 /* The bfd_reloc_outofrange return value, though intuitively
1647 a better value, will not get us an error. */
1648 return bfd_reloc_overflow
;
1652 else if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1653 MMIX_REG_SECTION_NAME
) == 0)
1655 if (srel
< 0 || srel
> 255)
1656 /* The bfd_reloc_outofrange return value, though intuitively a
1657 better value, will not get us an error. */
1658 return bfd_reloc_overflow
;
1662 /* Note: This is separated out into two messages in order
1663 to ease the translation into other languages. */
1664 if (symname
== NULL
|| *symname
== 0)
1666 /* xgettext:c-format */
1667 (_("%B: register relocation against non-register symbol:"
1668 " (unknown) in %A"),
1669 input_section
->owner
, symsec
);
1672 /* xgettext:c-format */
1673 (_("%B: register relocation against non-register symbol:"
1675 input_section
->owner
, symname
, symsec
);
1677 /* The bfd_reloc_outofrange return value, though intuitively a
1678 better value, will not get us an error. */
1679 return bfd_reloc_overflow
;
1682 contents
+= r_offset
;
1683 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1684 addr
, srel
, error_message
);
1688 /* This isn't a real relocation, it's just an assertion that the
1689 final relocation value corresponds to a local register. We
1690 ignore the actual relocation; nothing is changed. */
1693 = bfd_get_section_by_name (input_section
->output_section
->owner
,
1694 MMIX_REG_CONTENTS_SECTION_NAME
);
1695 bfd_vma first_global
;
1697 /* Check that this is an absolute value, or a reference to the
1698 register contents section or the register (symbol) section.
1699 Absolute numbers can get here as undefined section. Undefined
1700 symbols are signalled elsewhere, so there's no conflict in us
1701 accidentally handling it. */
1702 if (!bfd_is_abs_section (symsec
)
1703 && !bfd_is_und_section (symsec
)
1704 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1705 MMIX_REG_CONTENTS_SECTION_NAME
) != 0
1706 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1707 MMIX_REG_SECTION_NAME
) != 0)
1710 (_("%B: directive LOCAL valid only with a register or absolute value"),
1711 input_section
->owner
);
1713 return bfd_reloc_overflow
;
1716 /* If we don't have a register contents section, then $255 is the
1717 first global register. */
1723 = bfd_get_section_vma (input_section
->output_section
->owner
,
1725 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1726 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1728 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1729 /* The bfd_reloc_outofrange return value, though
1730 intuitively a better value, will not get us an error. */
1731 return bfd_reloc_overflow
;
1736 if ((bfd_vma
) srel
>= first_global
)
1738 /* FIXME: Better error message. */
1740 /* xgettext:c-format */
1741 (_("%B: LOCAL directive: Register $%Ld is not a local register."
1742 " First global register is $%Ld."),
1743 input_section
->owner
, srel
, first_global
);
1745 return bfd_reloc_overflow
;
1752 r
= _bfd_final_link_relocate (howto
, input_section
->owner
, input_section
,
1754 relocation
, r_addend
);
1760 /* Return the section that should be marked against GC for a given
1764 mmix_elf_gc_mark_hook (asection
*sec
,
1765 struct bfd_link_info
*info
,
1766 Elf_Internal_Rela
*rel
,
1767 struct elf_link_hash_entry
*h
,
1768 Elf_Internal_Sym
*sym
)
1771 switch (ELF64_R_TYPE (rel
->r_info
))
1773 case R_MMIX_GNU_VTINHERIT
:
1774 case R_MMIX_GNU_VTENTRY
:
1778 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1781 /* Sort register relocs to come before expanding relocs. */
1784 mmix_elf_sort_relocs (const void * p1
, const void * p2
)
1786 const Elf_Internal_Rela
*r1
= (const Elf_Internal_Rela
*) p1
;
1787 const Elf_Internal_Rela
*r2
= (const Elf_Internal_Rela
*) p2
;
1788 int r1_is_reg
, r2_is_reg
;
1790 /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1792 if ((r1
->r_offset
& ~(bfd_vma
) 3) > (r2
->r_offset
& ~(bfd_vma
) 3))
1794 else if ((r1
->r_offset
& ~(bfd_vma
) 3) < (r2
->r_offset
& ~(bfd_vma
) 3))
1798 = (ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG_OR_BYTE
1799 || ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG
);
1801 = (ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG_OR_BYTE
1802 || ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG
);
1803 if (r1_is_reg
!= r2_is_reg
)
1804 return r2_is_reg
- r1_is_reg
;
1806 /* Neither or both are register relocs. Then sort on full offset. */
1807 if (r1
->r_offset
> r2
->r_offset
)
1809 else if (r1
->r_offset
< r2
->r_offset
)
1814 /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
1817 mmix_elf_check_common_relocs (bfd
*abfd
,
1818 struct bfd_link_info
*info
,
1820 const Elf_Internal_Rela
*relocs
)
1822 bfd
*bpo_greg_owner
= NULL
;
1823 asection
*allocated_gregs_section
= NULL
;
1824 struct bpo_greg_section_info
*gregdata
= NULL
;
1825 struct bpo_reloc_section_info
*bpodata
= NULL
;
1826 const Elf_Internal_Rela
*rel
;
1827 const Elf_Internal_Rela
*rel_end
;
1829 /* We currently have to abuse this COFF-specific member, since there's
1830 no target-machine-dedicated member. There's no alternative outside
1831 the bfd_link_info struct; we can't specialize a hash-table since
1832 they're different between ELF and mmo. */
1833 bpo_greg_owner
= (bfd
*) info
->base_file
;
1835 rel_end
= relocs
+ sec
->reloc_count
;
1836 for (rel
= relocs
; rel
< rel_end
; rel
++)
1838 switch (ELF64_R_TYPE (rel
->r_info
))
1840 /* This relocation causes a GREG allocation. We need to count
1841 them, and we need to create a section for them, so we need an
1842 object to fake as the owner of that section. We can't use
1843 the ELF dynobj for this, since the ELF bits assume lots of
1844 DSO-related stuff if that member is non-NULL. */
1845 case R_MMIX_BASE_PLUS_OFFSET
:
1846 /* We don't do anything with this reloc for a relocatable link. */
1847 if (bfd_link_relocatable (info
))
1850 if (bpo_greg_owner
== NULL
)
1852 bpo_greg_owner
= abfd
;
1853 info
->base_file
= bpo_greg_owner
;
1856 if (allocated_gregs_section
== NULL
)
1857 allocated_gregs_section
1858 = bfd_get_section_by_name (bpo_greg_owner
,
1859 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
1861 if (allocated_gregs_section
== NULL
)
1863 allocated_gregs_section
1864 = bfd_make_section_with_flags (bpo_greg_owner
,
1865 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
,
1868 | SEC_LINKER_CREATED
));
1869 /* Setting both SEC_ALLOC and SEC_LOAD means the section is
1870 treated like any other section, and we'd get errors for
1871 address overlap with the text section. Let's set none of
1872 those flags, as that is what currently happens for usual
1873 GREG allocations, and that works. */
1874 if (allocated_gregs_section
== NULL
1875 || !bfd_set_section_alignment (bpo_greg_owner
,
1876 allocated_gregs_section
,
1880 gregdata
= (struct bpo_greg_section_info
*)
1881 bfd_zalloc (bpo_greg_owner
, sizeof (struct bpo_greg_section_info
));
1882 if (gregdata
== NULL
)
1884 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
1887 else if (gregdata
== NULL
)
1889 = mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
;
1891 /* Get ourselves some auxiliary info for the BPO-relocs. */
1892 if (bpodata
== NULL
)
1894 /* No use doing a separate iteration pass to find the upper
1895 limit - just use the number of relocs. */
1896 bpodata
= (struct bpo_reloc_section_info
*)
1897 bfd_alloc (bpo_greg_owner
,
1898 sizeof (struct bpo_reloc_section_info
)
1899 * (sec
->reloc_count
+ 1));
1900 if (bpodata
== NULL
)
1902 mmix_elf_section_data (sec
)->bpo
.reloc
= bpodata
;
1903 bpodata
->first_base_plus_offset_reloc
1904 = bpodata
->bpo_index
1905 = gregdata
->n_max_bpo_relocs
;
1906 bpodata
->bpo_greg_section
1907 = allocated_gregs_section
;
1908 bpodata
->n_bpo_relocs_this_section
= 0;
1911 bpodata
->n_bpo_relocs_this_section
++;
1912 gregdata
->n_max_bpo_relocs
++;
1914 /* We don't get another chance to set this before GC; we've not
1915 set up any hook that runs before GC. */
1916 gregdata
->n_bpo_relocs
1917 = gregdata
->n_max_bpo_relocs
;
1920 case R_MMIX_PUSHJ_STUBBABLE
:
1921 mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
++;
1926 /* Allocate per-reloc stub storage and initialize it to the max stub
1928 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
!= 0)
1932 mmix_elf_section_data (sec
)->pjs
.stub_size
1933 = bfd_alloc (abfd
, mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
1934 * sizeof (mmix_elf_section_data (sec
)
1935 ->pjs
.stub_size
[0]));
1936 if (mmix_elf_section_data (sec
)->pjs
.stub_size
== NULL
)
1939 for (i
= 0; i
< mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
; i
++)
1940 mmix_elf_section_data (sec
)->pjs
.stub_size
[i
] = MAX_PUSHJ_STUB_SIZE
;
1946 /* Look through the relocs for a section during the first phase. */
1949 mmix_elf_check_relocs (bfd
*abfd
,
1950 struct bfd_link_info
*info
,
1952 const Elf_Internal_Rela
*relocs
)
1954 Elf_Internal_Shdr
*symtab_hdr
;
1955 struct elf_link_hash_entry
**sym_hashes
;
1956 const Elf_Internal_Rela
*rel
;
1957 const Elf_Internal_Rela
*rel_end
;
1959 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1960 sym_hashes
= elf_sym_hashes (abfd
);
1962 /* First we sort the relocs so that any register relocs come before
1963 expansion-relocs to the same insn. FIXME: Not done for mmo. */
1964 qsort ((void *) relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
1965 mmix_elf_sort_relocs
);
1967 /* Do the common part. */
1968 if (!mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
))
1971 if (bfd_link_relocatable (info
))
1974 rel_end
= relocs
+ sec
->reloc_count
;
1975 for (rel
= relocs
; rel
< rel_end
; rel
++)
1977 struct elf_link_hash_entry
*h
;
1978 unsigned long r_symndx
;
1980 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1981 if (r_symndx
< symtab_hdr
->sh_info
)
1985 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1986 while (h
->root
.type
== bfd_link_hash_indirect
1987 || h
->root
.type
== bfd_link_hash_warning
)
1988 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1991 switch (ELF64_R_TYPE (rel
->r_info
))
1993 /* This relocation describes the C++ object vtable hierarchy.
1994 Reconstruct it for later use during GC. */
1995 case R_MMIX_GNU_VTINHERIT
:
1996 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2000 /* This relocation describes which C++ vtable entries are actually
2001 used. Record for later use during GC. */
2002 case R_MMIX_GNU_VTENTRY
:
2003 BFD_ASSERT (h
!= NULL
);
2005 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2014 /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
2015 Copied from elf_link_add_object_symbols. */
2018 _bfd_mmix_check_all_relocs (bfd
*abfd
, struct bfd_link_info
*info
)
2022 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2024 Elf_Internal_Rela
*internal_relocs
;
2027 if ((o
->flags
& SEC_RELOC
) == 0
2028 || o
->reloc_count
== 0
2029 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
2030 && (o
->flags
& SEC_DEBUGGING
) != 0)
2031 || bfd_is_abs_section (o
->output_section
))
2035 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
,
2036 (Elf_Internal_Rela
*) NULL
,
2038 if (internal_relocs
== NULL
)
2041 ok
= mmix_elf_check_common_relocs (abfd
, info
, o
, internal_relocs
);
2043 if (! info
->keep_memory
)
2044 free (internal_relocs
);
2053 /* Change symbols relative to the reg contents section to instead be to
2054 the register section, and scale them down to correspond to the register
2058 mmix_elf_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2059 const char *name ATTRIBUTE_UNUSED
,
2060 Elf_Internal_Sym
*sym
,
2061 asection
*input_sec
,
2062 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2064 if (input_sec
!= NULL
2065 && input_sec
->name
!= NULL
2066 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2067 && strcmp (input_sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2070 sym
->st_shndx
= SHN_REGISTER
;
2076 /* We fake a register section that holds values that are register numbers.
2077 Having a SHN_REGISTER and register section translates better to other
2078 formats (e.g. mmo) than for example a STT_REGISTER attribute.
2079 This section faking is based on a construct in elf32-mips.c. */
2080 static asection mmix_elf_reg_section
;
2081 static asymbol mmix_elf_reg_section_symbol
;
2082 static asymbol
*mmix_elf_reg_section_symbol_ptr
;
2084 /* Handle the special section numbers that a symbol may use. */
2087 mmix_elf_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
2089 elf_symbol_type
*elfsym
;
2091 elfsym
= (elf_symbol_type
*) asym
;
2092 switch (elfsym
->internal_elf_sym
.st_shndx
)
2095 if (mmix_elf_reg_section
.name
== NULL
)
2097 /* Initialize the register section. */
2098 mmix_elf_reg_section
.name
= MMIX_REG_SECTION_NAME
;
2099 mmix_elf_reg_section
.flags
= SEC_NO_FLAGS
;
2100 mmix_elf_reg_section
.output_section
= &mmix_elf_reg_section
;
2101 mmix_elf_reg_section
.symbol
= &mmix_elf_reg_section_symbol
;
2102 mmix_elf_reg_section
.symbol_ptr_ptr
= &mmix_elf_reg_section_symbol_ptr
;
2103 mmix_elf_reg_section_symbol
.name
= MMIX_REG_SECTION_NAME
;
2104 mmix_elf_reg_section_symbol
.flags
= BSF_SECTION_SYM
;
2105 mmix_elf_reg_section_symbol
.section
= &mmix_elf_reg_section
;
2106 mmix_elf_reg_section_symbol_ptr
= &mmix_elf_reg_section_symbol
;
2108 asym
->section
= &mmix_elf_reg_section
;
2116 /* Given a BFD section, try to locate the corresponding ELF section
2120 mmix_elf_section_from_bfd_section (bfd
* abfd ATTRIBUTE_UNUSED
,
2124 if (strcmp (bfd_get_section_name (abfd
, sec
), MMIX_REG_SECTION_NAME
) == 0)
2125 *retval
= SHN_REGISTER
;
2132 /* Hook called by the linker routine which adds symbols from an object
2133 file. We must handle the special SHN_REGISTER section number here.
2135 We also check that we only have *one* each of the section-start
2136 symbols, since otherwise having two with the same value would cause
2137 them to be "merged", but with the contents serialized. */
2140 mmix_elf_add_symbol_hook (bfd
*abfd
,
2141 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2142 Elf_Internal_Sym
*sym
,
2143 const char **namep ATTRIBUTE_UNUSED
,
2144 flagword
*flagsp ATTRIBUTE_UNUSED
,
2146 bfd_vma
*valp ATTRIBUTE_UNUSED
)
2148 if (sym
->st_shndx
== SHN_REGISTER
)
2150 *secp
= bfd_make_section_old_way (abfd
, MMIX_REG_SECTION_NAME
);
2151 (*secp
)->flags
|= SEC_LINKER_CREATED
;
2153 else if ((*namep
)[0] == '_' && (*namep
)[1] == '_' && (*namep
)[2] == '.'
2154 && CONST_STRNEQ (*namep
, MMIX_LOC_SECTION_START_SYMBOL_PREFIX
))
2156 /* See if we have another one. */
2157 struct bfd_link_hash_entry
*h
= bfd_link_hash_lookup (info
->hash
,
2163 if (h
!= NULL
&& h
->type
!= bfd_link_hash_undefined
)
2165 /* How do we get the asymbol (or really: the filename) from h?
2166 h->u.def.section->owner is NULL. */
2168 /* xgettext:c-format */
2169 (_("%B: Error: multiple definition of `%s'; start of %s "
2170 "is set in a earlier linked file\n"),
2172 *namep
+ strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
));
2173 bfd_set_error (bfd_error_bad_value
);
2181 /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
2184 mmix_elf_is_local_label_name (bfd
*abfd
, const char *name
)
2189 /* Also include the default local-label definition. */
2190 if (_bfd_elf_is_local_label_name (abfd
, name
))
2196 /* If there's no ":", or more than one, it's not a local symbol. */
2197 colpos
= strchr (name
, ':');
2198 if (colpos
== NULL
|| strchr (colpos
+ 1, ':') != NULL
)
2201 /* Check that there are remaining characters and that they are digits. */
2205 digits
= strspn (colpos
+ 1, "0123456789");
2206 return digits
!= 0 && colpos
[1 + digits
] == 0;
2209 /* We get rid of the register section here. */
2212 mmix_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
2214 /* We never output a register section, though we create one for
2215 temporary measures. Check that nobody entered contents into it. */
2216 asection
*reg_section
;
2218 reg_section
= bfd_get_section_by_name (abfd
, MMIX_REG_SECTION_NAME
);
2220 if (reg_section
!= NULL
)
2222 /* FIXME: Pass error state gracefully. */
2223 if (bfd_get_section_flags (abfd
, reg_section
) & SEC_HAS_CONTENTS
)
2224 _bfd_abort (__FILE__
, __LINE__
, _("Register section has contents\n"));
2226 /* Really remove the section, if it hasn't already been done. */
2227 if (!bfd_section_removed_from_list (abfd
, reg_section
))
2229 bfd_section_list_remove (abfd
, reg_section
);
2230 --abfd
->section_count
;
2234 if (! bfd_elf_final_link (abfd
, info
))
2237 /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
2238 the regular linker machinery. We do it here, like other targets with
2239 special sections. */
2240 if (info
->base_file
!= NULL
)
2242 asection
*greg_section
2243 = bfd_get_section_by_name ((bfd
*) info
->base_file
,
2244 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2245 if (!bfd_set_section_contents (abfd
,
2246 greg_section
->output_section
,
2247 greg_section
->contents
,
2248 (file_ptr
) greg_section
->output_offset
,
2249 greg_section
->size
))
2255 /* We need to include the maximum size of PUSHJ-stubs in the initial
2256 section size. This is expected to shrink during linker relaxation. */
2259 mmix_set_relaxable_size (bfd
*abfd ATTRIBUTE_UNUSED
,
2263 struct bfd_link_info
*info
= ptr
;
2265 /* Make sure we only do this for section where we know we want this,
2266 otherwise we might end up resetting the size of COMMONs. */
2267 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0)
2270 sec
->rawsize
= sec
->size
;
2271 sec
->size
+= (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2272 * MAX_PUSHJ_STUB_SIZE
);
2274 /* For use in relocatable link, we start with a max stubs size. See
2275 mmix_elf_relax_section. */
2276 if (bfd_link_relocatable (info
) && sec
->output_section
)
2277 mmix_elf_section_data (sec
->output_section
)->pjs
.stubs_size_sum
2278 += (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2279 * MAX_PUSHJ_STUB_SIZE
);
2282 /* Initialize stuff for the linker-generated GREGs to match
2283 R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
2286 _bfd_mmix_before_linker_allocation (bfd
*abfd ATTRIBUTE_UNUSED
,
2287 struct bfd_link_info
*info
)
2289 asection
*bpo_gregs_section
;
2290 bfd
*bpo_greg_owner
;
2291 struct bpo_greg_section_info
*gregdata
;
2295 size_t *bpo_reloc_indexes
;
2298 /* Set the initial size of sections. */
2299 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2300 bfd_map_over_sections (ibfd
, mmix_set_relaxable_size
, info
);
2302 /* The bpo_greg_owner bfd is supposed to have been set by
2303 mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
2304 If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2305 bpo_greg_owner
= (bfd
*) info
->base_file
;
2306 if (bpo_greg_owner
== NULL
)
2310 = bfd_get_section_by_name (bpo_greg_owner
,
2311 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2313 if (bpo_gregs_section
== NULL
)
2316 /* We use the target-data handle in the ELF section data. */
2317 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2318 if (gregdata
== NULL
)
2321 n_gregs
= gregdata
->n_bpo_relocs
;
2322 gregdata
->n_allocated_bpo_gregs
= n_gregs
;
2324 /* When this reaches zero during relaxation, all entries have been
2325 filled in and the size of the linker gregs can be calculated. */
2326 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
= n_gregs
;
2328 /* Set the zeroth-order estimate for the GREGs size. */
2329 gregs_size
= n_gregs
* 8;
2331 if (!bfd_set_section_size (bpo_greg_owner
, bpo_gregs_section
, gregs_size
))
2334 /* Allocate and set up the GREG arrays. They're filled in at relaxation
2335 time. Note that we must use the max number ever noted for the array,
2336 since the index numbers were created before GC. */
2337 gregdata
->reloc_request
2338 = bfd_zalloc (bpo_greg_owner
,
2339 sizeof (struct bpo_reloc_request
)
2340 * gregdata
->n_max_bpo_relocs
);
2342 gregdata
->bpo_reloc_indexes
2344 = bfd_alloc (bpo_greg_owner
,
2345 gregdata
->n_max_bpo_relocs
2347 if (bpo_reloc_indexes
== NULL
)
2350 /* The default order is an identity mapping. */
2351 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2353 bpo_reloc_indexes
[i
] = i
;
2354 gregdata
->reloc_request
[i
].bpo_reloc_no
= i
;
2360 /* Fill in contents in the linker allocated gregs. Everything is
2361 calculated at this point; we just move the contents into place here. */
2364 _bfd_mmix_after_linker_allocation (bfd
*abfd ATTRIBUTE_UNUSED
,
2365 struct bfd_link_info
*link_info
)
2367 asection
*bpo_gregs_section
;
2368 bfd
*bpo_greg_owner
;
2369 struct bpo_greg_section_info
*gregdata
;
2375 /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
2376 when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
2377 object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2378 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2379 if (bpo_greg_owner
== NULL
)
2383 = bfd_get_section_by_name (bpo_greg_owner
,
2384 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2386 /* This can't happen without DSO handling. When DSOs are handled
2387 without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
2389 if (bpo_gregs_section
== NULL
)
2392 /* We use the target-data handle in the ELF section data. */
2394 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2395 if (gregdata
== NULL
)
2398 n_gregs
= gregdata
->n_allocated_bpo_gregs
;
2400 bpo_gregs_section
->contents
2401 = contents
= bfd_alloc (bpo_greg_owner
, bpo_gregs_section
->size
);
2402 if (contents
== NULL
)
2405 /* Sanity check: If these numbers mismatch, some relocation has not been
2406 accounted for and the rest of gregdata is probably inconsistent.
2407 It's a bug, but it's more helpful to identify it than segfaulting
2409 if (gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2410 != gregdata
->n_bpo_relocs
)
2413 /* xgettext:c-format */
2414 (_("Internal inconsistency: remaining %lu != max %lu.\n\
2415 Please report this bug."),
2416 (unsigned long) gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2417 (unsigned long) gregdata
->n_bpo_relocs
);
2421 for (lastreg
= 255, i
= 0, j
= 0; j
< n_gregs
; i
++)
2422 if (gregdata
->reloc_request
[i
].regindex
!= lastreg
)
2424 bfd_put_64 (bpo_greg_owner
, gregdata
->reloc_request
[i
].value
,
2426 lastreg
= gregdata
->reloc_request
[i
].regindex
;
2433 /* Sort valid relocs to come before non-valid relocs, then on increasing
2437 bpo_reloc_request_sort_fn (const void * p1
, const void * p2
)
2439 const struct bpo_reloc_request
*r1
= (const struct bpo_reloc_request
*) p1
;
2440 const struct bpo_reloc_request
*r2
= (const struct bpo_reloc_request
*) p2
;
2442 /* Primary function is validity; non-valid relocs sorted after valid
2444 if (r1
->valid
!= r2
->valid
)
2445 return r2
->valid
- r1
->valid
;
2447 /* Then sort on value. Don't simplify and return just the difference of
2448 the values: the upper bits of the 64-bit value would be truncated on
2449 a host with 32-bit ints. */
2450 if (r1
->value
!= r2
->value
)
2451 return r1
->value
> r2
->value
? 1 : -1;
2453 /* As a last re-sort, use the relocation number, so we get a stable
2454 sort. The *addresses* aren't stable since items are swapped during
2455 sorting. It depends on the qsort implementation if this actually
2457 return r1
->bpo_reloc_no
> r2
->bpo_reloc_no
2458 ? 1 : (r1
->bpo_reloc_no
< r2
->bpo_reloc_no
? -1 : 0);
2461 /* For debug use only. Dumps the global register allocations resulting
2462 from base-plus-offset relocs. */
2465 mmix_dump_bpo_gregs (struct bfd_link_info
*link_info
,
2466 void (*pf
) (const char *fmt
, ...))
2468 bfd
*bpo_greg_owner
;
2469 asection
*bpo_gregs_section
;
2470 struct bpo_greg_section_info
*gregdata
;
2473 if (link_info
== NULL
|| link_info
->base_file
== NULL
)
2476 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2479 = bfd_get_section_by_name (bpo_greg_owner
,
2480 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2482 if (bpo_gregs_section
== NULL
)
2485 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2486 if (gregdata
== NULL
)
2490 pf
= _bfd_error_handler
;
2492 /* These format strings are not translated. They are for debug purposes
2493 only and never displayed to an end user. Should they escape, we
2494 surely want them in original. */
2495 (*pf
) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
2496 n_allocated_bpo_gregs: %u\n", gregdata
->n_bpo_relocs
,
2497 gregdata
->n_max_bpo_relocs
,
2498 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2499 gregdata
->n_allocated_bpo_gregs
);
2501 if (gregdata
->reloc_request
)
2502 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2503 (*pf
) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
2505 (gregdata
->bpo_reloc_indexes
!= NULL
2506 ? gregdata
->bpo_reloc_indexes
[i
] : (size_t) -1),
2507 gregdata
->reloc_request
[i
].bpo_reloc_no
,
2508 gregdata
->reloc_request
[i
].valid
,
2510 (unsigned long) (gregdata
->reloc_request
[i
].value
>> 32),
2511 (unsigned long) gregdata
->reloc_request
[i
].value
,
2512 gregdata
->reloc_request
[i
].regindex
,
2513 gregdata
->reloc_request
[i
].offset
);
2516 /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
2517 when the last such reloc is done, an index-array is sorted according to
2518 the values and iterated over to produce register numbers (indexed by 0
2519 from the first allocated register number) and offsets for use in real
2520 relocation. (N.B.: Relocatable runs are handled, not just punted.)
2522 PUSHJ stub accounting is also done here.
2524 Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
2527 mmix_elf_relax_section (bfd
*abfd
,
2529 struct bfd_link_info
*link_info
,
2532 Elf_Internal_Shdr
*symtab_hdr
;
2533 Elf_Internal_Rela
*internal_relocs
;
2534 Elf_Internal_Rela
*irel
, *irelend
;
2535 asection
*bpo_gregs_section
= NULL
;
2536 struct bpo_greg_section_info
*gregdata
;
2537 struct bpo_reloc_section_info
*bpodata
2538 = mmix_elf_section_data (sec
)->bpo
.reloc
;
2539 /* The initialization is to quiet compiler warnings. The value is to
2540 spot a missing actual initialization. */
2541 size_t bpono
= (size_t) -1;
2543 Elf_Internal_Sym
*isymbuf
= NULL
;
2544 bfd_size_type size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
2546 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
= 0;
2548 /* Assume nothing changes. */
2551 /* We don't have to do anything if this section does not have relocs, or
2552 if this is not a code section. */
2553 if ((sec
->flags
& SEC_RELOC
) == 0
2554 || sec
->reloc_count
== 0
2555 || (sec
->flags
& SEC_CODE
) == 0
2556 || (sec
->flags
& SEC_LINKER_CREATED
) != 0
2557 /* If no R_MMIX_BASE_PLUS_OFFSET relocs and no PUSHJ-stub relocs,
2558 then nothing to do. */
2560 && mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0))
2563 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2565 if (bpodata
!= NULL
)
2567 bpo_gregs_section
= bpodata
->bpo_greg_section
;
2568 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2569 bpono
= bpodata
->first_base_plus_offset_reloc
;
2574 /* Get a copy of the native relocations. */
2576 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
,
2577 (Elf_Internal_Rela
*) NULL
,
2578 link_info
->keep_memory
);
2579 if (internal_relocs
== NULL
)
2582 /* Walk through them looking for relaxing opportunities. */
2583 irelend
= internal_relocs
+ sec
->reloc_count
;
2584 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2587 struct elf_link_hash_entry
*h
= NULL
;
2589 /* We only process two relocs. */
2590 if (ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_BASE_PLUS_OFFSET
2591 && ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_PUSHJ_STUBBABLE
)
2594 /* We process relocs in a distinctly different way when this is a
2595 relocatable link (for one, we don't look at symbols), so we avoid
2596 mixing its code with that for the "normal" relaxation. */
2597 if (bfd_link_relocatable (link_info
))
2599 /* The only transformation in a relocatable link is to generate
2600 a full stub at the location of the stub calculated for the
2601 input section, if the relocated stub location, the end of the
2602 output section plus earlier stubs, cannot be reached. Thus
2603 relocatable linking can only lead to worse code, but it still
2605 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_PUSHJ_STUBBABLE
)
2607 /* If we can reach the end of the output-section and beyond
2608 any current stubs, then we don't need a stub for this
2609 reloc. The relaxed order of output stub allocation may
2610 not exactly match the straightforward order, so we always
2611 assume presence of output stubs, which will allow
2612 relaxation only on relocations indifferent to the
2613 presence of output stub allocations for other relocations
2614 and thus the order of output stub allocation. */
2615 if (bfd_check_overflow (complain_overflow_signed
,
2618 bfd_arch_bits_per_address (abfd
),
2619 /* Output-stub location. */
2620 sec
->output_section
->rawsize
2621 + (mmix_elf_section_data (sec
2623 ->pjs
.stubs_size_sum
)
2624 /* Location of this PUSHJ reloc. */
2625 - (sec
->output_offset
+ irel
->r_offset
)
2626 /* Don't count *this* stub twice. */
2627 - (mmix_elf_section_data (sec
)
2628 ->pjs
.stub_size
[pjsno
]
2629 + MAX_PUSHJ_STUB_SIZE
))
2631 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2633 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2634 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2642 /* Get the value of the symbol referred to by the reloc. */
2643 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2645 /* A local symbol. */
2646 Elf_Internal_Sym
*isym
;
2649 /* Read this BFD's local symbols if we haven't already. */
2650 if (isymbuf
== NULL
)
2652 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2653 if (isymbuf
== NULL
)
2654 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2655 symtab_hdr
->sh_info
, 0,
2661 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
2662 if (isym
->st_shndx
== SHN_UNDEF
)
2663 sym_sec
= bfd_und_section_ptr
;
2664 else if (isym
->st_shndx
== SHN_ABS
)
2665 sym_sec
= bfd_abs_section_ptr
;
2666 else if (isym
->st_shndx
== SHN_COMMON
)
2667 sym_sec
= bfd_com_section_ptr
;
2669 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2670 symval
= (isym
->st_value
2671 + sym_sec
->output_section
->vma
2672 + sym_sec
->output_offset
);
2678 /* An external symbol. */
2679 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2680 h
= elf_sym_hashes (abfd
)[indx
];
2681 BFD_ASSERT (h
!= NULL
);
2682 if (h
->root
.type
== bfd_link_hash_undefweak
)
2683 /* FIXME: for R_MMIX_PUSHJ_STUBBABLE, there are alternatives to
2684 the canonical value 0 for an unresolved weak symbol to
2685 consider: as the debug-friendly approach, resolve to "abort"
2686 (or a port-specific function), or as the space-friendly
2687 approach resolve to the next instruction (like some other
2688 ports, notably ARM and AArch64). These alternatives require
2689 matching code in mmix_elf_perform_relocation or its caller. */
2691 else if (h
->root
.type
== bfd_link_hash_defined
2692 || h
->root
.type
== bfd_link_hash_defweak
)
2693 symval
= (h
->root
.u
.def
.value
2694 + h
->root
.u
.def
.section
->output_section
->vma
2695 + h
->root
.u
.def
.section
->output_offset
);
2698 /* This appears to be a reference to an undefined symbol. Just
2699 ignore it--it will be caught by the regular reloc processing.
2700 We need to keep BPO reloc accounting consistent, though
2701 else we'll abort instead of emitting an error message. */
2702 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_BASE_PLUS_OFFSET
2703 && gregdata
!= NULL
)
2705 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2712 if (ELF64_R_TYPE (irel
->r_info
) == (int) R_MMIX_PUSHJ_STUBBABLE
)
2714 bfd_vma value
= symval
+ irel
->r_addend
;
2716 = (sec
->output_section
->vma
2717 + sec
->output_offset
2720 = (sec
->output_section
->vma
2721 + sec
->output_offset
2723 + mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
);
2725 if ((value
& 3) == 0
2726 && bfd_check_overflow (complain_overflow_signed
,
2729 bfd_arch_bits_per_address (abfd
),
2732 ? mmix_elf_section_data (sec
)
2733 ->pjs
.stub_size
[pjsno
]
2736 /* If the reloc fits, no stub is needed. */
2737 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2739 /* Maybe we can get away with just a JMP insn? */
2740 if ((value
& 3) == 0
2741 && bfd_check_overflow (complain_overflow_signed
,
2744 bfd_arch_bits_per_address (abfd
),
2747 ? mmix_elf_section_data (sec
)
2748 ->pjs
.stub_size
[pjsno
] - 4
2751 /* Yep, account for a stub consisting of a single JMP insn. */
2752 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 4;
2754 /* Nope, go for the full insn stub. It doesn't seem useful to
2755 emit the intermediate sizes; those will only be useful for
2756 a >64M program assuming contiguous code. */
2757 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
]
2758 = MAX_PUSHJ_STUB_SIZE
;
2760 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2761 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2766 /* We're looking at a R_MMIX_BASE_PLUS_OFFSET reloc. */
2768 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
]].value
2769 = symval
+ irel
->r_addend
;
2770 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
++]].valid
= TRUE
;
2771 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2774 /* Check if that was the last BPO-reloc. If so, sort the values and
2775 calculate how many registers we need to cover them. Set the size of
2776 the linker gregs, and if the number of registers changed, indicate
2777 that we need to relax some more because we have more work to do. */
2778 if (gregdata
!= NULL
2779 && gregdata
->n_remaining_bpo_relocs_this_relaxation_round
== 0)
2785 /* First, reset the remaining relocs for the next round. */
2786 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2787 = gregdata
->n_bpo_relocs
;
2789 qsort (gregdata
->reloc_request
,
2790 gregdata
->n_max_bpo_relocs
,
2791 sizeof (struct bpo_reloc_request
),
2792 bpo_reloc_request_sort_fn
);
2794 /* Recalculate indexes. When we find a change (however unlikely
2795 after the initial iteration), we know we need to relax again,
2796 since items in the GREG-array are sorted by increasing value and
2797 stored in the relaxation phase. */
2798 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2799 if (gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2802 gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2807 /* Allocate register numbers (indexing from 0). Stop at the first
2809 for (i
= 0, regindex
= 0, prev_base
= gregdata
->reloc_request
[0].value
;
2810 i
< gregdata
->n_bpo_relocs
;
2813 if (gregdata
->reloc_request
[i
].value
> prev_base
+ 255)
2816 prev_base
= gregdata
->reloc_request
[i
].value
;
2818 gregdata
->reloc_request
[i
].regindex
= regindex
;
2819 gregdata
->reloc_request
[i
].offset
2820 = gregdata
->reloc_request
[i
].value
- prev_base
;
2823 /* If it's not the same as the last time, we need to relax again,
2824 because the size of the section has changed. I'm not sure we
2825 actually need to do any adjustments since the shrinking happens
2826 at the start of this section, but better safe than sorry. */
2827 if (gregdata
->n_allocated_bpo_gregs
!= regindex
+ 1)
2829 gregdata
->n_allocated_bpo_gregs
= regindex
+ 1;
2833 bpo_gregs_section
->size
= (regindex
+ 1) * 8;
2836 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2838 if (! link_info
->keep_memory
)
2842 /* Cache the symbols for elf_link_input_bfd. */
2843 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2847 BFD_ASSERT(pjsno
== mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
);
2849 if (internal_relocs
!= NULL
2850 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2851 free (internal_relocs
);
2853 if (sec
->size
< size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2856 if (sec
->size
> size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2858 sec
->size
= size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
;
2865 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2867 if (internal_relocs
!= NULL
2868 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2869 free (internal_relocs
);
2873 #define ELF_ARCH bfd_arch_mmix
2874 #define ELF_MACHINE_CODE EM_MMIX
2876 /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
2877 However, that's too much for something somewhere in the linker part of
2878 BFD; perhaps the start-address has to be a non-zero multiple of this
2879 number, or larger than this number. The symptom is that the linker
2880 complains: "warning: allocated section `.text' not in segment". We
2881 settle for 64k; the page-size used in examples is 8k.
2882 #define ELF_MAXPAGESIZE 0x10000
2884 Unfortunately, this causes excessive padding in the supposedly small
2885 for-education programs that are the expected usage (where people would
2886 inspect output). We stick to 256 bytes just to have *some* default
2888 #define ELF_MAXPAGESIZE 0x100
2890 #define TARGET_BIG_SYM mmix_elf64_vec
2891 #define TARGET_BIG_NAME "elf64-mmix"
2893 #define elf_info_to_howto_rel NULL
2894 #define elf_info_to_howto mmix_info_to_howto_rela
2895 #define elf_backend_relocate_section mmix_elf_relocate_section
2896 #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
2898 #define elf_backend_link_output_symbol_hook \
2899 mmix_elf_link_output_symbol_hook
2900 #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
2902 #define elf_backend_check_relocs mmix_elf_check_relocs
2903 #define elf_backend_symbol_processing mmix_elf_symbol_processing
2904 #define elf_backend_omit_section_dynsym \
2905 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) (bfd_boolean (*)) bfd_true)
2907 #define bfd_elf64_bfd_copy_link_hash_symbol_type \
2908 _bfd_generic_copy_link_hash_symbol_type
2910 #define bfd_elf64_bfd_is_local_label_name \
2911 mmix_elf_is_local_label_name
2913 #define elf_backend_may_use_rel_p 0
2914 #define elf_backend_may_use_rela_p 1
2915 #define elf_backend_default_use_rela_p 1
2917 #define elf_backend_can_gc_sections 1
2918 #define elf_backend_section_from_bfd_section \
2919 mmix_elf_section_from_bfd_section
2921 #define bfd_elf64_new_section_hook mmix_elf_new_section_hook
2922 #define bfd_elf64_bfd_final_link mmix_elf_final_link
2923 #define bfd_elf64_bfd_relax_section mmix_elf_relax_section
2925 #include "elf64-target.h"