Commit | Line | Data |
---|---|---|
3442f309 | 1 | /* BFD back-end for Motorola MCore COFF/PE |
219d1afa | 2 | Copyright (C) 1999-2018 Free Software Foundation, Inc. |
252b5132 | 3 | |
cd123cb7 NC |
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. */ | |
252b5132 | 20 | |
252b5132 | 21 | #include "sysdep.h" |
3db64b00 | 22 | #include "bfd.h" |
252b5132 RH |
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 | #define BADMAG(x) MCOREBADMAG(x) | |
33 | ||
34 | #ifndef NUM_ELEM | |
35 | #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. */ | |
b34976b6 | 40 | extern bfd_boolean mcore_bfd_coff_final_link |
2c3fc389 | 41 | (bfd *, struct bfd_link_info *); |
b34976b6 | 42 | static bfd_reloc_status_type mcore_coff_unsupported_reloc |
2c3fc389 NC |
43 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
44 | ||
252b5132 RH |
45 | \f |
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. */ | |
f45fbf87 | 53 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 |
252b5132 RH |
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) | |
252b5132 RH |
58 | \f |
59 | static reloc_howto_type mcore_coff_howto_table[] = | |
60 | { | |
61 | /* Unused: */ | |
b48499ec | 62 | HOWTO (IMAGE_REL_MCORE_ABSOLUTE,/* type */ |
07d6d2b8 AM |
63 | 0, /* rightshift */ |
64 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
65 | 0, /* bitsize */ | |
66 | FALSE, /* pc_relative */ | |
67 | 0, /* bitpos */ | |
252b5132 | 68 | complain_overflow_dont, /* dont complain_on_overflow */ |
07d6d2b8 AM |
69 | NULL, /* special_function */ |
70 | "ABSOLUTE", /* name */ | |
71 | FALSE, /* partial_inplace */ | |
72 | 0x00, /* src_mask */ | |
73 | 0x00, /* dst_mask */ | |
74 | FALSE), /* pcrel_offset */ | |
b48499ec | 75 | |
252b5132 | 76 | HOWTO (IMAGE_REL_MCORE_ADDR32,/* type */ |
07d6d2b8 AM |
77 | 0, /* rightshift */ |
78 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
79 | 32, /* bitsize */ | |
80 | FALSE, /* pc_relative */ | |
81 | 0, /* bitpos */ | |
252b5132 | 82 | complain_overflow_bitfield, /* complain_on_overflow */ |
07d6d2b8 AM |
83 | NULL, /* special_function */ |
84 | "ADDR32", /* name */ | |
85 | TRUE, /* partial_inplace */ | |
86 | 0xffffffff, /* src_mask */ | |
87 | 0xffffffff, /* dst_mask */ | |
88 | FALSE), /* pcrel_offset */ | |
b48499ec | 89 | |
252b5132 | 90 | /* 8 bits + 2 zero bits; jmpi/jsri/lrw instructions. |
b48499ec | 91 | Should not appear in object files. */ |
252b5132 RH |
92 | HOWTO (IMAGE_REL_MCORE_PCREL_IMM8BY4, /* type */ |
93 | 2, /* rightshift */ | |
94 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
95 | 8, /* bitsize */ | |
b34976b6 | 96 | TRUE, /* pc_relative */ |
252b5132 RH |
97 | 0, /* bitpos */ |
98 | complain_overflow_bitfield, /* complain_on_overflow */ | |
36797d47 | 99 | mcore_coff_unsupported_reloc, /* special_function */ |
07d6d2b8 | 100 | "IMM8BY4", /* name */ |
b34976b6 | 101 | FALSE, /* partial_inplace */ |
252b5132 RH |
102 | 0, /* src_mask */ |
103 | 0, /* dst_mask */ | |
b34976b6 | 104 | TRUE), /* pcrel_offset */ |
252b5132 | 105 | |
b48499ec | 106 | /* bsr/bt/bf/br instructions; 11 bits + 1 zero bit |
252b5132 RH |
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 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
112 | 11, /* bitsize */ | |
b34976b6 | 113 | TRUE, /* pc_relative */ |
252b5132 RH |
114 | 0, /* bitpos */ |
115 | complain_overflow_signed, /* complain_on_overflow */ | |
07d6d2b8 AM |
116 | NULL, /* special_function */ |
117 | "IMM11BY2", /* name */ | |
b34976b6 | 118 | FALSE, /* partial_inplace */ |
252b5132 RH |
119 | 0x0, /* src_mask */ |
120 | 0x7ff, /* dst_mask */ | |
b34976b6 | 121 | TRUE), /* pcrel_offset */ |
252b5132 | 122 | |
b48499ec | 123 | /* 4 bits + 1 zero bit; 'loopt' instruction only; unsupported. */ |
252b5132 RH |
124 | HOWTO (IMAGE_REL_MCORE_PCREL_IMM4BY2, /* type */ |
125 | 1, /* rightshift */ | |
126 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
127 | 4, /* bitsize */ | |
b34976b6 | 128 | TRUE, /* pc_relative */ |
252b5132 RH |
129 | 0, /* bitpos */ |
130 | complain_overflow_bitfield, /* complain_on_overflow */ | |
36797d47 | 131 | mcore_coff_unsupported_reloc, /* special_function */ |
07d6d2b8 | 132 | "IMM4BY2", /* name */ |
b34976b6 | 133 | FALSE, /* partial_inplace */ |
252b5132 RH |
134 | 0, /* src_mask */ |
135 | 0, /* dst_mask */ | |
b34976b6 | 136 | TRUE), /* pcrel_offset */ |
252b5132 | 137 | |
b48499ec | 138 | /* 32-bit pc-relative. Eventually this will help support PIC code. */ |
252b5132 RH |
139 | HOWTO (IMAGE_REL_MCORE_PCREL_32,/* type */ |
140 | 0, /* rightshift */ | |
141 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
142 | 32, /* bitsize */ | |
b34976b6 | 143 | TRUE, /* pc_relative */ |
252b5132 RH |
144 | 0, /* bitpos */ |
145 | complain_overflow_bitfield, /* complain_on_overflow */ | |
07d6d2b8 AM |
146 | NULL, /* special_function */ |
147 | "PCREL_32", /* name */ | |
b34976b6 | 148 | FALSE, /* partial_inplace */ |
252b5132 RH |
149 | 0x0, /* src_mask */ |
150 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 151 | TRUE), /* pcrel_offset */ |
252b5132 RH |
152 | |
153 | /* Like PCREL_IMM11BY2, this relocation indicates that there is a | |
154 | 'jsri' at the specified address. There is a separate relocation | |
b48499ec | 155 | entry for the literal pool entry that it references, but we |
252b5132 RH |
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 | |
b48499ec | 159 | is a relocation that we are allowed to safely ignore. */ |
252b5132 RH |
160 | HOWTO (IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2,/* type */ |
161 | 1, /* rightshift */ | |
162 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
163 | 11, /* bitsize */ | |
b34976b6 | 164 | TRUE, /* pc_relative */ |
252b5132 RH |
165 | 0, /* bitpos */ |
166 | complain_overflow_signed, /* complain_on_overflow */ | |
07d6d2b8 AM |
167 | NULL, /* special_function */ |
168 | "JSR_IMM11BY2", /* name */ | |
b34976b6 | 169 | FALSE, /* partial_inplace */ |
252b5132 RH |
170 | 0x0, /* src_mask */ |
171 | 0x7ff, /* dst_mask */ | |
b34976b6 | 172 | TRUE), /* pcrel_offset */ |
b48499ec | 173 | |
07d6d2b8 | 174 | HOWTO (IMAGE_REL_MCORE_RVA, /* type */ |
36797d47 NC |
175 | 0, /* rightshift */ |
176 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
177 | 32, /* bitsize */ | |
b34976b6 | 178 | FALSE, /* pc_relative */ |
36797d47 NC |
179 | 0, /* bitpos */ |
180 | complain_overflow_signed, /* complain_on_overflow */ | |
07d6d2b8 AM |
181 | NULL, /* special_function */ |
182 | "MCORE_RVA", /* name */ | |
b34976b6 | 183 | TRUE, /* partial_inplace */ |
36797d47 NC |
184 | 0xffffffff, /* src_mask */ |
185 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 186 | TRUE) /* pcrel_offset */ |
252b5132 RH |
187 | }; |
188 | \f | |
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 | ||
07d6d2b8 AM |
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; | |
252b5132 RH |
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 | ||
252b5132 | 209 | \f |
69e70d30 | 210 | /* Add an entry to the base file. */ |
42ef282f | 211 | |
b1657152 AM |
212 | static bfd_boolean |
213 | mcore_emit_base_file_entry (struct bfd_link_info *info, | |
214 | bfd *output_bfd, | |
215 | asection *input_section, | |
216 | bfd_vma reloc_offset) | |
69e70d30 NC |
217 | { |
218 | bfd_vma addr = reloc_offset | |
07d6d2b8 AM |
219 | - input_section->vma |
220 | + input_section->output_offset | |
221 | + input_section->output_section->vma; | |
69e70d30 NC |
222 | |
223 | if (coff_data (output_bfd)->pe) | |
224 | addr -= pe_data (output_bfd)->pe_opthdr.ImageBase; | |
b48499ec | 225 | |
b1657152 AM |
226 | if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1) |
227 | return TRUE; | |
228 | ||
229 | bfd_set_error (bfd_error_system_call); | |
230 | return FALSE; | |
69e70d30 NC |
231 | } |
232 | \f | |
252b5132 | 233 | static bfd_reloc_status_type |
2c3fc389 NC |
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) | |
252b5132 RH |
241 | { |
242 | BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0); | |
b48499ec | 243 | |
695344c0 | 244 | /* xgettext: c-format */ |
871b3ab2 | 245 | _bfd_error_handler (_("%pB: Relocation %s (%d) is not currently supported.\n"), |
d003868e | 246 | abfd, |
252b5132 RH |
247 | reloc_entry->howto->name, |
248 | reloc_entry->howto->type); | |
b48499ec | 249 | |
252b5132 RH |
250 | return bfd_reloc_notsupported; |
251 | } | |
252b5132 | 252 | \f |
b48499ec | 253 | /* A cheesy little macro to make the code a little more readable. */ |
252b5132 RH |
254 | #define HOW2MAP(bfd_rtype, mcore_rtype) \ |
255 | case bfd_rtype: return & mcore_coff_howto_table [mcore_rtype] | |
256 | ||
257 | static reloc_howto_type * | |
2c3fc389 NC |
258 | mcore_coff_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
259 | bfd_reloc_code_real_type code) | |
252b5132 RH |
260 | { |
261 | switch (code) | |
b48499ec | 262 | { |
07d6d2b8 AM |
263 | HOW2MAP (BFD_RELOC_32, IMAGE_REL_MCORE_ADDR32); |
264 | HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM8BY4, IMAGE_REL_MCORE_PCREL_IMM8BY4); | |
265 | HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM11BY2, IMAGE_REL_MCORE_PCREL_IMM11BY2); | |
266 | HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM4BY2, IMAGE_REL_MCORE_PCREL_IMM4BY2); | |
267 | HOW2MAP (BFD_RELOC_32_PCREL, IMAGE_REL_MCORE_PCREL_32); | |
252b5132 | 268 | HOW2MAP (BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2, IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2); |
07d6d2b8 | 269 | HOW2MAP (BFD_RELOC_RVA, IMAGE_REL_MCORE_RVA); |
b48499ec | 270 | default: |
252b5132 RH |
271 | return NULL; |
272 | } | |
273 | /*NOTREACHED*/ | |
274 | } | |
252b5132 RH |
275 | #undef HOW2MAP |
276 | ||
a1165289 NC |
277 | #define NUM_HOWTOS NUM_ELEM (mcore_coff_howto_table) |
278 | ||
157090f7 AM |
279 | static reloc_howto_type * |
280 | mcore_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
281 | const char *r_name) | |
282 | { | |
283 | unsigned int i; | |
284 | ||
a1165289 | 285 | for (i = 0; i < NUM_HOWTOS; i++) |
157090f7 AM |
286 | if (mcore_coff_howto_table[i].name != NULL |
287 | && strcasecmp (mcore_coff_howto_table[i].name, r_name) == 0) | |
288 | return &mcore_coff_howto_table[i]; | |
289 | ||
290 | return NULL; | |
291 | } | |
292 | ||
a1165289 NC |
293 | #define RTYPE2HOWTO(cache_ptr, dst) \ |
294 | ((cache_ptr)->howto = \ | |
295 | ((dst)->r_type < NUM_HOWTOS \ | |
296 | ? mcore_coff_howto_table + (dst)->r_type \ | |
297 | : NULL)) | |
252b5132 RH |
298 | |
299 | static reloc_howto_type * | |
2c3fc389 NC |
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) | |
252b5132 RH |
306 | { |
307 | reloc_howto_type * howto; | |
308 | ||
a1165289 | 309 | if (rel->r_type >= NUM_HOWTOS) |
252b5132 | 310 | return NULL; |
b48499ec | 311 | |
252b5132 | 312 | howto = mcore_coff_howto_table + rel->r_type; |
36797d47 NC |
313 | |
314 | if (rel->r_type == IMAGE_REL_MCORE_RVA) | |
315 | * addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase; | |
b48499ec | 316 | |
078c8694 | 317 | else if (howto->pc_relative) |
252b5132 RH |
318 | { |
319 | * addendp = sec->vma - 2; /* XXX guess - is this right ? */ | |
b48499ec | 320 | |
252b5132 | 321 | /* If the symbol is defined, then the generic code is going to |
07d6d2b8 AM |
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. */ | |
252b5132 RH |
327 | if (sym != NULL && sym->n_scnum != 0) |
328 | * addendp -= sym->n_value; | |
329 | } | |
330 | else | |
331 | * addendp = 0; | |
b48499ec | 332 | |
252b5132 RH |
333 | return howto; |
334 | } | |
1349dd65 | 335 | |
b34976b6 | 336 | /* Return TRUE if this relocation should appear in the output .reloc section. |
1349dd65 | 337 | This function is referenced in pe_mkobject in peicode.h. */ |
42ef282f | 338 | |
b34976b6 | 339 | static bfd_boolean |
2c3fc389 | 340 | in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, reloc_howto_type * howto) |
1349dd65 NC |
341 | { |
342 | return ! howto->pc_relative && howto->type != IMAGE_REL_MCORE_RVA; | |
b48499ec | 343 | } |
252b5132 | 344 | \f |
252b5132 | 345 | /* The reloc processing routine for the optimized COFF linker. */ |
b34976b6 | 346 | static bfd_boolean |
2c3fc389 NC |
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) | |
252b5132 RH |
355 | { |
356 | struct internal_reloc * rel; | |
357 | struct internal_reloc * relend; | |
b48499ec | 358 | |
1049f94e | 359 | /* If we are performing a relocatable link, we don't need to do a |
252b5132 RH |
360 | thing. The caller will take care of adjusting the reloc |
361 | addresses and symbol indices. */ | |
0e1862bb | 362 | if (bfd_link_relocatable (info)) |
b34976b6 | 363 | return TRUE; |
b48499ec | 364 | |
cc643b88 | 365 | /* Check if we have the same endianness */ |
b23f908b NC |
366 | if ( input_bfd->xvec->byteorder != output_bfd->xvec->byteorder |
367 | && output_bfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) | |
368 | { | |
4eca0228 | 369 | _bfd_error_handler |
695344c0 | 370 | /* xgettext: c-format */ |
871b3ab2 | 371 | (_("%pB: compiled for a %s system and target is %s.\n"), |
d003868e | 372 | input_bfd, |
07d6d2b8 AM |
373 | bfd_big_endian (input_bfd) ? _("big endian") : _("little endian"), |
374 | bfd_big_endian (output_bfd) ? _("big endian") : _("little endian")); | |
b23f908b NC |
375 | |
376 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 377 | return FALSE; |
b23f908b | 378 | } |
252b5132 | 379 | |
252b5132 RH |
380 | rel = relocs; |
381 | relend = rel + input_section->reloc_count; | |
b48499ec | 382 | |
252b5132 RH |
383 | for (; rel < relend; rel++) |
384 | { | |
07d6d2b8 AM |
385 | long symndx; |
386 | struct internal_syment * sym; | |
387 | bfd_vma val; | |
388 | bfd_vma addend; | |
389 | bfd_reloc_status_type rstat; | |
390 | bfd_byte * loc; | |
391 | unsigned short r_type = rel->r_type; | |
392 | reloc_howto_type * howto = NULL; | |
252b5132 | 393 | struct coff_link_hash_entry * h; |
07d6d2b8 | 394 | const char * my_name; |
b48499ec | 395 | |
252b5132 RH |
396 | symndx = rel->r_symndx; |
397 | loc = contents + rel->r_vaddr - input_section->vma; | |
398 | ||
399 | if (symndx == -1) | |
400 | { | |
401 | h = NULL; | |
402 | sym = NULL; | |
403 | } | |
404 | else | |
405 | { | |
406 | h = obj_coff_sym_hashes (input_bfd)[symndx]; | |
407 | sym = syms + symndx; | |
408 | } | |
409 | ||
078c8694 | 410 | addend = 0; |
b48499ec | 411 | |
252b5132 RH |
412 | /* Get the howto and initialise the addend. */ |
413 | howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, | |
414 | sym, & addend); | |
415 | if (howto == NULL) | |
b34976b6 | 416 | return FALSE; |
252b5132 RH |
417 | |
418 | val = 0; | |
b48499ec | 419 | |
252b5132 RH |
420 | if (h == NULL) |
421 | { | |
422 | if (symndx == -1) | |
423 | my_name = "*ABS*"; | |
424 | else | |
425 | { | |
426 | asection * sec = sections[symndx]; | |
b48499ec KH |
427 | |
428 | val = (sym->n_value | |
252b5132 RH |
429 | + sec->output_section->vma |
430 | + sec->output_offset); | |
431 | ||
432 | if (sym == NULL) | |
433 | my_name = "*unknown*"; | |
434 | else if ( sym->_n._n_n._n_zeroes == 0 | |
435 | && sym->_n._n_n._n_offset != 0) | |
436 | my_name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; | |
b48499ec | 437 | else |
252b5132 RH |
438 | { |
439 | static char buf [SYMNMLEN + 1]; | |
b48499ec | 440 | |
252b5132 RH |
441 | strncpy (buf, sym->_n._n_name, SYMNMLEN); |
442 | buf[SYMNMLEN] = '\0'; | |
443 | my_name = buf; | |
444 | } | |
445 | } | |
446 | } | |
447 | else | |
448 | { | |
449 | if ( h->root.type == bfd_link_hash_defined | |
450 | || h->root.type == bfd_link_hash_defweak) | |
451 | { | |
452 | asection * sec = h->root.u.def.section; | |
b48499ec | 453 | |
252b5132 RH |
454 | val = (h->root.u.def.value |
455 | + sec->output_section->vma | |
456 | + sec->output_offset); | |
457 | } | |
458 | else | |
1a72702b AM |
459 | (*info->callbacks->undefined_symbol) |
460 | (info, h->root.root.string, input_bfd, input_section, | |
461 | rel->r_vaddr - input_section->vma, TRUE); | |
b48499ec | 462 | |
252b5132 | 463 | my_name = h->root.root.string; |
b48499ec | 464 | } |
252b5132 RH |
465 | |
466 | rstat = bfd_reloc_ok; | |
b48499ec | 467 | |
252b5132 RH |
468 | /* Each case must do its own relocation, setting rstat appropriately. */ |
469 | switch (r_type) | |
470 | { | |
471 | default: | |
695344c0 | 472 | /* xgettext: c-format */ |
0aa13fee | 473 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
d003868e | 474 | input_bfd, r_type); |
252b5132 | 475 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 476 | return FALSE; |
b48499ec | 477 | |
252b5132 | 478 | case IMAGE_REL_MCORE_ABSOLUTE: |
d003868e | 479 | _bfd_error_handler |
695344c0 | 480 | /* xgettext: c-format */ |
59d08d6c | 481 | (_("warning: unsupported reloc %s <file %pB, section %pA>\n" |
2dcf00ce | 482 | "sym %ld (%s), r_vaddr %" PRId64 " (%#" PRIx64 ")"), |
c08bb8dd | 483 | howto->name, input_bfd, input_section, |
2dcf00ce AM |
484 | rel->r_symndx, my_name, (int64_t) rel->r_vaddr, |
485 | (uint64_t) rel->r_vaddr); | |
252b5132 | 486 | break; |
b48499ec | 487 | |
252b5132 RH |
488 | case IMAGE_REL_MCORE_PCREL_IMM8BY4: |
489 | case IMAGE_REL_MCORE_PCREL_IMM11BY2: | |
490 | case IMAGE_REL_MCORE_PCREL_IMM4BY2: | |
491 | case IMAGE_REL_MCORE_PCREL_32: | |
492 | case IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2: | |
493 | case IMAGE_REL_MCORE_ADDR32: | |
078c8694 | 494 | /* XXX fixme - shouldn't this be like the code for the RVA reloc ? */ |
252b5132 RH |
495 | rstat = _bfd_relocate_contents (howto, input_bfd, val, loc); |
496 | break; | |
b48499ec | 497 | |
078c8694 NC |
498 | case IMAGE_REL_MCORE_RVA: |
499 | rstat = _bfd_final_link_relocate | |
500 | (howto, input_bfd, | |
501 | input_section, contents, rel->r_vaddr - input_section->vma, | |
502 | val, addend); | |
503 | break; | |
252b5132 | 504 | } |
b48499ec | 505 | |
b1657152 AM |
506 | /* Emit a reloc if the backend thinks it needs it. */ |
507 | if (info->base_file | |
508 | && sym | |
509 | && pe_data (output_bfd)->in_reloc_p (output_bfd, howto) | |
510 | && !mcore_emit_base_file_entry (info, output_bfd, input_section, | |
511 | rel->r_vaddr)) | |
512 | return FALSE; | |
b48499ec | 513 | |
252b5132 RH |
514 | switch (rstat) |
515 | { | |
516 | default: | |
517 | abort (); | |
b48499ec | 518 | |
252b5132 RH |
519 | case bfd_reloc_ok: |
520 | break; | |
b48499ec | 521 | |
252b5132 | 522 | case bfd_reloc_overflow: |
1a72702b AM |
523 | (*info->callbacks->reloc_overflow) |
524 | (info, (h ? &h->root : NULL), my_name, howto->name, | |
525 | (bfd_vma) 0, input_bfd, | |
526 | input_section, rel->r_vaddr - input_section->vma); | |
252b5132 | 527 | } |
b48499ec | 528 | } |
252b5132 | 529 | |
b34976b6 | 530 | return TRUE; |
252b5132 | 531 | } |
252b5132 | 532 | \f |
b48499ec | 533 | /* Tailor coffcode.h -- macro heaven. */ |
252b5132 RH |
534 | |
535 | /* We use the special COFF backend linker, with our own special touch. */ | |
536 | ||
537 | #define coff_bfd_reloc_type_lookup mcore_coff_reloc_type_lookup | |
157090f7 | 538 | #define coff_bfd_reloc_name_lookup mcore_coff_reloc_name_lookup |
07d6d2b8 AM |
539 | #define coff_relocate_section coff_mcore_relocate_section |
540 | #define coff_rtype_to_howto coff_mcore_rtype_to_howto | |
252b5132 RH |
541 | |
542 | #define SELECT_RELOC(internal, howto) {internal.r_type = howto->type;} | |
543 | ||
dc12c51f AM |
544 | /* Make sure that the 'r_offset' field is copied properly |
545 | so that identical binaries will compare the same. */ | |
07d6d2b8 AM |
546 | #define SWAP_IN_RELOC_OFFSET H_GET_32 |
547 | #define SWAP_OUT_RELOC_OFFSET H_PUT_32 | |
dc12c51f | 548 | |
07d6d2b8 | 549 | #define COFF_PAGE_SIZE 0x1000 |
252b5132 RH |
550 | |
551 | #include "coffcode.h" | |
552 | \f | |
5c4491d3 | 553 | /* Forward declaration to initialise alternative_target field. */ |
c3c89269 | 554 | extern const bfd_target TARGET_LITTLE_SYM; |
252b5132 | 555 | |
b48499ec | 556 | /* The transfer vectors that lead the outside world to all of the above. */ |
60bcf0fa NC |
557 | CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, |
558 | (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), | |
3fa78519 | 559 | 0, & TARGET_LITTLE_SYM, COFF_SWAP_TABLE) |
60bcf0fa NC |
560 | CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, |
561 | (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), | |
3fa78519 | 562 | 0, & TARGET_BIG_SYM, COFF_SWAP_TABLE) |