/src/binutils-gdb/bfd/coff-mcore.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* BFD back-end for Motorola MCore COFF/PE |
2 | | Copyright (C) 1999-2025 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of BFD, the Binary File Descriptor library. |
5 | | |
6 | | This program is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3 of the License, or |
9 | | (at your option) any later version. |
10 | | |
11 | | This program is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, 51 Franklin Street - Fifth Floor, |
19 | | Boston, MA 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include "bfd.h" |
23 | | #include "libbfd.h" |
24 | | #include "coff/mcore.h" |
25 | | #include "coff/internal.h" |
26 | | #include "coff/pe.h" |
27 | | #include "libcoff.h" |
28 | | |
29 | | #ifdef BADMAG |
30 | | #undef BADMAG |
31 | | #endif |
32 | 7.77M | #define BADMAG(x) MCOREBADMAG(x) |
33 | | |
34 | | #ifndef NUM_ELEM |
35 | 1.00k | #define NUM_ELEM(A) (sizeof (A) / sizeof (A)[0]) |
36 | | #endif |
37 | | |
38 | | /* This file is compiled more than once, but we only compile the |
39 | | final_link routine once. */ |
40 | | extern bool mcore_bfd_coff_final_link |
41 | | (bfd *, struct bfd_link_info *); |
42 | | static bfd_reloc_status_type mcore_coff_unsupported_reloc |
43 | | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
44 | | |
45 | | |
46 | | /* The NT loader points the toc register to &toc + 32768, in order to |
47 | | use the complete range of a 16-bit displacement. We have to adjust |
48 | | for this when we fix up loads displaced off the toc reg. */ |
49 | | #define TOC_LOAD_ADJUSTMENT (-32768) |
50 | | #define TOC_SECTION_NAME ".private.toc" |
51 | | |
52 | | /* The main body of code is in coffcode.h. */ |
53 | 972k | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 |
54 | | |
55 | | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value |
56 | | from smaller values. Start with zero, widen, *then* decrement. */ |
57 | | #define MINUS_ONE (((bfd_vma)0) - 1) |
58 | | |
59 | | static reloc_howto_type mcore_coff_howto_table[] = |
60 | | { |
61 | | /* Unused: */ |
62 | | HOWTO (IMAGE_REL_MCORE_ABSOLUTE,/* type */ |
63 | | 0, /* rightshift */ |
64 | | 0, /* size */ |
65 | | 0, /* bitsize */ |
66 | | false, /* pc_relative */ |
67 | | 0, /* bitpos */ |
68 | | complain_overflow_dont, /* dont complain_on_overflow */ |
69 | | NULL, /* special_function */ |
70 | | "ABSOLUTE", /* name */ |
71 | | false, /* partial_inplace */ |
72 | | 0x00, /* src_mask */ |
73 | | 0x00, /* dst_mask */ |
74 | | false), /* pcrel_offset */ |
75 | | |
76 | | HOWTO (IMAGE_REL_MCORE_ADDR32,/* type */ |
77 | | 0, /* rightshift */ |
78 | | 4, /* size */ |
79 | | 32, /* bitsize */ |
80 | | false, /* pc_relative */ |
81 | | 0, /* bitpos */ |
82 | | complain_overflow_bitfield, /* complain_on_overflow */ |
83 | | NULL, /* special_function */ |
84 | | "ADDR32", /* name */ |
85 | | true, /* partial_inplace */ |
86 | | 0xffffffff, /* src_mask */ |
87 | | 0xffffffff, /* dst_mask */ |
88 | | false), /* pcrel_offset */ |
89 | | |
90 | | /* 8 bits + 2 zero bits; jmpi/jsri/lrw instructions. |
91 | | Should not appear in object files. */ |
92 | | HOWTO (IMAGE_REL_MCORE_PCREL_IMM8BY4, /* type */ |
93 | | 2, /* rightshift */ |
94 | | 2, /* size */ |
95 | | 8, /* bitsize */ |
96 | | true, /* pc_relative */ |
97 | | 0, /* bitpos */ |
98 | | complain_overflow_bitfield, /* complain_on_overflow */ |
99 | | mcore_coff_unsupported_reloc, /* special_function */ |
100 | | "IMM8BY4", /* name */ |
101 | | false, /* partial_inplace */ |
102 | | 0, /* src_mask */ |
103 | | 0, /* dst_mask */ |
104 | | true), /* pcrel_offset */ |
105 | | |
106 | | /* bsr/bt/bf/br instructions; 11 bits + 1 zero bit |
107 | | Span 2k instructions == 4k bytes. |
108 | | Only useful pieces at the relocated address are the opcode (5 bits) */ |
109 | | HOWTO (IMAGE_REL_MCORE_PCREL_IMM11BY2,/* type */ |
110 | | 1, /* rightshift */ |
111 | | 2, /* size */ |
112 | | 11, /* bitsize */ |
113 | | true, /* pc_relative */ |
114 | | 0, /* bitpos */ |
115 | | complain_overflow_signed, /* complain_on_overflow */ |
116 | | NULL, /* special_function */ |
117 | | "IMM11BY2", /* name */ |
118 | | false, /* partial_inplace */ |
119 | | 0x0, /* src_mask */ |
120 | | 0x7ff, /* dst_mask */ |
121 | | true), /* pcrel_offset */ |
122 | | |
123 | | /* 4 bits + 1 zero bit; 'loopt' instruction only; unsupported. */ |
124 | | HOWTO (IMAGE_REL_MCORE_PCREL_IMM4BY2, /* type */ |
125 | | 1, /* rightshift */ |
126 | | 2, /* size */ |
127 | | 4, /* bitsize */ |
128 | | true, /* pc_relative */ |
129 | | 0, /* bitpos */ |
130 | | complain_overflow_bitfield, /* complain_on_overflow */ |
131 | | mcore_coff_unsupported_reloc, /* special_function */ |
132 | | "IMM4BY2", /* name */ |
133 | | false, /* partial_inplace */ |
134 | | 0, /* src_mask */ |
135 | | 0, /* dst_mask */ |
136 | | true), /* pcrel_offset */ |
137 | | |
138 | | /* 32-bit pc-relative. Eventually this will help support PIC code. */ |
139 | | HOWTO (IMAGE_REL_MCORE_PCREL_32,/* type */ |
140 | | 0, /* rightshift */ |
141 | | 4, /* size */ |
142 | | 32, /* bitsize */ |
143 | | true, /* pc_relative */ |
144 | | 0, /* bitpos */ |
145 | | complain_overflow_bitfield, /* complain_on_overflow */ |
146 | | NULL, /* special_function */ |
147 | | "PCREL_32", /* name */ |
148 | | false, /* partial_inplace */ |
149 | | 0x0, /* src_mask */ |
150 | | 0xffffffff, /* dst_mask */ |
151 | | true), /* pcrel_offset */ |
152 | | |
153 | | /* Like PCREL_IMM11BY2, this relocation indicates that there is a |
154 | | 'jsri' at the specified address. There is a separate relocation |
155 | | entry for the literal pool entry that it references, but we |
156 | | might be able to change the jsri to a bsr if the target turns out |
157 | | to be close enough [even though we won't reclaim the literal pool |
158 | | entry, we'll get some runtime efficiency back]. Note that this |
159 | | is a relocation that we are allowed to safely ignore. */ |
160 | | HOWTO (IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2,/* type */ |
161 | | 1, /* rightshift */ |
162 | | 2, /* size */ |
163 | | 11, /* bitsize */ |
164 | | true, /* pc_relative */ |
165 | | 0, /* bitpos */ |
166 | | complain_overflow_signed, /* complain_on_overflow */ |
167 | | NULL, /* special_function */ |
168 | | "JSR_IMM11BY2", /* name */ |
169 | | false, /* partial_inplace */ |
170 | | 0x0, /* src_mask */ |
171 | | 0x7ff, /* dst_mask */ |
172 | | true), /* pcrel_offset */ |
173 | | |
174 | | HOWTO (IMAGE_REL_MCORE_RVA, /* type */ |
175 | | 0, /* rightshift */ |
176 | | 4, /* size */ |
177 | | 32, /* bitsize */ |
178 | | false, /* pc_relative */ |
179 | | 0, /* bitpos */ |
180 | | complain_overflow_signed, /* complain_on_overflow */ |
181 | | NULL, /* special_function */ |
182 | | "MCORE_RVA", /* name */ |
183 | | true, /* partial_inplace */ |
184 | | 0xffffffff, /* src_mask */ |
185 | | 0xffffffff, /* dst_mask */ |
186 | | true) /* pcrel_offset */ |
187 | | }; |
188 | | |
189 | | /* Extend the coff_link_hash_table structure with a few M*Core specific fields. |
190 | | This allows us to store global data here without actually creating any |
191 | | global variables, which is a no-no in the BFD world. */ |
192 | | typedef struct coff_mcore_link_hash_table |
193 | | { |
194 | | /* The original coff_link_hash_table structure. MUST be first field. */ |
195 | | struct coff_link_hash_table root; |
196 | | |
197 | | bfd * bfd_of_toc_owner; |
198 | | long int global_toc_size; |
199 | | long int import_table_size; |
200 | | long int first_thunk_address; |
201 | | long int thunk_size; |
202 | | } |
203 | | mcore_hash_table; |
204 | | |
205 | | /* Get the MCore coff linker hash table from a link_info structure. */ |
206 | | #define coff_mcore_hash_table(info) \ |
207 | | ((mcore_hash_table *) ((info)->hash)) |
208 | | |
209 | | |
210 | | /* Add an entry to the base file. */ |
211 | | |
212 | | static bool |
213 | | mcore_emit_base_file_entry (struct bfd_link_info *info, |
214 | | bfd *output_bfd, |
215 | | asection *input_section, |
216 | | bfd_vma reloc_offset) |
217 | 0 | { |
218 | 0 | bfd_vma addr = reloc_offset |
219 | 0 | - input_section->vma |
220 | 0 | + input_section->output_offset |
221 | 0 | + input_section->output_section->vma; |
222 | |
|
223 | 0 | if (obj_pe (output_bfd)) |
224 | 0 | addr -= pe_data (output_bfd)->pe_opthdr.ImageBase; |
225 | |
|
226 | 0 | if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1) |
227 | 0 | return true; |
228 | | |
229 | 0 | bfd_set_error (bfd_error_system_call); |
230 | 0 | return false; |
231 | 0 | } Unexecuted instantiation: pe-mcore.c:mcore_emit_base_file_entry Unexecuted instantiation: pei-mcore.c:mcore_emit_base_file_entry |
232 | | |
233 | | static bfd_reloc_status_type |
234 | | mcore_coff_unsupported_reloc (bfd * abfd, |
235 | | arelent * reloc_entry, |
236 | | asymbol * symbol ATTRIBUTE_UNUSED, |
237 | | void * data ATTRIBUTE_UNUSED, |
238 | | asection * input_section ATTRIBUTE_UNUSED, |
239 | | bfd * output_bfd ATTRIBUTE_UNUSED, |
240 | | char ** error_message ATTRIBUTE_UNUSED) |
241 | 1 | { |
242 | 1 | BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0); |
243 | | |
244 | | /* xgettext: c-format */ |
245 | 1 | _bfd_error_handler (_("%pB: Relocation %s (%d) is not currently supported.\n"), |
246 | 1 | abfd, |
247 | 1 | reloc_entry->howto->name, |
248 | 1 | reloc_entry->howto->type); |
249 | | |
250 | 1 | return bfd_reloc_notsupported; |
251 | 1 | } pe-mcore.c:mcore_coff_unsupported_reloc Line | Count | Source | 241 | 1 | { | 242 | 1 | BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0); | 243 | | | 244 | | /* xgettext: c-format */ | 245 | 1 | _bfd_error_handler (_("%pB: Relocation %s (%d) is not currently supported.\n"), | 246 | 1 | abfd, | 247 | 1 | reloc_entry->howto->name, | 248 | 1 | reloc_entry->howto->type); | 249 | | | 250 | 1 | return bfd_reloc_notsupported; | 251 | 1 | } |
Unexecuted instantiation: pei-mcore.c:mcore_coff_unsupported_reloc |
252 | | |
253 | | /* A cheesy little macro to make the code a little more readable. */ |
254 | | #define HOW2MAP(bfd_rtype, mcore_rtype) \ |
255 | 0 | case bfd_rtype: return & mcore_coff_howto_table [mcore_rtype] |
256 | | |
257 | | static reloc_howto_type * |
258 | | mcore_coff_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
259 | | bfd_reloc_code_real_type code) |
260 | 0 | { |
261 | 0 | switch (code) |
262 | 0 | { |
263 | 0 | HOW2MAP (BFD_RELOC_32, IMAGE_REL_MCORE_ADDR32); |
264 | 0 | HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM8BY4, IMAGE_REL_MCORE_PCREL_IMM8BY4); |
265 | 0 | HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM11BY2, IMAGE_REL_MCORE_PCREL_IMM11BY2); |
266 | 0 | HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM4BY2, IMAGE_REL_MCORE_PCREL_IMM4BY2); |
267 | 0 | HOW2MAP (BFD_RELOC_32_PCREL, IMAGE_REL_MCORE_PCREL_32); |
268 | 0 | HOW2MAP (BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2, IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2); |
269 | 0 | HOW2MAP (BFD_RELOC_RVA, IMAGE_REL_MCORE_RVA); |
270 | 0 | default: |
271 | 0 | return NULL; |
272 | 0 | } |
273 | | /*NOTREACHED*/ |
274 | 0 | } Unexecuted instantiation: pe-mcore.c:mcore_coff_reloc_type_lookup Unexecuted instantiation: pei-mcore.c:mcore_coff_reloc_type_lookup |
275 | | #undef HOW2MAP |
276 | | |
277 | 1.00k | #define NUM_HOWTOS NUM_ELEM (mcore_coff_howto_table) |
278 | | |
279 | | static reloc_howto_type * |
280 | | mcore_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
281 | | const char *r_name) |
282 | 0 | { |
283 | 0 | unsigned int i; |
284 | |
|
285 | 0 | for (i = 0; i < NUM_HOWTOS; i++) |
286 | 0 | if (mcore_coff_howto_table[i].name != NULL |
287 | 0 | && strcasecmp (mcore_coff_howto_table[i].name, r_name) == 0) |
288 | 0 | return &mcore_coff_howto_table[i]; |
289 | | |
290 | 0 | return NULL; |
291 | 0 | } Unexecuted instantiation: pe-mcore.c:mcore_coff_reloc_name_lookup Unexecuted instantiation: pei-mcore.c:mcore_coff_reloc_name_lookup |
292 | | |
293 | | #define RTYPE2HOWTO(cache_ptr, dst) \ |
294 | 1.00k | ((cache_ptr)->howto = \ |
295 | 1.00k | ((dst)->r_type < NUM_HOWTOS \ |
296 | 1.00k | ? mcore_coff_howto_table + (dst)->r_type \ |
297 | 1.00k | : NULL)) |
298 | | |
299 | | static reloc_howto_type * |
300 | | coff_mcore_rtype_to_howto (bfd * abfd ATTRIBUTE_UNUSED, |
301 | | asection * sec, |
302 | | struct internal_reloc * rel, |
303 | | struct coff_link_hash_entry * h ATTRIBUTE_UNUSED, |
304 | | struct internal_syment * sym, |
305 | | bfd_vma * addendp) |
306 | 0 | { |
307 | 0 | reloc_howto_type * howto; |
308 | |
|
309 | 0 | if (rel->r_type >= NUM_HOWTOS) |
310 | 0 | return NULL; |
311 | | |
312 | 0 | howto = mcore_coff_howto_table + rel->r_type; |
313 | |
|
314 | 0 | if (rel->r_type == IMAGE_REL_MCORE_RVA) |
315 | 0 | * addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase; |
316 | | |
317 | 0 | else if (howto->pc_relative) |
318 | 0 | { |
319 | 0 | * addendp = sec->vma - 2; /* XXX guess - is this right ? */ |
320 | | |
321 | | /* If the symbol is defined, then the generic code is going to |
322 | | add back the symbol value in order to cancel out an |
323 | | adjustment it made to the addend. However, we set the addend |
324 | | to 0 at the start of this function. We need to adjust here, |
325 | | to avoid the adjustment the generic code will make. FIXME: |
326 | | This is getting a bit hackish. */ |
327 | 0 | if (sym != NULL && sym->n_scnum != 0) |
328 | 0 | * addendp -= sym->n_value; |
329 | 0 | } |
330 | 0 | else |
331 | 0 | * addendp = 0; |
332 | |
|
333 | 0 | return howto; |
334 | 0 | } Unexecuted instantiation: pe-mcore.c:coff_mcore_rtype_to_howto Unexecuted instantiation: pei-mcore.c:coff_mcore_rtype_to_howto |
335 | | |
336 | | /* Return TRUE if this relocation should appear in the output .reloc section. |
337 | | This function is referenced in pe_mkobject in peicode.h. */ |
338 | | |
339 | | static bool |
340 | | in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, reloc_howto_type * howto) |
341 | 0 | { |
342 | 0 | return ! howto->pc_relative && howto->type != IMAGE_REL_MCORE_RVA; |
343 | 0 | } Unexecuted instantiation: pe-mcore.c:in_reloc_p Unexecuted instantiation: pei-mcore.c:in_reloc_p |
344 | | |
345 | | /* The reloc processing routine for the optimized COFF linker. */ |
346 | | static bool |
347 | | coff_mcore_relocate_section (bfd * output_bfd, |
348 | | struct bfd_link_info * info, |
349 | | bfd * input_bfd, |
350 | | asection * input_section, |
351 | | bfd_byte * contents, |
352 | | struct internal_reloc * relocs, |
353 | | struct internal_syment * syms, |
354 | | asection ** sections) |
355 | 0 | { |
356 | 0 | struct internal_reloc * rel; |
357 | 0 | struct internal_reloc * relend; |
358 | | |
359 | | /* If we are performing a relocatable link, we don't need to do a |
360 | | thing. The caller will take care of adjusting the reloc |
361 | | addresses and symbol indices. */ |
362 | 0 | if (bfd_link_relocatable (info)) |
363 | 0 | return true; |
364 | | |
365 | | /* Check if we have the same endianness */ |
366 | 0 | if ( input_bfd->xvec->byteorder != output_bfd->xvec->byteorder |
367 | 0 | && output_bfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
368 | 0 | { |
369 | 0 | _bfd_error_handler |
370 | | /* xgettext: c-format */ |
371 | 0 | (_("%pB: compiled for a %s system and target is %s.\n"), |
372 | 0 | input_bfd, |
373 | 0 | bfd_big_endian (input_bfd) ? _("big endian") : _("little endian"), |
374 | 0 | bfd_big_endian (output_bfd) ? _("big endian") : _("little endian")); |
375 | |
|
376 | 0 | bfd_set_error (bfd_error_wrong_format); |
377 | 0 | return false; |
378 | 0 | } |
379 | | |
380 | 0 | rel = relocs; |
381 | 0 | relend = rel + input_section->reloc_count; |
382 | |
|
383 | 0 | for (; rel < relend; rel++) |
384 | 0 | { |
385 | 0 | long symndx; |
386 | 0 | struct internal_syment * sym; |
387 | 0 | bfd_vma val; |
388 | 0 | bfd_vma addend; |
389 | 0 | bfd_reloc_status_type rstat; |
390 | 0 | bfd_byte * loc; |
391 | 0 | unsigned short r_type = rel->r_type; |
392 | 0 | reloc_howto_type * howto = NULL; |
393 | 0 | struct coff_link_hash_entry * h; |
394 | 0 | const char * my_name; |
395 | 0 | char buf[SYMNMLEN + 1]; |
396 | |
|
397 | 0 | symndx = rel->r_symndx; |
398 | 0 | loc = contents + rel->r_vaddr - input_section->vma; |
399 | |
|
400 | 0 | if (symndx == -1) |
401 | 0 | { |
402 | 0 | h = NULL; |
403 | 0 | sym = NULL; |
404 | 0 | } |
405 | 0 | else |
406 | 0 | { |
407 | 0 | h = obj_coff_sym_hashes (input_bfd)[symndx]; |
408 | 0 | sym = syms + symndx; |
409 | 0 | } |
410 | |
|
411 | 0 | addend = 0; |
412 | | |
413 | | /* Get the howto and initialise the addend. */ |
414 | 0 | howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, |
415 | 0 | sym, & addend); |
416 | 0 | if (howto == NULL) |
417 | 0 | return false; |
418 | | |
419 | 0 | val = 0; |
420 | |
|
421 | 0 | if (h == NULL) |
422 | 0 | { |
423 | 0 | if (symndx == -1) |
424 | 0 | my_name = "*ABS*"; |
425 | 0 | else |
426 | 0 | { |
427 | 0 | asection * sec = sections[symndx]; |
428 | |
|
429 | 0 | val = (sym->n_value |
430 | 0 | + sec->output_section->vma |
431 | 0 | + sec->output_offset); |
432 | |
|
433 | 0 | if (sym == NULL) |
434 | 0 | my_name = "*unknown*"; |
435 | 0 | else if ( sym->_n._n_n._n_zeroes == 0 |
436 | 0 | && sym->_n._n_n._n_offset != 0) |
437 | 0 | { |
438 | 0 | if (sym->_n._n_n._n_offset < obj_coff_strings_len (input_bfd)) |
439 | 0 | my_name = (obj_coff_strings (input_bfd) |
440 | 0 | + sym->_n._n_n._n_offset); |
441 | 0 | else |
442 | 0 | my_name = "?"; |
443 | 0 | } |
444 | 0 | else |
445 | 0 | { |
446 | 0 | strncpy (buf, sym->_n._n_name, SYMNMLEN); |
447 | 0 | buf[SYMNMLEN] = '\0'; |
448 | 0 | my_name = buf; |
449 | 0 | } |
450 | 0 | } |
451 | 0 | } |
452 | 0 | else |
453 | 0 | { |
454 | 0 | if ( h->root.type == bfd_link_hash_defined |
455 | 0 | || h->root.type == bfd_link_hash_defweak) |
456 | 0 | { |
457 | 0 | asection * sec = h->root.u.def.section; |
458 | |
|
459 | 0 | val = (h->root.u.def.value |
460 | 0 | + sec->output_section->vma |
461 | 0 | + sec->output_offset); |
462 | 0 | } |
463 | 0 | else |
464 | 0 | (*info->callbacks->undefined_symbol) |
465 | 0 | (info, h->root.root.string, input_bfd, input_section, |
466 | 0 | rel->r_vaddr - input_section->vma, true); |
467 | |
|
468 | 0 | my_name = h->root.root.string; |
469 | 0 | } |
470 | |
|
471 | 0 | rstat = bfd_reloc_ok; |
472 | | |
473 | | /* Each case must do its own relocation, setting rstat appropriately. */ |
474 | 0 | switch (r_type) |
475 | 0 | { |
476 | 0 | default: |
477 | | /* xgettext: c-format */ |
478 | 0 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
479 | 0 | input_bfd, r_type); |
480 | 0 | bfd_set_error (bfd_error_bad_value); |
481 | 0 | return false; |
482 | | |
483 | 0 | case IMAGE_REL_MCORE_ABSOLUTE: |
484 | 0 | _bfd_error_handler |
485 | | /* xgettext: c-format */ |
486 | 0 | (_("warning: unsupported reloc %s <file %pB, section %pA>\n" |
487 | 0 | "sym %ld (%s), r_vaddr %" PRId64 " (%#" PRIx64 ")"), |
488 | 0 | howto->name, input_bfd, input_section, |
489 | 0 | rel->r_symndx, my_name, (int64_t) rel->r_vaddr, |
490 | 0 | (uint64_t) rel->r_vaddr); |
491 | 0 | break; |
492 | | |
493 | 0 | case IMAGE_REL_MCORE_PCREL_IMM8BY4: |
494 | 0 | case IMAGE_REL_MCORE_PCREL_IMM11BY2: |
495 | 0 | case IMAGE_REL_MCORE_PCREL_IMM4BY2: |
496 | 0 | case IMAGE_REL_MCORE_PCREL_32: |
497 | 0 | case IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2: |
498 | 0 | case IMAGE_REL_MCORE_ADDR32: |
499 | | /* XXX fixme - shouldn't this be like the code for the RVA reloc ? */ |
500 | 0 | rstat = _bfd_relocate_contents (howto, input_bfd, val, loc); |
501 | 0 | break; |
502 | | |
503 | 0 | case IMAGE_REL_MCORE_RVA: |
504 | 0 | rstat = _bfd_final_link_relocate |
505 | 0 | (howto, input_bfd, |
506 | 0 | input_section, contents, rel->r_vaddr - input_section->vma, |
507 | 0 | val, addend); |
508 | 0 | break; |
509 | 0 | } |
510 | | |
511 | | /* Emit a reloc if the backend thinks it needs it. */ |
512 | 0 | if (info->base_file |
513 | 0 | && sym |
514 | 0 | && pe_data (output_bfd)->in_reloc_p (output_bfd, howto) |
515 | 0 | && !mcore_emit_base_file_entry (info, output_bfd, input_section, |
516 | 0 | rel->r_vaddr)) |
517 | 0 | return false; |
518 | | |
519 | 0 | switch (rstat) |
520 | 0 | { |
521 | 0 | default: |
522 | 0 | abort (); |
523 | | |
524 | 0 | case bfd_reloc_ok: |
525 | 0 | break; |
526 | | |
527 | 0 | case bfd_reloc_overflow: |
528 | 0 | (*info->callbacks->reloc_overflow) |
529 | 0 | (info, (h ? &h->root : NULL), my_name, howto->name, |
530 | 0 | (bfd_vma) 0, input_bfd, |
531 | 0 | input_section, rel->r_vaddr - input_section->vma); |
532 | 0 | } |
533 | 0 | } |
534 | | |
535 | 0 | return true; |
536 | 0 | } Unexecuted instantiation: pe-mcore.c:coff_mcore_relocate_section Unexecuted instantiation: pei-mcore.c:coff_mcore_relocate_section |
537 | | |
538 | | /* Tailor coffcode.h -- macro heaven. */ |
539 | | |
540 | | /* We use the special COFF backend linker, with our own special touch. */ |
541 | | |
542 | | #define coff_bfd_reloc_type_lookup mcore_coff_reloc_type_lookup |
543 | | #define coff_bfd_reloc_name_lookup mcore_coff_reloc_name_lookup |
544 | | #define coff_relocate_section coff_mcore_relocate_section |
545 | | #define coff_rtype_to_howto coff_mcore_rtype_to_howto |
546 | | |
547 | 0 | #define SELECT_RELOC(internal, howto) {internal.r_type = howto->type;} |
548 | | |
549 | | /* Make sure that the 'r_offset' field is copied properly |
550 | | so that identical binaries will compare the same. */ |
551 | 32.2k | #define SWAP_IN_RELOC_OFFSET H_GET_32 |
552 | 0 | #define SWAP_OUT_RELOC_OFFSET H_PUT_32 |
553 | | |
554 | 0 | #define COFF_PAGE_SIZE 0x1000 |
555 | | |
556 | | #include "coffcode.h" |
557 | | |
558 | | /* Forward declaration to initialise alternative_target field. */ |
559 | | extern const bfd_target TARGET_LITTLE_SYM; |
560 | | |
561 | | /* The transfer vectors that lead the outside world to all of the above. */ |
562 | | CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, |
563 | | (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), |
564 | | 0, & TARGET_LITTLE_SYM, COFF_SWAP_TABLE) |
565 | | CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, |
566 | | (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), |
567 | | 0, & TARGET_BIG_SYM, COFF_SWAP_TABLE) |