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