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