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. */
1775 = bfd_get_section_vma (input_section
->output_section
->owner
,
1777 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1778 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1780 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1781 /* The bfd_reloc_outofrange return value, though
1782 intuitively a better value, will not get us an error. */
1783 return bfd_reloc_overflow
;
1788 if ((bfd_vma
) srel
>= first_global
)
1790 /* FIXME: Better error message. */
1791 (*_bfd_error_handler
)
1792 (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."),
1793 bfd_get_filename (input_section
->owner
), (long) srel
, (long) first_global
);
1795 return bfd_reloc_overflow
;
1802 r
= _bfd_final_link_relocate (howto
, input_section
->owner
, input_section
,
1804 relocation
, r_addend
);
1810 /* Return the section that should be marked against GC for a given
1814 mmix_elf_gc_mark_hook (asection
*sec
,
1815 struct bfd_link_info
*info
,
1816 Elf_Internal_Rela
*rel
,
1817 struct elf_link_hash_entry
*h
,
1818 Elf_Internal_Sym
*sym
)
1821 switch (ELF64_R_TYPE (rel
->r_info
))
1823 case R_MMIX_GNU_VTINHERIT
:
1824 case R_MMIX_GNU_VTENTRY
:
1828 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1831 /* Update relocation info for a GC-excluded section. We could supposedly
1832 perform the allocation after GC, but there's no suitable hook between
1833 GC (or section merge) and the point when all input sections must be
1834 present. Better to waste some memory and (perhaps) a little time. */
1837 mmix_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
1838 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1840 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
1842 struct bpo_reloc_section_info
*bpodata
1843 = mmix_elf_section_data (sec
)->bpo
.reloc
;
1844 asection
*allocated_gregs_section
;
1846 /* If no bpodata here, we have nothing to do. */
1847 if (bpodata
== NULL
)
1850 allocated_gregs_section
= bpodata
->bpo_greg_section
;
1852 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
->n_bpo_relocs
1853 -= bpodata
->n_bpo_relocs_this_section
;
1858 /* Sort register relocs to come before expanding relocs. */
1861 mmix_elf_sort_relocs (p1
, p2
)
1865 const Elf_Internal_Rela
*r1
= (const Elf_Internal_Rela
*) p1
;
1866 const Elf_Internal_Rela
*r2
= (const Elf_Internal_Rela
*) p2
;
1867 int r1_is_reg
, r2_is_reg
;
1869 /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1871 if ((r1
->r_offset
& ~(bfd_vma
) 3) > (r2
->r_offset
& ~(bfd_vma
) 3))
1873 else if ((r1
->r_offset
& ~(bfd_vma
) 3) < (r2
->r_offset
& ~(bfd_vma
) 3))
1877 = (ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG_OR_BYTE
1878 || ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG
);
1880 = (ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG_OR_BYTE
1881 || ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG
);
1882 if (r1_is_reg
!= r2_is_reg
)
1883 return r2_is_reg
- r1_is_reg
;
1885 /* Neither or both are register relocs. Then sort on full offset. */
1886 if (r1
->r_offset
> r2
->r_offset
)
1888 else if (r1
->r_offset
< r2
->r_offset
)
1893 /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
1896 mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
)
1898 struct bfd_link_info
*info
;
1900 const Elf_Internal_Rela
*relocs
;
1902 bfd
*bpo_greg_owner
= NULL
;
1903 asection
*allocated_gregs_section
= NULL
;
1904 struct bpo_greg_section_info
*gregdata
= NULL
;
1905 struct bpo_reloc_section_info
*bpodata
= NULL
;
1906 const Elf_Internal_Rela
*rel
;
1907 const Elf_Internal_Rela
*rel_end
;
1909 /* We currently have to abuse this COFF-specific member, since there's
1910 no target-machine-dedicated member. There's no alternative outside
1911 the bfd_link_info struct; we can't specialize a hash-table since
1912 they're different between ELF and mmo. */
1913 bpo_greg_owner
= (bfd
*) info
->base_file
;
1915 rel_end
= relocs
+ sec
->reloc_count
;
1916 for (rel
= relocs
; rel
< rel_end
; rel
++)
1918 switch (ELF64_R_TYPE (rel
->r_info
))
1920 /* This relocation causes a GREG allocation. We need to count
1921 them, and we need to create a section for them, so we need an
1922 object to fake as the owner of that section. We can't use
1923 the ELF dynobj for this, since the ELF bits assume lots of
1924 DSO-related stuff if that member is non-NULL. */
1925 case R_MMIX_BASE_PLUS_OFFSET
:
1926 /* We don't do anything with this reloc for a relocatable link. */
1927 if (info
->relocatable
)
1930 if (bpo_greg_owner
== NULL
)
1932 bpo_greg_owner
= abfd
;
1933 info
->base_file
= (PTR
) bpo_greg_owner
;
1936 if (allocated_gregs_section
== NULL
)
1937 allocated_gregs_section
1938 = bfd_get_section_by_name (bpo_greg_owner
,
1939 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
1941 if (allocated_gregs_section
== NULL
)
1943 allocated_gregs_section
1944 = bfd_make_section_with_flags (bpo_greg_owner
,
1945 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
,
1948 | SEC_LINKER_CREATED
));
1949 /* Setting both SEC_ALLOC and SEC_LOAD means the section is
1950 treated like any other section, and we'd get errors for
1951 address overlap with the text section. Let's set none of
1952 those flags, as that is what currently happens for usual
1953 GREG allocations, and that works. */
1954 if (allocated_gregs_section
== NULL
1955 || !bfd_set_section_alignment (bpo_greg_owner
,
1956 allocated_gregs_section
,
1960 gregdata
= (struct bpo_greg_section_info
*)
1961 bfd_zalloc (bpo_greg_owner
, sizeof (struct bpo_greg_section_info
));
1962 if (gregdata
== NULL
)
1964 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
1967 else if (gregdata
== NULL
)
1969 = mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
;
1971 /* Get ourselves some auxiliary info for the BPO-relocs. */
1972 if (bpodata
== NULL
)
1974 /* No use doing a separate iteration pass to find the upper
1975 limit - just use the number of relocs. */
1976 bpodata
= (struct bpo_reloc_section_info
*)
1977 bfd_alloc (bpo_greg_owner
,
1978 sizeof (struct bpo_reloc_section_info
)
1979 * (sec
->reloc_count
+ 1));
1980 if (bpodata
== NULL
)
1982 mmix_elf_section_data (sec
)->bpo
.reloc
= bpodata
;
1983 bpodata
->first_base_plus_offset_reloc
1984 = bpodata
->bpo_index
1985 = gregdata
->n_max_bpo_relocs
;
1986 bpodata
->bpo_greg_section
1987 = allocated_gregs_section
;
1988 bpodata
->n_bpo_relocs_this_section
= 0;
1991 bpodata
->n_bpo_relocs_this_section
++;
1992 gregdata
->n_max_bpo_relocs
++;
1994 /* We don't get another chance to set this before GC; we've not
1995 set up any hook that runs before GC. */
1996 gregdata
->n_bpo_relocs
1997 = gregdata
->n_max_bpo_relocs
;
2000 case R_MMIX_PUSHJ_STUBBABLE
:
2001 mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
++;
2006 /* Allocate per-reloc stub storage and initialize it to the max stub
2008 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
!= 0)
2012 mmix_elf_section_data (sec
)->pjs
.stub_size
2013 = bfd_alloc (abfd
, mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2014 * sizeof (mmix_elf_section_data (sec
)
2015 ->pjs
.stub_size
[0]));
2016 if (mmix_elf_section_data (sec
)->pjs
.stub_size
== NULL
)
2019 for (i
= 0; i
< mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
; i
++)
2020 mmix_elf_section_data (sec
)->pjs
.stub_size
[i
] = MAX_PUSHJ_STUB_SIZE
;
2026 /* Look through the relocs for a section during the first phase. */
2029 mmix_elf_check_relocs (abfd
, info
, sec
, relocs
)
2031 struct bfd_link_info
*info
;
2033 const Elf_Internal_Rela
*relocs
;
2035 Elf_Internal_Shdr
*symtab_hdr
;
2036 struct elf_link_hash_entry
**sym_hashes
;
2037 const Elf_Internal_Rela
*rel
;
2038 const Elf_Internal_Rela
*rel_end
;
2040 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2041 sym_hashes
= elf_sym_hashes (abfd
);
2043 /* First we sort the relocs so that any register relocs come before
2044 expansion-relocs to the same insn. FIXME: Not done for mmo. */
2045 qsort ((PTR
) relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
2046 mmix_elf_sort_relocs
);
2048 /* Do the common part. */
2049 if (!mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
))
2052 if (info
->relocatable
)
2055 rel_end
= relocs
+ sec
->reloc_count
;
2056 for (rel
= relocs
; rel
< rel_end
; rel
++)
2058 struct elf_link_hash_entry
*h
;
2059 unsigned long r_symndx
;
2061 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2062 if (r_symndx
< symtab_hdr
->sh_info
)
2066 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2067 while (h
->root
.type
== bfd_link_hash_indirect
2068 || h
->root
.type
== bfd_link_hash_warning
)
2069 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2072 switch (ELF64_R_TYPE (rel
->r_info
))
2074 /* This relocation describes the C++ object vtable hierarchy.
2075 Reconstruct it for later use during GC. */
2076 case R_MMIX_GNU_VTINHERIT
:
2077 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2081 /* This relocation describes which C++ vtable entries are actually
2082 used. Record for later use during GC. */
2083 case R_MMIX_GNU_VTENTRY
:
2084 BFD_ASSERT (h
!= NULL
);
2086 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2095 /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
2096 Copied from elf_link_add_object_symbols. */
2099 _bfd_mmix_check_all_relocs (abfd
, info
)
2101 struct bfd_link_info
*info
;
2105 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2107 Elf_Internal_Rela
*internal_relocs
;
2110 if ((o
->flags
& SEC_RELOC
) == 0
2111 || o
->reloc_count
== 0
2112 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
2113 && (o
->flags
& SEC_DEBUGGING
) != 0)
2114 || bfd_is_abs_section (o
->output_section
))
2118 = _bfd_elf_link_read_relocs (abfd
, o
, (PTR
) NULL
,
2119 (Elf_Internal_Rela
*) NULL
,
2121 if (internal_relocs
== NULL
)
2124 ok
= mmix_elf_check_common_relocs (abfd
, info
, o
, internal_relocs
);
2126 if (! info
->keep_memory
)
2127 free (internal_relocs
);
2136 /* Change symbols relative to the reg contents section to instead be to
2137 the register section, and scale them down to correspond to the register
2141 mmix_elf_link_output_symbol_hook (info
, name
, sym
, input_sec
, h
)
2142 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2143 const char *name ATTRIBUTE_UNUSED
;
2144 Elf_Internal_Sym
*sym
;
2145 asection
*input_sec
;
2146 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
;
2148 if (input_sec
!= NULL
2149 && input_sec
->name
!= NULL
2150 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2151 && strcmp (input_sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2154 sym
->st_shndx
= SHN_REGISTER
;
2160 /* We fake a register section that holds values that are register numbers.
2161 Having a SHN_REGISTER and register section translates better to other
2162 formats (e.g. mmo) than for example a STT_REGISTER attribute.
2163 This section faking is based on a construct in elf32-mips.c. */
2164 static asection mmix_elf_reg_section
;
2165 static asymbol mmix_elf_reg_section_symbol
;
2166 static asymbol
*mmix_elf_reg_section_symbol_ptr
;
2168 /* Handle the special section numbers that a symbol may use. */
2171 mmix_elf_symbol_processing (abfd
, asym
)
2172 bfd
*abfd ATTRIBUTE_UNUSED
;
2175 elf_symbol_type
*elfsym
;
2177 elfsym
= (elf_symbol_type
*) asym
;
2178 switch (elfsym
->internal_elf_sym
.st_shndx
)
2181 if (mmix_elf_reg_section
.name
== NULL
)
2183 /* Initialize the register section. */
2184 mmix_elf_reg_section
.name
= MMIX_REG_SECTION_NAME
;
2185 mmix_elf_reg_section
.flags
= SEC_NO_FLAGS
;
2186 mmix_elf_reg_section
.output_section
= &mmix_elf_reg_section
;
2187 mmix_elf_reg_section
.symbol
= &mmix_elf_reg_section_symbol
;
2188 mmix_elf_reg_section
.symbol_ptr_ptr
= &mmix_elf_reg_section_symbol_ptr
;
2189 mmix_elf_reg_section_symbol
.name
= MMIX_REG_SECTION_NAME
;
2190 mmix_elf_reg_section_symbol
.flags
= BSF_SECTION_SYM
;
2191 mmix_elf_reg_section_symbol
.section
= &mmix_elf_reg_section
;
2192 mmix_elf_reg_section_symbol_ptr
= &mmix_elf_reg_section_symbol
;
2194 asym
->section
= &mmix_elf_reg_section
;
2202 /* Given a BFD section, try to locate the corresponding ELF section
2206 mmix_elf_section_from_bfd_section (abfd
, sec
, retval
)
2207 bfd
* abfd ATTRIBUTE_UNUSED
;
2211 if (strcmp (bfd_get_section_name (abfd
, sec
), MMIX_REG_SECTION_NAME
) == 0)
2212 *retval
= SHN_REGISTER
;
2219 /* Hook called by the linker routine which adds symbols from an object
2220 file. We must handle the special SHN_REGISTER section number here.
2222 We also check that we only have *one* each of the section-start
2223 symbols, since otherwise having two with the same value would cause
2224 them to be "merged", but with the contents serialized. */
2227 mmix_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2229 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2230 Elf_Internal_Sym
*sym
;
2231 const char **namep ATTRIBUTE_UNUSED
;
2232 flagword
*flagsp ATTRIBUTE_UNUSED
;
2234 bfd_vma
*valp ATTRIBUTE_UNUSED
;
2236 if (sym
->st_shndx
== SHN_REGISTER
)
2238 *secp
= bfd_make_section_old_way (abfd
, MMIX_REG_SECTION_NAME
);
2239 (*secp
)->flags
|= SEC_LINKER_CREATED
;
2241 else if ((*namep
)[0] == '_' && (*namep
)[1] == '_' && (*namep
)[2] == '.'
2242 && CONST_STRNEQ (*namep
, MMIX_LOC_SECTION_START_SYMBOL_PREFIX
))
2244 /* See if we have another one. */
2245 struct bfd_link_hash_entry
*h
= bfd_link_hash_lookup (info
->hash
,
2251 if (h
!= NULL
&& h
->type
!= bfd_link_hash_undefined
)
2253 /* How do we get the asymbol (or really: the filename) from h?
2254 h->u.def.section->owner is NULL. */
2255 ((*_bfd_error_handler
)
2256 (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
2257 bfd_get_filename (abfd
), *namep
,
2258 *namep
+ strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
)));
2259 bfd_set_error (bfd_error_bad_value
);
2267 /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
2270 mmix_elf_is_local_label_name (abfd
, name
)
2277 /* Also include the default local-label definition. */
2278 if (_bfd_elf_is_local_label_name (abfd
, name
))
2284 /* If there's no ":", or more than one, it's not a local symbol. */
2285 colpos
= strchr (name
, ':');
2286 if (colpos
== NULL
|| strchr (colpos
+ 1, ':') != NULL
)
2289 /* Check that there are remaining characters and that they are digits. */
2293 digits
= strspn (colpos
+ 1, "0123456789");
2294 return digits
!= 0 && colpos
[1 + digits
] == 0;
2297 /* We get rid of the register section here. */
2300 mmix_elf_final_link (abfd
, info
)
2302 struct bfd_link_info
*info
;
2304 /* We never output a register section, though we create one for
2305 temporary measures. Check that nobody entered contents into it. */
2306 asection
*reg_section
;
2308 reg_section
= bfd_get_section_by_name (abfd
, MMIX_REG_SECTION_NAME
);
2310 if (reg_section
!= NULL
)
2312 /* FIXME: Pass error state gracefully. */
2313 if (bfd_get_section_flags (abfd
, reg_section
) & SEC_HAS_CONTENTS
)
2314 _bfd_abort (__FILE__
, __LINE__
, _("Register section has contents\n"));
2316 /* Really remove the section, if it hasn't already been done. */
2317 if (!bfd_section_removed_from_list (abfd
, reg_section
))
2319 bfd_section_list_remove (abfd
, reg_section
);
2320 --abfd
->section_count
;
2324 if (! bfd_elf_final_link (abfd
, info
))
2327 /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
2328 the regular linker machinery. We do it here, like other targets with
2329 special sections. */
2330 if (info
->base_file
!= NULL
)
2332 asection
*greg_section
2333 = bfd_get_section_by_name ((bfd
*) info
->base_file
,
2334 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2335 if (!bfd_set_section_contents (abfd
,
2336 greg_section
->output_section
,
2337 greg_section
->contents
,
2338 (file_ptr
) greg_section
->output_offset
,
2339 greg_section
->size
))
2345 /* We need to include the maximum size of PUSHJ-stubs in the initial
2346 section size. This is expected to shrink during linker relaxation. */
2349 mmix_set_relaxable_size (abfd
, sec
, ptr
)
2350 bfd
*abfd ATTRIBUTE_UNUSED
;
2354 struct bfd_link_info
*info
= ptr
;
2356 /* Make sure we only do this for section where we know we want this,
2357 otherwise we might end up resetting the size of COMMONs. */
2358 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0)
2361 sec
->rawsize
= sec
->size
;
2362 sec
->size
+= (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2363 * MAX_PUSHJ_STUB_SIZE
);
2365 /* For use in relocatable link, we start with a max stubs size. See
2366 mmix_elf_relax_section. */
2367 if (info
->relocatable
&& sec
->output_section
)
2368 mmix_elf_section_data (sec
->output_section
)->pjs
.stubs_size_sum
2369 += (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2370 * MAX_PUSHJ_STUB_SIZE
);
2373 /* Initialize stuff for the linker-generated GREGs to match
2374 R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
2377 _bfd_mmix_before_linker_allocation (abfd
, info
)
2378 bfd
*abfd ATTRIBUTE_UNUSED
;
2379 struct bfd_link_info
*info
;
2381 asection
*bpo_gregs_section
;
2382 bfd
*bpo_greg_owner
;
2383 struct bpo_greg_section_info
*gregdata
;
2387 size_t *bpo_reloc_indexes
;
2390 /* Set the initial size of sections. */
2391 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2392 bfd_map_over_sections (ibfd
, mmix_set_relaxable_size
, info
);
2394 /* The bpo_greg_owner bfd is supposed to have been set by
2395 mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
2396 If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2397 bpo_greg_owner
= (bfd
*) info
->base_file
;
2398 if (bpo_greg_owner
== NULL
)
2402 = bfd_get_section_by_name (bpo_greg_owner
,
2403 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2405 if (bpo_gregs_section
== NULL
)
2408 /* We use the target-data handle in the ELF section data. */
2409 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2410 if (gregdata
== NULL
)
2413 n_gregs
= gregdata
->n_bpo_relocs
;
2414 gregdata
->n_allocated_bpo_gregs
= n_gregs
;
2416 /* When this reaches zero during relaxation, all entries have been
2417 filled in and the size of the linker gregs can be calculated. */
2418 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
= n_gregs
;
2420 /* Set the zeroth-order estimate for the GREGs size. */
2421 gregs_size
= n_gregs
* 8;
2423 if (!bfd_set_section_size (bpo_greg_owner
, bpo_gregs_section
, gregs_size
))
2426 /* Allocate and set up the GREG arrays. They're filled in at relaxation
2427 time. Note that we must use the max number ever noted for the array,
2428 since the index numbers were created before GC. */
2429 gregdata
->reloc_request
2430 = bfd_zalloc (bpo_greg_owner
,
2431 sizeof (struct bpo_reloc_request
)
2432 * gregdata
->n_max_bpo_relocs
);
2434 gregdata
->bpo_reloc_indexes
2436 = bfd_alloc (bpo_greg_owner
,
2437 gregdata
->n_max_bpo_relocs
2439 if (bpo_reloc_indexes
== NULL
)
2442 /* The default order is an identity mapping. */
2443 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2445 bpo_reloc_indexes
[i
] = i
;
2446 gregdata
->reloc_request
[i
].bpo_reloc_no
= i
;
2452 /* Fill in contents in the linker allocated gregs. Everything is
2453 calculated at this point; we just move the contents into place here. */
2456 _bfd_mmix_after_linker_allocation (abfd
, link_info
)
2457 bfd
*abfd ATTRIBUTE_UNUSED
;
2458 struct bfd_link_info
*link_info
;
2460 asection
*bpo_gregs_section
;
2461 bfd
*bpo_greg_owner
;
2462 struct bpo_greg_section_info
*gregdata
;
2468 /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
2469 when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
2470 object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2471 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2472 if (bpo_greg_owner
== NULL
)
2476 = bfd_get_section_by_name (bpo_greg_owner
,
2477 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2479 /* This can't happen without DSO handling. When DSOs are handled
2480 without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
2482 if (bpo_gregs_section
== NULL
)
2485 /* We use the target-data handle in the ELF section data. */
2487 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2488 if (gregdata
== NULL
)
2491 n_gregs
= gregdata
->n_allocated_bpo_gregs
;
2493 bpo_gregs_section
->contents
2494 = contents
= bfd_alloc (bpo_greg_owner
, bpo_gregs_section
->size
);
2495 if (contents
== NULL
)
2498 /* Sanity check: If these numbers mismatch, some relocation has not been
2499 accounted for and the rest of gregdata is probably inconsistent.
2500 It's a bug, but it's more helpful to identify it than segfaulting
2502 if (gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2503 != gregdata
->n_bpo_relocs
)
2505 (*_bfd_error_handler
)
2506 (_("Internal inconsistency: remaining %u != max %u.\n\
2507 Please report this bug."),
2508 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2509 gregdata
->n_bpo_relocs
);
2513 for (lastreg
= 255, i
= 0, j
= 0; j
< n_gregs
; i
++)
2514 if (gregdata
->reloc_request
[i
].regindex
!= lastreg
)
2516 bfd_put_64 (bpo_greg_owner
, gregdata
->reloc_request
[i
].value
,
2518 lastreg
= gregdata
->reloc_request
[i
].regindex
;
2525 /* Sort valid relocs to come before non-valid relocs, then on increasing
2529 bpo_reloc_request_sort_fn (p1
, p2
)
2533 const struct bpo_reloc_request
*r1
= (const struct bpo_reloc_request
*) p1
;
2534 const struct bpo_reloc_request
*r2
= (const struct bpo_reloc_request
*) p2
;
2536 /* Primary function is validity; non-valid relocs sorted after valid
2538 if (r1
->valid
!= r2
->valid
)
2539 return r2
->valid
- r1
->valid
;
2541 /* Then sort on value. Don't simplify and return just the difference of
2542 the values: the upper bits of the 64-bit value would be truncated on
2543 a host with 32-bit ints. */
2544 if (r1
->value
!= r2
->value
)
2545 return r1
->value
> r2
->value
? 1 : -1;
2547 /* As a last re-sort, use the relocation number, so we get a stable
2548 sort. The *addresses* aren't stable since items are swapped during
2549 sorting. It depends on the qsort implementation if this actually
2551 return r1
->bpo_reloc_no
> r2
->bpo_reloc_no
2552 ? 1 : (r1
->bpo_reloc_no
< r2
->bpo_reloc_no
? -1 : 0);
2555 /* For debug use only. Dumps the global register allocations resulting
2556 from base-plus-offset relocs. */
2559 mmix_dump_bpo_gregs (link_info
, pf
)
2560 struct bfd_link_info
*link_info
;
2561 bfd_error_handler_type pf
;
2563 bfd
*bpo_greg_owner
;
2564 asection
*bpo_gregs_section
;
2565 struct bpo_greg_section_info
*gregdata
;
2568 if (link_info
== NULL
|| link_info
->base_file
== NULL
)
2571 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2574 = bfd_get_section_by_name (bpo_greg_owner
,
2575 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2577 if (bpo_gregs_section
== NULL
)
2580 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2581 if (gregdata
== NULL
)
2585 pf
= _bfd_error_handler
;
2587 /* These format strings are not translated. They are for debug purposes
2588 only and never displayed to an end user. Should they escape, we
2589 surely want them in original. */
2590 (*pf
) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
2591 n_allocated_bpo_gregs: %u\n", gregdata
->n_bpo_relocs
,
2592 gregdata
->n_max_bpo_relocs
,
2593 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2594 gregdata
->n_allocated_bpo_gregs
);
2596 if (gregdata
->reloc_request
)
2597 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2598 (*pf
) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
2600 (gregdata
->bpo_reloc_indexes
!= NULL
2601 ? gregdata
->bpo_reloc_indexes
[i
] : (size_t) -1),
2602 gregdata
->reloc_request
[i
].bpo_reloc_no
,
2603 gregdata
->reloc_request
[i
].valid
,
2605 (unsigned long) (gregdata
->reloc_request
[i
].value
>> 32),
2606 (unsigned long) gregdata
->reloc_request
[i
].value
,
2607 gregdata
->reloc_request
[i
].regindex
,
2608 gregdata
->reloc_request
[i
].offset
);
2611 /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
2612 when the last such reloc is done, an index-array is sorted according to
2613 the values and iterated over to produce register numbers (indexed by 0
2614 from the first allocated register number) and offsets for use in real
2615 relocation. (N.B.: Relocatable runs are handled, not just punted.)
2617 PUSHJ stub accounting is also done here.
2619 Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
2622 mmix_elf_relax_section (abfd
, sec
, link_info
, again
)
2625 struct bfd_link_info
*link_info
;
2628 Elf_Internal_Shdr
*symtab_hdr
;
2629 Elf_Internal_Rela
*internal_relocs
;
2630 Elf_Internal_Rela
*irel
, *irelend
;
2631 asection
*bpo_gregs_section
= NULL
;
2632 struct bpo_greg_section_info
*gregdata
;
2633 struct bpo_reloc_section_info
*bpodata
2634 = mmix_elf_section_data (sec
)->bpo
.reloc
;
2635 /* The initialization is to quiet compiler warnings. The value is to
2636 spot a missing actual initialization. */
2637 size_t bpono
= (size_t) -1;
2639 Elf_Internal_Sym
*isymbuf
= NULL
;
2640 bfd_size_type size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
2642 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
= 0;
2644 /* Assume nothing changes. */
2647 /* We don't have to do anything if this section does not have relocs, or
2648 if this is not a code section. */
2649 if ((sec
->flags
& SEC_RELOC
) == 0
2650 || sec
->reloc_count
== 0
2651 || (sec
->flags
& SEC_CODE
) == 0
2652 || (sec
->flags
& SEC_LINKER_CREATED
) != 0
2653 /* If no R_MMIX_BASE_PLUS_OFFSET relocs and no PUSHJ-stub relocs,
2654 then nothing to do. */
2656 && mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0))
2659 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2661 if (bpodata
!= NULL
)
2663 bpo_gregs_section
= bpodata
->bpo_greg_section
;
2664 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2665 bpono
= bpodata
->first_base_plus_offset_reloc
;
2670 /* Get a copy of the native relocations. */
2672 = _bfd_elf_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
2673 (Elf_Internal_Rela
*) NULL
,
2674 link_info
->keep_memory
);
2675 if (internal_relocs
== NULL
)
2678 /* Walk through them looking for relaxing opportunities. */
2679 irelend
= internal_relocs
+ sec
->reloc_count
;
2680 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2683 struct elf_link_hash_entry
*h
= NULL
;
2685 /* We only process two relocs. */
2686 if (ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_BASE_PLUS_OFFSET
2687 && ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_PUSHJ_STUBBABLE
)
2690 /* We process relocs in a distinctly different way when this is a
2691 relocatable link (for one, we don't look at symbols), so we avoid
2692 mixing its code with that for the "normal" relaxation. */
2693 if (link_info
->relocatable
)
2695 /* The only transformation in a relocatable link is to generate
2696 a full stub at the location of the stub calculated for the
2697 input section, if the relocated stub location, the end of the
2698 output section plus earlier stubs, cannot be reached. Thus
2699 relocatable linking can only lead to worse code, but it still
2701 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_PUSHJ_STUBBABLE
)
2703 /* If we can reach the end of the output-section and beyond
2704 any current stubs, then we don't need a stub for this
2705 reloc. The relaxed order of output stub allocation may
2706 not exactly match the straightforward order, so we always
2707 assume presence of output stubs, which will allow
2708 relaxation only on relocations indifferent to the
2709 presence of output stub allocations for other relocations
2710 and thus the order of output stub allocation. */
2711 if (bfd_check_overflow (complain_overflow_signed
,
2714 bfd_arch_bits_per_address (abfd
),
2715 /* Output-stub location. */
2716 sec
->output_section
->rawsize
2717 + (mmix_elf_section_data (sec
2719 ->pjs
.stubs_size_sum
)
2720 /* Location of this PUSHJ reloc. */
2721 - (sec
->output_offset
+ irel
->r_offset
)
2722 /* Don't count *this* stub twice. */
2723 - (mmix_elf_section_data (sec
)
2724 ->pjs
.stub_size
[pjsno
]
2725 + MAX_PUSHJ_STUB_SIZE
))
2727 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2729 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2730 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2738 /* Get the value of the symbol referred to by the reloc. */
2739 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2741 /* A local symbol. */
2742 Elf_Internal_Sym
*isym
;
2745 /* Read this BFD's local symbols if we haven't already. */
2746 if (isymbuf
== NULL
)
2748 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2749 if (isymbuf
== NULL
)
2750 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2751 symtab_hdr
->sh_info
, 0,
2757 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
2758 if (isym
->st_shndx
== SHN_UNDEF
)
2759 sym_sec
= bfd_und_section_ptr
;
2760 else if (isym
->st_shndx
== SHN_ABS
)
2761 sym_sec
= bfd_abs_section_ptr
;
2762 else if (isym
->st_shndx
== SHN_COMMON
)
2763 sym_sec
= bfd_com_section_ptr
;
2765 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2766 symval
= (isym
->st_value
2767 + sym_sec
->output_section
->vma
2768 + sym_sec
->output_offset
);
2774 /* An external symbol. */
2775 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2776 h
= elf_sym_hashes (abfd
)[indx
];
2777 BFD_ASSERT (h
!= NULL
);
2778 if (h
->root
.type
!= bfd_link_hash_defined
2779 && h
->root
.type
!= bfd_link_hash_defweak
)
2781 /* This appears to be a reference to an undefined symbol. Just
2782 ignore it--it will be caught by the regular reloc processing.
2783 We need to keep BPO reloc accounting consistent, though
2784 else we'll abort instead of emitting an error message. */
2785 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_BASE_PLUS_OFFSET
2786 && gregdata
!= NULL
)
2788 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2794 symval
= (h
->root
.u
.def
.value
2795 + h
->root
.u
.def
.section
->output_section
->vma
2796 + h
->root
.u
.def
.section
->output_offset
);
2799 if (ELF64_R_TYPE (irel
->r_info
) == (int) R_MMIX_PUSHJ_STUBBABLE
)
2801 bfd_vma value
= symval
+ irel
->r_addend
;
2803 = (sec
->output_section
->vma
2804 + sec
->output_offset
2807 = (sec
->output_section
->vma
2808 + sec
->output_offset
2810 + mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
);
2812 if ((value
& 3) == 0
2813 && bfd_check_overflow (complain_overflow_signed
,
2816 bfd_arch_bits_per_address (abfd
),
2819 ? mmix_elf_section_data (sec
)
2820 ->pjs
.stub_size
[pjsno
]
2823 /* If the reloc fits, no stub is needed. */
2824 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2826 /* Maybe we can get away with just a JMP insn? */
2827 if ((value
& 3) == 0
2828 && bfd_check_overflow (complain_overflow_signed
,
2831 bfd_arch_bits_per_address (abfd
),
2834 ? mmix_elf_section_data (sec
)
2835 ->pjs
.stub_size
[pjsno
] - 4
2838 /* Yep, account for a stub consisting of a single JMP insn. */
2839 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 4;
2841 /* Nope, go for the full insn stub. It doesn't seem useful to
2842 emit the intermediate sizes; those will only be useful for
2843 a >64M program assuming contiguous code. */
2844 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
]
2845 = MAX_PUSHJ_STUB_SIZE
;
2847 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2848 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2853 /* We're looking at a R_MMIX_BASE_PLUS_OFFSET reloc. */
2855 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
]].value
2856 = symval
+ irel
->r_addend
;
2857 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
++]].valid
= TRUE
;
2858 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2861 /* Check if that was the last BPO-reloc. If so, sort the values and
2862 calculate how many registers we need to cover them. Set the size of
2863 the linker gregs, and if the number of registers changed, indicate
2864 that we need to relax some more because we have more work to do. */
2865 if (gregdata
!= NULL
2866 && gregdata
->n_remaining_bpo_relocs_this_relaxation_round
== 0)
2872 /* First, reset the remaining relocs for the next round. */
2873 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2874 = gregdata
->n_bpo_relocs
;
2876 qsort ((PTR
) gregdata
->reloc_request
,
2877 gregdata
->n_max_bpo_relocs
,
2878 sizeof (struct bpo_reloc_request
),
2879 bpo_reloc_request_sort_fn
);
2881 /* Recalculate indexes. When we find a change (however unlikely
2882 after the initial iteration), we know we need to relax again,
2883 since items in the GREG-array are sorted by increasing value and
2884 stored in the relaxation phase. */
2885 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2886 if (gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2889 gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2894 /* Allocate register numbers (indexing from 0). Stop at the first
2896 for (i
= 0, regindex
= 0, prev_base
= gregdata
->reloc_request
[0].value
;
2897 i
< gregdata
->n_bpo_relocs
;
2900 if (gregdata
->reloc_request
[i
].value
> prev_base
+ 255)
2903 prev_base
= gregdata
->reloc_request
[i
].value
;
2905 gregdata
->reloc_request
[i
].regindex
= regindex
;
2906 gregdata
->reloc_request
[i
].offset
2907 = gregdata
->reloc_request
[i
].value
- prev_base
;
2910 /* If it's not the same as the last time, we need to relax again,
2911 because the size of the section has changed. I'm not sure we
2912 actually need to do any adjustments since the shrinking happens
2913 at the start of this section, but better safe than sorry. */
2914 if (gregdata
->n_allocated_bpo_gregs
!= regindex
+ 1)
2916 gregdata
->n_allocated_bpo_gregs
= regindex
+ 1;
2920 bpo_gregs_section
->size
= (regindex
+ 1) * 8;
2923 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2925 if (! link_info
->keep_memory
)
2929 /* Cache the symbols for elf_link_input_bfd. */
2930 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2934 if (internal_relocs
!= NULL
2935 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2936 free (internal_relocs
);
2938 if (sec
->size
< size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2941 if (sec
->size
> size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2943 sec
->size
= size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
;
2950 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2952 if (internal_relocs
!= NULL
2953 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2954 free (internal_relocs
);
2958 #define ELF_ARCH bfd_arch_mmix
2959 #define ELF_MACHINE_CODE EM_MMIX
2961 /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
2962 However, that's too much for something somewhere in the linker part of
2963 BFD; perhaps the start-address has to be a non-zero multiple of this
2964 number, or larger than this number. The symptom is that the linker
2965 complains: "warning: allocated section `.text' not in segment". We
2966 settle for 64k; the page-size used in examples is 8k.
2967 #define ELF_MAXPAGESIZE 0x10000
2969 Unfortunately, this causes excessive padding in the supposedly small
2970 for-education programs that are the expected usage (where people would
2971 inspect output). We stick to 256 bytes just to have *some* default
2973 #define ELF_MAXPAGESIZE 0x100
2975 #define TARGET_BIG_SYM bfd_elf64_mmix_vec
2976 #define TARGET_BIG_NAME "elf64-mmix"
2978 #define elf_info_to_howto_rel NULL
2979 #define elf_info_to_howto mmix_info_to_howto_rela
2980 #define elf_backend_relocate_section mmix_elf_relocate_section
2981 #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
2982 #define elf_backend_gc_sweep_hook mmix_elf_gc_sweep_hook
2984 #define elf_backend_link_output_symbol_hook \
2985 mmix_elf_link_output_symbol_hook
2986 #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
2988 #define elf_backend_check_relocs mmix_elf_check_relocs
2989 #define elf_backend_symbol_processing mmix_elf_symbol_processing
2990 #define elf_backend_omit_section_dynsym \
2991 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
2993 #define bfd_elf64_bfd_is_local_label_name \
2994 mmix_elf_is_local_label_name
2996 #define elf_backend_may_use_rel_p 0
2997 #define elf_backend_may_use_rela_p 1
2998 #define elf_backend_default_use_rela_p 1
3000 #define elf_backend_can_gc_sections 1
3001 #define elf_backend_section_from_bfd_section \
3002 mmix_elf_section_from_bfd_section
3004 #define bfd_elf64_new_section_hook mmix_elf_new_section_hook
3005 #define bfd_elf64_bfd_final_link mmix_elf_final_link
3006 #define bfd_elf64_bfd_relax_section mmix_elf_relax_section
3008 #include "elf64-target.h"