1 /* MMIX-specific support for 64-bit ELF.
2 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson <hp@bitrange.com>
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* No specific ABI or "processor-specific supplement" defined. */
24 - "Traditional" linker relaxation (shrinking whole sections).
25 - Merge reloc stubs jumping to same location.
26 - GETA stub relaxation (call a stub for out of range new
27 R_MMIX_GETA_STUBBABLE). */
34 #include "opcode/mmix.h"
36 #define MINUS_ONE (((bfd_vma) 0) - 1)
38 #define MAX_PUSHJ_STUB_SIZE (5 * 4)
40 /* Put these everywhere in new code. */
42 _bfd_abort (__FILE__, __LINE__, \
43 "Internal: Non-debugged code (test-case missing)")
46 _bfd_abort (__FILE__, __LINE__, \
49 struct _mmix_elf_section_data
51 struct bfd_elf_section_data elf
;
54 struct bpo_reloc_section_info
*reloc
;
55 struct bpo_greg_section_info
*greg
;
58 struct pushj_stub_info
60 /* Maximum number of stubs needed for this section. */
61 bfd_size_type n_pushj_relocs
;
63 /* Size of stubs after a mmix_elf_relax_section round. */
64 bfd_size_type stubs_size_sum
;
66 /* Per-reloc stubs_size_sum information. The stubs_size_sum member is the sum
67 of these. Allocated in mmix_elf_check_common_relocs. */
68 bfd_size_type
*stub_size
;
70 /* Offset of next stub during relocation. Somewhat redundant with the
71 above: error coverage is easier and we don't have to reset the
72 stubs_size_sum for relocation. */
73 bfd_size_type stub_offset
;
77 #define mmix_elf_section_data(sec) \
78 ((struct _mmix_elf_section_data *) elf_section_data (sec))
80 /* For each section containing a base-plus-offset (BPO) reloc, we attach
81 this struct as mmix_elf_section_data (section)->bpo, which is otherwise
83 struct bpo_reloc_section_info
85 /* The base is 1; this is the first number in this section. */
86 size_t first_base_plus_offset_reloc
;
88 /* Number of BPO-relocs in this section. */
89 size_t n_bpo_relocs_this_section
;
91 /* Running index, used at relocation time. */
94 /* We don't have access to the bfd_link_info struct in
95 mmix_final_link_relocate. What we really want to get at is the
96 global single struct greg_relocation, so we stash it here. */
97 asection
*bpo_greg_section
;
100 /* Helper struct (in global context) for the one below.
101 There's one of these created for every BPO reloc. */
102 struct bpo_reloc_request
106 /* Valid after relaxation. The base is 0; the first register number
107 must be added. The offset is in range 0..255. */
111 /* The order number for this BPO reloc, corresponding to the order in
112 which BPO relocs were found. Used to create an index after reloc
113 requests are sorted. */
116 /* Set when the value is computed. Better than coding "guard values"
117 into the other members. Is FALSE only for BPO relocs in a GC:ed
122 /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
123 greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
124 which is linked into the register contents section
125 (MMIX_REG_CONTENTS_SECTION_NAME). This section is created by the
126 linker; using the same hook as for usual with BPO relocs does not
128 struct bpo_greg_section_info
130 /* After GC, this reflects the number of remaining, non-excluded
134 /* This is the number of allocated bpo_reloc_requests; the size of
135 sorted_indexes. Valid after the check.*relocs functions are called
136 for all incoming sections. It includes the number of BPO relocs in
137 sections that were GC:ed. */
138 size_t n_max_bpo_relocs
;
140 /* A counter used to find out when to fold the BPO gregs, since we
141 don't have a single "after-relaxation" hook. */
142 size_t n_remaining_bpo_relocs_this_relaxation_round
;
144 /* The number of linker-allocated GREGs resulting from BPO relocs.
145 This is an approximation after _bfd_mmix_before_linker_allocation
146 and supposedly accurate after mmix_elf_relax_section is called for
147 all incoming non-collected sections. */
148 size_t n_allocated_bpo_gregs
;
150 /* Index into reloc_request[], sorted on increasing "value", secondary
151 by increasing index for strict sorting order. */
152 size_t *bpo_reloc_indexes
;
154 /* An array of all relocations, with the "value" member filled in by
155 the relaxation function. */
156 struct bpo_reloc_request
*reloc_request
;
159 static bfd_boolean mmix_elf_link_output_symbol_hook
160 PARAMS ((struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
161 asection
*, struct elf_link_hash_entry
*));
163 static bfd_reloc_status_type mmix_elf_reloc
164 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
166 static reloc_howto_type
*bfd_elf64_bfd_reloc_type_lookup
167 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
169 static void mmix_info_to_howto_rela
170 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
172 static int mmix_elf_sort_relocs
PARAMS ((const PTR
, const PTR
));
174 static bfd_boolean mmix_elf_new_section_hook
175 PARAMS ((bfd
*, asection
*));
177 static bfd_boolean mmix_elf_check_relocs
178 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
179 const Elf_Internal_Rela
*));
181 static bfd_boolean mmix_elf_check_common_relocs
182 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
183 const Elf_Internal_Rela
*));
185 static bfd_boolean mmix_elf_relocate_section
186 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
187 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
189 static asection
* mmix_elf_gc_mark_hook
190 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
191 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
193 static bfd_boolean mmix_elf_gc_sweep_hook
194 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
195 const Elf_Internal_Rela
*));
197 static bfd_reloc_status_type mmix_final_link_relocate
198 PARAMS ((reloc_howto_type
*, asection
*, bfd_byte
*,
199 bfd_vma
, bfd_signed_vma
, bfd_vma
, const char *, asection
*));
201 static bfd_reloc_status_type mmix_elf_perform_relocation
202 PARAMS ((asection
*, reloc_howto_type
*, PTR
, bfd_vma
, bfd_vma
));
204 static bfd_boolean mmix_elf_section_from_bfd_section
205 PARAMS ((bfd
*, asection
*, int *));
207 static bfd_boolean mmix_elf_add_symbol_hook
208 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
209 const char **, flagword
*, asection
**, bfd_vma
*));
211 static bfd_boolean mmix_elf_is_local_label_name
212 PARAMS ((bfd
*, const char *));
214 static int bpo_reloc_request_sort_fn
PARAMS ((const PTR
, const PTR
));
216 static bfd_boolean mmix_elf_relax_section
217 PARAMS ((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
218 bfd_boolean
*again
));
220 extern bfd_boolean mmix_elf_final_link
PARAMS ((bfd
*, struct bfd_link_info
*));
222 extern void mmix_elf_symbol_processing
PARAMS ((bfd
*, asymbol
*));
224 /* Only intended to be called from a debugger. */
225 extern void mmix_dump_bpo_gregs
226 PARAMS ((struct bfd_link_info
*, bfd_error_handler_type
));
229 mmix_set_relaxable_size
230 PARAMS ((bfd
*, asection
*, void *));
233 mmix_elf_get_section_contents
234 PARAMS ((bfd
*, sec_ptr
, void *, file_ptr
, bfd_size_type
));
237 /* Watch out: this currently needs to have elements with the same index as
238 their R_MMIX_ number. */
239 static reloc_howto_type elf_mmix_howto_table
[] =
241 /* This reloc does nothing. */
242 HOWTO (R_MMIX_NONE
, /* type */
244 2, /* size (0 = byte, 1 = short, 2 = long) */
246 FALSE
, /* pc_relative */
248 complain_overflow_bitfield
, /* complain_on_overflow */
249 bfd_elf_generic_reloc
, /* special_function */
250 "R_MMIX_NONE", /* name */
251 FALSE
, /* partial_inplace */
254 FALSE
), /* pcrel_offset */
256 /* An 8 bit absolute relocation. */
257 HOWTO (R_MMIX_8
, /* type */
259 0, /* size (0 = byte, 1 = short, 2 = long) */
261 FALSE
, /* pc_relative */
263 complain_overflow_bitfield
, /* complain_on_overflow */
264 bfd_elf_generic_reloc
, /* special_function */
265 "R_MMIX_8", /* name */
266 FALSE
, /* partial_inplace */
269 FALSE
), /* pcrel_offset */
271 /* An 16 bit absolute relocation. */
272 HOWTO (R_MMIX_16
, /* type */
274 1, /* size (0 = byte, 1 = short, 2 = long) */
276 FALSE
, /* pc_relative */
278 complain_overflow_bitfield
, /* complain_on_overflow */
279 bfd_elf_generic_reloc
, /* special_function */
280 "R_MMIX_16", /* name */
281 FALSE
, /* partial_inplace */
283 0xffff, /* dst_mask */
284 FALSE
), /* pcrel_offset */
286 /* An 24 bit absolute relocation. */
287 HOWTO (R_MMIX_24
, /* type */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
291 FALSE
, /* pc_relative */
293 complain_overflow_bitfield
, /* complain_on_overflow */
294 bfd_elf_generic_reloc
, /* special_function */
295 "R_MMIX_24", /* name */
296 FALSE
, /* partial_inplace */
297 ~0xffffff, /* src_mask */
298 0xffffff, /* dst_mask */
299 FALSE
), /* pcrel_offset */
301 /* A 32 bit absolute relocation. */
302 HOWTO (R_MMIX_32
, /* type */
304 2, /* size (0 = byte, 1 = short, 2 = long) */
306 FALSE
, /* pc_relative */
308 complain_overflow_bitfield
, /* complain_on_overflow */
309 bfd_elf_generic_reloc
, /* special_function */
310 "R_MMIX_32", /* name */
311 FALSE
, /* partial_inplace */
313 0xffffffff, /* dst_mask */
314 FALSE
), /* pcrel_offset */
316 /* 64 bit relocation. */
317 HOWTO (R_MMIX_64
, /* type */
319 4, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE
, /* pc_relative */
323 complain_overflow_bitfield
, /* complain_on_overflow */
324 bfd_elf_generic_reloc
, /* special_function */
325 "R_MMIX_64", /* name */
326 FALSE
, /* partial_inplace */
328 MINUS_ONE
, /* dst_mask */
329 FALSE
), /* pcrel_offset */
331 /* An 8 bit PC-relative relocation. */
332 HOWTO (R_MMIX_PC_8
, /* type */
334 0, /* size (0 = byte, 1 = short, 2 = long) */
336 TRUE
, /* pc_relative */
338 complain_overflow_bitfield
, /* complain_on_overflow */
339 bfd_elf_generic_reloc
, /* special_function */
340 "R_MMIX_PC_8", /* name */
341 FALSE
, /* partial_inplace */
344 TRUE
), /* pcrel_offset */
346 /* An 16 bit PC-relative relocation. */
347 HOWTO (R_MMIX_PC_16
, /* type */
349 1, /* size (0 = byte, 1 = short, 2 = long) */
351 TRUE
, /* pc_relative */
353 complain_overflow_bitfield
, /* complain_on_overflow */
354 bfd_elf_generic_reloc
, /* special_function */
355 "R_MMIX_PC_16", /* name */
356 FALSE
, /* partial_inplace */
358 0xffff, /* dst_mask */
359 TRUE
), /* pcrel_offset */
361 /* An 24 bit PC-relative relocation. */
362 HOWTO (R_MMIX_PC_24
, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 TRUE
, /* pc_relative */
368 complain_overflow_bitfield
, /* complain_on_overflow */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_MMIX_PC_24", /* name */
371 FALSE
, /* partial_inplace */
372 ~0xffffff, /* src_mask */
373 0xffffff, /* dst_mask */
374 TRUE
), /* pcrel_offset */
376 /* A 32 bit absolute PC-relative relocation. */
377 HOWTO (R_MMIX_PC_32
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 TRUE
, /* pc_relative */
383 complain_overflow_bitfield
, /* complain_on_overflow */
384 bfd_elf_generic_reloc
, /* special_function */
385 "R_MMIX_PC_32", /* name */
386 FALSE
, /* partial_inplace */
388 0xffffffff, /* dst_mask */
389 TRUE
), /* pcrel_offset */
391 /* 64 bit PC-relative relocation. */
392 HOWTO (R_MMIX_PC_64
, /* type */
394 4, /* size (0 = byte, 1 = short, 2 = long) */
396 TRUE
, /* pc_relative */
398 complain_overflow_bitfield
, /* complain_on_overflow */
399 bfd_elf_generic_reloc
, /* special_function */
400 "R_MMIX_PC_64", /* name */
401 FALSE
, /* partial_inplace */
403 MINUS_ONE
, /* dst_mask */
404 TRUE
), /* pcrel_offset */
406 /* GNU extension to record C++ vtable hierarchy. */
407 HOWTO (R_MMIX_GNU_VTINHERIT
, /* type */
409 0, /* size (0 = byte, 1 = short, 2 = long) */
411 FALSE
, /* pc_relative */
413 complain_overflow_dont
, /* complain_on_overflow */
414 NULL
, /* special_function */
415 "R_MMIX_GNU_VTINHERIT", /* name */
416 FALSE
, /* partial_inplace */
419 TRUE
), /* pcrel_offset */
421 /* GNU extension to record C++ vtable member usage. */
422 HOWTO (R_MMIX_GNU_VTENTRY
, /* type */
424 0, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE
, /* pc_relative */
428 complain_overflow_dont
, /* complain_on_overflow */
429 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
430 "R_MMIX_GNU_VTENTRY", /* name */
431 FALSE
, /* partial_inplace */
434 FALSE
), /* pcrel_offset */
436 /* The GETA relocation is supposed to get any address that could
437 possibly be reached by the GETA instruction. It can silently expand
438 to get a 64-bit operand, but will complain if any of the two least
439 significant bits are set. The howto members reflect a simple GETA. */
440 HOWTO (R_MMIX_GETA
, /* type */
442 2, /* size (0 = byte, 1 = short, 2 = long) */
444 TRUE
, /* pc_relative */
446 complain_overflow_signed
, /* complain_on_overflow */
447 mmix_elf_reloc
, /* special_function */
448 "R_MMIX_GETA", /* name */
449 FALSE
, /* partial_inplace */
450 ~0x0100ffff, /* src_mask */
451 0x0100ffff, /* dst_mask */
452 TRUE
), /* pcrel_offset */
454 HOWTO (R_MMIX_GETA_1
, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 TRUE
, /* pc_relative */
460 complain_overflow_signed
, /* complain_on_overflow */
461 mmix_elf_reloc
, /* special_function */
462 "R_MMIX_GETA_1", /* name */
463 FALSE
, /* partial_inplace */
464 ~0x0100ffff, /* src_mask */
465 0x0100ffff, /* dst_mask */
466 TRUE
), /* pcrel_offset */
468 HOWTO (R_MMIX_GETA_2
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 TRUE
, /* pc_relative */
474 complain_overflow_signed
, /* complain_on_overflow */
475 mmix_elf_reloc
, /* special_function */
476 "R_MMIX_GETA_2", /* name */
477 FALSE
, /* partial_inplace */
478 ~0x0100ffff, /* src_mask */
479 0x0100ffff, /* dst_mask */
480 TRUE
), /* pcrel_offset */
482 HOWTO (R_MMIX_GETA_3
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 TRUE
, /* pc_relative */
488 complain_overflow_signed
, /* complain_on_overflow */
489 mmix_elf_reloc
, /* special_function */
490 "R_MMIX_GETA_3", /* name */
491 FALSE
, /* partial_inplace */
492 ~0x0100ffff, /* src_mask */
493 0x0100ffff, /* dst_mask */
494 TRUE
), /* pcrel_offset */
496 /* The conditional branches are supposed to reach any (code) address.
497 It can silently expand to a 64-bit operand, but will emit an error if
498 any of the two least significant bits are set. The howto members
499 reflect a simple branch. */
500 HOWTO (R_MMIX_CBRANCH
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 TRUE
, /* pc_relative */
506 complain_overflow_signed
, /* complain_on_overflow */
507 mmix_elf_reloc
, /* special_function */
508 "R_MMIX_CBRANCH", /* name */
509 FALSE
, /* partial_inplace */
510 ~0x0100ffff, /* src_mask */
511 0x0100ffff, /* dst_mask */
512 TRUE
), /* pcrel_offset */
514 HOWTO (R_MMIX_CBRANCH_J
, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 TRUE
, /* pc_relative */
520 complain_overflow_signed
, /* complain_on_overflow */
521 mmix_elf_reloc
, /* special_function */
522 "R_MMIX_CBRANCH_J", /* name */
523 FALSE
, /* partial_inplace */
524 ~0x0100ffff, /* src_mask */
525 0x0100ffff, /* dst_mask */
526 TRUE
), /* pcrel_offset */
528 HOWTO (R_MMIX_CBRANCH_1
, /* type */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
532 TRUE
, /* pc_relative */
534 complain_overflow_signed
, /* complain_on_overflow */
535 mmix_elf_reloc
, /* special_function */
536 "R_MMIX_CBRANCH_1", /* name */
537 FALSE
, /* partial_inplace */
538 ~0x0100ffff, /* src_mask */
539 0x0100ffff, /* dst_mask */
540 TRUE
), /* pcrel_offset */
542 HOWTO (R_MMIX_CBRANCH_2
, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 TRUE
, /* pc_relative */
548 complain_overflow_signed
, /* complain_on_overflow */
549 mmix_elf_reloc
, /* special_function */
550 "R_MMIX_CBRANCH_2", /* name */
551 FALSE
, /* partial_inplace */
552 ~0x0100ffff, /* src_mask */
553 0x0100ffff, /* dst_mask */
554 TRUE
), /* pcrel_offset */
556 HOWTO (R_MMIX_CBRANCH_3
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 TRUE
, /* pc_relative */
562 complain_overflow_signed
, /* complain_on_overflow */
563 mmix_elf_reloc
, /* special_function */
564 "R_MMIX_CBRANCH_3", /* name */
565 FALSE
, /* partial_inplace */
566 ~0x0100ffff, /* src_mask */
567 0x0100ffff, /* dst_mask */
568 TRUE
), /* pcrel_offset */
570 /* The PUSHJ instruction can reach any (code) address, as long as it's
571 the beginning of a function (no usable restriction). It can silently
572 expand to a 64-bit operand, but will emit an error if any of the two
573 least significant bits are set. It can also expand into a call to a
574 stub; see R_MMIX_PUSHJ_STUBBABLE. The howto members reflect a simple
576 HOWTO (R_MMIX_PUSHJ
, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 TRUE
, /* pc_relative */
582 complain_overflow_signed
, /* complain_on_overflow */
583 mmix_elf_reloc
, /* special_function */
584 "R_MMIX_PUSHJ", /* name */
585 FALSE
, /* partial_inplace */
586 ~0x0100ffff, /* src_mask */
587 0x0100ffff, /* dst_mask */
588 TRUE
), /* pcrel_offset */
590 HOWTO (R_MMIX_PUSHJ_1
, /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 TRUE
, /* pc_relative */
596 complain_overflow_signed
, /* complain_on_overflow */
597 mmix_elf_reloc
, /* special_function */
598 "R_MMIX_PUSHJ_1", /* name */
599 FALSE
, /* partial_inplace */
600 ~0x0100ffff, /* src_mask */
601 0x0100ffff, /* dst_mask */
602 TRUE
), /* pcrel_offset */
604 HOWTO (R_MMIX_PUSHJ_2
, /* type */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
608 TRUE
, /* pc_relative */
610 complain_overflow_signed
, /* complain_on_overflow */
611 mmix_elf_reloc
, /* special_function */
612 "R_MMIX_PUSHJ_2", /* name */
613 FALSE
, /* partial_inplace */
614 ~0x0100ffff, /* src_mask */
615 0x0100ffff, /* dst_mask */
616 TRUE
), /* pcrel_offset */
618 HOWTO (R_MMIX_PUSHJ_3
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 TRUE
, /* pc_relative */
624 complain_overflow_signed
, /* complain_on_overflow */
625 mmix_elf_reloc
, /* special_function */
626 "R_MMIX_PUSHJ_3", /* name */
627 FALSE
, /* partial_inplace */
628 ~0x0100ffff, /* src_mask */
629 0x0100ffff, /* dst_mask */
630 TRUE
), /* pcrel_offset */
632 /* A JMP is supposed to reach any (code) address. By itself, it can
633 reach +-64M; the expansion can reach all 64 bits. Note that the 64M
634 limit is soon reached if you link the program in wildly different
635 memory segments. The howto members reflect a trivial JMP. */
636 HOWTO (R_MMIX_JMP
, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 TRUE
, /* pc_relative */
642 complain_overflow_signed
, /* complain_on_overflow */
643 mmix_elf_reloc
, /* special_function */
644 "R_MMIX_JMP", /* name */
645 FALSE
, /* partial_inplace */
646 ~0x1ffffff, /* src_mask */
647 0x1ffffff, /* dst_mask */
648 TRUE
), /* pcrel_offset */
650 HOWTO (R_MMIX_JMP_1
, /* type */
652 2, /* size (0 = byte, 1 = short, 2 = long) */
654 TRUE
, /* pc_relative */
656 complain_overflow_signed
, /* complain_on_overflow */
657 mmix_elf_reloc
, /* special_function */
658 "R_MMIX_JMP_1", /* name */
659 FALSE
, /* partial_inplace */
660 ~0x1ffffff, /* src_mask */
661 0x1ffffff, /* dst_mask */
662 TRUE
), /* pcrel_offset */
664 HOWTO (R_MMIX_JMP_2
, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 TRUE
, /* pc_relative */
670 complain_overflow_signed
, /* complain_on_overflow */
671 mmix_elf_reloc
, /* special_function */
672 "R_MMIX_JMP_2", /* name */
673 FALSE
, /* partial_inplace */
674 ~0x1ffffff, /* src_mask */
675 0x1ffffff, /* dst_mask */
676 TRUE
), /* pcrel_offset */
678 HOWTO (R_MMIX_JMP_3
, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 TRUE
, /* pc_relative */
684 complain_overflow_signed
, /* complain_on_overflow */
685 mmix_elf_reloc
, /* special_function */
686 "R_MMIX_JMP_3", /* name */
687 FALSE
, /* partial_inplace */
688 ~0x1ffffff, /* src_mask */
689 0x1ffffff, /* dst_mask */
690 TRUE
), /* pcrel_offset */
692 /* When we don't emit link-time-relaxable code from the assembler, or
693 when relaxation has done all it can do, these relocs are used. For
694 GETA/PUSHJ/branches. */
695 HOWTO (R_MMIX_ADDR19
, /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 TRUE
, /* pc_relative */
701 complain_overflow_signed
, /* complain_on_overflow */
702 mmix_elf_reloc
, /* special_function */
703 "R_MMIX_ADDR19", /* name */
704 FALSE
, /* partial_inplace */
705 ~0x0100ffff, /* src_mask */
706 0x0100ffff, /* dst_mask */
707 TRUE
), /* pcrel_offset */
710 HOWTO (R_MMIX_ADDR27
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 TRUE
, /* pc_relative */
716 complain_overflow_signed
, /* complain_on_overflow */
717 mmix_elf_reloc
, /* special_function */
718 "R_MMIX_ADDR27", /* name */
719 FALSE
, /* partial_inplace */
720 ~0x1ffffff, /* src_mask */
721 0x1ffffff, /* dst_mask */
722 TRUE
), /* pcrel_offset */
724 /* A general register or the value 0..255. If a value, then the
725 instruction (offset -3) needs adjusting. */
726 HOWTO (R_MMIX_REG_OR_BYTE
, /* type */
728 1, /* size (0 = byte, 1 = short, 2 = long) */
730 FALSE
, /* pc_relative */
732 complain_overflow_bitfield
, /* complain_on_overflow */
733 mmix_elf_reloc
, /* special_function */
734 "R_MMIX_REG_OR_BYTE", /* name */
735 FALSE
, /* partial_inplace */
738 FALSE
), /* pcrel_offset */
740 /* A general register. */
741 HOWTO (R_MMIX_REG
, /* type */
743 1, /* size (0 = byte, 1 = short, 2 = long) */
745 FALSE
, /* pc_relative */
747 complain_overflow_bitfield
, /* complain_on_overflow */
748 mmix_elf_reloc
, /* special_function */
749 "R_MMIX_REG", /* name */
750 FALSE
, /* partial_inplace */
753 FALSE
), /* pcrel_offset */
755 /* A register plus an index, corresponding to the relocation expression.
756 The sizes must correspond to the valid range of the expression, while
757 the bitmasks correspond to what we store in the image. */
758 HOWTO (R_MMIX_BASE_PLUS_OFFSET
, /* type */
760 4, /* size (0 = byte, 1 = short, 2 = long) */
762 FALSE
, /* pc_relative */
764 complain_overflow_bitfield
, /* complain_on_overflow */
765 mmix_elf_reloc
, /* special_function */
766 "R_MMIX_BASE_PLUS_OFFSET", /* name */
767 FALSE
, /* partial_inplace */
769 0xffff, /* dst_mask */
770 FALSE
), /* pcrel_offset */
772 /* A "magic" relocation for a LOCAL expression, asserting that the
773 expression is less than the number of global registers. No actual
774 modification of the contents is done. Implementing this as a
775 relocation was less intrusive than e.g. putting such expressions in a
776 section to discard *after* relocation. */
777 HOWTO (R_MMIX_LOCAL
, /* type */
779 0, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE
, /* pc_relative */
783 complain_overflow_dont
, /* complain_on_overflow */
784 mmix_elf_reloc
, /* special_function */
785 "R_MMIX_LOCAL", /* name */
786 FALSE
, /* partial_inplace */
789 FALSE
), /* pcrel_offset */
791 HOWTO (R_MMIX_PUSHJ_STUBBABLE
, /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 TRUE
, /* pc_relative */
797 complain_overflow_signed
, /* complain_on_overflow */
798 mmix_elf_reloc
, /* special_function */
799 "R_MMIX_PUSHJ_STUBBABLE", /* name */
800 FALSE
, /* partial_inplace */
801 ~0x0100ffff, /* src_mask */
802 0x0100ffff, /* dst_mask */
803 TRUE
) /* pcrel_offset */
807 /* Map BFD reloc types to MMIX ELF reloc types. */
809 struct mmix_reloc_map
811 bfd_reloc_code_real_type bfd_reloc_val
;
812 enum elf_mmix_reloc_type elf_reloc_val
;
816 static const struct mmix_reloc_map mmix_reloc_map
[] =
818 {BFD_RELOC_NONE
, R_MMIX_NONE
},
819 {BFD_RELOC_8
, R_MMIX_8
},
820 {BFD_RELOC_16
, R_MMIX_16
},
821 {BFD_RELOC_24
, R_MMIX_24
},
822 {BFD_RELOC_32
, R_MMIX_32
},
823 {BFD_RELOC_64
, R_MMIX_64
},
824 {BFD_RELOC_8_PCREL
, R_MMIX_PC_8
},
825 {BFD_RELOC_16_PCREL
, R_MMIX_PC_16
},
826 {BFD_RELOC_24_PCREL
, R_MMIX_PC_24
},
827 {BFD_RELOC_32_PCREL
, R_MMIX_PC_32
},
828 {BFD_RELOC_64_PCREL
, R_MMIX_PC_64
},
829 {BFD_RELOC_VTABLE_INHERIT
, R_MMIX_GNU_VTINHERIT
},
830 {BFD_RELOC_VTABLE_ENTRY
, R_MMIX_GNU_VTENTRY
},
831 {BFD_RELOC_MMIX_GETA
, R_MMIX_GETA
},
832 {BFD_RELOC_MMIX_CBRANCH
, R_MMIX_CBRANCH
},
833 {BFD_RELOC_MMIX_PUSHJ
, R_MMIX_PUSHJ
},
834 {BFD_RELOC_MMIX_JMP
, R_MMIX_JMP
},
835 {BFD_RELOC_MMIX_ADDR19
, R_MMIX_ADDR19
},
836 {BFD_RELOC_MMIX_ADDR27
, R_MMIX_ADDR27
},
837 {BFD_RELOC_MMIX_REG_OR_BYTE
, R_MMIX_REG_OR_BYTE
},
838 {BFD_RELOC_MMIX_REG
, R_MMIX_REG
},
839 {BFD_RELOC_MMIX_BASE_PLUS_OFFSET
, R_MMIX_BASE_PLUS_OFFSET
},
840 {BFD_RELOC_MMIX_LOCAL
, R_MMIX_LOCAL
},
841 {BFD_RELOC_MMIX_PUSHJ_STUBBABLE
, R_MMIX_PUSHJ_STUBBABLE
}
844 static reloc_howto_type
*
845 bfd_elf64_bfd_reloc_type_lookup (abfd
, code
)
846 bfd
*abfd ATTRIBUTE_UNUSED
;
847 bfd_reloc_code_real_type code
;
852 i
< sizeof (mmix_reloc_map
) / sizeof (mmix_reloc_map
[0]);
855 if (mmix_reloc_map
[i
].bfd_reloc_val
== code
)
856 return &elf_mmix_howto_table
[mmix_reloc_map
[i
].elf_reloc_val
];
863 mmix_elf_new_section_hook (abfd
, sec
)
867 struct _mmix_elf_section_data
*sdata
;
868 bfd_size_type amt
= sizeof (*sdata
);
870 sdata
= (struct _mmix_elf_section_data
*) bfd_zalloc (abfd
, amt
);
873 sec
->used_by_bfd
= (PTR
) sdata
;
875 return _bfd_elf_new_section_hook (abfd
, sec
);
879 /* This function performs the actual bitfiddling and sanity check for a
880 final relocation. Each relocation gets its *worst*-case expansion
881 in size when it arrives here; any reduction in size should have been
882 caught in linker relaxation earlier. When we get here, the relocation
883 looks like the smallest instruction with SWYM:s (nop:s) appended to the
884 max size. We fill in those nop:s.
886 R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
890 INCML $N,(foo >> 16) & 0xffff
891 INCMH $N,(foo >> 32) & 0xffff
892 INCH $N,(foo >> 48) & 0xffff
894 R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
895 condbranches needing relaxation might be rare enough to not be
906 R_MMIX_PUSHJ: (FIXME: Relaxation...)
915 R_MMIX_JMP: (FIXME: Relaxation...)
924 R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
926 static bfd_reloc_status_type
927 mmix_elf_perform_relocation (isec
, howto
, datap
, addr
, value
)
929 reloc_howto_type
*howto
;
934 bfd
*abfd
= isec
->owner
;
935 bfd_reloc_status_type flag
= bfd_reloc_ok
;
936 bfd_reloc_status_type r
;
940 /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
941 We handle the differences here and the common sequence later. */
946 reg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
948 /* We change to an absolute value. */
954 int in1
= bfd_get_16 (abfd
, (bfd_byte
*) datap
) << 16;
956 /* Invert the condition and prediction bit, and set the offset
957 to five instructions ahead.
959 We *can* do better if we want to. If the branch is found to be
960 within limits, we could leave the branch as is; there'll just
961 be a bunch of NOP:s after it. But we shouldn't see this
962 sequence often enough that it's worth doing it. */
965 (((in1
^ ((PRED_INV_BIT
| COND_INV_BIT
) << 24)) & ~0xffff)
969 /* Put a "GO $255,$255,0" after the common sequence. */
971 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24) | 0xffff00,
972 (bfd_byte
*) datap
+ 20);
974 /* Common sequence starts at offset 4. */
977 /* We change to an absolute value. */
982 case R_MMIX_PUSHJ_STUBBABLE
:
983 /* If the address fits, we're fine. */
985 /* Note rightshift 0; see R_MMIX_JMP case below. */
986 && (r
= bfd_check_overflow (complain_overflow_signed
,
989 bfd_arch_bits_per_address (abfd
),
990 value
)) == bfd_reloc_ok
)
991 goto pcrel_mmix_reloc_fits
;
996 - (mmix_elf_section_data (isec
)->pjs
.n_pushj_relocs
997 * MAX_PUSHJ_STUB_SIZE
));
999 /* We have the bytes at the PUSHJ insn and need to get the
1000 position for the stub. There's supposed to be room allocated
1002 bfd_byte
*stubcontents
1004 - (addr
- (isec
->output_section
->vma
+ isec
->output_offset
))
1006 + mmix_elf_section_data (isec
)->pjs
.stub_offset
);
1009 /* The address doesn't fit, so redirect the PUSHJ to the
1010 location of the stub. */
1011 r
= mmix_elf_perform_relocation (isec
,
1012 &elf_mmix_howto_table
1016 isec
->output_section
->vma
1017 + isec
->output_offset
1019 + (mmix_elf_section_data (isec
)
1022 if (r
!= bfd_reloc_ok
)
1026 = (isec
->output_section
->vma
1027 + isec
->output_offset
1029 + mmix_elf_section_data (isec
)->pjs
.stub_offset
);
1031 /* We generate a simple JMP if that suffices, else the whole 5
1033 if (bfd_check_overflow (complain_overflow_signed
,
1034 elf_mmix_howto_table
[R_MMIX_ADDR27
].bitsize
,
1036 bfd_arch_bits_per_address (abfd
),
1037 addr
+ value
- stubaddr
) == bfd_reloc_ok
)
1039 bfd_put_32 (abfd
, JMP_INSN_BYTE
<< 24, stubcontents
);
1040 r
= mmix_elf_perform_relocation (isec
,
1041 &elf_mmix_howto_table
1045 value
+ addr
- stubaddr
);
1046 mmix_elf_section_data (isec
)->pjs
.stub_offset
+= 4;
1048 if (size
+ mmix_elf_section_data (isec
)->pjs
.stub_offset
1056 /* Put a "GO $255,0" after the common sequence. */
1058 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1059 | 0xff00, (bfd_byte
*) stubcontents
+ 16);
1061 /* Prepare for the general code to set the first part of the
1064 datap
= stubcontents
;
1065 mmix_elf_section_data (isec
)->pjs
.stub_offset
1066 += MAX_PUSHJ_STUB_SIZE
;
1073 int inreg
= bfd_get_8 (abfd
, (bfd_byte
*) datap
+ 1);
1075 /* Put a "PUSHGO $N,$255,0" after the common sequence. */
1077 ((PUSHGO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1080 (bfd_byte
*) datap
+ 16);
1082 /* We change to an absolute value. */
1088 /* This one is a little special. If we get here on a non-relaxing
1089 link, and the destination is actually in range, we don't need to
1091 If so, we fall through to the bit-fiddling relocs.
1093 FIXME: bfd_check_overflow seems broken; the relocation is
1094 rightshifted before testing, so supply a zero rightshift. */
1096 if (! ((value
& 3) == 0
1097 && (r
= bfd_check_overflow (complain_overflow_signed
,
1100 bfd_arch_bits_per_address (abfd
),
1101 value
)) == bfd_reloc_ok
))
1103 /* If the relocation doesn't fit in a JMP, we let the NOP:s be
1104 modified below, and put a "GO $255,$255,0" after the
1105 address-loading sequence. */
1107 ((GO_INSN_BYTE
| IMM_OFFSET_BIT
) << 24)
1109 (bfd_byte
*) datap
+ 16);
1111 /* We change to an absolute value. */
1118 pcrel_mmix_reloc_fits
:
1119 /* These must be in range, or else we emit an error. */
1120 if ((value
& 3) == 0
1121 /* Note rightshift 0; see above. */
1122 && (r
= bfd_check_overflow (complain_overflow_signed
,
1125 bfd_arch_bits_per_address (abfd
),
1126 value
)) == bfd_reloc_ok
)
1129 = bfd_get_32 (abfd
, (bfd_byte
*) datap
);
1132 if ((bfd_signed_vma
) value
< 0)
1135 value
+= (1 << (howto
->bitsize
- 1));
1143 (in1
& howto
->src_mask
)
1145 | (value
& howto
->dst_mask
),
1146 (bfd_byte
*) datap
);
1148 return bfd_reloc_ok
;
1151 return bfd_reloc_overflow
;
1153 case R_MMIX_BASE_PLUS_OFFSET
:
1155 struct bpo_reloc_section_info
*bpodata
1156 = mmix_elf_section_data (isec
)->bpo
.reloc
;
1157 asection
*bpo_greg_section
1158 = bpodata
->bpo_greg_section
;
1159 struct bpo_greg_section_info
*gregdata
1160 = mmix_elf_section_data (bpo_greg_section
)->bpo
.greg
;
1162 = gregdata
->bpo_reloc_indexes
[bpodata
->bpo_index
++];
1164 /* A consistency check: The value we now have in "relocation" must
1165 be the same as the value we stored for that relocation. It
1166 doesn't cost much, so can be left in at all times. */
1167 if (value
!= gregdata
->reloc_request
[bpo_index
].value
)
1169 (*_bfd_error_handler
)
1170 (_("%s: Internal inconsistency error for value for\n\
1171 linker-allocated global register: linked: 0x%lx%08lx != relaxed: 0x%lx%08lx\n"),
1172 bfd_get_filename (isec
->owner
),
1173 (unsigned long) (value
>> 32), (unsigned long) value
,
1174 (unsigned long) (gregdata
->reloc_request
[bpo_index
].value
1176 (unsigned long) gregdata
->reloc_request
[bpo_index
].value
);
1177 bfd_set_error (bfd_error_bad_value
);
1178 return bfd_reloc_overflow
;
1181 /* Then store the register number and offset for that register
1182 into datap and datap + 1 respectively. */
1184 gregdata
->reloc_request
[bpo_index
].regindex
1185 + bpo_greg_section
->output_section
->vma
/ 8,
1188 gregdata
->reloc_request
[bpo_index
].offset
,
1189 ((unsigned char *) datap
) + 1);
1190 return bfd_reloc_ok
;
1193 case R_MMIX_REG_OR_BYTE
:
1196 return bfd_reloc_overflow
;
1197 bfd_put_8 (abfd
, value
, datap
);
1198 return bfd_reloc_ok
;
1201 BAD_CASE (howto
->type
);
1204 /* This code adds the common SETL/INCML/INCMH/INCH worst-case
1207 /* Lowest two bits must be 0. We return bfd_reloc_overflow for
1208 everything that looks strange. */
1210 flag
= bfd_reloc_overflow
;
1213 (SETL_INSN_BYTE
<< 24) | (value
& 0xffff) | (reg
<< 16),
1214 (bfd_byte
*) datap
+ offs
);
1216 (INCML_INSN_BYTE
<< 24) | ((value
>> 16) & 0xffff) | (reg
<< 16),
1217 (bfd_byte
*) datap
+ offs
+ 4);
1219 (INCMH_INSN_BYTE
<< 24) | ((value
>> 32) & 0xffff) | (reg
<< 16),
1220 (bfd_byte
*) datap
+ offs
+ 8);
1222 (INCH_INSN_BYTE
<< 24) | ((value
>> 48) & 0xffff) | (reg
<< 16),
1223 (bfd_byte
*) datap
+ offs
+ 12);
1228 /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
1231 mmix_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1232 bfd
*abfd ATTRIBUTE_UNUSED
;
1234 Elf_Internal_Rela
*dst
;
1236 unsigned int r_type
;
1238 r_type
= ELF64_R_TYPE (dst
->r_info
);
1239 BFD_ASSERT (r_type
< (unsigned int) R_MMIX_max
);
1240 cache_ptr
->howto
= &elf_mmix_howto_table
[r_type
];
1243 /* Any MMIX-specific relocation gets here at assembly time or when linking
1244 to other formats (such as mmo); this is the relocation function from
1245 the reloc_table. We don't get here for final pure ELF linking. */
1247 static bfd_reloc_status_type
1248 mmix_elf_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1249 output_bfd
, error_message
)
1251 arelent
*reloc_entry
;
1254 asection
*input_section
;
1256 char **error_message ATTRIBUTE_UNUSED
;
1259 bfd_reloc_status_type r
;
1260 asection
*reloc_target_output_section
;
1261 bfd_reloc_status_type flag
= bfd_reloc_ok
;
1262 bfd_vma output_base
= 0;
1265 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1266 input_section
, output_bfd
, error_message
);
1268 /* If that was all that was needed (i.e. this isn't a final link, only
1269 some segment adjustments), we're done. */
1270 if (r
!= bfd_reloc_continue
)
1273 if (bfd_is_und_section (symbol
->section
)
1274 && (symbol
->flags
& BSF_WEAK
) == 0
1275 && output_bfd
== (bfd
*) NULL
)
1276 return bfd_reloc_undefined
;
1278 /* Is the address of the relocation really within the section? */
1279 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1280 return bfd_reloc_outofrange
;
1282 /* Work out which section the relocation is targeted at and the
1283 initial relocation command value. */
1285 /* Get symbol value. (Common symbols are special.) */
1286 if (bfd_is_com_section (symbol
->section
))
1289 relocation
= symbol
->value
;
1291 reloc_target_output_section
= bfd_get_output_section (symbol
);
1293 /* Here the variable relocation holds the final address of the symbol we
1294 are relocating against, plus any addend. */
1298 output_base
= reloc_target_output_section
->vma
;
1300 relocation
+= output_base
+ symbol
->section
->output_offset
;
1302 /* Get position of relocation. */
1303 addr
= (reloc_entry
->address
+ input_section
->output_section
->vma
1304 + input_section
->output_offset
);
1305 if (output_bfd
!= (bfd
*) NULL
)
1307 /* Add in supplied addend. */
1308 relocation
+= reloc_entry
->addend
;
1310 /* This is a partial relocation, and we want to apply the
1311 relocation to the reloc entry rather than the raw data.
1312 Modify the reloc inplace to reflect what we now know. */
1313 reloc_entry
->addend
= relocation
;
1314 reloc_entry
->address
+= input_section
->output_offset
;
1318 return mmix_final_link_relocate (reloc_entry
->howto
, input_section
,
1319 data
, reloc_entry
->address
,
1320 reloc_entry
->addend
, relocation
,
1321 bfd_asymbol_name (symbol
),
1322 reloc_target_output_section
);
1325 /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
1326 for guidance if you're thinking of copying this. */
1329 mmix_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1330 contents
, relocs
, local_syms
, local_sections
)
1331 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1332 struct bfd_link_info
*info
;
1334 asection
*input_section
;
1336 Elf_Internal_Rela
*relocs
;
1337 Elf_Internal_Sym
*local_syms
;
1338 asection
**local_sections
;
1340 Elf_Internal_Shdr
*symtab_hdr
;
1341 struct elf_link_hash_entry
**sym_hashes
;
1342 Elf_Internal_Rela
*rel
;
1343 Elf_Internal_Rela
*relend
;
1345 = (input_section
->size
1346 - (mmix_elf_section_data (input_section
)->pjs
.n_pushj_relocs
1347 * MAX_PUSHJ_STUB_SIZE
));
1350 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1351 sym_hashes
= elf_sym_hashes (input_bfd
);
1352 relend
= relocs
+ input_section
->reloc_count
;
1354 for (rel
= relocs
; rel
< relend
; rel
++)
1356 reloc_howto_type
*howto
;
1357 unsigned long r_symndx
;
1358 Elf_Internal_Sym
*sym
;
1360 struct elf_link_hash_entry
*h
;
1362 bfd_reloc_status_type r
;
1363 const char *name
= NULL
;
1365 bfd_boolean undefined_signalled
= FALSE
;
1367 r_type
= ELF64_R_TYPE (rel
->r_info
);
1369 if (r_type
== R_MMIX_GNU_VTINHERIT
1370 || r_type
== R_MMIX_GNU_VTENTRY
)
1373 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1375 if (info
->relocatable
)
1377 /* This is a relocatable link. For most relocs we don't have to
1378 change anything, unless the reloc is against a section
1379 symbol, in which case we have to adjust according to where
1380 the section symbol winds up in the output section. */
1381 if (r_symndx
< symtab_hdr
->sh_info
)
1383 sym
= local_syms
+ r_symndx
;
1385 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1387 sec
= local_sections
[r_symndx
];
1388 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1392 /* For PUSHJ stub relocs however, we may need to change the
1393 reloc and the section contents, if the reloc doesn't reach
1394 beyond the end of the output section and previous stubs.
1395 Then we change the section contents to be a PUSHJ to the end
1396 of the input section plus stubs (we can do that without using
1397 a reloc), and then we change the reloc to be a R_MMIX_PUSHJ
1398 at the stub location. */
1399 if (r_type
== R_MMIX_PUSHJ_STUBBABLE
)
1401 /* We've already checked whether we need a stub; use that
1403 if (mmix_elf_section_data (input_section
)->pjs
.stub_size
[pjsno
]
1406 Elf_Internal_Rela relcpy
;
1408 if (mmix_elf_section_data (input_section
)
1409 ->pjs
.stub_size
[pjsno
] != MAX_PUSHJ_STUB_SIZE
)
1412 /* There's already a PUSHJ insn there, so just fill in
1413 the offset bits to the stub. */
1414 if (mmix_final_link_relocate (elf_mmix_howto_table
1421 ->output_section
->vma
1422 + input_section
->output_offset
1424 + mmix_elf_section_data (input_section
)
1426 NULL
, NULL
) != bfd_reloc_ok
)
1429 /* Put a JMP insn at the stub; it goes with the
1430 R_MMIX_JMP reloc. */
1431 bfd_put_32 (output_bfd
, JMP_INSN_BYTE
<< 24,
1434 + mmix_elf_section_data (input_section
)
1437 /* Change the reloc to be at the stub, and to a full
1438 R_MMIX_JMP reloc. */
1439 rel
->r_info
= ELF64_R_INFO (r_symndx
, R_MMIX_JMP
);
1442 + mmix_elf_section_data (input_section
)
1445 mmix_elf_section_data (input_section
)->pjs
.stub_offset
1446 += MAX_PUSHJ_STUB_SIZE
;
1448 /* Shift this reloc to the end of the relocs to maintain
1449 the r_offset sorted reloc order. */
1451 memmove (rel
, rel
+ 1, (char *) relend
- (char *) rel
);
1452 relend
[-1] = relcpy
;
1454 /* Back up one reloc, or else we'd skip the next reloc
1464 /* This is a final link. */
1465 howto
= elf_mmix_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
1470 if (r_symndx
< symtab_hdr
->sh_info
)
1472 sym
= local_syms
+ r_symndx
;
1473 sec
= local_sections
[r_symndx
];
1474 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1476 name
= bfd_elf_string_from_elf_section (input_bfd
,
1477 symtab_hdr
->sh_link
,
1480 name
= bfd_section_name (input_bfd
, sec
);
1484 bfd_boolean unresolved_reloc
;
1486 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1487 r_symndx
, symtab_hdr
, sym_hashes
,
1489 unresolved_reloc
, undefined_signalled
);
1490 name
= h
->root
.root
.string
;
1493 r
= mmix_final_link_relocate (howto
, input_section
,
1494 contents
, rel
->r_offset
,
1495 rel
->r_addend
, relocation
, name
, sec
);
1497 if (r
!= bfd_reloc_ok
)
1499 bfd_boolean check_ok
= TRUE
;
1500 const char * msg
= (const char *) NULL
;
1504 case bfd_reloc_overflow
:
1505 check_ok
= info
->callbacks
->reloc_overflow
1506 (info
, name
, howto
->name
, (bfd_vma
) 0,
1507 input_bfd
, input_section
, rel
->r_offset
);
1510 case bfd_reloc_undefined
:
1511 /* We may have sent this message above. */
1512 if (! undefined_signalled
)
1513 check_ok
= info
->callbacks
->undefined_symbol
1514 (info
, name
, input_bfd
, input_section
, rel
->r_offset
,
1516 undefined_signalled
= TRUE
;
1519 case bfd_reloc_outofrange
:
1520 msg
= _("internal error: out of range error");
1523 case bfd_reloc_notsupported
:
1524 msg
= _("internal error: unsupported relocation error");
1527 case bfd_reloc_dangerous
:
1528 msg
= _("internal error: dangerous relocation");
1532 msg
= _("internal error: unknown error");
1537 check_ok
= info
->callbacks
->warning
1538 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
1548 /* Perform a single relocation. By default we use the standard BFD
1549 routines. A few relocs we have to do ourselves. */
1551 static bfd_reloc_status_type
1552 mmix_final_link_relocate (howto
, input_section
, contents
,
1553 r_offset
, r_addend
, relocation
, symname
, symsec
)
1554 reloc_howto_type
*howto
;
1555 asection
*input_section
;
1558 bfd_signed_vma r_addend
;
1560 const char *symname
;
1563 bfd_reloc_status_type r
= bfd_reloc_ok
;
1565 = (input_section
->output_section
->vma
1566 + input_section
->output_offset
1569 = (bfd_signed_vma
) relocation
+ r_addend
;
1571 switch (howto
->type
)
1573 /* All these are PC-relative. */
1574 case R_MMIX_PUSHJ_STUBBABLE
:
1576 case R_MMIX_CBRANCH
:
1581 contents
+= r_offset
;
1583 srel
-= (input_section
->output_section
->vma
1584 + input_section
->output_offset
1587 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1591 case R_MMIX_BASE_PLUS_OFFSET
:
1593 return bfd_reloc_undefined
;
1595 /* Check that we're not relocating against a register symbol. */
1596 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1597 MMIX_REG_CONTENTS_SECTION_NAME
) == 0
1598 || strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1599 MMIX_REG_SECTION_NAME
) == 0)
1601 /* Note: This is separated out into two messages in order
1602 to ease the translation into other languages. */
1603 if (symname
== NULL
|| *symname
== 0)
1604 (*_bfd_error_handler
)
1605 (_("%s: base-plus-offset relocation against register symbol: (unknown) in %s"),
1606 bfd_get_filename (input_section
->owner
),
1607 bfd_get_section_name (symsec
->owner
, symsec
));
1609 (*_bfd_error_handler
)
1610 (_("%s: base-plus-offset relocation against register symbol: %s in %s"),
1611 bfd_get_filename (input_section
->owner
), symname
,
1612 bfd_get_section_name (symsec
->owner
, symsec
));
1613 return bfd_reloc_overflow
;
1617 case R_MMIX_REG_OR_BYTE
:
1619 /* For now, we handle these alike. They must refer to an register
1620 symbol, which is either relative to the register section and in
1621 the range 0..255, or is in the register contents section with vma
1624 /* FIXME: A better way to check for reg contents section?
1625 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
1627 return bfd_reloc_undefined
;
1629 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1630 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1632 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1634 /* The bfd_reloc_outofrange return value, though intuitively
1635 a better value, will not get us an error. */
1636 return bfd_reloc_overflow
;
1640 else if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1641 MMIX_REG_SECTION_NAME
) == 0)
1643 if (srel
< 0 || srel
> 255)
1644 /* The bfd_reloc_outofrange return value, though intuitively a
1645 better value, will not get us an error. */
1646 return bfd_reloc_overflow
;
1650 /* Note: This is separated out into two messages in order
1651 to ease the translation into other languages. */
1652 if (symname
== NULL
|| *symname
== 0)
1653 (*_bfd_error_handler
)
1654 (_("%s: register relocation against non-register symbol: (unknown) in %s"),
1655 bfd_get_filename (input_section
->owner
),
1656 bfd_get_section_name (symsec
->owner
, symsec
));
1658 (*_bfd_error_handler
)
1659 (_("%s: register relocation against non-register symbol: %s in %s"),
1660 bfd_get_filename (input_section
->owner
), symname
,
1661 bfd_get_section_name (symsec
->owner
, symsec
));
1663 /* The bfd_reloc_outofrange return value, though intuitively a
1664 better value, will not get us an error. */
1665 return bfd_reloc_overflow
;
1668 contents
+= r_offset
;
1669 r
= mmix_elf_perform_relocation (input_section
, howto
, contents
,
1674 /* This isn't a real relocation, it's just an assertion that the
1675 final relocation value corresponds to a local register. We
1676 ignore the actual relocation; nothing is changed. */
1679 = bfd_get_section_by_name (input_section
->output_section
->owner
,
1680 MMIX_REG_CONTENTS_SECTION_NAME
);
1681 bfd_vma first_global
;
1683 /* Check that this is an absolute value, or a reference to the
1684 register contents section or the register (symbol) section.
1685 Absolute numbers can get here as undefined section. Undefined
1686 symbols are signalled elsewhere, so there's no conflict in us
1687 accidentally handling it. */
1688 if (!bfd_is_abs_section (symsec
)
1689 && !bfd_is_und_section (symsec
)
1690 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1691 MMIX_REG_CONTENTS_SECTION_NAME
) != 0
1692 && strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1693 MMIX_REG_SECTION_NAME
) != 0)
1695 (*_bfd_error_handler
)
1696 (_("%s: directive LOCAL valid only with a register or absolute value"),
1697 bfd_get_filename (input_section
->owner
));
1699 return bfd_reloc_overflow
;
1702 /* If we don't have a register contents section, then $255 is the
1703 first global register. */
1708 first_global
= bfd_get_section_vma (abfd
, regsec
) / 8;
1709 if (strcmp (bfd_get_section_name (symsec
->owner
, symsec
),
1710 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
1712 if ((srel
& 7) != 0 || srel
< 32*8 || srel
> 255*8)
1713 /* The bfd_reloc_outofrange return value, though
1714 intuitively a better value, will not get us an error. */
1715 return bfd_reloc_overflow
;
1720 if ((bfd_vma
) srel
>= first_global
)
1722 /* FIXME: Better error message. */
1723 (*_bfd_error_handler
)
1724 (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."),
1725 bfd_get_filename (input_section
->owner
), (long) srel
, (long) first_global
);
1727 return bfd_reloc_overflow
;
1734 r
= _bfd_final_link_relocate (howto
, input_section
->owner
, input_section
,
1736 relocation
, r_addend
);
1742 /* Return the section that should be marked against GC for a given
1746 mmix_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
1748 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1749 Elf_Internal_Rela
*rel
;
1750 struct elf_link_hash_entry
*h
;
1751 Elf_Internal_Sym
*sym
;
1755 switch (ELF64_R_TYPE (rel
->r_info
))
1757 case R_MMIX_GNU_VTINHERIT
:
1758 case R_MMIX_GNU_VTENTRY
:
1762 switch (h
->root
.type
)
1764 case bfd_link_hash_defined
:
1765 case bfd_link_hash_defweak
:
1766 return h
->root
.u
.def
.section
;
1768 case bfd_link_hash_common
:
1769 return h
->root
.u
.c
.p
->section
;
1777 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1782 /* Update relocation info for a GC-excluded section. We could supposedly
1783 perform the allocation after GC, but there's no suitable hook between
1784 GC (or section merge) and the point when all input sections must be
1785 present. Better to waste some memory and (perhaps) a little time. */
1788 mmix_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1789 bfd
*abfd ATTRIBUTE_UNUSED
;
1790 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1791 asection
*sec ATTRIBUTE_UNUSED
;
1792 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
1794 struct bpo_reloc_section_info
*bpodata
1795 = mmix_elf_section_data (sec
)->bpo
.reloc
;
1796 asection
*allocated_gregs_section
;
1798 /* If no bpodata here, we have nothing to do. */
1799 if (bpodata
== NULL
)
1802 allocated_gregs_section
= bpodata
->bpo_greg_section
;
1804 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
->n_bpo_relocs
1805 -= bpodata
->n_bpo_relocs_this_section
;
1810 /* Sort register relocs to come before expanding relocs. */
1813 mmix_elf_sort_relocs (p1
, p2
)
1817 const Elf_Internal_Rela
*r1
= (const Elf_Internal_Rela
*) p1
;
1818 const Elf_Internal_Rela
*r2
= (const Elf_Internal_Rela
*) p2
;
1819 int r1_is_reg
, r2_is_reg
;
1821 /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1823 if ((r1
->r_offset
& ~(bfd_vma
) 3) > (r2
->r_offset
& ~(bfd_vma
) 3))
1825 else if ((r1
->r_offset
& ~(bfd_vma
) 3) < (r2
->r_offset
& ~(bfd_vma
) 3))
1829 = (ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG_OR_BYTE
1830 || ELF64_R_TYPE (r1
->r_info
) == R_MMIX_REG
);
1832 = (ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG_OR_BYTE
1833 || ELF64_R_TYPE (r2
->r_info
) == R_MMIX_REG
);
1834 if (r1_is_reg
!= r2_is_reg
)
1835 return r2_is_reg
- r1_is_reg
;
1837 /* Neither or both are register relocs. Then sort on full offset. */
1838 if (r1
->r_offset
> r2
->r_offset
)
1840 else if (r1
->r_offset
< r2
->r_offset
)
1845 /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
1848 mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
)
1850 struct bfd_link_info
*info
;
1852 const Elf_Internal_Rela
*relocs
;
1854 bfd
*bpo_greg_owner
= NULL
;
1855 asection
*allocated_gregs_section
= NULL
;
1856 struct bpo_greg_section_info
*gregdata
= NULL
;
1857 struct bpo_reloc_section_info
*bpodata
= NULL
;
1858 const Elf_Internal_Rela
*rel
;
1859 const Elf_Internal_Rela
*rel_end
;
1861 /* We currently have to abuse this COFF-specific member, since there's
1862 no target-machine-dedicated member. There's no alternative outside
1863 the bfd_link_info struct; we can't specialize a hash-table since
1864 they're different between ELF and mmo. */
1865 bpo_greg_owner
= (bfd
*) info
->base_file
;
1867 rel_end
= relocs
+ sec
->reloc_count
;
1868 for (rel
= relocs
; rel
< rel_end
; rel
++)
1870 switch (ELF64_R_TYPE (rel
->r_info
))
1872 /* This relocation causes a GREG allocation. We need to count
1873 them, and we need to create a section for them, so we need an
1874 object to fake as the owner of that section. We can't use
1875 the ELF dynobj for this, since the ELF bits assume lots of
1876 DSO-related stuff if that member is non-NULL. */
1877 case R_MMIX_BASE_PLUS_OFFSET
:
1878 /* We don't do anything with this reloc for a relocatable link. */
1879 if (info
->relocatable
)
1882 if (bpo_greg_owner
== NULL
)
1884 bpo_greg_owner
= abfd
;
1885 info
->base_file
= (PTR
) bpo_greg_owner
;
1888 if (allocated_gregs_section
== NULL
)
1889 allocated_gregs_section
1890 = bfd_get_section_by_name (bpo_greg_owner
,
1891 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
1893 if (allocated_gregs_section
== NULL
)
1895 allocated_gregs_section
1896 = bfd_make_section (bpo_greg_owner
,
1897 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
1898 /* Setting both SEC_ALLOC and SEC_LOAD means the section is
1899 treated like any other section, and we'd get errors for
1900 address overlap with the text section. Let's set none of
1901 those flags, as that is what currently happens for usual
1902 GREG allocations, and that works. */
1903 if (allocated_gregs_section
== NULL
1904 || !bfd_set_section_flags (bpo_greg_owner
,
1905 allocated_gregs_section
,
1908 | SEC_LINKER_CREATED
))
1909 || !bfd_set_section_alignment (bpo_greg_owner
,
1910 allocated_gregs_section
,
1914 gregdata
= (struct bpo_greg_section_info
*)
1915 bfd_zalloc (bpo_greg_owner
, sizeof (struct bpo_greg_section_info
));
1916 if (gregdata
== NULL
)
1918 mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
1921 else if (gregdata
== NULL
)
1923 = mmix_elf_section_data (allocated_gregs_section
)->bpo
.greg
;
1925 /* Get ourselves some auxiliary info for the BPO-relocs. */
1926 if (bpodata
== NULL
)
1928 /* No use doing a separate iteration pass to find the upper
1929 limit - just use the number of relocs. */
1930 bpodata
= (struct bpo_reloc_section_info
*)
1931 bfd_alloc (bpo_greg_owner
,
1932 sizeof (struct bpo_reloc_section_info
)
1933 * (sec
->reloc_count
+ 1));
1934 if (bpodata
== NULL
)
1936 mmix_elf_section_data (sec
)->bpo
.reloc
= bpodata
;
1937 bpodata
->first_base_plus_offset_reloc
1938 = bpodata
->bpo_index
1939 = gregdata
->n_max_bpo_relocs
;
1940 bpodata
->bpo_greg_section
1941 = allocated_gregs_section
;
1942 bpodata
->n_bpo_relocs_this_section
= 0;
1945 bpodata
->n_bpo_relocs_this_section
++;
1946 gregdata
->n_max_bpo_relocs
++;
1948 /* We don't get another chance to set this before GC; we've not
1949 set up any hook that runs before GC. */
1950 gregdata
->n_bpo_relocs
1951 = gregdata
->n_max_bpo_relocs
;
1954 case R_MMIX_PUSHJ_STUBBABLE
:
1955 mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
++;
1960 /* Allocate per-reloc stub storage and initialize it to the max stub
1962 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
!= 0)
1966 mmix_elf_section_data (sec
)->pjs
.stub_size
1967 = bfd_alloc (abfd
, mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
1968 * sizeof (mmix_elf_section_data (sec
)
1969 ->pjs
.stub_size
[0]));
1970 if (mmix_elf_section_data (sec
)->pjs
.stub_size
== NULL
)
1973 for (i
= 0; i
< mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
; i
++)
1974 mmix_elf_section_data (sec
)->pjs
.stub_size
[i
] = MAX_PUSHJ_STUB_SIZE
;
1980 /* Look through the relocs for a section during the first phase. */
1983 mmix_elf_check_relocs (abfd
, info
, sec
, relocs
)
1985 struct bfd_link_info
*info
;
1987 const Elf_Internal_Rela
*relocs
;
1989 Elf_Internal_Shdr
*symtab_hdr
;
1990 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1991 const Elf_Internal_Rela
*rel
;
1992 const Elf_Internal_Rela
*rel_end
;
1994 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1995 sym_hashes
= elf_sym_hashes (abfd
);
1996 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf64_External_Sym
);
1997 if (!elf_bad_symtab (abfd
))
1998 sym_hashes_end
-= symtab_hdr
->sh_info
;
2000 /* First we sort the relocs so that any register relocs come before
2001 expansion-relocs to the same insn. FIXME: Not done for mmo. */
2002 qsort ((PTR
) relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
2003 mmix_elf_sort_relocs
);
2005 /* Do the common part. */
2006 if (!mmix_elf_check_common_relocs (abfd
, info
, sec
, relocs
))
2009 if (info
->relocatable
)
2012 rel_end
= relocs
+ sec
->reloc_count
;
2013 for (rel
= relocs
; rel
< rel_end
; rel
++)
2015 struct elf_link_hash_entry
*h
;
2016 unsigned long r_symndx
;
2018 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2019 if (r_symndx
< symtab_hdr
->sh_info
)
2022 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2024 switch (ELF64_R_TYPE (rel
->r_info
))
2026 /* This relocation describes the C++ object vtable hierarchy.
2027 Reconstruct it for later use during GC. */
2028 case R_MMIX_GNU_VTINHERIT
:
2029 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2033 /* This relocation describes which C++ vtable entries are actually
2034 used. Record for later use during GC. */
2035 case R_MMIX_GNU_VTENTRY
:
2036 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2045 /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
2046 Copied from elf_link_add_object_symbols. */
2049 _bfd_mmix_check_all_relocs (abfd
, info
)
2051 struct bfd_link_info
*info
;
2055 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2057 Elf_Internal_Rela
*internal_relocs
;
2060 if ((o
->flags
& SEC_RELOC
) == 0
2061 || o
->reloc_count
== 0
2062 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
2063 && (o
->flags
& SEC_DEBUGGING
) != 0)
2064 || bfd_is_abs_section (o
->output_section
))
2068 = _bfd_elf_link_read_relocs (abfd
, o
, (PTR
) NULL
,
2069 (Elf_Internal_Rela
*) NULL
,
2071 if (internal_relocs
== NULL
)
2074 ok
= mmix_elf_check_common_relocs (abfd
, info
, o
, internal_relocs
);
2076 if (! info
->keep_memory
)
2077 free (internal_relocs
);
2086 /* Change symbols relative to the reg contents section to instead be to
2087 the register section, and scale them down to correspond to the register
2091 mmix_elf_link_output_symbol_hook (info
, name
, sym
, input_sec
, h
)
2092 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2093 const char *name ATTRIBUTE_UNUSED
;
2094 Elf_Internal_Sym
*sym
;
2095 asection
*input_sec
;
2096 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
;
2098 if (input_sec
!= NULL
2099 && input_sec
->name
!= NULL
2100 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2101 && strcmp (input_sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2104 sym
->st_shndx
= SHN_REGISTER
;
2110 /* We fake a register section that holds values that are register numbers.
2111 Having a SHN_REGISTER and register section translates better to other
2112 formats (e.g. mmo) than for example a STT_REGISTER attribute.
2113 This section faking is based on a construct in elf32-mips.c. */
2114 static asection mmix_elf_reg_section
;
2115 static asymbol mmix_elf_reg_section_symbol
;
2116 static asymbol
*mmix_elf_reg_section_symbol_ptr
;
2118 /* Handle the special section numbers that a symbol may use. */
2121 mmix_elf_symbol_processing (abfd
, asym
)
2122 bfd
*abfd ATTRIBUTE_UNUSED
;
2125 elf_symbol_type
*elfsym
;
2127 elfsym
= (elf_symbol_type
*) asym
;
2128 switch (elfsym
->internal_elf_sym
.st_shndx
)
2131 if (mmix_elf_reg_section
.name
== NULL
)
2133 /* Initialize the register section. */
2134 mmix_elf_reg_section
.name
= MMIX_REG_SECTION_NAME
;
2135 mmix_elf_reg_section
.flags
= SEC_NO_FLAGS
;
2136 mmix_elf_reg_section
.output_section
= &mmix_elf_reg_section
;
2137 mmix_elf_reg_section
.symbol
= &mmix_elf_reg_section_symbol
;
2138 mmix_elf_reg_section
.symbol_ptr_ptr
= &mmix_elf_reg_section_symbol_ptr
;
2139 mmix_elf_reg_section_symbol
.name
= MMIX_REG_SECTION_NAME
;
2140 mmix_elf_reg_section_symbol
.flags
= BSF_SECTION_SYM
;
2141 mmix_elf_reg_section_symbol
.section
= &mmix_elf_reg_section
;
2142 mmix_elf_reg_section_symbol_ptr
= &mmix_elf_reg_section_symbol
;
2144 asym
->section
= &mmix_elf_reg_section
;
2152 /* Given a BFD section, try to locate the corresponding ELF section
2156 mmix_elf_section_from_bfd_section (abfd
, sec
, retval
)
2157 bfd
* abfd ATTRIBUTE_UNUSED
;
2161 if (strcmp (bfd_get_section_name (abfd
, sec
), MMIX_REG_SECTION_NAME
) == 0)
2162 *retval
= SHN_REGISTER
;
2169 /* Hook called by the linker routine which adds symbols from an object
2170 file. We must handle the special SHN_REGISTER section number here.
2172 We also check that we only have *one* each of the section-start
2173 symbols, since otherwise having two with the same value would cause
2174 them to be "merged", but with the contents serialized. */
2177 mmix_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2179 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2180 Elf_Internal_Sym
*sym
;
2181 const char **namep ATTRIBUTE_UNUSED
;
2182 flagword
*flagsp ATTRIBUTE_UNUSED
;
2184 bfd_vma
*valp ATTRIBUTE_UNUSED
;
2186 if (sym
->st_shndx
== SHN_REGISTER
)
2187 *secp
= bfd_make_section_old_way (abfd
, MMIX_REG_SECTION_NAME
);
2188 else if ((*namep
)[0] == '_' && (*namep
)[1] == '_' && (*namep
)[2] == '.'
2189 && strncmp (*namep
, MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
2190 strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
)) == 0)
2192 /* See if we have another one. */
2193 struct bfd_link_hash_entry
*h
= bfd_link_hash_lookup (info
->hash
,
2199 if (h
!= NULL
&& h
->type
!= bfd_link_hash_undefined
)
2201 /* How do we get the asymbol (or really: the filename) from h?
2202 h->u.def.section->owner is NULL. */
2203 ((*_bfd_error_handler
)
2204 (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
2205 bfd_get_filename (abfd
), *namep
,
2206 *namep
+ strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
)));
2207 bfd_set_error (bfd_error_bad_value
);
2215 /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
2218 mmix_elf_is_local_label_name (abfd
, name
)
2225 /* Also include the default local-label definition. */
2226 if (_bfd_elf_is_local_label_name (abfd
, name
))
2232 /* If there's no ":", or more than one, it's not a local symbol. */
2233 colpos
= strchr (name
, ':');
2234 if (colpos
== NULL
|| strchr (colpos
+ 1, ':') != NULL
)
2237 /* Check that there are remaining characters and that they are digits. */
2241 digits
= strspn (colpos
+ 1, "0123456789");
2242 return digits
!= 0 && colpos
[1 + digits
] == 0;
2245 /* We get rid of the register section here. */
2248 mmix_elf_final_link (abfd
, info
)
2250 struct bfd_link_info
*info
;
2252 /* We never output a register section, though we create one for
2253 temporary measures. Check that nobody entered contents into it. */
2254 asection
*reg_section
;
2257 reg_section
= bfd_get_section_by_name (abfd
, MMIX_REG_SECTION_NAME
);
2259 if (reg_section
!= NULL
)
2261 /* FIXME: Pass error state gracefully. */
2262 if (bfd_get_section_flags (abfd
, reg_section
) & SEC_HAS_CONTENTS
)
2263 _bfd_abort (__FILE__
, __LINE__
, _("Register section has contents\n"));
2265 /* Really remove the section. */
2266 for (secpp
= &abfd
->sections
;
2267 *secpp
!= reg_section
;
2268 secpp
= &(*secpp
)->next
)
2270 bfd_section_list_remove (abfd
, secpp
);
2271 --abfd
->section_count
;
2274 if (! bfd_elf_final_link (abfd
, info
))
2277 /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
2278 the regular linker machinery. We do it here, like other targets with
2279 special sections. */
2280 if (info
->base_file
!= NULL
)
2282 asection
*greg_section
2283 = bfd_get_section_by_name ((bfd
*) info
->base_file
,
2284 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2285 if (!bfd_set_section_contents (abfd
,
2286 greg_section
->output_section
,
2287 greg_section
->contents
,
2288 (file_ptr
) greg_section
->output_offset
,
2289 greg_section
->size
))
2295 /* We need to include the maximum size of PUSHJ-stubs in the initial
2296 section size. This is expected to shrink during linker relaxation. */
2299 mmix_set_relaxable_size (abfd
, sec
, ptr
)
2300 bfd
*abfd ATTRIBUTE_UNUSED
;
2304 struct bfd_link_info
*info
= ptr
;
2306 /* Make sure we only do this for section where we know we want this,
2307 otherwise we might end up resetting the size of COMMONs. */
2308 if (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0)
2311 sec
->size
+= (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2312 * MAX_PUSHJ_STUB_SIZE
);
2314 /* For use in relocatable link, we start with a max stubs size. See
2315 mmix_elf_relax_section. */
2316 if (info
->relocatable
&& sec
->output_section
)
2317 mmix_elf_section_data (sec
->output_section
)->pjs
.stubs_size_sum
2318 += (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2319 * MAX_PUSHJ_STUB_SIZE
);
2322 /* Initialize stuff for the linker-generated GREGs to match
2323 R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
2326 _bfd_mmix_before_linker_allocation (abfd
, info
)
2327 bfd
*abfd ATTRIBUTE_UNUSED
;
2328 struct bfd_link_info
*info
;
2330 asection
*bpo_gregs_section
;
2331 bfd
*bpo_greg_owner
;
2332 struct bpo_greg_section_info
*gregdata
;
2336 size_t *bpo_reloc_indexes
;
2339 /* Set the initial size of sections. */
2340 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2341 bfd_map_over_sections (ibfd
, mmix_set_relaxable_size
, info
);
2343 /* The bpo_greg_owner bfd is supposed to have been set by
2344 mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
2345 If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2346 bpo_greg_owner
= (bfd
*) info
->base_file
;
2347 if (bpo_greg_owner
== NULL
)
2351 = bfd_get_section_by_name (bpo_greg_owner
,
2352 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2354 if (bpo_gregs_section
== NULL
)
2357 /* We use the target-data handle in the ELF section data. */
2358 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2359 if (gregdata
== NULL
)
2362 n_gregs
= gregdata
->n_bpo_relocs
;
2363 gregdata
->n_allocated_bpo_gregs
= n_gregs
;
2365 /* When this reaches zero during relaxation, all entries have been
2366 filled in and the size of the linker gregs can be calculated. */
2367 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
= n_gregs
;
2369 /* Set the zeroth-order estimate for the GREGs size. */
2370 gregs_size
= n_gregs
* 8;
2372 if (!bfd_set_section_size (bpo_greg_owner
, bpo_gregs_section
, gregs_size
))
2375 /* Allocate and set up the GREG arrays. They're filled in at relaxation
2376 time. Note that we must use the max number ever noted for the array,
2377 since the index numbers were created before GC. */
2378 gregdata
->reloc_request
2379 = bfd_zalloc (bpo_greg_owner
,
2380 sizeof (struct bpo_reloc_request
)
2381 * gregdata
->n_max_bpo_relocs
);
2383 gregdata
->bpo_reloc_indexes
2385 = bfd_alloc (bpo_greg_owner
,
2386 gregdata
->n_max_bpo_relocs
2388 if (bpo_reloc_indexes
== NULL
)
2391 /* The default order is an identity mapping. */
2392 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2394 bpo_reloc_indexes
[i
] = i
;
2395 gregdata
->reloc_request
[i
].bpo_reloc_no
= i
;
2401 /* Fill in contents in the linker allocated gregs. Everything is
2402 calculated at this point; we just move the contents into place here. */
2405 _bfd_mmix_after_linker_allocation (abfd
, link_info
)
2406 bfd
*abfd ATTRIBUTE_UNUSED
;
2407 struct bfd_link_info
*link_info
;
2409 asection
*bpo_gregs_section
;
2410 bfd
*bpo_greg_owner
;
2411 struct bpo_greg_section_info
*gregdata
;
2417 /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
2418 when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
2419 object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2420 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2421 if (bpo_greg_owner
== NULL
)
2425 = bfd_get_section_by_name (bpo_greg_owner
,
2426 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2428 /* This can't happen without DSO handling. When DSOs are handled
2429 without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
2431 if (bpo_gregs_section
== NULL
)
2434 /* We use the target-data handle in the ELF section data. */
2436 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2437 if (gregdata
== NULL
)
2440 n_gregs
= gregdata
->n_allocated_bpo_gregs
;
2442 bpo_gregs_section
->contents
2443 = contents
= bfd_alloc (bpo_greg_owner
, bpo_gregs_section
->size
);
2444 if (contents
== NULL
)
2447 /* Sanity check: If these numbers mismatch, some relocation has not been
2448 accounted for and the rest of gregdata is probably inconsistent.
2449 It's a bug, but it's more helpful to identify it than segfaulting
2451 if (gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2452 != gregdata
->n_bpo_relocs
)
2454 (*_bfd_error_handler
)
2455 (_("Internal inconsistency: remaining %u != max %u.\n\
2456 Please report this bug."),
2457 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2458 gregdata
->n_bpo_relocs
);
2462 for (lastreg
= 255, i
= 0, j
= 0; j
< n_gregs
; i
++)
2463 if (gregdata
->reloc_request
[i
].regindex
!= lastreg
)
2465 bfd_put_64 (bpo_greg_owner
, gregdata
->reloc_request
[i
].value
,
2467 lastreg
= gregdata
->reloc_request
[i
].regindex
;
2474 /* Sort valid relocs to come before non-valid relocs, then on increasing
2478 bpo_reloc_request_sort_fn (p1
, p2
)
2482 const struct bpo_reloc_request
*r1
= (const struct bpo_reloc_request
*) p1
;
2483 const struct bpo_reloc_request
*r2
= (const struct bpo_reloc_request
*) p2
;
2485 /* Primary function is validity; non-valid relocs sorted after valid
2487 if (r1
->valid
!= r2
->valid
)
2488 return r2
->valid
- r1
->valid
;
2490 /* Then sort on value. Don't simplify and return just the difference of
2491 the values: the upper bits of the 64-bit value would be truncated on
2492 a host with 32-bit ints. */
2493 if (r1
->value
!= r2
->value
)
2494 return r1
->value
> r2
->value
? 1 : -1;
2496 /* As a last re-sort, use the relocation number, so we get a stable
2497 sort. The *addresses* aren't stable since items are swapped during
2498 sorting. It depends on the qsort implementation if this actually
2500 return r1
->bpo_reloc_no
> r2
->bpo_reloc_no
2501 ? 1 : (r1
->bpo_reloc_no
< r2
->bpo_reloc_no
? -1 : 0);
2504 /* For debug use only. Dumps the global register allocations resulting
2505 from base-plus-offset relocs. */
2508 mmix_dump_bpo_gregs (link_info
, pf
)
2509 struct bfd_link_info
*link_info
;
2510 bfd_error_handler_type pf
;
2512 bfd
*bpo_greg_owner
;
2513 asection
*bpo_gregs_section
;
2514 struct bpo_greg_section_info
*gregdata
;
2517 if (link_info
== NULL
|| link_info
->base_file
== NULL
)
2520 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2523 = bfd_get_section_by_name (bpo_greg_owner
,
2524 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME
);
2526 if (bpo_gregs_section
== NULL
)
2529 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2530 if (gregdata
== NULL
)
2534 pf
= _bfd_error_handler
;
2536 /* These format strings are not translated. They are for debug purposes
2537 only and never displayed to an end user. Should they escape, we
2538 surely want them in original. */
2539 (*pf
) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
2540 n_allocated_bpo_gregs: %u\n", gregdata
->n_bpo_relocs
,
2541 gregdata
->n_max_bpo_relocs
,
2542 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
,
2543 gregdata
->n_allocated_bpo_gregs
);
2545 if (gregdata
->reloc_request
)
2546 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2547 (*pf
) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
2549 (gregdata
->bpo_reloc_indexes
!= NULL
2550 ? gregdata
->bpo_reloc_indexes
[i
] : (size_t) -1),
2551 gregdata
->reloc_request
[i
].bpo_reloc_no
,
2552 gregdata
->reloc_request
[i
].valid
,
2554 (unsigned long) (gregdata
->reloc_request
[i
].value
>> 32),
2555 (unsigned long) gregdata
->reloc_request
[i
].value
,
2556 gregdata
->reloc_request
[i
].regindex
,
2557 gregdata
->reloc_request
[i
].offset
);
2560 /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
2561 when the last such reloc is done, an index-array is sorted according to
2562 the values and iterated over to produce register numbers (indexed by 0
2563 from the first allocated register number) and offsets for use in real
2566 PUSHJ stub accounting is also done here.
2568 Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
2571 mmix_elf_relax_section (abfd
, sec
, link_info
, again
)
2574 struct bfd_link_info
*link_info
;
2577 Elf_Internal_Shdr
*symtab_hdr
;
2578 Elf_Internal_Rela
*internal_relocs
;
2579 Elf_Internal_Rela
*irel
, *irelend
;
2580 asection
*bpo_gregs_section
= NULL
;
2581 struct bpo_greg_section_info
*gregdata
;
2582 struct bpo_reloc_section_info
*bpodata
2583 = mmix_elf_section_data (sec
)->bpo
.reloc
;
2584 /* The initialization is to quiet compiler warnings. The value is to
2585 spot a missing actual initialization. */
2586 size_t bpono
= (size_t) -1;
2588 bfd
*bpo_greg_owner
;
2589 Elf_Internal_Sym
*isymbuf
= NULL
;
2590 bfd_size_type size
= (sec
->size
2591 - (mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
2592 * MAX_PUSHJ_STUB_SIZE
));
2594 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
= 0;
2596 /* Assume nothing changes. */
2599 /* We don't have to do anything if this section does not have relocs, or
2600 if this is not a code section. */
2601 if ((sec
->flags
& SEC_RELOC
) == 0
2602 || sec
->reloc_count
== 0
2603 || (sec
->flags
& SEC_CODE
) == 0
2604 || (sec
->flags
& SEC_LINKER_CREATED
) != 0
2605 /* If no R_MMIX_BASE_PLUS_OFFSET relocs and no PUSHJ-stub relocs,
2606 then nothing to do. */
2608 && mmix_elf_section_data (sec
)->pjs
.n_pushj_relocs
== 0))
2611 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2613 bpo_greg_owner
= (bfd
*) link_info
->base_file
;
2615 if (bpodata
!= NULL
)
2617 bpo_gregs_section
= bpodata
->bpo_greg_section
;
2618 gregdata
= mmix_elf_section_data (bpo_gregs_section
)->bpo
.greg
;
2619 bpono
= bpodata
->first_base_plus_offset_reloc
;
2624 /* Get a copy of the native relocations. */
2626 = _bfd_elf_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
2627 (Elf_Internal_Rela
*) NULL
,
2628 link_info
->keep_memory
);
2629 if (internal_relocs
== NULL
)
2632 /* Walk through them looking for relaxing opportunities. */
2633 irelend
= internal_relocs
+ sec
->reloc_count
;
2634 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2637 struct elf_link_hash_entry
*h
= NULL
;
2639 /* We only process two relocs. */
2640 if (ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_BASE_PLUS_OFFSET
2641 && ELF64_R_TYPE (irel
->r_info
) != (int) R_MMIX_PUSHJ_STUBBABLE
)
2644 /* We process relocs in a distinctly different way when this is a
2645 relocatable link (for one, we don't look at symbols), so we avoid
2646 mixing its code with that for the "normal" relaxation. */
2647 if (link_info
->relocatable
)
2649 /* The only transformation in a relocatable link is to generate
2650 a full stub at the location of the stub calculated for the
2651 input section, if the relocated stub location, the end of the
2652 output section plus earlier stubs, cannot be reached. Thus
2653 relocatable linking can only lead to worse code, but it still
2655 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_PUSHJ_STUBBABLE
)
2657 /* If we can reach the end of the output-section and beyond
2658 any current stubs, then we don't need a stub for this
2659 reloc. The relaxed order of output stub allocation may
2660 not exactly match the straightforward order, so we always
2661 assume presence of output stubs, which will allow
2662 relaxation only on relocations indifferent to the
2663 presence of output stub allocations for other relocations
2664 and thus the order of output stub allocation. */
2665 if (bfd_check_overflow (complain_overflow_signed
,
2668 bfd_arch_bits_per_address (abfd
),
2669 /* Output-stub location. */
2670 sec
->output_section
->size
2671 + (mmix_elf_section_data (sec
2673 ->pjs
.stubs_size_sum
)
2674 /* Location of this PUSHJ reloc. */
2675 - (sec
->output_offset
+ irel
->r_offset
)
2676 /* Don't count *this* stub twice. */
2677 - (mmix_elf_section_data (sec
)
2678 ->pjs
.stub_size
[pjsno
]
2679 + MAX_PUSHJ_STUB_SIZE
))
2681 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2683 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2684 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2692 /* Get the value of the symbol referred to by the reloc. */
2693 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2695 /* A local symbol. */
2696 Elf_Internal_Sym
*isym
;
2699 /* Read this BFD's local symbols if we haven't already. */
2700 if (isymbuf
== NULL
)
2702 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2703 if (isymbuf
== NULL
)
2704 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2705 symtab_hdr
->sh_info
, 0,
2711 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
2712 if (isym
->st_shndx
== SHN_UNDEF
)
2713 sym_sec
= bfd_und_section_ptr
;
2714 else if (isym
->st_shndx
== SHN_ABS
)
2715 sym_sec
= bfd_abs_section_ptr
;
2716 else if (isym
->st_shndx
== SHN_COMMON
)
2717 sym_sec
= bfd_com_section_ptr
;
2719 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2720 symval
= (isym
->st_value
2721 + sym_sec
->output_section
->vma
2722 + sym_sec
->output_offset
);
2728 /* An external symbol. */
2729 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2730 h
= elf_sym_hashes (abfd
)[indx
];
2731 BFD_ASSERT (h
!= NULL
);
2732 if (h
->root
.type
!= bfd_link_hash_defined
2733 && h
->root
.type
!= bfd_link_hash_defweak
)
2735 /* This appears to be a reference to an undefined symbol. Just
2736 ignore it--it will be caught by the regular reloc processing.
2737 We need to keep BPO reloc accounting consistent, though
2738 else we'll abort instead of emitting an error message. */
2739 if (ELF64_R_TYPE (irel
->r_info
) == R_MMIX_BASE_PLUS_OFFSET
2740 && gregdata
!= NULL
)
2742 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2748 symval
= (h
->root
.u
.def
.value
2749 + h
->root
.u
.def
.section
->output_section
->vma
2750 + h
->root
.u
.def
.section
->output_offset
);
2753 if (ELF64_R_TYPE (irel
->r_info
) == (int) R_MMIX_PUSHJ_STUBBABLE
)
2755 bfd_vma value
= symval
+ irel
->r_addend
;
2757 = (sec
->output_section
->vma
2758 + sec
->output_offset
2761 = (sec
->output_section
->vma
2762 + sec
->output_offset
2764 + mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
);
2766 if ((value
& 3) == 0
2767 && bfd_check_overflow (complain_overflow_signed
,
2770 bfd_arch_bits_per_address (abfd
),
2773 ? mmix_elf_section_data (sec
)
2774 ->pjs
.stub_size
[pjsno
]
2777 /* If the reloc fits, no stub is needed. */
2778 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 0;
2780 /* Maybe we can get away with just a JMP insn? */
2781 if ((value
& 3) == 0
2782 && bfd_check_overflow (complain_overflow_signed
,
2785 bfd_arch_bits_per_address (abfd
),
2788 ? mmix_elf_section_data (sec
)
2789 ->pjs
.stub_size
[pjsno
] - 4
2792 /* Yep, account for a stub consisting of a single JMP insn. */
2793 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
] = 4;
2795 /* Nope, go for the full insn stub. It doesn't seem useful to
2796 emit the intermediate sizes; those will only be useful for
2797 a >64M program assuming contiguous code. */
2798 mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
]
2799 = MAX_PUSHJ_STUB_SIZE
;
2801 mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
2802 += mmix_elf_section_data (sec
)->pjs
.stub_size
[pjsno
];
2807 /* We're looking at a R_MMIX_BASE_PLUS_OFFSET reloc. */
2809 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
]].value
2810 = symval
+ irel
->r_addend
;
2811 gregdata
->reloc_request
[gregdata
->bpo_reloc_indexes
[bpono
++]].valid
= TRUE
;
2812 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
--;
2815 /* Check if that was the last BPO-reloc. If so, sort the values and
2816 calculate how many registers we need to cover them. Set the size of
2817 the linker gregs, and if the number of registers changed, indicate
2818 that we need to relax some more because we have more work to do. */
2819 if (gregdata
!= NULL
2820 && gregdata
->n_remaining_bpo_relocs_this_relaxation_round
== 0)
2826 /* First, reset the remaining relocs for the next round. */
2827 gregdata
->n_remaining_bpo_relocs_this_relaxation_round
2828 = gregdata
->n_bpo_relocs
;
2830 qsort ((PTR
) gregdata
->reloc_request
,
2831 gregdata
->n_max_bpo_relocs
,
2832 sizeof (struct bpo_reloc_request
),
2833 bpo_reloc_request_sort_fn
);
2835 /* Recalculate indexes. When we find a change (however unlikely
2836 after the initial iteration), we know we need to relax again,
2837 since items in the GREG-array are sorted by increasing value and
2838 stored in the relaxation phase. */
2839 for (i
= 0; i
< gregdata
->n_max_bpo_relocs
; i
++)
2840 if (gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2843 gregdata
->bpo_reloc_indexes
[gregdata
->reloc_request
[i
].bpo_reloc_no
]
2848 /* Allocate register numbers (indexing from 0). Stop at the first
2850 for (i
= 0, regindex
= 0, prev_base
= gregdata
->reloc_request
[0].value
;
2851 i
< gregdata
->n_bpo_relocs
;
2854 if (gregdata
->reloc_request
[i
].value
> prev_base
+ 255)
2857 prev_base
= gregdata
->reloc_request
[i
].value
;
2859 gregdata
->reloc_request
[i
].regindex
= regindex
;
2860 gregdata
->reloc_request
[i
].offset
2861 = gregdata
->reloc_request
[i
].value
- prev_base
;
2864 /* If it's not the same as the last time, we need to relax again,
2865 because the size of the section has changed. I'm not sure we
2866 actually need to do any adjustments since the shrinking happens
2867 at the start of this section, but better safe than sorry. */
2868 if (gregdata
->n_allocated_bpo_gregs
!= regindex
+ 1)
2870 gregdata
->n_allocated_bpo_gregs
= regindex
+ 1;
2874 bpo_gregs_section
->size
= (regindex
+ 1) * 8;
2877 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2879 if (! link_info
->keep_memory
)
2883 /* Cache the symbols for elf_link_input_bfd. */
2884 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2888 if (internal_relocs
!= NULL
2889 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2890 free (internal_relocs
);
2892 if (sec
->size
< size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2895 if (sec
->size
> size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
)
2897 sec
->size
= size
+ mmix_elf_section_data (sec
)->pjs
.stubs_size_sum
;
2904 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2906 if (internal_relocs
!= NULL
2907 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2908 free (internal_relocs
);
2912 /* Because we set size to include the max size of pushj stubs,
2913 i.e. larger than the actual section input size (see
2914 mmix_set_relaxablesize), we have to take care of that when reading
2918 mmix_elf_get_section_contents (abfd
, section
, location
, offset
, count
)
2923 bfd_size_type count
;
2925 bfd_size_type size
= (section
->size
2926 - (mmix_elf_section_data (section
)->pjs
.n_pushj_relocs
2927 * MAX_PUSHJ_STUB_SIZE
));
2929 if (offset
+ count
> section
->size
)
2932 bfd_set_error (bfd_error_invalid_operation
);
2936 /* Check bounds against the faked size. */
2937 if (offset
+ count
> size
)
2939 /* Clear the part in the faked area. */
2940 memset (location
+ size
- offset
, 0, count
- (size
- offset
));
2942 /* If there's no initial part within the "real" contents, we're
2944 if ((bfd_size_type
) offset
>= size
)
2947 /* Else adjust the count and fall through to call the generic
2949 count
= size
- offset
;
2953 _bfd_generic_get_section_contents (abfd
, section
, location
, offset
,
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
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
3005 #define bfd_elf64_get_section_contents mmix_elf_get_section_contents
3007 #include "elf64-target.h"