1 /* MMIX-specific support for 64-bit ELF.
2 Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011,
4 Free Software Foundation, Inc.
5 Contributed by Hans-Peter Nilsson <hp@bitrange.com>
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 /* No specific ABI or "processor-specific supplement" defined. */
28 - "Traditional" linker relaxation (shrinking whole sections).
29 - Merge reloc stubs jumping to same location.
30 - GETA stub relaxation (call a stub for out of range new
31 R_MMIX_GETA_STUBBABLE). */
38 #include "opcode/mmix.h"
40 #define MINUS_ONE (((bfd_vma) 0) - 1)
42 #define MAX_PUSHJ_STUB_SIZE (5 * 4)
44 /* Put these everywhere in new code. */
46 _bfd_abort (__FILE__, __LINE__, \
47 "Internal: Non-debugged code (test-case missing)")
50 _bfd_abort (__FILE__, __LINE__, \
53 struct _mmix_elf_section_data
55 struct bfd_elf_section_data elf
;
58 struct bpo_reloc_section_info
*reloc
;
59 struct bpo_greg_section_info
*greg
;
62 struct pushj_stub_info
64 /* Maximum number of stubs needed for this section. */
65 bfd_size_type n_pushj_relocs
;
67 /* Size of stubs after a mmix_elf_relax_section round. */
68 bfd_size_type stubs_size_sum
;
70 /* Per-reloc stubs_size_sum information. The stubs_size_sum member is the sum
71 of these. Allocated in mmix_elf_check_common_relocs. */
72 bfd_size_type
*stub_size
;
74 /* Offset of next stub during relocation. Somewhat redundant with the
75 above: error coverage is easier and we don't have to reset the
76 stubs_size_sum for relocation. */
77 bfd_size_type stub_offset
;
80 /* Whether there has been a warning that this section could not be
81 linked due to a specific cause. FIXME: a way to access the
82 linker info or output section, then stuff the limiter guard
84 bfd_boolean has_warned_bpo
;
85 bfd_boolean has_warned_pushj
;
88 #define mmix_elf_section_data(sec) \
89 ((struct _mmix_elf_section_data *) elf_section_data (sec))
91 /* For each section containing a base-plus-offset (BPO) reloc, we attach
92 this struct as mmix_elf_section_data (section)->bpo, which is otherwise
94 struct bpo_reloc_section_info
96 /* The base is 1; this is the first number in this section. */
97 size_t first_base_plus_offset_reloc
;
99 /* Number of BPO-relocs in this section. */
100 size_t n_bpo_relocs_this_section
;
102 /* Running index, used at relocation time. */
105 /* We don't have access to the bfd_link_info struct in
106 mmix_final_link_relocate. What we really want to get at is the
107 global single struct greg_relocation, so we stash it here. */
108 asection
*bpo_greg_section
;
111 /* Helper struct (in global context) for the one below.
112 There's one of these created for every BPO reloc. */
113 struct bpo_reloc_request
117 /* Valid after relaxation. The base is 0; the first register number
118 must be added. The offset is in range 0..255. */
122 /* The order number for this BPO reloc, corresponding to the order in
123 which BPO relocs were found. Used to create an index after reloc
124 requests are sorted. */
127 /* Set when the value is computed. Better than coding "guard values"
128 into the other members. Is FALSE only for BPO relocs in a GC:ed
133 /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
134 greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
135 which is linked into the register contents section
136 (MMIX_REG_CONTENTS_SECTION_NAME). This section is created by the
137 linker; using the same hook as for usual with BPO relocs does not
139 struct bpo_greg_section_info
141 /* After GC, this reflects the number of remaining, non-excluded
145 /* This is the number of allocated bpo_reloc_requests; the size of
146 sorted_indexes. Valid after the check.*relocs functions are called
147 for all incoming sections. It includes the number of BPO relocs in
148 sections that were GC:ed. */
149 size_t n_max_bpo_relocs
;
151 /* A counter used to find out when to fold the BPO gregs, since we
152 don't have a single "after-relaxation" hook. */
153 size_t n_remaining_bpo_relocs_this_relaxation_round
;
155 /* The number of linker-allocated GREGs resulting from BPO relocs.
156 This is an approximation after _bfd_mmix_before_linker_allocation
157 and supposedly accurate after mmix_elf_relax_section is called for
158 all incoming non-collected sections. */
159 size_t n_allocated_bpo_gregs
;
161 /* Index into reloc_request[], sorted on increasing "value", secondary
162 by increasing index for strict sorting order. */
163 size_t *bpo_reloc_indexes
;
165 /* An array of all relocations, with the "value" member filled in by
166 the relaxation function. */
167 struct bpo_reloc_request
*reloc_request
;
170 static int mmix_elf_link_output_symbol_hook
171 PARAMS ((struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
172 asection
*, struct elf_link_hash_entry
*));
174 static bfd_reloc_status_type mmix_elf_reloc
175 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
177 static reloc_howto_type
*bfd_elf64_bfd_reloc_type_lookup
178 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
180 static void mmix_info_to_howto_rela
181 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
183 static int mmix_elf_sort_relocs
PARAMS ((const PTR
, const PTR
));
185 static bfd_boolean mmix_elf_new_section_hook
186 PARAMS ((bfd
*, asection
*));
188 static bfd_boolean mmix_elf_check_relocs
189 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
190 const Elf_Internal_Rela
*));
192 static bfd_boolean mmix_elf_check_common_relocs
193 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
194 const Elf_Internal_Rela
*));
196 static bfd_boolean mmix_elf_relocate_section
197 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
198 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
200 static bfd_reloc_status_type mmix_final_link_relocate
201 (reloc_howto_type
*, asection
*, bfd_byte
*, bfd_vma
, bfd_signed_vma
,
202 bfd_vma
, const char *, asection
*, char **);
204 static bfd_reloc_status_type mmix_elf_perform_relocation
205 (asection
*, reloc_howto_type
*, void *, bfd_vma
, bfd_vma
, char **);
207 static bfd_boolean mmix_elf_section_from_bfd_section
208 PARAMS ((bfd
*, asection
*, int *));
210 static bfd_boolean mmix_elf_add_symbol_hook
211 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
212 const char **, flagword
*, asection
**, bfd_vma
*));
214 static bfd_boolean mmix_elf_is_local_label_name
215 PARAMS ((bfd
*, const char *));
217 static int bpo_reloc_request_sort_fn
PARAMS ((const PTR
, const PTR
));
219 static bfd_boolean mmix_elf_relax_section
220 PARAMS ((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
221 bfd_boolean
*again
));
223 extern bfd_boolean mmix_elf_final_link
PARAMS ((bfd
*, struct bfd_link_info
*));
225 extern void mmix_elf_symbol_processing
PARAMS ((bfd
*, asymbol
*));
227 /* Only intended to be called from a debugger. */
228 extern void mmix_dump_bpo_gregs
229 PARAMS ((struct bfd_link_info
*, bfd_error_handler_type
));
232 mmix_set_relaxable_size
233 PARAMS ((bfd
*, asection
*, void *));
236 /* Watch out: this currently needs to have elements with the same index as
237 their R_MMIX_ number. */
238 static reloc_howto_type elf_mmix_howto_table
[] =
240 /* This reloc does nothing. */
241 HOWTO (R_MMIX_NONE
, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 FALSE
, /* pc_relative */
247 complain_overflow_bitfield
, /* complain_on_overflow */
248 bfd_elf_generic_reloc
, /* special_function */
249 "R_MMIX_NONE", /* name */
250 FALSE
, /* partial_inplace */
253 FALSE
), /* pcrel_offset */
255 /* An 8 bit absolute relocation. */
256 HOWTO (R_MMIX_8
, /* type */
258 0, /* size (0 = byte, 1 = short, 2 = long) */
260 FALSE
, /* pc_relative */
262 complain_overflow_bitfield
, /* complain_on_overflow */
263 bfd_elf_generic_reloc
, /* special_function */
264 "R_MMIX_8", /* name */
265 FALSE
, /* partial_inplace */
268 FALSE
), /* pcrel_offset */
270 /* An 16 bit absolute relocation. */
271 HOWTO (R_MMIX_16
, /* type */
273 1, /* size (0 = byte, 1 = short, 2 = long) */
275 FALSE
, /* pc_relative */
277 complain_overflow_bitfield
, /* complain_on_overflow */
278 bfd_elf_generic_reloc
, /* special_function */
279 "R_MMIX_16", /* name */
280 FALSE
, /* partial_inplace */
282 0xffff, /* dst_mask */
283 FALSE
), /* pcrel_offset */
285 /* An 24 bit absolute relocation. */
286 HOWTO (R_MMIX_24
, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 FALSE
, /* pc_relative */
292 complain_overflow_bitfield
, /* complain_on_overflow */
293 bfd_elf_generic_reloc
, /* special_function */
294 "R_MMIX_24", /* name */
295 FALSE
, /* partial_inplace */
296 ~0xffffff, /* src_mask */
297 0xffffff, /* dst_mask */
298 FALSE
), /* pcrel_offset */
300 /* A 32 bit absolute relocation. */
301 HOWTO (R_MMIX_32
, /* type */
303 2, /* size (0 = byte, 1 = short, 2 = long) */
305 FALSE
, /* pc_relative */
307 complain_overflow_bitfield
, /* complain_on_overflow */
308 bfd_elf_generic_reloc
, /* special_function */
309 "R_MMIX_32", /* name */
310 FALSE
, /* partial_inplace */
312 0xffffffff, /* dst_mask */
313 FALSE
), /* pcrel_offset */
315 /* 64 bit relocation. */
316 HOWTO (R_MMIX_64
, /* type */
318 4, /* size (0 = byte, 1 = short, 2 = long) */
320 FALSE
, /* pc_relative */
322 complain_overflow_bitfield
, /* complain_on_overflow */
323 bfd_elf_generic_reloc
, /* special_function */
324 "R_MMIX_64", /* name */
325 FALSE
, /* partial_inplace */
327 MINUS_ONE
, /* dst_mask */
328 FALSE
), /* pcrel_offset */
330 /* An 8 bit PC-relative relocation. */
331 HOWTO (R_MMIX_PC_8
, /* type */
333 0, /* size (0 = byte, 1 = short, 2 = long) */
335 TRUE
, /* pc_relative */
337 complain_overflow_bitfield
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_MMIX_PC_8", /* name */
340 FALSE
, /* partial_inplace */
343 TRUE
), /* pcrel_offset */
345 /* An 16 bit PC-relative relocation. */
346 HOWTO (R_MMIX_PC_16
, /* type */
348 1, /* size (0 = byte, 1 = short, 2 = long) */
350 TRUE
, /* pc_relative */
352 complain_overflow_bitfield
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_MMIX_PC_16", /* name */
355 FALSE
, /* partial_inplace */
357 0xffff, /* dst_mask */
358 TRUE
), /* pcrel_offset */
360 /* An 24 bit PC-relative relocation. */
361 HOWTO (R_MMIX_PC_24
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 TRUE
, /* pc_relative */
367 complain_overflow_bitfield
, /* complain_on_overflow */
368 bfd_elf_generic_reloc
, /* special_function */
369 "R_MMIX_PC_24", /* name */
370 FALSE
, /* partial_inplace */
371 ~0xffffff, /* src_mask */
372 0xffffff, /* dst_mask */
373 TRUE
), /* pcrel_offset */
375 /* A 32 bit absolute PC-relative relocation. */
376 HOWTO (R_MMIX_PC_32
, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 TRUE
, /* pc_relative */
382 complain_overflow_bitfield
, /* complain_on_overflow */
383 bfd_elf_generic_reloc
, /* special_function */
384 "R_MMIX_PC_32", /* name */
385 FALSE
, /* partial_inplace */
387 0xffffffff, /* dst_mask */
388 TRUE
), /* pcrel_offset */
390 /* 64 bit PC-relative relocation. */
391 HOWTO (R_MMIX_PC_64
, /* type */
393 4, /* size (0 = byte, 1 = short, 2 = long) */
395 TRUE
, /* pc_relative */
397 complain_overflow_bitfield
, /* complain_on_overflow */
398 bfd_elf_generic_reloc
, /* special_function */
399 "R_MMIX_PC_64", /* name */
400 FALSE
, /* partial_inplace */
402 MINUS_ONE
, /* dst_mask */
403 TRUE
), /* pcrel_offset */
405 /* GNU extension to record C++ vtable hierarchy. */
406 HOWTO (R_MMIX_GNU_VTINHERIT
, /* type */
408 0, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE
, /* pc_relative */
412 complain_overflow_dont
, /* complain_on_overflow */
413 NULL
, /* special_function */
414 "R_MMIX_GNU_VTINHERIT", /* name */
415 FALSE
, /* partial_inplace */
418 TRUE
), /* pcrel_offset */
420 /* GNU extension to record C++ vtable member usage. */
421 HOWTO (R_MMIX_GNU_VTENTRY
, /* type */
423 0, /* size (0 = byte, 1 = short, 2 = long) */
425 FALSE
, /* pc_relative */
427 complain_overflow_dont
, /* complain_on_overflow */
428 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
429 "R_MMIX_GNU_VTENTRY", /* name */
430 FALSE
, /* partial_inplace */
433 FALSE
), /* pcrel_offset */
435 /* The GETA relocation is supposed to get any address that could
436 possibly be reached by the GETA instruction. It can silently expand
437 to get a 64-bit operand, but will complain if any of the two least
438 significant bits are set. The howto members reflect a simple GETA. */
439 HOWTO (R_MMIX_GETA
, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 TRUE
, /* pc_relative */
445 complain_overflow_signed
, /* complain_on_overflow */
446 mmix_elf_reloc
, /* special_function */
447 "R_MMIX_GETA", /* name */
448 FALSE
, /* partial_inplace */
449 ~0x0100ffff, /* src_mask */
450 0x0100ffff, /* dst_mask */
451 TRUE
), /* pcrel_offset */
453 HOWTO (R_MMIX_GETA_1
, /* type */
455 2, /* size (0 = byte, 1 = short, 2 = long) */
457 TRUE
, /* pc_relative */
459 complain_overflow_signed
, /* complain_on_overflow */
460 mmix_elf_reloc
, /* special_function */
461 "R_MMIX_GETA_1", /* name */
462 FALSE
, /* partial_inplace */
463 ~0x0100ffff, /* src_mask */
464 0x0100ffff, /* dst_mask */
465 TRUE
), /* pcrel_offset */
467 HOWTO (R_MMIX_GETA_2
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 TRUE
, /* pc_relative */
473 complain_overflow_signed
, /* complain_on_overflow */
474 mmix_elf_reloc
, /* special_function */
475 "R_MMIX_GETA_2", /* name */
476 FALSE
, /* partial_inplace */
477 ~0x0100ffff, /* src_mask */
478 0x0100ffff, /* dst_mask */
479 TRUE
), /* pcrel_offset */
481 HOWTO (R_MMIX_GETA_3
, /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 TRUE
, /* pc_relative */
487 complain_overflow_signed
, /* complain_on_overflow */
488 mmix_elf_reloc
, /* special_function */
489 "R_MMIX_GETA_3", /* name */
490 FALSE
, /* partial_inplace */
491 ~0x0100ffff, /* src_mask */
492 0x0100ffff, /* dst_mask */
493 TRUE
), /* pcrel_offset */
495 /* The conditional branches are supposed to reach any (code) address.
496 It can silently expand to a 64-bit operand, but will emit an error if
497 any of the two least significant bits are set. The howto members
498 reflect a simple branch. */
499 HOWTO (R_MMIX_CBRANCH
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 TRUE
, /* pc_relative */
505 complain_overflow_signed
, /* complain_on_overflow */
506 mmix_elf_reloc
, /* special_function */
507 "R_MMIX_CBRANCH", /* name */
508 FALSE
, /* partial_inplace */
509 ~0x0100ffff, /* src_mask */
510 0x0100ffff, /* dst_mask */
511 TRUE
), /* pcrel_offset */
513 HOWTO (R_MMIX_CBRANCH_J
, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 TRUE
, /* pc_relative */
519 complain_overflow_signed
, /* complain_on_overflow */
520 mmix_elf_reloc
, /* special_function */
521 "R_MMIX_CBRANCH_J", /* name */
522 FALSE
, /* partial_inplace */
523 ~0x0100ffff, /* src_mask */
524 0x0100ffff, /* dst_mask */
525 TRUE
), /* pcrel_offset */
527 HOWTO (R_MMIX_CBRANCH_1
, /* 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_CBRANCH_1", /* name */
536 FALSE
, /* partial_inplace */
537 ~0x0100ffff, /* src_mask */
538 0x0100ffff, /* dst_mask */
539 TRUE
), /* pcrel_offset */
541 HOWTO (R_MMIX_CBRANCH_2
, /* 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_CBRANCH_2", /* name */
550 FALSE
, /* partial_inplace */
551 ~0x0100ffff, /* src_mask */
552 0x0100ffff, /* dst_mask */
553 TRUE
), /* pcrel_offset */
555 HOWTO (R_MMIX_CBRANCH_3
, /* 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_CBRANCH_3", /* name */
564 FALSE
, /* partial_inplace */
565 ~0x0100ffff, /* src_mask */
566 0x0100ffff, /* dst_mask */
567 TRUE
), /* pcrel_offset */
569 /* The PUSHJ instruction can reach any (code) address, as long as it's
570 the beginning of a function (no usable restriction). It can silently
571 expand to a 64-bit operand, but will emit an error if any of the two
572 least significant bits are set. It can also expand into a call to a
573 stub; see R_MMIX_PUSHJ_STUBBABLE. The howto members reflect a simple
575 HOWTO (R_MMIX_PUSHJ
, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 TRUE
, /* pc_relative */
581 complain_overflow_signed
, /* complain_on_overflow */
582 mmix_elf_reloc
, /* special_function */
583 "R_MMIX_PUSHJ", /* name */
584 FALSE
, /* partial_inplace */
585 ~0x0100ffff, /* src_mask */
586 0x0100ffff, /* dst_mask */
587 TRUE
), /* pcrel_offset */
589 HOWTO (R_MMIX_PUSHJ_1
, /* type */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
593 TRUE
, /* pc_relative */
595 complain_overflow_signed
, /* complain_on_overflow */
596 mmix_elf_reloc
, /* special_function */
597 "R_MMIX_PUSHJ_1", /* name */
598 FALSE
, /* partial_inplace */
599 ~0x0100ffff, /* src_mask */
600 0x0100ffff, /* dst_mask */
601 TRUE
), /* pcrel_offset */
603 HOWTO (R_MMIX_PUSHJ_2
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 TRUE
, /* pc_relative */
609 complain_overflow_signed
, /* complain_on_overflow */
610 mmix_elf_reloc
, /* special_function */
611 "R_MMIX_PUSHJ_2", /* name */
612 FALSE
, /* partial_inplace */
613 ~0x0100ffff, /* src_mask */
614 0x0100ffff, /* dst_mask */
615 TRUE
), /* pcrel_offset */
617 HOWTO (R_MMIX_PUSHJ_3
, /* type */
619 2, /* size (0 = byte, 1 = short, 2 = long) */
621 TRUE
, /* pc_relative */
623 complain_overflow_signed
, /* complain_on_overflow */
624 mmix_elf_reloc
, /* special_function */
625 "R_MMIX_PUSHJ_3", /* name */
626 FALSE
, /* partial_inplace */
627 ~0x0100ffff, /* src_mask */
628 0x0100ffff, /* dst_mask */
629 TRUE
), /* pcrel_offset */
631 /* A JMP is supposed to reach any (code) address. By itself, it can
632 reach +-64M; the expansion can reach all 64 bits. Note that the 64M
633 limit is soon reached if you link the program in wildly different
634 memory segments. The howto members reflect a trivial JMP. */
635 HOWTO (R_MMIX_JMP
, /* type */
637 2, /* size (0 = byte, 1 = short, 2 = long) */
639 TRUE
, /* pc_relative */
641 complain_overflow_signed
, /* complain_on_overflow */
642 mmix_elf_reloc
, /* special_function */
643 "R_MMIX_JMP", /* name */
644 FALSE
, /* partial_inplace */
645 ~0x1ffffff, /* src_mask */
646 0x1ffffff, /* dst_mask */
647 TRUE
), /* pcrel_offset */
649 HOWTO (R_MMIX_JMP_1
, /* type */
651 2, /* size (0 = byte, 1 = short, 2 = long) */
653 TRUE
, /* pc_relative */
655 complain_overflow_signed
, /* complain_on_overflow */
656 mmix_elf_reloc
, /* special_function */
657 "R_MMIX_JMP_1", /* name */
658 FALSE
, /* partial_inplace */
659 ~0x1ffffff, /* src_mask */
660 0x1ffffff, /* dst_mask */
661 TRUE
), /* pcrel_offset */
663 HOWTO (R_MMIX_JMP_2
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 TRUE
, /* pc_relative */
669 complain_overflow_signed
, /* complain_on_overflow */
670 mmix_elf_reloc
, /* special_function */
671 "R_MMIX_JMP_2", /* name */
672 FALSE
, /* partial_inplace */
673 ~0x1ffffff, /* src_mask */
674 0x1ffffff, /* dst_mask */
675 TRUE
), /* pcrel_offset */
677 HOWTO (R_MMIX_JMP_3
, /* type */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
681 TRUE
, /* pc_relative */
683 complain_overflow_signed
, /* complain_on_overflow */
684 mmix_elf_reloc
, /* special_function */
685 "R_MMIX_JMP_3", /* name */
686 FALSE
, /* partial_inplace */
687 ~0x1ffffff, /* src_mask */
688 0x1ffffff, /* dst_mask */
689 TRUE
), /* pcrel_offset */
691 /* When we don't emit link-time-relaxable code from the assembler, or
692 when relaxation has done all it can do, these relocs are used. For
693 GETA/PUSHJ/branches. */
694 HOWTO (R_MMIX_ADDR19
, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 TRUE
, /* pc_relative */
700 complain_overflow_signed
, /* complain_on_overflow */
701 mmix_elf_reloc
, /* special_function */
702 "R_MMIX_ADDR19", /* name */
703 FALSE
, /* partial_inplace */
704 ~0x0100ffff, /* src_mask */
705 0x0100ffff, /* dst_mask */
706 TRUE
), /* pcrel_offset */
709 HOWTO (R_MMIX_ADDR27
, /* type */
711 2, /* size (0 = byte, 1 = short, 2 = long) */
713 TRUE
, /* pc_relative */
715 complain_overflow_signed
, /* complain_on_overflow */
716 mmix_elf_reloc
, /* special_function */
717 "R_MMIX_ADDR27", /* name */
718 FALSE
, /* partial_inplace */
719 ~0x1ffffff, /* src_mask */
720 0x1ffffff, /* dst_mask */
721 TRUE
), /* pcrel_offset */
723 /* A general register or the value 0..255. If a value, then the
724 instruction (offset -3) needs adjusting. */
725 HOWTO (R_MMIX_REG_OR_BYTE
, /* type */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE
, /* pc_relative */
731 complain_overflow_bitfield
, /* complain_on_overflow */
732 mmix_elf_reloc
, /* special_function */
733 "R_MMIX_REG_OR_BYTE", /* name */
734 FALSE
, /* partial_inplace */
737 FALSE
), /* pcrel_offset */
739 /* A general register. */
740 HOWTO (R_MMIX_REG
, /* type */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE
, /* pc_relative */
746 complain_overflow_bitfield
, /* complain_on_overflow */
747 mmix_elf_reloc
, /* special_function */
748 "R_MMIX_REG", /* name */
749 FALSE
, /* partial_inplace */
752 FALSE
), /* pcrel_offset */
754 /* A register plus an index, corresponding to the relocation expression.
755 The sizes must correspond to the valid range of the expression, while
756 the bitmasks correspond to what we store in the image. */
757 HOWTO (R_MMIX_BASE_PLUS_OFFSET
, /* type */
759 4, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE
, /* pc_relative */
763 complain_overflow_bitfield
, /* complain_on_overflow */
764 mmix_elf_reloc
, /* special_function */
765 "R_MMIX_BASE_PLUS_OFFSET", /* name */
766 FALSE
, /* partial_inplace */
768 0xffff, /* dst_mask */
769 FALSE
), /* pcrel_offset */
771 /* A "magic" relocation for a LOCAL expression, asserting that the
772 expression is less than the number of global registers. No actual
773 modification of the contents is done. Implementing this as a
774 relocation was less intrusive than e.g. putting such expressions in a
775 section to discard *after* relocation. */
776 HOWTO (R_MMIX_LOCAL
, /* type */
778 0, /* size (0 = byte, 1 = short, 2 = long) */
780 FALSE
, /* pc_relative */
782 complain_overflow_dont
, /* complain_on_overflow */
783 mmix_elf_reloc
, /* special_function */
784 "R_MMIX_LOCAL", /* name */
785 FALSE
, /* partial_inplace */
788 FALSE
), /* pcrel_offset */
790 HOWTO (R_MMIX_PUSHJ_STUBBABLE
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 TRUE
, /* pc_relative */
796 complain_overflow_signed
, /* complain_on_overflow */
797 mmix_elf_reloc
, /* special_function */
798 "R_MMIX_PUSHJ_STUBBABLE", /* name */
799 FALSE
, /* partial_inplace */
800 ~0x0100ffff, /* src_mask */
801 0x0100ffff, /* dst_mask */
802 TRUE
) /* pcrel_offset */
806 /* Map BFD reloc types to MMIX ELF reloc types. */
808 struct mmix_reloc_map
810 bfd_reloc_code_real_type bfd_reloc_val
;
811 enum elf_mmix_reloc_type elf_reloc_val
;
815 static const struct mmix_reloc_map mmix_reloc_map
[] =
817 {BFD_RELOC_NONE
, R_MMIX_NONE
},
818 {BFD_RELOC_8
, R_MMIX_8
},
819 {BFD_RELOC_16
, R_MMIX_16
},
820 {BFD_RELOC_24
, R_MMIX_24
},
821 {BFD_RELOC_32
, R_MMIX_32
},
822 {BFD_RELOC_64
, R_MMIX_64
},
823 {BFD_RELOC_8_PCREL
, R_MMIX_PC_8
},
824 {BFD_RELOC_16_PCREL
, R_MMIX_PC_16
},
825 {BFD_RELOC_24_PCREL
, R_MMIX_PC_24
},
826 {BFD_RELOC_32_PCREL
, R_MMIX_PC_32
},
827 {BFD_RELOC_64_PCREL
, R_MMIX_PC_64
},
828 {BFD_RELOC_VTABLE_INHERIT
, R_MMIX_GNU_VTINHERIT
},
829 {BFD_RELOC_VTABLE_ENTRY
, R_MMIX_GNU_VTENTRY
},
830 {BFD_RELOC_MMIX_GETA
, R_MMIX_GETA
},
831 {BFD_RELOC_MMIX_CBRANCH
, R_MMIX_CBRANCH
},
832 {BFD_RELOC_MMIX_PUSHJ
, R_MMIX_PUSHJ
},
833 {BFD_RELOC_MMIX_JMP
, R_MMIX_JMP
},
834 {BFD_RELOC_MMIX_ADDR19
, R_MMIX_ADDR19
},
835 {BFD_RELOC_MMIX_ADDR27
, R_MMIX_ADDR27
},
836 {BFD_RELOC_MMIX_REG_OR_BYTE
, R_MMIX_REG_OR_BYTE
},
837 {BFD_RELOC_MMIX_REG
, R_MMIX_REG
},
838 {BFD_RELOC_MMIX_BASE_PLUS_OFFSET
, R_MMIX_BASE_PLUS_OFFSET
},
839 {BFD_RELOC_MMIX_LOCAL
, R_MMIX_LOCAL
},
840 {BFD_RELOC_MMIX_PUSHJ_STUBBABLE
, R_MMIX_PUSHJ_STUBBABLE
}
843 static reloc_howto_type
*
844 bfd_elf64_bfd_reloc_type_lookup (abfd
, code
)
845 bfd
*abfd ATTRIBUTE_UNUSED
;
846 bfd_reloc_code_real_type code
;
851 i
< sizeof (mmix_reloc_map
) / sizeof (mmix_reloc_map
[0]);
854 if (mmix_reloc_map
[i
].bfd_reloc_val
== code
)
855 return &elf_mmix_howto_table
[mmix_reloc_map
[i
].elf_reloc_val
];
861 static reloc_howto_type
*
862 bfd_elf64_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
868 i
< sizeof (elf_mmix_howto_table
) / sizeof (elf_mmix_howto_table
[0]);
870 if (elf_mmix_howto_table
[i
].name
!= NULL
871 && strcasecmp (elf_mmix_howto_table
[i
].name
, r_name
) == 0)
872 return &elf_mmix_howto_table
[i
];
878 mmix_elf_new_section_hook (abfd
, sec
)
882 if (!sec
->used_by_bfd
)
884 struct _mmix_elf_section_data
*sdata
;
885 bfd_size_type amt
= sizeof (*sdata
);
887 sdata
= bfd_zalloc (abfd
, amt
);
890 sec
->used_by_bfd
= sdata
;
893 return _bfd_elf_new_section_hook (abfd
, sec
);
897 /* This function performs the actual bitfiddling and sanity check for a
898 final relocation. Each relocation gets its *worst*-case expansion
899 in size when it arrives here; any reduction in size should have been
900 caught in linker relaxation earlier. When we get here, the relocation
901 looks like the smallest instruction with SWYM:s (nop:s) appended to the
902 max size. We fill in those nop:s.
904 R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
908 INCML $N,(foo >> 16) & 0xffff
909 INCMH $N,(foo >> 32) & 0xffff
910 INCH $N,(foo >> 48) & 0xffff
912 R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
913 condbranches needing relaxation might be rare enough to not be
924 R_MMIX_PUSHJ: (FIXME: Relaxation...)
933 R_MMIX_JMP: (FIXME: Relaxation...)
942 R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
944 static bfd_reloc_status_type
945 mmix_elf_perform_relocation (asection
*isec
, reloc_howto_type
*howto
,
946 void *datap
, bfd_vma addr
, bfd_vma value
,
947 char **error_message
)
949 bfd
*abfd
= isec
->owner
;
950 bfd_reloc_status_type flag
= bfd_reloc_ok
;
951 bfd_reloc_status_type r
;
955 /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
956 We handle the differences here and the common sequence later. */
961 reg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
963 /* We change to an absolute value. */
969 int in1
= bfd_get_16 (abfd
, (bfd_byte
*) datap
) << 16;
971 /* Invert the condition and prediction bit, and set the offset
972 to five instructions ahead.
974 We *can* do better if we want to. If the branch is found to be
975 within limits, we could leave the branch as is; there'll just
976 be a bunch of NOP:s after it. But we shouldn't see this
977 sequence often enough that it's worth doing it. */
980 (((in1
^ ((PRED_INV_BIT
| COND_INV_BIT
) << 24)) & ~0xffff)
984 /* Put a "GO $255,$255,0" after the common sequence. */
986 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24) | 0xffff00,
987 (bfd_byte
*) datap
+ 20);
989 /* Common sequence starts at offset 4. */
992 /* We change to an absolute value. */
997 case R_MMIX_PUSHJ_STUBBABLE
:
998 /* If the address fits, we're fine. */
1000 /* Note rightshift 0; see R_MMIX_JMP case below. */
1001 && (r
= bfd_check_overflow (complain_overflow_signed
,
1004 bfd_arch_bits_per_address (abfd
),
1005 value
)) == bfd_reloc_ok
)
1006 goto pcrel_mmix_reloc_fits
;
1009 bfd_size_type size
= isec
->rawsize
? isec
->rawsize
: isec
->size
;
1011 /* We have the bytes at the PUSHJ insn and need to get the
1012 position for the stub. There's supposed to be room allocated
1014 bfd_byte
*stubcontents
1015 = ((bfd_byte
*) datap
1016 - (addr
- (isec
->output_section
->vma
+ isec
->output_offset
))
1018 + mmix_elf_section_data (isec
)->pjs
.stub_offset
);
1021 if (mmix_elf_section_data (isec
)->pjs
.n_pushj_relocs
== 0)
1023 /* This shouldn't happen when linking to ELF or mmo, so
1024 this is an attempt to link to "binary", right? We
1025 can't access the output bfd, so we can't verify that
1026 assumption. We only know that the critical
1027 mmix_elf_check_common_relocs has not been called,
1028 which happens when the output format is different
1029 from the input format (and is not mmo). */
1030 if (! mmix_elf_section_data (isec
)->has_warned_pushj
)
1032 /* For the first such error per input section, produce
1033 a verbose message. */
1035 = _("invalid input relocation when producing"
1036 " non-ELF, non-mmo format output."
1037 "\n Please use the objcopy program to convert from"
1039 "\n or assemble using"
1040 " \"-no-expand\" (for gcc, \"-Wa,-no-expand\"");
1041 mmix_elf_section_data (isec
)->has_warned_pushj
= TRUE
;
1042 return bfd_reloc_dangerous
;
1045 /* For subsequent errors, return this one, which is
1046 rate-limited but looks a little bit different,
1047 hopefully without affecting user-friendliness. */
1048 return bfd_reloc_overflow
;
1051 /* The address doesn't fit, so redirect the PUSHJ to the
1052 location of the stub. */
1053 r
= mmix_elf_perform_relocation (isec
,
1054 &elf_mmix_howto_table
1058 isec
->output_section
->vma
1059 + isec
->output_offset
1061 + (mmix_elf_section_data (isec
)
1065 if (r
!= bfd_reloc_ok
)
1069 = (isec
->output_section
->vma
1070 + isec
->output_offset
1072 + mmix_elf_section_data (isec
)->pjs
.stub_offset
);
1074 /* We generate a simple JMP if that suffices, else the whole 5
1076 if (bfd_check_overflow (complain_overflow_signed
,
1077 elf_mmix_howto_table
[R_MMIX_ADDR27
].bitsize
,
1079 bfd_arch_bits_per_address (abfd
),
1080 addr
+ value
- stubaddr
) == bfd_reloc_ok
)
1082 bfd_put_32 (abfd
, JMP_INSN_BYTE
<< 24, stubcontents
);
1083 r
= mmix_elf_perform_relocation (isec
,
1084 &elf_mmix_howto_table
1088 value
+ addr
- stubaddr
,
1090 mmix_elf_section_data (isec
)->pjs
.stub_offset
+= 4;
1092 if (size
+ mmix_elf_section_data (isec
)->pjs
.stub_offset
1100 /* Put a "GO $255,0" after the common sequence. */
1102 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1103 | 0xff00, (bfd_byte
*) stubcontents
+ 16);
1105 /* Prepare for the general code to set the first part of the
1108 datap
= stubcontents
;
1109 mmix_elf_section_data (isec
)->pjs
.stub_offset
1110 += MAX_PUSHJ_STUB_SIZE
;
1117 int inreg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
1119 /* Put a "PUSHGO $N,$255,0" after the common sequence. */
1121 ((PUSHGO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1124 (bfd_byte
*) datap
+ 16);
1126 /* We change to an absolute value. */
1132 /* This one is a little special. If we get here on a non-relaxing
1133 link, and the destination is actually in range, we don't need to
1135 If so, we fall through to the bit-fiddling relocs.
1137 FIXME: bfd_check_overflow seems broken; the relocation is
1138 rightshifted before testing, so supply a zero rightshift. */
1140 if (! ((value
& 3) == 0
1141 && (r
= bfd_check_overflow (complain_overflow_signed
,
1144 bfd_arch_bits_per_address (abfd
),
1145 value
)) == bfd_reloc_ok
))
1147 /* If the relocation doesn't fit in a JMP, we let the NOP:s be
1148 modified below, and put a "GO $255,$255,0" after the
1149 address-loading sequence. */
1151 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1153 (bfd_byte
*) datap
+ 16);
1155 /* We change to an absolute value. */
1162 pcrel_mmix_reloc_fits
:
1163 /* These must be in range, or else we emit an error. */
1164 if ((value
& 3) == 0
1165 /* Note rightshift 0; see above. */
1166 && (r
= bfd_check_overflow (complain_overflow_signed
,
1169 bfd_arch_bits_per_address (abfd
),
1170 value
)) == bfd_reloc_ok
)
1173 = bfd_get_32 (abfd
, (bfd_byte
*) datap
);
1176 if ((bfd_signed_vma
) value
< 0)
1179 value
+= (1 << (howto
->bitsize
- 1));
1187 (in1
& howto
->src_mask
)
1189 | (value
& howto
->dst_mask
),
1190 (bfd_byte
*) datap
);
1192 return bfd_reloc_ok
;
1195 return bfd_reloc_overflow
;
1197 case R_MMIX_BASE_PLUS_OFFSET
:
1199 struct bpo_reloc_section_info
*bpodata
1200 = mmix_elf_section_data (isec
)->bpo
.reloc
;
1201 asection
*bpo_greg_section
;
1202 struct bpo_greg_section_info
*gregdata
;
1205 if (bpodata
== NULL
)
1207 /* This shouldn't happen when linking to ELF or mmo, so
1208 this is an attempt to link to "binary", right? We
1209 can't access the output bfd, so we can't verify that
1210 assumption. We only know that the critical
1211 mmix_elf_check_common_relocs has not been called, which
1212 happens when the output format is different from the
1213 input format (and is not mmo). */
1214 if (! mmix_elf_section_data (isec
)->has_warned_bpo
)
1216 /* For the first such error per input section, produce
1217 a verbose message. */
1219 = _("invalid input relocation when producing"
1220 " non-ELF, non-mmo format output."
1221 "\n Please use the objcopy program to convert from"
1223 "\n or compile using the gcc-option"
1224 " \"-mno-base-addresses\".");
1225 mmix_elf_section_data (isec
)->has_warned_bpo
= TRUE
;
1226 return bfd_reloc_dangerous
;
1229 /* For subsequent errors, return this one, which is
1230 rate-limited but looks a little bit different,
1231 hopefully without affecting user-friendliness. */
1232 return bfd_reloc_overflow
;
1235 bpo_greg_section
= bpodata
->bpo_greg_section
;
1236 gregdata
= mmix_elf_section_data (bpo_greg_section
)->bpo
.greg
;
1237 bpo_index
= gregdata
->bpo_reloc_indexes
[bpodata
->bpo_index
++];
1239 /* A consistency check: The value we now have in "relocation" must
1240 be the same as the value we stored for that relocation. It
1241 doesn't cost much, so can be left in at all times. */
1242 if (value
!= gregdata
->reloc_request
[bpo_index
].value
)
1244 (*_bfd_error_handler
)
1245 (_("%s: Internal inconsistency error for value for\n\
1246 linker-allocated global register: linked: 0x%lx%08lx != relaxed: 0x%lx%08lx\n"),
1247 bfd_get_filename (isec
->owner
),
1248 (unsigned long) (value
>> 32), (unsigned long) value
,
1249 (unsigned long) (gregdata
->reloc_request
[bpo_index
].value
1251 (unsigned long) gregdata
->reloc_request
[bpo_index
].value
);
1252 bfd_set_error (bfd_error_bad_value
);
1253 return bfd_reloc_overflow
;
1256 /* Then store the register number and offset for that register
1257 into datap and datap + 1 respectively. */
1259 gregdata
->reloc_request
[bpo_index
].regindex
1260 + bpo_greg_section
->output_section
->vma
/ 8,
1263 gregdata
->reloc_request
[bpo_index
].offset
,
1264 ((unsigned char *) datap
) + 1);
1265 return bfd_reloc_ok
;
1268 case R_MMIX_REG_OR_BYTE
:
1271 return bfd_reloc_overflow
;
1272 bfd_put_8 (abfd
, value
, datap
);
1273 return bfd_reloc_ok
;
1276 BAD_CASE (howto
->type
);
1279 /* This code adds the common SETL/INCML/INCMH/INCH worst-case
1282 /* Lowest two bits must be 0. We return bfd_reloc_overflow for
1283 everything that looks strange. */
1285 flag
= bfd_reloc_overflow
;
1288 (SETL_INSN_BYTE
<< 24) | (value
& 0xffff) | (reg
<< 16),
1289 (bfd_byte
*) datap
+ offs
);
1291 (INCML_INSN_BYTE
<< 24) | ((value
>> 16) & 0xffff) | (reg
<< 16),
1292 (bfd_byte
*) datap
+ offs
+ 4);
1294 (INCMH_INSN_BYTE
<< 24) | ((value
>> 32) & 0xffff) | (reg
<< 16),
1295 (bfd_byte
*) datap
+ offs
+ 8);
1297 (INCH_INSN_BYTE
<< 24) | ((value
>> 48) & 0xffff) | (reg
<< 16),
1298 (bfd_byte
*) datap
+ offs
+ 12);
1303 /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
1306 mmix_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1307 bfd
*abfd ATTRIBUTE_UNUSED
;
1309 Elf_Internal_Rela
*dst
;
1311 unsigned int r_type
;
1313 r_type
= ELF64_R_TYPE (dst
->r_info
);
1314 BFD_ASSERT (r_type
< (unsigned int) R_MMIX_max
);
1315 cache_ptr
->howto
= &elf_mmix_howto_table
[r_type
];
1318 /* Any MMIX-specific relocation gets here at assembly time or when linking
1319 to other formats (such as mmo); this is the relocation function from
1320 the reloc_table. We don't get here for final pure ELF linking. */
1322 static bfd_reloc_status_type
1323 mmix_elf_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1324 output_bfd
, error_message
)
1326 arelent
*reloc_entry
;
1329 asection
*input_section
;
1331 char **error_message
;
1334 bfd_reloc_status_type r
;
1335 asection
*reloc_target_output_section
;
1336 bfd_reloc_status_type flag
= bfd_reloc_ok
;
1337 bfd_vma output_base
= 0;
1339 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1340 input_section
, output_bfd
, error_message
);
1342 /* If that was all that was needed (i.e. this isn't a final link, only
1343 some segment adjustments), we're done. */
1344 if (r
!= bfd_reloc_continue
)
1347 if (bfd_is_und_section (symbol
->section
)
1348 && (symbol
->flags
& BSF_WEAK
) == 0
1349 && output_bfd
== (bfd
*) NULL
)
1350 return bfd_reloc_undefined
;
1352 /* Is the address of the relocation really within the section? */
1353 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1354 return bfd_reloc_outofrange
;
1356 /* Work out which section the relocation is targeted at and the
1357 initial relocation command value. */
1359 /* Get symbol value. (Common symbols are special.) */
1360 if (bfd_is_com_section (symbol
->section
))
1363 relocation
= symbol
->value
;
1365 reloc_target_output_section
= bfd_get_output_section (symbol
);
1367 /* Here the variable relocation holds the final address of the symbol we
1368 are relocating against, plus any addend. */
1372 output_base
= reloc_target_output_section
->vma
;
1374 relocation
+= output_base
+ symbol
->section
->output_offset
;
1376 if (output_bfd
!= (bfd
*) NULL
)
1378 /* Add in supplied addend. */
1379 relocation
+= reloc_entry
->addend
;
1381 /* This is a partial relocation, and we want to apply the
1382 relocation to the reloc entry rather than the raw data.
1383 Modify the reloc inplace to reflect what we now know. */
1384 reloc_entry
->addend
= relocation
;
1385 reloc_entry
->address
+= input_section
->output_offset
;
1389 return mmix_final_link_relocate (reloc_entry
->howto
, input_section
,
1390 data
, reloc_entry
->address
,
1391 reloc_entry
->addend
, relocation
,
1392 bfd_asymbol_name (symbol
),
1393 reloc_target_output_section
,
1397 /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
1398 for guidance if you're thinking of copying this. */
1401 mmix_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1402 contents
, relocs
, local_syms
, local_sections
)
1403 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1404 struct bfd_link_info
*info
;
1406 asection
*input_section
;
1408 Elf_Internal_Rela
*relocs
;
1409 Elf_Internal_Sym
*local_syms
;
1410 asection
**local_sections
;
1412 Elf_Internal_Shdr
*symtab_hdr
;
1413 struct elf_link_hash_entry
**sym_hashes
;
1414 Elf_Internal_Rela
*rel
;
1415 Elf_Internal_Rela
*relend
;
1419 size
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
1420 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1421 sym_hashes
= elf_sym_hashes (input_bfd
);
1422 relend
= relocs
+ input_section
->reloc_count
;
1424 /* Zero the stub area before we start. */
1425 if (input_section
->rawsize
!= 0
1426 && input_section
->size
> input_section
->rawsize
)
1427 memset (contents
+ input_section
->rawsize
, 0,
1428 input_section
->size
- input_section
->rawsize
);
1430 for (rel
= relocs
; rel
< relend
; rel
++)
1432 reloc_howto_type
*howto
;
1433 unsigned long r_symndx
;
1434 Elf_Internal_Sym
*sym
;
1436 struct elf_link_hash_entry
*h
;
1438 bfd_reloc_status_type r
;
1439 const char *name
= NULL
;
1441 bfd_boolean undefined_signalled
= FALSE
;
1443 r_type
= ELF64_R_TYPE (rel
->r_info
);
1445 if (r_type
== R_MMIX_GNU_VTINHERIT
1446 || r_type
== R_MMIX_GNU_VTENTRY
)
1449 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1451 howto
= elf_mmix_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
1456 if (r_symndx
< symtab_hdr
->sh_info
)
1458 sym
= local_syms
+ r_symndx
;
1459 sec
= local_sections
[r_symndx
];
1460 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1462 name
= bfd_elf_string_from_elf_section (input_bfd
,
1463 symtab_hdr
->sh_link
,
1466 name
= bfd_section_name (input_bfd
, sec
);
1470 bfd_boolean unresolved_reloc
;
1472 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1473 r_symndx
, symtab_hdr
, sym_hashes
,
1475 unresolved_reloc
, undefined_signalled
);
1476 name
= h
->root
.root
.string
;
1479 if (sec
!= NULL
&& discarded_section (sec
))
1480 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
1481 rel
, 1, relend
, howto
, 0, contents
);
1483 if (info
->relocatable
)
1485 /* This is a relocatable link. For most relocs we don't have to
1486 change anything, unless the reloc is against a section
1487 symbol, in which case we have to adjust according to where
1488 the section symbol winds up in the output section. */
1489 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1490 rel
->r_addend
+= sec
->output_offset
;
1492 /* For PUSHJ stub relocs however, we may need to change the
1493 reloc and the section contents, if the reloc doesn't reach
1494 beyond the end of the output section and previous stubs.
1495 Then we change the section contents to be a PUSHJ to the end
1496 of the input section plus stubs (we can do that without using
1497 a reloc), and then we change the reloc to be a R_MMIX_PUSHJ
1498 at the stub location. */
1499 if (r_type
== R_MMIX_PUSHJ_STUBBABLE
)
1501 /* We've already checked whether we need a stub; use that
1503 if (mmix_elf_section_data (input_section
)->pjs
.stub_size
[pjsno
]
1506 Elf_Internal_Rela relcpy
;
1508 if (mmix_elf_section_data (input_section
)
1509 ->pjs
.stub_size
[pjsno
] != MAX_PUSHJ_STUB_SIZE
)
1512 /* There's already a PUSHJ insn there, so just fill in
1513 the offset bits to the stub. */
1514 if (mmix_final_link_relocate (elf_mmix_howto_table
1521 ->output_section
->vma
1522 + input_section
->output_offset
1524 + mmix_elf_section_data (input_section
)
1526 NULL
, NULL
, NULL
) != bfd_reloc_ok
)
1529 /* Put a JMP insn at the stub; it goes with the
1530 R_MMIX_JMP reloc. */
1531 bfd_put_32 (output_bfd
, JMP_INSN_BYTE
<< 24,
1534 + mmix_elf_section_data (input_section
)
1537 /* Change the reloc to be at the stub, and to a full
1538 R_MMIX_JMP reloc. */
1539 rel
->r_info
= ELF64_R_INFO (r_symndx
, R_MMIX_JMP
);
1542 + mmix_elf_section_data (input_section
)
1545 mmix_elf_section_data (input_section
)->pjs
.stub_offset
1546 += MAX_PUSHJ_STUB_SIZE
;
1548 /* Shift this reloc to the end of the relocs to maintain
1549 the r_offset sorted reloc order. */
1551 memmove (rel
, rel
+ 1, (char *) relend
- (char *) rel
);
1552 relend
[-1] = relcpy
;
1554 /* Back up one reloc, or else we'd skip the next reloc
1564 r
= mmix_final_link_relocate (howto
, input_section
,
1565 contents
, rel
->r_offset
,
1566 rel
->r_addend
, relocation
, name
, sec
, NULL
);
1568 if (r
!= bfd_reloc_ok
)
1570 bfd_boolean check_ok
= TRUE
;
1571 const char * msg
= (const char *) NULL
;
1575 case bfd_reloc_overflow
:
1576 check_ok
= info
->callbacks
->reloc_overflow
1577 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1578 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
1581 case bfd_reloc_undefined
:
1582 /* We may have sent this message above. */
1583 if (! undefined_signalled
)
1584 check_ok
= info
->callbacks
->undefined_symbol
1585 (info
, name
, input_bfd
, input_section
, rel
->r_offset
,
1587 undefined_signalled
= TRUE
;
1590 case bfd_reloc_outofrange
:
1591 msg
= _("internal error: out of range error");
1594 case bfd_reloc_notsupported
:
1595 msg
= _("internal error: unsupported relocation error");
1598 case bfd_reloc_dangerous
:
1599 msg
= _("internal error: dangerous relocation");
1603 msg
= _("internal error: unknown error");
1608 check_ok
= info
->callbacks
->warning
1609 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
1619 /* Perform a single relocation. By default we use the standard BFD
1620 routines. A few relocs we have to do ourselves. */
1622 static bfd_reloc_status_type
1623 mmix_final_link_relocate (reloc_howto_type
*howto
, asection
*input_section
,
1624 bfd_byte
*contents
, bfd_vma r_offset
,
1625 bfd_signed_vma r_addend
, bfd_vma relocation
,
1626 const char *symname
, asection
*symsec
,
1627 char **error_message
)
1629 bfd_reloc_status_type r
= bfd_reloc_ok
;
1631 = (input_section
->output_section
->vma
1632 + input_section
->output_offset
1635 = (bfd_signed_vma
) relocation
+ r_addend
;
1637 switch (howto
->type
)
1639 /* All these are PC-relative. */
1640 case R_MMIX_PUSHJ_STUBBABLE
:
1642 case R_MMIX_CBRANCH
:
1647 contents
+= r_offset
;
1649 srel
-= (input_section
->output_section
->vma
1650 + input_section
->output_offset
1653 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1654 addr
, srel
, error_message
);
1657 case R_MMIX_BASE_PLUS_OFFSET
:
1659 return bfd_reloc_undefined
;
1661 /* Check that we're not relocating against a register symbol. */
1662 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1663 MMIX_REG_CONTENTS_SECTION_NAME
) == 0
1664 || strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1665 MMIX_REG_SECTION_NAME
) == 0)
1667 /* Note: This is separated out into two messages in order
1668 to ease the translation into other languages. */
1669 if (symname
== NULL
|| *symname
== 0)
1670 (*_bfd_error_handler
)
1671 (_("%s: base-plus-offset relocation against register symbol: (unknown) in %s"),
1672 bfd_get_filename (input_section
->owner
),
1673 bfd_get_section_name (symsec
->owner
, symsec
));
1675 (*_bfd_error_handler
)
1676 (_("%s: base-plus-offset relocation against register symbol: %s in %s"),
1677 bfd_get_filename (input_section
->owner
), symname
,
1678 bfd_get_section_name (symsec
->owner
, symsec
));
1679 return bfd_reloc_overflow
;
1683 case R_MMIX_REG_OR_BYTE
:
1685 /* For now, we handle these alike. They must refer to an register
1686 symbol, which is either relative to the register section and in
1687 the range 0..255, or is in the register contents section with vma
1690 /* FIXME: A better way to check for reg contents section?
1691 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
1693 return bfd_reloc_undefined
;
1695 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1696 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1698 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1700 /* The bfd_reloc_outofrange return value, though intuitively
1701 a better value, will not get us an error. */
1702 return bfd_reloc_overflow
;
1706 else if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1707 MMIX_REG_SECTION_NAME
) == 0)
1709 if (srel
< 0 || srel
> 255)
1710 /* The bfd_reloc_outofrange return value, though intuitively a
1711 better value, will not get us an error. */
1712 return bfd_reloc_overflow
;
1716 /* Note: This is separated out into two messages in order
1717 to ease the translation into other languages. */
1718 if (symname
== NULL
|| *symname
== 0)
1719 (*_bfd_error_handler
)
1720 (_("%s: register relocation against non-register symbol: (unknown) in %s"),
1721 bfd_get_filename (input_section
->owner
),
1722 bfd_get_section_name (symsec
->owner
, symsec
));
1724 (*_bfd_error_handler
)
1725 (_("%s: register relocation against non-register symbol: %s in %s"),
1726 bfd_get_filename (input_section
->owner
), symname
,
1727 bfd_get_section_name (symsec
->owner
, symsec
));
1729 /* The bfd_reloc_outofrange return value, though intuitively a
1730 better value, will not get us an error. */
1731 return bfd_reloc_overflow
;
1734 contents
+= r_offset
;
1735 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1736 addr
, srel
, error_message
);
1740 /* This isn't a real relocation, it's just an assertion that the
1741 final relocation value corresponds to a local register. We
1742 ignore the actual relocation; nothing is changed. */
1745 = bfd_get_section_by_name (input_section
->output_section
->owner
,
1746 MMIX_REG_CONTENTS_SECTION_NAME
);
1747 bfd_vma first_global
;
1749 /* Check that this is an absolute value, or a reference to the
1750 register contents section or the register (symbol) section.
1751 Absolute numbers can get here as undefined section. Undefined
1752 symbols are signalled elsewhere, so there's no conflict in us
1753 accidentally handling it. */
1754 if (!bfd_is_abs_section (symsec
)
1755 && !bfd_is_und_section (symsec
)
1756 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1757 MMIX_REG_CONTENTS_SECTION_NAME
) != 0
1758 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1759 MMIX_REG_SECTION_NAME
) != 0)
1761 (*_bfd_error_handler
)
1762 (_("%s: directive LOCAL valid only with a register or absolute value"),
1763 bfd_get_filename (input_section
->owner
));
1765 return bfd_reloc_overflow
;
1768 /* If we don't have a register contents section, then $255 is the
1769 first global register. */
1774 first_global
= bfd_get_section_vma (abfd
, regsec
) / 8;
1775 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1776 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1778 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1779 /* The bfd_reloc_outofrange return value, though
1780 intuitively a better value, will not get us an error. */
1781 return bfd_reloc_overflow
;
1786 if ((bfd_vma
) srel
>= first_global
)
1788 /* FIXME: Better error message. */
1789 (*_bfd_error_handler
)
1790 (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."),
1791 bfd_get_filename (input_section
->owner
), (long) srel
, (long) first_global
);
1793 return bfd_reloc_overflow
;
1800 r
= _bfd_final_link_relocate (howto
, input_section
->owner
, input_section
,
1802 relocation
, r_addend
);
1808 /* Return the section that should be marked against GC for a given
1812 mmix_elf_gc_mark_hook (asection
*sec
,
1813 struct bfd_link_info
*info
,
1814 Elf_Internal_Rela
*rel
,
1815 struct elf_link_hash_entry
*h
,
1816 Elf_Internal_Sym
*sym
)
1819 switch (ELF64_R_TYPE (rel
->r_info
))
1821 case R_MMIX_GNU_VTINHERIT
:
1822 case R_MMIX_GNU_VTENTRY
:
1826 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1829 /* Update relocation info for a GC-excluded section. We could supposedly
1830 perform the allocation after GC, but there's no suitable hook between
1831 GC (or section merge) and the point when all input sections must be
1832 present. Better to waste some memory and (perhaps) a little time. */
1835 mmix_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
1836 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1838 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
1840 struct bpo_reloc_section_info
*bpodata
1841 = mmix_elf_section_data (sec
)->bpo
.reloc
;
1842 asection
*allocated_gregs_section
;
1844 /* If no bpodata here, we have nothing to do. */
1845 if (bpodata
== NULL
)
1848 allocated_gregs_section
= bpodata
->bpo_greg_section
;
1850 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
->n_bpo_relocs
1851 -= bpodata
->n_bpo_relocs_this_section
;
1856 /* Sort register relocs to come before expanding relocs. */
1859 mmix_elf_sort_relocs (p1
, p2
)
1863 const Elf_Internal_Rela
*r1
= (const Elf_Internal_Rela
*) p1
;
1864 const Elf_Internal_Rela
*r2
= (const Elf_Internal_Rela
*) p2
;
1865 int r1_is_reg
, r2_is_reg
;
1867 /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1869 if ((r1
->r_offset
& ~(bfd_vma
) 3) > (r2
->r_offset
& ~(bfd_vma
) 3))
1871 else if ((r1
->r_offset
& ~(bfd_vma
) 3) < (r2
->r_offset
& ~(bfd_vma
) 3))
1875 = (ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG_OR_BYTE
1876 || ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG
);
1878 = (ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG_OR_BYTE
1879 || ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG
);
1880 if (r1_is_reg
!= r2_is_reg
)
1881 return r2_is_reg
- r1_is_reg
;
1883 /* Neither or both are register relocs. Then sort on full offset. */
1884 if (r1
->r_offset
> r2
->r_offset
)
1886 else if (r1
->r_offset
< r2
->r_offset
)
1891 /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
1894 mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
)
1896 struct bfd_link_info
*info
;
1898 const Elf_Internal_Rela
*relocs
;
1900 bfd
*bpo_greg_owner
= NULL
;
1901 asection
*allocated_gregs_section
= NULL
;
1902 struct bpo_greg_section_info
*gregdata
= NULL
;
1903 struct bpo_reloc_section_info
*bpodata
= NULL
;
1904 const Elf_Internal_Rela
*rel
;
1905 const Elf_Internal_Rela
*rel_end
;
1907 /* We currently have to abuse this COFF-specific member, since there's
1908 no target-machine-dedicated member. There's no alternative outside
1909 the bfd_link_info struct; we can't specialize a hash-table since
1910 they're different between ELF and mmo. */
1911 bpo_greg_owner
= (bfd
*) info
->base_file
;
1913 rel_end
= relocs
+ sec
->reloc_count
;
1914 for (rel
= relocs
; rel
< rel_end
; rel
++)
1916 switch (ELF64_R_TYPE (rel
->r_info
))
1918 /* This relocation causes a GREG allocation. We need to count
1919 them, and we need to create a section for them, so we need an
1920 object to fake as the owner of that section. We can't use
1921 the ELF dynobj for this, since the ELF bits assume lots of
1922 DSO-related stuff if that member is non-NULL. */
1923 case R_MMIX_BASE_PLUS_OFFSET
:
1924 /* We don't do anything with this reloc for a relocatable link. */
1925 if (info
->relocatable
)
1928 if (bpo_greg_owner
== NULL
)
1930 bpo_greg_owner
= abfd
;
1931 info
->base_file
= (PTR
) bpo_greg_owner
;
1934 if (allocated_gregs_section
== NULL
)
1935 allocated_gregs_section
1936 = bfd_get_section_by_name (bpo_greg_owner
,
1937 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
1939 if (allocated_gregs_section
== NULL
)
1941 allocated_gregs_section
1942 = bfd_make_section_with_flags (bpo_greg_owner
,
1943 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
,
1946 | SEC_LINKER_CREATED
));
1947 /* Setting both SEC_ALLOC and SEC_LOAD means the section is
1948 treated like any other section, and we'd get errors for
1949 address overlap with the text section. Let's set none of
1950 those flags, as that is what currently happens for usual
1951 GREG allocations, and that works. */
1952 if (allocated_gregs_section
== NULL
1953 || !bfd_set_section_alignment (bpo_greg_owner
,
1954 allocated_gregs_section
,
1958 gregdata
= (struct bpo_greg_section_info
*)
1959 bfd_zalloc (bpo_greg_owner
, sizeof (struct bpo_greg_section_info
));
1960 if (gregdata
== NULL
)
1962 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
1965 else if (gregdata
== NULL
)
1967 = mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
;
1969 /* Get ourselves some auxiliary info for the BPO-relocs. */
1970 if (bpodata
== NULL
)
1972 /* No use doing a separate iteration pass to find the upper
1973 limit - just use the number of relocs. */
1974 bpodata
= (struct bpo_reloc_section_info
*)
1975 bfd_alloc (bpo_greg_owner
,
1976 sizeof (struct bpo_reloc_section_info
)
1977 * (sec
->reloc_count
+ 1));
1978 if (bpodata
== NULL
)
1980 mmix_elf_section_data (sec
)->bpo
.reloc
= bpodata
;
1981 bpodata
->first_base_plus_offset_reloc
1982 = bpodata
->bpo_index
1983 = gregdata
->n_max_bpo_relocs
;
1984 bpodata
->bpo_greg_section
1985 = allocated_gregs_section
;
1986 bpodata
->n_bpo_relocs_this_section
= 0;
1989 bpodata
->n_bpo_relocs_this_section
++;
1990 gregdata
->n_max_bpo_relocs
++;
1992 /* We don't get another chance to set this before GC; we've not
1993 set up any hook that runs before GC. */
1994 gregdata
->n_bpo_relocs
1995 = gregdata
->n_max_bpo_relocs
;
1998 case R_MMIX_PUSHJ_STUBBABLE
:
1999 mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
++;
2004 /* Allocate per-reloc stub storage and initialize it to the max stub
2006 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
!= 0)
2010 mmix_elf_section_data (sec
)->pjs
.stub_size
2011 = bfd_alloc (abfd
, mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2012 * sizeof (mmix_elf_section_data (sec
)
2013 ->pjs
.stub_size
[0]));
2014 if (mmix_elf_section_data (sec
)->pjs
.stub_size
== NULL
)
2017 for (i
= 0; i
< mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
; i
++)
2018 mmix_elf_section_data (sec
)->pjs
.stub_size
[i
] = MAX_PUSHJ_STUB_SIZE
;
2024 /* Look through the relocs for a section during the first phase. */
2027 mmix_elf_check_relocs (abfd
, info
, sec
, relocs
)
2029 struct bfd_link_info
*info
;
2031 const Elf_Internal_Rela
*relocs
;
2033 Elf_Internal_Shdr
*symtab_hdr
;
2034 struct elf_link_hash_entry
**sym_hashes
;
2035 const Elf_Internal_Rela
*rel
;
2036 const Elf_Internal_Rela
*rel_end
;
2038 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2039 sym_hashes
= elf_sym_hashes (abfd
);
2041 /* First we sort the relocs so that any register relocs come before
2042 expansion-relocs to the same insn. FIXME: Not done for mmo. */
2043 qsort ((PTR
) relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
2044 mmix_elf_sort_relocs
);
2046 /* Do the common part. */
2047 if (!mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
))
2050 if (info
->relocatable
)
2053 rel_end
= relocs
+ sec
->reloc_count
;
2054 for (rel
= relocs
; rel
< rel_end
; rel
++)
2056 struct elf_link_hash_entry
*h
;
2057 unsigned long r_symndx
;
2059 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2060 if (r_symndx
< symtab_hdr
->sh_info
)
2064 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2065 while (h
->root
.type
== bfd_link_hash_indirect
2066 || h
->root
.type
== bfd_link_hash_warning
)
2067 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2070 switch (ELF64_R_TYPE (rel
->r_info
))
2072 /* This relocation describes the C++ object vtable hierarchy.
2073 Reconstruct it for later use during GC. */
2074 case R_MMIX_GNU_VTINHERIT
:
2075 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2079 /* This relocation describes which C++ vtable entries are actually
2080 used. Record for later use during GC. */
2081 case R_MMIX_GNU_VTENTRY
:
2082 BFD_ASSERT (h
!= NULL
);
2084 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2093 /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
2094 Copied from elf_link_add_object_symbols. */
2097 _bfd_mmix_check_all_relocs (abfd
, info
)
2099 struct bfd_link_info
*info
;
2103 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2105 Elf_Internal_Rela
*internal_relocs
;
2108 if ((o
->flags
& SEC_RELOC
) == 0
2109 || o
->reloc_count
== 0
2110 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
2111 && (o
->flags
& SEC_DEBUGGING
) != 0)
2112 || bfd_is_abs_section (o
->output_section
))
2116 = _bfd_elf_link_read_relocs (abfd
, o
, (PTR
) NULL
,
2117 (Elf_Internal_Rela
*) NULL
,
2119 if (internal_relocs
== NULL
)
2122 ok
= mmix_elf_check_common_relocs (abfd
, info
, o
, internal_relocs
);
2124 if (! info
->keep_memory
)
2125 free (internal_relocs
);
2134 /* Change symbols relative to the reg contents section to instead be to
2135 the register section, and scale them down to correspond to the register
2139 mmix_elf_link_output_symbol_hook (info
, name
, sym
, input_sec
, h
)
2140 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2141 const char *name ATTRIBUTE_UNUSED
;
2142 Elf_Internal_Sym
*sym
;
2143 asection
*input_sec
;
2144 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
;
2146 if (input_sec
!= NULL
2147 && input_sec
->name
!= NULL
2148 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2149 && strcmp (input_sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2152 sym
->st_shndx
= SHN_REGISTER
;
2158 /* We fake a register section that holds values that are register numbers.
2159 Having a SHN_REGISTER and register section translates better to other
2160 formats (e.g. mmo) than for example a STT_REGISTER attribute.
2161 This section faking is based on a construct in elf32-mips.c. */
2162 static asection mmix_elf_reg_section
;
2163 static asymbol mmix_elf_reg_section_symbol
;
2164 static asymbol
*mmix_elf_reg_section_symbol_ptr
;
2166 /* Handle the special section numbers that a symbol may use. */
2169 mmix_elf_symbol_processing (abfd
, asym
)
2170 bfd
*abfd ATTRIBUTE_UNUSED
;
2173 elf_symbol_type
*elfsym
;
2175 elfsym
= (elf_symbol_type
*) asym
;
2176 switch (elfsym
->internal_elf_sym
.st_shndx
)
2179 if (mmix_elf_reg_section
.name
== NULL
)
2181 /* Initialize the register section. */
2182 mmix_elf_reg_section
.name
= MMIX_REG_SECTION_NAME
;
2183 mmix_elf_reg_section
.flags
= SEC_NO_FLAGS
;
2184 mmix_elf_reg_section
.output_section
= &mmix_elf_reg_section
;
2185 mmix_elf_reg_section
.symbol
= &mmix_elf_reg_section_symbol
;
2186 mmix_elf_reg_section
.symbol_ptr_ptr
= &mmix_elf_reg_section_symbol_ptr
;
2187 mmix_elf_reg_section_symbol
.name
= MMIX_REG_SECTION_NAME
;
2188 mmix_elf_reg_section_symbol
.flags
= BSF_SECTION_SYM
;
2189 mmix_elf_reg_section_symbol
.section
= &mmix_elf_reg_section
;
2190 mmix_elf_reg_section_symbol_ptr
= &mmix_elf_reg_section_symbol
;
2192 asym
->section
= &mmix_elf_reg_section
;
2200 /* Given a BFD section, try to locate the corresponding ELF section
2204 mmix_elf_section_from_bfd_section (abfd
, sec
, retval
)
2205 bfd
* abfd ATTRIBUTE_UNUSED
;
2209 if (strcmp (bfd_get_section_name (abfd
, sec
), MMIX_REG_SECTION_NAME
) == 0)
2210 *retval
= SHN_REGISTER
;
2217 /* Hook called by the linker routine which adds symbols from an object
2218 file. We must handle the special SHN_REGISTER section number here.
2220 We also check that we only have *one* each of the section-start
2221 symbols, since otherwise having two with the same value would cause
2222 them to be "merged", but with the contents serialized. */
2225 mmix_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2227 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2228 Elf_Internal_Sym
*sym
;
2229 const char **namep ATTRIBUTE_UNUSED
;
2230 flagword
*flagsp ATTRIBUTE_UNUSED
;
2232 bfd_vma
*valp ATTRIBUTE_UNUSED
;
2234 if (sym
->st_shndx
== SHN_REGISTER
)
2236 *secp
= bfd_make_section_old_way (abfd
, MMIX_REG_SECTION_NAME
);
2237 (*secp
)->flags
|= SEC_LINKER_CREATED
;
2239 else if ((*namep
)[0] == '_' && (*namep
)[1] == '_' && (*namep
)[2] == '.'
2240 && CONST_STRNEQ (*namep
, MMIX_LOC_SECTION_START_SYMBOL_PREFIX
))
2242 /* See if we have another one. */
2243 struct bfd_link_hash_entry
*h
= bfd_link_hash_lookup (info
->hash
,
2249 if (h
!= NULL
&& h
->type
!= bfd_link_hash_undefined
)
2251 /* How do we get the asymbol (or really: the filename) from h?
2252 h->u.def.section->owner is NULL. */
2253 ((*_bfd_error_handler
)
2254 (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
2255 bfd_get_filename (abfd
), *namep
,
2256 *namep
+ strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
)));
2257 bfd_set_error (bfd_error_bad_value
);
2265 /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
2268 mmix_elf_is_local_label_name (abfd
, name
)
2275 /* Also include the default local-label definition. */
2276 if (_bfd_elf_is_local_label_name (abfd
, name
))
2282 /* If there's no ":", or more than one, it's not a local symbol. */
2283 colpos
= strchr (name
, ':');
2284 if (colpos
== NULL
|| strchr (colpos
+ 1, ':') != NULL
)
2287 /* Check that there are remaining characters and that they are digits. */
2291 digits
= strspn (colpos
+ 1, "0123456789");
2292 return digits
!= 0 && colpos
[1 + digits
] == 0;
2295 /* We get rid of the register section here. */
2298 mmix_elf_final_link (abfd
, info
)
2300 struct bfd_link_info
*info
;
2302 /* We never output a register section, though we create one for
2303 temporary measures. Check that nobody entered contents into it. */
2304 asection
*reg_section
;
2306 reg_section
= bfd_get_section_by_name (abfd
, MMIX_REG_SECTION_NAME
);
2308 if (reg_section
!= NULL
)
2310 /* FIXME: Pass error state gracefully. */
2311 if (bfd_get_section_flags (abfd
, reg_section
) & SEC_HAS_CONTENTS
)
2312 _bfd_abort (__FILE__
, __LINE__
, _("Register section has contents\n"));
2314 /* Really remove the section, if it hasn't already been done. */
2315 if (!bfd_section_removed_from_list (abfd
, reg_section
))
2317 bfd_section_list_remove (abfd
, reg_section
);
2318 --abfd
->section_count
;
2322 if (! bfd_elf_final_link (abfd
, info
))
2325 /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
2326 the regular linker machinery. We do it here, like other targets with
2327 special sections. */
2328 if (info
->base_file
!= NULL
)
2330 asection
*greg_section
2331 = bfd_get_section_by_name ((bfd
*) info
->base_file
,
2332 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2333 if (!bfd_set_section_contents (abfd
,
2334 greg_section
->output_section
,
2335 greg_section
->contents
,
2336 (file_ptr
) greg_section
->output_offset
,
2337 greg_section
->size
))
2343 /* We need to include the maximum size of PUSHJ-stubs in the initial
2344 section size. This is expected to shrink during linker relaxation. */
2347 mmix_set_relaxable_size (abfd
, sec
, ptr
)
2348 bfd
*abfd ATTRIBUTE_UNUSED
;
2352 struct bfd_link_info
*info
= ptr
;
2354 /* Make sure we only do this for section where we know we want this,
2355 otherwise we might end up resetting the size of COMMONs. */
2356 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0)
2359 sec
->rawsize
= sec
->size
;
2360 sec
->size
+= (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2361 * MAX_PUSHJ_STUB_SIZE
);
2363 /* For use in relocatable link, we start with a max stubs size. See
2364 mmix_elf_relax_section. */
2365 if (info
->relocatable
&& sec
->output_section
)
2366 mmix_elf_section_data (sec
->output_section
)->pjs
.stubs_size_sum
2367 += (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2368 * MAX_PUSHJ_STUB_SIZE
);
2371 /* Initialize stuff for the linker-generated GREGs to match
2372 R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
2375 _bfd_mmix_before_linker_allocation (abfd
, info
)
2376 bfd
*abfd ATTRIBUTE_UNUSED
;
2377 struct bfd_link_info
*info
;
2379 asection
*bpo_gregs_section
;
2380 bfd
*bpo_greg_owner
;
2381 struct bpo_greg_section_info
*gregdata
;
2385 size_t *bpo_reloc_indexes
;
2388 /* Set the initial size of sections. */
2389 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2390 bfd_map_over_sections (ibfd
, mmix_set_relaxable_size
, info
);
2392 /* The bpo_greg_owner bfd is supposed to have been set by
2393 mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
2394 If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2395 bpo_greg_owner
= (bfd
*) info
->base_file
;
2396 if (bpo_greg_owner
== NULL
)
2400 = bfd_get_section_by_name (bpo_greg_owner
,
2401 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2403 if (bpo_gregs_section
== NULL
)
2406 /* We use the target-data handle in the ELF section data. */
2407 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2408 if (gregdata
== NULL
)
2411 n_gregs
= gregdata
->n_bpo_relocs
;
2412 gregdata
->n_allocated_bpo_gregs
= n_gregs
;
2414 /* When this reaches zero during relaxation, all entries have been
2415 filled in and the size of the linker gregs can be calculated. */
2416 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
= n_gregs
;
2418 /* Set the zeroth-order estimate for the GREGs size. */
2419 gregs_size
= n_gregs
* 8;
2421 if (!bfd_set_section_size (bpo_greg_owner
, bpo_gregs_section
, gregs_size
))
2424 /* Allocate and set up the GREG arrays. They're filled in at relaxation
2425 time. Note that we must use the max number ever noted for the array,
2426 since the index numbers were created before GC. */
2427 gregdata
->reloc_request
2428 = bfd_zalloc (bpo_greg_owner
,
2429 sizeof (struct bpo_reloc_request
)
2430 * gregdata
->n_max_bpo_relocs
);
2432 gregdata
->bpo_reloc_indexes
2434 = bfd_alloc (bpo_greg_owner
,
2435 gregdata
->n_max_bpo_relocs
2437 if (bpo_reloc_indexes
== NULL
)
2440 /* The default order is an identity mapping. */
2441 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2443 bpo_reloc_indexes
[i
] = i
;
2444 gregdata
->reloc_request
[i
].bpo_reloc_no
= i
;
2450 /* Fill in contents in the linker allocated gregs. Everything is
2451 calculated at this point; we just move the contents into place here. */
2454 _bfd_mmix_after_linker_allocation (abfd
, link_info
)
2455 bfd
*abfd ATTRIBUTE_UNUSED
;
2456 struct bfd_link_info
*link_info
;
2458 asection
*bpo_gregs_section
;
2459 bfd
*bpo_greg_owner
;
2460 struct bpo_greg_section_info
*gregdata
;
2466 /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
2467 when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
2468 object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2469 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2470 if (bpo_greg_owner
== NULL
)
2474 = bfd_get_section_by_name (bpo_greg_owner
,
2475 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2477 /* This can't happen without DSO handling. When DSOs are handled
2478 without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
2480 if (bpo_gregs_section
== NULL
)
2483 /* We use the target-data handle in the ELF section data. */
2485 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2486 if (gregdata
== NULL
)
2489 n_gregs
= gregdata
->n_allocated_bpo_gregs
;
2491 bpo_gregs_section
->contents
2492 = contents
= bfd_alloc (bpo_greg_owner
, bpo_gregs_section
->size
);
2493 if (contents
== NULL
)
2496 /* Sanity check: If these numbers mismatch, some relocation has not been
2497 accounted for and the rest of gregdata is probably inconsistent.
2498 It's a bug, but it's more helpful to identify it than segfaulting
2500 if (gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2501 != gregdata
->n_bpo_relocs
)
2503 (*_bfd_error_handler
)
2504 (_("Internal inconsistency: remaining %u != max %u.\n\
2505 Please report this bug."),
2506 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2507 gregdata
->n_bpo_relocs
);
2511 for (lastreg
= 255, i
= 0, j
= 0; j
< n_gregs
; i
++)
2512 if (gregdata
->reloc_request
[i
].regindex
!= lastreg
)
2514 bfd_put_64 (bpo_greg_owner
, gregdata
->reloc_request
[i
].value
,
2516 lastreg
= gregdata
->reloc_request
[i
].regindex
;
2523 /* Sort valid relocs to come before non-valid relocs, then on increasing
2527 bpo_reloc_request_sort_fn (p1
, p2
)
2531 const struct bpo_reloc_request
*r1
= (const struct bpo_reloc_request
*) p1
;
2532 const struct bpo_reloc_request
*r2
= (const struct bpo_reloc_request
*) p2
;
2534 /* Primary function is validity; non-valid relocs sorted after valid
2536 if (r1
->valid
!= r2
->valid
)
2537 return r2
->valid
- r1
->valid
;
2539 /* Then sort on value. Don't simplify and return just the difference of
2540 the values: the upper bits of the 64-bit value would be truncated on
2541 a host with 32-bit ints. */
2542 if (r1
->value
!= r2
->value
)
2543 return r1
->value
> r2
->value
? 1 : -1;
2545 /* As a last re-sort, use the relocation number, so we get a stable
2546 sort. The *addresses* aren't stable since items are swapped during
2547 sorting. It depends on the qsort implementation if this actually
2549 return r1
->bpo_reloc_no
> r2
->bpo_reloc_no
2550 ? 1 : (r1
->bpo_reloc_no
< r2
->bpo_reloc_no
? -1 : 0);
2553 /* For debug use only. Dumps the global register allocations resulting
2554 from base-plus-offset relocs. */
2557 mmix_dump_bpo_gregs (link_info
, pf
)
2558 struct bfd_link_info
*link_info
;
2559 bfd_error_handler_type pf
;
2561 bfd
*bpo_greg_owner
;
2562 asection
*bpo_gregs_section
;
2563 struct bpo_greg_section_info
*gregdata
;
2566 if (link_info
== NULL
|| link_info
->base_file
== NULL
)
2569 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2572 = bfd_get_section_by_name (bpo_greg_owner
,
2573 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2575 if (bpo_gregs_section
== NULL
)
2578 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2579 if (gregdata
== NULL
)
2583 pf
= _bfd_error_handler
;
2585 /* These format strings are not translated. They are for debug purposes
2586 only and never displayed to an end user. Should they escape, we
2587 surely want them in original. */
2588 (*pf
) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
2589 n_allocated_bpo_gregs: %u\n", gregdata
->n_bpo_relocs
,
2590 gregdata
->n_max_bpo_relocs
,
2591 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2592 gregdata
->n_allocated_bpo_gregs
);
2594 if (gregdata
->reloc_request
)
2595 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2596 (*pf
) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
2598 (gregdata
->bpo_reloc_indexes
!= NULL
2599 ? gregdata
->bpo_reloc_indexes
[i
] : (size_t) -1),
2600 gregdata
->reloc_request
[i
].bpo_reloc_no
,
2601 gregdata
->reloc_request
[i
].valid
,
2603 (unsigned long) (gregdata
->reloc_request
[i
].value
>> 32),
2604 (unsigned long) gregdata
->reloc_request
[i
].value
,
2605 gregdata
->reloc_request
[i
].regindex
,
2606 gregdata
->reloc_request
[i
].offset
);
2609 /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
2610 when the last such reloc is done, an index-array is sorted according to
2611 the values and iterated over to produce register numbers (indexed by 0
2612 from the first allocated register number) and offsets for use in real
2613 relocation. (N.B.: Relocatable runs are handled, not just punted.)
2615 PUSHJ stub accounting is also done here.
2617 Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
2620 mmix_elf_relax_section (abfd
, sec
, link_info
, again
)
2623 struct bfd_link_info
*link_info
;
2626 Elf_Internal_Shdr
*symtab_hdr
;
2627 Elf_Internal_Rela
*internal_relocs
;
2628 Elf_Internal_Rela
*irel
, *irelend
;
2629 asection
*bpo_gregs_section
= NULL
;
2630 struct bpo_greg_section_info
*gregdata
;
2631 struct bpo_reloc_section_info
*bpodata
2632 = mmix_elf_section_data (sec
)->bpo
.reloc
;
2633 /* The initialization is to quiet compiler warnings. The value is to
2634 spot a missing actual initialization. */
2635 size_t bpono
= (size_t) -1;
2637 Elf_Internal_Sym
*isymbuf
= NULL
;
2638 bfd_size_type size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
2640 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
= 0;
2642 /* Assume nothing changes. */
2645 /* We don't have to do anything if this section does not have relocs, or
2646 if this is not a code section. */
2647 if ((sec
->flags
& SEC_RELOC
) == 0
2648 || sec
->reloc_count
== 0
2649 || (sec
->flags
& SEC_CODE
) == 0
2650 || (sec
->flags
& SEC_LINKER_CREATED
) != 0
2651 /* If no R_MMIX_BASE_PLUS_OFFSET relocs and no PUSHJ-stub relocs,
2652 then nothing to do. */
2654 && mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0))
2657 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2659 if (bpodata
!= NULL
)
2661 bpo_gregs_section
= bpodata
->bpo_greg_section
;
2662 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2663 bpono
= bpodata
->first_base_plus_offset_reloc
;
2668 /* Get a copy of the native relocations. */
2670 = _bfd_elf_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
2671 (Elf_Internal_Rela
*) NULL
,
2672 link_info
->keep_memory
);
2673 if (internal_relocs
== NULL
)
2676 /* Walk through them looking for relaxing opportunities. */
2677 irelend
= internal_relocs
+ sec
->reloc_count
;
2678 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2681 struct elf_link_hash_entry
*h
= NULL
;
2683 /* We only process two relocs. */
2684 if (ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_BASE_PLUS_OFFSET
2685 && ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_PUSHJ_STUBBABLE
)
2688 /* We process relocs in a distinctly different way when this is a
2689 relocatable link (for one, we don't look at symbols), so we avoid
2690 mixing its code with that for the "normal" relaxation. */
2691 if (link_info
->relocatable
)
2693 /* The only transformation in a relocatable link is to generate
2694 a full stub at the location of the stub calculated for the
2695 input section, if the relocated stub location, the end of the
2696 output section plus earlier stubs, cannot be reached. Thus
2697 relocatable linking can only lead to worse code, but it still
2699 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_PUSHJ_STUBBABLE
)
2701 /* If we can reach the end of the output-section and beyond
2702 any current stubs, then we don't need a stub for this
2703 reloc. The relaxed order of output stub allocation may
2704 not exactly match the straightforward order, so we always
2705 assume presence of output stubs, which will allow
2706 relaxation only on relocations indifferent to the
2707 presence of output stub allocations for other relocations
2708 and thus the order of output stub allocation. */
2709 if (bfd_check_overflow (complain_overflow_signed
,
2712 bfd_arch_bits_per_address (abfd
),
2713 /* Output-stub location. */
2714 sec
->output_section
->rawsize
2715 + (mmix_elf_section_data (sec
2717 ->pjs
.stubs_size_sum
)
2718 /* Location of this PUSHJ reloc. */
2719 - (sec
->output_offset
+ irel
->r_offset
)
2720 /* Don't count *this* stub twice. */
2721 - (mmix_elf_section_data (sec
)
2722 ->pjs
.stub_size
[pjsno
]
2723 + MAX_PUSHJ_STUB_SIZE
))
2725 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2727 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2728 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2736 /* Get the value of the symbol referred to by the reloc. */
2737 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2739 /* A local symbol. */
2740 Elf_Internal_Sym
*isym
;
2743 /* Read this BFD's local symbols if we haven't already. */
2744 if (isymbuf
== NULL
)
2746 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2747 if (isymbuf
== NULL
)
2748 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2749 symtab_hdr
->sh_info
, 0,
2755 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
2756 if (isym
->st_shndx
== SHN_UNDEF
)
2757 sym_sec
= bfd_und_section_ptr
;
2758 else if (isym
->st_shndx
== SHN_ABS
)
2759 sym_sec
= bfd_abs_section_ptr
;
2760 else if (isym
->st_shndx
== SHN_COMMON
)
2761 sym_sec
= bfd_com_section_ptr
;
2763 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2764 symval
= (isym
->st_value
2765 + sym_sec
->output_section
->vma
2766 + sym_sec
->output_offset
);
2772 /* An external symbol. */
2773 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2774 h
= elf_sym_hashes (abfd
)[indx
];
2775 BFD_ASSERT (h
!= NULL
);
2776 if (h
->root
.type
!= bfd_link_hash_defined
2777 && h
->root
.type
!= bfd_link_hash_defweak
)
2779 /* This appears to be a reference to an undefined symbol. Just
2780 ignore it--it will be caught by the regular reloc processing.
2781 We need to keep BPO reloc accounting consistent, though
2782 else we'll abort instead of emitting an error message. */
2783 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_BASE_PLUS_OFFSET
2784 && gregdata
!= NULL
)
2786 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2792 symval
= (h
->root
.u
.def
.value
2793 + h
->root
.u
.def
.section
->output_section
->vma
2794 + h
->root
.u
.def
.section
->output_offset
);
2797 if (ELF64_R_TYPE (irel
->r_info
) == (int) R_MMIX_PUSHJ_STUBBABLE
)
2799 bfd_vma value
= symval
+ irel
->r_addend
;
2801 = (sec
->output_section
->vma
2802 + sec
->output_offset
2805 = (sec
->output_section
->vma
2806 + sec
->output_offset
2808 + mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
);
2810 if ((value
& 3) == 0
2811 && bfd_check_overflow (complain_overflow_signed
,
2814 bfd_arch_bits_per_address (abfd
),
2817 ? mmix_elf_section_data (sec
)
2818 ->pjs
.stub_size
[pjsno
]
2821 /* If the reloc fits, no stub is needed. */
2822 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2824 /* Maybe we can get away with just a JMP insn? */
2825 if ((value
& 3) == 0
2826 && bfd_check_overflow (complain_overflow_signed
,
2829 bfd_arch_bits_per_address (abfd
),
2832 ? mmix_elf_section_data (sec
)
2833 ->pjs
.stub_size
[pjsno
] - 4
2836 /* Yep, account for a stub consisting of a single JMP insn. */
2837 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 4;
2839 /* Nope, go for the full insn stub. It doesn't seem useful to
2840 emit the intermediate sizes; those will only be useful for
2841 a >64M program assuming contiguous code. */
2842 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
]
2843 = MAX_PUSHJ_STUB_SIZE
;
2845 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2846 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2851 /* We're looking at a R_MMIX_BASE_PLUS_OFFSET reloc. */
2853 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
]].value
2854 = symval
+ irel
->r_addend
;
2855 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
++]].valid
= TRUE
;
2856 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2859 /* Check if that was the last BPO-reloc. If so, sort the values and
2860 calculate how many registers we need to cover them. Set the size of
2861 the linker gregs, and if the number of registers changed, indicate
2862 that we need to relax some more because we have more work to do. */
2863 if (gregdata
!= NULL
2864 && gregdata
->n_remaining_bpo_relocs_this_relaxation_round
== 0)
2870 /* First, reset the remaining relocs for the next round. */
2871 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2872 = gregdata
->n_bpo_relocs
;
2874 qsort ((PTR
) gregdata
->reloc_request
,
2875 gregdata
->n_max_bpo_relocs
,
2876 sizeof (struct bpo_reloc_request
),
2877 bpo_reloc_request_sort_fn
);
2879 /* Recalculate indexes. When we find a change (however unlikely
2880 after the initial iteration), we know we need to relax again,
2881 since items in the GREG-array are sorted by increasing value and
2882 stored in the relaxation phase. */
2883 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2884 if (gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2887 gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2892 /* Allocate register numbers (indexing from 0). Stop at the first
2894 for (i
= 0, regindex
= 0, prev_base
= gregdata
->reloc_request
[0].value
;
2895 i
< gregdata
->n_bpo_relocs
;
2898 if (gregdata
->reloc_request
[i
].value
> prev_base
+ 255)
2901 prev_base
= gregdata
->reloc_request
[i
].value
;
2903 gregdata
->reloc_request
[i
].regindex
= regindex
;
2904 gregdata
->reloc_request
[i
].offset
2905 = gregdata
->reloc_request
[i
].value
- prev_base
;
2908 /* If it's not the same as the last time, we need to relax again,
2909 because the size of the section has changed. I'm not sure we
2910 actually need to do any adjustments since the shrinking happens
2911 at the start of this section, but better safe than sorry. */
2912 if (gregdata
->n_allocated_bpo_gregs
!= regindex
+ 1)
2914 gregdata
->n_allocated_bpo_gregs
= regindex
+ 1;
2918 bpo_gregs_section
->size
= (regindex
+ 1) * 8;
2921 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2923 if (! link_info
->keep_memory
)
2927 /* Cache the symbols for elf_link_input_bfd. */
2928 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2932 if (internal_relocs
!= NULL
2933 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2934 free (internal_relocs
);
2936 if (sec
->size
< size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2939 if (sec
->size
> size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2941 sec
->size
= size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
;
2948 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2950 if (internal_relocs
!= NULL
2951 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2952 free (internal_relocs
);
2956 #define ELF_ARCH bfd_arch_mmix
2957 #define ELF_MACHINE_CODE EM_MMIX
2959 /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
2960 However, that's too much for something somewhere in the linker part of
2961 BFD; perhaps the start-address has to be a non-zero multiple of this
2962 number, or larger than this number. The symptom is that the linker
2963 complains: "warning: allocated section `.text' not in segment". We
2964 settle for 64k; the page-size used in examples is 8k.
2965 #define ELF_MAXPAGESIZE 0x10000
2967 Unfortunately, this causes excessive padding in the supposedly small
2968 for-education programs that are the expected usage (where people would
2969 inspect output). We stick to 256 bytes just to have *some* default
2971 #define ELF_MAXPAGESIZE 0x100
2973 #define TARGET_BIG_SYM bfd_elf64_mmix_vec
2974 #define TARGET_BIG_NAME "elf64-mmix"
2976 #define elf_info_to_howto_rel NULL
2977 #define elf_info_to_howto mmix_info_to_howto_rela
2978 #define elf_backend_relocate_section mmix_elf_relocate_section
2979 #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
2980 #define elf_backend_gc_sweep_hook mmix_elf_gc_sweep_hook
2982 #define elf_backend_link_output_symbol_hook \
2983 mmix_elf_link_output_symbol_hook
2984 #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
2986 #define elf_backend_check_relocs mmix_elf_check_relocs
2987 #define elf_backend_symbol_processing mmix_elf_symbol_processing
2988 #define elf_backend_omit_section_dynsym \
2989 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
2991 #define bfd_elf64_bfd_is_local_label_name \
2992 mmix_elf_is_local_label_name
2994 #define elf_backend_may_use_rel_p 0
2995 #define elf_backend_may_use_rela_p 1
2996 #define elf_backend_default_use_rela_p 1
2998 #define elf_backend_can_gc_sections 1
2999 #define elf_backend_section_from_bfd_section \
3000 mmix_elf_section_from_bfd_section
3002 #define bfd_elf64_new_section_hook mmix_elf_new_section_hook
3003 #define bfd_elf64_bfd_final_link mmix_elf_final_link
3004 #define bfd_elf64_bfd_relax_section mmix_elf_relax_section
3006 #include "elf64-target.h"