]>
Commit | Line | Data |
---|---|---|
3c3bdf30 | 1 | /* MMIX-specific support for 64-bit ELF. |
9e7b37b3 | 2 | Copyright 2001, 2002 Free Software Foundation, Inc. |
3c3bdf30 NC |
3 | Contributed by Hans-Peter Nilsson <[email protected]> |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | /* No specific ABI or "processor-specific supplement" defined. */ | |
22 | ||
23 | /* TODO: | |
24 | - Linker relaxation. | |
25 | - On-demand register allocation (from R_MMIX_BASE_PLUS_OFFSET). */ | |
26 | ||
27 | #include "bfd.h" | |
28 | #include "sysdep.h" | |
29 | #include "libbfd.h" | |
30 | #include "elf-bfd.h" | |
31 | #include "elf/mmix.h" | |
32 | #include "opcode/mmix.h" | |
33 | ||
34 | #define MINUS_ONE (((bfd_vma) 0) - 1) | |
35 | ||
36 | /* Put these everywhere in new code. */ | |
37 | #define FATAL_DEBUG \ | |
38 | _bfd_abort (__FILE__, __LINE__, \ | |
39 | "Internal: Non-debugged code (test-case missing)") | |
40 | ||
41 | #define BAD_CASE(x) \ | |
42 | _bfd_abort (__FILE__, __LINE__, \ | |
43 | "bad case for " #x) | |
44 | ||
45 | static boolean mmix_elf_link_output_symbol_hook | |
46 | PARAMS ((bfd *, struct bfd_link_info *, const char *, | |
47 | Elf_Internal_Sym *, asection *)); | |
48 | ||
49 | static bfd_reloc_status_type mmix_elf_reloc | |
50 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
51 | ||
52 | static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup | |
53 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
54 | ||
55 | static void mmix_info_to_howto_rela | |
56 | PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *)); | |
57 | ||
58 | static int mmix_elf_sort_relocs PARAMS ((const PTR, const PTR)); | |
59 | ||
60 | static boolean mmix_elf_check_relocs | |
61 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
62 | const Elf_Internal_Rela *)); | |
63 | ||
64 | static boolean mmix_elf_relocate_section | |
65 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
66 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
67 | ||
68 | static asection * mmix_elf_gc_mark_hook | |
69 | PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, | |
70 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
71 | ||
72 | static bfd_reloc_status_type mmix_final_link_relocate | |
73 | PARAMS ((reloc_howto_type *, asection *, bfd_byte *, | |
74 | bfd_vma, bfd_signed_vma, bfd_vma, const char *, asection *)); | |
75 | ||
76 | static bfd_reloc_status_type mmix_elf_perform_relocation | |
77 | PARAMS ((asection *, reloc_howto_type *, PTR, bfd_vma, bfd_vma)); | |
78 | ||
79 | static boolean mmix_elf_section_from_bfd_section | |
af746e92 | 80 | PARAMS ((bfd *, asection *, int *)); |
3c3bdf30 NC |
81 | |
82 | static boolean mmix_elf_add_symbol_hook | |
83 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, | |
84 | const char **, flagword *, asection **, bfd_vma *)); | |
85 | ||
86 | static boolean mmix_elf_is_local_label_name | |
87 | PARAMS ((bfd *, const char *)); | |
88 | ||
89 | extern boolean mmix_elf_final_link PARAMS ((bfd *, struct bfd_link_info *)); | |
90 | ||
91 | extern void mmix_elf_symbol_processing PARAMS ((bfd *, asymbol *)); | |
92 | ||
93 | /* Watch out: this currently needs to have elements with the same index as | |
94 | their R_MMIX_ number. */ | |
95 | static reloc_howto_type elf_mmix_howto_table[] = | |
96 | { | |
97 | /* This reloc does nothing. */ | |
98 | HOWTO (R_MMIX_NONE, /* type */ | |
99 | 0, /* rightshift */ | |
100 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
101 | 32, /* bitsize */ | |
102 | false, /* pc_relative */ | |
103 | 0, /* bitpos */ | |
104 | complain_overflow_bitfield, /* complain_on_overflow */ | |
105 | bfd_elf_generic_reloc, /* special_function */ | |
106 | "R_MMIX_NONE", /* name */ | |
107 | false, /* partial_inplace */ | |
108 | 0, /* src_mask */ | |
109 | 0, /* dst_mask */ | |
110 | false), /* pcrel_offset */ | |
111 | ||
112 | /* An 8 bit absolute relocation. */ | |
113 | HOWTO (R_MMIX_8, /* type */ | |
114 | 0, /* rightshift */ | |
115 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
116 | 8, /* bitsize */ | |
117 | false, /* pc_relative */ | |
118 | 0, /* bitpos */ | |
119 | complain_overflow_bitfield, /* complain_on_overflow */ | |
120 | bfd_elf_generic_reloc, /* special_function */ | |
121 | "R_MMIX_8", /* name */ | |
122 | false, /* partial_inplace */ | |
123 | 0xff, /* src_mask */ | |
124 | 0xff, /* dst_mask */ | |
125 | false), /* pcrel_offset */ | |
126 | ||
127 | /* An 16 bit absolute relocation. */ | |
128 | HOWTO (R_MMIX_16, /* type */ | |
129 | 0, /* rightshift */ | |
130 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
131 | 16, /* bitsize */ | |
132 | false, /* pc_relative */ | |
133 | 0, /* bitpos */ | |
134 | complain_overflow_bitfield, /* complain_on_overflow */ | |
135 | bfd_elf_generic_reloc, /* special_function */ | |
136 | "R_MMIX_16", /* name */ | |
137 | false, /* partial_inplace */ | |
138 | 0xffff, /* src_mask */ | |
139 | 0xffff, /* dst_mask */ | |
140 | false), /* pcrel_offset */ | |
141 | ||
142 | /* An 24 bit absolute relocation. */ | |
143 | HOWTO (R_MMIX_24, /* type */ | |
144 | 0, /* rightshift */ | |
145 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
146 | 24, /* bitsize */ | |
147 | false, /* pc_relative */ | |
148 | 0, /* bitpos */ | |
149 | complain_overflow_bitfield, /* complain_on_overflow */ | |
150 | bfd_elf_generic_reloc, /* special_function */ | |
151 | "R_MMIX_24", /* name */ | |
152 | false, /* partial_inplace */ | |
153 | 0xffffff, /* src_mask */ | |
154 | 0xffffff, /* dst_mask */ | |
155 | false), /* pcrel_offset */ | |
156 | ||
157 | /* A 32 bit absolute relocation. */ | |
158 | HOWTO (R_MMIX_32, /* type */ | |
159 | 0, /* rightshift */ | |
160 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
161 | 32, /* bitsize */ | |
162 | false, /* pc_relative */ | |
163 | 0, /* bitpos */ | |
164 | complain_overflow_bitfield, /* complain_on_overflow */ | |
165 | bfd_elf_generic_reloc, /* special_function */ | |
166 | "R_MMIX_32", /* name */ | |
167 | false, /* partial_inplace */ | |
168 | 0xffffffff, /* src_mask */ | |
169 | 0xffffffff, /* dst_mask */ | |
170 | false), /* pcrel_offset */ | |
171 | ||
172 | /* 64 bit relocation. */ | |
173 | HOWTO (R_MMIX_64, /* type */ | |
174 | 0, /* rightshift */ | |
175 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
176 | 64, /* bitsize */ | |
177 | false, /* pc_relative */ | |
178 | 0, /* bitpos */ | |
179 | complain_overflow_bitfield, /* complain_on_overflow */ | |
180 | bfd_elf_generic_reloc, /* special_function */ | |
181 | "R_MMIX_64", /* name */ | |
182 | false, /* partial_inplace */ | |
183 | MINUS_ONE, /* src_mask */ | |
184 | MINUS_ONE, /* dst_mask */ | |
185 | false), /* pcrel_offset */ | |
186 | ||
187 | /* An 8 bit PC-relative relocation. */ | |
188 | HOWTO (R_MMIX_PC_8, /* type */ | |
189 | 0, /* rightshift */ | |
190 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
191 | 8, /* bitsize */ | |
192 | true, /* pc_relative */ | |
193 | 0, /* bitpos */ | |
194 | complain_overflow_bitfield, /* complain_on_overflow */ | |
195 | bfd_elf_generic_reloc, /* special_function */ | |
196 | "R_MMIX_PC_8", /* name */ | |
197 | false, /* partial_inplace */ | |
198 | 0xff, /* src_mask */ | |
199 | 0xff, /* dst_mask */ | |
200 | true), /* pcrel_offset */ | |
201 | ||
202 | /* An 16 bit PC-relative relocation. */ | |
203 | HOWTO (R_MMIX_PC_16, /* type */ | |
204 | 0, /* rightshift */ | |
205 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
206 | 16, /* bitsize */ | |
207 | true, /* pc_relative */ | |
208 | 0, /* bitpos */ | |
209 | complain_overflow_bitfield, /* complain_on_overflow */ | |
210 | bfd_elf_generic_reloc, /* special_function */ | |
211 | "R_MMIX_PC_16", /* name */ | |
212 | false, /* partial_inplace */ | |
213 | 0xffff, /* src_mask */ | |
214 | 0xffff, /* dst_mask */ | |
215 | true), /* pcrel_offset */ | |
216 | ||
217 | /* An 24 bit PC-relative relocation. */ | |
218 | HOWTO (R_MMIX_PC_24, /* type */ | |
219 | 0, /* rightshift */ | |
220 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
221 | 24, /* bitsize */ | |
222 | true, /* pc_relative */ | |
223 | 0, /* bitpos */ | |
224 | complain_overflow_bitfield, /* complain_on_overflow */ | |
225 | bfd_elf_generic_reloc, /* special_function */ | |
226 | "R_MMIX_PC_24", /* name */ | |
227 | false, /* partial_inplace */ | |
228 | 0xffffff, /* src_mask */ | |
229 | 0xffffff, /* dst_mask */ | |
230 | true), /* pcrel_offset */ | |
231 | ||
232 | /* A 32 bit absolute PC-relative relocation. */ | |
233 | HOWTO (R_MMIX_PC_32, /* type */ | |
234 | 0, /* rightshift */ | |
235 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
236 | 32, /* bitsize */ | |
237 | true, /* pc_relative */ | |
238 | 0, /* bitpos */ | |
239 | complain_overflow_bitfield, /* complain_on_overflow */ | |
240 | bfd_elf_generic_reloc, /* special_function */ | |
241 | "R_MMIX_PC_32", /* name */ | |
242 | false, /* partial_inplace */ | |
243 | 0xffffffff, /* src_mask */ | |
244 | 0xffffffff, /* dst_mask */ | |
245 | true), /* pcrel_offset */ | |
246 | ||
247 | /* 64 bit PC-relative relocation. */ | |
248 | HOWTO (R_MMIX_PC_64, /* type */ | |
249 | 0, /* rightshift */ | |
250 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
251 | 64, /* bitsize */ | |
252 | true, /* pc_relative */ | |
253 | 0, /* bitpos */ | |
254 | complain_overflow_bitfield, /* complain_on_overflow */ | |
255 | bfd_elf_generic_reloc, /* special_function */ | |
256 | "R_MMIX_PC_64", /* name */ | |
257 | false, /* partial_inplace */ | |
258 | MINUS_ONE, /* src_mask */ | |
259 | MINUS_ONE, /* dst_mask */ | |
260 | true), /* pcrel_offset */ | |
261 | ||
262 | /* GNU extension to record C++ vtable hierarchy. */ | |
263 | HOWTO (R_MMIX_GNU_VTINHERIT, /* type */ | |
264 | 0, /* rightshift */ | |
265 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
266 | 0, /* bitsize */ | |
267 | false, /* pc_relative */ | |
268 | 0, /* bitpos */ | |
269 | complain_overflow_dont, /* complain_on_overflow */ | |
270 | NULL, /* special_function */ | |
271 | "R_MMIX_GNU_VTINHERIT", /* name */ | |
272 | false, /* partial_inplace */ | |
273 | 0, /* src_mask */ | |
274 | 0, /* dst_mask */ | |
275 | true), /* pcrel_offset */ | |
276 | ||
277 | /* GNU extension to record C++ vtable member usage. */ | |
278 | HOWTO (R_MMIX_GNU_VTENTRY, /* type */ | |
279 | 0, /* rightshift */ | |
280 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
281 | 0, /* bitsize */ | |
282 | false, /* pc_relative */ | |
283 | 0, /* bitpos */ | |
284 | complain_overflow_dont, /* complain_on_overflow */ | |
285 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
286 | "R_MMIX_GNU_VTENTRY", /* name */ | |
287 | false, /* partial_inplace */ | |
288 | 0, /* src_mask */ | |
289 | 0, /* dst_mask */ | |
290 | false), /* pcrel_offset */ | |
291 | ||
292 | /* The GETA relocation is supposed to get any address that could | |
293 | possibly be reached by the GETA instruction. It can silently expand | |
294 | to get a 64-bit operand, but will complain if any of the two least | |
295 | significant bits are set. The howto members reflect a simple GETA. */ | |
296 | HOWTO (R_MMIX_GETA, /* type */ | |
297 | 2, /* rightshift */ | |
298 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
299 | 19, /* bitsize */ | |
300 | true, /* pc_relative */ | |
301 | 0, /* bitpos */ | |
302 | complain_overflow_signed, /* complain_on_overflow */ | |
303 | mmix_elf_reloc, /* special_function */ | |
304 | "R_MMIX_GETA", /* name */ | |
305 | false, /* partial_inplace */ | |
306 | 0x0100ffff, /* src_mask */ | |
307 | 0x0100ffff, /* dst_mask */ | |
308 | true), /* pcrel_offset */ | |
309 | ||
310 | HOWTO (R_MMIX_GETA_1, /* type */ | |
311 | 2, /* rightshift */ | |
312 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
313 | 19, /* bitsize */ | |
314 | true, /* pc_relative */ | |
315 | 0, /* bitpos */ | |
316 | complain_overflow_signed, /* complain_on_overflow */ | |
317 | mmix_elf_reloc, /* special_function */ | |
318 | "R_MMIX_GETA_1", /* name */ | |
319 | false, /* partial_inplace */ | |
320 | 0x0100ffff, /* src_mask */ | |
321 | 0x0100ffff, /* dst_mask */ | |
322 | true), /* pcrel_offset */ | |
323 | ||
324 | HOWTO (R_MMIX_GETA_2, /* type */ | |
325 | 2, /* rightshift */ | |
326 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
327 | 19, /* bitsize */ | |
328 | true, /* pc_relative */ | |
329 | 0, /* bitpos */ | |
330 | complain_overflow_signed, /* complain_on_overflow */ | |
331 | mmix_elf_reloc, /* special_function */ | |
332 | "R_MMIX_GETA_2", /* name */ | |
333 | false, /* partial_inplace */ | |
334 | 0x0100ffff, /* src_mask */ | |
335 | 0x0100ffff, /* dst_mask */ | |
336 | true), /* pcrel_offset */ | |
337 | ||
338 | HOWTO (R_MMIX_GETA_3, /* type */ | |
339 | 2, /* rightshift */ | |
340 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
341 | 19, /* bitsize */ | |
342 | true, /* pc_relative */ | |
343 | 0, /* bitpos */ | |
344 | complain_overflow_signed, /* complain_on_overflow */ | |
345 | mmix_elf_reloc, /* special_function */ | |
346 | "R_MMIX_GETA_3", /* name */ | |
347 | false, /* partial_inplace */ | |
348 | 0x0100ffff, /* src_mask */ | |
349 | 0x0100ffff, /* dst_mask */ | |
350 | true), /* pcrel_offset */ | |
351 | ||
352 | /* The conditional branches are supposed to reach any (code) address. | |
353 | It can silently expand to a 64-bit operand, but will emit an error if | |
354 | any of the two least significant bits are set. The howto members | |
355 | reflect a simple branch. */ | |
356 | HOWTO (R_MMIX_CBRANCH, /* type */ | |
357 | 2, /* rightshift */ | |
358 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
359 | 19, /* bitsize */ | |
360 | true, /* pc_relative */ | |
361 | 0, /* bitpos */ | |
362 | complain_overflow_signed, /* complain_on_overflow */ | |
363 | mmix_elf_reloc, /* special_function */ | |
364 | "R_MMIX_CBRANCH", /* name */ | |
365 | false, /* partial_inplace */ | |
366 | 0x0100ffff, /* src_mask */ | |
367 | 0x0100ffff, /* dst_mask */ | |
368 | true), /* pcrel_offset */ | |
369 | ||
370 | HOWTO (R_MMIX_CBRANCH_J, /* type */ | |
371 | 2, /* rightshift */ | |
372 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
373 | 19, /* bitsize */ | |
374 | true, /* pc_relative */ | |
375 | 0, /* bitpos */ | |
376 | complain_overflow_signed, /* complain_on_overflow */ | |
377 | mmix_elf_reloc, /* special_function */ | |
378 | "R_MMIX_CBRANCH_J", /* name */ | |
379 | false, /* partial_inplace */ | |
380 | 0x0100ffff, /* src_mask */ | |
381 | 0x0100ffff, /* dst_mask */ | |
382 | true), /* pcrel_offset */ | |
383 | ||
384 | HOWTO (R_MMIX_CBRANCH_1, /* type */ | |
385 | 2, /* rightshift */ | |
386 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
387 | 19, /* bitsize */ | |
388 | true, /* pc_relative */ | |
389 | 0, /* bitpos */ | |
390 | complain_overflow_signed, /* complain_on_overflow */ | |
391 | mmix_elf_reloc, /* special_function */ | |
392 | "R_MMIX_CBRANCH_1", /* name */ | |
393 | false, /* partial_inplace */ | |
394 | 0x0100ffff, /* src_mask */ | |
395 | 0x0100ffff, /* dst_mask */ | |
396 | true), /* pcrel_offset */ | |
397 | ||
398 | HOWTO (R_MMIX_CBRANCH_2, /* type */ | |
399 | 2, /* rightshift */ | |
400 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
401 | 19, /* bitsize */ | |
402 | true, /* pc_relative */ | |
403 | 0, /* bitpos */ | |
404 | complain_overflow_signed, /* complain_on_overflow */ | |
405 | mmix_elf_reloc, /* special_function */ | |
406 | "R_MMIX_CBRANCH_2", /* name */ | |
407 | false, /* partial_inplace */ | |
408 | 0x0100ffff, /* src_mask */ | |
409 | 0x0100ffff, /* dst_mask */ | |
410 | true), /* pcrel_offset */ | |
411 | ||
412 | HOWTO (R_MMIX_CBRANCH_3, /* type */ | |
413 | 2, /* rightshift */ | |
414 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
415 | 19, /* bitsize */ | |
416 | true, /* pc_relative */ | |
417 | 0, /* bitpos */ | |
418 | complain_overflow_signed, /* complain_on_overflow */ | |
419 | mmix_elf_reloc, /* special_function */ | |
420 | "R_MMIX_CBRANCH_3", /* name */ | |
421 | false, /* partial_inplace */ | |
422 | 0x0100ffff, /* src_mask */ | |
423 | 0x0100ffff, /* dst_mask */ | |
424 | true), /* pcrel_offset */ | |
425 | ||
426 | /* The PUSHJ instruction can reach any (code) address, as long as it's | |
427 | the beginning of a function (no usable restriction). It can silently | |
428 | expand to a 64-bit operand, but will emit an error if any of the two | |
429 | least significant bits are set. The howto members reflect a simple | |
430 | PUSHJ. */ | |
431 | HOWTO (R_MMIX_PUSHJ, /* type */ | |
432 | 2, /* rightshift */ | |
433 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
434 | 19, /* bitsize */ | |
435 | true, /* pc_relative */ | |
436 | 0, /* bitpos */ | |
437 | complain_overflow_signed, /* complain_on_overflow */ | |
438 | mmix_elf_reloc, /* special_function */ | |
439 | "R_MMIX_PUSHJ", /* name */ | |
440 | false, /* partial_inplace */ | |
441 | 0x0100ffff, /* src_mask */ | |
442 | 0x0100ffff, /* dst_mask */ | |
443 | true), /* pcrel_offset */ | |
444 | ||
445 | HOWTO (R_MMIX_PUSHJ_1, /* type */ | |
446 | 2, /* rightshift */ | |
447 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
448 | 19, /* bitsize */ | |
449 | true, /* pc_relative */ | |
450 | 0, /* bitpos */ | |
451 | complain_overflow_signed, /* complain_on_overflow */ | |
452 | mmix_elf_reloc, /* special_function */ | |
453 | "R_MMIX_PUSHJ_1", /* name */ | |
454 | false, /* partial_inplace */ | |
455 | 0x0100ffff, /* src_mask */ | |
456 | 0x0100ffff, /* dst_mask */ | |
457 | true), /* pcrel_offset */ | |
458 | ||
459 | HOWTO (R_MMIX_PUSHJ_2, /* type */ | |
460 | 2, /* rightshift */ | |
461 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
462 | 19, /* bitsize */ | |
463 | true, /* pc_relative */ | |
464 | 0, /* bitpos */ | |
465 | complain_overflow_signed, /* complain_on_overflow */ | |
466 | mmix_elf_reloc, /* special_function */ | |
467 | "R_MMIX_PUSHJ_2", /* name */ | |
468 | false, /* partial_inplace */ | |
469 | 0x0100ffff, /* src_mask */ | |
470 | 0x0100ffff, /* dst_mask */ | |
471 | true), /* pcrel_offset */ | |
472 | ||
473 | HOWTO (R_MMIX_PUSHJ_3, /* type */ | |
474 | 2, /* rightshift */ | |
475 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
476 | 19, /* bitsize */ | |
477 | true, /* pc_relative */ | |
478 | 0, /* bitpos */ | |
479 | complain_overflow_signed, /* complain_on_overflow */ | |
480 | mmix_elf_reloc, /* special_function */ | |
481 | "R_MMIX_PUSHJ_3", /* name */ | |
482 | false, /* partial_inplace */ | |
483 | 0x0100ffff, /* src_mask */ | |
484 | 0x0100ffff, /* dst_mask */ | |
485 | true), /* pcrel_offset */ | |
486 | ||
487 | /* A JMP is supposed to reach any (code) address. By itself, it can | |
488 | reach +-64M; the expansion can reach all 64 bits. Note that the 64M | |
489 | limit is soon reached if you link the program in wildly different | |
490 | memory segments. The howto members reflect a trivial JMP. */ | |
491 | HOWTO (R_MMIX_JMP, /* type */ | |
492 | 2, /* rightshift */ | |
493 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
494 | 27, /* bitsize */ | |
495 | true, /* pc_relative */ | |
496 | 0, /* bitpos */ | |
497 | complain_overflow_signed, /* complain_on_overflow */ | |
498 | mmix_elf_reloc, /* special_function */ | |
499 | "R_MMIX_JMP", /* name */ | |
500 | false, /* partial_inplace */ | |
501 | 0x1ffffff, /* src_mask */ | |
502 | 0x1ffffff, /* dst_mask */ | |
503 | true), /* pcrel_offset */ | |
504 | ||
505 | HOWTO (R_MMIX_JMP_1, /* type */ | |
506 | 2, /* rightshift */ | |
507 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
508 | 27, /* bitsize */ | |
509 | true, /* pc_relative */ | |
510 | 0, /* bitpos */ | |
511 | complain_overflow_signed, /* complain_on_overflow */ | |
512 | mmix_elf_reloc, /* special_function */ | |
513 | "R_MMIX_JMP_1", /* name */ | |
514 | false, /* partial_inplace */ | |
515 | 0x1ffffff, /* src_mask */ | |
516 | 0x1ffffff, /* dst_mask */ | |
517 | true), /* pcrel_offset */ | |
518 | ||
519 | HOWTO (R_MMIX_JMP_2, /* type */ | |
520 | 2, /* rightshift */ | |
521 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
522 | 27, /* bitsize */ | |
523 | true, /* pc_relative */ | |
524 | 0, /* bitpos */ | |
525 | complain_overflow_signed, /* complain_on_overflow */ | |
526 | mmix_elf_reloc, /* special_function */ | |
527 | "R_MMIX_JMP_2", /* name */ | |
528 | false, /* partial_inplace */ | |
529 | 0x1ffffff, /* src_mask */ | |
530 | 0x1ffffff, /* dst_mask */ | |
531 | true), /* pcrel_offset */ | |
532 | ||
533 | HOWTO (R_MMIX_JMP_3, /* type */ | |
534 | 2, /* rightshift */ | |
535 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
536 | 27, /* bitsize */ | |
537 | true, /* pc_relative */ | |
538 | 0, /* bitpos */ | |
539 | complain_overflow_signed, /* complain_on_overflow */ | |
540 | mmix_elf_reloc, /* special_function */ | |
541 | "R_MMIX_JMP_3", /* name */ | |
542 | false, /* partial_inplace */ | |
543 | 0x1ffffff, /* src_mask */ | |
544 | 0x1ffffff, /* dst_mask */ | |
545 | true), /* pcrel_offset */ | |
546 | ||
547 | /* When we don't emit link-time-relaxable code from the assembler, or | |
548 | when relaxation has done all it can do, these relocs are used. For | |
549 | GETA/PUSHJ/branches. */ | |
550 | HOWTO (R_MMIX_ADDR19, /* type */ | |
551 | 2, /* rightshift */ | |
552 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
553 | 19, /* bitsize */ | |
554 | true, /* pc_relative */ | |
555 | 0, /* bitpos */ | |
556 | complain_overflow_signed, /* complain_on_overflow */ | |
557 | mmix_elf_reloc, /* special_function */ | |
558 | "R_MMIX_ADDR19", /* name */ | |
559 | false, /* partial_inplace */ | |
560 | 0x0100ffff, /* src_mask */ | |
561 | 0x0100ffff, /* dst_mask */ | |
562 | true), /* pcrel_offset */ | |
563 | ||
564 | /* For JMP. */ | |
565 | HOWTO (R_MMIX_ADDR27, /* type */ | |
566 | 2, /* rightshift */ | |
567 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
568 | 27, /* bitsize */ | |
569 | true, /* pc_relative */ | |
570 | 0, /* bitpos */ | |
571 | complain_overflow_signed, /* complain_on_overflow */ | |
572 | mmix_elf_reloc, /* special_function */ | |
573 | "R_MMIX_ADDR27", /* name */ | |
574 | false, /* partial_inplace */ | |
575 | 0x1ffffff, /* src_mask */ | |
576 | 0x1ffffff, /* dst_mask */ | |
577 | true), /* pcrel_offset */ | |
578 | ||
579 | /* A general register or the value 0..255. If a value, then the | |
580 | instruction (offset -3) needs adjusting. */ | |
581 | HOWTO (R_MMIX_REG_OR_BYTE, /* type */ | |
582 | 0, /* rightshift */ | |
583 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
584 | 8, /* bitsize */ | |
585 | false, /* pc_relative */ | |
586 | 0, /* bitpos */ | |
587 | complain_overflow_bitfield, /* complain_on_overflow */ | |
588 | mmix_elf_reloc, /* special_function */ | |
589 | "R_MMIX_REG_OR_BYTE", /* name */ | |
590 | false, /* partial_inplace */ | |
591 | 0xff, /* src_mask */ | |
592 | 0xff, /* dst_mask */ | |
593 | false), /* pcrel_offset */ | |
594 | ||
595 | /* A general register. */ | |
596 | HOWTO (R_MMIX_REG, /* type */ | |
597 | 0, /* rightshift */ | |
598 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
599 | 8, /* bitsize */ | |
600 | false, /* pc_relative */ | |
601 | 0, /* bitpos */ | |
602 | complain_overflow_bitfield, /* complain_on_overflow */ | |
603 | mmix_elf_reloc, /* special_function */ | |
604 | "R_MMIX_REG", /* name */ | |
605 | false, /* partial_inplace */ | |
606 | 0xff, /* src_mask */ | |
607 | 0xff, /* dst_mask */ | |
608 | false), /* pcrel_offset */ | |
609 | ||
610 | /* A register plus an index, corresponding to the relocation expression. | |
611 | The sizes must correspond to the valid range of the expression, while | |
612 | the bitmasks correspond to what we store in the image. */ | |
613 | HOWTO (R_MMIX_BASE_PLUS_OFFSET, /* type */ | |
614 | 0, /* rightshift */ | |
615 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
616 | 64, /* bitsize */ | |
617 | false, /* pc_relative */ | |
618 | 0, /* bitpos */ | |
619 | complain_overflow_bitfield, /* complain_on_overflow */ | |
620 | mmix_elf_reloc, /* special_function */ | |
621 | "R_MMIX_BASE_PLUS_OFFSET", /* name */ | |
622 | false, /* partial_inplace */ | |
623 | 0xffff, /* src_mask */ | |
624 | 0xffff, /* dst_mask */ | |
625 | false), /* pcrel_offset */ | |
626 | ||
627 | /* A "magic" relocation for a LOCAL expression, asserting that the | |
628 | expression is less than the number of global registers. No actual | |
629 | modification of the contents is done. Implementing this as a | |
630 | relocation was less intrusive than e.g. putting such expressions in a | |
631 | section to discard *after* relocation. */ | |
632 | HOWTO (R_MMIX_LOCAL, /* type */ | |
633 | 0, /* rightshift */ | |
634 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
635 | 0, /* bitsize */ | |
636 | false, /* pc_relative */ | |
637 | 0, /* bitpos */ | |
638 | complain_overflow_dont, /* complain_on_overflow */ | |
639 | mmix_elf_reloc, /* special_function */ | |
640 | "R_MMIX_LOCAL", /* name */ | |
641 | false, /* partial_inplace */ | |
642 | 0, /* src_mask */ | |
643 | 0, /* dst_mask */ | |
644 | false), /* pcrel_offset */ | |
645 | }; | |
646 | ||
647 | ||
648 | /* Map BFD reloc types to MMIX ELF reloc types. */ | |
649 | ||
650 | struct mmix_reloc_map | |
651 | { | |
652 | bfd_reloc_code_real_type bfd_reloc_val; | |
653 | enum elf_mmix_reloc_type elf_reloc_val; | |
654 | }; | |
655 | ||
656 | ||
657 | static const struct mmix_reloc_map mmix_reloc_map[] = | |
658 | { | |
659 | {BFD_RELOC_NONE, R_MMIX_NONE}, | |
660 | {BFD_RELOC_8, R_MMIX_8}, | |
661 | {BFD_RELOC_16, R_MMIX_16}, | |
662 | {BFD_RELOC_24, R_MMIX_24}, | |
663 | {BFD_RELOC_32, R_MMIX_32}, | |
664 | {BFD_RELOC_64, R_MMIX_64}, | |
665 | {BFD_RELOC_8_PCREL, R_MMIX_PC_8}, | |
666 | {BFD_RELOC_16_PCREL, R_MMIX_PC_16}, | |
667 | {BFD_RELOC_24_PCREL, R_MMIX_PC_24}, | |
668 | {BFD_RELOC_32_PCREL, R_MMIX_PC_32}, | |
669 | {BFD_RELOC_64_PCREL, R_MMIX_PC_64}, | |
670 | {BFD_RELOC_VTABLE_INHERIT, R_MMIX_GNU_VTINHERIT}, | |
671 | {BFD_RELOC_VTABLE_ENTRY, R_MMIX_GNU_VTENTRY}, | |
672 | {BFD_RELOC_MMIX_GETA, R_MMIX_GETA}, | |
673 | {BFD_RELOC_MMIX_CBRANCH, R_MMIX_CBRANCH}, | |
674 | {BFD_RELOC_MMIX_PUSHJ, R_MMIX_PUSHJ}, | |
675 | {BFD_RELOC_MMIX_JMP, R_MMIX_JMP}, | |
676 | {BFD_RELOC_MMIX_ADDR19, R_MMIX_ADDR19}, | |
677 | {BFD_RELOC_MMIX_ADDR27, R_MMIX_ADDR27}, | |
678 | {BFD_RELOC_MMIX_REG_OR_BYTE, R_MMIX_REG_OR_BYTE}, | |
679 | {BFD_RELOC_MMIX_REG, R_MMIX_REG}, | |
680 | {BFD_RELOC_MMIX_BASE_PLUS_OFFSET, R_MMIX_BASE_PLUS_OFFSET}, | |
681 | {BFD_RELOC_MMIX_LOCAL, R_MMIX_LOCAL} | |
682 | }; | |
683 | ||
684 | static reloc_howto_type * | |
685 | bfd_elf64_bfd_reloc_type_lookup (abfd, code) | |
686 | bfd *abfd ATTRIBUTE_UNUSED; | |
687 | bfd_reloc_code_real_type code; | |
688 | { | |
689 | unsigned int i; | |
690 | ||
691 | for (i = 0; | |
692 | i < sizeof (mmix_reloc_map) / sizeof (mmix_reloc_map[0]); | |
693 | i++) | |
694 | { | |
695 | if (mmix_reloc_map[i].bfd_reloc_val == code) | |
696 | return &elf_mmix_howto_table[mmix_reloc_map[i].elf_reloc_val]; | |
697 | } | |
698 | ||
699 | return NULL; | |
700 | } | |
701 | ||
702 | ||
703 | /* This function performs the actual bitfiddling and sanity check for a | |
704 | final relocation. Each relocation gets its *worst*-case expansion | |
705 | in size when it arrives here; any reduction in size should have been | |
706 | caught in linker relaxation earlier. When we get here, the relocation | |
707 | looks like the smallest instruction with SWYM:s (nop:s) appended to the | |
708 | max size. We fill in those nop:s. | |
709 | ||
710 | R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra) | |
711 | GETA $N,foo | |
712 | -> | |
713 | SETL $N,foo & 0xffff | |
714 | INCML $N,(foo >> 16) & 0xffff | |
715 | INCMH $N,(foo >> 32) & 0xffff | |
716 | INCH $N,(foo >> 48) & 0xffff | |
717 | ||
718 | R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but | |
719 | condbranches needing relaxation might be rare enough to not be | |
720 | worthwhile.) | |
721 | [P]Bcc $N,foo | |
722 | -> | |
723 | [~P]B~cc $N,.+20 | |
724 | SETL $255,foo & ... | |
725 | INCML ... | |
726 | INCMH ... | |
727 | INCH ... | |
728 | GO $255,$255,0 | |
729 | ||
730 | R_MMIX_PUSHJ: (FIXME: Relaxation...) | |
731 | PUSHJ $N,foo | |
732 | -> | |
733 | SETL $255,foo & ... | |
734 | INCML ... | |
735 | INCMH ... | |
736 | INCH ... | |
737 | PUSHGO $N,$255,0 | |
738 | ||
739 | R_MMIX_JMP: (FIXME: Relaxation...) | |
740 | JMP foo | |
741 | -> | |
742 | SETL $255,foo & ... | |
743 | INCML ... | |
744 | INCMH ... | |
745 | INCH ... | |
746 | GO $255,$255,0 | |
747 | ||
748 | R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */ | |
749 | ||
750 | static bfd_reloc_status_type | |
751 | mmix_elf_perform_relocation (isec, howto, datap, addr, value) | |
752 | asection *isec; | |
753 | reloc_howto_type *howto; | |
754 | PTR datap; | |
755 | bfd_vma addr ATTRIBUTE_UNUSED; | |
756 | bfd_vma value; | |
757 | { | |
758 | bfd *abfd = isec->owner; | |
759 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
760 | bfd_reloc_status_type r; | |
761 | int offs = 0; | |
762 | int reg = 255; | |
763 | ||
764 | /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences. | |
765 | We handle the differences here and the common sequence later. */ | |
766 | switch (howto->type) | |
767 | { | |
768 | case R_MMIX_GETA: | |
769 | offs = 0; | |
770 | reg = bfd_get_8 (abfd, (bfd_byte *) datap + 1); | |
771 | ||
772 | /* We change to an absolute value. */ | |
773 | value += addr; | |
774 | break; | |
775 | ||
776 | case R_MMIX_CBRANCH: | |
777 | { | |
778 | int in1 = bfd_get_16 (abfd, (bfd_byte *) datap) << 16; | |
779 | ||
780 | /* Invert the condition and prediction bit, and set the offset | |
781 | to five instructions ahead. | |
782 | ||
783 | We *can* do better if we want to. If the branch is found to be | |
784 | within limits, we could leave the branch as is; there'll just | |
785 | be a bunch of NOP:s after it. But we shouldn't see this | |
786 | sequence often enough that it's worth doing it. */ | |
787 | ||
788 | bfd_put_32 (abfd, | |
789 | (((in1 ^ ((PRED_INV_BIT | COND_INV_BIT) << 24)) & ~0xffff) | |
790 | | (24/4)), | |
791 | (bfd_byte *) datap); | |
792 | ||
793 | /* Put a "GO $255,$255,0" after the common sequence. */ | |
794 | bfd_put_32 (abfd, | |
795 | ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | 0xffff00, | |
796 | (bfd_byte *) datap + 20); | |
797 | ||
798 | /* Common sequence starts at offset 4. */ | |
799 | offs = 4; | |
800 | ||
801 | /* We change to an absolute value. */ | |
802 | value += addr; | |
803 | } | |
804 | break; | |
805 | ||
806 | case R_MMIX_PUSHJ: | |
807 | { | |
808 | int inreg = bfd_get_8 (abfd, (bfd_byte *) datap + 1); | |
809 | ||
810 | /* Put a "PUSHGO $N,$255,0" after the common sequence. */ | |
811 | bfd_put_32 (abfd, | |
812 | ((PUSHGO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | |
813 | | (inreg << 16) | |
814 | | 0xff00, | |
815 | (bfd_byte *) datap + 16); | |
816 | ||
817 | /* We change to an absolute value. */ | |
818 | value += addr; | |
819 | } | |
820 | break; | |
821 | ||
822 | case R_MMIX_JMP: | |
823 | /* This one is a little special. If we get here on a non-relaxing | |
824 | link, and the destination is actually in range, we don't need to | |
825 | execute the nops. | |
826 | If so, we fall through to the bit-fiddling relocs. | |
827 | ||
828 | FIXME: bfd_check_overflow seems broken; the relocation is | |
829 | rightshifted before testing, so supply a zero rightshift. */ | |
830 | ||
831 | if (! ((value & 3) == 0 | |
832 | && (r = bfd_check_overflow (complain_overflow_signed, | |
833 | howto->bitsize, | |
834 | 0, | |
835 | bfd_arch_bits_per_address (abfd), | |
836 | value)) == bfd_reloc_ok)) | |
837 | { | |
838 | /* If the relocation doesn't fit in a JMP, we let the NOP:s be | |
839 | modified below, and put a "GO $255,$255,0" after the | |
840 | address-loading sequence. */ | |
841 | bfd_put_32 (abfd, | |
842 | ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | |
843 | | 0xffff00, | |
844 | (bfd_byte *) datap + 16); | |
845 | ||
846 | /* We change to an absolute value. */ | |
847 | value += addr; | |
848 | break; | |
849 | } | |
850 | /* FALLTHROUGH. */ | |
851 | case R_MMIX_ADDR19: | |
852 | case R_MMIX_ADDR27: | |
853 | /* These must be in range, or else we emit an error. */ | |
854 | if ((value & 3) == 0 | |
855 | /* Note rightshift 0; see above. */ | |
856 | && (r = bfd_check_overflow (complain_overflow_signed, | |
857 | howto->bitsize, | |
858 | 0, | |
859 | bfd_arch_bits_per_address (abfd), | |
860 | value)) == bfd_reloc_ok) | |
861 | { | |
862 | bfd_vma in1 | |
863 | = bfd_get_32 (abfd, (bfd_byte *) datap); | |
864 | bfd_vma highbit; | |
865 | ||
866 | if ((bfd_signed_vma) value < 0) | |
867 | { | |
868 | highbit = (1 << 24); | |
869 | value += (1 << (howto->bitsize - 1)); | |
870 | } | |
871 | else | |
872 | highbit = 0; | |
873 | ||
874 | value >>= 2; | |
875 | ||
876 | bfd_put_32 (abfd, | |
877 | (in1 & ~howto->src_mask) | |
878 | | highbit | |
879 | | (value & howto->dst_mask), | |
880 | (bfd_byte *) datap); | |
881 | ||
882 | return bfd_reloc_ok; | |
883 | } | |
884 | else | |
885 | return bfd_reloc_overflow; | |
886 | ||
887 | case R_MMIX_REG_OR_BYTE: | |
888 | case R_MMIX_REG: | |
889 | if (value > 255) | |
890 | return bfd_reloc_overflow; | |
891 | bfd_put_8 (abfd, value, datap); | |
892 | return bfd_reloc_ok; | |
893 | ||
894 | default: | |
895 | BAD_CASE (howto->type); | |
896 | } | |
897 | ||
898 | /* This code adds the common SETL/INCML/INCMH/INCH worst-case | |
899 | sequence. */ | |
900 | ||
901 | /* Lowest two bits must be 0. We return bfd_reloc_overflow for | |
902 | everything that looks strange. */ | |
903 | if (value & 3) | |
904 | flag = bfd_reloc_overflow; | |
905 | ||
906 | bfd_put_32 (abfd, | |
907 | (SETL_INSN_BYTE << 24) | (value & 0xffff) | (reg << 16), | |
908 | (bfd_byte *) datap + offs); | |
909 | bfd_put_32 (abfd, | |
910 | (INCML_INSN_BYTE << 24) | ((value >> 16) & 0xffff) | (reg << 16), | |
911 | (bfd_byte *) datap + offs + 4); | |
912 | bfd_put_32 (abfd, | |
913 | (INCMH_INSN_BYTE << 24) | ((value >> 32) & 0xffff) | (reg << 16), | |
914 | (bfd_byte *) datap + offs + 8); | |
915 | bfd_put_32 (abfd, | |
916 | (INCH_INSN_BYTE << 24) | ((value >> 48) & 0xffff) | (reg << 16), | |
917 | (bfd_byte *) datap + offs + 12); | |
918 | ||
919 | return flag; | |
920 | } | |
921 | ||
922 | /* Set the howto pointer for an MMIX ELF reloc (type RELA). */ | |
923 | ||
924 | static void | |
925 | mmix_info_to_howto_rela (abfd, cache_ptr, dst) | |
926 | bfd *abfd ATTRIBUTE_UNUSED; | |
927 | arelent *cache_ptr; | |
928 | Elf64_Internal_Rela *dst; | |
929 | { | |
930 | unsigned int r_type; | |
931 | ||
932 | r_type = ELF64_R_TYPE (dst->r_info); | |
933 | BFD_ASSERT (r_type < (unsigned int) R_MMIX_max); | |
934 | cache_ptr->howto = &elf_mmix_howto_table[r_type]; | |
935 | } | |
936 | ||
937 | /* Any MMIX-specific relocation gets here at assembly time or when linking | |
938 | to other formats (such as mmo); this is the relocation function from | |
939 | the reloc_table. We don't get here for final pure ELF linking. */ | |
940 | ||
941 | static bfd_reloc_status_type | |
942 | mmix_elf_reloc (abfd, reloc_entry, symbol, data, input_section, | |
943 | output_bfd, error_message) | |
944 | bfd *abfd; | |
945 | arelent *reloc_entry; | |
946 | asymbol *symbol; | |
947 | PTR data; | |
948 | asection *input_section; | |
949 | bfd *output_bfd; | |
950 | char **error_message ATTRIBUTE_UNUSED; | |
951 | { | |
952 | bfd_vma relocation; | |
953 | bfd_reloc_status_type r; | |
954 | asection *reloc_target_output_section; | |
955 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
956 | bfd_vma output_base = 0; | |
957 | bfd_vma addr; | |
958 | ||
959 | r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
960 | input_section, output_bfd, error_message); | |
961 | ||
962 | /* If that was all that was needed (i.e. this isn't a final link, only | |
963 | some segment adjustments), we're done. */ | |
964 | if (r != bfd_reloc_continue) | |
965 | return r; | |
966 | ||
967 | if (bfd_is_und_section (symbol->section) | |
968 | && (symbol->flags & BSF_WEAK) == 0 | |
969 | && output_bfd == (bfd *) NULL) | |
970 | return bfd_reloc_undefined; | |
971 | ||
972 | /* Is the address of the relocation really within the section? */ | |
973 | if (reloc_entry->address > input_section->_cooked_size) | |
974 | return bfd_reloc_outofrange; | |
975 | ||
976 | /* Work out which section the relocation is targetted at and the | |
977 | initial relocation command value. */ | |
978 | ||
979 | /* Get symbol value. (Common symbols are special.) */ | |
980 | if (bfd_is_com_section (symbol->section)) | |
981 | relocation = 0; | |
982 | else | |
983 | relocation = symbol->value; | |
984 | ||
985 | reloc_target_output_section = bfd_get_output_section (symbol); | |
986 | ||
987 | /* Here the variable relocation holds the final address of the symbol we | |
988 | are relocating against, plus any addend. */ | |
989 | if (output_bfd) | |
990 | output_base = 0; | |
991 | else | |
992 | output_base = reloc_target_output_section->vma; | |
993 | ||
994 | relocation += output_base + symbol->section->output_offset; | |
995 | ||
996 | /* Get position of relocation. */ | |
997 | addr = (reloc_entry->address + input_section->output_section->vma | |
998 | + input_section->output_offset); | |
999 | if (output_bfd != (bfd *) NULL) | |
1000 | { | |
1001 | /* Add in supplied addend. */ | |
1002 | relocation += reloc_entry->addend; | |
1003 | ||
1004 | /* This is a partial relocation, and we want to apply the | |
1005 | relocation to the reloc entry rather than the raw data. | |
1006 | Modify the reloc inplace to reflect what we now know. */ | |
1007 | reloc_entry->addend = relocation; | |
1008 | reloc_entry->address += input_section->output_offset; | |
1009 | return flag; | |
1010 | } | |
1011 | ||
1012 | return mmix_final_link_relocate (reloc_entry->howto, input_section, | |
1013 | data, reloc_entry->address, | |
1014 | reloc_entry->addend, relocation, | |
1015 | bfd_asymbol_name (symbol), | |
1016 | reloc_target_output_section); | |
1017 | } | |
e06fcc86 | 1018 | \f |
3c3bdf30 NC |
1019 | /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it |
1020 | for guidance if you're thinking of copying this. */ | |
1021 | ||
1022 | static boolean | |
1023 | mmix_elf_relocate_section (output_bfd, info, input_bfd, input_section, | |
1024 | contents, relocs, local_syms, local_sections) | |
1025 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
1026 | struct bfd_link_info *info; | |
1027 | bfd *input_bfd; | |
1028 | asection *input_section; | |
1029 | bfd_byte *contents; | |
1030 | Elf_Internal_Rela *relocs; | |
1031 | Elf_Internal_Sym *local_syms; | |
1032 | asection **local_sections; | |
1033 | { | |
1034 | Elf_Internal_Shdr *symtab_hdr; | |
1035 | struct elf_link_hash_entry **sym_hashes; | |
1036 | Elf_Internal_Rela *rel; | |
1037 | Elf_Internal_Rela *relend; | |
1038 | ||
1039 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
1040 | sym_hashes = elf_sym_hashes (input_bfd); | |
1041 | relend = relocs + input_section->reloc_count; | |
1042 | ||
1043 | for (rel = relocs; rel < relend; rel ++) | |
1044 | { | |
1045 | reloc_howto_type *howto; | |
1046 | unsigned long r_symndx; | |
1047 | Elf_Internal_Sym *sym; | |
1048 | asection *sec; | |
1049 | struct elf_link_hash_entry *h; | |
1050 | bfd_vma relocation; | |
1051 | bfd_reloc_status_type r; | |
1052 | const char *name = NULL; | |
1053 | int r_type; | |
1054 | boolean undefined_signalled = false; | |
1055 | ||
1056 | r_type = ELF64_R_TYPE (rel->r_info); | |
1057 | ||
1058 | if (r_type == R_MMIX_GNU_VTINHERIT | |
1059 | || r_type == R_MMIX_GNU_VTENTRY) | |
1060 | continue; | |
1061 | ||
1062 | r_symndx = ELF64_R_SYM (rel->r_info); | |
1063 | ||
1064 | if (info->relocateable) | |
1065 | { | |
1066 | /* This is a relocateable link. We don't have to change | |
1067 | anything, unless the reloc is against a section symbol, | |
1068 | in which case we have to adjust according to where the | |
1069 | section symbol winds up in the output section. */ | |
1070 | if (r_symndx < symtab_hdr->sh_info) | |
1071 | { | |
1072 | sym = local_syms + r_symndx; | |
1073 | ||
1074 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
1075 | { | |
1076 | sec = local_sections [r_symndx]; | |
1077 | rel->r_addend += sec->output_offset + sym->st_value; | |
1078 | } | |
1079 | } | |
1080 | ||
1081 | continue; | |
1082 | } | |
1083 | ||
1084 | /* This is a final link. */ | |
1085 | howto = elf_mmix_howto_table + ELF64_R_TYPE (rel->r_info); | |
1086 | h = NULL; | |
1087 | sym = NULL; | |
1088 | sec = NULL; | |
1089 | ||
1090 | if (r_symndx < symtab_hdr->sh_info) | |
1091 | { | |
1092 | sym = local_syms + r_symndx; | |
1093 | sec = local_sections [r_symndx]; | |
f8df10f4 | 1094 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
3c3bdf30 NC |
1095 | |
1096 | name = bfd_elf_string_from_elf_section | |
1097 | (input_bfd, symtab_hdr->sh_link, sym->st_name); | |
1098 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; | |
1099 | } | |
1100 | else | |
1101 | { | |
1102 | h = sym_hashes [r_symndx - symtab_hdr->sh_info]; | |
1103 | ||
1104 | while (h->root.type == bfd_link_hash_indirect | |
1105 | || h->root.type == bfd_link_hash_warning) | |
1106 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
1107 | ||
1108 | name = h->root.root.string; | |
1109 | ||
1110 | if (h->root.type == bfd_link_hash_defined | |
1111 | || h->root.type == bfd_link_hash_defweak) | |
1112 | { | |
1113 | sec = h->root.u.def.section; | |
1114 | relocation = (h->root.u.def.value | |
1115 | + sec->output_section->vma | |
1116 | + sec->output_offset); | |
1117 | } | |
1118 | else if (h->root.type == bfd_link_hash_undefweak) | |
1119 | relocation = 0; | |
1120 | else if (info->shared | |
1121 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
1122 | relocation = 0; | |
1123 | else | |
1124 | { | |
1125 | /* The test on undefined_signalled is redundant at the | |
1126 | moment, but kept for symmetry. */ | |
1127 | if (! undefined_signalled | |
1128 | && ! ((*info->callbacks->undefined_symbol) | |
1129 | (info, h->root.root.string, input_bfd, | |
1130 | input_section, rel->r_offset, true))) | |
1131 | return false; | |
1132 | undefined_signalled = true; | |
1133 | relocation = 0; | |
1134 | } | |
1135 | } | |
1136 | ||
1137 | r = mmix_final_link_relocate (howto, input_section, | |
1138 | contents, rel->r_offset, | |
1139 | rel->r_addend, relocation, name, sec); | |
1140 | ||
1141 | if (r != bfd_reloc_ok) | |
1142 | { | |
1143 | boolean check_ok = true; | |
1144 | const char * msg = (const char *) NULL; | |
1145 | ||
1146 | switch (r) | |
1147 | { | |
1148 | case bfd_reloc_overflow: | |
1149 | check_ok = info->callbacks->reloc_overflow | |
1150 | (info, name, howto->name, (bfd_vma) 0, | |
1151 | input_bfd, input_section, rel->r_offset); | |
1152 | break; | |
1153 | ||
1154 | case bfd_reloc_undefined: | |
1155 | /* We may have sent this message above. */ | |
1156 | if (! undefined_signalled) | |
1157 | check_ok = info->callbacks->undefined_symbol | |
1158 | (info, name, input_bfd, input_section, rel->r_offset, | |
1159 | true); | |
1160 | undefined_signalled = true; | |
1161 | break; | |
1162 | ||
1163 | case bfd_reloc_outofrange: | |
1164 | msg = _("internal error: out of range error"); | |
1165 | break; | |
1166 | ||
1167 | case bfd_reloc_notsupported: | |
1168 | msg = _("internal error: unsupported relocation error"); | |
1169 | break; | |
1170 | ||
1171 | case bfd_reloc_dangerous: | |
1172 | msg = _("internal error: dangerous relocation"); | |
1173 | break; | |
1174 | ||
1175 | default: | |
1176 | msg = _("internal error: unknown error"); | |
1177 | break; | |
1178 | } | |
1179 | ||
1180 | if (msg) | |
1181 | check_ok = info->callbacks->warning | |
1182 | (info, msg, name, input_bfd, input_section, rel->r_offset); | |
1183 | ||
1184 | if (! check_ok) | |
1185 | return false; | |
1186 | } | |
1187 | } | |
1188 | ||
1189 | return true; | |
1190 | } | |
e06fcc86 | 1191 | \f |
3c3bdf30 NC |
1192 | /* Perform a single relocation. By default we use the standard BFD |
1193 | routines. A few relocs we have to do ourselves. */ | |
1194 | ||
1195 | static bfd_reloc_status_type | |
1196 | mmix_final_link_relocate (howto, input_section, contents, | |
1197 | r_offset, r_addend, relocation, symname, symsec) | |
1198 | reloc_howto_type *howto; | |
1199 | asection *input_section; | |
1200 | bfd_byte *contents; | |
1201 | bfd_vma r_offset; | |
1202 | bfd_signed_vma r_addend; | |
1203 | bfd_vma relocation; | |
1204 | const char *symname; | |
1205 | asection *symsec; | |
1206 | { | |
1207 | bfd_reloc_status_type r = bfd_reloc_ok; | |
1208 | bfd_vma addr | |
1209 | = (input_section->output_section->vma | |
1210 | + input_section->output_offset | |
1211 | + r_offset); | |
1212 | bfd_signed_vma srel | |
1213 | = (bfd_signed_vma) relocation + r_addend; | |
1214 | ||
1215 | switch (howto->type) | |
1216 | { | |
1217 | /* All these are PC-relative. */ | |
1218 | case R_MMIX_PUSHJ: | |
1219 | case R_MMIX_CBRANCH: | |
1220 | case R_MMIX_ADDR19: | |
1221 | case R_MMIX_GETA: | |
1222 | case R_MMIX_ADDR27: | |
1223 | case R_MMIX_JMP: | |
1224 | contents += r_offset; | |
1225 | ||
1226 | srel -= (input_section->output_section->vma | |
1227 | + input_section->output_offset | |
1228 | + r_offset); | |
1229 | ||
1230 | r = mmix_elf_perform_relocation (input_section, howto, contents, | |
1231 | addr, srel); | |
1232 | break; | |
1233 | ||
1234 | case R_MMIX_REG_OR_BYTE: | |
1235 | case R_MMIX_REG: | |
1236 | /* For now, we handle these alike. They must refer to an register | |
1237 | symbol, which is either relative to the register section and in | |
1238 | the range 0..255, or is in the register contents section with vma | |
1239 | regno * 8. */ | |
1240 | ||
1241 | /* FIXME: A better way to check for reg contents section? | |
1242 | FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */ | |
1243 | if (symsec == NULL) | |
1244 | return bfd_reloc_undefined; | |
1245 | ||
1246 | if (strcmp (bfd_get_section_name (symsec->owner, symsec), | |
1247 | MMIX_REG_CONTENTS_SECTION_NAME) == 0) | |
1248 | { | |
1249 | if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8) | |
1250 | { | |
1251 | /* The bfd_reloc_outofrange return value, though intuitively | |
1252 | a better value, will not get us an error. */ | |
1253 | return bfd_reloc_overflow; | |
1254 | } | |
1255 | srel /= 8; | |
1256 | } | |
1257 | else if (strcmp (bfd_get_section_name (symsec->owner, symsec), | |
1258 | MMIX_REG_SECTION_NAME) == 0) | |
1259 | { | |
1260 | if (srel < 0 || srel > 255) | |
1261 | /* The bfd_reloc_outofrange return value, though intuitively a | |
1262 | better value, will not get us an error. */ | |
1263 | return bfd_reloc_overflow; | |
1264 | } | |
1265 | else | |
1266 | { | |
ca09e32b NC |
1267 | /* Note: This is seperated out into two messages in order |
1268 | to ease the translation into other languages. */ | |
1269 | if (symname == NULL || *symname == 0) | |
1270 | (*_bfd_error_handler) | |
1271 | (_("%s: register relocation against non-register symbol: (unknown) in %s"), | |
1272 | bfd_get_filename (input_section->owner), | |
1273 | bfd_get_section_name (symsec->owner, symsec)); | |
1274 | else | |
1275 | (*_bfd_error_handler) | |
1276 | (_("%s: register relocation against non-register symbol: %s in %s"), | |
1277 | bfd_get_filename (input_section->owner), symname, | |
1278 | bfd_get_section_name (symsec->owner, symsec)); | |
3c3bdf30 NC |
1279 | |
1280 | /* The bfd_reloc_outofrange return value, though intuitively a | |
1281 | better value, will not get us an error. */ | |
1282 | return bfd_reloc_overflow; | |
1283 | } | |
1284 | contents += r_offset; | |
1285 | r = mmix_elf_perform_relocation (input_section, howto, contents, | |
1286 | addr, srel); | |
1287 | break; | |
1288 | ||
1289 | case R_MMIX_LOCAL: | |
1290 | /* This isn't a real relocation, it's just an assertion that the | |
1291 | final relocation value corresponds to a local register. We | |
1292 | ignore the actual relocation; nothing is changed. */ | |
1293 | { | |
1294 | asection *regsec | |
1295 | = bfd_get_section_by_name (input_section->output_section->owner, | |
1296 | MMIX_REG_CONTENTS_SECTION_NAME); | |
1297 | bfd_vma first_global; | |
1298 | ||
1299 | /* Check that this is an absolute value, or a reference to the | |
1300 | register contents section or the register (symbol) section. | |
1301 | Absolute numbers can get here as undefined section. Undefined | |
1302 | symbols are signalled elsewhere, so there's no conflict in us | |
1303 | accidentally handling it. */ | |
1304 | if (!bfd_is_abs_section (symsec) | |
1305 | && !bfd_is_und_section (symsec) | |
1306 | && strcmp (bfd_get_section_name (symsec->owner, symsec), | |
1307 | MMIX_REG_CONTENTS_SECTION_NAME) != 0 | |
1308 | && strcmp (bfd_get_section_name (symsec->owner, symsec), | |
1309 | MMIX_REG_SECTION_NAME) != 0) | |
1310 | { | |
1311 | (*_bfd_error_handler) | |
1312 | (_("%s: directive LOCAL valid only with a register or absolute value"), | |
1313 | bfd_get_filename (input_section->owner)); | |
1314 | ||
1315 | return bfd_reloc_overflow; | |
1316 | } | |
1317 | ||
1318 | /* If we don't have a register contents section, then $255 is the | |
1319 | first global register. */ | |
1320 | if (regsec == NULL) | |
1321 | first_global = 255; | |
1322 | else | |
1323 | { | |
1324 | first_global = bfd_get_section_vma (abfd, regsec) / 8; | |
1325 | if (strcmp (bfd_get_section_name (symsec->owner, symsec), | |
1326 | MMIX_REG_CONTENTS_SECTION_NAME) == 0) | |
1327 | { | |
1328 | if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8) | |
1329 | /* The bfd_reloc_outofrange return value, though | |
1330 | intuitively a better value, will not get us an error. */ | |
1331 | return bfd_reloc_overflow; | |
1332 | srel /= 8; | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | if ((bfd_vma) srel >= first_global) | |
1337 | { | |
1338 | /* FIXME: Better error message. */ | |
1339 | (*_bfd_error_handler) | |
1340 | (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."), | |
1341 | bfd_get_filename (input_section->owner), (long) srel, (long) first_global); | |
1342 | ||
1343 | return bfd_reloc_overflow; | |
1344 | } | |
1345 | } | |
1346 | r = bfd_reloc_ok; | |
1347 | break; | |
1348 | ||
1349 | default: | |
1350 | r = _bfd_final_link_relocate (howto, input_section->owner, input_section, | |
1351 | contents, r_offset, | |
1352 | relocation, r_addend); | |
1353 | } | |
1354 | ||
1355 | return r; | |
1356 | } | |
e06fcc86 | 1357 | \f |
3c3bdf30 NC |
1358 | /* Return the section that should be marked against GC for a given |
1359 | relocation. */ | |
1360 | ||
1361 | static asection * | |
1362 | mmix_elf_gc_mark_hook (abfd, info, rel, h, sym) | |
1363 | bfd *abfd; | |
1364 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
1365 | Elf_Internal_Rela *rel; | |
1366 | struct elf_link_hash_entry *h; | |
1367 | Elf_Internal_Sym *sym; | |
1368 | { | |
1369 | if (h != NULL) | |
1370 | { | |
1371 | switch (ELF64_R_TYPE (rel->r_info)) | |
1372 | { | |
1373 | case R_MMIX_GNU_VTINHERIT: | |
1374 | case R_MMIX_GNU_VTENTRY: | |
1375 | break; | |
1376 | ||
1377 | default: | |
1378 | switch (h->root.type) | |
1379 | { | |
1380 | case bfd_link_hash_defined: | |
1381 | case bfd_link_hash_defweak: | |
1382 | return h->root.u.def.section; | |
1383 | ||
1384 | case bfd_link_hash_common: | |
1385 | return h->root.u.c.p->section; | |
1386 | ||
1387 | default: | |
1388 | break; | |
1389 | } | |
1390 | } | |
1391 | } | |
1392 | else | |
1393 | { | |
9ad5cbcf | 1394 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
3c3bdf30 NC |
1395 | } |
1396 | ||
1397 | return NULL; | |
1398 | } | |
e06fcc86 | 1399 | \f |
3c3bdf30 NC |
1400 | /* Sort register relocs to come before expanding relocs. */ |
1401 | ||
1402 | static int | |
1403 | mmix_elf_sort_relocs (p1, p2) | |
1404 | const PTR p1; | |
1405 | const PTR p2; | |
1406 | { | |
1407 | const Elf_Internal_Rela *r1 = (const Elf_Internal_Rela *) p1; | |
1408 | const Elf_Internal_Rela *r2 = (const Elf_Internal_Rela *) p2; | |
1409 | int r1_is_reg, r2_is_reg; | |
1410 | ||
1411 | /* Sort primarily on r_offset & ~3, so relocs are done to consecutive | |
1412 | insns. */ | |
1413 | if ((r1->r_offset & ~(bfd_vma) 3) > (r2->r_offset & ~(bfd_vma) 3)) | |
1414 | return 1; | |
1415 | else if ((r1->r_offset & ~(bfd_vma) 3) < (r2->r_offset & ~(bfd_vma) 3)) | |
1416 | return -1; | |
1417 | ||
1418 | r1_is_reg | |
1419 | = (ELF64_R_TYPE (r1->r_info) == R_MMIX_REG_OR_BYTE | |
1420 | || ELF64_R_TYPE (r1->r_info) == R_MMIX_REG); | |
1421 | r2_is_reg | |
1422 | = (ELF64_R_TYPE (r2->r_info) == R_MMIX_REG_OR_BYTE | |
1423 | || ELF64_R_TYPE (r2->r_info) == R_MMIX_REG); | |
1424 | if (r1_is_reg != r2_is_reg) | |
1425 | return r2_is_reg - r1_is_reg; | |
1426 | ||
1427 | /* Neither or both are register relocs. Then sort on full offset. */ | |
1428 | if (r1->r_offset > r2->r_offset) | |
1429 | return 1; | |
1430 | else if (r1->r_offset < r2->r_offset) | |
1431 | return -1; | |
1432 | return 0; | |
1433 | } | |
1434 | ||
1435 | /* Look through the relocs for a section during the first phase. */ | |
1436 | ||
1437 | static boolean | |
1438 | mmix_elf_check_relocs (abfd, info, sec, relocs) | |
1439 | bfd *abfd; | |
1440 | struct bfd_link_info *info; | |
1441 | asection *sec; | |
1442 | const Elf_Internal_Rela *relocs; | |
1443 | { | |
1444 | Elf_Internal_Shdr *symtab_hdr; | |
1445 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
1446 | const Elf_Internal_Rela *rel; | |
1447 | const Elf_Internal_Rela *rel_end; | |
1448 | ||
1449 | if (info->relocateable) | |
1450 | return true; | |
1451 | ||
1452 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
1453 | sym_hashes = elf_sym_hashes (abfd); | |
1454 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf64_External_Sym); | |
1455 | if (!elf_bad_symtab (abfd)) | |
1456 | sym_hashes_end -= symtab_hdr->sh_info; | |
1457 | ||
1458 | /* First we sort the relocs so that any register relocs come before | |
1459 | expansion-relocs to the same insn. FIXME: Not done for mmo. */ | |
1460 | qsort ((PTR) relocs, sec->reloc_count, sizeof (Elf_Internal_Rela), | |
1461 | mmix_elf_sort_relocs); | |
1462 | ||
1463 | rel_end = relocs + sec->reloc_count; | |
1464 | for (rel = relocs; rel < rel_end; rel++) | |
1465 | { | |
1466 | struct elf_link_hash_entry *h; | |
1467 | unsigned long r_symndx; | |
1468 | ||
1469 | r_symndx = ELF64_R_SYM (rel->r_info); | |
1470 | if (r_symndx < symtab_hdr->sh_info) | |
1471 | h = NULL; | |
1472 | else | |
1473 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1474 | ||
1475 | switch (ELF64_R_TYPE (rel->r_info)) | |
1476 | { | |
1477 | /* This relocation describes the C++ object vtable hierarchy. | |
1478 | Reconstruct it for later use during GC. */ | |
1479 | case R_MMIX_GNU_VTINHERIT: | |
1480 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
1481 | return false; | |
1482 | break; | |
1483 | ||
1484 | /* This relocation describes which C++ vtable entries are actually | |
1485 | used. Record for later use during GC. */ | |
1486 | case R_MMIX_GNU_VTENTRY: | |
1487 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
1488 | return false; | |
1489 | break; | |
1490 | } | |
1491 | } | |
1492 | ||
1493 | return true; | |
1494 | } | |
e06fcc86 | 1495 | \f |
3c3bdf30 NC |
1496 | /* Change symbols relative to the reg contents section to instead be to |
1497 | the register section, and scale them down to correspond to the register | |
1498 | number. */ | |
1499 | ||
1500 | static boolean | |
1501 | mmix_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec) | |
1502 | bfd *abfd ATTRIBUTE_UNUSED; | |
1503 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
1504 | const char *name ATTRIBUTE_UNUSED; | |
1505 | Elf_Internal_Sym *sym; | |
1506 | asection *input_sec; | |
1507 | { | |
1508 | if (input_sec != NULL | |
1509 | && input_sec->name != NULL | |
1510 | && ELF_ST_TYPE (sym->st_info) != STT_SECTION | |
1511 | && strcmp (input_sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0) | |
1512 | { | |
1513 | sym->st_value /= 8; | |
1514 | sym->st_shndx = SHN_REGISTER; | |
1515 | } | |
1516 | ||
1517 | return true; | |
1518 | } | |
1519 | ||
1520 | /* We fake a register section that holds values that are register numbers. | |
1521 | Having a SHN_REGISTER and register section translates better to other | |
1522 | formats (e.g. mmo) than for example a STT_REGISTER attribute. | |
1523 | This section faking is based on a construct in elf32-mips.c. */ | |
1524 | static asection mmix_elf_reg_section; | |
1525 | static asymbol mmix_elf_reg_section_symbol; | |
1526 | static asymbol *mmix_elf_reg_section_symbol_ptr; | |
1527 | ||
1528 | /* Handle the special MIPS section numbers that a symbol may use. | |
1529 | This is used for both the 32-bit and the 64-bit ABI. */ | |
1530 | ||
1531 | void | |
1532 | mmix_elf_symbol_processing (abfd, asym) | |
1533 | bfd *abfd ATTRIBUTE_UNUSED; | |
1534 | asymbol *asym; | |
1535 | { | |
1536 | elf_symbol_type *elfsym; | |
1537 | ||
1538 | elfsym = (elf_symbol_type *) asym; | |
1539 | switch (elfsym->internal_elf_sym.st_shndx) | |
1540 | { | |
1541 | case SHN_REGISTER: | |
1542 | if (mmix_elf_reg_section.name == NULL) | |
1543 | { | |
1544 | /* Initialize the register section. */ | |
1545 | mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME; | |
1546 | mmix_elf_reg_section.flags = SEC_NO_FLAGS; | |
1547 | mmix_elf_reg_section.output_section = &mmix_elf_reg_section; | |
1548 | mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol; | |
1549 | mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr; | |
1550 | mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME; | |
1551 | mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM; | |
1552 | mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section; | |
1553 | mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol; | |
1554 | } | |
1555 | asym->section = &mmix_elf_reg_section; | |
1556 | break; | |
1557 | ||
1558 | default: | |
1559 | break; | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | /* Given a BFD section, try to locate the corresponding ELF section | |
1564 | index. */ | |
1565 | ||
1566 | static boolean | |
af746e92 | 1567 | mmix_elf_section_from_bfd_section (abfd, sec, retval) |
3c3bdf30 | 1568 | bfd * abfd ATTRIBUTE_UNUSED; |
3c3bdf30 NC |
1569 | asection * sec; |
1570 | int * retval; | |
1571 | { | |
1572 | if (strcmp (bfd_get_section_name (abfd, sec), MMIX_REG_SECTION_NAME) == 0) | |
1573 | *retval = SHN_REGISTER; | |
1574 | else | |
1575 | return false; | |
1576 | ||
1577 | return true; | |
1578 | } | |
1579 | ||
1580 | /* Hook called by the linker routine which adds symbols from an object | |
1581 | file. We must handle the special SHN_REGISTER section number here. | |
1582 | ||
1583 | We also check that we only have *one* each of the section-start | |
1584 | symbols, since otherwise having two with the same value would cause | |
1585 | them to be "merged", but with the contents serialized. */ | |
1586 | ||
1587 | boolean | |
1588 | mmix_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) | |
1589 | bfd *abfd; | |
1590 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
1591 | const Elf_Internal_Sym *sym; | |
1592 | const char **namep ATTRIBUTE_UNUSED; | |
1593 | flagword *flagsp ATTRIBUTE_UNUSED; | |
1594 | asection **secp; | |
1595 | bfd_vma *valp ATTRIBUTE_UNUSED; | |
1596 | { | |
1597 | if (sym->st_shndx == SHN_REGISTER) | |
1598 | *secp = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME); | |
1599 | else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.' | |
1600 | && strncmp (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX, | |
1601 | strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)) == 0) | |
1602 | { | |
1603 | /* See if we have another one. */ | |
1604 | struct elf_link_hash_entry *h | |
1605 | = (struct elf_link_hash_entry *) bfd_link_hash_lookup (info->hash, | |
1606 | *namep, | |
1607 | false, | |
1608 | false, false); | |
1609 | ||
1610 | if (h != NULL && h->root.type != bfd_link_hash_undefined) | |
1611 | { | |
1612 | /* How do we get the asymbol (or really: the filename) from h? | |
1613 | h->root.u.def.section->owner is NULL. */ | |
1614 | ((*_bfd_error_handler) | |
1615 | (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"), | |
1616 | bfd_get_filename (abfd), *namep, | |
1617 | *namep + strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX))); | |
1618 | bfd_set_error (bfd_error_bad_value); | |
1619 | return false; | |
1620 | } | |
1621 | } | |
1622 | ||
1623 | return true; | |
1624 | } | |
1625 | ||
1626 | /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */ | |
1627 | ||
1628 | boolean | |
1629 | mmix_elf_is_local_label_name (abfd, name) | |
1630 | bfd *abfd; | |
1631 | const char *name; | |
1632 | { | |
1633 | const char *colpos; | |
1634 | int digits; | |
1635 | ||
1636 | /* Also include the default local-label definition. */ | |
1637 | if (_bfd_elf_is_local_label_name (abfd, name)) | |
1638 | return true; | |
1639 | ||
1640 | if (*name != 'L') | |
1641 | return false; | |
1642 | ||
1643 | /* If there's no ":", or more than one, it's not a local symbol. */ | |
1644 | colpos = strchr (name, ':'); | |
1645 | if (colpos == NULL || strchr (colpos + 1, ':') != NULL) | |
1646 | return false; | |
1647 | ||
1648 | /* Check that there are remaining characters and that they are digits. */ | |
1649 | if (colpos[1] == 0) | |
1650 | return false; | |
1651 | ||
1652 | digits = strspn (colpos + 1, "0123456789"); | |
1653 | return digits != 0 && colpos[1 + digits] == 0; | |
1654 | } | |
1655 | ||
1656 | /* We get rid of the register section here. */ | |
1657 | ||
1658 | boolean | |
1659 | mmix_elf_final_link (abfd, info) | |
1660 | bfd *abfd; | |
1661 | struct bfd_link_info *info; | |
1662 | { | |
1663 | /* We never output a register section, though we create one for | |
1664 | temporary measures. Check that nobody entered contents into it. */ | |
1665 | asection *reg_section; | |
1666 | asection **secpp; | |
1667 | ||
1668 | reg_section = bfd_get_section_by_name (abfd, MMIX_REG_SECTION_NAME); | |
1669 | ||
1670 | if (reg_section != NULL) | |
1671 | { | |
1672 | /* FIXME: Pass error state gracefully. */ | |
1673 | if (bfd_get_section_flags (abfd, reg_section) & SEC_HAS_CONTENTS) | |
1674 | _bfd_abort (__FILE__, __LINE__, _("Register section has contents\n")); | |
1675 | ||
3c3bdf30 NC |
1676 | /* Really remove the section. */ |
1677 | for (secpp = &abfd->sections; | |
1678 | *secpp != reg_section; | |
1679 | secpp = &(*secpp)->next) | |
1680 | ; | |
9e7b37b3 | 1681 | bfd_section_list_remove (abfd, secpp); |
3c3bdf30 NC |
1682 | --abfd->section_count; |
1683 | } | |
1684 | ||
1685 | if (! bfd_elf64_bfd_final_link (abfd, info)) | |
1686 | return false; | |
1687 | ||
1688 | return true; | |
1689 | } | |
e06fcc86 | 1690 | \f |
3c3bdf30 NC |
1691 | #define ELF_ARCH bfd_arch_mmix |
1692 | #define ELF_MACHINE_CODE EM_MMIX | |
1693 | ||
1694 | /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL). | |
1695 | However, that's too much for something somewhere in the linker part of | |
1696 | BFD; perhaps the start-address has to be a non-zero multiple of this | |
1697 | number, or larger than this number. The symptom is that the linker | |
1698 | complains: "warning: allocated section `.text' not in segment". We | |
1699 | settle for 64k; the page-size used in examples is 8k. | |
1700 | #define ELF_MAXPAGESIZE 0x10000 | |
1701 | ||
1702 | Unfortunately, this causes excessive padding in the supposedly small | |
1703 | for-education programs that are the expected usage (where people would | |
1704 | inspect output). We stick to 256 bytes just to have *some* default | |
1705 | alignment. */ | |
1706 | #define ELF_MAXPAGESIZE 0x100 | |
1707 | ||
1708 | #define TARGET_BIG_SYM bfd_elf64_mmix_vec | |
1709 | #define TARGET_BIG_NAME "elf64-mmix" | |
1710 | ||
1711 | #define elf_info_to_howto_rel NULL | |
1712 | #define elf_info_to_howto mmix_info_to_howto_rela | |
1713 | #define elf_backend_relocate_section mmix_elf_relocate_section | |
1714 | #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook | |
1715 | #define elf_backend_link_output_symbol_hook \ | |
1716 | mmix_elf_link_output_symbol_hook | |
1717 | #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook | |
1718 | ||
1719 | #define elf_backend_check_relocs mmix_elf_check_relocs | |
1720 | #define elf_backend_symbol_processing mmix_elf_symbol_processing | |
1721 | ||
1722 | #define bfd_elf64_bfd_is_local_label_name \ | |
1723 | mmix_elf_is_local_label_name | |
1724 | ||
1725 | #define elf_backend_may_use_rel_p 0 | |
1726 | #define elf_backend_may_use_rela_p 1 | |
1727 | #define elf_backend_default_use_rela_p 1 | |
1728 | ||
1729 | #define elf_backend_can_gc_sections 1 | |
1730 | #define elf_backend_section_from_bfd_section \ | |
1731 | mmix_elf_section_from_bfd_section | |
1732 | ||
1733 | #define bfd_elf64_bfd_final_link mmix_elf_final_link | |
1734 | ||
1735 | #include "elf64-target.h" |