OSDN Git Service

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