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