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