Add code to emit relocs into a base file.
[platform/upstream/binutils.git] / bfd / coff-mcore.c
1 /* BFD back-end for Motorolla MCore COFF/PE
2    Copyright (C) 1999 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 2 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, 59 Temple Place - Suite 330,
19 Boston, 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.  */
40 extern boolean mcore_bfd_coff_final_link
41   PARAMS ((bfd *, struct bfd_link_info *));
42
43 static struct bfd_link_hash_table * coff_mcore_link_hash_table_create
44   PARAMS ((bfd *));
45 static bfd_reloc_status_type        mcore_coff_unsupported_reloc 
46   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
47 static boolean                      coff_mcore_relocate_section
48   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
49            struct internal_reloc *, struct internal_syment *, asection **));
50 static reloc_howto_type *           mcore_coff_reloc_type_lookup
51   PARAMS ((bfd *, bfd_reloc_code_real_type));
52 static reloc_howto_type *           coff_mcore_rtype_to_howto
53   PARAMS ((bfd *, asection *, struct internal_reloc *,
54            struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *));
55 static const bfd_target *           pe_object_p
56   PARAMS ((bfd *));
57
58
59 \f
60 /* The NT loader points the toc register to &toc + 32768, in order to
61    use the complete range of a 16-bit displacement. We have to adjust
62    for this when we fix up loads displaced off the toc reg.  */
63 #define TOC_LOAD_ADJUSTMENT (-32768)
64 #define TOC_SECTION_NAME ".private.toc"
65
66 /* The main body of code is in coffcode.h.  */
67 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
68
69 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
70    from smaller values.  Start with zero, widen, *then* decrement.  */
71 #define MINUS_ONE       (((bfd_vma)0) - 1)
72
73 \f
74 static reloc_howto_type mcore_coff_howto_table[] =
75 {
76   /* Unused: */
77   HOWTO (IMAGE_REL_MCORE_ABSOLUTE,/* type */                                 
78          0,                      /* rightshift */                           
79          0,                      /* size (0 = byte, 1 = short, 2 = long) */ 
80          0,                      /* bitsize */                   
81          false,                  /* pc_relative */                          
82          0,                      /* bitpos */                               
83          complain_overflow_dont, /* dont complain_on_overflow */
84          NULL,                   /* special_function */                     
85          "ABSOLUTE",             /* name */
86          false,                  /* partial_inplace */                      
87          0x00,                   /* src_mask */                             
88          0x00,                   /* dst_mask */                             
89          false),                 /* pcrel_offset */
90   
91   HOWTO (IMAGE_REL_MCORE_ADDR32,/* type */
92          0,                     /* rightshift */                           
93          2,                     /* size (0 = byte, 1 = short, 2 = long) */ 
94          32,                    /* bitsize */                   
95          false,                 /* pc_relative */                          
96          0,                     /* bitpos */                               
97          complain_overflow_bitfield, /* complain_on_overflow */
98          NULL,                  /* special_function */                     
99          "ADDR32",              /* name */
100          true,                  /* partial_inplace */                      
101          0xffffffff,            /* src_mask */                             
102          0xffffffff,            /* dst_mask */                             
103          false),                /* pcrel_offset */
104   
105   /* 8 bits + 2 zero bits; jmpi/jsri/lrw instructions.
106      Should not appear in object files. */
107   HOWTO (IMAGE_REL_MCORE_PCREL_IMM8BY4, /* type */
108          2,                     /* rightshift */
109          1,                     /* size (0 = byte, 1 = short, 2 = long) */
110          8,                     /* bitsize */
111          true,                  /* pc_relative */
112          0,                     /* bitpos */
113          complain_overflow_bitfield, /* complain_on_overflow */
114          mcore_coff_unsupported_reloc, /* special_function */
115          "IMM8BY4",             /* name */
116          false,                 /* partial_inplace */
117          0,                     /* src_mask */
118          0,                     /* dst_mask */
119          true),                 /* pcrel_offset */
120
121   /* bsr/bt/bf/br instructions; 11 bits + 1 zero bit 
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 */
128          true,                  /* pc_relative */
129          0,                     /* bitpos */
130          complain_overflow_signed, /* complain_on_overflow */
131          NULL,                  /* special_function */
132          "IMM11BY2",            /* name */
133          false,                 /* partial_inplace */
134          0x0,                   /* src_mask */
135          0x7ff,                 /* dst_mask */
136          true),                 /* pcrel_offset */
137
138   /* 4 bits + 1 zero bit; 'loopt' instruction only; unsupported. */
139   HOWTO (IMAGE_REL_MCORE_PCREL_IMM4BY2, /* type */
140          1,                     /* rightshift */
141          1,                     /* size (0 = byte, 1 = short, 2 = long) */
142          4,                     /* bitsize */
143          true,                  /* pc_relative */
144          0,                     /* bitpos */
145          complain_overflow_bitfield, /* complain_on_overflow */
146          mcore_coff_unsupported_reloc, /* special_function */
147          "IMM4BY2",              /* name */
148          false,                 /* partial_inplace */
149          0,                     /* src_mask */
150          0,                     /* dst_mask */
151          true),                 /* pcrel_offset */
152
153   /* 32-bit pc-relative. Eventually this will help support PIC code. */
154   HOWTO (IMAGE_REL_MCORE_PCREL_32,/* type */
155          0,                     /* rightshift */
156          2,                     /* size (0 = byte, 1 = short, 2 = long) */
157          32,                    /* bitsize */
158          true,                  /* pc_relative */
159          0,                     /* bitpos */
160          complain_overflow_bitfield, /* complain_on_overflow */
161          NULL,                  /* special_function */
162          "PCREL_32",            /* name */
163          false,                 /* partial_inplace */
164          0x0,                   /* src_mask */
165          0xffffffff,            /* dst_mask */
166          true),                 /* pcrel_offset */
167
168   /* Like PCREL_IMM11BY2, this relocation indicates that there is a
169      'jsri' at the specified address. There is a separate relocation
170      entry for the literal pool entry that it references, but we 
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
174      is a relocation that we are allowed to safely ignore.  */ 
175   HOWTO (IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2,/* type */
176          1,                     /* rightshift */
177          1,                     /* size (0 = byte, 1 = short, 2 = long) */
178          11,                    /* bitsize */
179          true,                  /* pc_relative */
180          0,                     /* bitpos */
181          complain_overflow_signed, /* complain_on_overflow */
182          NULL,                  /* special_function */
183          "JSR_IMM11BY2",        /* name */
184          false,                 /* partial_inplace */
185          0x0,                   /* src_mask */
186          0x7ff,                 /* dst_mask */
187          true),                 /* pcrel_offset */
188   
189   HOWTO (IMAGE_REL_MCORE_RVA,   /* type */
190          0,                     /* rightshift */
191          2,                     /* size (0 = byte, 1 = short, 2 = long) */
192          32,                    /* bitsize */
193          false,                 /* pc_relative */
194          0,                     /* bitpos */
195          complain_overflow_signed, /* complain_on_overflow */
196          NULL,                  /* special_function */
197          "MCORE_RVA",           /* name */
198          true,                  /* partial_inplace */
199          0xffffffff,            /* src_mask */
200          0xffffffff,            /* dst_mask */
201          true)                  /* pcrel_offset */
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.  */
207 typedef 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 }
218 mcore_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
224 /* Create an MCore coff linker hash table.  */
225 static struct bfd_link_hash_table *
226 coff_mcore_link_hash_table_create (abfd)
227      bfd * abfd;
228 {
229   mcore_hash_table * ret;
230
231   ret = ((mcore_hash_table *) bfd_alloc (abfd, sizeof (* ret)));
232   if (ret == (mcore_hash_table *) NULL)
233     return NULL;
234
235   if (! _bfd_coff_link_hash_table_init
236       (& ret->root, abfd, _bfd_coff_link_hash_newfunc))
237     {
238       bfd_release (abfd, ret);
239       return (struct bfd_link_hash_table *) NULL;
240     }
241
242   ret->bfd_of_toc_owner = NULL;
243   ret->global_toc_size  = 0;
244   ret->import_table_size = 0;
245   ret->first_thunk_address = 0;
246   ret->thunk_size = 0;
247
248   return & ret->root.root;
249 }
250 \f
251 /* Add an entry to the base file.  */
252 static void
253 mcore_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)
254       struct bfd_link_info * info;
255       bfd *                  output_bfd;
256       asection *             input_section;
257       bfd_vma                reloc_offset;
258 {
259   bfd_vma addr = reloc_offset
260                  - input_section->vma
261                  + input_section->output_offset
262                  + input_section->output_section->vma;
263
264   if (coff_data (output_bfd)->pe)
265      addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
266   
267   fwrite (&addr, 1, sizeof (addr), (FILE *) info->base_file);
268 }
269 \f
270 /*ARGSUSED*/
271 static bfd_reloc_status_type
272 mcore_coff_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
273                            output_bfd, error_message)
274      bfd * abfd;
275      arelent * reloc_entry;
276      asymbol * symbol ATTRIBUTE_UNUSED;
277      PTR data ATTRIBUTE_UNUSED;
278      asection * input_section ATTRIBUTE_UNUSED;
279      bfd * output_bfd ATTRIBUTE_UNUSED;
280      char ** error_message ATTRIBUTE_UNUSED;
281 {
282   BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0);
283   
284   _bfd_error_handler (_("%s: Relocation %s (%d) is not currently supported.\n"),
285                       bfd_get_filename (abfd),
286                       reloc_entry->howto->name,
287                       reloc_entry->howto->type);
288   
289   return bfd_reloc_notsupported;
290 }
291
292 \f
293 /* A cheesy little macro to make the code a little more readable. */
294 #define HOW2MAP(bfd_rtype, mcore_rtype)  \
295  case bfd_rtype: return & mcore_coff_howto_table [mcore_rtype]
296
297 static reloc_howto_type *
298 mcore_coff_reloc_type_lookup (abfd, code)
299      bfd * abfd ATTRIBUTE_UNUSED;
300      bfd_reloc_code_real_type code;
301 {
302   switch (code)
303     { 
304       HOW2MAP (BFD_RELOC_32,                       IMAGE_REL_MCORE_ADDR32);
305       HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM8BY4,      IMAGE_REL_MCORE_PCREL_IMM8BY4);
306       HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM11BY2,     IMAGE_REL_MCORE_PCREL_IMM11BY2);
307       HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM4BY2,      IMAGE_REL_MCORE_PCREL_IMM4BY2);
308       HOW2MAP (BFD_RELOC_32_PCREL,                 IMAGE_REL_MCORE_PCREL_32);
309       HOW2MAP (BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2, IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2);
310       HOW2MAP (BFD_RELOC_RVA,                      IMAGE_REL_MCORE_RVA);
311    default: 
312       return NULL;
313     }
314   /*NOTREACHED*/
315 }
316
317 #undef HOW2MAP
318
319 #define RTYPE2HOWTO(cache_ptr, dst) \
320   (cache_ptr)->howto = mcore_coff_howto_table + (dst)->r_type;
321
322 static reloc_howto_type *
323 coff_mcore_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
324      bfd * abfd ATTRIBUTE_UNUSED;
325      asection * sec;
326      struct internal_reloc * rel;
327      struct coff_link_hash_entry * h ATTRIBUTE_UNUSED;
328      struct internal_syment * sym;
329      bfd_vma * addendp;
330 {
331   reloc_howto_type * howto;
332
333
334   if (rel->r_type >= NUM_ELEM (mcore_coff_howto_table))
335     return NULL;
336   
337   howto = mcore_coff_howto_table + rel->r_type;
338
339   if (rel->r_type == IMAGE_REL_MCORE_RVA)
340     * addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
341   
342   if (howto->pc_relative)
343     {
344       * addendp = sec->vma - 2; /* XXX guess - is this right ? */
345       
346       /* If the symbol is defined, then the generic code is going to
347          add back the symbol value in order to cancel out an
348          adjustment it made to the addend.  However, we set the addend
349          to 0 at the start of this function.  We need to adjust here,
350          to avoid the adjustment the generic code will make.  FIXME:
351          This is getting a bit hackish.  */
352       if (sym != NULL && sym->n_scnum != 0)
353         * addendp -= sym->n_value;
354     }
355   else
356     * addendp = 0;
357   
358   return howto;
359 }
360
361 /* Return true if this relocation should appear in the output .reloc section.
362    This function is referenced in pe_mkobject in peicode.h.  */
363 static boolean
364 in_reloc_p (abfd, howto)
365      bfd * abfd ATTRIBUTE_UNUSED;
366      reloc_howto_type * howto;
367 {
368   return ! howto->pc_relative && howto->type != IMAGE_REL_MCORE_RVA;
369 }     
370
371 \f
372 /* The reloc processing routine for the optimized COFF linker.  */
373 static boolean
374 coff_mcore_relocate_section (output_bfd, info, input_bfd, input_section,
375                            contents, relocs, syms, sections)
376      bfd * output_bfd;
377      struct bfd_link_info * info;
378      bfd * input_bfd;
379      asection * input_section;
380      bfd_byte * contents;
381      struct internal_reloc * relocs;
382      struct internal_syment * syms;
383      asection ** sections;
384 {
385   struct internal_reloc * rel;
386   struct internal_reloc * relend;
387   boolean hihalf;
388   bfd_vma hihalf_val;
389   
390   /* If we are performing a relocateable link, we don't need to do a
391      thing.  The caller will take care of adjusting the reloc
392      addresses and symbol indices.  */
393   if (info->relocateable)
394     return true;
395   
396   /* Check if we have the same endianess */
397   if (   input_bfd->xvec->byteorder != output_bfd->xvec->byteorder
398       && output_bfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
399     {
400       (*_bfd_error_handler)
401         (_("%s: compiled for a %s endian system and target is %s endian.\n"),
402          bfd_get_filename (input_bfd),
403          bfd_big_endian (input_bfd) ? "big" : "little",
404          bfd_big_endian (output_bfd) ? "big" : "little");
405
406       bfd_set_error (bfd_error_wrong_format);
407       return false;
408     }
409
410   hihalf = false;
411   hihalf_val = 0;
412
413   rel = relocs;
414   relend = rel + input_section->reloc_count;
415   
416   for (; rel < relend; rel++)
417     {
418       long                           symndx;
419       struct internal_syment *       sym;
420       bfd_vma                        val;
421       bfd_vma                        addend;
422       bfd_reloc_status_type          rstat;
423       bfd_byte *                     loc;
424       unsigned short                 r_type = rel->r_type;
425       reloc_howto_type *             howto = NULL;
426       struct coff_link_hash_entry *  h;
427       const char *                   my_name;
428   
429       symndx = rel->r_symndx;
430       loc = contents + rel->r_vaddr - input_section->vma;
431
432       if (symndx == -1)
433         {
434           h = NULL;
435           sym = NULL;
436         }
437       else
438         {
439           h = obj_coff_sym_hashes (input_bfd)[symndx];
440           sym = syms + symndx;
441         }
442
443       /* Get the howto and initialise the addend.  */
444       howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
445                                        sym, & addend);
446       if (howto == NULL)
447         return false;
448
449       val = 0;
450       
451       if (h == NULL)
452         {
453           if (symndx == -1)
454             my_name = "*ABS*";
455           else
456             {
457               asection * sec = sections[symndx];
458               
459               val = (sym->n_value 
460                      + sec->output_section->vma
461                      + sec->output_offset);
462
463               if (sym == NULL)
464                 my_name = "*unknown*";
465               else if (   sym->_n._n_n._n_zeroes == 0
466                        && sym->_n._n_n._n_offset != 0)
467                 my_name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset;
468               else 
469                 {
470                   static char buf [SYMNMLEN + 1];
471                   
472                   strncpy (buf, sym->_n._n_name, SYMNMLEN);
473                   buf[SYMNMLEN] = '\0';
474                   my_name = buf;
475                 }
476             }
477         }
478       else
479         {
480           if (   h->root.type == bfd_link_hash_defined
481               || h->root.type == bfd_link_hash_defweak)
482             {
483               asection * sec = h->root.u.def.section;
484               
485               val = (h->root.u.def.value
486                      + sec->output_section->vma
487                      + sec->output_offset);
488             }
489           else
490             {
491               if (! ((*info->callbacks->undefined_symbol)
492                      (info, h->root.root.string, input_bfd, input_section,
493                       rel->r_vaddr - input_section->vma)))
494                 return false;
495             }
496           
497           my_name = h->root.root.string;
498         }       
499
500       rstat = bfd_reloc_ok;
501       
502       /* Each case must do its own relocation, setting rstat appropriately.  */
503       switch (r_type)
504         {
505         default:
506           _bfd_error_handler (_("%s: unsupported relocation type 0x%02x"),
507                               bfd_get_filename (input_bfd), r_type);
508           bfd_set_error (bfd_error_bad_value);
509           return false;
510           
511         case IMAGE_REL_MCORE_ABSOLUTE:
512           fprintf (stderr, 
513                    _("Warning: unsupported reloc %s <file %s, section %s>\n"), 
514                    howto->name,
515                    bfd_get_filename (input_bfd),
516                    input_section->name);
517           
518           fprintf (stderr,"sym %ld (%s), r_vaddr %ld (%lx)\n", 
519                    rel->r_symndx, my_name, (long) rel->r_vaddr,
520                    (unsigned long) rel->r_vaddr);  
521           break;
522           
523         case IMAGE_REL_MCORE_PCREL_IMM8BY4:
524         case IMAGE_REL_MCORE_PCREL_IMM11BY2:
525         case IMAGE_REL_MCORE_PCREL_IMM4BY2:
526         case IMAGE_REL_MCORE_PCREL_32:
527         case IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2:
528         case IMAGE_REL_MCORE_ADDR32:
529         case IMAGE_REL_MCORE_RVA:
530           rstat = _bfd_relocate_contents (howto, input_bfd, val, loc);
531           break;
532         }
533       
534       if (info->base_file)
535         {
536           /* Emit a reloc if the backend thinks it needs it.  */
537           if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto))
538             mcore_emit_base_file_entry (info, output_bfd, input_section, rel->r_vaddr);
539         }
540   
541       switch (rstat)
542         {
543         default:
544           abort ();
545           
546         case bfd_reloc_ok:
547           break;
548           
549         case bfd_reloc_overflow:
550           if (! ((*info->callbacks->reloc_overflow)
551                  (info, my_name, howto->name, 
552                   (bfd_vma) 0, input_bfd,
553                   input_section, rel->r_vaddr - input_section->vma)))
554             return false;
555         }
556     }     
557
558   return true;
559 }
560
561 \f
562 /* Tailor coffcode.h -- macro heaven. */
563
564 /* We use the special COFF backend linker, with our own special touch.  */
565
566 #define coff_bfd_reloc_type_lookup   mcore_coff_reloc_type_lookup
567 #define coff_relocate_section        coff_mcore_relocate_section
568 #define coff_rtype_to_howto          coff_mcore_rtype_to_howto
569
570 #define SELECT_RELOC(internal, howto) {internal.r_type = howto->type;}
571
572 #define COFF_PAGE_SIZE               0x1000
573
574 #include "coffcode.h"
575 \f
576 static const bfd_target *
577 pe_object_p (abfd)
578      bfd * abfd;
579 {
580 #ifdef COFF_IMAGE_WITH_PE
581   /* We need to hack badly to handle a PE image correctly.  In PE
582      images created by the GNU linker, the offset to the COFF header
583      is always the size.  However, this is not the case in images
584      generated by other PE linkers.  The PE format stores a four byte
585      offset to the PE signature just before the COFF header at
586      location 0x3c of the file.  We pick up that offset, verify that
587      the PE signature is there, and then set ourselves up to read in
588      the COFF header.  */
589   {
590     bfd_byte ext_offset[4];
591     file_ptr offset;
592     bfd_byte ext_signature[4];
593     unsigned long signature;
594
595     if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0
596         || bfd_read (ext_offset, 1, 4, abfd) != 4)
597       {
598         if (bfd_get_error () != bfd_error_system_call)
599           bfd_set_error (bfd_error_wrong_format);
600         return NULL;
601       }
602     
603     offset = bfd_h_get_32 (abfd, ext_offset);
604     
605     if (bfd_seek (abfd, offset, SEEK_SET) != 0
606         || bfd_read (ext_signature, 1, 4, abfd) != 4)
607       {
608         if (bfd_get_error () != bfd_error_system_call)
609           bfd_set_error (bfd_error_wrong_format);
610         
611         return NULL;
612       }
613     
614     signature = bfd_h_get_32 (abfd, ext_signature);
615
616     if (signature != 0x4550)
617       {
618         bfd_set_error (bfd_error_wrong_format);
619         return NULL;
620       }
621
622     /* Here is the hack.  coff_object_p wants to read filhsz bytes to
623        pick up the COFF header.  We adjust so that that will work.  20
624        is the size of the mips COFF filehdr.  */
625     if (bfd_seek (abfd, (bfd_tell (abfd) - bfd_coff_filhsz (abfd) + 20),
626                   SEEK_SET) != 0)
627       {
628         if (bfd_get_error () != bfd_error_system_call)
629           bfd_set_error (bfd_error_wrong_format);
630         
631         return NULL;
632       }
633   }
634 #endif
635
636   return coff_object_p (abfd);
637 }
638 \f
639 /* Forward declaration to initialise alterbative_target field.  */
640 extern const bfd_target TARGET_LITTLE_SYM;
641
642 /* The transfer vectors that lead the outside world to all of the above. */
643 CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, (SEC_LINK_ONCE | SEC_LINK_DUPLICATES), 0, & TARGET_LITTLE_SYM)
644 CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, (SEC_LINK_ONCE | SEC_LINK_DUPLICATES), 0, & TARGET_BIG_SYM)