bfd/
[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,
157090f7 3 2006, 2007 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);
280 start = get_4 (&ptr);
281 break;
282 case ESD_STD_REL_SEC:
283 case ESD_SHRT_REL_SEC:
116c20d2
NC
284 sec->size = get_4 (&ptr);
285 sec->flags |= SEC_ALLOC;
252b5132
RH
286 break;
287 case ESD_XDEF_IN_ABS:
288 sec = (asection *) & bfd_abs_section;
289 case ESD_XDEF_IN_SEC:
290 {
291 int snum = VDATA (abfd)->def_idx++;
dc810e39 292 bfd_vma val;
116c20d2 293
252b5132
RH
294 get_10 (&ptr, name);
295 val = get_4 (&ptr);
296 if (pass == 1)
116c20d2
NC
297 /* Just remember the symbol. */
298 VDATA (abfd)->stringlen += strlen (name) + 1;
252b5132
RH
299 else
300 {
301 asymbol *s;
302 char *n = new_symbol_string (abfd, name);
116c20d2 303
dc810e39
AM
304 s = versados_new_symbol (abfd, snum + VDATA (abfd)->nrefs, n,
305 val, sec);
252b5132
RH
306 s->flags |= BSF_GLOBAL;
307 }
308 }
309 break;
310 }
311 }
312}
313
116c20d2
NC
314#define R_RELWORD 1
315#define R_RELLONG 2
252b5132
RH
316#define R_RELWORD_NEG 3
317#define R_RELLONG_NEG 4
318
319reloc_howto_type versados_howto_table[] =
320{
b34976b6 321 HOWTO (R_RELWORD, 0, 1, 16, FALSE,
252b5132 322 0, complain_overflow_dont, 0,
b34976b6
AM
323 "+v16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
324 HOWTO (R_RELLONG, 0, 2, 32, FALSE,
252b5132 325 0, complain_overflow_dont, 0,
b34976b6 326 "+v32", TRUE, 0xffffffff, 0xffffffff, FALSE),
252b5132 327
b34976b6 328 HOWTO (R_RELWORD_NEG, 0, -1, 16, FALSE,
252b5132 329 0, complain_overflow_dont, 0,
b34976b6
AM
330 "-v16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
331 HOWTO (R_RELLONG_NEG, 0, -2, 32, FALSE,
252b5132 332 0, complain_overflow_dont, 0,
b34976b6 333 "-v32", TRUE, 0xffffffff, 0xffffffff, FALSE),
252b5132
RH
334};
335
252b5132 336static int
116c20d2 337get_offset (int len, unsigned char *ptr)
252b5132
RH
338{
339 int val = 0;
116c20d2 340
252b5132
RH
341 if (len)
342 {
343 int i;
116c20d2 344
252b5132
RH
345 val = *ptr++;
346 if (val & 0x80)
347 val |= ~0xff;
348 for (i = 1; i < len; i++)
349 val = (val << 8) | *ptr++;
350 }
351
352 return val;
353}
354
355static void
116c20d2 356process_otr (bfd *abfd, struct ext_otr *otr, int pass)
252b5132
RH
357{
358 unsigned long shift;
359 unsigned char *srcp = otr->data;
360 unsigned char *endp = (unsigned char *) otr + otr->size;
361 unsigned int bits = (otr->map[0] << 24)
362 | (otr->map[1] << 16)
363 | (otr->map[2] << 8)
364 | (otr->map[3] << 0);
365
366 struct esdid *esdid = &EDATA (abfd, otr->esdid - 1);
367 unsigned char *contents = esdid->contents;
368 int need_contents = 0;
369 unsigned int dst_idx = esdid->pc;
370
dc810e39 371 for (shift = ((unsigned long) 1 << 31); shift && srcp < endp; shift >>= 1)
252b5132
RH
372 {
373 if (bits & shift)
374 {
375 int flag = *srcp++;
376 int esdids = (flag >> 5) & 0x7;
377 int sizeinwords = ((flag >> 3) & 1) ? 2 : 1;
378 int offsetlen = flag & 0x7;
379 int j;
380
252b5132
RH
381 if (esdids == 0)
382 {
116c20d2 383 /* A zero esdid means the new pc is the offset given. */
252b5132
RH
384 dst_idx += get_offset (offsetlen, srcp);
385 srcp += offsetlen;
386 }
387 else
388 {
389 int val = get_offset (offsetlen, srcp + esdids);
116c20d2 390
252b5132
RH
391 if (pass == 1)
392 need_contents = 1;
393 else
394 for (j = 0; j < sizeinwords * 2; j++)
395 {
396 contents[dst_idx + (sizeinwords * 2) - j - 1] = val;
397 val >>= 8;
398 }
399
400 for (j = 0; j < esdids; j++)
401 {
402 int esdid = *srcp++;
403
404 if (esdid)
405 {
406 int rn = EDATA (abfd, otr->esdid - 1).relocs++;
116c20d2 407
252b5132
RH
408 if (pass == 1)
409 {
116c20d2
NC
410 /* This is the first pass over the data,
411 just remember that we need a reloc. */
252b5132
RH
412 }
413 else
414 {
415 arelent *n =
416 EDATA (abfd, otr->esdid - 1).section->relocation + rn;
417 n->address = dst_idx;
418
f60ca5e3 419 n->sym_ptr_ptr = (asymbol **) (size_t) esdid;
252b5132
RH
420 n->addend = 0;
421 n->howto = versados_howto_table + ((j & 1) * 2) + (sizeinwords - 1);
422 }
423 }
424 }
425 srcp += offsetlen;
426 dst_idx += sizeinwords * 2;
427 }
428 }
429 else
430 {
431 need_contents = 1;
eea6121a 432 if (dst_idx < esdid->section->size)
252b5132
RH
433 if (pass == 2)
434 {
116c20d2 435 /* Absolute code, comes in 16 bit lumps. */
252b5132
RH
436 contents[dst_idx] = srcp[0];
437 contents[dst_idx + 1] = srcp[1];
438 }
439 dst_idx += 2;
440 srcp += 2;
441 }
442 }
443 EDATA (abfd, otr->esdid - 1).pc = dst_idx;
444
445 if (!contents && need_contents)
dc810e39 446 {
eea6121a 447 bfd_size_type size = esdid->section->size;
116c20d2 448 esdid->contents = bfd_alloc (abfd, size);
dc810e39 449 }
252b5132
RH
450}
451
b34976b6 452static bfd_boolean
116c20d2 453versados_scan (bfd *abfd)
252b5132
RH
454{
455 int loop = 1;
456 int i;
457 int j;
458 int nsecs = 0;
dc810e39 459 bfd_size_type amt;
252b5132 460
bfde9f99 461 VDATA (abfd)->stringlen = 0;
252b5132
RH
462 VDATA (abfd)->nrefs = 0;
463 VDATA (abfd)->ndefs = 0;
464 VDATA (abfd)->ref_idx = 0;
465 VDATA (abfd)->def_idx = 0;
bfde9f99 466 VDATA (abfd)->pass_2_done = 0;
252b5132
RH
467
468 while (loop)
469 {
470 union ext_any any;
116c20d2 471
252b5132 472 if (!get_record (abfd, &any))
b34976b6 473 return TRUE;
252b5132
RH
474 switch (any.header.type)
475 {
476 case VHEADER:
477 break;
478 case VEND:
479 loop = 0;
480 break;
481 case VESTDEF:
482 process_esd (abfd, &any.esd, 1);
483 break;
484 case VOTR:
485 process_otr (abfd, &any.otr, 1);
486 break;
487 }
488 }
489
116c20d2 490 /* Now allocate space for the relocs and sections. */
252b5132
RH
491 VDATA (abfd)->nrefs = VDATA (abfd)->ref_idx;
492 VDATA (abfd)->ndefs = VDATA (abfd)->def_idx;
493 VDATA (abfd)->ref_idx = 0;
494 VDATA (abfd)->def_idx = 0;
495
496 abfd->symcount = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs;
497
498 for (i = 0; i < 16; i++)
499 {
500 struct esdid *esdid = &EDATA (abfd, i);
116c20d2 501
252b5132
RH
502 if (esdid->section)
503 {
dc810e39 504 amt = (bfd_size_type) esdid->relocs * sizeof (arelent);
116c20d2 505 esdid->section->relocation = bfd_alloc (abfd, amt);
252b5132
RH
506
507 esdid->pc = 0;
508
509 if (esdid->contents)
510 esdid->section->flags |= SEC_HAS_CONTENTS | SEC_LOAD;
511
512 esdid->section->reloc_count = esdid->relocs;
513 if (esdid->relocs)
514 esdid->section->flags |= SEC_RELOC;
515
516 esdid->relocs = 0;
517
116c20d2 518 /* Add an entry into the symbol table for it. */
252b5132
RH
519 nsecs++;
520 VDATA (abfd)->stringlen += strlen (esdid->section->name) + 1;
521 }
522 }
523
524 abfd->symcount += nsecs;
525
dc810e39
AM
526 amt = abfd->symcount;
527 amt *= sizeof (asymbol);
116c20d2 528 VDATA (abfd)->symbols = bfd_alloc (abfd, amt);
252b5132 529
dc810e39
AM
530 amt = VDATA (abfd)->stringlen;
531 VDATA (abfd)->strings = bfd_alloc (abfd, amt);
252b5132
RH
532
533 if ((VDATA (abfd)->symbols == NULL && abfd->symcount > 0)
534 || (VDATA (abfd)->strings == NULL && VDATA (abfd)->stringlen > 0))
b34976b6 535 return FALSE;
252b5132
RH
536
537 /* Actually fill in the section symbols,
116c20d2 538 we stick them at the end of the table. */
252b5132
RH
539 for (j = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs, i = 0; i < 16; i++)
540 {
541 struct esdid *esdid = &EDATA (abfd, i);
542 asection *sec = esdid->section;
116c20d2 543
252b5132
RH
544 if (sec)
545 {
546 asymbol *s = VDATA (abfd)->symbols + j;
547 s->name = new_symbol_string (abfd, sec->name);
548 s->section = sec;
549 s->flags = BSF_LOCAL;
550 s->value = 0;
551 s->the_bfd = abfd;
552 j++;
553 }
554 }
116c20d2 555
252b5132
RH
556 if (abfd->symcount)
557 abfd->flags |= HAS_SYMS;
558
559 /* Set this to nsecs - since we've already planted the section
116c20d2 560 symbols. */
252b5132
RH
561 VDATA (abfd)->nsecsyms = nsecs;
562
563 VDATA (abfd)->ref_idx = 0;
564
565 return 1;
566}
567
252b5132
RH
568/* Check whether an existing file is a versados file. */
569
570static const bfd_target *
116c20d2 571versados_object_p (bfd *abfd)
252b5132
RH
572{
573 struct ext_vheader ext;
574 unsigned char len;
487e54f2 575 tdata_type *tdata_save;
252b5132
RH
576
577 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
578 return NULL;
579
dc810e39 580 if (bfd_bread (&len, (bfd_size_type) 1, abfd) != 1)
252b5132
RH
581 {
582 if (bfd_get_error () != bfd_error_system_call)
583 bfd_set_error (bfd_error_wrong_format);
584 return NULL;
585 }
586
dc810e39 587 if (bfd_bread (&ext.type, (bfd_size_type) len, abfd) != len)
252b5132
RH
588 {
589 if (bfd_get_error () != bfd_error_system_call)
590 bfd_set_error (bfd_error_wrong_format);
591 return NULL;
592 }
593
594 /* We guess that the language field will never be larger than 10.
595 In sample files, it is always either 0 or 1. Checking for this
596 prevents confusion with Intel Hex files. */
597 if (ext.type != VHEADER
598 || ext.lang > 10)
599 {
600 bfd_set_error (bfd_error_wrong_format);
601 return NULL;
602 }
603
604 /* OK, looks like a record, build the tdata and read in. */
487e54f2
AM
605 tdata_save = abfd->tdata.versados_data;
606 if (!versados_mkobject (abfd) || !versados_scan (abfd))
607 {
608 abfd->tdata.versados_data = tdata_save;
609 return NULL;
610 }
252b5132
RH
611
612 return abfd->xvec;
613}
614
b34976b6 615static bfd_boolean
116c20d2 616versados_pass_2 (bfd *abfd)
252b5132
RH
617{
618 union ext_any any;
619
620 if (VDATA (abfd)->pass_2_done)
621 return 1;
622
dc810e39 623 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
252b5132
RH
624 return 0;
625
626 VDATA (abfd)->es_done = ES_BASE;
627
116c20d2 628 /* Read records till we get to where we want to be. */
252b5132
RH
629 while (1)
630 {
631 get_record (abfd, &any);
632 switch (any.header.type)
633 {
634 case VEND:
635 VDATA (abfd)->pass_2_done = 1;
636 return 1;
637 case VESTDEF:
638 process_esd (abfd, &any.esd, 2);
639 break;
640 case VOTR:
641 process_otr (abfd, &any.otr, 2);
642 break;
643 }
644 }
645}
646
b34976b6 647static bfd_boolean
116c20d2
NC
648versados_get_section_contents (bfd *abfd,
649 asection *section,
650 void * location,
651 file_ptr offset,
652 bfd_size_type count)
252b5132
RH
653{
654 if (!versados_pass_2 (abfd))
b34976b6 655 return FALSE;
252b5132
RH
656
657 memcpy (location,
658 EDATA (abfd, section->target_index).contents + offset,
659 (size_t) count);
660
b34976b6 661 return TRUE;
252b5132
RH
662}
663
664#define versados_get_section_contents_in_window \
665 _bfd_generic_get_section_contents_in_window
666
b34976b6 667static bfd_boolean
116c20d2
NC
668versados_set_section_contents (bfd *abfd ATTRIBUTE_UNUSED,
669 sec_ptr section ATTRIBUTE_UNUSED,
670 const void * location ATTRIBUTE_UNUSED,
671 file_ptr offset ATTRIBUTE_UNUSED,
672 bfd_size_type bytes_to_do ATTRIBUTE_UNUSED)
252b5132 673{
b34976b6 674 return FALSE;
252b5132
RH
675}
676
252b5132 677static int
116c20d2 678versados_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
a6b96beb 679 struct bfd_link_info *info ATTRIBUTE_UNUSED)
252b5132
RH
680{
681 return 0;
682}
683
252b5132
RH
684/* Return the amount of memory needed to read the symbol table. */
685
686static long
116c20d2 687versados_get_symtab_upper_bound (bfd *abfd)
252b5132
RH
688{
689 return (bfd_get_symcount (abfd) + 1) * sizeof (asymbol *);
690}
691
692/* Return the symbol table. */
693
694static long
116c20d2 695versados_canonicalize_symtab (bfd *abfd, asymbol **alocation)
252b5132
RH
696{
697 unsigned int symcount = bfd_get_symcount (abfd);
698 unsigned int i;
699 asymbol *s;
700
701 versados_pass_2 (abfd);
702
703 for (i = 0, s = VDATA (abfd)->symbols;
704 i < symcount;
705 s++, i++)
116c20d2 706 *alocation++ = s;
252b5132
RH
707
708 *alocation = NULL;
709
710 return symcount;
711}
712
dc810e39 713static void
116c20d2
NC
714versados_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
715 asymbol *symbol,
716 symbol_info *ret)
252b5132
RH
717{
718 bfd_symbol_info (symbol, ret);
719}
720
dc810e39 721static void
116c20d2
NC
722versados_print_symbol (bfd *abfd,
723 void * afile,
724 asymbol *symbol,
725 bfd_print_symbol_type how)
252b5132
RH
726{
727 FILE *file = (FILE *) afile;
116c20d2 728
252b5132
RH
729 switch (how)
730 {
731 case bfd_print_symbol_name:
732 fprintf (file, "%s", symbol->name);
733 break;
734 default:
116c20d2 735 bfd_print_symbol_vandf (abfd, (void *) file, symbol);
252b5132
RH
736 fprintf (file, " %-5s %s",
737 symbol->section->name,
738 symbol->name);
252b5132
RH
739 }
740}
741
dc810e39 742static long
116c20d2
NC
743versados_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
744 sec_ptr asect)
252b5132
RH
745{
746 return (asect->reloc_count + 1) * sizeof (arelent *);
747}
748
dc810e39 749static long
116c20d2
NC
750versados_canonicalize_reloc (bfd *abfd,
751 sec_ptr section,
752 arelent **relptr,
753 asymbol **symbols)
252b5132
RH
754{
755 unsigned int count;
756 arelent *src;
757
758 versados_pass_2 (abfd);
759 src = section->relocation;
760 if (!EDATA (abfd, section->target_index).donerel)
761 {
762 EDATA (abfd, section->target_index).donerel = 1;
116c20d2 763 /* Translate from indexes to symptr ptrs. */
252b5132
RH
764 for (count = 0; count < section->reloc_count; count++)
765 {
f60ca5e3 766 int esdid = (int) (size_t) src[count].sym_ptr_ptr;
252b5132
RH
767
768 if (esdid == 0)
116c20d2
NC
769 src[count].sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
770 else if (esdid < ES_BASE)
252b5132 771 {
116c20d2 772 /* Section relative thing. */
252b5132 773 struct esdid *e = &EDATA (abfd, esdid - 1);
116c20d2 774
252b5132
RH
775 src[count].sym_ptr_ptr = e->section->symbol_ptr_ptr;
776 }
777 else
116c20d2 778 src[count].sym_ptr_ptr = symbols + esdid - ES_BASE;
252b5132
RH
779 }
780 }
781
782 for (count = 0; count < section->reloc_count; count++)
116c20d2
NC
783 *relptr++ = src++;
784
252b5132
RH
785 *relptr = 0;
786 return section->reloc_count;
787}
788
116c20d2
NC
789#define versados_close_and_cleanup _bfd_generic_close_and_cleanup
790#define versados_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
791#define versados_new_section_hook _bfd_generic_new_section_hook
792#define versados_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
793#define versados_bfd_is_local_label_name bfd_generic_is_local_label_name
794#define versados_get_lineno _bfd_nosymbols_get_lineno
795#define versados_find_nearest_line _bfd_nosymbols_find_nearest_line
4ab527b0 796#define versados_find_inliner_info _bfd_nosymbols_find_inliner_info
116c20d2
NC
797#define versados_make_empty_symbol _bfd_generic_make_empty_symbol
798#define versados_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
799#define versados_read_minisymbols _bfd_generic_read_minisymbols
800#define versados_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
801#define versados_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
157090f7 802#define versados_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
116c20d2
NC
803#define versados_set_arch_mach bfd_default_set_arch_mach
804#define versados_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
805#define versados_bfd_relax_section bfd_generic_relax_section
806#define versados_bfd_gc_sections bfd_generic_gc_sections
807#define versados_bfd_merge_sections bfd_generic_merge_sections
808#define versados_bfd_is_group_section bfd_generic_is_group_section
809#define versados_bfd_discard_group bfd_generic_discard_group
810#define versados_section_already_linked _bfd_generic_section_already_linked
3023e3f6 811#define versados_bfd_define_common_symbol bfd_generic_define_common_symbol
116c20d2
NC
812#define versados_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
813#define versados_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
814#define versados_bfd_link_add_symbols _bfd_generic_link_add_symbols
815#define versados_bfd_link_just_syms _bfd_generic_link_just_syms
816#define versados_bfd_final_link _bfd_generic_final_link
817#define versados_bfd_link_split_section _bfd_generic_link_split_section
252b5132
RH
818
819const bfd_target versados_vec =
820{
116c20d2 821 "versados", /* Name. */
252b5132 822 bfd_target_versados_flavour,
116c20d2
NC
823 BFD_ENDIAN_BIG, /* Target byte order. */
824 BFD_ENDIAN_BIG, /* Target headers byte order. */
825 (HAS_RELOC | EXEC_P | /* Object flags. */
252b5132
RH
826 HAS_LINENO | HAS_DEBUG |
827 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
828 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
116c20d2
NC
829 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
830 0, /* Leading underscore. */
831 ' ', /* AR_pad_char. */
832 16, /* AR_max_namelen. */
252b5132
RH
833 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
834 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
116c20d2 835 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
252b5132
RH
836 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
837 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
116c20d2 838 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
252b5132
RH
839
840 {
841 _bfd_dummy_target,
116c20d2 842 versados_object_p, /* bfd_check_format. */
252b5132
RH
843 _bfd_dummy_target,
844 _bfd_dummy_target,
845 },
846 {
847 bfd_false,
848 versados_mkobject,
849 _bfd_generic_mkarchive,
850 bfd_false,
851 },
116c20d2 852 { /* bfd_write_contents. */
252b5132
RH
853 bfd_false,
854 bfd_false,
855 _bfd_write_archive_contents,
856 bfd_false,
857 },
858
859 BFD_JUMP_TABLE_GENERIC (versados),
860 BFD_JUMP_TABLE_COPY (_bfd_generic),
861 BFD_JUMP_TABLE_CORE (_bfd_nocore),
862 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
863 BFD_JUMP_TABLE_SYMBOLS (versados),
864 BFD_JUMP_TABLE_RELOCS (versados),
865 BFD_JUMP_TABLE_WRITE (versados),
866 BFD_JUMP_TABLE_LINK (versados),
867 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
868
c3c89269 869 NULL,
558e161f 870
116c20d2 871 NULL
252b5132 872};
This page took 0.598328 seconds and 4 git commands to generate.