daily update
[binutils.git] / bfd / elf64-mmix.c
blobbcf996265716056a4089ed4170ba954cb8530b4f
1 /* MMIX-specific support for 64-bit ELF.
2 Copyright 2001, 2002, 2003 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. */
23 /* TODO:
24 - Linker relaxation. */
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "libbfd.h"
29 #include "elf-bfd.h"
30 #include "elf/mmix.h"
31 #include "opcode/mmix.h"
33 #define MINUS_ONE (((bfd_vma) 0) - 1)
35 /* Put these everywhere in new code. */
36 #define FATAL_DEBUG \
37 _bfd_abort (__FILE__, __LINE__, \
38 "Internal: Non-debugged code (test-case missing)")
40 #define BAD_CASE(x) \
41 _bfd_abort (__FILE__, __LINE__, \
42 "bad case for " #x)
44 struct _mmix_elf_section_data
46 struct bfd_elf_section_data elf;
47 union
49 struct bpo_reloc_section_info *reloc;
50 struct bpo_greg_section_info *greg;
51 } bpo;
54 #define mmix_elf_section_data(sec) \
55 ((struct _mmix_elf_section_data *) elf_section_data (sec))
57 /* For each section containing a base-plus-offset (BPO) reloc, we attach
58 this struct as mmix_elf_section_data (section)->bpo, which is otherwise
59 NULL. */
60 struct bpo_reloc_section_info
62 /* The base is 1; this is the first number in this section. */
63 size_t first_base_plus_offset_reloc;
65 /* Number of BPO-relocs in this section. */
66 size_t n_bpo_relocs_this_section;
68 /* Running index, used at relocation time. */
69 size_t bpo_index;
71 /* We don't have access to the bfd_link_info struct in
72 mmix_final_link_relocate. What we really want to get at is the
73 global single struct greg_relocation, so we stash it here. */
74 asection *bpo_greg_section;
77 /* Helper struct (in global context) for the one below.
78 There's one of these created for every BPO reloc. */
79 struct bpo_reloc_request
81 bfd_vma value;
83 /* Valid after relaxation. The base is 0; the first register number
84 must be added. The offset is in range 0..255. */
85 size_t regindex;
86 size_t offset;
88 /* The order number for this BPO reloc, corresponding to the order in
89 which BPO relocs were found. Used to create an index after reloc
90 requests are sorted. */
91 size_t bpo_reloc_no;
93 /* Set when the value is computed. Better than coding "guard values"
94 into the other members. Is FALSE only for BPO relocs in a GC:ed
95 section. */
96 bfd_boolean valid;
99 /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
100 greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
101 which is linked into the register contents section
102 (MMIX_REG_CONTENTS_SECTION_NAME). This section is created by the
103 linker; using the same hook as for usual with BPO relocs does not
104 collide. */
105 struct bpo_greg_section_info
107 /* After GC, this reflects the number of remaining, non-excluded
108 BPO-relocs. */
109 size_t n_bpo_relocs;
111 /* This is the number of allocated bpo_reloc_requests; the size of
112 sorted_indexes. Valid after the check.*relocs functions are called
113 for all incoming sections. It includes the number of BPO relocs in
114 sections that were GC:ed. */
115 size_t n_max_bpo_relocs;
117 /* A counter used to find out when to fold the BPO gregs, since we
118 don't have a single "after-relaxation" hook. */
119 size_t n_remaining_bpo_relocs_this_relaxation_round;
121 /* The number of linker-allocated GREGs resulting from BPO relocs.
122 This is an approximation after _bfd_mmix_allocated_gregs_init and
123 supposedly accurate after mmix_elf_relax_section is called for all
124 incoming non-collected sections. */
125 size_t n_allocated_bpo_gregs;
127 /* Index into reloc_request[], sorted on increasing "value", secondary
128 by increasing index for strict sorting order. */
129 size_t *bpo_reloc_indexes;
131 /* An array of all relocations, with the "value" member filled in by
132 the relaxation function. */
133 struct bpo_reloc_request *reloc_request;
136 static bfd_boolean mmix_elf_link_output_symbol_hook
137 PARAMS ((bfd *, struct bfd_link_info *, const char *,
138 Elf_Internal_Sym *, asection *));
140 static bfd_reloc_status_type mmix_elf_reloc
141 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
143 static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
144 PARAMS ((bfd *, bfd_reloc_code_real_type));
146 static void mmix_info_to_howto_rela
147 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
149 static int mmix_elf_sort_relocs PARAMS ((const PTR, const PTR));
151 static bfd_boolean mmix_elf_new_section_hook
152 PARAMS ((bfd *, asection *));
154 static bfd_boolean mmix_elf_check_relocs
155 PARAMS ((bfd *, struct bfd_link_info *, asection *,
156 const Elf_Internal_Rela *));
158 static bfd_boolean mmix_elf_check_common_relocs
159 PARAMS ((bfd *, struct bfd_link_info *, asection *,
160 const Elf_Internal_Rela *));
162 static bfd_boolean mmix_elf_relocate_section
163 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
164 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
166 static asection * mmix_elf_gc_mark_hook
167 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
168 struct elf_link_hash_entry *, Elf_Internal_Sym *));
170 static bfd_boolean mmix_elf_gc_sweep_hook
171 PARAMS ((bfd *, struct bfd_link_info *, asection *,
172 const Elf_Internal_Rela *));
174 static bfd_reloc_status_type mmix_final_link_relocate
175 PARAMS ((reloc_howto_type *, asection *, bfd_byte *,
176 bfd_vma, bfd_signed_vma, bfd_vma, const char *, asection *));
178 static bfd_reloc_status_type mmix_elf_perform_relocation
179 PARAMS ((asection *, reloc_howto_type *, PTR, bfd_vma, bfd_vma));
181 static bfd_boolean mmix_elf_section_from_bfd_section
182 PARAMS ((bfd *, asection *, int *));
184 static bfd_boolean mmix_elf_add_symbol_hook
185 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
186 const char **, flagword *, asection **, bfd_vma *));
188 static bfd_boolean mmix_elf_is_local_label_name
189 PARAMS ((bfd *, const char *));
191 static int bpo_reloc_request_sort_fn PARAMS ((const PTR, const PTR));
193 static bfd_boolean mmix_elf_relax_section
194 PARAMS ((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
195 bfd_boolean *again));
197 extern bfd_boolean mmix_elf_final_link PARAMS ((bfd *, struct bfd_link_info *));
199 extern void mmix_elf_symbol_processing PARAMS ((bfd *, asymbol *));
201 /* Only intended to be called from a debugger. */
202 extern void mmix_dump_bpo_gregs
203 PARAMS ((struct bfd_link_info *, bfd_error_handler_type));
205 /* Watch out: this currently needs to have elements with the same index as
206 their R_MMIX_ number. */
207 static reloc_howto_type elf_mmix_howto_table[] =
209 /* This reloc does nothing. */
210 HOWTO (R_MMIX_NONE, /* type */
211 0, /* rightshift */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
213 32, /* bitsize */
214 FALSE, /* pc_relative */
215 0, /* bitpos */
216 complain_overflow_bitfield, /* complain_on_overflow */
217 bfd_elf_generic_reloc, /* special_function */
218 "R_MMIX_NONE", /* name */
219 FALSE, /* partial_inplace */
220 0, /* src_mask */
221 0, /* dst_mask */
222 FALSE), /* pcrel_offset */
224 /* An 8 bit absolute relocation. */
225 HOWTO (R_MMIX_8, /* type */
226 0, /* rightshift */
227 0, /* size (0 = byte, 1 = short, 2 = long) */
228 8, /* bitsize */
229 FALSE, /* pc_relative */
230 0, /* bitpos */
231 complain_overflow_bitfield, /* complain_on_overflow */
232 bfd_elf_generic_reloc, /* special_function */
233 "R_MMIX_8", /* name */
234 FALSE, /* partial_inplace */
235 0, /* src_mask */
236 0xff, /* dst_mask */
237 FALSE), /* pcrel_offset */
239 /* An 16 bit absolute relocation. */
240 HOWTO (R_MMIX_16, /* type */
241 0, /* rightshift */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
243 16, /* bitsize */
244 FALSE, /* pc_relative */
245 0, /* bitpos */
246 complain_overflow_bitfield, /* complain_on_overflow */
247 bfd_elf_generic_reloc, /* special_function */
248 "R_MMIX_16", /* name */
249 FALSE, /* partial_inplace */
250 0, /* src_mask */
251 0xffff, /* dst_mask */
252 FALSE), /* pcrel_offset */
254 /* An 24 bit absolute relocation. */
255 HOWTO (R_MMIX_24, /* type */
256 0, /* rightshift */
257 2, /* size (0 = byte, 1 = short, 2 = long) */
258 24, /* bitsize */
259 FALSE, /* pc_relative */
260 0, /* bitpos */
261 complain_overflow_bitfield, /* complain_on_overflow */
262 bfd_elf_generic_reloc, /* special_function */
263 "R_MMIX_24", /* name */
264 FALSE, /* partial_inplace */
265 ~0xffffff, /* src_mask */
266 0xffffff, /* dst_mask */
267 FALSE), /* pcrel_offset */
269 /* A 32 bit absolute relocation. */
270 HOWTO (R_MMIX_32, /* type */
271 0, /* rightshift */
272 2, /* size (0 = byte, 1 = short, 2 = long) */
273 32, /* bitsize */
274 FALSE, /* pc_relative */
275 0, /* bitpos */
276 complain_overflow_bitfield, /* complain_on_overflow */
277 bfd_elf_generic_reloc, /* special_function */
278 "R_MMIX_32", /* name */
279 FALSE, /* partial_inplace */
280 0, /* src_mask */
281 0xffffffff, /* dst_mask */
282 FALSE), /* pcrel_offset */
284 /* 64 bit relocation. */
285 HOWTO (R_MMIX_64, /* type */
286 0, /* rightshift */
287 4, /* size (0 = byte, 1 = short, 2 = long) */
288 64, /* bitsize */
289 FALSE, /* pc_relative */
290 0, /* bitpos */
291 complain_overflow_bitfield, /* complain_on_overflow */
292 bfd_elf_generic_reloc, /* special_function */
293 "R_MMIX_64", /* name */
294 FALSE, /* partial_inplace */
295 0, /* src_mask */
296 MINUS_ONE, /* dst_mask */
297 FALSE), /* pcrel_offset */
299 /* An 8 bit PC-relative relocation. */
300 HOWTO (R_MMIX_PC_8, /* type */
301 0, /* rightshift */
302 0, /* size (0 = byte, 1 = short, 2 = long) */
303 8, /* bitsize */
304 TRUE, /* pc_relative */
305 0, /* bitpos */
306 complain_overflow_bitfield, /* complain_on_overflow */
307 bfd_elf_generic_reloc, /* special_function */
308 "R_MMIX_PC_8", /* name */
309 FALSE, /* partial_inplace */
310 0, /* src_mask */
311 0xff, /* dst_mask */
312 TRUE), /* pcrel_offset */
314 /* An 16 bit PC-relative relocation. */
315 HOWTO (R_MMIX_PC_16, /* type */
316 0, /* rightshift */
317 1, /* size (0 = byte, 1 = short, 2 = long) */
318 16, /* bitsize */
319 TRUE, /* pc_relative */
320 0, /* bitpos */
321 complain_overflow_bitfield, /* complain_on_overflow */
322 bfd_elf_generic_reloc, /* special_function */
323 "R_MMIX_PC_16", /* name */
324 FALSE, /* partial_inplace */
325 0, /* src_mask */
326 0xffff, /* dst_mask */
327 TRUE), /* pcrel_offset */
329 /* An 24 bit PC-relative relocation. */
330 HOWTO (R_MMIX_PC_24, /* type */
331 0, /* rightshift */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
333 24, /* bitsize */
334 TRUE, /* pc_relative */
335 0, /* bitpos */
336 complain_overflow_bitfield, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 "R_MMIX_PC_24", /* name */
339 FALSE, /* partial_inplace */
340 ~0xffffff, /* src_mask */
341 0xffffff, /* dst_mask */
342 TRUE), /* pcrel_offset */
344 /* A 32 bit absolute PC-relative relocation. */
345 HOWTO (R_MMIX_PC_32, /* type */
346 0, /* rightshift */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
348 32, /* bitsize */
349 TRUE, /* pc_relative */
350 0, /* bitpos */
351 complain_overflow_bitfield, /* complain_on_overflow */
352 bfd_elf_generic_reloc, /* special_function */
353 "R_MMIX_PC_32", /* name */
354 FALSE, /* partial_inplace */
355 0, /* src_mask */
356 0xffffffff, /* dst_mask */
357 TRUE), /* pcrel_offset */
359 /* 64 bit PC-relative relocation. */
360 HOWTO (R_MMIX_PC_64, /* type */
361 0, /* rightshift */
362 4, /* size (0 = byte, 1 = short, 2 = long) */
363 64, /* bitsize */
364 TRUE, /* pc_relative */
365 0, /* bitpos */
366 complain_overflow_bitfield, /* complain_on_overflow */
367 bfd_elf_generic_reloc, /* special_function */
368 "R_MMIX_PC_64", /* name */
369 FALSE, /* partial_inplace */
370 0, /* src_mask */
371 MINUS_ONE, /* dst_mask */
372 TRUE), /* pcrel_offset */
374 /* GNU extension to record C++ vtable hierarchy. */
375 HOWTO (R_MMIX_GNU_VTINHERIT, /* type */
376 0, /* rightshift */
377 0, /* size (0 = byte, 1 = short, 2 = long) */
378 0, /* bitsize */
379 FALSE, /* pc_relative */
380 0, /* bitpos */
381 complain_overflow_dont, /* complain_on_overflow */
382 NULL, /* special_function */
383 "R_MMIX_GNU_VTINHERIT", /* name */
384 FALSE, /* partial_inplace */
385 0, /* src_mask */
386 0, /* dst_mask */
387 TRUE), /* pcrel_offset */
389 /* GNU extension to record C++ vtable member usage. */
390 HOWTO (R_MMIX_GNU_VTENTRY, /* type */
391 0, /* rightshift */
392 0, /* size (0 = byte, 1 = short, 2 = long) */
393 0, /* bitsize */
394 FALSE, /* pc_relative */
395 0, /* bitpos */
396 complain_overflow_dont, /* complain_on_overflow */
397 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
398 "R_MMIX_GNU_VTENTRY", /* name */
399 FALSE, /* partial_inplace */
400 0, /* src_mask */
401 0, /* dst_mask */
402 FALSE), /* pcrel_offset */
404 /* The GETA relocation is supposed to get any address that could
405 possibly be reached by the GETA instruction. It can silently expand
406 to get a 64-bit operand, but will complain if any of the two least
407 significant bits are set. The howto members reflect a simple GETA. */
408 HOWTO (R_MMIX_GETA, /* type */
409 2, /* rightshift */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
411 19, /* bitsize */
412 TRUE, /* pc_relative */
413 0, /* bitpos */
414 complain_overflow_signed, /* complain_on_overflow */
415 mmix_elf_reloc, /* special_function */
416 "R_MMIX_GETA", /* name */
417 FALSE, /* partial_inplace */
418 ~0x0100ffff, /* src_mask */
419 0x0100ffff, /* dst_mask */
420 TRUE), /* pcrel_offset */
422 HOWTO (R_MMIX_GETA_1, /* type */
423 2, /* rightshift */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
425 19, /* bitsize */
426 TRUE, /* pc_relative */
427 0, /* bitpos */
428 complain_overflow_signed, /* complain_on_overflow */
429 mmix_elf_reloc, /* special_function */
430 "R_MMIX_GETA_1", /* name */
431 FALSE, /* partial_inplace */
432 ~0x0100ffff, /* src_mask */
433 0x0100ffff, /* dst_mask */
434 TRUE), /* pcrel_offset */
436 HOWTO (R_MMIX_GETA_2, /* type */
437 2, /* rightshift */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
439 19, /* bitsize */
440 TRUE, /* pc_relative */
441 0, /* bitpos */
442 complain_overflow_signed, /* complain_on_overflow */
443 mmix_elf_reloc, /* special_function */
444 "R_MMIX_GETA_2", /* name */
445 FALSE, /* partial_inplace */
446 ~0x0100ffff, /* src_mask */
447 0x0100ffff, /* dst_mask */
448 TRUE), /* pcrel_offset */
450 HOWTO (R_MMIX_GETA_3, /* type */
451 2, /* rightshift */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
453 19, /* bitsize */
454 TRUE, /* pc_relative */
455 0, /* bitpos */
456 complain_overflow_signed, /* complain_on_overflow */
457 mmix_elf_reloc, /* special_function */
458 "R_MMIX_GETA_3", /* name */
459 FALSE, /* partial_inplace */
460 ~0x0100ffff, /* src_mask */
461 0x0100ffff, /* dst_mask */
462 TRUE), /* pcrel_offset */
464 /* The conditional branches are supposed to reach any (code) address.
465 It can silently expand to a 64-bit operand, but will emit an error if
466 any of the two least significant bits are set. The howto members
467 reflect a simple branch. */
468 HOWTO (R_MMIX_CBRANCH, /* type */
469 2, /* rightshift */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
471 19, /* bitsize */
472 TRUE, /* pc_relative */
473 0, /* bitpos */
474 complain_overflow_signed, /* complain_on_overflow */
475 mmix_elf_reloc, /* special_function */
476 "R_MMIX_CBRANCH", /* name */
477 FALSE, /* partial_inplace */
478 ~0x0100ffff, /* src_mask */
479 0x0100ffff, /* dst_mask */
480 TRUE), /* pcrel_offset */
482 HOWTO (R_MMIX_CBRANCH_J, /* type */
483 2, /* rightshift */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
485 19, /* bitsize */
486 TRUE, /* pc_relative */
487 0, /* bitpos */
488 complain_overflow_signed, /* complain_on_overflow */
489 mmix_elf_reloc, /* special_function */
490 "R_MMIX_CBRANCH_J", /* name */
491 FALSE, /* partial_inplace */
492 ~0x0100ffff, /* src_mask */
493 0x0100ffff, /* dst_mask */
494 TRUE), /* pcrel_offset */
496 HOWTO (R_MMIX_CBRANCH_1, /* type */
497 2, /* rightshift */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
499 19, /* bitsize */
500 TRUE, /* pc_relative */
501 0, /* bitpos */
502 complain_overflow_signed, /* complain_on_overflow */
503 mmix_elf_reloc, /* special_function */
504 "R_MMIX_CBRANCH_1", /* name */
505 FALSE, /* partial_inplace */
506 ~0x0100ffff, /* src_mask */
507 0x0100ffff, /* dst_mask */
508 TRUE), /* pcrel_offset */
510 HOWTO (R_MMIX_CBRANCH_2, /* type */
511 2, /* rightshift */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
513 19, /* bitsize */
514 TRUE, /* pc_relative */
515 0, /* bitpos */
516 complain_overflow_signed, /* complain_on_overflow */
517 mmix_elf_reloc, /* special_function */
518 "R_MMIX_CBRANCH_2", /* name */
519 FALSE, /* partial_inplace */
520 ~0x0100ffff, /* src_mask */
521 0x0100ffff, /* dst_mask */
522 TRUE), /* pcrel_offset */
524 HOWTO (R_MMIX_CBRANCH_3, /* type */
525 2, /* rightshift */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
527 19, /* bitsize */
528 TRUE, /* pc_relative */
529 0, /* bitpos */
530 complain_overflow_signed, /* complain_on_overflow */
531 mmix_elf_reloc, /* special_function */
532 "R_MMIX_CBRANCH_3", /* name */
533 FALSE, /* partial_inplace */
534 ~0x0100ffff, /* src_mask */
535 0x0100ffff, /* dst_mask */
536 TRUE), /* pcrel_offset */
538 /* The PUSHJ instruction can reach any (code) address, as long as it's
539 the beginning of a function (no usable restriction). It can silently
540 expand to a 64-bit operand, but will emit an error if any of the two
541 least significant bits are set. The howto members reflect a simple
542 PUSHJ. */
543 HOWTO (R_MMIX_PUSHJ, /* type */
544 2, /* rightshift */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
546 19, /* bitsize */
547 TRUE, /* pc_relative */
548 0, /* bitpos */
549 complain_overflow_signed, /* complain_on_overflow */
550 mmix_elf_reloc, /* special_function */
551 "R_MMIX_PUSHJ", /* name */
552 FALSE, /* partial_inplace */
553 ~0x0100ffff, /* src_mask */
554 0x0100ffff, /* dst_mask */
555 TRUE), /* pcrel_offset */
557 HOWTO (R_MMIX_PUSHJ_1, /* type */
558 2, /* rightshift */
559 2, /* size (0 = byte, 1 = short, 2 = long) */
560 19, /* bitsize */
561 TRUE, /* pc_relative */
562 0, /* bitpos */
563 complain_overflow_signed, /* complain_on_overflow */
564 mmix_elf_reloc, /* special_function */
565 "R_MMIX_PUSHJ_1", /* name */
566 FALSE, /* partial_inplace */
567 ~0x0100ffff, /* src_mask */
568 0x0100ffff, /* dst_mask */
569 TRUE), /* pcrel_offset */
571 HOWTO (R_MMIX_PUSHJ_2, /* type */
572 2, /* rightshift */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
574 19, /* bitsize */
575 TRUE, /* pc_relative */
576 0, /* bitpos */
577 complain_overflow_signed, /* complain_on_overflow */
578 mmix_elf_reloc, /* special_function */
579 "R_MMIX_PUSHJ_2", /* name */
580 FALSE, /* partial_inplace */
581 ~0x0100ffff, /* src_mask */
582 0x0100ffff, /* dst_mask */
583 TRUE), /* pcrel_offset */
585 HOWTO (R_MMIX_PUSHJ_3, /* type */
586 2, /* rightshift */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
588 19, /* bitsize */
589 TRUE, /* pc_relative */
590 0, /* bitpos */
591 complain_overflow_signed, /* complain_on_overflow */
592 mmix_elf_reloc, /* special_function */
593 "R_MMIX_PUSHJ_3", /* name */
594 FALSE, /* partial_inplace */
595 ~0x0100ffff, /* src_mask */
596 0x0100ffff, /* dst_mask */
597 TRUE), /* pcrel_offset */
599 /* A JMP is supposed to reach any (code) address. By itself, it can
600 reach +-64M; the expansion can reach all 64 bits. Note that the 64M
601 limit is soon reached if you link the program in wildly different
602 memory segments. The howto members reflect a trivial JMP. */
603 HOWTO (R_MMIX_JMP, /* type */
604 2, /* rightshift */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
606 27, /* bitsize */
607 TRUE, /* pc_relative */
608 0, /* bitpos */
609 complain_overflow_signed, /* complain_on_overflow */
610 mmix_elf_reloc, /* special_function */
611 "R_MMIX_JMP", /* name */
612 FALSE, /* partial_inplace */
613 ~0x1ffffff, /* src_mask */
614 0x1ffffff, /* dst_mask */
615 TRUE), /* pcrel_offset */
617 HOWTO (R_MMIX_JMP_1, /* type */
618 2, /* rightshift */
619 2, /* size (0 = byte, 1 = short, 2 = long) */
620 27, /* bitsize */
621 TRUE, /* pc_relative */
622 0, /* bitpos */
623 complain_overflow_signed, /* complain_on_overflow */
624 mmix_elf_reloc, /* special_function */
625 "R_MMIX_JMP_1", /* name */
626 FALSE, /* partial_inplace */
627 ~0x1ffffff, /* src_mask */
628 0x1ffffff, /* dst_mask */
629 TRUE), /* pcrel_offset */
631 HOWTO (R_MMIX_JMP_2, /* type */
632 2, /* rightshift */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
634 27, /* bitsize */
635 TRUE, /* pc_relative */
636 0, /* bitpos */
637 complain_overflow_signed, /* complain_on_overflow */
638 mmix_elf_reloc, /* special_function */
639 "R_MMIX_JMP_2", /* name */
640 FALSE, /* partial_inplace */
641 ~0x1ffffff, /* src_mask */
642 0x1ffffff, /* dst_mask */
643 TRUE), /* pcrel_offset */
645 HOWTO (R_MMIX_JMP_3, /* type */
646 2, /* rightshift */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
648 27, /* bitsize */
649 TRUE, /* pc_relative */
650 0, /* bitpos */
651 complain_overflow_signed, /* complain_on_overflow */
652 mmix_elf_reloc, /* special_function */
653 "R_MMIX_JMP_3", /* name */
654 FALSE, /* partial_inplace */
655 ~0x1ffffff, /* src_mask */
656 0x1ffffff, /* dst_mask */
657 TRUE), /* pcrel_offset */
659 /* When we don't emit link-time-relaxable code from the assembler, or
660 when relaxation has done all it can do, these relocs are used. For
661 GETA/PUSHJ/branches. */
662 HOWTO (R_MMIX_ADDR19, /* type */
663 2, /* rightshift */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
665 19, /* bitsize */
666 TRUE, /* pc_relative */
667 0, /* bitpos */
668 complain_overflow_signed, /* complain_on_overflow */
669 mmix_elf_reloc, /* special_function */
670 "R_MMIX_ADDR19", /* name */
671 FALSE, /* partial_inplace */
672 ~0x0100ffff, /* src_mask */
673 0x0100ffff, /* dst_mask */
674 TRUE), /* pcrel_offset */
676 /* For JMP. */
677 HOWTO (R_MMIX_ADDR27, /* type */
678 2, /* rightshift */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
680 27, /* bitsize */
681 TRUE, /* pc_relative */
682 0, /* bitpos */
683 complain_overflow_signed, /* complain_on_overflow */
684 mmix_elf_reloc, /* special_function */
685 "R_MMIX_ADDR27", /* name */
686 FALSE, /* partial_inplace */
687 ~0x1ffffff, /* src_mask */
688 0x1ffffff, /* dst_mask */
689 TRUE), /* pcrel_offset */
691 /* A general register or the value 0..255. If a value, then the
692 instruction (offset -3) needs adjusting. */
693 HOWTO (R_MMIX_REG_OR_BYTE, /* type */
694 0, /* rightshift */
695 1, /* size (0 = byte, 1 = short, 2 = long) */
696 8, /* bitsize */
697 FALSE, /* pc_relative */
698 0, /* bitpos */
699 complain_overflow_bitfield, /* complain_on_overflow */
700 mmix_elf_reloc, /* special_function */
701 "R_MMIX_REG_OR_BYTE", /* name */
702 FALSE, /* partial_inplace */
703 0, /* src_mask */
704 0xff, /* dst_mask */
705 FALSE), /* pcrel_offset */
707 /* A general register. */
708 HOWTO (R_MMIX_REG, /* type */
709 0, /* rightshift */
710 1, /* size (0 = byte, 1 = short, 2 = long) */
711 8, /* bitsize */
712 FALSE, /* pc_relative */
713 0, /* bitpos */
714 complain_overflow_bitfield, /* complain_on_overflow */
715 mmix_elf_reloc, /* special_function */
716 "R_MMIX_REG", /* name */
717 FALSE, /* partial_inplace */
718 0, /* src_mask */
719 0xff, /* dst_mask */
720 FALSE), /* pcrel_offset */
722 /* A register plus an index, corresponding to the relocation expression.
723 The sizes must correspond to the valid range of the expression, while
724 the bitmasks correspond to what we store in the image. */
725 HOWTO (R_MMIX_BASE_PLUS_OFFSET, /* type */
726 0, /* rightshift */
727 4, /* size (0 = byte, 1 = short, 2 = long) */
728 64, /* bitsize */
729 FALSE, /* pc_relative */
730 0, /* bitpos */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 mmix_elf_reloc, /* special_function */
733 "R_MMIX_BASE_PLUS_OFFSET", /* name */
734 FALSE, /* partial_inplace */
735 0, /* src_mask */
736 0xffff, /* dst_mask */
737 FALSE), /* pcrel_offset */
739 /* A "magic" relocation for a LOCAL expression, asserting that the
740 expression is less than the number of global registers. No actual
741 modification of the contents is done. Implementing this as a
742 relocation was less intrusive than e.g. putting such expressions in a
743 section to discard *after* relocation. */
744 HOWTO (R_MMIX_LOCAL, /* type */
745 0, /* rightshift */
746 0, /* size (0 = byte, 1 = short, 2 = long) */
747 0, /* bitsize */
748 FALSE, /* pc_relative */
749 0, /* bitpos */
750 complain_overflow_dont, /* complain_on_overflow */
751 mmix_elf_reloc, /* special_function */
752 "R_MMIX_LOCAL", /* name */
753 FALSE, /* partial_inplace */
754 0, /* src_mask */
755 0, /* dst_mask */
756 FALSE), /* pcrel_offset */
760 /* Map BFD reloc types to MMIX ELF reloc types. */
762 struct mmix_reloc_map
764 bfd_reloc_code_real_type bfd_reloc_val;
765 enum elf_mmix_reloc_type elf_reloc_val;
769 static const struct mmix_reloc_map mmix_reloc_map[] =
771 {BFD_RELOC_NONE, R_MMIX_NONE},
772 {BFD_RELOC_8, R_MMIX_8},
773 {BFD_RELOC_16, R_MMIX_16},
774 {BFD_RELOC_24, R_MMIX_24},
775 {BFD_RELOC_32, R_MMIX_32},
776 {BFD_RELOC_64, R_MMIX_64},
777 {BFD_RELOC_8_PCREL, R_MMIX_PC_8},
778 {BFD_RELOC_16_PCREL, R_MMIX_PC_16},
779 {BFD_RELOC_24_PCREL, R_MMIX_PC_24},
780 {BFD_RELOC_32_PCREL, R_MMIX_PC_32},
781 {BFD_RELOC_64_PCREL, R_MMIX_PC_64},
782 {BFD_RELOC_VTABLE_INHERIT, R_MMIX_GNU_VTINHERIT},
783 {BFD_RELOC_VTABLE_ENTRY, R_MMIX_GNU_VTENTRY},
784 {BFD_RELOC_MMIX_GETA, R_MMIX_GETA},
785 {BFD_RELOC_MMIX_CBRANCH, R_MMIX_CBRANCH},
786 {BFD_RELOC_MMIX_PUSHJ, R_MMIX_PUSHJ},
787 {BFD_RELOC_MMIX_JMP, R_MMIX_JMP},
788 {BFD_RELOC_MMIX_ADDR19, R_MMIX_ADDR19},
789 {BFD_RELOC_MMIX_ADDR27, R_MMIX_ADDR27},
790 {BFD_RELOC_MMIX_REG_OR_BYTE, R_MMIX_REG_OR_BYTE},
791 {BFD_RELOC_MMIX_REG, R_MMIX_REG},
792 {BFD_RELOC_MMIX_BASE_PLUS_OFFSET, R_MMIX_BASE_PLUS_OFFSET},
793 {BFD_RELOC_MMIX_LOCAL, R_MMIX_LOCAL}
796 static reloc_howto_type *
797 bfd_elf64_bfd_reloc_type_lookup (abfd, code)
798 bfd *abfd ATTRIBUTE_UNUSED;
799 bfd_reloc_code_real_type code;
801 unsigned int i;
803 for (i = 0;
804 i < sizeof (mmix_reloc_map) / sizeof (mmix_reloc_map[0]);
805 i++)
807 if (mmix_reloc_map[i].bfd_reloc_val == code)
808 return &elf_mmix_howto_table[mmix_reloc_map[i].elf_reloc_val];
811 return NULL;
814 static bfd_boolean
815 mmix_elf_new_section_hook (abfd, sec)
816 bfd *abfd;
817 asection *sec;
819 struct _mmix_elf_section_data *sdata;
820 bfd_size_type amt = sizeof (*sdata);
822 sdata = (struct _mmix_elf_section_data *) bfd_zalloc (abfd, amt);
823 if (sdata == NULL)
824 return FALSE;
825 sec->used_by_bfd = (PTR) sdata;
827 return _bfd_elf_new_section_hook (abfd, sec);
831 /* This function performs the actual bitfiddling and sanity check for a
832 final relocation. Each relocation gets its *worst*-case expansion
833 in size when it arrives here; any reduction in size should have been
834 caught in linker relaxation earlier. When we get here, the relocation
835 looks like the smallest instruction with SWYM:s (nop:s) appended to the
836 max size. We fill in those nop:s.
838 R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
839 GETA $N,foo
841 SETL $N,foo & 0xffff
842 INCML $N,(foo >> 16) & 0xffff
843 INCMH $N,(foo >> 32) & 0xffff
844 INCH $N,(foo >> 48) & 0xffff
846 R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
847 condbranches needing relaxation might be rare enough to not be
848 worthwhile.)
849 [P]Bcc $N,foo
851 [~P]B~cc $N,.+20
852 SETL $255,foo & ...
853 INCML ...
854 INCMH ...
855 INCH ...
856 GO $255,$255,0
858 R_MMIX_PUSHJ: (FIXME: Relaxation...)
859 PUSHJ $N,foo
861 SETL $255,foo & ...
862 INCML ...
863 INCMH ...
864 INCH ...
865 PUSHGO $N,$255,0
867 R_MMIX_JMP: (FIXME: Relaxation...)
868 JMP foo
870 SETL $255,foo & ...
871 INCML ...
872 INCMH ...
873 INCH ...
874 GO $255,$255,0
876 R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
878 static bfd_reloc_status_type
879 mmix_elf_perform_relocation (isec, howto, datap, addr, value)
880 asection *isec;
881 reloc_howto_type *howto;
882 PTR datap;
883 bfd_vma addr ATTRIBUTE_UNUSED;
884 bfd_vma value;
886 bfd *abfd = isec->owner;
887 bfd_reloc_status_type flag = bfd_reloc_ok;
888 bfd_reloc_status_type r;
889 int offs = 0;
890 int reg = 255;
892 /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
893 We handle the differences here and the common sequence later. */
894 switch (howto->type)
896 case R_MMIX_GETA:
897 offs = 0;
898 reg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
900 /* We change to an absolute value. */
901 value += addr;
902 break;
904 case R_MMIX_CBRANCH:
906 int in1 = bfd_get_16 (abfd, (bfd_byte *) datap) << 16;
908 /* Invert the condition and prediction bit, and set the offset
909 to five instructions ahead.
911 We *can* do better if we want to. If the branch is found to be
912 within limits, we could leave the branch as is; there'll just
913 be a bunch of NOP:s after it. But we shouldn't see this
914 sequence often enough that it's worth doing it. */
916 bfd_put_32 (abfd,
917 (((in1 ^ ((PRED_INV_BIT | COND_INV_BIT) << 24)) & ~0xffff)
918 | (24/4)),
919 (bfd_byte *) datap);
921 /* Put a "GO $255,$255,0" after the common sequence. */
922 bfd_put_32 (abfd,
923 ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | 0xffff00,
924 (bfd_byte *) datap + 20);
926 /* Common sequence starts at offset 4. */
927 offs = 4;
929 /* We change to an absolute value. */
930 value += addr;
932 break;
934 case R_MMIX_PUSHJ:
936 int inreg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
938 /* Put a "PUSHGO $N,$255,0" after the common sequence. */
939 bfd_put_32 (abfd,
940 ((PUSHGO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
941 | (inreg << 16)
942 | 0xff00,
943 (bfd_byte *) datap + 16);
945 /* We change to an absolute value. */
946 value += addr;
948 break;
950 case R_MMIX_JMP:
951 /* This one is a little special. If we get here on a non-relaxing
952 link, and the destination is actually in range, we don't need to
953 execute the nops.
954 If so, we fall through to the bit-fiddling relocs.
956 FIXME: bfd_check_overflow seems broken; the relocation is
957 rightshifted before testing, so supply a zero rightshift. */
959 if (! ((value & 3) == 0
960 && (r = bfd_check_overflow (complain_overflow_signed,
961 howto->bitsize,
963 bfd_arch_bits_per_address (abfd),
964 value)) == bfd_reloc_ok))
966 /* If the relocation doesn't fit in a JMP, we let the NOP:s be
967 modified below, and put a "GO $255,$255,0" after the
968 address-loading sequence. */
969 bfd_put_32 (abfd,
970 ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
971 | 0xffff00,
972 (bfd_byte *) datap + 16);
974 /* We change to an absolute value. */
975 value += addr;
976 break;
978 /* FALLTHROUGH. */
979 case R_MMIX_ADDR19:
980 case R_MMIX_ADDR27:
981 /* These must be in range, or else we emit an error. */
982 if ((value & 3) == 0
983 /* Note rightshift 0; see above. */
984 && (r = bfd_check_overflow (complain_overflow_signed,
985 howto->bitsize,
987 bfd_arch_bits_per_address (abfd),
988 value)) == bfd_reloc_ok)
990 bfd_vma in1
991 = bfd_get_32 (abfd, (bfd_byte *) datap);
992 bfd_vma highbit;
994 if ((bfd_signed_vma) value < 0)
996 highbit = (1 << 24);
997 value += (1 << (howto->bitsize - 1));
999 else
1000 highbit = 0;
1002 value >>= 2;
1004 bfd_put_32 (abfd,
1005 (in1 & howto->src_mask)
1006 | highbit
1007 | (value & howto->dst_mask),
1008 (bfd_byte *) datap);
1010 return bfd_reloc_ok;
1012 else
1013 return bfd_reloc_overflow;
1015 case R_MMIX_BASE_PLUS_OFFSET:
1017 struct bpo_reloc_section_info *bpodata
1018 = mmix_elf_section_data (isec)->bpo.reloc;
1019 asection *bpo_greg_section
1020 = bpodata->bpo_greg_section;
1021 struct bpo_greg_section_info *gregdata
1022 = mmix_elf_section_data (bpo_greg_section)->bpo.greg;
1023 size_t bpo_index
1024 = gregdata->bpo_reloc_indexes[bpodata->bpo_index++];
1026 /* A consistency check: The value we now have in "relocation" must
1027 be the same as the value we stored for that relocation. It
1028 doesn't cost much, so can be left in at all times. */
1029 if (value != gregdata->reloc_request[bpo_index].value)
1031 (*_bfd_error_handler)
1032 (_("%s: Internal inconsistency error for value for\n\
1033 linker-allocated global register: linked: 0x%lx%08lx != relaxed: 0x%lx%08lx\n"),
1034 bfd_get_filename (isec->owner),
1035 (unsigned long) (value >> 32), (unsigned long) value,
1036 (unsigned long) (gregdata->reloc_request[bpo_index].value
1037 >> 32),
1038 (unsigned long) gregdata->reloc_request[bpo_index].value);
1039 bfd_set_error (bfd_error_bad_value);
1040 return bfd_reloc_overflow;
1043 /* Then store the register number and offset for that register
1044 into datap and datap + 1 respectively. */
1045 bfd_put_8 (abfd,
1046 gregdata->reloc_request[bpo_index].regindex
1047 + bpo_greg_section->output_section->vma / 8,
1048 datap);
1049 bfd_put_8 (abfd,
1050 gregdata->reloc_request[bpo_index].offset,
1051 ((unsigned char *) datap) + 1);
1052 return bfd_reloc_ok;
1055 case R_MMIX_REG_OR_BYTE:
1056 case R_MMIX_REG:
1057 if (value > 255)
1058 return bfd_reloc_overflow;
1059 bfd_put_8 (abfd, value, datap);
1060 return bfd_reloc_ok;
1062 default:
1063 BAD_CASE (howto->type);
1066 /* This code adds the common SETL/INCML/INCMH/INCH worst-case
1067 sequence. */
1069 /* Lowest two bits must be 0. We return bfd_reloc_overflow for
1070 everything that looks strange. */
1071 if (value & 3)
1072 flag = bfd_reloc_overflow;
1074 bfd_put_32 (abfd,
1075 (SETL_INSN_BYTE << 24) | (value & 0xffff) | (reg << 16),
1076 (bfd_byte *) datap + offs);
1077 bfd_put_32 (abfd,
1078 (INCML_INSN_BYTE << 24) | ((value >> 16) & 0xffff) | (reg << 16),
1079 (bfd_byte *) datap + offs + 4);
1080 bfd_put_32 (abfd,
1081 (INCMH_INSN_BYTE << 24) | ((value >> 32) & 0xffff) | (reg << 16),
1082 (bfd_byte *) datap + offs + 8);
1083 bfd_put_32 (abfd,
1084 (INCH_INSN_BYTE << 24) | ((value >> 48) & 0xffff) | (reg << 16),
1085 (bfd_byte *) datap + offs + 12);
1087 return flag;
1090 /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
1092 static void
1093 mmix_info_to_howto_rela (abfd, cache_ptr, dst)
1094 bfd *abfd ATTRIBUTE_UNUSED;
1095 arelent *cache_ptr;
1096 Elf_Internal_Rela *dst;
1098 unsigned int r_type;
1100 r_type = ELF64_R_TYPE (dst->r_info);
1101 BFD_ASSERT (r_type < (unsigned int) R_MMIX_max);
1102 cache_ptr->howto = &elf_mmix_howto_table[r_type];
1105 /* Any MMIX-specific relocation gets here at assembly time or when linking
1106 to other formats (such as mmo); this is the relocation function from
1107 the reloc_table. We don't get here for final pure ELF linking. */
1109 static bfd_reloc_status_type
1110 mmix_elf_reloc (abfd, reloc_entry, symbol, data, input_section,
1111 output_bfd, error_message)
1112 bfd *abfd;
1113 arelent *reloc_entry;
1114 asymbol *symbol;
1115 PTR data;
1116 asection *input_section;
1117 bfd *output_bfd;
1118 char **error_message ATTRIBUTE_UNUSED;
1120 bfd_vma relocation;
1121 bfd_reloc_status_type r;
1122 asection *reloc_target_output_section;
1123 bfd_reloc_status_type flag = bfd_reloc_ok;
1124 bfd_vma output_base = 0;
1125 bfd_vma addr;
1127 r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1128 input_section, output_bfd, error_message);
1130 /* If that was all that was needed (i.e. this isn't a final link, only
1131 some segment adjustments), we're done. */
1132 if (r != bfd_reloc_continue)
1133 return r;
1135 if (bfd_is_und_section (symbol->section)
1136 && (symbol->flags & BSF_WEAK) == 0
1137 && output_bfd == (bfd *) NULL)
1138 return bfd_reloc_undefined;
1140 /* Is the address of the relocation really within the section? */
1141 if (reloc_entry->address > input_section->_cooked_size)
1142 return bfd_reloc_outofrange;
1144 /* Work out which section the relocation is targetted at and the
1145 initial relocation command value. */
1147 /* Get symbol value. (Common symbols are special.) */
1148 if (bfd_is_com_section (symbol->section))
1149 relocation = 0;
1150 else
1151 relocation = symbol->value;
1153 reloc_target_output_section = bfd_get_output_section (symbol);
1155 /* Here the variable relocation holds the final address of the symbol we
1156 are relocating against, plus any addend. */
1157 if (output_bfd)
1158 output_base = 0;
1159 else
1160 output_base = reloc_target_output_section->vma;
1162 relocation += output_base + symbol->section->output_offset;
1164 /* Get position of relocation. */
1165 addr = (reloc_entry->address + input_section->output_section->vma
1166 + input_section->output_offset);
1167 if (output_bfd != (bfd *) NULL)
1169 /* Add in supplied addend. */
1170 relocation += reloc_entry->addend;
1172 /* This is a partial relocation, and we want to apply the
1173 relocation to the reloc entry rather than the raw data.
1174 Modify the reloc inplace to reflect what we now know. */
1175 reloc_entry->addend = relocation;
1176 reloc_entry->address += input_section->output_offset;
1177 return flag;
1180 return mmix_final_link_relocate (reloc_entry->howto, input_section,
1181 data, reloc_entry->address,
1182 reloc_entry->addend, relocation,
1183 bfd_asymbol_name (symbol),
1184 reloc_target_output_section);
1187 /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
1188 for guidance if you're thinking of copying this. */
1190 static bfd_boolean
1191 mmix_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1192 contents, relocs, local_syms, local_sections)
1193 bfd *output_bfd ATTRIBUTE_UNUSED;
1194 struct bfd_link_info *info;
1195 bfd *input_bfd;
1196 asection *input_section;
1197 bfd_byte *contents;
1198 Elf_Internal_Rela *relocs;
1199 Elf_Internal_Sym *local_syms;
1200 asection **local_sections;
1202 Elf_Internal_Shdr *symtab_hdr;
1203 struct elf_link_hash_entry **sym_hashes;
1204 Elf_Internal_Rela *rel;
1205 Elf_Internal_Rela *relend;
1207 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1208 sym_hashes = elf_sym_hashes (input_bfd);
1209 relend = relocs + input_section->reloc_count;
1211 for (rel = relocs; rel < relend; rel ++)
1213 reloc_howto_type *howto;
1214 unsigned long r_symndx;
1215 Elf_Internal_Sym *sym;
1216 asection *sec;
1217 struct elf_link_hash_entry *h;
1218 bfd_vma relocation;
1219 bfd_reloc_status_type r;
1220 const char *name = NULL;
1221 int r_type;
1222 bfd_boolean undefined_signalled = FALSE;
1224 r_type = ELF64_R_TYPE (rel->r_info);
1226 if (r_type == R_MMIX_GNU_VTINHERIT
1227 || r_type == R_MMIX_GNU_VTENTRY)
1228 continue;
1230 r_symndx = ELF64_R_SYM (rel->r_info);
1232 if (info->relocateable)
1234 /* This is a relocateable link. We don't have to change
1235 anything, unless the reloc is against a section symbol,
1236 in which case we have to adjust according to where the
1237 section symbol winds up in the output section. */
1238 if (r_symndx < symtab_hdr->sh_info)
1240 sym = local_syms + r_symndx;
1242 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1244 sec = local_sections [r_symndx];
1245 rel->r_addend += sec->output_offset + sym->st_value;
1249 continue;
1252 /* This is a final link. */
1253 howto = elf_mmix_howto_table + ELF64_R_TYPE (rel->r_info);
1254 h = NULL;
1255 sym = NULL;
1256 sec = NULL;
1258 if (r_symndx < symtab_hdr->sh_info)
1260 sym = local_syms + r_symndx;
1261 sec = local_sections [r_symndx];
1262 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
1264 name = bfd_elf_string_from_elf_section
1265 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1266 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1268 else
1270 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
1272 while (h->root.type == bfd_link_hash_indirect
1273 || h->root.type == bfd_link_hash_warning)
1274 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1276 name = h->root.root.string;
1278 if (h->root.type == bfd_link_hash_defined
1279 || h->root.type == bfd_link_hash_defweak)
1281 sec = h->root.u.def.section;
1282 relocation = (h->root.u.def.value
1283 + sec->output_section->vma
1284 + sec->output_offset);
1286 else if (h->root.type == bfd_link_hash_undefweak)
1287 relocation = 0;
1288 else if (info->shared
1289 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1290 relocation = 0;
1291 else
1293 /* The test on undefined_signalled is redundant at the
1294 moment, but kept for symmetry. */
1295 if (! undefined_signalled
1296 && ! ((*info->callbacks->undefined_symbol)
1297 (info, h->root.root.string, input_bfd,
1298 input_section, rel->r_offset, TRUE)))
1299 return FALSE;
1300 undefined_signalled = TRUE;
1301 relocation = 0;
1305 r = mmix_final_link_relocate (howto, input_section,
1306 contents, rel->r_offset,
1307 rel->r_addend, relocation, name, sec);
1309 if (r != bfd_reloc_ok)
1311 bfd_boolean check_ok = TRUE;
1312 const char * msg = (const char *) NULL;
1314 switch (r)
1316 case bfd_reloc_overflow:
1317 check_ok = info->callbacks->reloc_overflow
1318 (info, name, howto->name, (bfd_vma) 0,
1319 input_bfd, input_section, rel->r_offset);
1320 break;
1322 case bfd_reloc_undefined:
1323 /* We may have sent this message above. */
1324 if (! undefined_signalled)
1325 check_ok = info->callbacks->undefined_symbol
1326 (info, name, input_bfd, input_section, rel->r_offset,
1327 TRUE);
1328 undefined_signalled = TRUE;
1329 break;
1331 case bfd_reloc_outofrange:
1332 msg = _("internal error: out of range error");
1333 break;
1335 case bfd_reloc_notsupported:
1336 msg = _("internal error: unsupported relocation error");
1337 break;
1339 case bfd_reloc_dangerous:
1340 msg = _("internal error: dangerous relocation");
1341 break;
1343 default:
1344 msg = _("internal error: unknown error");
1345 break;
1348 if (msg)
1349 check_ok = info->callbacks->warning
1350 (info, msg, name, input_bfd, input_section, rel->r_offset);
1352 if (! check_ok)
1353 return FALSE;
1357 return TRUE;
1360 /* Perform a single relocation. By default we use the standard BFD
1361 routines. A few relocs we have to do ourselves. */
1363 static bfd_reloc_status_type
1364 mmix_final_link_relocate (howto, input_section, contents,
1365 r_offset, r_addend, relocation, symname, symsec)
1366 reloc_howto_type *howto;
1367 asection *input_section;
1368 bfd_byte *contents;
1369 bfd_vma r_offset;
1370 bfd_signed_vma r_addend;
1371 bfd_vma relocation;
1372 const char *symname;
1373 asection *symsec;
1375 bfd_reloc_status_type r = bfd_reloc_ok;
1376 bfd_vma addr
1377 = (input_section->output_section->vma
1378 + input_section->output_offset
1379 + r_offset);
1380 bfd_signed_vma srel
1381 = (bfd_signed_vma) relocation + r_addend;
1383 switch (howto->type)
1385 /* All these are PC-relative. */
1386 case R_MMIX_PUSHJ:
1387 case R_MMIX_CBRANCH:
1388 case R_MMIX_ADDR19:
1389 case R_MMIX_GETA:
1390 case R_MMIX_ADDR27:
1391 case R_MMIX_JMP:
1392 contents += r_offset;
1394 srel -= (input_section->output_section->vma
1395 + input_section->output_offset
1396 + r_offset);
1398 r = mmix_elf_perform_relocation (input_section, howto, contents,
1399 addr, srel);
1400 break;
1402 case R_MMIX_BASE_PLUS_OFFSET:
1403 if (symsec == NULL)
1404 return bfd_reloc_undefined;
1406 /* Check that we're not relocating against a register symbol. */
1407 if (strcmp (bfd_get_section_name (symsec->owner, symsec),
1408 MMIX_REG_CONTENTS_SECTION_NAME) == 0
1409 || strcmp (bfd_get_section_name (symsec->owner, symsec),
1410 MMIX_REG_SECTION_NAME) == 0)
1412 /* Note: This is separated out into two messages in order
1413 to ease the translation into other languages. */
1414 if (symname == NULL || *symname == 0)
1415 (*_bfd_error_handler)
1416 (_("%s: base-plus-offset relocation against register symbol: (unknown) in %s"),
1417 bfd_get_filename (input_section->owner),
1418 bfd_get_section_name (symsec->owner, symsec));
1419 else
1420 (*_bfd_error_handler)
1421 (_("%s: base-plus-offset relocation against register symbol: %s in %s"),
1422 bfd_get_filename (input_section->owner), symname,
1423 bfd_get_section_name (symsec->owner, symsec));
1424 return bfd_reloc_overflow;
1426 goto do_mmix_reloc;
1428 case R_MMIX_REG_OR_BYTE:
1429 case R_MMIX_REG:
1430 /* For now, we handle these alike. They must refer to an register
1431 symbol, which is either relative to the register section and in
1432 the range 0..255, or is in the register contents section with vma
1433 regno * 8. */
1435 /* FIXME: A better way to check for reg contents section?
1436 FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
1437 if (symsec == NULL)
1438 return bfd_reloc_undefined;
1440 if (strcmp (bfd_get_section_name (symsec->owner, symsec),
1441 MMIX_REG_CONTENTS_SECTION_NAME) == 0)
1443 if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
1445 /* The bfd_reloc_outofrange return value, though intuitively
1446 a better value, will not get us an error. */
1447 return bfd_reloc_overflow;
1449 srel /= 8;
1451 else if (strcmp (bfd_get_section_name (symsec->owner, symsec),
1452 MMIX_REG_SECTION_NAME) == 0)
1454 if (srel < 0 || srel > 255)
1455 /* The bfd_reloc_outofrange return value, though intuitively a
1456 better value, will not get us an error. */
1457 return bfd_reloc_overflow;
1459 else
1461 /* Note: This is separated out into two messages in order
1462 to ease the translation into other languages. */
1463 if (symname == NULL || *symname == 0)
1464 (*_bfd_error_handler)
1465 (_("%s: register relocation against non-register symbol: (unknown) in %s"),
1466 bfd_get_filename (input_section->owner),
1467 bfd_get_section_name (symsec->owner, symsec));
1468 else
1469 (*_bfd_error_handler)
1470 (_("%s: register relocation against non-register symbol: %s in %s"),
1471 bfd_get_filename (input_section->owner), symname,
1472 bfd_get_section_name (symsec->owner, symsec));
1474 /* The bfd_reloc_outofrange return value, though intuitively a
1475 better value, will not get us an error. */
1476 return bfd_reloc_overflow;
1478 do_mmix_reloc:
1479 contents += r_offset;
1480 r = mmix_elf_perform_relocation (input_section, howto, contents,
1481 addr, srel);
1482 break;
1484 case R_MMIX_LOCAL:
1485 /* This isn't a real relocation, it's just an assertion that the
1486 final relocation value corresponds to a local register. We
1487 ignore the actual relocation; nothing is changed. */
1489 asection *regsec
1490 = bfd_get_section_by_name (input_section->output_section->owner,
1491 MMIX_REG_CONTENTS_SECTION_NAME);
1492 bfd_vma first_global;
1494 /* Check that this is an absolute value, or a reference to the
1495 register contents section or the register (symbol) section.
1496 Absolute numbers can get here as undefined section. Undefined
1497 symbols are signalled elsewhere, so there's no conflict in us
1498 accidentally handling it. */
1499 if (!bfd_is_abs_section (symsec)
1500 && !bfd_is_und_section (symsec)
1501 && strcmp (bfd_get_section_name (symsec->owner, symsec),
1502 MMIX_REG_CONTENTS_SECTION_NAME) != 0
1503 && strcmp (bfd_get_section_name (symsec->owner, symsec),
1504 MMIX_REG_SECTION_NAME) != 0)
1506 (*_bfd_error_handler)
1507 (_("%s: directive LOCAL valid only with a register or absolute value"),
1508 bfd_get_filename (input_section->owner));
1510 return bfd_reloc_overflow;
1513 /* If we don't have a register contents section, then $255 is the
1514 first global register. */
1515 if (regsec == NULL)
1516 first_global = 255;
1517 else
1519 first_global = bfd_get_section_vma (abfd, regsec) / 8;
1520 if (strcmp (bfd_get_section_name (symsec->owner, symsec),
1521 MMIX_REG_CONTENTS_SECTION_NAME) == 0)
1523 if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
1524 /* The bfd_reloc_outofrange return value, though
1525 intuitively a better value, will not get us an error. */
1526 return bfd_reloc_overflow;
1527 srel /= 8;
1531 if ((bfd_vma) srel >= first_global)
1533 /* FIXME: Better error message. */
1534 (*_bfd_error_handler)
1535 (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."),
1536 bfd_get_filename (input_section->owner), (long) srel, (long) first_global);
1538 return bfd_reloc_overflow;
1541 r = bfd_reloc_ok;
1542 break;
1544 default:
1545 r = _bfd_final_link_relocate (howto, input_section->owner, input_section,
1546 contents, r_offset,
1547 relocation, r_addend);
1550 return r;
1553 /* Return the section that should be marked against GC for a given
1554 relocation. */
1556 static asection *
1557 mmix_elf_gc_mark_hook (sec, info, rel, h, sym)
1558 asection *sec;
1559 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1560 Elf_Internal_Rela *rel;
1561 struct elf_link_hash_entry *h;
1562 Elf_Internal_Sym *sym;
1564 if (h != NULL)
1566 switch (ELF64_R_TYPE (rel->r_info))
1568 case R_MMIX_GNU_VTINHERIT:
1569 case R_MMIX_GNU_VTENTRY:
1570 break;
1572 default:
1573 switch (h->root.type)
1575 case bfd_link_hash_defined:
1576 case bfd_link_hash_defweak:
1577 return h->root.u.def.section;
1579 case bfd_link_hash_common:
1580 return h->root.u.c.p->section;
1582 default:
1583 break;
1587 else
1588 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
1590 return NULL;
1593 /* Update relocation info for a GC-excluded section. We could supposedly
1594 perform the allocation after GC, but there's no suitable hook between
1595 GC (or section merge) and the point when all input sections must be
1596 present. Better to waste some memory and (perhaps) a little time. */
1598 static bfd_boolean
1599 mmix_elf_gc_sweep_hook (abfd, info, sec, relocs)
1600 bfd *abfd ATTRIBUTE_UNUSED;
1601 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1602 asection *sec ATTRIBUTE_UNUSED;
1603 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
1605 struct bpo_reloc_section_info *bpodata
1606 = mmix_elf_section_data (sec)->bpo.reloc;
1607 asection *allocated_gregs_section;
1609 /* If no bpodata here, we have nothing to do. */
1610 if (bpodata == NULL)
1611 return TRUE;
1613 allocated_gregs_section = bpodata->bpo_greg_section;
1615 mmix_elf_section_data (allocated_gregs_section)->bpo.greg->n_bpo_relocs
1616 -= bpodata->n_bpo_relocs_this_section;
1618 return TRUE;
1621 /* Sort register relocs to come before expanding relocs. */
1623 static int
1624 mmix_elf_sort_relocs (p1, p2)
1625 const PTR p1;
1626 const PTR p2;
1628 const Elf_Internal_Rela *r1 = (const Elf_Internal_Rela *) p1;
1629 const Elf_Internal_Rela *r2 = (const Elf_Internal_Rela *) p2;
1630 int r1_is_reg, r2_is_reg;
1632 /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1633 insns. */
1634 if ((r1->r_offset & ~(bfd_vma) 3) > (r2->r_offset & ~(bfd_vma) 3))
1635 return 1;
1636 else if ((r1->r_offset & ~(bfd_vma) 3) < (r2->r_offset & ~(bfd_vma) 3))
1637 return -1;
1639 r1_is_reg
1640 = (ELF64_R_TYPE (r1->r_info) == R_MMIX_REG_OR_BYTE
1641 || ELF64_R_TYPE (r1->r_info) == R_MMIX_REG);
1642 r2_is_reg
1643 = (ELF64_R_TYPE (r2->r_info) == R_MMIX_REG_OR_BYTE
1644 || ELF64_R_TYPE (r2->r_info) == R_MMIX_REG);
1645 if (r1_is_reg != r2_is_reg)
1646 return r2_is_reg - r1_is_reg;
1648 /* Neither or both are register relocs. Then sort on full offset. */
1649 if (r1->r_offset > r2->r_offset)
1650 return 1;
1651 else if (r1->r_offset < r2->r_offset)
1652 return -1;
1653 return 0;
1656 /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
1658 static bfd_boolean
1659 mmix_elf_check_common_relocs (abfd, info, sec, relocs)
1660 bfd *abfd;
1661 struct bfd_link_info *info;
1662 asection *sec;
1663 const Elf_Internal_Rela *relocs;
1665 bfd *bpo_greg_owner = NULL;
1666 asection *allocated_gregs_section = NULL;
1667 struct bpo_greg_section_info *gregdata = NULL;
1668 struct bpo_reloc_section_info *bpodata = NULL;
1669 const Elf_Internal_Rela *rel;
1670 const Elf_Internal_Rela *rel_end;
1672 if (info->relocateable)
1673 return TRUE;
1675 /* We currently have to abuse this COFF-specific member, since there's
1676 no target-machine-dedicated member. There's no alternative outside
1677 the bfd_link_info struct; we can't specialize a hash-table since
1678 they're different between ELF and mmo. */
1679 bpo_greg_owner = (bfd *) info->base_file;
1681 rel_end = relocs + sec->reloc_count;
1682 for (rel = relocs; rel < rel_end; rel++)
1684 switch (ELF64_R_TYPE (rel->r_info))
1686 /* This relocation causes a GREG allocation. We need to count
1687 them, and we need to create a section for them, so we need an
1688 object to fake as the owner of that section. We can't use
1689 the ELF dynobj for this, since the ELF bits assume lots of
1690 DSO-related stuff if that member is non-NULL. */
1691 case R_MMIX_BASE_PLUS_OFFSET:
1692 if (bpo_greg_owner == NULL)
1694 bpo_greg_owner = abfd;
1695 info->base_file = (PTR) bpo_greg_owner;
1698 if (allocated_gregs_section == NULL)
1699 allocated_gregs_section
1700 = bfd_get_section_by_name (bpo_greg_owner,
1701 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
1703 if (allocated_gregs_section == NULL)
1705 allocated_gregs_section
1706 = bfd_make_section (bpo_greg_owner,
1707 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
1708 /* Setting both SEC_ALLOC and SEC_LOAD means the section is
1709 treated like any other section, and we'd get errors for
1710 address overlap with the text section. Let's set none of
1711 those flags, as that is what currently happens for usual
1712 GREG allocations, and that works. */
1713 if (allocated_gregs_section == NULL
1714 || !bfd_set_section_flags (bpo_greg_owner,
1715 allocated_gregs_section,
1716 (SEC_HAS_CONTENTS
1717 | SEC_IN_MEMORY
1718 | SEC_LINKER_CREATED))
1719 || !bfd_set_section_alignment (bpo_greg_owner,
1720 allocated_gregs_section,
1722 return FALSE;
1724 gregdata = (struct bpo_greg_section_info *)
1725 bfd_zalloc (bpo_greg_owner, sizeof (struct bpo_greg_section_info));
1726 if (gregdata == NULL)
1727 return FALSE;
1728 mmix_elf_section_data (allocated_gregs_section)->bpo.greg
1729 = gregdata;
1731 else if (gregdata == NULL)
1732 gregdata
1733 = mmix_elf_section_data (allocated_gregs_section)->bpo.greg;
1735 /* Get ourselves some auxiliary info for the BPO-relocs. */
1736 if (bpodata == NULL)
1738 /* No use doing a separate iteration pass to find the upper
1739 limit - just use the number of relocs. */
1740 bpodata = (struct bpo_reloc_section_info *)
1741 bfd_alloc (bpo_greg_owner,
1742 sizeof (struct bpo_reloc_section_info)
1743 * (sec->reloc_count + 1));
1744 if (bpodata == NULL)
1745 return FALSE;
1746 mmix_elf_section_data (sec)->bpo.reloc = bpodata;
1747 bpodata->first_base_plus_offset_reloc
1748 = bpodata->bpo_index
1749 = gregdata->n_max_bpo_relocs;
1750 bpodata->bpo_greg_section
1751 = allocated_gregs_section;
1752 bpodata->n_bpo_relocs_this_section = 0;
1755 bpodata->n_bpo_relocs_this_section++;
1756 gregdata->n_max_bpo_relocs++;
1758 /* We don't get another chance to set this before GC; we've not
1759 set up set up any hook that runs before GC. */
1760 gregdata->n_bpo_relocs
1761 = gregdata->n_max_bpo_relocs;
1762 break;
1766 return TRUE;
1769 /* Look through the relocs for a section during the first phase. */
1771 static bfd_boolean
1772 mmix_elf_check_relocs (abfd, info, sec, relocs)
1773 bfd *abfd;
1774 struct bfd_link_info *info;
1775 asection *sec;
1776 const Elf_Internal_Rela *relocs;
1778 Elf_Internal_Shdr *symtab_hdr;
1779 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
1780 const Elf_Internal_Rela *rel;
1781 const Elf_Internal_Rela *rel_end;
1783 if (info->relocateable)
1784 return TRUE;
1786 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1787 sym_hashes = elf_sym_hashes (abfd);
1788 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf64_External_Sym);
1789 if (!elf_bad_symtab (abfd))
1790 sym_hashes_end -= symtab_hdr->sh_info;
1792 /* First we sort the relocs so that any register relocs come before
1793 expansion-relocs to the same insn. FIXME: Not done for mmo. */
1794 qsort ((PTR) relocs, sec->reloc_count, sizeof (Elf_Internal_Rela),
1795 mmix_elf_sort_relocs);
1797 /* Do the common part. */
1798 if (!mmix_elf_check_common_relocs (abfd, info, sec, relocs))
1799 return FALSE;
1801 rel_end = relocs + sec->reloc_count;
1802 for (rel = relocs; rel < rel_end; rel++)
1804 struct elf_link_hash_entry *h;
1805 unsigned long r_symndx;
1807 r_symndx = ELF64_R_SYM (rel->r_info);
1808 if (r_symndx < symtab_hdr->sh_info)
1809 h = NULL;
1810 else
1811 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1813 switch (ELF64_R_TYPE (rel->r_info))
1815 /* This relocation describes the C++ object vtable hierarchy.
1816 Reconstruct it for later use during GC. */
1817 case R_MMIX_GNU_VTINHERIT:
1818 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1819 return FALSE;
1820 break;
1822 /* This relocation describes which C++ vtable entries are actually
1823 used. Record for later use during GC. */
1824 case R_MMIX_GNU_VTENTRY:
1825 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1826 return FALSE;
1827 break;
1831 return TRUE;
1834 /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
1835 Copied from elf_link_add_object_symbols. */
1837 bfd_boolean
1838 _bfd_mmix_check_all_relocs (abfd, info)
1839 bfd *abfd;
1840 struct bfd_link_info *info;
1842 asection *o;
1844 for (o = abfd->sections; o != NULL; o = o->next)
1846 Elf_Internal_Rela *internal_relocs;
1847 bfd_boolean ok;
1849 if ((o->flags & SEC_RELOC) == 0
1850 || o->reloc_count == 0
1851 || ((info->strip == strip_all || info->strip == strip_debugger)
1852 && (o->flags & SEC_DEBUGGING) != 0)
1853 || bfd_is_abs_section (o->output_section))
1854 continue;
1856 internal_relocs
1857 = _bfd_elf64_link_read_relocs (abfd, o, (PTR) NULL,
1858 (Elf_Internal_Rela *) NULL,
1859 info->keep_memory);
1860 if (internal_relocs == NULL)
1861 return FALSE;
1863 ok = mmix_elf_check_common_relocs (abfd, info, o, internal_relocs);
1865 if (! info->keep_memory)
1866 free (internal_relocs);
1868 if (! ok)
1869 return FALSE;
1872 return TRUE;
1875 /* Change symbols relative to the reg contents section to instead be to
1876 the register section, and scale them down to correspond to the register
1877 number. */
1879 static bfd_boolean
1880 mmix_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
1881 bfd *abfd ATTRIBUTE_UNUSED;
1882 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1883 const char *name ATTRIBUTE_UNUSED;
1884 Elf_Internal_Sym *sym;
1885 asection *input_sec;
1887 if (input_sec != NULL
1888 && input_sec->name != NULL
1889 && ELF_ST_TYPE (sym->st_info) != STT_SECTION
1890 && strcmp (input_sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
1892 sym->st_value /= 8;
1893 sym->st_shndx = SHN_REGISTER;
1896 return TRUE;
1899 /* We fake a register section that holds values that are register numbers.
1900 Having a SHN_REGISTER and register section translates better to other
1901 formats (e.g. mmo) than for example a STT_REGISTER attribute.
1902 This section faking is based on a construct in elf32-mips.c. */
1903 static asection mmix_elf_reg_section;
1904 static asymbol mmix_elf_reg_section_symbol;
1905 static asymbol *mmix_elf_reg_section_symbol_ptr;
1907 /* Handle the special MIPS section numbers that a symbol may use.
1908 This is used for both the 32-bit and the 64-bit ABI. */
1910 void
1911 mmix_elf_symbol_processing (abfd, asym)
1912 bfd *abfd ATTRIBUTE_UNUSED;
1913 asymbol *asym;
1915 elf_symbol_type *elfsym;
1917 elfsym = (elf_symbol_type *) asym;
1918 switch (elfsym->internal_elf_sym.st_shndx)
1920 case SHN_REGISTER:
1921 if (mmix_elf_reg_section.name == NULL)
1923 /* Initialize the register section. */
1924 mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME;
1925 mmix_elf_reg_section.flags = SEC_NO_FLAGS;
1926 mmix_elf_reg_section.output_section = &mmix_elf_reg_section;
1927 mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol;
1928 mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr;
1929 mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME;
1930 mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM;
1931 mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section;
1932 mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol;
1934 asym->section = &mmix_elf_reg_section;
1935 break;
1937 default:
1938 break;
1942 /* Given a BFD section, try to locate the corresponding ELF section
1943 index. */
1945 static bfd_boolean
1946 mmix_elf_section_from_bfd_section (abfd, sec, retval)
1947 bfd * abfd ATTRIBUTE_UNUSED;
1948 asection * sec;
1949 int * retval;
1951 if (strcmp (bfd_get_section_name (abfd, sec), MMIX_REG_SECTION_NAME) == 0)
1952 *retval = SHN_REGISTER;
1953 else
1954 return FALSE;
1956 return TRUE;
1959 /* Hook called by the linker routine which adds symbols from an object
1960 file. We must handle the special SHN_REGISTER section number here.
1962 We also check that we only have *one* each of the section-start
1963 symbols, since otherwise having two with the same value would cause
1964 them to be "merged", but with the contents serialized. */
1966 bfd_boolean
1967 mmix_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1968 bfd *abfd;
1969 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1970 const Elf_Internal_Sym *sym;
1971 const char **namep ATTRIBUTE_UNUSED;
1972 flagword *flagsp ATTRIBUTE_UNUSED;
1973 asection **secp;
1974 bfd_vma *valp ATTRIBUTE_UNUSED;
1976 if (sym->st_shndx == SHN_REGISTER)
1977 *secp = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
1978 else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.'
1979 && strncmp (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
1980 strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)) == 0)
1982 /* See if we have another one. */
1983 struct bfd_link_hash_entry *h = bfd_link_hash_lookup (info->hash,
1984 *namep,
1985 FALSE,
1986 FALSE,
1987 FALSE);
1989 if (h != NULL && h->type != bfd_link_hash_undefined)
1991 /* How do we get the asymbol (or really: the filename) from h?
1992 h->u.def.section->owner is NULL. */
1993 ((*_bfd_error_handler)
1994 (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
1995 bfd_get_filename (abfd), *namep,
1996 *namep + strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)));
1997 bfd_set_error (bfd_error_bad_value);
1998 return FALSE;
2002 return TRUE;
2005 /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
2007 bfd_boolean
2008 mmix_elf_is_local_label_name (abfd, name)
2009 bfd *abfd;
2010 const char *name;
2012 const char *colpos;
2013 int digits;
2015 /* Also include the default local-label definition. */
2016 if (_bfd_elf_is_local_label_name (abfd, name))
2017 return TRUE;
2019 if (*name != 'L')
2020 return FALSE;
2022 /* If there's no ":", or more than one, it's not a local symbol. */
2023 colpos = strchr (name, ':');
2024 if (colpos == NULL || strchr (colpos + 1, ':') != NULL)
2025 return FALSE;
2027 /* Check that there are remaining characters and that they are digits. */
2028 if (colpos[1] == 0)
2029 return FALSE;
2031 digits = strspn (colpos + 1, "0123456789");
2032 return digits != 0 && colpos[1 + digits] == 0;
2035 /* We get rid of the register section here. */
2037 bfd_boolean
2038 mmix_elf_final_link (abfd, info)
2039 bfd *abfd;
2040 struct bfd_link_info *info;
2042 /* We never output a register section, though we create one for
2043 temporary measures. Check that nobody entered contents into it. */
2044 asection *reg_section;
2045 asection **secpp;
2047 reg_section = bfd_get_section_by_name (abfd, MMIX_REG_SECTION_NAME);
2049 if (reg_section != NULL)
2051 /* FIXME: Pass error state gracefully. */
2052 if (bfd_get_section_flags (abfd, reg_section) & SEC_HAS_CONTENTS)
2053 _bfd_abort (__FILE__, __LINE__, _("Register section has contents\n"));
2055 /* Really remove the section. */
2056 for (secpp = &abfd->sections;
2057 *secpp != reg_section;
2058 secpp = &(*secpp)->next)
2060 bfd_section_list_remove (abfd, secpp);
2061 --abfd->section_count;
2064 if (! bfd_elf64_bfd_final_link (abfd, info))
2065 return FALSE;
2067 /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
2068 the regular linker machinery. We do it here, like other targets with
2069 special sections. */
2070 if (info->base_file != NULL)
2072 asection *greg_section
2073 = bfd_get_section_by_name ((bfd *) info->base_file,
2074 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2075 if (!bfd_set_section_contents (abfd,
2076 greg_section->output_section,
2077 greg_section->contents,
2078 (file_ptr) greg_section->output_offset,
2079 greg_section->_cooked_size))
2080 return FALSE;
2082 return TRUE;
2085 /* Initialize stuff for the linker-generated GREGs to match
2086 R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
2088 bfd_boolean
2089 _bfd_mmix_prepare_linker_allocated_gregs (abfd, info)
2090 bfd *abfd ATTRIBUTE_UNUSED;
2091 struct bfd_link_info *info;
2093 asection *bpo_gregs_section;
2094 bfd *bpo_greg_owner;
2095 struct bpo_greg_section_info *gregdata;
2096 size_t n_gregs;
2097 bfd_vma gregs_size;
2098 size_t i;
2099 size_t *bpo_reloc_indexes;
2101 /* The bpo_greg_owner bfd is supposed to have been set by
2102 mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
2103 If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2104 bpo_greg_owner = (bfd *) info->base_file;
2105 if (bpo_greg_owner == NULL)
2106 return TRUE;
2108 bpo_gregs_section
2109 = bfd_get_section_by_name (bpo_greg_owner,
2110 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2112 if (bpo_gregs_section == NULL)
2113 return TRUE;
2115 /* We use the target-data handle in the ELF section data. */
2116 gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2117 if (gregdata == NULL)
2118 return FALSE;
2120 n_gregs = gregdata->n_bpo_relocs;
2121 gregdata->n_allocated_bpo_gregs = n_gregs;
2123 /* When this reaches zero during relaxation, all entries have been
2124 filled in and the size of the linker gregs can be calculated. */
2125 gregdata->n_remaining_bpo_relocs_this_relaxation_round = n_gregs;
2127 /* Set the zeroth-order estimate for the GREGs size. */
2128 gregs_size = n_gregs * 8;
2130 if (!bfd_set_section_size (bpo_greg_owner, bpo_gregs_section, gregs_size))
2131 return FALSE;
2133 /* Allocate and set up the GREG arrays. They're filled in at relaxation
2134 time. Note that we must use the max number ever noted for the array,
2135 since the index numbers were created before GC. */
2136 gregdata->reloc_request
2137 = bfd_zalloc (bpo_greg_owner,
2138 sizeof (struct bpo_reloc_request)
2139 * gregdata->n_max_bpo_relocs);
2141 gregdata->bpo_reloc_indexes
2142 = bpo_reloc_indexes
2143 = bfd_alloc (bpo_greg_owner,
2144 gregdata->n_max_bpo_relocs
2145 * sizeof (size_t));
2146 if (bpo_reloc_indexes == NULL)
2147 return FALSE;
2149 /* The default order is an identity mapping. */
2150 for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
2152 bpo_reloc_indexes[i] = i;
2153 gregdata->reloc_request[i].bpo_reloc_no = i;
2156 return TRUE;
2159 /* Fill in contents in the linker allocated gregs. Everything is
2160 calculated at this point; we just move the contents into place here. */
2162 bfd_boolean
2163 _bfd_mmix_finalize_linker_allocated_gregs (abfd, link_info)
2164 bfd *abfd ATTRIBUTE_UNUSED;
2165 struct bfd_link_info *link_info;
2167 asection *bpo_gregs_section;
2168 bfd *bpo_greg_owner;
2169 struct bpo_greg_section_info *gregdata;
2170 size_t n_gregs;
2171 size_t i, j;
2172 size_t lastreg;
2173 bfd_byte *contents;
2175 /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
2176 when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
2177 object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2178 bpo_greg_owner = (bfd *) link_info->base_file;
2179 if (bpo_greg_owner == NULL)
2180 return TRUE;
2182 bpo_gregs_section
2183 = bfd_get_section_by_name (bpo_greg_owner,
2184 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2186 /* This can't happen without DSO handling. When DSOs are handled
2187 without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
2188 section. */
2189 if (bpo_gregs_section == NULL)
2190 return TRUE;
2192 /* We use the target-data handle in the ELF section data. */
2194 gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2195 if (gregdata == NULL)
2196 return FALSE;
2198 n_gregs = gregdata->n_allocated_bpo_gregs;
2200 /* We need to have a _raw_size contents even though there's only
2201 _cooked_size worth of data, since the generic relocation machinery
2202 will allocate and copy that much temporarily. */
2203 bpo_gregs_section->contents
2204 = contents = bfd_alloc (bpo_greg_owner, bpo_gregs_section->_raw_size);
2205 if (contents == NULL)
2206 return FALSE;
2208 /* Sanity check: If these numbers mismatch, some relocation has not been
2209 accounted for and the rest of gregdata is probably inconsistent.
2210 It's a bug, but it's more helpful to identify it than segfaulting
2211 below. */
2212 if (gregdata->n_remaining_bpo_relocs_this_relaxation_round
2213 != gregdata->n_bpo_relocs)
2215 (*_bfd_error_handler)
2216 (_("Internal inconsistency: remaining %u != max %u.\n\
2217 Please report this bug."),
2218 gregdata->n_remaining_bpo_relocs_this_relaxation_round,
2219 gregdata->n_bpo_relocs);
2220 return FALSE;
2223 for (lastreg = 255, i = 0, j = 0; j < n_gregs; i++)
2224 if (gregdata->reloc_request[i].regindex != lastreg)
2226 bfd_put_64 (bpo_greg_owner, gregdata->reloc_request[i].value,
2227 contents + j * 8);
2228 lastreg = gregdata->reloc_request[i].regindex;
2229 j++;
2232 return TRUE;
2235 /* Sort valid relocs to come before non-valid relocs, then on increasing
2236 value. */
2238 static int
2239 bpo_reloc_request_sort_fn (p1, p2)
2240 const PTR p1;
2241 const PTR p2;
2243 const struct bpo_reloc_request *r1 = (const struct bpo_reloc_request *) p1;
2244 const struct bpo_reloc_request *r2 = (const struct bpo_reloc_request *) p2;
2246 /* Primary function is validity; non-valid relocs sorted after valid
2247 ones. */
2248 if (r1->valid != r2->valid)
2249 return r2->valid - r1->valid;
2251 /* Then sort on value. Don't simplify and return just the difference of
2252 the values: the upper bits of the 64-bit value would be truncated on
2253 a host with 32-bit ints. */
2254 if (r1->value != r2->value)
2255 return r1->value > r2->value ? 1 : -1;
2257 /* As a last re-sort, use the relocation number, so we get a stable
2258 sort. The *addresses* aren't stable since items are swapped during
2259 sorting. It depends on the qsort implementation if this actually
2260 happens. */
2261 return r1->bpo_reloc_no > r2->bpo_reloc_no
2262 ? 1 : (r1->bpo_reloc_no < r2->bpo_reloc_no ? -1 : 0);
2265 /* For debug use only. Dumps the global register allocations resulting
2266 from base-plus-offset relocs. */
2268 void
2269 mmix_dump_bpo_gregs (link_info, pf)
2270 struct bfd_link_info *link_info;
2271 bfd_error_handler_type pf;
2273 bfd *bpo_greg_owner;
2274 asection *bpo_gregs_section;
2275 struct bpo_greg_section_info *gregdata;
2276 unsigned int i;
2278 if (link_info == NULL || link_info->base_file == NULL)
2279 return;
2281 bpo_greg_owner = (bfd *) link_info->base_file;
2283 bpo_gregs_section
2284 = bfd_get_section_by_name (bpo_greg_owner,
2285 MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2287 if (bpo_gregs_section == NULL)
2288 return;
2290 gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2291 if (gregdata == NULL)
2292 return;
2294 if (pf == NULL)
2295 pf = _bfd_error_handler;
2297 /* These format strings are not translated. They are for debug purposes
2298 only and never displayed to an end user. Should they escape, we
2299 surely want them in original. */
2300 (*pf) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
2301 n_allocated_bpo_gregs: %u\n", gregdata->n_bpo_relocs,
2302 gregdata->n_max_bpo_relocs,
2303 gregdata->n_remaining_bpo_relocs_this_relaxation_round,
2304 gregdata->n_allocated_bpo_gregs);
2306 if (gregdata->reloc_request)
2307 for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
2308 (*pf) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
2310 (gregdata->bpo_reloc_indexes != NULL
2311 ? gregdata->bpo_reloc_indexes[i] : (size_t) -1),
2312 gregdata->reloc_request[i].bpo_reloc_no,
2313 gregdata->reloc_request[i].valid,
2315 (unsigned long) (gregdata->reloc_request[i].value >> 32),
2316 (unsigned long) gregdata->reloc_request[i].value,
2317 gregdata->reloc_request[i].regindex,
2318 gregdata->reloc_request[i].offset);
2321 /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
2322 when the last such reloc is done, an index-array is sorted according to
2323 the values and iterated over to produce register numbers (indexed by 0
2324 from the first allocated register number) and offsets for use in real
2325 relocation.
2327 Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
2329 static bfd_boolean
2330 mmix_elf_relax_section (abfd, sec, link_info, again)
2331 bfd *abfd;
2332 asection *sec;
2333 struct bfd_link_info *link_info;
2334 bfd_boolean *again;
2336 Elf_Internal_Shdr *symtab_hdr;
2337 Elf_Internal_Rela *internal_relocs;
2338 Elf_Internal_Rela *irel, *irelend;
2339 asection *bpo_gregs_section = NULL;
2340 struct bpo_greg_section_info *gregdata;
2341 struct bpo_reloc_section_info *bpodata
2342 = mmix_elf_section_data (sec)->bpo.reloc;
2343 size_t bpono;
2344 bfd *bpo_greg_owner;
2345 Elf_Internal_Sym *isymbuf = NULL;
2347 /* Assume nothing changes. */
2348 *again = FALSE;
2350 /* If this is the first time we have been called for this section,
2351 initialize the cooked size. */
2352 if (sec->_cooked_size == 0)
2353 sec->_cooked_size = sec->_raw_size;
2355 /* We don't have to do anything for a relocateable link, if
2356 this section does not have relocs, or if this is not a
2357 code section. */
2358 if (link_info->relocateable
2359 || (sec->flags & SEC_RELOC) == 0
2360 || sec->reloc_count == 0
2361 || (sec->flags & SEC_CODE) == 0
2362 || (sec->flags & SEC_LINKER_CREATED) != 0
2363 /* If no R_MMIX_BASE_PLUS_OFFSET relocs, then nothing to do. */
2364 || bpodata == NULL)
2365 return TRUE;
2367 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2369 bpo_greg_owner = (bfd *) link_info->base_file;
2370 bpo_gregs_section = bpodata->bpo_greg_section;
2371 gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2373 bpono = bpodata->first_base_plus_offset_reloc;
2375 /* Get a copy of the native relocations. */
2376 internal_relocs
2377 = _bfd_elf64_link_read_relocs (abfd, sec, (PTR) NULL,
2378 (Elf_Internal_Rela *) NULL,
2379 link_info->keep_memory);
2380 if (internal_relocs == NULL)
2381 goto error_return;
2383 /* Walk through them looking for relaxing opportunities. */
2384 irelend = internal_relocs + sec->reloc_count;
2385 for (irel = internal_relocs; irel < irelend; irel++)
2387 bfd_vma symval;
2389 if (ELF64_R_TYPE (irel->r_info) != (int) R_MMIX_BASE_PLUS_OFFSET)
2390 continue;
2392 /* Get the value of the symbol referred to by the reloc. */
2393 if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2395 /* A local symbol. */
2396 Elf_Internal_Sym *isym;
2397 asection *sym_sec;
2399 /* Read this BFD's local symbols if we haven't already. */
2400 if (isymbuf == NULL)
2402 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2403 if (isymbuf == NULL)
2404 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2405 symtab_hdr->sh_info, 0,
2406 NULL, NULL, NULL);
2407 if (isymbuf == 0)
2408 goto error_return;
2411 isym = isymbuf + ELF64_R_SYM (irel->r_info);
2412 if (isym->st_shndx == SHN_UNDEF)
2413 sym_sec = bfd_und_section_ptr;
2414 else if (isym->st_shndx == SHN_ABS)
2415 sym_sec = bfd_abs_section_ptr;
2416 else if (isym->st_shndx == SHN_COMMON)
2417 sym_sec = bfd_com_section_ptr;
2418 else
2419 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2420 symval = (isym->st_value
2421 + sym_sec->output_section->vma
2422 + sym_sec->output_offset);
2424 else
2426 unsigned long indx;
2427 struct elf_link_hash_entry *h;
2429 /* An external symbol. */
2430 indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2431 h = elf_sym_hashes (abfd)[indx];
2432 BFD_ASSERT (h != NULL);
2433 if (h->root.type != bfd_link_hash_defined
2434 && h->root.type != bfd_link_hash_defweak)
2436 /* This appears to be a reference to an undefined symbol.
2437 Just ignore it--it will be caught by the regular reloc
2438 processing. We need to keep BPO reloc accounting
2439 consistent, though. */
2440 gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
2441 bpono++;
2442 continue;
2445 symval = (h->root.u.def.value
2446 + h->root.u.def.section->output_section->vma
2447 + h->root.u.def.section->output_offset);
2450 gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono]].value
2451 = symval + irel->r_addend;
2452 gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono++]].valid = TRUE;
2453 gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
2456 /* Check if that was the last BPO-reloc. If so, sort the values and
2457 calculate how many registers we need to cover them. Set the size of
2458 the linker gregs, and if the number of registers changed, indicate
2459 that we need to relax some more because we have more work to do. */
2460 if (gregdata->n_remaining_bpo_relocs_this_relaxation_round == 0)
2462 size_t i;
2463 bfd_vma prev_base;
2464 size_t regindex;
2466 /* First, reset the remaining relocs for the next round. */
2467 gregdata->n_remaining_bpo_relocs_this_relaxation_round
2468 = gregdata->n_bpo_relocs;
2470 qsort ((PTR) gregdata->reloc_request,
2471 gregdata->n_max_bpo_relocs,
2472 sizeof (struct bpo_reloc_request),
2473 bpo_reloc_request_sort_fn);
2475 /* Recalculate indexes. When we find a change (however unlikely
2476 after the initial iteration), we know we need to relax again,
2477 since items in the GREG-array are sorted by increasing value and
2478 stored in the relaxation phase. */
2479 for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
2480 if (gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
2481 != i)
2483 gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
2484 = i;
2485 *again = TRUE;
2488 /* Allocate register numbers (indexing from 0). Stop at the first
2489 non-valid reloc. */
2490 for (i = 0, regindex = 0, prev_base = gregdata->reloc_request[0].value;
2491 i < gregdata->n_bpo_relocs;
2492 i++)
2494 if (gregdata->reloc_request[i].value > prev_base + 255)
2496 regindex++;
2497 prev_base = gregdata->reloc_request[i].value;
2499 gregdata->reloc_request[i].regindex = regindex;
2500 gregdata->reloc_request[i].offset
2501 = gregdata->reloc_request[i].value - prev_base;
2504 /* If it's not the same as the last time, we need to relax again,
2505 because the size of the section has changed. I'm not sure we
2506 actually need to do any adjustments since the shrinking happens
2507 at the start of this section, but better safe than sorry. */
2508 if (gregdata->n_allocated_bpo_gregs != regindex + 1)
2510 gregdata->n_allocated_bpo_gregs = regindex + 1;
2511 *again = TRUE;
2514 bpo_gregs_section->_cooked_size = (regindex + 1) * 8;
2517 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
2519 if (! link_info->keep_memory)
2520 free (isymbuf);
2521 else
2523 /* Cache the symbols for elf_link_input_bfd. */
2524 symtab_hdr->contents = (unsigned char *) isymbuf;
2528 if (internal_relocs != NULL
2529 && elf_section_data (sec)->relocs != internal_relocs)
2530 free (internal_relocs);
2532 return TRUE;
2534 error_return:
2535 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
2536 free (isymbuf);
2537 if (internal_relocs != NULL
2538 && elf_section_data (sec)->relocs != internal_relocs)
2539 free (internal_relocs);
2540 return FALSE;
2543 #define ELF_ARCH bfd_arch_mmix
2544 #define ELF_MACHINE_CODE EM_MMIX
2546 /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
2547 However, that's too much for something somewhere in the linker part of
2548 BFD; perhaps the start-address has to be a non-zero multiple of this
2549 number, or larger than this number. The symptom is that the linker
2550 complains: "warning: allocated section `.text' not in segment". We
2551 settle for 64k; the page-size used in examples is 8k.
2552 #define ELF_MAXPAGESIZE 0x10000
2554 Unfortunately, this causes excessive padding in the supposedly small
2555 for-education programs that are the expected usage (where people would
2556 inspect output). We stick to 256 bytes just to have *some* default
2557 alignment. */
2558 #define ELF_MAXPAGESIZE 0x100
2560 #define TARGET_BIG_SYM bfd_elf64_mmix_vec
2561 #define TARGET_BIG_NAME "elf64-mmix"
2563 #define elf_info_to_howto_rel NULL
2564 #define elf_info_to_howto mmix_info_to_howto_rela
2565 #define elf_backend_relocate_section mmix_elf_relocate_section
2566 #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
2567 #define elf_backend_gc_sweep_hook mmix_elf_gc_sweep_hook
2569 #define elf_backend_link_output_symbol_hook \
2570 mmix_elf_link_output_symbol_hook
2571 #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
2573 #define elf_backend_check_relocs mmix_elf_check_relocs
2574 #define elf_backend_symbol_processing mmix_elf_symbol_processing
2576 #define bfd_elf64_bfd_is_local_label_name \
2577 mmix_elf_is_local_label_name
2579 #define elf_backend_may_use_rel_p 0
2580 #define elf_backend_may_use_rela_p 1
2581 #define elf_backend_default_use_rela_p 1
2583 #define elf_backend_can_gc_sections 1
2584 #define elf_backend_section_from_bfd_section \
2585 mmix_elf_section_from_bfd_section
2587 #define bfd_elf64_new_section_hook mmix_elf_new_section_hook
2588 #define bfd_elf64_bfd_final_link mmix_elf_final_link
2589 #define bfd_elf64_bfd_relax_section mmix_elf_relax_section
2591 #include "elf64-target.h"