Regenerate Makeile.in file for copyright update
[external/binutils.git] / bfd / versados.c
1 /* BFD back-end for VERSAdos-E objects.
2    Copyright (C) 1995-2015 Free Software Foundation, Inc.
3    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
4
5    Versados is a Motorola trademark.
6
7    This file is part of BFD, the Binary File Descriptor library.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22    MA 02110-1301, USA.  */
23
24 /*
25    SUBSECTION
26    VERSAdos-E relocatable object file format
27
28    DESCRIPTION
29
30    This module supports reading of VERSAdos relocatable
31    object files.
32
33    A VERSAdos file looks like contains
34
35    o Identification Record
36    o External Symbol Definition Record
37    o Object Text Record
38    o End Record.  */
39
40 #include "sysdep.h"
41 #include "bfd.h"
42 #include "libbfd.h"
43 #include "libiberty.h"
44
45
46 #define VHEADER '1'
47 #define VESTDEF '2'
48 #define VOTR '3'
49 #define VEND '4'
50
51 #define ES_BASE 17              /* First symbol has esdid 17.  */
52
53 /* Per file target dependent information.  */
54
55 /* One for each section.  */
56 struct esdid
57 {
58   asection *section;            /* Ptr to bfd version.  */
59   unsigned char *contents;      /* Used to build image.  */
60   int pc;
61   int relocs;                   /* Reloc count, valid end of pass 1.  */
62   int donerel;                  /* Have relocs been translated.  */
63 };
64
65 typedef struct versados_data_struct
66 {
67   int es_done;                  /* Count of symbol index, starts at ES_BASE.  */
68   asymbol *symbols;             /* Pointer to local symbols.  */
69   char *strings;                /* Strings of all the above.  */
70   int stringlen;                /* Len of string table (valid end of pass1).  */
71   int nsecsyms;                 /* Number of sections.  */
72
73   int ndefs;                    /* Number of exported symbols (they dont get esdids).  */
74   int nrefs;                    /* Number of imported symbols  (valid end of pass1).  */
75
76   int ref_idx;                  /* Current processed value of the above.  */
77   int def_idx;
78
79   int pass_2_done;
80
81   struct esdid e[16];           /* Per section info.  */
82   int alert;                    /* To see if we're trampling.  */
83   asymbol *rest[256 - 16];      /* Per symbol info.  */
84 }
85 tdata_type;
86
87 #define VDATA(abfd)       (abfd->tdata.versados_data)
88 #define EDATA(abfd, n)    (abfd->tdata.versados_data->e[(n) < 16 ? (n) : 0])
89 #define RDATA(abfd, n)    (abfd->tdata.versados_data->rest[(n) < 240 ? (n) : 0])
90
91 struct ext_otr
92 {
93   unsigned char size;
94   char type;
95   unsigned char map[4];
96   unsigned char esdid;
97   unsigned char data[200];
98 };
99
100 struct ext_vheader
101 {
102   unsigned char size;
103   char type;                    /* Record type.  */
104   char name[10];                /* Module name.  */
105   char rev;                     /* Module rev number.  */
106   char lang;
107   char vol[4];
108   char user[2];
109   char cat[8];
110   char fname[8];
111   char ext[2];
112   char time[3];
113   char date[3];
114   char rest[211];
115 };
116
117 struct ext_esd
118 {
119   unsigned char size;
120   char type;
121   unsigned char esd_entries[1];
122 };
123
124 #define ESD_ABS           0
125 #define ESD_COMMON        1
126 #define ESD_STD_REL_SEC   2
127 #define ESD_SHRT_REL_SEC  3
128 #define ESD_XDEF_IN_SEC   4
129 #define ESD_XDEF_IN_ABS   5
130 #define ESD_XREF_SEC      6
131 #define ESD_XREF_SYM      7
132
133 union ext_any
134 {
135   unsigned char size;
136   struct ext_vheader header;
137   struct ext_esd esd;
138   struct ext_otr otr;
139 };
140
141 /* Initialize by filling in the hex conversion array.  */
142
143 /* Set up the tdata information.  */
144
145 static bfd_boolean
146 versados_mkobject (bfd *abfd)
147 {
148   if (abfd->tdata.versados_data == NULL)
149     {
150       bfd_size_type amt = sizeof (tdata_type);
151       tdata_type *tdata = bfd_alloc (abfd, amt);
152
153       if (tdata == NULL)
154         return FALSE;
155       abfd->tdata.versados_data = tdata;
156       tdata->symbols = NULL;
157       VDATA (abfd)->alert = 0x12345678;
158     }
159
160   bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0);
161   return TRUE;
162 }
163
164 /* Report a problem in an S record file.  FIXME: This probably should
165    not call fprintf, but we really do need some mechanism for printing
166    error messages.  */
167
168 static asymbol *
169 versados_new_symbol (bfd *abfd,
170                      int snum,
171                      const char *name,
172                      bfd_vma val,
173                      asection *sec)
174 {
175   asymbol *n = VDATA (abfd)->symbols + snum;
176   n->name = name;
177   n->value = val;
178   n->section = sec;
179   n->the_bfd = abfd;
180   n->flags = 0;
181   return n;
182 }
183
184 static bfd_boolean
185 get_record (bfd *abfd, union ext_any *ptr)
186 {
187   if (bfd_bread (&ptr->size, (bfd_size_type) 1, abfd) != 1
188       || (bfd_bread ((char *) ptr + 1, (bfd_size_type) ptr->size, abfd)
189           != ptr->size))
190     return FALSE;
191
192   {
193     bfd_size_type amt = ptr->size + 1;
194
195     if (amt < sizeof (* ptr))
196       memset ((char *) ptr + amt, 0, sizeof (* ptr) - amt);
197   }
198
199   return TRUE;
200 }
201
202 static int
203 get_4 (unsigned char **pp)
204 {
205   unsigned char *p = *pp;
206
207   *pp += 4;
208   return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0);
209 }
210
211 static void
212 get_10 (unsigned char **pp, char *name)
213 {
214   char *p = (char *) *pp;
215   int len = 10;
216
217   *pp += len;
218   while (*p != ' ' && len)
219     {
220       *name++ = *p++;
221       len--;
222     }
223   *name = 0;
224 }
225
226 static char *
227 new_symbol_string (bfd *abfd, const char *name)
228 {
229   char *n = VDATA (abfd)->strings;
230
231   strcpy (VDATA (abfd)->strings, name);
232   VDATA (abfd)->strings += strlen (VDATA (abfd)->strings) + 1;
233   return n;
234 }
235
236 static void
237 process_esd (bfd *abfd, struct ext_esd *esd, int pass)
238 {
239   /* Read through the ext def for the est entries.  */
240   int togo = esd->size - 2;
241   bfd_vma size;
242   bfd_vma start;
243   asection *sec;
244   char name[11];
245   unsigned char *ptr = esd->esd_entries;
246   unsigned char *end = ptr + togo;
247
248   while (ptr < end)
249     {
250       int scn = *ptr & 0xf;
251       int typ = (*ptr >> 4) & 0xf;
252
253       /* Declare this section.  */
254       sprintf (name, "%d", scn);
255       sec = bfd_make_section_old_way (abfd, strdup (name));
256       sec->target_index = scn;
257       EDATA (abfd, scn).section = sec;
258       ptr++;
259
260       switch (typ)
261         {
262         default:
263           abort ();
264         case ESD_XREF_SEC:
265         case ESD_XREF_SYM:
266           {
267             int snum = VDATA (abfd)->ref_idx++;
268             get_10 (&ptr, name);
269             if (pass == 1)
270               VDATA (abfd)->stringlen += strlen (name) + 1;
271             else
272               {
273                 int esidx;
274                 asymbol *s;
275                 char *n = new_symbol_string (abfd, name);
276
277                 s = versados_new_symbol (abfd, snum, n, (bfd_vma) 0,
278                                          bfd_und_section_ptr);
279                 esidx = VDATA (abfd)->es_done++;
280                 RDATA (abfd, esidx - ES_BASE) = s;
281               }
282           }
283           break;
284
285         case ESD_ABS:
286           size = get_4 (&ptr);
287           (void) size;
288           start = get_4 (&ptr);
289           (void) start;
290           break;
291         case ESD_STD_REL_SEC:
292         case ESD_SHRT_REL_SEC:
293           sec->size = get_4 (&ptr);
294           sec->flags |= SEC_ALLOC;
295           break;
296         case ESD_XDEF_IN_ABS:
297           sec = bfd_abs_section_ptr;
298         case ESD_XDEF_IN_SEC:
299           {
300             int snum = VDATA (abfd)->def_idx++;
301             bfd_vma val;
302
303             get_10 (&ptr, name);
304             val = get_4 (&ptr);
305             if (pass == 1)
306               /* Just remember the symbol.  */
307               VDATA (abfd)->stringlen += strlen (name) + 1;
308             else
309               {
310                 asymbol *s;
311                 char *n = new_symbol_string (abfd, name);
312
313                 s = versados_new_symbol (abfd, snum + VDATA (abfd)->nrefs, n,
314                                          val, sec);
315                 s->flags |= BSF_GLOBAL;
316               }
317           }
318           break;
319         }
320     }
321 }
322
323 #define R_RELWORD     1
324 #define R_RELLONG     2
325 #define R_RELWORD_NEG 3
326 #define R_RELLONG_NEG 4
327
328 reloc_howto_type versados_howto_table[] =
329 {
330   HOWTO (R_RELWORD, 0, 1, 16, FALSE,
331          0, complain_overflow_dont, 0,
332          "+v16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
333   HOWTO (R_RELLONG, 0, 2, 32, FALSE,
334          0, complain_overflow_dont, 0,
335          "+v32", TRUE, 0xffffffff, 0xffffffff, FALSE),
336
337   HOWTO (R_RELWORD_NEG, 0, -1, 16, FALSE,
338          0, complain_overflow_dont, 0,
339          "-v16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
340   HOWTO (R_RELLONG_NEG, 0, -2, 32, FALSE,
341          0, complain_overflow_dont, 0,
342          "-v32", TRUE, 0xffffffff, 0xffffffff, FALSE),
343 };
344
345 static int
346 get_offset (int len, unsigned char *ptr)
347 {
348   int val = 0;
349
350   if (len)
351     {
352       int i;
353
354       val = *ptr++;
355       if (val & 0x80)
356         val |= ~0xff;
357       for (i = 1; i < len; i++)
358         val = (val << 8) | *ptr++;
359     }
360
361   return val;
362 }
363
364 static void
365 process_otr (bfd *abfd, struct ext_otr *otr, int pass)
366 {
367   unsigned long shift;
368   unsigned char *srcp = otr->data;
369   unsigned char *endp = (unsigned char *) otr + otr->size;
370   unsigned int bits = (otr->map[0] << 24)
371   | (otr->map[1] << 16)
372   | (otr->map[2] << 8)
373   | (otr->map[3] << 0);
374
375   struct esdid *esdid = &EDATA (abfd, otr->esdid - 1);
376   unsigned char *contents;
377   bfd_boolean need_contents = FALSE;
378   unsigned int dst_idx;
379
380   /* PR 17512: file: ac7da425.  */
381   if (otr->esdid == 0)
382     return;
383   
384   contents = esdid->contents;
385   dst_idx = esdid->pc;
386   
387   for (shift = ((unsigned long) 1 << 31); shift && srcp < endp; shift >>= 1)
388     {
389       if (bits & shift)
390         {
391           int flag = *srcp++;
392           int esdids = (flag >> 5) & 0x7;
393           int sizeinwords = ((flag >> 3) & 1) ? 2 : 1;
394           int offsetlen = flag & 0x7;
395           int j;
396
397           if (esdids == 0)
398             {
399               /* A zero esdid means the new pc is the offset given.  */
400               dst_idx += get_offset (offsetlen, srcp);
401               srcp += offsetlen;
402             }
403           else
404             {
405               int val = get_offset (offsetlen, srcp + esdids);
406
407               if (pass == 1)
408                 need_contents = TRUE;
409               else if (contents && dst_idx < esdid->section->size - sizeinwords * 2)
410                 for (j = 0; j < sizeinwords * 2; j++)
411                   {
412                     contents[dst_idx + (sizeinwords * 2) - j - 1] = val;
413                     val >>= 8;
414                   }
415
416               for (j = 0; j < esdids; j++)
417                 {
418                   int id = *srcp++;
419
420                   if (id)
421                     {
422                       int rn = EDATA (abfd, otr->esdid - 1).relocs++;
423
424                       if (pass == 1)
425                         {
426                           /* This is the first pass over the data,
427                              just remember that we need a reloc.  */
428                         }
429                       else
430                         {
431                           arelent *n;
432
433                           /* PR 17512: file: 54f733e0.  */
434                           if (EDATA (abfd, otr->esdid - 1).section == NULL)
435                             continue;
436                           n = EDATA (abfd, otr->esdid - 1).section->relocation + rn;
437                           n->address = dst_idx;
438                           n->sym_ptr_ptr = (asymbol **) (size_t) id;
439                           n->addend = 0;
440                           n->howto = versados_howto_table + ((j & 1) * 2) + (sizeinwords - 1);
441                         }
442                     }
443                 }
444               srcp += offsetlen;
445               dst_idx += sizeinwords * 2;
446             }
447         }
448       else
449         {
450           need_contents = TRUE;
451
452           if (esdid->section && contents && dst_idx < esdid->section->size)
453             if (pass == 2)
454               {
455                 /* Absolute code, comes in 16 bit lumps.  */
456                 contents[dst_idx] = srcp[0];
457                 contents[dst_idx + 1] = srcp[1];
458               }
459
460           dst_idx += 2;
461           srcp += 2;
462         }
463     }
464
465   EDATA (abfd, otr->esdid - 1).pc = dst_idx;
466
467   if (!contents && need_contents)
468     {
469       if (esdid->section)
470         {
471           bfd_size_type size;
472
473           size = esdid->section->size;
474           esdid->contents = bfd_alloc (abfd, size);
475         }
476       else
477         esdid->contents = NULL;
478     }
479 }
480
481 static bfd_boolean
482 versados_scan (bfd *abfd)
483 {
484   bfd_boolean loop = TRUE;
485   int i;
486   int j;
487   int nsecs = 0;
488   bfd_size_type amt;
489
490   VDATA (abfd)->stringlen = 0;
491   VDATA (abfd)->nrefs = 0;
492   VDATA (abfd)->ndefs = 0;
493   VDATA (abfd)->ref_idx = 0;
494   VDATA (abfd)->def_idx = 0;
495   VDATA (abfd)->pass_2_done = 0;
496
497   while (loop)
498     {
499       union ext_any any;
500
501       if (!get_record (abfd, &any))
502         return FALSE;
503       switch (any.header.type)
504         {
505         case VHEADER:
506           break;
507         case VEND:
508           loop = FALSE;
509           break;
510         case VESTDEF:
511           process_esd (abfd, &any.esd, 1);
512           break;
513         case VOTR:
514           process_otr (abfd, &any.otr, 1);
515           break;
516         }
517     }
518
519   /* Now allocate space for the relocs and sections.  */
520   VDATA (abfd)->nrefs = VDATA (abfd)->ref_idx;
521   VDATA (abfd)->ndefs = VDATA (abfd)->def_idx;
522   VDATA (abfd)->ref_idx = 0;
523   VDATA (abfd)->def_idx = 0;
524
525   abfd->symcount = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs;
526
527   for (i = 0; i < 16; i++)
528     {
529       struct esdid *esdid = &EDATA (abfd, i);
530
531       if (esdid->section)
532         {
533           amt = (bfd_size_type) esdid->relocs * sizeof (arelent);
534           esdid->section->relocation = bfd_alloc (abfd, amt);
535           esdid->pc = 0;
536
537           if (esdid->contents)
538             esdid->section->flags |= SEC_HAS_CONTENTS | SEC_LOAD;
539
540           esdid->section->reloc_count = esdid->relocs;
541           if (esdid->relocs)
542             esdid->section->flags |= SEC_RELOC;
543
544           esdid->relocs = 0;
545
546           /* Add an entry into the symbol table for it.  */
547           nsecs++;
548           VDATA (abfd)->stringlen += strlen (esdid->section->name) + 1;
549         }
550     }
551
552   abfd->symcount += nsecs;
553
554   amt = abfd->symcount;
555   amt *= sizeof (asymbol);
556   VDATA (abfd)->symbols = bfd_alloc (abfd, amt);
557
558   amt = VDATA (abfd)->stringlen;
559   VDATA (abfd)->strings = bfd_alloc (abfd, amt);
560
561   if ((VDATA (abfd)->symbols == NULL && abfd->symcount > 0)
562       || (VDATA (abfd)->strings == NULL && VDATA (abfd)->stringlen > 0))
563     return FALSE;
564
565   /* Actually fill in the section symbols,
566      we stick them at the end of the table.  */
567   for (j = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs, i = 0; i < 16; i++)
568     {
569       struct esdid *esdid = &EDATA (abfd, i);
570       asection *sec = esdid->section;
571
572       if (sec)
573         {
574           asymbol *s = VDATA (abfd)->symbols + j;
575           s->name = new_symbol_string (abfd, sec->name);
576           s->section = sec;
577           s->flags = BSF_LOCAL;
578           s->value = 0;
579           s->the_bfd = abfd;
580           j++;
581         }
582     }
583
584   if (abfd->symcount)
585     abfd->flags |= HAS_SYMS;
586
587   /* Set this to nsecs - since we've already planted the section
588      symbols.  */
589   VDATA (abfd)->nsecsyms = nsecs;
590
591   VDATA (abfd)->ref_idx = 0;
592
593   return TRUE;
594 }
595
596 /* Check whether an existing file is a versados  file.  */
597
598 static const bfd_target *
599 versados_object_p (bfd *abfd)
600 {
601   struct ext_vheader ext;
602   unsigned char len;
603   tdata_type *tdata_save;
604
605   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
606     return NULL;
607
608   if (bfd_bread (&len, (bfd_size_type) 1, abfd) != 1)
609     {
610       if (bfd_get_error () != bfd_error_system_call)
611         bfd_set_error (bfd_error_wrong_format);
612       return NULL;
613     }
614
615   /* PR 17512: file: 726-2128-0.004.  */
616   if (len < 13)
617     {
618       bfd_set_error (bfd_error_wrong_format);
619       return NULL;
620     }
621
622   if (bfd_bread (&ext.type, (bfd_size_type) len, abfd) != len)
623     {
624       if (bfd_get_error () != bfd_error_system_call)
625         bfd_set_error (bfd_error_wrong_format);
626       return NULL;
627     }
628
629   /* We guess that the language field will never be larger than 10.
630      In sample files, it is always either 0 or 1.  Checking for this
631      prevents confusion with Intel Hex files.  */
632   if (ext.type != VHEADER
633       || ext.lang > 10)
634     {
635       bfd_set_error (bfd_error_wrong_format);
636       return NULL;
637     }
638
639   /* OK, looks like a record, build the tdata and read in.  */
640   tdata_save = abfd->tdata.versados_data;
641   if (!versados_mkobject (abfd) || !versados_scan (abfd))
642     {
643       abfd->tdata.versados_data = tdata_save;
644       return NULL;
645     }
646
647   return abfd->xvec;
648 }
649
650 static bfd_boolean
651 versados_pass_2 (bfd *abfd)
652 {
653   union ext_any any;
654
655   if (VDATA (abfd)->pass_2_done)
656     return 1;
657
658   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
659     return 0;
660
661   VDATA (abfd)->es_done = ES_BASE;
662
663   /* Read records till we get to where we want to be.  */
664   while (1)
665     {
666       get_record (abfd, &any);
667       switch (any.header.type)
668         {
669         case VEND:
670           VDATA (abfd)->pass_2_done = 1;
671           return 1;
672         case VESTDEF:
673           process_esd (abfd, &any.esd, 2);
674           break;
675         case VOTR:
676           process_otr (abfd, &any.otr, 2);
677           break;
678         }
679     }
680 }
681
682 static bfd_boolean
683 versados_get_section_contents (bfd *abfd,
684                                asection *section,
685                                void * location,
686                                file_ptr offset,
687                                bfd_size_type count)
688 {
689   if (!versados_pass_2 (abfd))
690     return FALSE;
691
692   memcpy (location,
693           EDATA (abfd, section->target_index).contents + offset,
694           (size_t) count);
695
696   return TRUE;
697 }
698
699 #define versados_get_section_contents_in_window \
700   _bfd_generic_get_section_contents_in_window
701
702 static bfd_boolean
703 versados_set_section_contents (bfd *abfd ATTRIBUTE_UNUSED,
704                                sec_ptr section ATTRIBUTE_UNUSED,
705                                const void * location ATTRIBUTE_UNUSED,
706                                file_ptr offset ATTRIBUTE_UNUSED,
707                                bfd_size_type bytes_to_do ATTRIBUTE_UNUSED)
708 {
709   return FALSE;
710 }
711
712 static int
713 versados_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
714                          struct bfd_link_info *info ATTRIBUTE_UNUSED)
715 {
716   return 0;
717 }
718
719 /* Return the amount of memory needed to read the symbol table.  */
720
721 static long
722 versados_get_symtab_upper_bound (bfd *abfd)
723 {
724   return (bfd_get_symcount (abfd) + 1) * sizeof (asymbol *);
725 }
726
727 /* Return the symbol table.  */
728
729 static long
730 versados_canonicalize_symtab (bfd *abfd, asymbol **alocation)
731 {
732   unsigned int symcount = bfd_get_symcount (abfd);
733   unsigned int i;
734   asymbol *s;
735
736   versados_pass_2 (abfd);
737
738   for (i = 0, s = VDATA (abfd)->symbols;
739        i < symcount;
740        s++, i++)
741     *alocation++ = s;
742
743   *alocation = NULL;
744
745   return symcount;
746 }
747
748 static void
749 versados_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
750                           asymbol *symbol,
751                           symbol_info *ret)
752 {
753   bfd_symbol_info (symbol, ret);
754 }
755
756 static void
757 versados_print_symbol (bfd *abfd,
758                        void * afile,
759                        asymbol *symbol,
760                        bfd_print_symbol_type how)
761 {
762   FILE *file = (FILE *) afile;
763
764   switch (how)
765     {
766     case bfd_print_symbol_name:
767       fprintf (file, "%s", symbol->name);
768       break;
769     default:
770       bfd_print_symbol_vandf (abfd, (void *) file, symbol);
771       fprintf (file, " %-5s %s",
772                symbol->section->name,
773                symbol->name);
774     }
775 }
776
777 static long
778 versados_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
779                                 sec_ptr asect)
780 {
781   return (asect->reloc_count + 1) * sizeof (arelent *);
782 }
783
784 static long
785 versados_canonicalize_reloc (bfd *abfd,
786                              sec_ptr section,
787                              arelent **relptr,
788                              asymbol **symbols)
789 {
790   unsigned int count;
791   arelent *src;
792
793   versados_pass_2 (abfd);
794   src = section->relocation;
795
796   if (!EDATA (abfd, section->target_index).donerel)
797     {
798       EDATA (abfd, section->target_index).donerel = 1;
799       /* Translate from indexes to symptr ptrs.  */
800       for (count = 0; count < section->reloc_count; count++)
801         {
802           int esdid = (int) (size_t) src[count].sym_ptr_ptr;
803
804           if (esdid == 0)
805             src[count].sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
806           else if (esdid < ES_BASE)
807             {
808               /* Section relative thing.  */
809               struct esdid *e = &EDATA (abfd, esdid - 1);
810
811               /* PR 17512: file:cd92277c.  */
812               if (e->section)
813                 src[count].sym_ptr_ptr = e->section->symbol_ptr_ptr;
814               else
815                 src[count].sym_ptr_ptr = bfd_und_section_ptr->symbol_ptr_ptr;
816             }
817           /* PR 17512: file:3757-2936-0.004.  */
818           else if ((unsigned) (esdid - ES_BASE) >= bfd_get_symcount (abfd))
819             src[count].sym_ptr_ptr = bfd_und_section_ptr->symbol_ptr_ptr;
820           else
821             src[count].sym_ptr_ptr = symbols + esdid - ES_BASE;
822         }
823     }
824
825   for (count = 0; count < section->reloc_count; count++)
826     *relptr++ = src++;
827
828   *relptr = 0;
829   return section->reloc_count;
830 }
831
832 #define versados_close_and_cleanup                    _bfd_generic_close_and_cleanup
833 #define versados_bfd_free_cached_info                 _bfd_generic_bfd_free_cached_info
834 #define versados_new_section_hook                     _bfd_generic_new_section_hook
835 #define versados_bfd_is_target_special_symbol   ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
836 #define versados_bfd_is_local_label_name              bfd_generic_is_local_label_name
837 #define versados_get_lineno                           _bfd_nosymbols_get_lineno
838 #define versados_find_nearest_line                    _bfd_nosymbols_find_nearest_line
839 #define versados_find_line                            _bfd_nosymbols_find_line
840 #define versados_find_inliner_info                    _bfd_nosymbols_find_inliner_info
841 #define versados_get_symbol_version_string            _bfd_nosymbols_get_symbol_version_string
842 #define versados_make_empty_symbol                    _bfd_generic_make_empty_symbol
843 #define versados_bfd_make_debug_symbol                _bfd_nosymbols_bfd_make_debug_symbol
844 #define versados_read_minisymbols                     _bfd_generic_read_minisymbols
845 #define versados_minisymbol_to_symbol                 _bfd_generic_minisymbol_to_symbol
846 #define versados_bfd_reloc_type_lookup                _bfd_norelocs_bfd_reloc_type_lookup
847 #define versados_bfd_reloc_name_lookup          _bfd_norelocs_bfd_reloc_name_lookup
848 #define versados_set_arch_mach                        bfd_default_set_arch_mach
849 #define versados_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
850 #define versados_bfd_relax_section                    bfd_generic_relax_section
851 #define versados_bfd_gc_sections                      bfd_generic_gc_sections
852 #define versados_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
853 #define versados_bfd_merge_sections                   bfd_generic_merge_sections
854 #define versados_bfd_is_group_section                 bfd_generic_is_group_section
855 #define versados_bfd_discard_group                    bfd_generic_discard_group
856 #define versados_section_already_linked               _bfd_generic_section_already_linked
857 #define versados_bfd_define_common_symbol             bfd_generic_define_common_symbol
858 #define versados_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
859 #define versados_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
860 #define versados_bfd_link_just_syms                   _bfd_generic_link_just_syms
861 #define versados_bfd_copy_link_hash_symbol_type \
862   _bfd_generic_copy_link_hash_symbol_type
863 #define versados_bfd_final_link                       _bfd_generic_final_link
864 #define versados_bfd_link_split_section               _bfd_generic_link_split_section
865
866 const bfd_target m68k_versados_vec =
867 {
868   "versados",                   /* Name.  */
869   bfd_target_versados_flavour,
870   BFD_ENDIAN_BIG,               /* Target byte order.  */
871   BFD_ENDIAN_BIG,               /* Target headers byte order.  */
872   (HAS_RELOC | EXEC_P |         /* Object flags.  */
873    HAS_LINENO | HAS_DEBUG |
874    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
875   (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
876    | SEC_ALLOC | SEC_LOAD | SEC_RELOC),         /* Section flags.  */
877   0,                            /* Leading underscore.  */
878   ' ',                          /* AR_pad_char.  */
879   16,                           /* AR_max_namelen.  */
880   0,                            /* match priority.  */
881   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
882   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
883   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* Data.  */
884   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
885   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
886   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* Headers.  */
887
888   {
889     _bfd_dummy_target,
890     versados_object_p,          /* bfd_check_format.  */
891     _bfd_dummy_target,
892     _bfd_dummy_target,
893   },
894   {
895     bfd_false,
896     versados_mkobject,
897     _bfd_generic_mkarchive,
898     bfd_false,
899   },
900   {                             /* bfd_write_contents.  */
901     bfd_false,
902     bfd_false,
903     _bfd_write_archive_contents,
904     bfd_false,
905   },
906
907   BFD_JUMP_TABLE_GENERIC (versados),
908   BFD_JUMP_TABLE_COPY (_bfd_generic),
909   BFD_JUMP_TABLE_CORE (_bfd_nocore),
910   BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
911   BFD_JUMP_TABLE_SYMBOLS (versados),
912   BFD_JUMP_TABLE_RELOCS (versados),
913   BFD_JUMP_TABLE_WRITE (versados),
914   BFD_JUMP_TABLE_LINK (versados),
915   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
916
917   NULL,
918
919   NULL
920 };