1a1ba9ba4Schristos /* MMIX-specific support for 64-bit ELF.
2*184b2d41Schristos Copyright (C) 2001-2020 Free Software Foundation, Inc.
3a1ba9ba4Schristos Contributed by Hans-Peter Nilsson <hp@bitrange.com>
4a1ba9ba4Schristos
5a1ba9ba4Schristos This file is part of BFD, the Binary File Descriptor library.
6a1ba9ba4Schristos
7a1ba9ba4Schristos This program is free software; you can redistribute it and/or modify
8a1ba9ba4Schristos it under the terms of the GNU General Public License as published by
9a1ba9ba4Schristos the Free Software Foundation; either version 3 of the License, or
10a1ba9ba4Schristos (at your option) any later version.
11a1ba9ba4Schristos
12a1ba9ba4Schristos This program is distributed in the hope that it will be useful,
13a1ba9ba4Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
14a1ba9ba4Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15a1ba9ba4Schristos GNU General Public License for more details.
16a1ba9ba4Schristos
17a1ba9ba4Schristos You should have received a copy of the GNU General Public License
18a1ba9ba4Schristos along with this program; if not, write to the Free Software
19a1ba9ba4Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20a1ba9ba4Schristos MA 02110-1301, USA. */
21a1ba9ba4Schristos
22a1ba9ba4Schristos
23a1ba9ba4Schristos /* No specific ABI or "processor-specific supplement" defined. */
24a1ba9ba4Schristos
25a1ba9ba4Schristos /* TODO:
26a1ba9ba4Schristos - "Traditional" linker relaxation (shrinking whole sections).
27a1ba9ba4Schristos - Merge reloc stubs jumping to same location.
28a1ba9ba4Schristos - GETA stub relaxation (call a stub for out of range new
29a1ba9ba4Schristos R_MMIX_GETA_STUBBABLE). */
30a1ba9ba4Schristos
31a1ba9ba4Schristos #include "sysdep.h"
32a1ba9ba4Schristos #include "bfd.h"
33a1ba9ba4Schristos #include "libbfd.h"
34a1ba9ba4Schristos #include "elf-bfd.h"
35a1ba9ba4Schristos #include "elf/mmix.h"
36a1ba9ba4Schristos #include "opcode/mmix.h"
37a1ba9ba4Schristos
38a1ba9ba4Schristos #define MINUS_ONE (((bfd_vma) 0) - 1)
39a1ba9ba4Schristos
40a1ba9ba4Schristos #define MAX_PUSHJ_STUB_SIZE (5 * 4)
41a1ba9ba4Schristos
42a1ba9ba4Schristos /* Put these everywhere in new code. */
43a1ba9ba4Schristos #define FATAL_DEBUG \
44a1ba9ba4Schristos _bfd_abort (__FILE__, __LINE__, \
45a1ba9ba4Schristos "Internal: Non-debugged code (test-case missing)")
46a1ba9ba4Schristos
47a1ba9ba4Schristos #define BAD_CASE(x) \
48a1ba9ba4Schristos _bfd_abort (__FILE__, __LINE__, \
49a1ba9ba4Schristos "bad case for " #x)
50a1ba9ba4Schristos
51a1ba9ba4Schristos struct _mmix_elf_section_data
52a1ba9ba4Schristos {
53a1ba9ba4Schristos struct bfd_elf_section_data elf;
54a1ba9ba4Schristos union
55a1ba9ba4Schristos {
56a1ba9ba4Schristos struct bpo_reloc_section_info *reloc;
57a1ba9ba4Schristos struct bpo_greg_section_info *greg;
58a1ba9ba4Schristos } bpo;
59a1ba9ba4Schristos
60a1ba9ba4Schristos struct pushj_stub_info
61a1ba9ba4Schristos {
62a1ba9ba4Schristos /* Maximum number of stubs needed for this section. */
63a1ba9ba4Schristos bfd_size_type n_pushj_relocs;
64a1ba9ba4Schristos
65a1ba9ba4Schristos /* Size of stubs after a mmix_elf_relax_section round. */
66a1ba9ba4Schristos bfd_size_type stubs_size_sum;
67a1ba9ba4Schristos
68a1ba9ba4Schristos /* Per-reloc stubs_size_sum information. The stubs_size_sum member is the sum
69a1ba9ba4Schristos of these. Allocated in mmix_elf_check_common_relocs. */
70a1ba9ba4Schristos bfd_size_type *stub_size;
71a1ba9ba4Schristos
72a1ba9ba4Schristos /* Offset of next stub during relocation. Somewhat redundant with the
73a1ba9ba4Schristos above: error coverage is easier and we don't have to reset the
74a1ba9ba4Schristos stubs_size_sum for relocation. */
75a1ba9ba4Schristos bfd_size_type stub_offset;
76a1ba9ba4Schristos } pjs;
77a1ba9ba4Schristos
78a1ba9ba4Schristos /* Whether there has been a warning that this section could not be
79a1ba9ba4Schristos linked due to a specific cause. FIXME: a way to access the
80a1ba9ba4Schristos linker info or output section, then stuff the limiter guard
81a1ba9ba4Schristos there. */
82a1ba9ba4Schristos bfd_boolean has_warned_bpo;
83a1ba9ba4Schristos bfd_boolean has_warned_pushj;
84a1ba9ba4Schristos };
85a1ba9ba4Schristos
86a1ba9ba4Schristos #define mmix_elf_section_data(sec) \
87a1ba9ba4Schristos ((struct _mmix_elf_section_data *) elf_section_data (sec))
88a1ba9ba4Schristos
89a1ba9ba4Schristos /* For each section containing a base-plus-offset (BPO) reloc, we attach
90a1ba9ba4Schristos this struct as mmix_elf_section_data (section)->bpo, which is otherwise
91a1ba9ba4Schristos NULL. */
92a1ba9ba4Schristos struct bpo_reloc_section_info
93a1ba9ba4Schristos {
94a1ba9ba4Schristos /* The base is 1; this is the first number in this section. */
95a1ba9ba4Schristos size_t first_base_plus_offset_reloc;
96a1ba9ba4Schristos
97a1ba9ba4Schristos /* Number of BPO-relocs in this section. */
98a1ba9ba4Schristos size_t n_bpo_relocs_this_section;
99a1ba9ba4Schristos
100a1ba9ba4Schristos /* Running index, used at relocation time. */
101a1ba9ba4Schristos size_t bpo_index;
102a1ba9ba4Schristos
103a1ba9ba4Schristos /* We don't have access to the bfd_link_info struct in
104a1ba9ba4Schristos mmix_final_link_relocate. What we really want to get at is the
105a1ba9ba4Schristos global single struct greg_relocation, so we stash it here. */
106a1ba9ba4Schristos asection *bpo_greg_section;
107a1ba9ba4Schristos };
108a1ba9ba4Schristos
109a1ba9ba4Schristos /* Helper struct (in global context) for the one below.
110a1ba9ba4Schristos There's one of these created for every BPO reloc. */
111a1ba9ba4Schristos struct bpo_reloc_request
112a1ba9ba4Schristos {
113a1ba9ba4Schristos bfd_vma value;
114a1ba9ba4Schristos
115a1ba9ba4Schristos /* Valid after relaxation. The base is 0; the first register number
116a1ba9ba4Schristos must be added. The offset is in range 0..255. */
117a1ba9ba4Schristos size_t regindex;
118a1ba9ba4Schristos size_t offset;
119a1ba9ba4Schristos
120a1ba9ba4Schristos /* The order number for this BPO reloc, corresponding to the order in
121a1ba9ba4Schristos which BPO relocs were found. Used to create an index after reloc
122a1ba9ba4Schristos requests are sorted. */
123a1ba9ba4Schristos size_t bpo_reloc_no;
124a1ba9ba4Schristos
125a1ba9ba4Schristos /* Set when the value is computed. Better than coding "guard values"
126a1ba9ba4Schristos into the other members. Is FALSE only for BPO relocs in a GC:ed
127a1ba9ba4Schristos section. */
128a1ba9ba4Schristos bfd_boolean valid;
129a1ba9ba4Schristos };
130a1ba9ba4Schristos
131a1ba9ba4Schristos /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
132a1ba9ba4Schristos greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
133a1ba9ba4Schristos which is linked into the register contents section
134a1ba9ba4Schristos (MMIX_REG_CONTENTS_SECTION_NAME). This section is created by the
135a1ba9ba4Schristos linker; using the same hook as for usual with BPO relocs does not
136a1ba9ba4Schristos collide. */
137a1ba9ba4Schristos struct bpo_greg_section_info
138a1ba9ba4Schristos {
139a1ba9ba4Schristos /* After GC, this reflects the number of remaining, non-excluded
140a1ba9ba4Schristos BPO-relocs. */
141a1ba9ba4Schristos size_t n_bpo_relocs;
142a1ba9ba4Schristos
143a1ba9ba4Schristos /* This is the number of allocated bpo_reloc_requests; the size of
144a1ba9ba4Schristos sorted_indexes. Valid after the check.*relocs functions are called
145a1ba9ba4Schristos for all incoming sections. It includes the number of BPO relocs in
146a1ba9ba4Schristos sections that were GC:ed. */
147a1ba9ba4Schristos size_t n_max_bpo_relocs;
148a1ba9ba4Schristos
149a1ba9ba4Schristos /* A counter used to find out when to fold the BPO gregs, since we
150a1ba9ba4Schristos don't have a single "after-relaxation" hook. */
151a1ba9ba4Schristos size_t n_remaining_bpo_relocs_this_relaxation_round;
152a1ba9ba4Schristos
153a1ba9ba4Schristos /* The number of linker-allocated GREGs resulting from BPO relocs.
154a1ba9ba4Schristos This is an approximation after _bfd_mmix_before_linker_allocation
155a1ba9ba4Schristos and supposedly accurate after mmix_elf_relax_section is called for
156a1ba9ba4Schristos all incoming non-collected sections. */
157a1ba9ba4Schristos size_t n_allocated_bpo_gregs;
158a1ba9ba4Schristos
159a1ba9ba4Schristos /* Index into reloc_request[], sorted on increasing "value", secondary
160a1ba9ba4Schristos by increasing index for strict sorting order. */
161a1ba9ba4Schristos size_t *bpo_reloc_indexes;
162a1ba9ba4Schristos
163a1ba9ba4Schristos /* An array of all relocations, with the "value" member filled in by
164a1ba9ba4Schristos the relaxation function. */
165a1ba9ba4Schristos struct bpo_reloc_request *reloc_request;
166a1ba9ba4Schristos };
167a1ba9ba4Schristos
168a1ba9ba4Schristos
169a1ba9ba4Schristos extern bfd_boolean mmix_elf_final_link (bfd *, struct bfd_link_info *);
170a1ba9ba4Schristos
171a1ba9ba4Schristos extern void mmix_elf_symbol_processing (bfd *, asymbol *);
172a1ba9ba4Schristos
173a1ba9ba4Schristos /* Only intended to be called from a debugger. */
174a1ba9ba4Schristos extern void mmix_dump_bpo_gregs
17515d8e94aSchristos (struct bfd_link_info *, void (*) (const char *, ...));
176a1ba9ba4Schristos
177a1ba9ba4Schristos static void
178a1ba9ba4Schristos mmix_set_relaxable_size (bfd *, asection *, void *);
179a1ba9ba4Schristos static bfd_reloc_status_type
180a1ba9ba4Schristos mmix_elf_reloc (bfd *, arelent *, asymbol *, void *,
181a1ba9ba4Schristos asection *, bfd *, char **);
182a1ba9ba4Schristos static bfd_reloc_status_type
183a1ba9ba4Schristos mmix_final_link_relocate (reloc_howto_type *, asection *, bfd_byte *, bfd_vma,
184a1ba9ba4Schristos bfd_signed_vma, bfd_vma, const char *, asection *,
185a1ba9ba4Schristos char **);
186a1ba9ba4Schristos
187a1ba9ba4Schristos
188a1ba9ba4Schristos /* Watch out: this currently needs to have elements with the same index as
189a1ba9ba4Schristos their R_MMIX_ number. */
190a1ba9ba4Schristos static reloc_howto_type elf_mmix_howto_table[] =
191a1ba9ba4Schristos {
192a1ba9ba4Schristos /* This reloc does nothing. */
193a1ba9ba4Schristos HOWTO (R_MMIX_NONE, /* type */
194a1ba9ba4Schristos 0, /* rightshift */
195a1ba9ba4Schristos 3, /* size (0 = byte, 1 = short, 2 = long) */
196a1ba9ba4Schristos 0, /* bitsize */
197a1ba9ba4Schristos FALSE, /* pc_relative */
198a1ba9ba4Schristos 0, /* bitpos */
199a1ba9ba4Schristos complain_overflow_dont, /* complain_on_overflow */
200a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
201a1ba9ba4Schristos "R_MMIX_NONE", /* name */
202a1ba9ba4Schristos FALSE, /* partial_inplace */
203a1ba9ba4Schristos 0, /* src_mask */
204a1ba9ba4Schristos 0, /* dst_mask */
205a1ba9ba4Schristos FALSE), /* pcrel_offset */
206a1ba9ba4Schristos
207a1ba9ba4Schristos /* An 8 bit absolute relocation. */
208a1ba9ba4Schristos HOWTO (R_MMIX_8, /* type */
209a1ba9ba4Schristos 0, /* rightshift */
210a1ba9ba4Schristos 0, /* size (0 = byte, 1 = short, 2 = long) */
211a1ba9ba4Schristos 8, /* bitsize */
212a1ba9ba4Schristos FALSE, /* pc_relative */
213a1ba9ba4Schristos 0, /* bitpos */
214a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
215a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
216a1ba9ba4Schristos "R_MMIX_8", /* name */
217a1ba9ba4Schristos FALSE, /* partial_inplace */
218a1ba9ba4Schristos 0, /* src_mask */
219a1ba9ba4Schristos 0xff, /* dst_mask */
220a1ba9ba4Schristos FALSE), /* pcrel_offset */
221a1ba9ba4Schristos
222a1ba9ba4Schristos /* An 16 bit absolute relocation. */
223a1ba9ba4Schristos HOWTO (R_MMIX_16, /* type */
224a1ba9ba4Schristos 0, /* rightshift */
225a1ba9ba4Schristos 1, /* size (0 = byte, 1 = short, 2 = long) */
226a1ba9ba4Schristos 16, /* bitsize */
227a1ba9ba4Schristos FALSE, /* pc_relative */
228a1ba9ba4Schristos 0, /* bitpos */
229a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
230a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
231a1ba9ba4Schristos "R_MMIX_16", /* name */
232a1ba9ba4Schristos FALSE, /* partial_inplace */
233a1ba9ba4Schristos 0, /* src_mask */
234a1ba9ba4Schristos 0xffff, /* dst_mask */
235a1ba9ba4Schristos FALSE), /* pcrel_offset */
236a1ba9ba4Schristos
237a1ba9ba4Schristos /* An 24 bit absolute relocation. */
238a1ba9ba4Schristos HOWTO (R_MMIX_24, /* type */
239a1ba9ba4Schristos 0, /* rightshift */
240a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
241a1ba9ba4Schristos 24, /* bitsize */
242a1ba9ba4Schristos FALSE, /* pc_relative */
243a1ba9ba4Schristos 0, /* bitpos */
244a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
245a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
246a1ba9ba4Schristos "R_MMIX_24", /* name */
247a1ba9ba4Schristos FALSE, /* partial_inplace */
248a1ba9ba4Schristos ~0xffffff, /* src_mask */
249a1ba9ba4Schristos 0xffffff, /* dst_mask */
250a1ba9ba4Schristos FALSE), /* pcrel_offset */
251a1ba9ba4Schristos
252a1ba9ba4Schristos /* A 32 bit absolute relocation. */
253a1ba9ba4Schristos HOWTO (R_MMIX_32, /* type */
254a1ba9ba4Schristos 0, /* rightshift */
255a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
256a1ba9ba4Schristos 32, /* bitsize */
257a1ba9ba4Schristos FALSE, /* pc_relative */
258a1ba9ba4Schristos 0, /* bitpos */
259a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
260a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
261a1ba9ba4Schristos "R_MMIX_32", /* name */
262a1ba9ba4Schristos FALSE, /* partial_inplace */
263a1ba9ba4Schristos 0, /* src_mask */
264a1ba9ba4Schristos 0xffffffff, /* dst_mask */
265a1ba9ba4Schristos FALSE), /* pcrel_offset */
266a1ba9ba4Schristos
267a1ba9ba4Schristos /* 64 bit relocation. */
268a1ba9ba4Schristos HOWTO (R_MMIX_64, /* type */
269a1ba9ba4Schristos 0, /* rightshift */
270a1ba9ba4Schristos 4, /* size (0 = byte, 1 = short, 2 = long) */
271a1ba9ba4Schristos 64, /* bitsize */
272a1ba9ba4Schristos FALSE, /* pc_relative */
273a1ba9ba4Schristos 0, /* bitpos */
274a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
275a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
276a1ba9ba4Schristos "R_MMIX_64", /* name */
277a1ba9ba4Schristos FALSE, /* partial_inplace */
278a1ba9ba4Schristos 0, /* src_mask */
279a1ba9ba4Schristos MINUS_ONE, /* dst_mask */
280a1ba9ba4Schristos FALSE), /* pcrel_offset */
281a1ba9ba4Schristos
282a1ba9ba4Schristos /* An 8 bit PC-relative relocation. */
283a1ba9ba4Schristos HOWTO (R_MMIX_PC_8, /* type */
284a1ba9ba4Schristos 0, /* rightshift */
285a1ba9ba4Schristos 0, /* size (0 = byte, 1 = short, 2 = long) */
286a1ba9ba4Schristos 8, /* bitsize */
287a1ba9ba4Schristos TRUE, /* pc_relative */
288a1ba9ba4Schristos 0, /* bitpos */
289a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
290a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
291a1ba9ba4Schristos "R_MMIX_PC_8", /* name */
292a1ba9ba4Schristos FALSE, /* partial_inplace */
293a1ba9ba4Schristos 0, /* src_mask */
294a1ba9ba4Schristos 0xff, /* dst_mask */
295a1ba9ba4Schristos TRUE), /* pcrel_offset */
296a1ba9ba4Schristos
297a1ba9ba4Schristos /* An 16 bit PC-relative relocation. */
298a1ba9ba4Schristos HOWTO (R_MMIX_PC_16, /* type */
299a1ba9ba4Schristos 0, /* rightshift */
300a1ba9ba4Schristos 1, /* size (0 = byte, 1 = short, 2 = long) */
301a1ba9ba4Schristos 16, /* bitsize */
302a1ba9ba4Schristos TRUE, /* pc_relative */
303a1ba9ba4Schristos 0, /* bitpos */
304a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
305a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
306a1ba9ba4Schristos "R_MMIX_PC_16", /* name */
307a1ba9ba4Schristos FALSE, /* partial_inplace */
308a1ba9ba4Schristos 0, /* src_mask */
309a1ba9ba4Schristos 0xffff, /* dst_mask */
310a1ba9ba4Schristos TRUE), /* pcrel_offset */
311a1ba9ba4Schristos
312a1ba9ba4Schristos /* An 24 bit PC-relative relocation. */
313a1ba9ba4Schristos HOWTO (R_MMIX_PC_24, /* type */
314a1ba9ba4Schristos 0, /* rightshift */
315a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
316a1ba9ba4Schristos 24, /* bitsize */
317a1ba9ba4Schristos TRUE, /* pc_relative */
318a1ba9ba4Schristos 0, /* bitpos */
319a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
320a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
321a1ba9ba4Schristos "R_MMIX_PC_24", /* name */
322a1ba9ba4Schristos FALSE, /* partial_inplace */
323a1ba9ba4Schristos ~0xffffff, /* src_mask */
324a1ba9ba4Schristos 0xffffff, /* dst_mask */
325a1ba9ba4Schristos TRUE), /* pcrel_offset */
326a1ba9ba4Schristos
327a1ba9ba4Schristos /* A 32 bit absolute PC-relative relocation. */
328a1ba9ba4Schristos HOWTO (R_MMIX_PC_32, /* type */
329a1ba9ba4Schristos 0, /* rightshift */
330a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
331a1ba9ba4Schristos 32, /* bitsize */
332a1ba9ba4Schristos TRUE, /* pc_relative */
333a1ba9ba4Schristos 0, /* bitpos */
334a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
335a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
336a1ba9ba4Schristos "R_MMIX_PC_32", /* name */
337a1ba9ba4Schristos FALSE, /* partial_inplace */
338a1ba9ba4Schristos 0, /* src_mask */
339a1ba9ba4Schristos 0xffffffff, /* dst_mask */
340a1ba9ba4Schristos TRUE), /* pcrel_offset */
341a1ba9ba4Schristos
342a1ba9ba4Schristos /* 64 bit PC-relative relocation. */
343a1ba9ba4Schristos HOWTO (R_MMIX_PC_64, /* type */
344a1ba9ba4Schristos 0, /* rightshift */
345a1ba9ba4Schristos 4, /* size (0 = byte, 1 = short, 2 = long) */
346a1ba9ba4Schristos 64, /* bitsize */
347a1ba9ba4Schristos TRUE, /* pc_relative */
348a1ba9ba4Schristos 0, /* bitpos */
349a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
350a1ba9ba4Schristos bfd_elf_generic_reloc, /* special_function */
351a1ba9ba4Schristos "R_MMIX_PC_64", /* name */
352a1ba9ba4Schristos FALSE, /* partial_inplace */
353a1ba9ba4Schristos 0, /* src_mask */
354a1ba9ba4Schristos MINUS_ONE, /* dst_mask */
355a1ba9ba4Schristos TRUE), /* pcrel_offset */
356a1ba9ba4Schristos
357a1ba9ba4Schristos /* GNU extension to record C++ vtable hierarchy. */
358a1ba9ba4Schristos HOWTO (R_MMIX_GNU_VTINHERIT, /* type */
359a1ba9ba4Schristos 0, /* rightshift */
360a1ba9ba4Schristos 0, /* size (0 = byte, 1 = short, 2 = long) */
361a1ba9ba4Schristos 0, /* bitsize */
362a1ba9ba4Schristos FALSE, /* pc_relative */
363a1ba9ba4Schristos 0, /* bitpos */
364a1ba9ba4Schristos complain_overflow_dont, /* complain_on_overflow */
365a1ba9ba4Schristos NULL, /* special_function */
366a1ba9ba4Schristos "R_MMIX_GNU_VTINHERIT", /* name */
367a1ba9ba4Schristos FALSE, /* partial_inplace */
368a1ba9ba4Schristos 0, /* src_mask */
369a1ba9ba4Schristos 0, /* dst_mask */
370a1ba9ba4Schristos TRUE), /* pcrel_offset */
371a1ba9ba4Schristos
372a1ba9ba4Schristos /* GNU extension to record C++ vtable member usage. */
373a1ba9ba4Schristos HOWTO (R_MMIX_GNU_VTENTRY, /* type */
374a1ba9ba4Schristos 0, /* rightshift */
375a1ba9ba4Schristos 0, /* size (0 = byte, 1 = short, 2 = long) */
376a1ba9ba4Schristos 0, /* bitsize */
377a1ba9ba4Schristos FALSE, /* pc_relative */
378a1ba9ba4Schristos 0, /* bitpos */
379a1ba9ba4Schristos complain_overflow_dont, /* complain_on_overflow */
380a1ba9ba4Schristos _bfd_elf_rel_vtable_reloc_fn, /* special_function */
381a1ba9ba4Schristos "R_MMIX_GNU_VTENTRY", /* name */
382a1ba9ba4Schristos FALSE, /* partial_inplace */
383a1ba9ba4Schristos 0, /* src_mask */
384a1ba9ba4Schristos 0, /* dst_mask */
385a1ba9ba4Schristos FALSE), /* pcrel_offset */
386a1ba9ba4Schristos
387a1ba9ba4Schristos /* The GETA relocation is supposed to get any address that could
388a1ba9ba4Schristos possibly be reached by the GETA instruction. It can silently expand
389a1ba9ba4Schristos to get a 64-bit operand, but will complain if any of the two least
390a1ba9ba4Schristos significant bits are set. The howto members reflect a simple GETA. */
391a1ba9ba4Schristos HOWTO (R_MMIX_GETA, /* type */
392a1ba9ba4Schristos 2, /* rightshift */
393a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
394a1ba9ba4Schristos 19, /* bitsize */
395a1ba9ba4Schristos TRUE, /* pc_relative */
396a1ba9ba4Schristos 0, /* bitpos */
397a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
398a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
399a1ba9ba4Schristos "R_MMIX_GETA", /* name */
400a1ba9ba4Schristos FALSE, /* partial_inplace */
401a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
402a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
403a1ba9ba4Schristos TRUE), /* pcrel_offset */
404a1ba9ba4Schristos
405a1ba9ba4Schristos HOWTO (R_MMIX_GETA_1, /* type */
406a1ba9ba4Schristos 2, /* rightshift */
407a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
408a1ba9ba4Schristos 19, /* bitsize */
409a1ba9ba4Schristos TRUE, /* pc_relative */
410a1ba9ba4Schristos 0, /* bitpos */
411a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
412a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
413a1ba9ba4Schristos "R_MMIX_GETA_1", /* name */
414a1ba9ba4Schristos FALSE, /* partial_inplace */
415a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
416a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
417a1ba9ba4Schristos TRUE), /* pcrel_offset */
418a1ba9ba4Schristos
419a1ba9ba4Schristos HOWTO (R_MMIX_GETA_2, /* type */
420a1ba9ba4Schristos 2, /* rightshift */
421a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
422a1ba9ba4Schristos 19, /* bitsize */
423a1ba9ba4Schristos TRUE, /* pc_relative */
424a1ba9ba4Schristos 0, /* bitpos */
425a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
426a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
427a1ba9ba4Schristos "R_MMIX_GETA_2", /* name */
428a1ba9ba4Schristos FALSE, /* partial_inplace */
429a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
430a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
431a1ba9ba4Schristos TRUE), /* pcrel_offset */
432a1ba9ba4Schristos
433a1ba9ba4Schristos HOWTO (R_MMIX_GETA_3, /* type */
434a1ba9ba4Schristos 2, /* rightshift */
435a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
436a1ba9ba4Schristos 19, /* bitsize */
437a1ba9ba4Schristos TRUE, /* pc_relative */
438a1ba9ba4Schristos 0, /* bitpos */
439a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
440a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
441a1ba9ba4Schristos "R_MMIX_GETA_3", /* name */
442a1ba9ba4Schristos FALSE, /* partial_inplace */
443a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
444a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
445a1ba9ba4Schristos TRUE), /* pcrel_offset */
446a1ba9ba4Schristos
447a1ba9ba4Schristos /* The conditional branches are supposed to reach any (code) address.
448a1ba9ba4Schristos It can silently expand to a 64-bit operand, but will emit an error if
449a1ba9ba4Schristos any of the two least significant bits are set. The howto members
450a1ba9ba4Schristos reflect a simple branch. */
451a1ba9ba4Schristos HOWTO (R_MMIX_CBRANCH, /* type */
452a1ba9ba4Schristos 2, /* rightshift */
453a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
454a1ba9ba4Schristos 19, /* bitsize */
455a1ba9ba4Schristos TRUE, /* pc_relative */
456a1ba9ba4Schristos 0, /* bitpos */
457a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
458a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
459a1ba9ba4Schristos "R_MMIX_CBRANCH", /* name */
460a1ba9ba4Schristos FALSE, /* partial_inplace */
461a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
462a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
463a1ba9ba4Schristos TRUE), /* pcrel_offset */
464a1ba9ba4Schristos
465a1ba9ba4Schristos HOWTO (R_MMIX_CBRANCH_J, /* type */
466a1ba9ba4Schristos 2, /* rightshift */
467a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
468a1ba9ba4Schristos 19, /* bitsize */
469a1ba9ba4Schristos TRUE, /* pc_relative */
470a1ba9ba4Schristos 0, /* bitpos */
471a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
472a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
473a1ba9ba4Schristos "R_MMIX_CBRANCH_J", /* name */
474a1ba9ba4Schristos FALSE, /* partial_inplace */
475a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
476a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
477a1ba9ba4Schristos TRUE), /* pcrel_offset */
478a1ba9ba4Schristos
479a1ba9ba4Schristos HOWTO (R_MMIX_CBRANCH_1, /* type */
480a1ba9ba4Schristos 2, /* rightshift */
481a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
482a1ba9ba4Schristos 19, /* bitsize */
483a1ba9ba4Schristos TRUE, /* pc_relative */
484a1ba9ba4Schristos 0, /* bitpos */
485a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
486a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
487a1ba9ba4Schristos "R_MMIX_CBRANCH_1", /* name */
488a1ba9ba4Schristos FALSE, /* partial_inplace */
489a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
490a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
491a1ba9ba4Schristos TRUE), /* pcrel_offset */
492a1ba9ba4Schristos
493a1ba9ba4Schristos HOWTO (R_MMIX_CBRANCH_2, /* type */
494a1ba9ba4Schristos 2, /* rightshift */
495a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
496a1ba9ba4Schristos 19, /* bitsize */
497a1ba9ba4Schristos TRUE, /* pc_relative */
498a1ba9ba4Schristos 0, /* bitpos */
499a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
500a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
501a1ba9ba4Schristos "R_MMIX_CBRANCH_2", /* name */
502a1ba9ba4Schristos FALSE, /* partial_inplace */
503a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
504a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
505a1ba9ba4Schristos TRUE), /* pcrel_offset */
506a1ba9ba4Schristos
507a1ba9ba4Schristos HOWTO (R_MMIX_CBRANCH_3, /* type */
508a1ba9ba4Schristos 2, /* rightshift */
509a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
510a1ba9ba4Schristos 19, /* bitsize */
511a1ba9ba4Schristos TRUE, /* pc_relative */
512a1ba9ba4Schristos 0, /* bitpos */
513a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
514a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
515a1ba9ba4Schristos "R_MMIX_CBRANCH_3", /* name */
516a1ba9ba4Schristos FALSE, /* partial_inplace */
517a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
518a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
519a1ba9ba4Schristos TRUE), /* pcrel_offset */
520a1ba9ba4Schristos
521a1ba9ba4Schristos /* The PUSHJ instruction can reach any (code) address, as long as it's
522a1ba9ba4Schristos the beginning of a function (no usable restriction). It can silently
523a1ba9ba4Schristos expand to a 64-bit operand, but will emit an error if any of the two
524a1ba9ba4Schristos least significant bits are set. It can also expand into a call to a
525a1ba9ba4Schristos stub; see R_MMIX_PUSHJ_STUBBABLE. The howto members reflect a simple
526a1ba9ba4Schristos PUSHJ. */
527a1ba9ba4Schristos HOWTO (R_MMIX_PUSHJ, /* type */
528a1ba9ba4Schristos 2, /* rightshift */
529a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
530a1ba9ba4Schristos 19, /* bitsize */
531a1ba9ba4Schristos TRUE, /* pc_relative */
532a1ba9ba4Schristos 0, /* bitpos */
533a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
534a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
535a1ba9ba4Schristos "R_MMIX_PUSHJ", /* name */
536a1ba9ba4Schristos FALSE, /* partial_inplace */
537a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
538a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
539a1ba9ba4Schristos TRUE), /* pcrel_offset */
540a1ba9ba4Schristos
541a1ba9ba4Schristos HOWTO (R_MMIX_PUSHJ_1, /* type */
542a1ba9ba4Schristos 2, /* rightshift */
543a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
544a1ba9ba4Schristos 19, /* bitsize */
545a1ba9ba4Schristos TRUE, /* pc_relative */
546a1ba9ba4Schristos 0, /* bitpos */
547a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
548a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
549a1ba9ba4Schristos "R_MMIX_PUSHJ_1", /* name */
550a1ba9ba4Schristos FALSE, /* partial_inplace */
551a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
552a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
553a1ba9ba4Schristos TRUE), /* pcrel_offset */
554a1ba9ba4Schristos
555a1ba9ba4Schristos HOWTO (R_MMIX_PUSHJ_2, /* type */
556a1ba9ba4Schristos 2, /* rightshift */
557a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
558a1ba9ba4Schristos 19, /* bitsize */
559a1ba9ba4Schristos TRUE, /* pc_relative */
560a1ba9ba4Schristos 0, /* bitpos */
561a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
562a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
563a1ba9ba4Schristos "R_MMIX_PUSHJ_2", /* name */
564a1ba9ba4Schristos FALSE, /* partial_inplace */
565a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
566a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
567a1ba9ba4Schristos TRUE), /* pcrel_offset */
568a1ba9ba4Schristos
569a1ba9ba4Schristos HOWTO (R_MMIX_PUSHJ_3, /* type */
570a1ba9ba4Schristos 2, /* rightshift */
571a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
572a1ba9ba4Schristos 19, /* bitsize */
573a1ba9ba4Schristos TRUE, /* pc_relative */
574a1ba9ba4Schristos 0, /* bitpos */
575a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
576a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
577a1ba9ba4Schristos "R_MMIX_PUSHJ_3", /* name */
578a1ba9ba4Schristos FALSE, /* partial_inplace */
579a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
580a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
581a1ba9ba4Schristos TRUE), /* pcrel_offset */
582a1ba9ba4Schristos
583a1ba9ba4Schristos /* A JMP is supposed to reach any (code) address. By itself, it can
584a1ba9ba4Schristos reach +-64M; the expansion can reach all 64 bits. Note that the 64M
585a1ba9ba4Schristos limit is soon reached if you link the program in wildly different
586a1ba9ba4Schristos memory segments. The howto members reflect a trivial JMP. */
587a1ba9ba4Schristos HOWTO (R_MMIX_JMP, /* type */
588a1ba9ba4Schristos 2, /* rightshift */
589a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
590a1ba9ba4Schristos 27, /* bitsize */
591a1ba9ba4Schristos TRUE, /* pc_relative */
592a1ba9ba4Schristos 0, /* bitpos */
593a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
594a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
595a1ba9ba4Schristos "R_MMIX_JMP", /* name */
596a1ba9ba4Schristos FALSE, /* partial_inplace */
597a1ba9ba4Schristos ~0x1ffffff, /* src_mask */
598a1ba9ba4Schristos 0x1ffffff, /* dst_mask */
599a1ba9ba4Schristos TRUE), /* pcrel_offset */
600a1ba9ba4Schristos
601a1ba9ba4Schristos HOWTO (R_MMIX_JMP_1, /* type */
602a1ba9ba4Schristos 2, /* rightshift */
603a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
604a1ba9ba4Schristos 27, /* bitsize */
605a1ba9ba4Schristos TRUE, /* pc_relative */
606a1ba9ba4Schristos 0, /* bitpos */
607a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
608a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
609a1ba9ba4Schristos "R_MMIX_JMP_1", /* name */
610a1ba9ba4Schristos FALSE, /* partial_inplace */
611a1ba9ba4Schristos ~0x1ffffff, /* src_mask */
612a1ba9ba4Schristos 0x1ffffff, /* dst_mask */
613a1ba9ba4Schristos TRUE), /* pcrel_offset */
614a1ba9ba4Schristos
615a1ba9ba4Schristos HOWTO (R_MMIX_JMP_2, /* type */
616a1ba9ba4Schristos 2, /* rightshift */
617a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
618a1ba9ba4Schristos 27, /* bitsize */
619a1ba9ba4Schristos TRUE, /* pc_relative */
620a1ba9ba4Schristos 0, /* bitpos */
621a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
622a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
623a1ba9ba4Schristos "R_MMIX_JMP_2", /* name */
624a1ba9ba4Schristos FALSE, /* partial_inplace */
625a1ba9ba4Schristos ~0x1ffffff, /* src_mask */
626a1ba9ba4Schristos 0x1ffffff, /* dst_mask */
627a1ba9ba4Schristos TRUE), /* pcrel_offset */
628a1ba9ba4Schristos
629a1ba9ba4Schristos HOWTO (R_MMIX_JMP_3, /* type */
630a1ba9ba4Schristos 2, /* rightshift */
631a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
632a1ba9ba4Schristos 27, /* bitsize */
633a1ba9ba4Schristos TRUE, /* pc_relative */
634a1ba9ba4Schristos 0, /* bitpos */
635a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
636a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
637a1ba9ba4Schristos "R_MMIX_JMP_3", /* name */
638a1ba9ba4Schristos FALSE, /* partial_inplace */
639a1ba9ba4Schristos ~0x1ffffff, /* src_mask */
640a1ba9ba4Schristos 0x1ffffff, /* dst_mask */
641a1ba9ba4Schristos TRUE), /* pcrel_offset */
642a1ba9ba4Schristos
643a1ba9ba4Schristos /* When we don't emit link-time-relaxable code from the assembler, or
644a1ba9ba4Schristos when relaxation has done all it can do, these relocs are used. For
645a1ba9ba4Schristos GETA/PUSHJ/branches. */
646a1ba9ba4Schristos HOWTO (R_MMIX_ADDR19, /* type */
647a1ba9ba4Schristos 2, /* rightshift */
648a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
649a1ba9ba4Schristos 19, /* bitsize */
650a1ba9ba4Schristos TRUE, /* pc_relative */
651a1ba9ba4Schristos 0, /* bitpos */
652a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
653a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
654a1ba9ba4Schristos "R_MMIX_ADDR19", /* name */
655a1ba9ba4Schristos FALSE, /* partial_inplace */
656a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
657a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
658a1ba9ba4Schristos TRUE), /* pcrel_offset */
659a1ba9ba4Schristos
660a1ba9ba4Schristos /* For JMP. */
661a1ba9ba4Schristos HOWTO (R_MMIX_ADDR27, /* type */
662a1ba9ba4Schristos 2, /* rightshift */
663a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
664a1ba9ba4Schristos 27, /* bitsize */
665a1ba9ba4Schristos TRUE, /* pc_relative */
666a1ba9ba4Schristos 0, /* bitpos */
667a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
668a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
669a1ba9ba4Schristos "R_MMIX_ADDR27", /* name */
670a1ba9ba4Schristos FALSE, /* partial_inplace */
671a1ba9ba4Schristos ~0x1ffffff, /* src_mask */
672a1ba9ba4Schristos 0x1ffffff, /* dst_mask */
673a1ba9ba4Schristos TRUE), /* pcrel_offset */
674a1ba9ba4Schristos
675a1ba9ba4Schristos /* A general register or the value 0..255. If a value, then the
676a1ba9ba4Schristos instruction (offset -3) needs adjusting. */
677a1ba9ba4Schristos HOWTO (R_MMIX_REG_OR_BYTE, /* type */
678a1ba9ba4Schristos 0, /* rightshift */
679a1ba9ba4Schristos 1, /* size (0 = byte, 1 = short, 2 = long) */
680a1ba9ba4Schristos 8, /* bitsize */
681a1ba9ba4Schristos FALSE, /* pc_relative */
682a1ba9ba4Schristos 0, /* bitpos */
683a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
684a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
685a1ba9ba4Schristos "R_MMIX_REG_OR_BYTE", /* name */
686a1ba9ba4Schristos FALSE, /* partial_inplace */
687a1ba9ba4Schristos 0, /* src_mask */
688a1ba9ba4Schristos 0xff, /* dst_mask */
689a1ba9ba4Schristos FALSE), /* pcrel_offset */
690a1ba9ba4Schristos
691a1ba9ba4Schristos /* A general register. */
692a1ba9ba4Schristos HOWTO (R_MMIX_REG, /* type */
693a1ba9ba4Schristos 0, /* rightshift */
694a1ba9ba4Schristos 1, /* size (0 = byte, 1 = short, 2 = long) */
695a1ba9ba4Schristos 8, /* bitsize */
696a1ba9ba4Schristos FALSE, /* pc_relative */
697a1ba9ba4Schristos 0, /* bitpos */
698a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
699a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
700a1ba9ba4Schristos "R_MMIX_REG", /* name */
701a1ba9ba4Schristos FALSE, /* partial_inplace */
702a1ba9ba4Schristos 0, /* src_mask */
703a1ba9ba4Schristos 0xff, /* dst_mask */
704a1ba9ba4Schristos FALSE), /* pcrel_offset */
705a1ba9ba4Schristos
706a1ba9ba4Schristos /* A register plus an index, corresponding to the relocation expression.
707a1ba9ba4Schristos The sizes must correspond to the valid range of the expression, while
708a1ba9ba4Schristos the bitmasks correspond to what we store in the image. */
709a1ba9ba4Schristos HOWTO (R_MMIX_BASE_PLUS_OFFSET, /* type */
710a1ba9ba4Schristos 0, /* rightshift */
711a1ba9ba4Schristos 4, /* size (0 = byte, 1 = short, 2 = long) */
712a1ba9ba4Schristos 64, /* bitsize */
713a1ba9ba4Schristos FALSE, /* pc_relative */
714a1ba9ba4Schristos 0, /* bitpos */
715a1ba9ba4Schristos complain_overflow_bitfield, /* complain_on_overflow */
716a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
717a1ba9ba4Schristos "R_MMIX_BASE_PLUS_OFFSET", /* name */
718a1ba9ba4Schristos FALSE, /* partial_inplace */
719a1ba9ba4Schristos 0, /* src_mask */
720a1ba9ba4Schristos 0xffff, /* dst_mask */
721a1ba9ba4Schristos FALSE), /* pcrel_offset */
722a1ba9ba4Schristos
723a1ba9ba4Schristos /* A "magic" relocation for a LOCAL expression, asserting that the
724a1ba9ba4Schristos expression is less than the number of global registers. No actual
725a1ba9ba4Schristos modification of the contents is done. Implementing this as a
726a1ba9ba4Schristos relocation was less intrusive than e.g. putting such expressions in a
727a1ba9ba4Schristos section to discard *after* relocation. */
728a1ba9ba4Schristos HOWTO (R_MMIX_LOCAL, /* type */
729a1ba9ba4Schristos 0, /* rightshift */
730a1ba9ba4Schristos 0, /* size (0 = byte, 1 = short, 2 = long) */
731a1ba9ba4Schristos 0, /* bitsize */
732a1ba9ba4Schristos FALSE, /* pc_relative */
733a1ba9ba4Schristos 0, /* bitpos */
734a1ba9ba4Schristos complain_overflow_dont, /* complain_on_overflow */
735a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
736a1ba9ba4Schristos "R_MMIX_LOCAL", /* name */
737a1ba9ba4Schristos FALSE, /* partial_inplace */
738a1ba9ba4Schristos 0, /* src_mask */
739a1ba9ba4Schristos 0, /* dst_mask */
740a1ba9ba4Schristos FALSE), /* pcrel_offset */
741a1ba9ba4Schristos
742a1ba9ba4Schristos HOWTO (R_MMIX_PUSHJ_STUBBABLE, /* type */
743a1ba9ba4Schristos 2, /* rightshift */
744a1ba9ba4Schristos 2, /* size (0 = byte, 1 = short, 2 = long) */
745a1ba9ba4Schristos 19, /* bitsize */
746a1ba9ba4Schristos TRUE, /* pc_relative */
747a1ba9ba4Schristos 0, /* bitpos */
748a1ba9ba4Schristos complain_overflow_signed, /* complain_on_overflow */
749a1ba9ba4Schristos mmix_elf_reloc, /* special_function */
750a1ba9ba4Schristos "R_MMIX_PUSHJ_STUBBABLE", /* name */
751a1ba9ba4Schristos FALSE, /* partial_inplace */
752a1ba9ba4Schristos ~0x0100ffff, /* src_mask */
753a1ba9ba4Schristos 0x0100ffff, /* dst_mask */
754a1ba9ba4Schristos TRUE) /* pcrel_offset */
755a1ba9ba4Schristos };
756a1ba9ba4Schristos
757a1ba9ba4Schristos
758a1ba9ba4Schristos /* Map BFD reloc types to MMIX ELF reloc types. */
759a1ba9ba4Schristos
760a1ba9ba4Schristos struct mmix_reloc_map
761a1ba9ba4Schristos {
762a1ba9ba4Schristos bfd_reloc_code_real_type bfd_reloc_val;
763a1ba9ba4Schristos enum elf_mmix_reloc_type elf_reloc_val;
764a1ba9ba4Schristos };
765a1ba9ba4Schristos
766a1ba9ba4Schristos
767a1ba9ba4Schristos static const struct mmix_reloc_map mmix_reloc_map[] =
768a1ba9ba4Schristos {
769a1ba9ba4Schristos {BFD_RELOC_NONE, R_MMIX_NONE},
770a1ba9ba4Schristos {BFD_RELOC_8, R_MMIX_8},
771a1ba9ba4Schristos {BFD_RELOC_16, R_MMIX_16},
772a1ba9ba4Schristos {BFD_RELOC_24, R_MMIX_24},
773a1ba9ba4Schristos {BFD_RELOC_32, R_MMIX_32},
774a1ba9ba4Schristos {BFD_RELOC_64, R_MMIX_64},
775a1ba9ba4Schristos {BFD_RELOC_8_PCREL, R_MMIX_PC_8},
776a1ba9ba4Schristos {BFD_RELOC_16_PCREL, R_MMIX_PC_16},
777a1ba9ba4Schristos {BFD_RELOC_24_PCREL, R_MMIX_PC_24},
778a1ba9ba4Schristos {BFD_RELOC_32_PCREL, R_MMIX_PC_32},
779a1ba9ba4Schristos {BFD_RELOC_64_PCREL, R_MMIX_PC_64},
780a1ba9ba4Schristos {BFD_RELOC_VTABLE_INHERIT, R_MMIX_GNU_VTINHERIT},
781a1ba9ba4Schristos {BFD_RELOC_VTABLE_ENTRY, R_MMIX_GNU_VTENTRY},
782a1ba9ba4Schristos {BFD_RELOC_MMIX_GETA, R_MMIX_GETA},
783a1ba9ba4Schristos {BFD_RELOC_MMIX_CBRANCH, R_MMIX_CBRANCH},
784a1ba9ba4Schristos {BFD_RELOC_MMIX_PUSHJ, R_MMIX_PUSHJ},
785a1ba9ba4Schristos {BFD_RELOC_MMIX_JMP, R_MMIX_JMP},
786a1ba9ba4Schristos {BFD_RELOC_MMIX_ADDR19, R_MMIX_ADDR19},
787a1ba9ba4Schristos {BFD_RELOC_MMIX_ADDR27, R_MMIX_ADDR27},
788a1ba9ba4Schristos {BFD_RELOC_MMIX_REG_OR_BYTE, R_MMIX_REG_OR_BYTE},
789a1ba9ba4Schristos {BFD_RELOC_MMIX_REG, R_MMIX_REG},
790a1ba9ba4Schristos {BFD_RELOC_MMIX_BASE_PLUS_OFFSET, R_MMIX_BASE_PLUS_OFFSET},
791a1ba9ba4Schristos {BFD_RELOC_MMIX_LOCAL, R_MMIX_LOCAL},
792a1ba9ba4Schristos {BFD_RELOC_MMIX_PUSHJ_STUBBABLE, R_MMIX_PUSHJ_STUBBABLE}
793a1ba9ba4Schristos };
794a1ba9ba4Schristos
795a1ba9ba4Schristos static reloc_howto_type *
bfd_elf64_bfd_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)796a1ba9ba4Schristos bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
797a1ba9ba4Schristos bfd_reloc_code_real_type code)
798a1ba9ba4Schristos {
799a1ba9ba4Schristos unsigned int i;
800a1ba9ba4Schristos
801a1ba9ba4Schristos for (i = 0;
802a1ba9ba4Schristos i < sizeof (mmix_reloc_map) / sizeof (mmix_reloc_map[0]);
803a1ba9ba4Schristos i++)
804a1ba9ba4Schristos {
805a1ba9ba4Schristos if (mmix_reloc_map[i].bfd_reloc_val == code)
806a1ba9ba4Schristos return &elf_mmix_howto_table[mmix_reloc_map[i].elf_reloc_val];
807a1ba9ba4Schristos }
808a1ba9ba4Schristos
809a1ba9ba4Schristos return NULL;
810a1ba9ba4Schristos }
811a1ba9ba4Schristos
812a1ba9ba4Schristos static reloc_howto_type *
bfd_elf64_bfd_reloc_name_lookup(bfd * abfd ATTRIBUTE_UNUSED,const char * r_name)813a1ba9ba4Schristos bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
814a1ba9ba4Schristos const char *r_name)
815a1ba9ba4Schristos {
816a1ba9ba4Schristos unsigned int i;
817a1ba9ba4Schristos
818a1ba9ba4Schristos for (i = 0;
819a1ba9ba4Schristos i < sizeof (elf_mmix_howto_table) / sizeof (elf_mmix_howto_table[0]);
820a1ba9ba4Schristos i++)
821a1ba9ba4Schristos if (elf_mmix_howto_table[i].name != NULL
822a1ba9ba4Schristos && strcasecmp (elf_mmix_howto_table[i].name, r_name) == 0)
823a1ba9ba4Schristos return &elf_mmix_howto_table[i];
824a1ba9ba4Schristos
825a1ba9ba4Schristos return NULL;
826a1ba9ba4Schristos }
827a1ba9ba4Schristos
828a1ba9ba4Schristos static bfd_boolean
mmix_elf_new_section_hook(bfd * abfd,asection * sec)829a1ba9ba4Schristos mmix_elf_new_section_hook (bfd *abfd, asection *sec)
830a1ba9ba4Schristos {
831a1ba9ba4Schristos if (!sec->used_by_bfd)
832a1ba9ba4Schristos {
833a1ba9ba4Schristos struct _mmix_elf_section_data *sdata;
834*184b2d41Schristos size_t amt = sizeof (*sdata);
835a1ba9ba4Schristos
836a1ba9ba4Schristos sdata = bfd_zalloc (abfd, amt);
837a1ba9ba4Schristos if (sdata == NULL)
838a1ba9ba4Schristos return FALSE;
839a1ba9ba4Schristos sec->used_by_bfd = sdata;
840a1ba9ba4Schristos }
841a1ba9ba4Schristos
842a1ba9ba4Schristos return _bfd_elf_new_section_hook (abfd, sec);
843a1ba9ba4Schristos }
844a1ba9ba4Schristos
845a1ba9ba4Schristos
846a1ba9ba4Schristos /* This function performs the actual bitfiddling and sanity check for a
847a1ba9ba4Schristos final relocation. Each relocation gets its *worst*-case expansion
848a1ba9ba4Schristos in size when it arrives here; any reduction in size should have been
849a1ba9ba4Schristos caught in linker relaxation earlier. When we get here, the relocation
850a1ba9ba4Schristos looks like the smallest instruction with SWYM:s (nop:s) appended to the
851a1ba9ba4Schristos max size. We fill in those nop:s.
852a1ba9ba4Schristos
853a1ba9ba4Schristos R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
854a1ba9ba4Schristos GETA $N,foo
855a1ba9ba4Schristos ->
856a1ba9ba4Schristos SETL $N,foo & 0xffff
857a1ba9ba4Schristos INCML $N,(foo >> 16) & 0xffff
858a1ba9ba4Schristos INCMH $N,(foo >> 32) & 0xffff
859a1ba9ba4Schristos INCH $N,(foo >> 48) & 0xffff
860a1ba9ba4Schristos
861a1ba9ba4Schristos R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
862a1ba9ba4Schristos condbranches needing relaxation might be rare enough to not be
863a1ba9ba4Schristos worthwhile.)
864a1ba9ba4Schristos [P]Bcc $N,foo
865a1ba9ba4Schristos ->
866a1ba9ba4Schristos [~P]B~cc $N,.+20
867a1ba9ba4Schristos SETL $255,foo & ...
868a1ba9ba4Schristos INCML ...
869a1ba9ba4Schristos INCMH ...
870a1ba9ba4Schristos INCH ...
871a1ba9ba4Schristos GO $255,$255,0
872a1ba9ba4Schristos
873a1ba9ba4Schristos R_MMIX_PUSHJ: (FIXME: Relaxation...)
874a1ba9ba4Schristos PUSHJ $N,foo
875a1ba9ba4Schristos ->
876a1ba9ba4Schristos SETL $255,foo & ...
877a1ba9ba4Schristos INCML ...
878a1ba9ba4Schristos INCMH ...
879a1ba9ba4Schristos INCH ...
880a1ba9ba4Schristos PUSHGO $N,$255,0
881a1ba9ba4Schristos
882a1ba9ba4Schristos R_MMIX_JMP: (FIXME: Relaxation...)
883a1ba9ba4Schristos JMP foo
884a1ba9ba4Schristos ->
885a1ba9ba4Schristos SETL $255,foo & ...
886a1ba9ba4Schristos INCML ...
887a1ba9ba4Schristos INCMH ...
888a1ba9ba4Schristos INCH ...
889a1ba9ba4Schristos GO $255,$255,0
890a1ba9ba4Schristos
891a1ba9ba4Schristos R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
892a1ba9ba4Schristos
893a1ba9ba4Schristos static bfd_reloc_status_type
mmix_elf_perform_relocation(asection * isec,reloc_howto_type * howto,void * datap,bfd_vma addr,bfd_vma value,char ** error_message)894a1ba9ba4Schristos mmix_elf_perform_relocation (asection *isec, reloc_howto_type *howto,
895a1ba9ba4Schristos void *datap, bfd_vma addr, bfd_vma value,
896a1ba9ba4Schristos char **error_message)
897a1ba9ba4Schristos {
898a1ba9ba4Schristos bfd *abfd = isec->owner;
899a1ba9ba4Schristos bfd_reloc_status_type flag = bfd_reloc_ok;
900a1ba9ba4Schristos bfd_reloc_status_type r;
901a1ba9ba4Schristos int offs = 0;
902a1ba9ba4Schristos int reg = 255;
903a1ba9ba4Schristos
904a1ba9ba4Schristos /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
905a1ba9ba4Schristos We handle the differences here and the common sequence later. */
906a1ba9ba4Schristos switch (howto->type)
907a1ba9ba4Schristos {
908a1ba9ba4Schristos case R_MMIX_GETA:
909a1ba9ba4Schristos offs = 0;
910a1ba9ba4Schristos reg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
911a1ba9ba4Schristos
912a1ba9ba4Schristos /* We change to an absolute value. */
913a1ba9ba4Schristos value += addr;
914a1ba9ba4Schristos break;
915a1ba9ba4Schristos
916a1ba9ba4Schristos case R_MMIX_CBRANCH:
917a1ba9ba4Schristos {
918a1ba9ba4Schristos int in1 = bfd_get_16 (abfd, (bfd_byte *) datap) << 16;
919a1ba9ba4Schristos
920a1ba9ba4Schristos /* Invert the condition and prediction bit, and set the offset
921a1ba9ba4Schristos to five instructions ahead.
922a1ba9ba4Schristos
923a1ba9ba4Schristos We *can* do better if we want to. If the branch is found to be
924a1ba9ba4Schristos within limits, we could leave the branch as is; there'll just
925a1ba9ba4Schristos be a bunch of NOP:s after it. But we shouldn't see this
926a1ba9ba4Schristos sequence often enough that it's worth doing it. */
927a1ba9ba4Schristos
928a1ba9ba4Schristos bfd_put_32 (abfd,
929a1ba9ba4Schristos (((in1 ^ ((PRED_INV_BIT | COND_INV_BIT) << 24)) & ~0xffff)
930a1ba9ba4Schristos | (24/4)),
931a1ba9ba4Schristos (bfd_byte *) datap);
932a1ba9ba4Schristos
933a1ba9ba4Schristos /* Put a "GO $255,$255,0" after the common sequence. */
934a1ba9ba4Schristos bfd_put_32 (abfd,
935a1ba9ba4Schristos ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | 0xffff00,
936a1ba9ba4Schristos (bfd_byte *) datap + 20);
937a1ba9ba4Schristos
938a1ba9ba4Schristos /* Common sequence starts at offset 4. */
939a1ba9ba4Schristos offs = 4;
940a1ba9ba4Schristos
941a1ba9ba4Schristos /* We change to an absolute value. */
942a1ba9ba4Schristos value += addr;
943a1ba9ba4Schristos }
944a1ba9ba4Schristos break;
945a1ba9ba4Schristos
946a1ba9ba4Schristos case R_MMIX_PUSHJ_STUBBABLE:
947a1ba9ba4Schristos /* If the address fits, we're fine. */
948a1ba9ba4Schristos if ((value & 3) == 0
949a1ba9ba4Schristos /* Note rightshift 0; see R_MMIX_JMP case below. */
950a1ba9ba4Schristos && (r = bfd_check_overflow (complain_overflow_signed,
951a1ba9ba4Schristos howto->bitsize,
952a1ba9ba4Schristos 0,
953a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
954a1ba9ba4Schristos value)) == bfd_reloc_ok)
955a1ba9ba4Schristos goto pcrel_mmix_reloc_fits;
956a1ba9ba4Schristos else
957a1ba9ba4Schristos {
958a1ba9ba4Schristos bfd_size_type size = isec->rawsize ? isec->rawsize : isec->size;
959a1ba9ba4Schristos
960a1ba9ba4Schristos /* We have the bytes at the PUSHJ insn and need to get the
961a1ba9ba4Schristos position for the stub. There's supposed to be room allocated
962a1ba9ba4Schristos for the stub. */
963a1ba9ba4Schristos bfd_byte *stubcontents
964a1ba9ba4Schristos = ((bfd_byte *) datap
965a1ba9ba4Schristos - (addr - (isec->output_section->vma + isec->output_offset))
966a1ba9ba4Schristos + size
967a1ba9ba4Schristos + mmix_elf_section_data (isec)->pjs.stub_offset);
968a1ba9ba4Schristos bfd_vma stubaddr;
969a1ba9ba4Schristos
970a1ba9ba4Schristos if (mmix_elf_section_data (isec)->pjs.n_pushj_relocs == 0)
971a1ba9ba4Schristos {
972a1ba9ba4Schristos /* This shouldn't happen when linking to ELF or mmo, so
973a1ba9ba4Schristos this is an attempt to link to "binary", right? We
974a1ba9ba4Schristos can't access the output bfd, so we can't verify that
975a1ba9ba4Schristos assumption. We only know that the critical
976a1ba9ba4Schristos mmix_elf_check_common_relocs has not been called,
977a1ba9ba4Schristos which happens when the output format is different
978a1ba9ba4Schristos from the input format (and is not mmo). */
979a1ba9ba4Schristos if (! mmix_elf_section_data (isec)->has_warned_pushj)
980a1ba9ba4Schristos {
981a1ba9ba4Schristos /* For the first such error per input section, produce
982a1ba9ba4Schristos a verbose message. */
983a1ba9ba4Schristos *error_message
984a1ba9ba4Schristos = _("invalid input relocation when producing"
985051580eeSchristos " non-ELF, non-mmo format output;"
986051580eeSchristos " please use the objcopy program to convert from"
987a1ba9ba4Schristos " ELF or mmo,"
988051580eeSchristos " or assemble using"
989a1ba9ba4Schristos " \"-no-expand\" (for gcc, \"-Wa,-no-expand\"");
990a1ba9ba4Schristos mmix_elf_section_data (isec)->has_warned_pushj = TRUE;
991a1ba9ba4Schristos return bfd_reloc_dangerous;
992a1ba9ba4Schristos }
993a1ba9ba4Schristos
994a1ba9ba4Schristos /* For subsequent errors, return this one, which is
995a1ba9ba4Schristos rate-limited but looks a little bit different,
996a1ba9ba4Schristos hopefully without affecting user-friendliness. */
997a1ba9ba4Schristos return bfd_reloc_overflow;
998a1ba9ba4Schristos }
999a1ba9ba4Schristos
1000a1ba9ba4Schristos /* The address doesn't fit, so redirect the PUSHJ to the
1001a1ba9ba4Schristos location of the stub. */
1002a1ba9ba4Schristos r = mmix_elf_perform_relocation (isec,
1003a1ba9ba4Schristos &elf_mmix_howto_table
1004a1ba9ba4Schristos [R_MMIX_ADDR19],
1005a1ba9ba4Schristos datap,
1006a1ba9ba4Schristos addr,
1007a1ba9ba4Schristos isec->output_section->vma
1008a1ba9ba4Schristos + isec->output_offset
1009a1ba9ba4Schristos + size
1010a1ba9ba4Schristos + (mmix_elf_section_data (isec)
1011a1ba9ba4Schristos ->pjs.stub_offset)
1012a1ba9ba4Schristos - addr,
1013a1ba9ba4Schristos error_message);
1014a1ba9ba4Schristos if (r != bfd_reloc_ok)
1015a1ba9ba4Schristos return r;
1016a1ba9ba4Schristos
1017a1ba9ba4Schristos stubaddr
1018a1ba9ba4Schristos = (isec->output_section->vma
1019a1ba9ba4Schristos + isec->output_offset
1020a1ba9ba4Schristos + size
1021a1ba9ba4Schristos + mmix_elf_section_data (isec)->pjs.stub_offset);
1022a1ba9ba4Schristos
1023a1ba9ba4Schristos /* We generate a simple JMP if that suffices, else the whole 5
1024a1ba9ba4Schristos insn stub. */
1025a1ba9ba4Schristos if (bfd_check_overflow (complain_overflow_signed,
1026a1ba9ba4Schristos elf_mmix_howto_table[R_MMIX_ADDR27].bitsize,
1027a1ba9ba4Schristos 0,
1028a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
1029a1ba9ba4Schristos addr + value - stubaddr) == bfd_reloc_ok)
1030a1ba9ba4Schristos {
1031a1ba9ba4Schristos bfd_put_32 (abfd, JMP_INSN_BYTE << 24, stubcontents);
1032a1ba9ba4Schristos r = mmix_elf_perform_relocation (isec,
1033a1ba9ba4Schristos &elf_mmix_howto_table
1034a1ba9ba4Schristos [R_MMIX_ADDR27],
1035a1ba9ba4Schristos stubcontents,
1036a1ba9ba4Schristos stubaddr,
1037a1ba9ba4Schristos value + addr - stubaddr,
1038a1ba9ba4Schristos error_message);
1039a1ba9ba4Schristos mmix_elf_section_data (isec)->pjs.stub_offset += 4;
1040a1ba9ba4Schristos
1041a1ba9ba4Schristos if (size + mmix_elf_section_data (isec)->pjs.stub_offset
1042a1ba9ba4Schristos > isec->size)
1043a1ba9ba4Schristos abort ();
1044a1ba9ba4Schristos
1045a1ba9ba4Schristos return r;
1046a1ba9ba4Schristos }
1047a1ba9ba4Schristos else
1048a1ba9ba4Schristos {
1049a1ba9ba4Schristos /* Put a "GO $255,0" after the common sequence. */
1050a1ba9ba4Schristos bfd_put_32 (abfd,
1051a1ba9ba4Schristos ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
1052a1ba9ba4Schristos | 0xff00, (bfd_byte *) stubcontents + 16);
1053a1ba9ba4Schristos
1054a1ba9ba4Schristos /* Prepare for the general code to set the first part of the
1055a1ba9ba4Schristos linker stub, and */
1056a1ba9ba4Schristos value += addr;
1057a1ba9ba4Schristos datap = stubcontents;
1058a1ba9ba4Schristos mmix_elf_section_data (isec)->pjs.stub_offset
1059a1ba9ba4Schristos += MAX_PUSHJ_STUB_SIZE;
1060a1ba9ba4Schristos }
1061a1ba9ba4Schristos }
1062a1ba9ba4Schristos break;
1063a1ba9ba4Schristos
1064a1ba9ba4Schristos case R_MMIX_PUSHJ:
1065a1ba9ba4Schristos {
1066a1ba9ba4Schristos int inreg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
1067a1ba9ba4Schristos
1068a1ba9ba4Schristos /* Put a "PUSHGO $N,$255,0" after the common sequence. */
1069a1ba9ba4Schristos bfd_put_32 (abfd,
1070a1ba9ba4Schristos ((PUSHGO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
1071a1ba9ba4Schristos | (inreg << 16)
1072a1ba9ba4Schristos | 0xff00,
1073a1ba9ba4Schristos (bfd_byte *) datap + 16);
1074a1ba9ba4Schristos
1075a1ba9ba4Schristos /* We change to an absolute value. */
1076a1ba9ba4Schristos value += addr;
1077a1ba9ba4Schristos }
1078a1ba9ba4Schristos break;
1079a1ba9ba4Schristos
1080a1ba9ba4Schristos case R_MMIX_JMP:
1081a1ba9ba4Schristos /* This one is a little special. If we get here on a non-relaxing
1082a1ba9ba4Schristos link, and the destination is actually in range, we don't need to
1083a1ba9ba4Schristos execute the nops.
1084a1ba9ba4Schristos If so, we fall through to the bit-fiddling relocs.
1085a1ba9ba4Schristos
1086a1ba9ba4Schristos FIXME: bfd_check_overflow seems broken; the relocation is
1087a1ba9ba4Schristos rightshifted before testing, so supply a zero rightshift. */
1088a1ba9ba4Schristos
1089a1ba9ba4Schristos if (! ((value & 3) == 0
1090a1ba9ba4Schristos && (r = bfd_check_overflow (complain_overflow_signed,
1091a1ba9ba4Schristos howto->bitsize,
1092a1ba9ba4Schristos 0,
1093a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
1094a1ba9ba4Schristos value)) == bfd_reloc_ok))
1095a1ba9ba4Schristos {
1096a1ba9ba4Schristos /* If the relocation doesn't fit in a JMP, we let the NOP:s be
1097a1ba9ba4Schristos modified below, and put a "GO $255,$255,0" after the
1098a1ba9ba4Schristos address-loading sequence. */
1099a1ba9ba4Schristos bfd_put_32 (abfd,
1100a1ba9ba4Schristos ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
1101a1ba9ba4Schristos | 0xffff00,
1102a1ba9ba4Schristos (bfd_byte *) datap + 16);
1103a1ba9ba4Schristos
1104a1ba9ba4Schristos /* We change to an absolute value. */
1105a1ba9ba4Schristos value += addr;
1106a1ba9ba4Schristos break;
1107a1ba9ba4Schristos }
1108a1ba9ba4Schristos /* FALLTHROUGH. */
1109a1ba9ba4Schristos case R_MMIX_ADDR19:
1110a1ba9ba4Schristos case R_MMIX_ADDR27:
1111a1ba9ba4Schristos pcrel_mmix_reloc_fits:
1112a1ba9ba4Schristos /* These must be in range, or else we emit an error. */
1113a1ba9ba4Schristos if ((value & 3) == 0
1114a1ba9ba4Schristos /* Note rightshift 0; see above. */
1115a1ba9ba4Schristos && (r = bfd_check_overflow (complain_overflow_signed,
1116a1ba9ba4Schristos howto->bitsize,
1117a1ba9ba4Schristos 0,
1118a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
1119a1ba9ba4Schristos value)) == bfd_reloc_ok)
1120a1ba9ba4Schristos {
1121a1ba9ba4Schristos bfd_vma in1
1122a1ba9ba4Schristos = bfd_get_32 (abfd, (bfd_byte *) datap);
1123a1ba9ba4Schristos bfd_vma highbit;
1124a1ba9ba4Schristos
1125a1ba9ba4Schristos if ((bfd_signed_vma) value < 0)
1126a1ba9ba4Schristos {
1127a1ba9ba4Schristos highbit = 1 << 24;
1128a1ba9ba4Schristos value += (1 << (howto->bitsize - 1));
1129a1ba9ba4Schristos }
1130a1ba9ba4Schristos else
1131a1ba9ba4Schristos highbit = 0;
1132a1ba9ba4Schristos
1133a1ba9ba4Schristos value >>= 2;
1134a1ba9ba4Schristos
1135a1ba9ba4Schristos bfd_put_32 (abfd,
1136a1ba9ba4Schristos (in1 & howto->src_mask)
1137a1ba9ba4Schristos | highbit
1138a1ba9ba4Schristos | (value & howto->dst_mask),
1139a1ba9ba4Schristos (bfd_byte *) datap);
1140a1ba9ba4Schristos
1141a1ba9ba4Schristos return bfd_reloc_ok;
1142a1ba9ba4Schristos }
1143a1ba9ba4Schristos else
1144a1ba9ba4Schristos return bfd_reloc_overflow;
1145a1ba9ba4Schristos
1146a1ba9ba4Schristos case R_MMIX_BASE_PLUS_OFFSET:
1147a1ba9ba4Schristos {
1148a1ba9ba4Schristos struct bpo_reloc_section_info *bpodata
1149a1ba9ba4Schristos = mmix_elf_section_data (isec)->bpo.reloc;
1150a1ba9ba4Schristos asection *bpo_greg_section;
1151a1ba9ba4Schristos struct bpo_greg_section_info *gregdata;
1152a1ba9ba4Schristos size_t bpo_index;
1153a1ba9ba4Schristos
1154a1ba9ba4Schristos if (bpodata == NULL)
1155a1ba9ba4Schristos {
1156a1ba9ba4Schristos /* This shouldn't happen when linking to ELF or mmo, so
1157a1ba9ba4Schristos this is an attempt to link to "binary", right? We
1158a1ba9ba4Schristos can't access the output bfd, so we can't verify that
1159a1ba9ba4Schristos assumption. We only know that the critical
1160a1ba9ba4Schristos mmix_elf_check_common_relocs has not been called, which
1161a1ba9ba4Schristos happens when the output format is different from the
1162a1ba9ba4Schristos input format (and is not mmo). */
1163a1ba9ba4Schristos if (! mmix_elf_section_data (isec)->has_warned_bpo)
1164a1ba9ba4Schristos {
1165a1ba9ba4Schristos /* For the first such error per input section, produce
1166a1ba9ba4Schristos a verbose message. */
1167a1ba9ba4Schristos *error_message
1168a1ba9ba4Schristos = _("invalid input relocation when producing"
1169051580eeSchristos " non-ELF, non-mmo format output;"
1170051580eeSchristos " please use the objcopy program to convert from"
1171a1ba9ba4Schristos " ELF or mmo,"
1172051580eeSchristos " or compile using the gcc-option"
1173a1ba9ba4Schristos " \"-mno-base-addresses\".");
1174a1ba9ba4Schristos mmix_elf_section_data (isec)->has_warned_bpo = TRUE;
1175a1ba9ba4Schristos return bfd_reloc_dangerous;
1176a1ba9ba4Schristos }
1177a1ba9ba4Schristos
1178a1ba9ba4Schristos /* For subsequent errors, return this one, which is
1179a1ba9ba4Schristos rate-limited but looks a little bit different,
1180a1ba9ba4Schristos hopefully without affecting user-friendliness. */
1181a1ba9ba4Schristos return bfd_reloc_overflow;
1182a1ba9ba4Schristos }
1183a1ba9ba4Schristos
1184a1ba9ba4Schristos bpo_greg_section = bpodata->bpo_greg_section;
1185a1ba9ba4Schristos gregdata = mmix_elf_section_data (bpo_greg_section)->bpo.greg;
1186a1ba9ba4Schristos bpo_index = gregdata->bpo_reloc_indexes[bpodata->bpo_index++];
1187a1ba9ba4Schristos
1188a1ba9ba4Schristos /* A consistency check: The value we now have in "relocation" must
1189a1ba9ba4Schristos be the same as the value we stored for that relocation. It
1190a1ba9ba4Schristos doesn't cost much, so can be left in at all times. */
1191a1ba9ba4Schristos if (value != gregdata->reloc_request[bpo_index].value)
1192a1ba9ba4Schristos {
119315d8e94aSchristos _bfd_error_handler
119415d8e94aSchristos /* xgettext:c-format */
1195051580eeSchristos (_("%pB: Internal inconsistency error for value for\n\
1196051580eeSchristos linker-allocated global register: linked: %#" PRIx64 " != relaxed: %#" PRIx64 ""),
119715d8e94aSchristos isec->owner,
1198051580eeSchristos (uint64_t) value,
1199051580eeSchristos (uint64_t) gregdata->reloc_request[bpo_index].value);
1200a1ba9ba4Schristos bfd_set_error (bfd_error_bad_value);
1201a1ba9ba4Schristos return bfd_reloc_overflow;
1202a1ba9ba4Schristos }
1203a1ba9ba4Schristos
1204a1ba9ba4Schristos /* Then store the register number and offset for that register
1205a1ba9ba4Schristos into datap and datap + 1 respectively. */
1206a1ba9ba4Schristos bfd_put_8 (abfd,
1207a1ba9ba4Schristos gregdata->reloc_request[bpo_index].regindex
1208a1ba9ba4Schristos + bpo_greg_section->output_section->vma / 8,
1209a1ba9ba4Schristos datap);
1210a1ba9ba4Schristos bfd_put_8 (abfd,
1211a1ba9ba4Schristos gregdata->reloc_request[bpo_index].offset,
1212a1ba9ba4Schristos ((unsigned char *) datap) + 1);
1213a1ba9ba4Schristos return bfd_reloc_ok;
1214a1ba9ba4Schristos }
1215a1ba9ba4Schristos
1216a1ba9ba4Schristos case R_MMIX_REG_OR_BYTE:
1217a1ba9ba4Schristos case R_MMIX_REG:
1218a1ba9ba4Schristos if (value > 255)
1219a1ba9ba4Schristos return bfd_reloc_overflow;
1220a1ba9ba4Schristos bfd_put_8 (abfd, value, datap);
1221a1ba9ba4Schristos return bfd_reloc_ok;
1222a1ba9ba4Schristos
1223a1ba9ba4Schristos default:
1224a1ba9ba4Schristos BAD_CASE (howto->type);
1225a1ba9ba4Schristos }
1226a1ba9ba4Schristos
1227a1ba9ba4Schristos /* This code adds the common SETL/INCML/INCMH/INCH worst-case
1228a1ba9ba4Schristos sequence. */
1229a1ba9ba4Schristos
1230a1ba9ba4Schristos /* Lowest two bits must be 0. We return bfd_reloc_overflow for
1231a1ba9ba4Schristos everything that looks strange. */
1232a1ba9ba4Schristos if (value & 3)
1233a1ba9ba4Schristos flag = bfd_reloc_overflow;
1234a1ba9ba4Schristos
1235a1ba9ba4Schristos bfd_put_32 (abfd,
1236a1ba9ba4Schristos (SETL_INSN_BYTE << 24) | (value & 0xffff) | (reg << 16),
1237a1ba9ba4Schristos (bfd_byte *) datap + offs);
1238a1ba9ba4Schristos bfd_put_32 (abfd,
1239a1ba9ba4Schristos (INCML_INSN_BYTE << 24) | ((value >> 16) & 0xffff) | (reg << 16),
1240a1ba9ba4Schristos (bfd_byte *) datap + offs + 4);
1241a1ba9ba4Schristos bfd_put_32 (abfd,
1242a1ba9ba4Schristos (INCMH_INSN_BYTE << 24) | ((value >> 32) & 0xffff) | (reg << 16),
1243a1ba9ba4Schristos (bfd_byte *) datap + offs + 8);
1244a1ba9ba4Schristos bfd_put_32 (abfd,
1245a1ba9ba4Schristos (INCH_INSN_BYTE << 24) | ((value >> 48) & 0xffff) | (reg << 16),
1246a1ba9ba4Schristos (bfd_byte *) datap + offs + 12);
1247a1ba9ba4Schristos
1248a1ba9ba4Schristos return flag;
1249a1ba9ba4Schristos }
1250a1ba9ba4Schristos
1251a1ba9ba4Schristos /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
1252a1ba9ba4Schristos
1253051580eeSchristos static bfd_boolean
mmix_info_to_howto_rela(bfd * abfd,arelent * cache_ptr,Elf_Internal_Rela * dst)1254051580eeSchristos mmix_info_to_howto_rela (bfd *abfd,
1255a1ba9ba4Schristos arelent *cache_ptr,
1256a1ba9ba4Schristos Elf_Internal_Rela *dst)
1257a1ba9ba4Schristos {
1258a1ba9ba4Schristos unsigned int r_type;
1259a1ba9ba4Schristos
1260a1ba9ba4Schristos r_type = ELF64_R_TYPE (dst->r_info);
1261a1ba9ba4Schristos if (r_type >= (unsigned int) R_MMIX_max)
1262a1ba9ba4Schristos {
126315d8e94aSchristos /* xgettext:c-format */
1264051580eeSchristos _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1265051580eeSchristos abfd, r_type);
1266051580eeSchristos bfd_set_error (bfd_error_bad_value);
1267051580eeSchristos return FALSE;
1268a1ba9ba4Schristos }
1269a1ba9ba4Schristos cache_ptr->howto = &elf_mmix_howto_table[r_type];
1270051580eeSchristos return TRUE;
1271a1ba9ba4Schristos }
1272a1ba9ba4Schristos
1273a1ba9ba4Schristos /* Any MMIX-specific relocation gets here at assembly time or when linking
1274a1ba9ba4Schristos to other formats (such as mmo); this is the relocation function from
1275a1ba9ba4Schristos the reloc_table. We don't get here for final pure ELF linking. */
1276a1ba9ba4Schristos
1277a1ba9ba4Schristos static bfd_reloc_status_type
mmix_elf_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)1278a1ba9ba4Schristos mmix_elf_reloc (bfd *abfd,
1279a1ba9ba4Schristos arelent *reloc_entry,
1280a1ba9ba4Schristos asymbol *symbol,
1281a1ba9ba4Schristos void * data,
1282a1ba9ba4Schristos asection *input_section,
1283a1ba9ba4Schristos bfd *output_bfd,
1284a1ba9ba4Schristos char **error_message)
1285a1ba9ba4Schristos {
1286a1ba9ba4Schristos bfd_vma relocation;
1287a1ba9ba4Schristos bfd_reloc_status_type r;
1288a1ba9ba4Schristos asection *reloc_target_output_section;
1289a1ba9ba4Schristos bfd_reloc_status_type flag = bfd_reloc_ok;
1290a1ba9ba4Schristos bfd_vma output_base = 0;
1291a1ba9ba4Schristos
1292a1ba9ba4Schristos r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1293a1ba9ba4Schristos input_section, output_bfd, error_message);
1294a1ba9ba4Schristos
1295a1ba9ba4Schristos /* If that was all that was needed (i.e. this isn't a final link, only
1296a1ba9ba4Schristos some segment adjustments), we're done. */
1297a1ba9ba4Schristos if (r != bfd_reloc_continue)
1298a1ba9ba4Schristos return r;
1299a1ba9ba4Schristos
1300a1ba9ba4Schristos if (bfd_is_und_section (symbol->section)
1301a1ba9ba4Schristos && (symbol->flags & BSF_WEAK) == 0
1302a1ba9ba4Schristos && output_bfd == (bfd *) NULL)
1303a1ba9ba4Schristos return bfd_reloc_undefined;
1304a1ba9ba4Schristos
1305a1ba9ba4Schristos /* Is the address of the relocation really within the section? */
1306a1ba9ba4Schristos if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1307a1ba9ba4Schristos return bfd_reloc_outofrange;
1308a1ba9ba4Schristos
1309a1ba9ba4Schristos /* Work out which section the relocation is targeted at and the
1310a1ba9ba4Schristos initial relocation command value. */
1311a1ba9ba4Schristos
1312a1ba9ba4Schristos /* Get symbol value. (Common symbols are special.) */
1313a1ba9ba4Schristos if (bfd_is_com_section (symbol->section))
1314a1ba9ba4Schristos relocation = 0;
1315a1ba9ba4Schristos else
1316a1ba9ba4Schristos relocation = symbol->value;
1317a1ba9ba4Schristos
1318*184b2d41Schristos reloc_target_output_section = bfd_asymbol_section (symbol)->output_section;
1319a1ba9ba4Schristos
1320a1ba9ba4Schristos /* Here the variable relocation holds the final address of the symbol we
1321a1ba9ba4Schristos are relocating against, plus any addend. */
1322a1ba9ba4Schristos if (output_bfd)
1323a1ba9ba4Schristos output_base = 0;
1324a1ba9ba4Schristos else
1325a1ba9ba4Schristos output_base = reloc_target_output_section->vma;
1326a1ba9ba4Schristos
1327a1ba9ba4Schristos relocation += output_base + symbol->section->output_offset;
1328a1ba9ba4Schristos
1329a1ba9ba4Schristos if (output_bfd != (bfd *) NULL)
1330a1ba9ba4Schristos {
1331a1ba9ba4Schristos /* Add in supplied addend. */
1332a1ba9ba4Schristos relocation += reloc_entry->addend;
1333a1ba9ba4Schristos
1334a1ba9ba4Schristos /* This is a partial relocation, and we want to apply the
1335a1ba9ba4Schristos relocation to the reloc entry rather than the raw data.
1336a1ba9ba4Schristos Modify the reloc inplace to reflect what we now know. */
1337a1ba9ba4Schristos reloc_entry->addend = relocation;
1338a1ba9ba4Schristos reloc_entry->address += input_section->output_offset;
1339a1ba9ba4Schristos return flag;
1340a1ba9ba4Schristos }
1341a1ba9ba4Schristos
1342a1ba9ba4Schristos return mmix_final_link_relocate (reloc_entry->howto, input_section,
1343a1ba9ba4Schristos data, reloc_entry->address,
1344a1ba9ba4Schristos reloc_entry->addend, relocation,
1345a1ba9ba4Schristos bfd_asymbol_name (symbol),
1346a1ba9ba4Schristos reloc_target_output_section,
1347a1ba9ba4Schristos error_message);
1348a1ba9ba4Schristos }
1349a1ba9ba4Schristos
1350a1ba9ba4Schristos /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
1351a1ba9ba4Schristos for guidance if you're thinking of copying this. */
1352a1ba9ba4Schristos
1353a1ba9ba4Schristos static bfd_boolean
mmix_elf_relocate_section(bfd * output_bfd ATTRIBUTE_UNUSED,struct bfd_link_info * info,bfd * input_bfd,asection * input_section,bfd_byte * contents,Elf_Internal_Rela * relocs,Elf_Internal_Sym * local_syms,asection ** local_sections)1354a1ba9ba4Schristos mmix_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
1355a1ba9ba4Schristos struct bfd_link_info *info,
1356a1ba9ba4Schristos bfd *input_bfd,
1357a1ba9ba4Schristos asection *input_section,
1358a1ba9ba4Schristos bfd_byte *contents,
1359a1ba9ba4Schristos Elf_Internal_Rela *relocs,
1360a1ba9ba4Schristos Elf_Internal_Sym *local_syms,
1361a1ba9ba4Schristos asection **local_sections)
1362a1ba9ba4Schristos {
1363a1ba9ba4Schristos Elf_Internal_Shdr *symtab_hdr;
1364a1ba9ba4Schristos struct elf_link_hash_entry **sym_hashes;
1365a1ba9ba4Schristos Elf_Internal_Rela *rel;
1366a1ba9ba4Schristos Elf_Internal_Rela *relend;
1367a1ba9ba4Schristos bfd_size_type size;
1368a1ba9ba4Schristos size_t pjsno = 0;
1369a1ba9ba4Schristos
1370a1ba9ba4Schristos size = input_section->rawsize ? input_section->rawsize : input_section->size;
1371a1ba9ba4Schristos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1372a1ba9ba4Schristos sym_hashes = elf_sym_hashes (input_bfd);
1373a1ba9ba4Schristos relend = relocs + input_section->reloc_count;
1374a1ba9ba4Schristos
1375a1ba9ba4Schristos /* Zero the stub area before we start. */
1376a1ba9ba4Schristos if (input_section->rawsize != 0
1377a1ba9ba4Schristos && input_section->size > input_section->rawsize)
1378a1ba9ba4Schristos memset (contents + input_section->rawsize, 0,
1379a1ba9ba4Schristos input_section->size - input_section->rawsize);
1380a1ba9ba4Schristos
1381a1ba9ba4Schristos for (rel = relocs; rel < relend; rel ++)
1382a1ba9ba4Schristos {
1383a1ba9ba4Schristos reloc_howto_type *howto;
1384a1ba9ba4Schristos unsigned long r_symndx;
1385a1ba9ba4Schristos Elf_Internal_Sym *sym;
1386a1ba9ba4Schristos asection *sec;
1387a1ba9ba4Schristos struct elf_link_hash_entry *h;
1388a1ba9ba4Schristos bfd_vma relocation;
1389a1ba9ba4Schristos bfd_reloc_status_type r;
1390a1ba9ba4Schristos const char *name = NULL;
1391a1ba9ba4Schristos int r_type;
1392a1ba9ba4Schristos bfd_boolean undefined_signalled = FALSE;
1393a1ba9ba4Schristos
1394a1ba9ba4Schristos r_type = ELF64_R_TYPE (rel->r_info);
1395a1ba9ba4Schristos
1396a1ba9ba4Schristos if (r_type == R_MMIX_GNU_VTINHERIT
1397a1ba9ba4Schristos || r_type == R_MMIX_GNU_VTENTRY)
1398a1ba9ba4Schristos continue;
1399a1ba9ba4Schristos
1400a1ba9ba4Schristos r_symndx = ELF64_R_SYM (rel->r_info);
1401a1ba9ba4Schristos
1402a1ba9ba4Schristos howto = elf_mmix_howto_table + ELF64_R_TYPE (rel->r_info);
1403a1ba9ba4Schristos h = NULL;
1404a1ba9ba4Schristos sym = NULL;
1405a1ba9ba4Schristos sec = NULL;
1406a1ba9ba4Schristos
1407a1ba9ba4Schristos if (r_symndx < symtab_hdr->sh_info)
1408a1ba9ba4Schristos {
1409a1ba9ba4Schristos sym = local_syms + r_symndx;
1410a1ba9ba4Schristos sec = local_sections [r_symndx];
1411a1ba9ba4Schristos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1412a1ba9ba4Schristos
1413a1ba9ba4Schristos name = bfd_elf_string_from_elf_section (input_bfd,
1414a1ba9ba4Schristos symtab_hdr->sh_link,
1415a1ba9ba4Schristos sym->st_name);
1416a1ba9ba4Schristos if (name == NULL)
1417*184b2d41Schristos name = bfd_section_name (sec);
1418a1ba9ba4Schristos }
1419a1ba9ba4Schristos else
1420a1ba9ba4Schristos {
1421a1ba9ba4Schristos bfd_boolean unresolved_reloc, ignored;
1422a1ba9ba4Schristos
1423a1ba9ba4Schristos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1424a1ba9ba4Schristos r_symndx, symtab_hdr, sym_hashes,
1425a1ba9ba4Schristos h, sec, relocation,
1426a1ba9ba4Schristos unresolved_reloc, undefined_signalled,
1427a1ba9ba4Schristos ignored);
1428a1ba9ba4Schristos name = h->root.root.string;
1429a1ba9ba4Schristos }
1430a1ba9ba4Schristos
1431a1ba9ba4Schristos if (sec != NULL && discarded_section (sec))
1432a1ba9ba4Schristos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1433a1ba9ba4Schristos rel, 1, relend, howto, 0, contents);
1434a1ba9ba4Schristos
1435b2396a7bSchristos if (bfd_link_relocatable (info))
1436a1ba9ba4Schristos {
1437a1ba9ba4Schristos /* This is a relocatable link. For most relocs we don't have to
1438a1ba9ba4Schristos change anything, unless the reloc is against a section
1439a1ba9ba4Schristos symbol, in which case we have to adjust according to where
1440a1ba9ba4Schristos the section symbol winds up in the output section. */
1441a1ba9ba4Schristos if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1442a1ba9ba4Schristos rel->r_addend += sec->output_offset;
1443a1ba9ba4Schristos
1444a1ba9ba4Schristos /* For PUSHJ stub relocs however, we may need to change the
1445a1ba9ba4Schristos reloc and the section contents, if the reloc doesn't reach
1446a1ba9ba4Schristos beyond the end of the output section and previous stubs.
1447a1ba9ba4Schristos Then we change the section contents to be a PUSHJ to the end
1448a1ba9ba4Schristos of the input section plus stubs (we can do that without using
1449a1ba9ba4Schristos a reloc), and then we change the reloc to be a R_MMIX_PUSHJ
1450a1ba9ba4Schristos at the stub location. */
1451a1ba9ba4Schristos if (r_type == R_MMIX_PUSHJ_STUBBABLE)
1452a1ba9ba4Schristos {
1453a1ba9ba4Schristos /* We've already checked whether we need a stub; use that
1454a1ba9ba4Schristos knowledge. */
1455a1ba9ba4Schristos if (mmix_elf_section_data (input_section)->pjs.stub_size[pjsno]
1456a1ba9ba4Schristos != 0)
1457a1ba9ba4Schristos {
1458a1ba9ba4Schristos Elf_Internal_Rela relcpy;
1459a1ba9ba4Schristos
1460a1ba9ba4Schristos if (mmix_elf_section_data (input_section)
1461a1ba9ba4Schristos ->pjs.stub_size[pjsno] != MAX_PUSHJ_STUB_SIZE)
1462a1ba9ba4Schristos abort ();
1463a1ba9ba4Schristos
1464a1ba9ba4Schristos /* There's already a PUSHJ insn there, so just fill in
1465a1ba9ba4Schristos the offset bits to the stub. */
1466a1ba9ba4Schristos if (mmix_final_link_relocate (elf_mmix_howto_table
1467a1ba9ba4Schristos + R_MMIX_ADDR19,
1468a1ba9ba4Schristos input_section,
1469a1ba9ba4Schristos contents,
1470a1ba9ba4Schristos rel->r_offset,
1471a1ba9ba4Schristos 0,
1472a1ba9ba4Schristos input_section
1473a1ba9ba4Schristos ->output_section->vma
1474a1ba9ba4Schristos + input_section->output_offset
1475a1ba9ba4Schristos + size
1476a1ba9ba4Schristos + mmix_elf_section_data (input_section)
1477a1ba9ba4Schristos ->pjs.stub_offset,
1478a1ba9ba4Schristos NULL, NULL, NULL) != bfd_reloc_ok)
1479a1ba9ba4Schristos return FALSE;
1480a1ba9ba4Schristos
1481a1ba9ba4Schristos /* Put a JMP insn at the stub; it goes with the
1482a1ba9ba4Schristos R_MMIX_JMP reloc. */
1483a1ba9ba4Schristos bfd_put_32 (output_bfd, JMP_INSN_BYTE << 24,
1484a1ba9ba4Schristos contents
1485a1ba9ba4Schristos + size
1486a1ba9ba4Schristos + mmix_elf_section_data (input_section)
1487a1ba9ba4Schristos ->pjs.stub_offset);
1488a1ba9ba4Schristos
1489a1ba9ba4Schristos /* Change the reloc to be at the stub, and to a full
1490a1ba9ba4Schristos R_MMIX_JMP reloc. */
1491a1ba9ba4Schristos rel->r_info = ELF64_R_INFO (r_symndx, R_MMIX_JMP);
1492a1ba9ba4Schristos rel->r_offset
1493a1ba9ba4Schristos = (size
1494a1ba9ba4Schristos + mmix_elf_section_data (input_section)
1495a1ba9ba4Schristos ->pjs.stub_offset);
1496a1ba9ba4Schristos
1497a1ba9ba4Schristos mmix_elf_section_data (input_section)->pjs.stub_offset
1498a1ba9ba4Schristos += MAX_PUSHJ_STUB_SIZE;
1499a1ba9ba4Schristos
1500a1ba9ba4Schristos /* Shift this reloc to the end of the relocs to maintain
1501a1ba9ba4Schristos the r_offset sorted reloc order. */
1502a1ba9ba4Schristos relcpy = *rel;
1503a1ba9ba4Schristos memmove (rel, rel + 1, (char *) relend - (char *) rel);
1504a1ba9ba4Schristos relend[-1] = relcpy;
1505a1ba9ba4Schristos
1506a1ba9ba4Schristos /* Back up one reloc, or else we'd skip the next reloc
1507a1ba9ba4Schristos in turn. */
1508a1ba9ba4Schristos rel--;
1509a1ba9ba4Schristos }
1510a1ba9ba4Schristos
1511a1ba9ba4Schristos pjsno++;
1512a1ba9ba4Schristos }
1513a1ba9ba4Schristos continue;
1514a1ba9ba4Schristos }
1515a1ba9ba4Schristos
1516a1ba9ba4Schristos r = mmix_final_link_relocate (howto, input_section,
1517a1ba9ba4Schristos contents, rel->r_offset,
1518a1ba9ba4Schristos rel->r_addend, relocation, name, sec, NULL);
1519a1ba9ba4Schristos
1520a1ba9ba4Schristos if (r != bfd_reloc_ok)
1521a1ba9ba4Schristos {
1522a1ba9ba4Schristos const char * msg = (const char *) NULL;
1523a1ba9ba4Schristos
1524a1ba9ba4Schristos switch (r)
1525a1ba9ba4Schristos {
1526a1ba9ba4Schristos case bfd_reloc_overflow:
1527b2396a7bSchristos info->callbacks->reloc_overflow
1528a1ba9ba4Schristos (info, (h ? &h->root : NULL), name, howto->name,
1529a1ba9ba4Schristos (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1530a1ba9ba4Schristos break;
1531a1ba9ba4Schristos
1532a1ba9ba4Schristos case bfd_reloc_undefined:
1533a1ba9ba4Schristos /* We may have sent this message above. */
1534a1ba9ba4Schristos if (! undefined_signalled)
1535b2396a7bSchristos info->callbacks->undefined_symbol
1536b2396a7bSchristos (info, name, input_bfd, input_section, rel->r_offset, TRUE);
1537a1ba9ba4Schristos undefined_signalled = TRUE;
1538a1ba9ba4Schristos break;
1539a1ba9ba4Schristos
1540a1ba9ba4Schristos case bfd_reloc_outofrange:
1541a1ba9ba4Schristos msg = _("internal error: out of range error");
1542a1ba9ba4Schristos break;
1543a1ba9ba4Schristos
1544a1ba9ba4Schristos case bfd_reloc_notsupported:
1545a1ba9ba4Schristos msg = _("internal error: unsupported relocation error");
1546a1ba9ba4Schristos break;
1547a1ba9ba4Schristos
1548a1ba9ba4Schristos case bfd_reloc_dangerous:
1549a1ba9ba4Schristos msg = _("internal error: dangerous relocation");
1550a1ba9ba4Schristos break;
1551a1ba9ba4Schristos
1552a1ba9ba4Schristos default:
1553a1ba9ba4Schristos msg = _("internal error: unknown error");
1554a1ba9ba4Schristos break;
1555a1ba9ba4Schristos }
1556a1ba9ba4Schristos
1557a1ba9ba4Schristos if (msg)
1558b2396a7bSchristos (*info->callbacks->warning) (info, msg, name, input_bfd,
1559b2396a7bSchristos input_section, rel->r_offset);
1560a1ba9ba4Schristos }
1561a1ba9ba4Schristos }
1562a1ba9ba4Schristos
1563a1ba9ba4Schristos return TRUE;
1564a1ba9ba4Schristos }
1565a1ba9ba4Schristos
1566a1ba9ba4Schristos /* Perform a single relocation. By default we use the standard BFD
1567a1ba9ba4Schristos routines. A few relocs we have to do ourselves. */
1568a1ba9ba4Schristos
1569a1ba9ba4Schristos static bfd_reloc_status_type
mmix_final_link_relocate(reloc_howto_type * howto,asection * input_section,bfd_byte * contents,bfd_vma r_offset,bfd_signed_vma r_addend,bfd_vma relocation,const char * symname,asection * symsec,char ** error_message)1570a1ba9ba4Schristos mmix_final_link_relocate (reloc_howto_type *howto, asection *input_section,
1571a1ba9ba4Schristos bfd_byte *contents, bfd_vma r_offset,
1572a1ba9ba4Schristos bfd_signed_vma r_addend, bfd_vma relocation,
1573a1ba9ba4Schristos const char *symname, asection *symsec,
1574a1ba9ba4Schristos char **error_message)
1575a1ba9ba4Schristos {
1576a1ba9ba4Schristos bfd_reloc_status_type r = bfd_reloc_ok;
1577a1ba9ba4Schristos bfd_vma addr
1578a1ba9ba4Schristos = (input_section->output_section->vma
1579a1ba9ba4Schristos + input_section->output_offset
1580a1ba9ba4Schristos + r_offset);
1581a1ba9ba4Schristos bfd_signed_vma srel
1582a1ba9ba4Schristos = (bfd_signed_vma) relocation + r_addend;
1583a1ba9ba4Schristos
1584a1ba9ba4Schristos switch (howto->type)
1585a1ba9ba4Schristos {
1586a1ba9ba4Schristos /* All these are PC-relative. */
1587a1ba9ba4Schristos case R_MMIX_PUSHJ_STUBBABLE:
1588a1ba9ba4Schristos case R_MMIX_PUSHJ:
1589a1ba9ba4Schristos case R_MMIX_CBRANCH:
1590a1ba9ba4Schristos case R_MMIX_ADDR19:
1591a1ba9ba4Schristos case R_MMIX_GETA:
1592a1ba9ba4Schristos case R_MMIX_ADDR27:
1593a1ba9ba4Schristos case R_MMIX_JMP:
1594a1ba9ba4Schristos contents += r_offset;
1595a1ba9ba4Schristos
1596a1ba9ba4Schristos srel -= (input_section->output_section->vma
1597a1ba9ba4Schristos + input_section->output_offset
1598a1ba9ba4Schristos + r_offset);
1599a1ba9ba4Schristos
1600a1ba9ba4Schristos r = mmix_elf_perform_relocation (input_section, howto, contents,
1601a1ba9ba4Schristos addr, srel, error_message);
1602a1ba9ba4Schristos break;
1603a1ba9ba4Schristos
1604a1ba9ba4Schristos case R_MMIX_BASE_PLUS_OFFSET:
1605a1ba9ba4Schristos if (symsec == NULL)
1606a1ba9ba4Schristos return bfd_reloc_undefined;
1607a1ba9ba4Schristos
1608a1ba9ba4Schristos /* Check that we're not relocating against a register symbol. */
1609*184b2d41Schristos if (strcmp (bfd_section_name (symsec),
1610a1ba9ba4Schristos MMIX_REG_CONTENTS_SECTION_NAME) == 0
1611*184b2d41Schristos || strcmp (bfd_section_name (symsec),
1612a1ba9ba4Schristos MMIX_REG_SECTION_NAME) == 0)
1613a1ba9ba4Schristos {
1614a1ba9ba4Schristos /* Note: This is separated out into two messages in order
1615a1ba9ba4Schristos to ease the translation into other languages. */
1616a1ba9ba4Schristos if (symname == NULL || *symname == 0)
161715d8e94aSchristos _bfd_error_handler
161815d8e94aSchristos /* xgettext:c-format */
1619051580eeSchristos (_("%pB: base-plus-offset relocation against register symbol:"
1620051580eeSchristos " (unknown) in %pA"),
162115d8e94aSchristos input_section->owner, symsec);
1622a1ba9ba4Schristos else
162315d8e94aSchristos _bfd_error_handler
162415d8e94aSchristos /* xgettext:c-format */
1625051580eeSchristos (_("%pB: base-plus-offset relocation against register symbol:"
1626051580eeSchristos " %s in %pA"),
162715d8e94aSchristos input_section->owner, symname, symsec);
1628a1ba9ba4Schristos return bfd_reloc_overflow;
1629a1ba9ba4Schristos }
1630a1ba9ba4Schristos goto do_mmix_reloc;
1631a1ba9ba4Schristos
1632a1ba9ba4Schristos case R_MMIX_REG_OR_BYTE:
1633a1ba9ba4Schristos case R_MMIX_REG:
1634a1ba9ba4Schristos /* For now, we handle these alike. They must refer to an register
1635a1ba9ba4Schristos symbol, which is either relative to the register section and in
1636a1ba9ba4Schristos the range 0..255, or is in the register contents section with vma
1637a1ba9ba4Schristos regno * 8. */
1638a1ba9ba4Schristos
1639a1ba9ba4Schristos /* FIXME: A better way to check for reg contents section?
1640a1ba9ba4Schristos FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
1641a1ba9ba4Schristos if (symsec == NULL)
1642a1ba9ba4Schristos return bfd_reloc_undefined;
1643a1ba9ba4Schristos
1644*184b2d41Schristos if (strcmp (bfd_section_name (symsec),
1645a1ba9ba4Schristos MMIX_REG_CONTENTS_SECTION_NAME) == 0)
1646a1ba9ba4Schristos {
1647a1ba9ba4Schristos if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
1648a1ba9ba4Schristos {
1649a1ba9ba4Schristos /* The bfd_reloc_outofrange return value, though intuitively
1650a1ba9ba4Schristos a better value, will not get us an error. */
1651a1ba9ba4Schristos return bfd_reloc_overflow;
1652a1ba9ba4Schristos }
1653a1ba9ba4Schristos srel /= 8;
1654a1ba9ba4Schristos }
1655*184b2d41Schristos else if (strcmp (bfd_section_name (symsec),
1656a1ba9ba4Schristos MMIX_REG_SECTION_NAME) == 0)
1657a1ba9ba4Schristos {
1658a1ba9ba4Schristos if (srel < 0 || srel > 255)
1659a1ba9ba4Schristos /* The bfd_reloc_outofrange return value, though intuitively a
1660a1ba9ba4Schristos better value, will not get us an error. */
1661a1ba9ba4Schristos return bfd_reloc_overflow;
1662a1ba9ba4Schristos }
1663a1ba9ba4Schristos else
1664a1ba9ba4Schristos {
1665a1ba9ba4Schristos /* Note: This is separated out into two messages in order
1666a1ba9ba4Schristos to ease the translation into other languages. */
1667a1ba9ba4Schristos if (symname == NULL || *symname == 0)
166815d8e94aSchristos _bfd_error_handler
166915d8e94aSchristos /* xgettext:c-format */
1670051580eeSchristos (_("%pB: register relocation against non-register symbol:"
1671051580eeSchristos " (unknown) in %pA"),
167215d8e94aSchristos input_section->owner, symsec);
1673a1ba9ba4Schristos else
167415d8e94aSchristos _bfd_error_handler
167515d8e94aSchristos /* xgettext:c-format */
1676051580eeSchristos (_("%pB: register relocation against non-register symbol:"
1677051580eeSchristos " %s in %pA"),
167815d8e94aSchristos input_section->owner, symname, symsec);
1679a1ba9ba4Schristos
1680a1ba9ba4Schristos /* The bfd_reloc_outofrange return value, though intuitively a
1681a1ba9ba4Schristos better value, will not get us an error. */
1682a1ba9ba4Schristos return bfd_reloc_overflow;
1683a1ba9ba4Schristos }
1684a1ba9ba4Schristos do_mmix_reloc:
1685a1ba9ba4Schristos contents += r_offset;
1686a1ba9ba4Schristos r = mmix_elf_perform_relocation (input_section, howto, contents,
1687a1ba9ba4Schristos addr, srel, error_message);
1688a1ba9ba4Schristos break;
1689a1ba9ba4Schristos
1690a1ba9ba4Schristos case R_MMIX_LOCAL:
1691a1ba9ba4Schristos /* This isn't a real relocation, it's just an assertion that the
1692a1ba9ba4Schristos final relocation value corresponds to a local register. We
1693a1ba9ba4Schristos ignore the actual relocation; nothing is changed. */
1694a1ba9ba4Schristos {
1695a1ba9ba4Schristos asection *regsec
1696a1ba9ba4Schristos = bfd_get_section_by_name (input_section->output_section->owner,
1697a1ba9ba4Schristos MMIX_REG_CONTENTS_SECTION_NAME);
1698a1ba9ba4Schristos bfd_vma first_global;
1699a1ba9ba4Schristos
1700a1ba9ba4Schristos /* Check that this is an absolute value, or a reference to the
1701a1ba9ba4Schristos register contents section or the register (symbol) section.
1702a1ba9ba4Schristos Absolute numbers can get here as undefined section. Undefined
1703a1ba9ba4Schristos symbols are signalled elsewhere, so there's no conflict in us
1704a1ba9ba4Schristos accidentally handling it. */
1705a1ba9ba4Schristos if (!bfd_is_abs_section (symsec)
1706a1ba9ba4Schristos && !bfd_is_und_section (symsec)
1707*184b2d41Schristos && strcmp (bfd_section_name (symsec),
1708a1ba9ba4Schristos MMIX_REG_CONTENTS_SECTION_NAME) != 0
1709*184b2d41Schristos && strcmp (bfd_section_name (symsec),
1710a1ba9ba4Schristos MMIX_REG_SECTION_NAME) != 0)
1711a1ba9ba4Schristos {
171215d8e94aSchristos _bfd_error_handler
1713051580eeSchristos (_("%pB: directive LOCAL valid only with a register or absolute value"),
171415d8e94aSchristos input_section->owner);
1715a1ba9ba4Schristos
1716a1ba9ba4Schristos return bfd_reloc_overflow;
1717a1ba9ba4Schristos }
1718a1ba9ba4Schristos
1719a1ba9ba4Schristos /* If we don't have a register contents section, then $255 is the
1720a1ba9ba4Schristos first global register. */
1721a1ba9ba4Schristos if (regsec == NULL)
1722a1ba9ba4Schristos first_global = 255;
1723a1ba9ba4Schristos else
1724a1ba9ba4Schristos {
1725*184b2d41Schristos first_global = bfd_section_vma (regsec) / 8;
1726*184b2d41Schristos if (strcmp (bfd_section_name (symsec),
1727a1ba9ba4Schristos MMIX_REG_CONTENTS_SECTION_NAME) == 0)
1728a1ba9ba4Schristos {
1729a1ba9ba4Schristos if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
1730a1ba9ba4Schristos /* The bfd_reloc_outofrange return value, though
1731a1ba9ba4Schristos intuitively a better value, will not get us an error. */
1732a1ba9ba4Schristos return bfd_reloc_overflow;
1733a1ba9ba4Schristos srel /= 8;
1734a1ba9ba4Schristos }
1735a1ba9ba4Schristos }
1736a1ba9ba4Schristos
1737a1ba9ba4Schristos if ((bfd_vma) srel >= first_global)
1738a1ba9ba4Schristos {
1739a1ba9ba4Schristos /* FIXME: Better error message. */
174015d8e94aSchristos _bfd_error_handler
174115d8e94aSchristos /* xgettext:c-format */
1742051580eeSchristos (_("%pB: LOCAL directive: "
1743051580eeSchristos "register $%" PRId64 " is not a local register;"
1744051580eeSchristos " first global register is $%" PRId64),
1745051580eeSchristos input_section->owner, (int64_t) srel, (int64_t) first_global);
1746a1ba9ba4Schristos
1747a1ba9ba4Schristos return bfd_reloc_overflow;
1748a1ba9ba4Schristos }
1749a1ba9ba4Schristos }
1750a1ba9ba4Schristos r = bfd_reloc_ok;
1751a1ba9ba4Schristos break;
1752a1ba9ba4Schristos
1753a1ba9ba4Schristos default:
1754a1ba9ba4Schristos r = _bfd_final_link_relocate (howto, input_section->owner, input_section,
1755a1ba9ba4Schristos contents, r_offset,
1756a1ba9ba4Schristos relocation, r_addend);
1757a1ba9ba4Schristos }
1758a1ba9ba4Schristos
1759a1ba9ba4Schristos return r;
1760a1ba9ba4Schristos }
1761a1ba9ba4Schristos
1762a1ba9ba4Schristos /* Return the section that should be marked against GC for a given
1763a1ba9ba4Schristos relocation. */
1764a1ba9ba4Schristos
1765a1ba9ba4Schristos static asection *
mmix_elf_gc_mark_hook(asection * sec,struct bfd_link_info * info,Elf_Internal_Rela * rel,struct elf_link_hash_entry * h,Elf_Internal_Sym * sym)1766a1ba9ba4Schristos mmix_elf_gc_mark_hook (asection *sec,
1767a1ba9ba4Schristos struct bfd_link_info *info,
1768a1ba9ba4Schristos Elf_Internal_Rela *rel,
1769a1ba9ba4Schristos struct elf_link_hash_entry *h,
1770a1ba9ba4Schristos Elf_Internal_Sym *sym)
1771a1ba9ba4Schristos {
1772a1ba9ba4Schristos if (h != NULL)
1773a1ba9ba4Schristos switch (ELF64_R_TYPE (rel->r_info))
1774a1ba9ba4Schristos {
1775a1ba9ba4Schristos case R_MMIX_GNU_VTINHERIT:
1776a1ba9ba4Schristos case R_MMIX_GNU_VTENTRY:
1777a1ba9ba4Schristos return NULL;
1778a1ba9ba4Schristos }
1779a1ba9ba4Schristos
1780a1ba9ba4Schristos return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1781a1ba9ba4Schristos }
1782a1ba9ba4Schristos
1783a1ba9ba4Schristos /* Sort register relocs to come before expanding relocs. */
1784a1ba9ba4Schristos
1785a1ba9ba4Schristos static int
mmix_elf_sort_relocs(const void * p1,const void * p2)1786a1ba9ba4Schristos mmix_elf_sort_relocs (const void * p1, const void * p2)
1787a1ba9ba4Schristos {
1788a1ba9ba4Schristos const Elf_Internal_Rela *r1 = (const Elf_Internal_Rela *) p1;
1789a1ba9ba4Schristos const Elf_Internal_Rela *r2 = (const Elf_Internal_Rela *) p2;
1790a1ba9ba4Schristos int r1_is_reg, r2_is_reg;
1791a1ba9ba4Schristos
1792a1ba9ba4Schristos /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
1793a1ba9ba4Schristos insns. */
1794a1ba9ba4Schristos if ((r1->r_offset & ~(bfd_vma) 3) > (r2->r_offset & ~(bfd_vma) 3))
1795a1ba9ba4Schristos return 1;
1796a1ba9ba4Schristos else if ((r1->r_offset & ~(bfd_vma) 3) < (r2->r_offset & ~(bfd_vma) 3))
1797a1ba9ba4Schristos return -1;
1798a1ba9ba4Schristos
1799a1ba9ba4Schristos r1_is_reg
1800a1ba9ba4Schristos = (ELF64_R_TYPE (r1->r_info) == R_MMIX_REG_OR_BYTE
1801a1ba9ba4Schristos || ELF64_R_TYPE (r1->r_info) == R_MMIX_REG);
1802a1ba9ba4Schristos r2_is_reg
1803a1ba9ba4Schristos = (ELF64_R_TYPE (r2->r_info) == R_MMIX_REG_OR_BYTE
1804a1ba9ba4Schristos || ELF64_R_TYPE (r2->r_info) == R_MMIX_REG);
1805a1ba9ba4Schristos if (r1_is_reg != r2_is_reg)
1806a1ba9ba4Schristos return r2_is_reg - r1_is_reg;
1807a1ba9ba4Schristos
1808a1ba9ba4Schristos /* Neither or both are register relocs. Then sort on full offset. */
1809a1ba9ba4Schristos if (r1->r_offset > r2->r_offset)
1810a1ba9ba4Schristos return 1;
1811a1ba9ba4Schristos else if (r1->r_offset < r2->r_offset)
1812a1ba9ba4Schristos return -1;
1813a1ba9ba4Schristos return 0;
1814a1ba9ba4Schristos }
1815a1ba9ba4Schristos
1816a1ba9ba4Schristos /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
1817a1ba9ba4Schristos
1818a1ba9ba4Schristos static bfd_boolean
mmix_elf_check_common_relocs(bfd * abfd,struct bfd_link_info * info,asection * sec,const Elf_Internal_Rela * relocs)1819a1ba9ba4Schristos mmix_elf_check_common_relocs (bfd *abfd,
1820a1ba9ba4Schristos struct bfd_link_info *info,
1821a1ba9ba4Schristos asection *sec,
1822a1ba9ba4Schristos const Elf_Internal_Rela *relocs)
1823a1ba9ba4Schristos {
1824a1ba9ba4Schristos bfd *bpo_greg_owner = NULL;
1825a1ba9ba4Schristos asection *allocated_gregs_section = NULL;
1826a1ba9ba4Schristos struct bpo_greg_section_info *gregdata = NULL;
1827a1ba9ba4Schristos struct bpo_reloc_section_info *bpodata = NULL;
1828a1ba9ba4Schristos const Elf_Internal_Rela *rel;
1829a1ba9ba4Schristos const Elf_Internal_Rela *rel_end;
1830a1ba9ba4Schristos
1831a1ba9ba4Schristos /* We currently have to abuse this COFF-specific member, since there's
1832a1ba9ba4Schristos no target-machine-dedicated member. There's no alternative outside
1833a1ba9ba4Schristos the bfd_link_info struct; we can't specialize a hash-table since
1834a1ba9ba4Schristos they're different between ELF and mmo. */
1835a1ba9ba4Schristos bpo_greg_owner = (bfd *) info->base_file;
1836a1ba9ba4Schristos
1837a1ba9ba4Schristos rel_end = relocs + sec->reloc_count;
1838a1ba9ba4Schristos for (rel = relocs; rel < rel_end; rel++)
1839a1ba9ba4Schristos {
1840a1ba9ba4Schristos switch (ELF64_R_TYPE (rel->r_info))
1841a1ba9ba4Schristos {
1842a1ba9ba4Schristos /* This relocation causes a GREG allocation. We need to count
1843a1ba9ba4Schristos them, and we need to create a section for them, so we need an
1844a1ba9ba4Schristos object to fake as the owner of that section. We can't use
1845a1ba9ba4Schristos the ELF dynobj for this, since the ELF bits assume lots of
1846a1ba9ba4Schristos DSO-related stuff if that member is non-NULL. */
1847a1ba9ba4Schristos case R_MMIX_BASE_PLUS_OFFSET:
1848a1ba9ba4Schristos /* We don't do anything with this reloc for a relocatable link. */
1849b2396a7bSchristos if (bfd_link_relocatable (info))
1850a1ba9ba4Schristos break;
1851a1ba9ba4Schristos
1852a1ba9ba4Schristos if (bpo_greg_owner == NULL)
1853a1ba9ba4Schristos {
1854a1ba9ba4Schristos bpo_greg_owner = abfd;
1855a1ba9ba4Schristos info->base_file = bpo_greg_owner;
1856a1ba9ba4Schristos }
1857a1ba9ba4Schristos
1858a1ba9ba4Schristos if (allocated_gregs_section == NULL)
1859a1ba9ba4Schristos allocated_gregs_section
1860a1ba9ba4Schristos = bfd_get_section_by_name (bpo_greg_owner,
1861a1ba9ba4Schristos MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
1862a1ba9ba4Schristos
1863a1ba9ba4Schristos if (allocated_gregs_section == NULL)
1864a1ba9ba4Schristos {
1865a1ba9ba4Schristos allocated_gregs_section
1866a1ba9ba4Schristos = bfd_make_section_with_flags (bpo_greg_owner,
1867a1ba9ba4Schristos MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME,
1868a1ba9ba4Schristos (SEC_HAS_CONTENTS
1869a1ba9ba4Schristos | SEC_IN_MEMORY
1870a1ba9ba4Schristos | SEC_LINKER_CREATED));
1871a1ba9ba4Schristos /* Setting both SEC_ALLOC and SEC_LOAD means the section is
1872a1ba9ba4Schristos treated like any other section, and we'd get errors for
1873a1ba9ba4Schristos address overlap with the text section. Let's set none of
1874a1ba9ba4Schristos those flags, as that is what currently happens for usual
1875a1ba9ba4Schristos GREG allocations, and that works. */
1876a1ba9ba4Schristos if (allocated_gregs_section == NULL
1877*184b2d41Schristos || !bfd_set_section_alignment (allocated_gregs_section, 3))
1878a1ba9ba4Schristos return FALSE;
1879a1ba9ba4Schristos
1880a1ba9ba4Schristos gregdata = (struct bpo_greg_section_info *)
1881a1ba9ba4Schristos bfd_zalloc (bpo_greg_owner, sizeof (struct bpo_greg_section_info));
1882a1ba9ba4Schristos if (gregdata == NULL)
1883a1ba9ba4Schristos return FALSE;
1884a1ba9ba4Schristos mmix_elf_section_data (allocated_gregs_section)->bpo.greg
1885a1ba9ba4Schristos = gregdata;
1886a1ba9ba4Schristos }
1887a1ba9ba4Schristos else if (gregdata == NULL)
1888a1ba9ba4Schristos gregdata
1889a1ba9ba4Schristos = mmix_elf_section_data (allocated_gregs_section)->bpo.greg;
1890a1ba9ba4Schristos
1891a1ba9ba4Schristos /* Get ourselves some auxiliary info for the BPO-relocs. */
1892a1ba9ba4Schristos if (bpodata == NULL)
1893a1ba9ba4Schristos {
1894a1ba9ba4Schristos /* No use doing a separate iteration pass to find the upper
1895a1ba9ba4Schristos limit - just use the number of relocs. */
1896a1ba9ba4Schristos bpodata = (struct bpo_reloc_section_info *)
1897a1ba9ba4Schristos bfd_alloc (bpo_greg_owner,
1898a1ba9ba4Schristos sizeof (struct bpo_reloc_section_info)
1899a1ba9ba4Schristos * (sec->reloc_count + 1));
1900a1ba9ba4Schristos if (bpodata == NULL)
1901a1ba9ba4Schristos return FALSE;
1902a1ba9ba4Schristos mmix_elf_section_data (sec)->bpo.reloc = bpodata;
1903a1ba9ba4Schristos bpodata->first_base_plus_offset_reloc
1904a1ba9ba4Schristos = bpodata->bpo_index
1905a1ba9ba4Schristos = gregdata->n_max_bpo_relocs;
1906a1ba9ba4Schristos bpodata->bpo_greg_section
1907a1ba9ba4Schristos = allocated_gregs_section;
1908a1ba9ba4Schristos bpodata->n_bpo_relocs_this_section = 0;
1909a1ba9ba4Schristos }
1910a1ba9ba4Schristos
1911a1ba9ba4Schristos bpodata->n_bpo_relocs_this_section++;
1912a1ba9ba4Schristos gregdata->n_max_bpo_relocs++;
1913a1ba9ba4Schristos
1914a1ba9ba4Schristos /* We don't get another chance to set this before GC; we've not
1915a1ba9ba4Schristos set up any hook that runs before GC. */
1916a1ba9ba4Schristos gregdata->n_bpo_relocs
1917a1ba9ba4Schristos = gregdata->n_max_bpo_relocs;
1918a1ba9ba4Schristos break;
1919a1ba9ba4Schristos
1920a1ba9ba4Schristos case R_MMIX_PUSHJ_STUBBABLE:
1921a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.n_pushj_relocs++;
1922a1ba9ba4Schristos break;
1923a1ba9ba4Schristos }
1924a1ba9ba4Schristos }
1925a1ba9ba4Schristos
1926a1ba9ba4Schristos /* Allocate per-reloc stub storage and initialize it to the max stub
1927a1ba9ba4Schristos size. */
1928a1ba9ba4Schristos if (mmix_elf_section_data (sec)->pjs.n_pushj_relocs != 0)
1929a1ba9ba4Schristos {
1930a1ba9ba4Schristos size_t i;
1931a1ba9ba4Schristos
1932a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stub_size
1933a1ba9ba4Schristos = bfd_alloc (abfd, mmix_elf_section_data (sec)->pjs.n_pushj_relocs
1934a1ba9ba4Schristos * sizeof (mmix_elf_section_data (sec)
1935a1ba9ba4Schristos ->pjs.stub_size[0]));
1936a1ba9ba4Schristos if (mmix_elf_section_data (sec)->pjs.stub_size == NULL)
1937a1ba9ba4Schristos return FALSE;
1938a1ba9ba4Schristos
1939a1ba9ba4Schristos for (i = 0; i < mmix_elf_section_data (sec)->pjs.n_pushj_relocs; i++)
1940a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stub_size[i] = MAX_PUSHJ_STUB_SIZE;
1941a1ba9ba4Schristos }
1942a1ba9ba4Schristos
1943a1ba9ba4Schristos return TRUE;
1944a1ba9ba4Schristos }
1945a1ba9ba4Schristos
1946a1ba9ba4Schristos /* Look through the relocs for a section during the first phase. */
1947a1ba9ba4Schristos
1948a1ba9ba4Schristos static bfd_boolean
mmix_elf_check_relocs(bfd * abfd,struct bfd_link_info * info,asection * sec,const Elf_Internal_Rela * relocs)1949a1ba9ba4Schristos mmix_elf_check_relocs (bfd *abfd,
1950a1ba9ba4Schristos struct bfd_link_info *info,
1951a1ba9ba4Schristos asection *sec,
1952a1ba9ba4Schristos const Elf_Internal_Rela *relocs)
1953a1ba9ba4Schristos {
1954a1ba9ba4Schristos Elf_Internal_Shdr *symtab_hdr;
1955a1ba9ba4Schristos struct elf_link_hash_entry **sym_hashes;
1956a1ba9ba4Schristos const Elf_Internal_Rela *rel;
1957a1ba9ba4Schristos const Elf_Internal_Rela *rel_end;
1958a1ba9ba4Schristos
1959a1ba9ba4Schristos symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1960a1ba9ba4Schristos sym_hashes = elf_sym_hashes (abfd);
1961a1ba9ba4Schristos
1962a1ba9ba4Schristos /* First we sort the relocs so that any register relocs come before
1963a1ba9ba4Schristos expansion-relocs to the same insn. FIXME: Not done for mmo. */
1964a1ba9ba4Schristos qsort ((void *) relocs, sec->reloc_count, sizeof (Elf_Internal_Rela),
1965a1ba9ba4Schristos mmix_elf_sort_relocs);
1966a1ba9ba4Schristos
1967a1ba9ba4Schristos /* Do the common part. */
1968a1ba9ba4Schristos if (!mmix_elf_check_common_relocs (abfd, info, sec, relocs))
1969a1ba9ba4Schristos return FALSE;
1970a1ba9ba4Schristos
1971b2396a7bSchristos if (bfd_link_relocatable (info))
1972a1ba9ba4Schristos return TRUE;
1973a1ba9ba4Schristos
1974a1ba9ba4Schristos rel_end = relocs + sec->reloc_count;
1975a1ba9ba4Schristos for (rel = relocs; rel < rel_end; rel++)
1976a1ba9ba4Schristos {
1977a1ba9ba4Schristos struct elf_link_hash_entry *h;
1978a1ba9ba4Schristos unsigned long r_symndx;
1979a1ba9ba4Schristos
1980a1ba9ba4Schristos r_symndx = ELF64_R_SYM (rel->r_info);
1981a1ba9ba4Schristos if (r_symndx < symtab_hdr->sh_info)
1982a1ba9ba4Schristos h = NULL;
1983a1ba9ba4Schristos else
1984a1ba9ba4Schristos {
1985a1ba9ba4Schristos h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1986a1ba9ba4Schristos while (h->root.type == bfd_link_hash_indirect
1987a1ba9ba4Schristos || h->root.type == bfd_link_hash_warning)
1988a1ba9ba4Schristos h = (struct elf_link_hash_entry *) h->root.u.i.link;
1989a1ba9ba4Schristos }
1990a1ba9ba4Schristos
1991a1ba9ba4Schristos switch (ELF64_R_TYPE (rel->r_info))
1992a1ba9ba4Schristos {
1993a1ba9ba4Schristos /* This relocation describes the C++ object vtable hierarchy.
1994a1ba9ba4Schristos Reconstruct it for later use during GC. */
1995a1ba9ba4Schristos case R_MMIX_GNU_VTINHERIT:
1996a1ba9ba4Schristos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1997a1ba9ba4Schristos return FALSE;
1998a1ba9ba4Schristos break;
1999a1ba9ba4Schristos
2000a1ba9ba4Schristos /* This relocation describes which C++ vtable entries are actually
2001a1ba9ba4Schristos used. Record for later use during GC. */
2002a1ba9ba4Schristos case R_MMIX_GNU_VTENTRY:
2003*184b2d41Schristos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2004a1ba9ba4Schristos return FALSE;
2005a1ba9ba4Schristos break;
2006a1ba9ba4Schristos }
2007a1ba9ba4Schristos }
2008a1ba9ba4Schristos
2009a1ba9ba4Schristos return TRUE;
2010a1ba9ba4Schristos }
2011a1ba9ba4Schristos
2012a1ba9ba4Schristos /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
2013a1ba9ba4Schristos Copied from elf_link_add_object_symbols. */
2014a1ba9ba4Schristos
2015a1ba9ba4Schristos bfd_boolean
_bfd_mmix_check_all_relocs(bfd * abfd,struct bfd_link_info * info)2016a1ba9ba4Schristos _bfd_mmix_check_all_relocs (bfd *abfd, struct bfd_link_info *info)
2017a1ba9ba4Schristos {
2018a1ba9ba4Schristos asection *o;
2019a1ba9ba4Schristos
2020a1ba9ba4Schristos for (o = abfd->sections; o != NULL; o = o->next)
2021a1ba9ba4Schristos {
2022a1ba9ba4Schristos Elf_Internal_Rela *internal_relocs;
2023a1ba9ba4Schristos bfd_boolean ok;
2024a1ba9ba4Schristos
2025a1ba9ba4Schristos if ((o->flags & SEC_RELOC) == 0
2026a1ba9ba4Schristos || o->reloc_count == 0
2027a1ba9ba4Schristos || ((info->strip == strip_all || info->strip == strip_debugger)
2028a1ba9ba4Schristos && (o->flags & SEC_DEBUGGING) != 0)
2029a1ba9ba4Schristos || bfd_is_abs_section (o->output_section))
2030a1ba9ba4Schristos continue;
2031a1ba9ba4Schristos
2032a1ba9ba4Schristos internal_relocs
2033a1ba9ba4Schristos = _bfd_elf_link_read_relocs (abfd, o, NULL,
2034a1ba9ba4Schristos (Elf_Internal_Rela *) NULL,
2035a1ba9ba4Schristos info->keep_memory);
2036a1ba9ba4Schristos if (internal_relocs == NULL)
2037a1ba9ba4Schristos return FALSE;
2038a1ba9ba4Schristos
2039a1ba9ba4Schristos ok = mmix_elf_check_common_relocs (abfd, info, o, internal_relocs);
2040a1ba9ba4Schristos
2041a1ba9ba4Schristos if (! info->keep_memory)
2042a1ba9ba4Schristos free (internal_relocs);
2043a1ba9ba4Schristos
2044a1ba9ba4Schristos if (! ok)
2045a1ba9ba4Schristos return FALSE;
2046a1ba9ba4Schristos }
2047a1ba9ba4Schristos
2048a1ba9ba4Schristos return TRUE;
2049a1ba9ba4Schristos }
2050a1ba9ba4Schristos
2051a1ba9ba4Schristos /* Change symbols relative to the reg contents section to instead be to
2052a1ba9ba4Schristos the register section, and scale them down to correspond to the register
2053a1ba9ba4Schristos number. */
2054a1ba9ba4Schristos
2055a1ba9ba4Schristos static int
mmix_elf_link_output_symbol_hook(struct bfd_link_info * info ATTRIBUTE_UNUSED,const char * name ATTRIBUTE_UNUSED,Elf_Internal_Sym * sym,asection * input_sec,struct elf_link_hash_entry * h ATTRIBUTE_UNUSED)2056a1ba9ba4Schristos mmix_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2057a1ba9ba4Schristos const char *name ATTRIBUTE_UNUSED,
2058a1ba9ba4Schristos Elf_Internal_Sym *sym,
2059a1ba9ba4Schristos asection *input_sec,
2060a1ba9ba4Schristos struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2061a1ba9ba4Schristos {
2062a1ba9ba4Schristos if (input_sec != NULL
2063a1ba9ba4Schristos && input_sec->name != NULL
2064a1ba9ba4Schristos && ELF_ST_TYPE (sym->st_info) != STT_SECTION
2065a1ba9ba4Schristos && strcmp (input_sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
2066a1ba9ba4Schristos {
2067a1ba9ba4Schristos sym->st_value /= 8;
2068a1ba9ba4Schristos sym->st_shndx = SHN_REGISTER;
2069a1ba9ba4Schristos }
2070a1ba9ba4Schristos
2071a1ba9ba4Schristos return 1;
2072a1ba9ba4Schristos }
2073a1ba9ba4Schristos
2074a1ba9ba4Schristos /* We fake a register section that holds values that are register numbers.
2075a1ba9ba4Schristos Having a SHN_REGISTER and register section translates better to other
2076a1ba9ba4Schristos formats (e.g. mmo) than for example a STT_REGISTER attribute.
2077a1ba9ba4Schristos This section faking is based on a construct in elf32-mips.c. */
2078a1ba9ba4Schristos static asection mmix_elf_reg_section;
2079a1ba9ba4Schristos static asymbol mmix_elf_reg_section_symbol;
2080a1ba9ba4Schristos static asymbol *mmix_elf_reg_section_symbol_ptr;
2081a1ba9ba4Schristos
2082a1ba9ba4Schristos /* Handle the special section numbers that a symbol may use. */
2083a1ba9ba4Schristos
2084a1ba9ba4Schristos void
mmix_elf_symbol_processing(bfd * abfd ATTRIBUTE_UNUSED,asymbol * asym)2085b2396a7bSchristos mmix_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
2086a1ba9ba4Schristos {
2087a1ba9ba4Schristos elf_symbol_type *elfsym;
2088a1ba9ba4Schristos
2089a1ba9ba4Schristos elfsym = (elf_symbol_type *) asym;
2090a1ba9ba4Schristos switch (elfsym->internal_elf_sym.st_shndx)
2091a1ba9ba4Schristos {
2092a1ba9ba4Schristos case SHN_REGISTER:
2093a1ba9ba4Schristos if (mmix_elf_reg_section.name == NULL)
2094a1ba9ba4Schristos {
2095a1ba9ba4Schristos /* Initialize the register section. */
2096a1ba9ba4Schristos mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME;
2097a1ba9ba4Schristos mmix_elf_reg_section.flags = SEC_NO_FLAGS;
2098a1ba9ba4Schristos mmix_elf_reg_section.output_section = &mmix_elf_reg_section;
2099a1ba9ba4Schristos mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol;
2100a1ba9ba4Schristos mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr;
2101a1ba9ba4Schristos mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME;
2102a1ba9ba4Schristos mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM;
2103a1ba9ba4Schristos mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section;
2104a1ba9ba4Schristos mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol;
2105a1ba9ba4Schristos }
2106a1ba9ba4Schristos asym->section = &mmix_elf_reg_section;
2107a1ba9ba4Schristos break;
2108a1ba9ba4Schristos
2109a1ba9ba4Schristos default:
2110a1ba9ba4Schristos break;
2111a1ba9ba4Schristos }
2112a1ba9ba4Schristos }
2113a1ba9ba4Schristos
2114a1ba9ba4Schristos /* Given a BFD section, try to locate the corresponding ELF section
2115a1ba9ba4Schristos index. */
2116a1ba9ba4Schristos
2117a1ba9ba4Schristos static bfd_boolean
mmix_elf_section_from_bfd_section(bfd * abfd ATTRIBUTE_UNUSED,asection * sec,int * retval)2118a1ba9ba4Schristos mmix_elf_section_from_bfd_section (bfd * abfd ATTRIBUTE_UNUSED,
2119a1ba9ba4Schristos asection * sec,
2120a1ba9ba4Schristos int * retval)
2121a1ba9ba4Schristos {
2122*184b2d41Schristos if (strcmp (bfd_section_name (sec), MMIX_REG_SECTION_NAME) == 0)
2123a1ba9ba4Schristos *retval = SHN_REGISTER;
2124a1ba9ba4Schristos else
2125a1ba9ba4Schristos return FALSE;
2126a1ba9ba4Schristos
2127a1ba9ba4Schristos return TRUE;
2128a1ba9ba4Schristos }
2129a1ba9ba4Schristos
2130a1ba9ba4Schristos /* Hook called by the linker routine which adds symbols from an object
2131a1ba9ba4Schristos file. We must handle the special SHN_REGISTER section number here.
2132a1ba9ba4Schristos
2133a1ba9ba4Schristos We also check that we only have *one* each of the section-start
2134a1ba9ba4Schristos symbols, since otherwise having two with the same value would cause
2135a1ba9ba4Schristos them to be "merged", but with the contents serialized. */
2136a1ba9ba4Schristos
2137a1ba9ba4Schristos static bfd_boolean
mmix_elf_add_symbol_hook(bfd * abfd,struct bfd_link_info * info ATTRIBUTE_UNUSED,Elf_Internal_Sym * sym,const char ** namep ATTRIBUTE_UNUSED,flagword * flagsp ATTRIBUTE_UNUSED,asection ** secp,bfd_vma * valp ATTRIBUTE_UNUSED)2138a1ba9ba4Schristos mmix_elf_add_symbol_hook (bfd *abfd,
2139a1ba9ba4Schristos struct bfd_link_info *info ATTRIBUTE_UNUSED,
2140a1ba9ba4Schristos Elf_Internal_Sym *sym,
2141a1ba9ba4Schristos const char **namep ATTRIBUTE_UNUSED,
2142a1ba9ba4Schristos flagword *flagsp ATTRIBUTE_UNUSED,
2143a1ba9ba4Schristos asection **secp,
2144a1ba9ba4Schristos bfd_vma *valp ATTRIBUTE_UNUSED)
2145a1ba9ba4Schristos {
2146a1ba9ba4Schristos if (sym->st_shndx == SHN_REGISTER)
2147a1ba9ba4Schristos {
2148a1ba9ba4Schristos *secp = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
2149a1ba9ba4Schristos (*secp)->flags |= SEC_LINKER_CREATED;
2150a1ba9ba4Schristos }
2151a1ba9ba4Schristos else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.'
2152a1ba9ba4Schristos && CONST_STRNEQ (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX))
2153a1ba9ba4Schristos {
2154a1ba9ba4Schristos /* See if we have another one. */
2155a1ba9ba4Schristos struct bfd_link_hash_entry *h = bfd_link_hash_lookup (info->hash,
2156a1ba9ba4Schristos *namep,
2157a1ba9ba4Schristos FALSE,
2158a1ba9ba4Schristos FALSE,
2159a1ba9ba4Schristos FALSE);
2160a1ba9ba4Schristos
2161a1ba9ba4Schristos if (h != NULL && h->type != bfd_link_hash_undefined)
2162a1ba9ba4Schristos {
2163a1ba9ba4Schristos /* How do we get the asymbol (or really: the filename) from h?
2164a1ba9ba4Schristos h->u.def.section->owner is NULL. */
216515d8e94aSchristos _bfd_error_handler
216615d8e94aSchristos /* xgettext:c-format */
2167051580eeSchristos (_("%pB: error: multiple definition of `%s'; start of %s "
2168051580eeSchristos "is set in a earlier linked file"),
216915d8e94aSchristos abfd, *namep,
217015d8e94aSchristos *namep + strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX));
2171a1ba9ba4Schristos bfd_set_error (bfd_error_bad_value);
2172a1ba9ba4Schristos return FALSE;
2173a1ba9ba4Schristos }
2174a1ba9ba4Schristos }
2175a1ba9ba4Schristos
2176a1ba9ba4Schristos return TRUE;
2177a1ba9ba4Schristos }
2178a1ba9ba4Schristos
2179a1ba9ba4Schristos /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
2180a1ba9ba4Schristos
2181a1ba9ba4Schristos static bfd_boolean
mmix_elf_is_local_label_name(bfd * abfd,const char * name)2182a1ba9ba4Schristos mmix_elf_is_local_label_name (bfd *abfd, const char *name)
2183a1ba9ba4Schristos {
2184a1ba9ba4Schristos const char *colpos;
2185a1ba9ba4Schristos int digits;
2186a1ba9ba4Schristos
2187a1ba9ba4Schristos /* Also include the default local-label definition. */
2188a1ba9ba4Schristos if (_bfd_elf_is_local_label_name (abfd, name))
2189a1ba9ba4Schristos return TRUE;
2190a1ba9ba4Schristos
2191a1ba9ba4Schristos if (*name != 'L')
2192a1ba9ba4Schristos return FALSE;
2193a1ba9ba4Schristos
2194a1ba9ba4Schristos /* If there's no ":", or more than one, it's not a local symbol. */
2195a1ba9ba4Schristos colpos = strchr (name, ':');
2196a1ba9ba4Schristos if (colpos == NULL || strchr (colpos + 1, ':') != NULL)
2197a1ba9ba4Schristos return FALSE;
2198a1ba9ba4Schristos
2199a1ba9ba4Schristos /* Check that there are remaining characters and that they are digits. */
2200a1ba9ba4Schristos if (colpos[1] == 0)
2201a1ba9ba4Schristos return FALSE;
2202a1ba9ba4Schristos
2203a1ba9ba4Schristos digits = strspn (colpos + 1, "0123456789");
2204a1ba9ba4Schristos return digits != 0 && colpos[1 + digits] == 0;
2205a1ba9ba4Schristos }
2206a1ba9ba4Schristos
2207a1ba9ba4Schristos /* We get rid of the register section here. */
2208a1ba9ba4Schristos
2209a1ba9ba4Schristos bfd_boolean
mmix_elf_final_link(bfd * abfd,struct bfd_link_info * info)2210a1ba9ba4Schristos mmix_elf_final_link (bfd *abfd, struct bfd_link_info *info)
2211a1ba9ba4Schristos {
2212a1ba9ba4Schristos /* We never output a register section, though we create one for
2213a1ba9ba4Schristos temporary measures. Check that nobody entered contents into it. */
2214a1ba9ba4Schristos asection *reg_section;
2215a1ba9ba4Schristos
2216a1ba9ba4Schristos reg_section = bfd_get_section_by_name (abfd, MMIX_REG_SECTION_NAME);
2217a1ba9ba4Schristos
2218a1ba9ba4Schristos if (reg_section != NULL)
2219a1ba9ba4Schristos {
2220a1ba9ba4Schristos /* FIXME: Pass error state gracefully. */
2221*184b2d41Schristos if (bfd_section_flags (reg_section) & SEC_HAS_CONTENTS)
2222051580eeSchristos _bfd_abort (__FILE__, __LINE__, _("register section has contents\n"));
2223a1ba9ba4Schristos
2224a1ba9ba4Schristos /* Really remove the section, if it hasn't already been done. */
2225a1ba9ba4Schristos if (!bfd_section_removed_from_list (abfd, reg_section))
2226a1ba9ba4Schristos {
2227a1ba9ba4Schristos bfd_section_list_remove (abfd, reg_section);
2228a1ba9ba4Schristos --abfd->section_count;
2229a1ba9ba4Schristos }
2230a1ba9ba4Schristos }
2231a1ba9ba4Schristos
2232a1ba9ba4Schristos if (! bfd_elf_final_link (abfd, info))
2233a1ba9ba4Schristos return FALSE;
2234a1ba9ba4Schristos
2235a1ba9ba4Schristos /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
2236a1ba9ba4Schristos the regular linker machinery. We do it here, like other targets with
2237a1ba9ba4Schristos special sections. */
2238a1ba9ba4Schristos if (info->base_file != NULL)
2239a1ba9ba4Schristos {
2240a1ba9ba4Schristos asection *greg_section
2241a1ba9ba4Schristos = bfd_get_section_by_name ((bfd *) info->base_file,
2242a1ba9ba4Schristos MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2243a1ba9ba4Schristos if (!bfd_set_section_contents (abfd,
2244a1ba9ba4Schristos greg_section->output_section,
2245a1ba9ba4Schristos greg_section->contents,
2246a1ba9ba4Schristos (file_ptr) greg_section->output_offset,
2247a1ba9ba4Schristos greg_section->size))
2248a1ba9ba4Schristos return FALSE;
2249a1ba9ba4Schristos }
2250a1ba9ba4Schristos return TRUE;
2251a1ba9ba4Schristos }
2252a1ba9ba4Schristos
2253a1ba9ba4Schristos /* We need to include the maximum size of PUSHJ-stubs in the initial
2254a1ba9ba4Schristos section size. This is expected to shrink during linker relaxation. */
2255a1ba9ba4Schristos
2256a1ba9ba4Schristos static void
mmix_set_relaxable_size(bfd * abfd ATTRIBUTE_UNUSED,asection * sec,void * ptr)2257a1ba9ba4Schristos mmix_set_relaxable_size (bfd *abfd ATTRIBUTE_UNUSED,
2258a1ba9ba4Schristos asection *sec,
2259a1ba9ba4Schristos void *ptr)
2260a1ba9ba4Schristos {
2261a1ba9ba4Schristos struct bfd_link_info *info = ptr;
2262a1ba9ba4Schristos
2263a1ba9ba4Schristos /* Make sure we only do this for section where we know we want this,
2264a1ba9ba4Schristos otherwise we might end up resetting the size of COMMONs. */
2265a1ba9ba4Schristos if (mmix_elf_section_data (sec)->pjs.n_pushj_relocs == 0)
2266a1ba9ba4Schristos return;
2267a1ba9ba4Schristos
2268a1ba9ba4Schristos sec->rawsize = sec->size;
2269a1ba9ba4Schristos sec->size += (mmix_elf_section_data (sec)->pjs.n_pushj_relocs
2270a1ba9ba4Schristos * MAX_PUSHJ_STUB_SIZE);
2271a1ba9ba4Schristos
2272a1ba9ba4Schristos /* For use in relocatable link, we start with a max stubs size. See
2273a1ba9ba4Schristos mmix_elf_relax_section. */
2274b2396a7bSchristos if (bfd_link_relocatable (info) && sec->output_section)
2275a1ba9ba4Schristos mmix_elf_section_data (sec->output_section)->pjs.stubs_size_sum
2276a1ba9ba4Schristos += (mmix_elf_section_data (sec)->pjs.n_pushj_relocs
2277a1ba9ba4Schristos * MAX_PUSHJ_STUB_SIZE);
2278a1ba9ba4Schristos }
2279a1ba9ba4Schristos
2280a1ba9ba4Schristos /* Initialize stuff for the linker-generated GREGs to match
2281a1ba9ba4Schristos R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
2282a1ba9ba4Schristos
2283a1ba9ba4Schristos bfd_boolean
_bfd_mmix_before_linker_allocation(bfd * abfd ATTRIBUTE_UNUSED,struct bfd_link_info * info)2284a1ba9ba4Schristos _bfd_mmix_before_linker_allocation (bfd *abfd ATTRIBUTE_UNUSED,
2285a1ba9ba4Schristos struct bfd_link_info *info)
2286a1ba9ba4Schristos {
2287a1ba9ba4Schristos asection *bpo_gregs_section;
2288a1ba9ba4Schristos bfd *bpo_greg_owner;
2289a1ba9ba4Schristos struct bpo_greg_section_info *gregdata;
2290a1ba9ba4Schristos size_t n_gregs;
2291a1ba9ba4Schristos bfd_vma gregs_size;
2292a1ba9ba4Schristos size_t i;
2293a1ba9ba4Schristos size_t *bpo_reloc_indexes;
2294a1ba9ba4Schristos bfd *ibfd;
2295a1ba9ba4Schristos
2296a1ba9ba4Schristos /* Set the initial size of sections. */
2297a1ba9ba4Schristos for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2298a1ba9ba4Schristos bfd_map_over_sections (ibfd, mmix_set_relaxable_size, info);
2299a1ba9ba4Schristos
2300a1ba9ba4Schristos /* The bpo_greg_owner bfd is supposed to have been set by
2301a1ba9ba4Schristos mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
2302a1ba9ba4Schristos If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2303a1ba9ba4Schristos bpo_greg_owner = (bfd *) info->base_file;
2304a1ba9ba4Schristos if (bpo_greg_owner == NULL)
2305a1ba9ba4Schristos return TRUE;
2306a1ba9ba4Schristos
2307a1ba9ba4Schristos bpo_gregs_section
2308a1ba9ba4Schristos = bfd_get_section_by_name (bpo_greg_owner,
2309a1ba9ba4Schristos MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2310a1ba9ba4Schristos
2311a1ba9ba4Schristos if (bpo_gregs_section == NULL)
2312a1ba9ba4Schristos return TRUE;
2313a1ba9ba4Schristos
2314a1ba9ba4Schristos /* We use the target-data handle in the ELF section data. */
2315a1ba9ba4Schristos gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2316a1ba9ba4Schristos if (gregdata == NULL)
2317a1ba9ba4Schristos return FALSE;
2318a1ba9ba4Schristos
2319a1ba9ba4Schristos n_gregs = gregdata->n_bpo_relocs;
2320a1ba9ba4Schristos gregdata->n_allocated_bpo_gregs = n_gregs;
2321a1ba9ba4Schristos
2322a1ba9ba4Schristos /* When this reaches zero during relaxation, all entries have been
2323a1ba9ba4Schristos filled in and the size of the linker gregs can be calculated. */
2324a1ba9ba4Schristos gregdata->n_remaining_bpo_relocs_this_relaxation_round = n_gregs;
2325a1ba9ba4Schristos
2326a1ba9ba4Schristos /* Set the zeroth-order estimate for the GREGs size. */
2327a1ba9ba4Schristos gregs_size = n_gregs * 8;
2328a1ba9ba4Schristos
2329*184b2d41Schristos if (!bfd_set_section_size (bpo_gregs_section, gregs_size))
2330a1ba9ba4Schristos return FALSE;
2331a1ba9ba4Schristos
2332a1ba9ba4Schristos /* Allocate and set up the GREG arrays. They're filled in at relaxation
2333a1ba9ba4Schristos time. Note that we must use the max number ever noted for the array,
2334a1ba9ba4Schristos since the index numbers were created before GC. */
2335a1ba9ba4Schristos gregdata->reloc_request
2336a1ba9ba4Schristos = bfd_zalloc (bpo_greg_owner,
2337a1ba9ba4Schristos sizeof (struct bpo_reloc_request)
2338a1ba9ba4Schristos * gregdata->n_max_bpo_relocs);
2339a1ba9ba4Schristos
2340a1ba9ba4Schristos gregdata->bpo_reloc_indexes
2341a1ba9ba4Schristos = bpo_reloc_indexes
2342a1ba9ba4Schristos = bfd_alloc (bpo_greg_owner,
2343a1ba9ba4Schristos gregdata->n_max_bpo_relocs
2344a1ba9ba4Schristos * sizeof (size_t));
2345a1ba9ba4Schristos if (bpo_reloc_indexes == NULL)
2346a1ba9ba4Schristos return FALSE;
2347a1ba9ba4Schristos
2348a1ba9ba4Schristos /* The default order is an identity mapping. */
2349a1ba9ba4Schristos for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
2350a1ba9ba4Schristos {
2351a1ba9ba4Schristos bpo_reloc_indexes[i] = i;
2352a1ba9ba4Schristos gregdata->reloc_request[i].bpo_reloc_no = i;
2353a1ba9ba4Schristos }
2354a1ba9ba4Schristos
2355a1ba9ba4Schristos return TRUE;
2356a1ba9ba4Schristos }
2357a1ba9ba4Schristos
2358a1ba9ba4Schristos /* Fill in contents in the linker allocated gregs. Everything is
2359a1ba9ba4Schristos calculated at this point; we just move the contents into place here. */
2360a1ba9ba4Schristos
2361a1ba9ba4Schristos bfd_boolean
_bfd_mmix_after_linker_allocation(bfd * abfd ATTRIBUTE_UNUSED,struct bfd_link_info * link_info)2362a1ba9ba4Schristos _bfd_mmix_after_linker_allocation (bfd *abfd ATTRIBUTE_UNUSED,
2363a1ba9ba4Schristos struct bfd_link_info *link_info)
2364a1ba9ba4Schristos {
2365a1ba9ba4Schristos asection *bpo_gregs_section;
2366a1ba9ba4Schristos bfd *bpo_greg_owner;
2367a1ba9ba4Schristos struct bpo_greg_section_info *gregdata;
2368a1ba9ba4Schristos size_t n_gregs;
2369a1ba9ba4Schristos size_t i, j;
2370a1ba9ba4Schristos size_t lastreg;
2371a1ba9ba4Schristos bfd_byte *contents;
2372a1ba9ba4Schristos
2373a1ba9ba4Schristos /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
2374a1ba9ba4Schristos when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
2375a1ba9ba4Schristos object, there was no R_MMIX_BASE_PLUS_OFFSET. */
2376a1ba9ba4Schristos bpo_greg_owner = (bfd *) link_info->base_file;
2377a1ba9ba4Schristos if (bpo_greg_owner == NULL)
2378a1ba9ba4Schristos return TRUE;
2379a1ba9ba4Schristos
2380a1ba9ba4Schristos bpo_gregs_section
2381a1ba9ba4Schristos = bfd_get_section_by_name (bpo_greg_owner,
2382a1ba9ba4Schristos MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2383a1ba9ba4Schristos
2384a1ba9ba4Schristos /* This can't happen without DSO handling. When DSOs are handled
2385a1ba9ba4Schristos without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
2386a1ba9ba4Schristos section. */
2387a1ba9ba4Schristos if (bpo_gregs_section == NULL)
2388a1ba9ba4Schristos return TRUE;
2389a1ba9ba4Schristos
2390a1ba9ba4Schristos /* We use the target-data handle in the ELF section data. */
2391a1ba9ba4Schristos
2392a1ba9ba4Schristos gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2393a1ba9ba4Schristos if (gregdata == NULL)
2394a1ba9ba4Schristos return FALSE;
2395a1ba9ba4Schristos
2396a1ba9ba4Schristos n_gregs = gregdata->n_allocated_bpo_gregs;
2397a1ba9ba4Schristos
2398a1ba9ba4Schristos bpo_gregs_section->contents
2399a1ba9ba4Schristos = contents = bfd_alloc (bpo_greg_owner, bpo_gregs_section->size);
2400a1ba9ba4Schristos if (contents == NULL)
2401a1ba9ba4Schristos return FALSE;
2402a1ba9ba4Schristos
2403a1ba9ba4Schristos /* Sanity check: If these numbers mismatch, some relocation has not been
2404a1ba9ba4Schristos accounted for and the rest of gregdata is probably inconsistent.
2405a1ba9ba4Schristos It's a bug, but it's more helpful to identify it than segfaulting
2406a1ba9ba4Schristos below. */
2407a1ba9ba4Schristos if (gregdata->n_remaining_bpo_relocs_this_relaxation_round
2408a1ba9ba4Schristos != gregdata->n_bpo_relocs)
2409a1ba9ba4Schristos {
241015d8e94aSchristos _bfd_error_handler
241115d8e94aSchristos /* xgettext:c-format */
2412051580eeSchristos (_("internal inconsistency: remaining %lu != max %lu;"
2413051580eeSchristos " please report this bug"),
2414051580eeSchristos (unsigned long) gregdata->n_remaining_bpo_relocs_this_relaxation_round,
2415051580eeSchristos (unsigned long) gregdata->n_bpo_relocs);
2416a1ba9ba4Schristos return FALSE;
2417a1ba9ba4Schristos }
2418a1ba9ba4Schristos
2419a1ba9ba4Schristos for (lastreg = 255, i = 0, j = 0; j < n_gregs; i++)
2420a1ba9ba4Schristos if (gregdata->reloc_request[i].regindex != lastreg)
2421a1ba9ba4Schristos {
2422a1ba9ba4Schristos bfd_put_64 (bpo_greg_owner, gregdata->reloc_request[i].value,
2423a1ba9ba4Schristos contents + j * 8);
2424a1ba9ba4Schristos lastreg = gregdata->reloc_request[i].regindex;
2425a1ba9ba4Schristos j++;
2426a1ba9ba4Schristos }
2427a1ba9ba4Schristos
2428a1ba9ba4Schristos return TRUE;
2429a1ba9ba4Schristos }
2430a1ba9ba4Schristos
2431a1ba9ba4Schristos /* Sort valid relocs to come before non-valid relocs, then on increasing
2432a1ba9ba4Schristos value. */
2433a1ba9ba4Schristos
2434a1ba9ba4Schristos static int
bpo_reloc_request_sort_fn(const void * p1,const void * p2)2435a1ba9ba4Schristos bpo_reloc_request_sort_fn (const void * p1, const void * p2)
2436a1ba9ba4Schristos {
2437a1ba9ba4Schristos const struct bpo_reloc_request *r1 = (const struct bpo_reloc_request *) p1;
2438a1ba9ba4Schristos const struct bpo_reloc_request *r2 = (const struct bpo_reloc_request *) p2;
2439a1ba9ba4Schristos
2440a1ba9ba4Schristos /* Primary function is validity; non-valid relocs sorted after valid
2441a1ba9ba4Schristos ones. */
2442a1ba9ba4Schristos if (r1->valid != r2->valid)
2443a1ba9ba4Schristos return r2->valid - r1->valid;
2444a1ba9ba4Schristos
2445a1ba9ba4Schristos /* Then sort on value. Don't simplify and return just the difference of
2446a1ba9ba4Schristos the values: the upper bits of the 64-bit value would be truncated on
2447a1ba9ba4Schristos a host with 32-bit ints. */
2448a1ba9ba4Schristos if (r1->value != r2->value)
2449a1ba9ba4Schristos return r1->value > r2->value ? 1 : -1;
2450a1ba9ba4Schristos
2451a1ba9ba4Schristos /* As a last re-sort, use the relocation number, so we get a stable
2452a1ba9ba4Schristos sort. The *addresses* aren't stable since items are swapped during
2453a1ba9ba4Schristos sorting. It depends on the qsort implementation if this actually
2454a1ba9ba4Schristos happens. */
2455a1ba9ba4Schristos return r1->bpo_reloc_no > r2->bpo_reloc_no
2456a1ba9ba4Schristos ? 1 : (r1->bpo_reloc_no < r2->bpo_reloc_no ? -1 : 0);
2457a1ba9ba4Schristos }
2458a1ba9ba4Schristos
2459a1ba9ba4Schristos /* For debug use only. Dumps the global register allocations resulting
2460a1ba9ba4Schristos from base-plus-offset relocs. */
2461a1ba9ba4Schristos
2462a1ba9ba4Schristos void
mmix_dump_bpo_gregs(struct bfd_link_info * link_info,void (* pf)(const char * fmt,...))2463b2396a7bSchristos mmix_dump_bpo_gregs (struct bfd_link_info *link_info,
246415d8e94aSchristos void (*pf) (const char *fmt, ...))
2465a1ba9ba4Schristos {
2466a1ba9ba4Schristos bfd *bpo_greg_owner;
2467a1ba9ba4Schristos asection *bpo_gregs_section;
2468a1ba9ba4Schristos struct bpo_greg_section_info *gregdata;
2469a1ba9ba4Schristos unsigned int i;
2470a1ba9ba4Schristos
2471a1ba9ba4Schristos if (link_info == NULL || link_info->base_file == NULL)
2472a1ba9ba4Schristos return;
2473a1ba9ba4Schristos
2474a1ba9ba4Schristos bpo_greg_owner = (bfd *) link_info->base_file;
2475a1ba9ba4Schristos
2476a1ba9ba4Schristos bpo_gregs_section
2477a1ba9ba4Schristos = bfd_get_section_by_name (bpo_greg_owner,
2478a1ba9ba4Schristos MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
2479a1ba9ba4Schristos
2480a1ba9ba4Schristos if (bpo_gregs_section == NULL)
2481a1ba9ba4Schristos return;
2482a1ba9ba4Schristos
2483a1ba9ba4Schristos gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2484a1ba9ba4Schristos if (gregdata == NULL)
2485a1ba9ba4Schristos return;
2486a1ba9ba4Schristos
2487a1ba9ba4Schristos if (pf == NULL)
2488a1ba9ba4Schristos pf = _bfd_error_handler;
2489a1ba9ba4Schristos
2490a1ba9ba4Schristos /* These format strings are not translated. They are for debug purposes
2491a1ba9ba4Schristos only and never displayed to an end user. Should they escape, we
2492a1ba9ba4Schristos surely want them in original. */
2493a1ba9ba4Schristos (*pf) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
2494a1ba9ba4Schristos n_allocated_bpo_gregs: %u\n", gregdata->n_bpo_relocs,
2495a1ba9ba4Schristos gregdata->n_max_bpo_relocs,
2496a1ba9ba4Schristos gregdata->n_remaining_bpo_relocs_this_relaxation_round,
2497a1ba9ba4Schristos gregdata->n_allocated_bpo_gregs);
2498a1ba9ba4Schristos
2499a1ba9ba4Schristos if (gregdata->reloc_request)
2500a1ba9ba4Schristos for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
2501a1ba9ba4Schristos (*pf) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
2502a1ba9ba4Schristos i,
2503a1ba9ba4Schristos (gregdata->bpo_reloc_indexes != NULL
2504a1ba9ba4Schristos ? gregdata->bpo_reloc_indexes[i] : (size_t) -1),
2505a1ba9ba4Schristos gregdata->reloc_request[i].bpo_reloc_no,
2506a1ba9ba4Schristos gregdata->reloc_request[i].valid,
2507a1ba9ba4Schristos
2508a1ba9ba4Schristos (unsigned long) (gregdata->reloc_request[i].value >> 32),
2509a1ba9ba4Schristos (unsigned long) gregdata->reloc_request[i].value,
2510a1ba9ba4Schristos gregdata->reloc_request[i].regindex,
2511a1ba9ba4Schristos gregdata->reloc_request[i].offset);
2512a1ba9ba4Schristos }
2513a1ba9ba4Schristos
2514a1ba9ba4Schristos /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
2515a1ba9ba4Schristos when the last such reloc is done, an index-array is sorted according to
2516a1ba9ba4Schristos the values and iterated over to produce register numbers (indexed by 0
2517a1ba9ba4Schristos from the first allocated register number) and offsets for use in real
2518a1ba9ba4Schristos relocation. (N.B.: Relocatable runs are handled, not just punted.)
2519a1ba9ba4Schristos
2520a1ba9ba4Schristos PUSHJ stub accounting is also done here.
2521a1ba9ba4Schristos
2522a1ba9ba4Schristos Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
2523a1ba9ba4Schristos
2524a1ba9ba4Schristos static bfd_boolean
mmix_elf_relax_section(bfd * abfd,asection * sec,struct bfd_link_info * link_info,bfd_boolean * again)2525a1ba9ba4Schristos mmix_elf_relax_section (bfd *abfd,
2526a1ba9ba4Schristos asection *sec,
2527a1ba9ba4Schristos struct bfd_link_info *link_info,
2528a1ba9ba4Schristos bfd_boolean *again)
2529a1ba9ba4Schristos {
2530a1ba9ba4Schristos Elf_Internal_Shdr *symtab_hdr;
2531a1ba9ba4Schristos Elf_Internal_Rela *internal_relocs;
2532a1ba9ba4Schristos Elf_Internal_Rela *irel, *irelend;
2533a1ba9ba4Schristos asection *bpo_gregs_section = NULL;
2534a1ba9ba4Schristos struct bpo_greg_section_info *gregdata;
2535a1ba9ba4Schristos struct bpo_reloc_section_info *bpodata
2536a1ba9ba4Schristos = mmix_elf_section_data (sec)->bpo.reloc;
2537a1ba9ba4Schristos /* The initialization is to quiet compiler warnings. The value is to
2538a1ba9ba4Schristos spot a missing actual initialization. */
2539a1ba9ba4Schristos size_t bpono = (size_t) -1;
2540a1ba9ba4Schristos size_t pjsno = 0;
2541*184b2d41Schristos size_t pjsno_undefs = 0;
2542a1ba9ba4Schristos Elf_Internal_Sym *isymbuf = NULL;
2543a1ba9ba4Schristos bfd_size_type size = sec->rawsize ? sec->rawsize : sec->size;
2544a1ba9ba4Schristos
2545a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stubs_size_sum = 0;
2546a1ba9ba4Schristos
2547a1ba9ba4Schristos /* Assume nothing changes. */
2548a1ba9ba4Schristos *again = FALSE;
2549a1ba9ba4Schristos
2550a1ba9ba4Schristos /* We don't have to do anything if this section does not have relocs, or
2551a1ba9ba4Schristos if this is not a code section. */
2552a1ba9ba4Schristos if ((sec->flags & SEC_RELOC) == 0
2553a1ba9ba4Schristos || sec->reloc_count == 0
2554a1ba9ba4Schristos || (sec->flags & SEC_CODE) == 0
2555a1ba9ba4Schristos || (sec->flags & SEC_LINKER_CREATED) != 0
2556a1ba9ba4Schristos /* If no R_MMIX_BASE_PLUS_OFFSET relocs and no PUSHJ-stub relocs,
2557a1ba9ba4Schristos then nothing to do. */
2558a1ba9ba4Schristos || (bpodata == NULL
2559a1ba9ba4Schristos && mmix_elf_section_data (sec)->pjs.n_pushj_relocs == 0))
2560a1ba9ba4Schristos return TRUE;
2561a1ba9ba4Schristos
2562a1ba9ba4Schristos symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2563a1ba9ba4Schristos
2564a1ba9ba4Schristos if (bpodata != NULL)
2565a1ba9ba4Schristos {
2566a1ba9ba4Schristos bpo_gregs_section = bpodata->bpo_greg_section;
2567a1ba9ba4Schristos gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
2568a1ba9ba4Schristos bpono = bpodata->first_base_plus_offset_reloc;
2569a1ba9ba4Schristos }
2570a1ba9ba4Schristos else
2571a1ba9ba4Schristos gregdata = NULL;
2572a1ba9ba4Schristos
2573a1ba9ba4Schristos /* Get a copy of the native relocations. */
2574a1ba9ba4Schristos internal_relocs
2575a1ba9ba4Schristos = _bfd_elf_link_read_relocs (abfd, sec, NULL,
2576a1ba9ba4Schristos (Elf_Internal_Rela *) NULL,
2577a1ba9ba4Schristos link_info->keep_memory);
2578a1ba9ba4Schristos if (internal_relocs == NULL)
2579a1ba9ba4Schristos goto error_return;
2580a1ba9ba4Schristos
2581a1ba9ba4Schristos /* Walk through them looking for relaxing opportunities. */
2582a1ba9ba4Schristos irelend = internal_relocs + sec->reloc_count;
2583a1ba9ba4Schristos for (irel = internal_relocs; irel < irelend; irel++)
2584a1ba9ba4Schristos {
2585a1ba9ba4Schristos bfd_vma symval;
2586a1ba9ba4Schristos struct elf_link_hash_entry *h = NULL;
2587a1ba9ba4Schristos
2588a1ba9ba4Schristos /* We only process two relocs. */
2589a1ba9ba4Schristos if (ELF64_R_TYPE (irel->r_info) != (int) R_MMIX_BASE_PLUS_OFFSET
2590a1ba9ba4Schristos && ELF64_R_TYPE (irel->r_info) != (int) R_MMIX_PUSHJ_STUBBABLE)
2591a1ba9ba4Schristos continue;
2592a1ba9ba4Schristos
2593a1ba9ba4Schristos /* We process relocs in a distinctly different way when this is a
2594a1ba9ba4Schristos relocatable link (for one, we don't look at symbols), so we avoid
2595a1ba9ba4Schristos mixing its code with that for the "normal" relaxation. */
2596b2396a7bSchristos if (bfd_link_relocatable (link_info))
2597a1ba9ba4Schristos {
2598a1ba9ba4Schristos /* The only transformation in a relocatable link is to generate
2599a1ba9ba4Schristos a full stub at the location of the stub calculated for the
2600a1ba9ba4Schristos input section, if the relocated stub location, the end of the
2601a1ba9ba4Schristos output section plus earlier stubs, cannot be reached. Thus
2602a1ba9ba4Schristos relocatable linking can only lead to worse code, but it still
2603a1ba9ba4Schristos works. */
2604a1ba9ba4Schristos if (ELF64_R_TYPE (irel->r_info) == R_MMIX_PUSHJ_STUBBABLE)
2605a1ba9ba4Schristos {
2606a1ba9ba4Schristos /* If we can reach the end of the output-section and beyond
2607a1ba9ba4Schristos any current stubs, then we don't need a stub for this
2608a1ba9ba4Schristos reloc. The relaxed order of output stub allocation may
2609a1ba9ba4Schristos not exactly match the straightforward order, so we always
2610a1ba9ba4Schristos assume presence of output stubs, which will allow
2611a1ba9ba4Schristos relaxation only on relocations indifferent to the
2612a1ba9ba4Schristos presence of output stub allocations for other relocations
2613a1ba9ba4Schristos and thus the order of output stub allocation. */
2614a1ba9ba4Schristos if (bfd_check_overflow (complain_overflow_signed,
2615a1ba9ba4Schristos 19,
2616a1ba9ba4Schristos 0,
2617a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
2618a1ba9ba4Schristos /* Output-stub location. */
2619a1ba9ba4Schristos sec->output_section->rawsize
2620a1ba9ba4Schristos + (mmix_elf_section_data (sec
2621a1ba9ba4Schristos ->output_section)
2622a1ba9ba4Schristos ->pjs.stubs_size_sum)
2623a1ba9ba4Schristos /* Location of this PUSHJ reloc. */
2624a1ba9ba4Schristos - (sec->output_offset + irel->r_offset)
2625a1ba9ba4Schristos /* Don't count *this* stub twice. */
2626a1ba9ba4Schristos - (mmix_elf_section_data (sec)
2627a1ba9ba4Schristos ->pjs.stub_size[pjsno]
2628a1ba9ba4Schristos + MAX_PUSHJ_STUB_SIZE))
2629a1ba9ba4Schristos == bfd_reloc_ok)
2630a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stub_size[pjsno] = 0;
2631a1ba9ba4Schristos
2632a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stubs_size_sum
2633a1ba9ba4Schristos += mmix_elf_section_data (sec)->pjs.stub_size[pjsno];
2634a1ba9ba4Schristos
2635a1ba9ba4Schristos pjsno++;
2636a1ba9ba4Schristos }
2637a1ba9ba4Schristos
2638a1ba9ba4Schristos continue;
2639a1ba9ba4Schristos }
2640a1ba9ba4Schristos
2641a1ba9ba4Schristos /* Get the value of the symbol referred to by the reloc. */
2642a1ba9ba4Schristos if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2643a1ba9ba4Schristos {
2644a1ba9ba4Schristos /* A local symbol. */
2645a1ba9ba4Schristos Elf_Internal_Sym *isym;
2646a1ba9ba4Schristos asection *sym_sec;
2647a1ba9ba4Schristos
2648a1ba9ba4Schristos /* Read this BFD's local symbols if we haven't already. */
2649a1ba9ba4Schristos if (isymbuf == NULL)
2650a1ba9ba4Schristos {
2651a1ba9ba4Schristos isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2652a1ba9ba4Schristos if (isymbuf == NULL)
2653a1ba9ba4Schristos isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2654a1ba9ba4Schristos symtab_hdr->sh_info, 0,
2655a1ba9ba4Schristos NULL, NULL, NULL);
2656a1ba9ba4Schristos if (isymbuf == 0)
2657a1ba9ba4Schristos goto error_return;
2658a1ba9ba4Schristos }
2659a1ba9ba4Schristos
2660a1ba9ba4Schristos isym = isymbuf + ELF64_R_SYM (irel->r_info);
2661a1ba9ba4Schristos if (isym->st_shndx == SHN_UNDEF)
2662a1ba9ba4Schristos sym_sec = bfd_und_section_ptr;
2663a1ba9ba4Schristos else if (isym->st_shndx == SHN_ABS)
2664a1ba9ba4Schristos sym_sec = bfd_abs_section_ptr;
2665a1ba9ba4Schristos else if (isym->st_shndx == SHN_COMMON)
2666a1ba9ba4Schristos sym_sec = bfd_com_section_ptr;
2667a1ba9ba4Schristos else
2668a1ba9ba4Schristos sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2669a1ba9ba4Schristos symval = (isym->st_value
2670a1ba9ba4Schristos + sym_sec->output_section->vma
2671a1ba9ba4Schristos + sym_sec->output_offset);
2672a1ba9ba4Schristos }
2673a1ba9ba4Schristos else
2674a1ba9ba4Schristos {
2675a1ba9ba4Schristos unsigned long indx;
2676a1ba9ba4Schristos
2677a1ba9ba4Schristos /* An external symbol. */
2678a1ba9ba4Schristos indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2679a1ba9ba4Schristos h = elf_sym_hashes (abfd)[indx];
2680a1ba9ba4Schristos BFD_ASSERT (h != NULL);
2681051580eeSchristos if (h->root.type == bfd_link_hash_undefweak)
2682051580eeSchristos /* FIXME: for R_MMIX_PUSHJ_STUBBABLE, there are alternatives to
2683051580eeSchristos the canonical value 0 for an unresolved weak symbol to
2684051580eeSchristos consider: as the debug-friendly approach, resolve to "abort"
2685051580eeSchristos (or a port-specific function), or as the space-friendly
2686051580eeSchristos approach resolve to the next instruction (like some other
2687051580eeSchristos ports, notably ARM and AArch64). These alternatives require
2688051580eeSchristos matching code in mmix_elf_perform_relocation or its caller. */
2689051580eeSchristos symval = 0;
2690051580eeSchristos else if (h->root.type == bfd_link_hash_defined
2691051580eeSchristos || h->root.type == bfd_link_hash_defweak)
2692051580eeSchristos symval = (h->root.u.def.value
2693051580eeSchristos + h->root.u.def.section->output_section->vma
2694051580eeSchristos + h->root.u.def.section->output_offset);
2695051580eeSchristos else
2696a1ba9ba4Schristos {
2697a1ba9ba4Schristos /* This appears to be a reference to an undefined symbol. Just
2698a1ba9ba4Schristos ignore it--it will be caught by the regular reloc processing.
2699a1ba9ba4Schristos We need to keep BPO reloc accounting consistent, though
2700a1ba9ba4Schristos else we'll abort instead of emitting an error message. */
2701a1ba9ba4Schristos if (ELF64_R_TYPE (irel->r_info) == R_MMIX_BASE_PLUS_OFFSET
2702a1ba9ba4Schristos && gregdata != NULL)
2703a1ba9ba4Schristos {
2704a1ba9ba4Schristos gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
2705a1ba9ba4Schristos bpono++;
2706a1ba9ba4Schristos }
2707*184b2d41Schristos
2708*184b2d41Schristos /* Similarly, keep accounting consistent for PUSHJ
2709*184b2d41Schristos referring to an undefined symbol. */
2710*184b2d41Schristos if (ELF64_R_TYPE (irel->r_info) == R_MMIX_PUSHJ_STUBBABLE)
2711*184b2d41Schristos pjsno_undefs++;
2712a1ba9ba4Schristos continue;
2713a1ba9ba4Schristos }
2714a1ba9ba4Schristos }
2715a1ba9ba4Schristos
2716a1ba9ba4Schristos if (ELF64_R_TYPE (irel->r_info) == (int) R_MMIX_PUSHJ_STUBBABLE)
2717a1ba9ba4Schristos {
2718a1ba9ba4Schristos bfd_vma value = symval + irel->r_addend;
2719a1ba9ba4Schristos bfd_vma dot
2720a1ba9ba4Schristos = (sec->output_section->vma
2721a1ba9ba4Schristos + sec->output_offset
2722a1ba9ba4Schristos + irel->r_offset);
2723a1ba9ba4Schristos bfd_vma stubaddr
2724a1ba9ba4Schristos = (sec->output_section->vma
2725a1ba9ba4Schristos + sec->output_offset
2726a1ba9ba4Schristos + size
2727a1ba9ba4Schristos + mmix_elf_section_data (sec)->pjs.stubs_size_sum);
2728a1ba9ba4Schristos
2729a1ba9ba4Schristos if ((value & 3) == 0
2730a1ba9ba4Schristos && bfd_check_overflow (complain_overflow_signed,
2731a1ba9ba4Schristos 19,
2732a1ba9ba4Schristos 0,
2733a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
2734a1ba9ba4Schristos value - dot
2735a1ba9ba4Schristos - (value > dot
2736a1ba9ba4Schristos ? mmix_elf_section_data (sec)
2737a1ba9ba4Schristos ->pjs.stub_size[pjsno]
2738a1ba9ba4Schristos : 0))
2739a1ba9ba4Schristos == bfd_reloc_ok)
2740a1ba9ba4Schristos /* If the reloc fits, no stub is needed. */
2741a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stub_size[pjsno] = 0;
2742a1ba9ba4Schristos else
2743a1ba9ba4Schristos /* Maybe we can get away with just a JMP insn? */
2744a1ba9ba4Schristos if ((value & 3) == 0
2745a1ba9ba4Schristos && bfd_check_overflow (complain_overflow_signed,
2746a1ba9ba4Schristos 27,
2747a1ba9ba4Schristos 0,
2748a1ba9ba4Schristos bfd_arch_bits_per_address (abfd),
2749a1ba9ba4Schristos value - stubaddr
2750a1ba9ba4Schristos - (value > dot
2751a1ba9ba4Schristos ? mmix_elf_section_data (sec)
2752a1ba9ba4Schristos ->pjs.stub_size[pjsno] - 4
2753a1ba9ba4Schristos : 0))
2754a1ba9ba4Schristos == bfd_reloc_ok)
2755a1ba9ba4Schristos /* Yep, account for a stub consisting of a single JMP insn. */
2756a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stub_size[pjsno] = 4;
2757a1ba9ba4Schristos else
2758a1ba9ba4Schristos /* Nope, go for the full insn stub. It doesn't seem useful to
2759a1ba9ba4Schristos emit the intermediate sizes; those will only be useful for
2760a1ba9ba4Schristos a >64M program assuming contiguous code. */
2761a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stub_size[pjsno]
2762a1ba9ba4Schristos = MAX_PUSHJ_STUB_SIZE;
2763a1ba9ba4Schristos
2764a1ba9ba4Schristos mmix_elf_section_data (sec)->pjs.stubs_size_sum
2765a1ba9ba4Schristos += mmix_elf_section_data (sec)->pjs.stub_size[pjsno];
2766a1ba9ba4Schristos pjsno++;
2767a1ba9ba4Schristos continue;
2768a1ba9ba4Schristos }
2769a1ba9ba4Schristos
2770a1ba9ba4Schristos /* We're looking at a R_MMIX_BASE_PLUS_OFFSET reloc. */
2771a1ba9ba4Schristos
2772a1ba9ba4Schristos gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono]].value
2773a1ba9ba4Schristos = symval + irel->r_addend;
2774a1ba9ba4Schristos gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono++]].valid = TRUE;
2775a1ba9ba4Schristos gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
2776a1ba9ba4Schristos }
2777a1ba9ba4Schristos
2778a1ba9ba4Schristos /* Check if that was the last BPO-reloc. If so, sort the values and
2779a1ba9ba4Schristos calculate how many registers we need to cover them. Set the size of
2780a1ba9ba4Schristos the linker gregs, and if the number of registers changed, indicate
2781a1ba9ba4Schristos that we need to relax some more because we have more work to do. */
2782a1ba9ba4Schristos if (gregdata != NULL
2783a1ba9ba4Schristos && gregdata->n_remaining_bpo_relocs_this_relaxation_round == 0)
2784a1ba9ba4Schristos {
2785a1ba9ba4Schristos size_t i;
2786a1ba9ba4Schristos bfd_vma prev_base;
2787a1ba9ba4Schristos size_t regindex;
2788a1ba9ba4Schristos
2789a1ba9ba4Schristos /* First, reset the remaining relocs for the next round. */
2790a1ba9ba4Schristos gregdata->n_remaining_bpo_relocs_this_relaxation_round
2791a1ba9ba4Schristos = gregdata->n_bpo_relocs;
2792a1ba9ba4Schristos
2793a1ba9ba4Schristos qsort (gregdata->reloc_request,
2794a1ba9ba4Schristos gregdata->n_max_bpo_relocs,
2795a1ba9ba4Schristos sizeof (struct bpo_reloc_request),
2796a1ba9ba4Schristos bpo_reloc_request_sort_fn);
2797a1ba9ba4Schristos
2798a1ba9ba4Schristos /* Recalculate indexes. When we find a change (however unlikely
2799a1ba9ba4Schristos after the initial iteration), we know we need to relax again,
2800a1ba9ba4Schristos since items in the GREG-array are sorted by increasing value and
2801a1ba9ba4Schristos stored in the relaxation phase. */
2802a1ba9ba4Schristos for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
2803a1ba9ba4Schristos if (gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
2804a1ba9ba4Schristos != i)
2805a1ba9ba4Schristos {
2806a1ba9ba4Schristos gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
2807a1ba9ba4Schristos = i;
2808a1ba9ba4Schristos *again = TRUE;
2809a1ba9ba4Schristos }
2810a1ba9ba4Schristos
2811a1ba9ba4Schristos /* Allocate register numbers (indexing from 0). Stop at the first
2812a1ba9ba4Schristos non-valid reloc. */
2813a1ba9ba4Schristos for (i = 0, regindex = 0, prev_base = gregdata->reloc_request[0].value;
2814a1ba9ba4Schristos i < gregdata->n_bpo_relocs;
2815a1ba9ba4Schristos i++)
2816a1ba9ba4Schristos {
2817a1ba9ba4Schristos if (gregdata->reloc_request[i].value > prev_base + 255)
2818a1ba9ba4Schristos {
2819a1ba9ba4Schristos regindex++;
2820a1ba9ba4Schristos prev_base = gregdata->reloc_request[i].value;
2821a1ba9ba4Schristos }
2822a1ba9ba4Schristos gregdata->reloc_request[i].regindex = regindex;
2823a1ba9ba4Schristos gregdata->reloc_request[i].offset
2824a1ba9ba4Schristos = gregdata->reloc_request[i].value - prev_base;
2825a1ba9ba4Schristos }
2826a1ba9ba4Schristos
2827a1ba9ba4Schristos /* If it's not the same as the last time, we need to relax again,
2828a1ba9ba4Schristos because the size of the section has changed. I'm not sure we
2829a1ba9ba4Schristos actually need to do any adjustments since the shrinking happens
2830a1ba9ba4Schristos at the start of this section, but better safe than sorry. */
2831a1ba9ba4Schristos if (gregdata->n_allocated_bpo_gregs != regindex + 1)
2832a1ba9ba4Schristos {
2833a1ba9ba4Schristos gregdata->n_allocated_bpo_gregs = regindex + 1;
2834a1ba9ba4Schristos *again = TRUE;
2835a1ba9ba4Schristos }
2836a1ba9ba4Schristos
2837a1ba9ba4Schristos bpo_gregs_section->size = (regindex + 1) * 8;
2838a1ba9ba4Schristos }
2839a1ba9ba4Schristos
2840a1ba9ba4Schristos if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
2841a1ba9ba4Schristos {
2842a1ba9ba4Schristos if (! link_info->keep_memory)
2843a1ba9ba4Schristos free (isymbuf);
2844a1ba9ba4Schristos else
2845a1ba9ba4Schristos {
2846a1ba9ba4Schristos /* Cache the symbols for elf_link_input_bfd. */
2847a1ba9ba4Schristos symtab_hdr->contents = (unsigned char *) isymbuf;
2848a1ba9ba4Schristos }
2849a1ba9ba4Schristos }
2850a1ba9ba4Schristos
2851*184b2d41Schristos BFD_ASSERT(pjsno + pjsno_undefs
2852*184b2d41Schristos == mmix_elf_section_data (sec)->pjs.n_pushj_relocs);
2853051580eeSchristos
2854*184b2d41Schristos if (elf_section_data (sec)->relocs != internal_relocs)
2855a1ba9ba4Schristos free (internal_relocs);
2856a1ba9ba4Schristos
2857a1ba9ba4Schristos if (sec->size < size + mmix_elf_section_data (sec)->pjs.stubs_size_sum)
2858a1ba9ba4Schristos abort ();
2859a1ba9ba4Schristos
2860a1ba9ba4Schristos if (sec->size > size + mmix_elf_section_data (sec)->pjs.stubs_size_sum)
2861a1ba9ba4Schristos {
2862a1ba9ba4Schristos sec->size = size + mmix_elf_section_data (sec)->pjs.stubs_size_sum;
2863a1ba9ba4Schristos *again = TRUE;
2864a1ba9ba4Schristos }
2865a1ba9ba4Schristos
2866a1ba9ba4Schristos return TRUE;
2867a1ba9ba4Schristos
2868a1ba9ba4Schristos error_return:
2869*184b2d41Schristos if ((unsigned char *) isymbuf != symtab_hdr->contents)
2870a1ba9ba4Schristos free (isymbuf);
2871*184b2d41Schristos if (elf_section_data (sec)->relocs != internal_relocs)
2872a1ba9ba4Schristos free (internal_relocs);
2873a1ba9ba4Schristos return FALSE;
2874a1ba9ba4Schristos }
2875a1ba9ba4Schristos
2876a1ba9ba4Schristos #define ELF_ARCH bfd_arch_mmix
2877a1ba9ba4Schristos #define ELF_MACHINE_CODE EM_MMIX
2878a1ba9ba4Schristos
2879a1ba9ba4Schristos /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
2880a1ba9ba4Schristos However, that's too much for something somewhere in the linker part of
2881a1ba9ba4Schristos BFD; perhaps the start-address has to be a non-zero multiple of this
2882a1ba9ba4Schristos number, or larger than this number. The symptom is that the linker
2883a1ba9ba4Schristos complains: "warning: allocated section `.text' not in segment". We
2884a1ba9ba4Schristos settle for 64k; the page-size used in examples is 8k.
2885a1ba9ba4Schristos #define ELF_MAXPAGESIZE 0x10000
2886a1ba9ba4Schristos
2887a1ba9ba4Schristos Unfortunately, this causes excessive padding in the supposedly small
2888a1ba9ba4Schristos for-education programs that are the expected usage (where people would
2889a1ba9ba4Schristos inspect output). We stick to 256 bytes just to have *some* default
2890a1ba9ba4Schristos alignment. */
2891a1ba9ba4Schristos #define ELF_MAXPAGESIZE 0x100
2892a1ba9ba4Schristos
2893a1ba9ba4Schristos #define TARGET_BIG_SYM mmix_elf64_vec
2894a1ba9ba4Schristos #define TARGET_BIG_NAME "elf64-mmix"
2895a1ba9ba4Schristos
2896a1ba9ba4Schristos #define elf_info_to_howto_rel NULL
2897a1ba9ba4Schristos #define elf_info_to_howto mmix_info_to_howto_rela
2898a1ba9ba4Schristos #define elf_backend_relocate_section mmix_elf_relocate_section
2899a1ba9ba4Schristos #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
2900a1ba9ba4Schristos
2901a1ba9ba4Schristos #define elf_backend_link_output_symbol_hook \
2902a1ba9ba4Schristos mmix_elf_link_output_symbol_hook
2903a1ba9ba4Schristos #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
2904a1ba9ba4Schristos
2905a1ba9ba4Schristos #define elf_backend_check_relocs mmix_elf_check_relocs
2906a1ba9ba4Schristos #define elf_backend_symbol_processing mmix_elf_symbol_processing
2907051580eeSchristos #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
2908051580eeSchristos
2909051580eeSchristos #define bfd_elf64_bfd_copy_link_hash_symbol_type \
2910051580eeSchristos _bfd_generic_copy_link_hash_symbol_type
2911a1ba9ba4Schristos
2912a1ba9ba4Schristos #define bfd_elf64_bfd_is_local_label_name \
2913a1ba9ba4Schristos mmix_elf_is_local_label_name
2914a1ba9ba4Schristos
2915a1ba9ba4Schristos #define elf_backend_may_use_rel_p 0
2916a1ba9ba4Schristos #define elf_backend_may_use_rela_p 1
2917a1ba9ba4Schristos #define elf_backend_default_use_rela_p 1
2918a1ba9ba4Schristos
2919a1ba9ba4Schristos #define elf_backend_can_gc_sections 1
2920a1ba9ba4Schristos #define elf_backend_section_from_bfd_section \
2921a1ba9ba4Schristos mmix_elf_section_from_bfd_section
2922a1ba9ba4Schristos
2923a1ba9ba4Schristos #define bfd_elf64_new_section_hook mmix_elf_new_section_hook
2924a1ba9ba4Schristos #define bfd_elf64_bfd_final_link mmix_elf_final_link
2925a1ba9ba4Schristos #define bfd_elf64_bfd_relax_section mmix_elf_relax_section
2926a1ba9ba4Schristos
2927a1ba9ba4Schristos #include "elf64-target.h"
2928