Make all callers of malloc or realloc (including via obstacks)
[external/binutils.git] / bfd / srec.c
1 /* BFD back-end for s-record objects.
2    Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /*
22 SUBSECTION
23         S-Record handling
24
25 DESCRIPTION
26         
27         Ordinary S-Records cannot hold anything but addresses and
28         data, so that's all that we implement.
29
30         The only interesting thing is that S-Records may come out of
31         order and there is no header, so an initial scan is required
32         to discover the minimum and maximum addresses used to create
33         the vma and size of the only section we create.  We
34         arbitrarily call this section ".text".
35
36         When bfd_get_section_contents is called the file is read
37         again, and this time the data is placed into a bfd_alloc'd
38         area.
39
40         Any number of sections may be created for output, we save them
41         up and output them when it's time to close the bfd.
42
43         An s record looks like:
44         
45 EXAMPLE
46         S<type><length><address><data><checksum>
47         
48 DESCRIPTION
49         Where
50         o length
51         is the number of bytes following upto the checksum. Note that
52         this is not the number of chars following, since it takes two
53         chars to represent a byte.
54         o type
55         is one of:
56         0) header record
57         1) two byte address data record
58         2) three byte address data record
59         3) four byte address data record
60         7) four byte address termination record
61         8) three byte address termination record
62         9) two byte address termination record
63         
64         o address
65         is the start address of the data following, or in the case of
66         a termination record, the start address of the image
67         o data
68         is the data.
69         o checksum
70         is the sum of all the raw byte data in the record, from the length
71         upwards, modulo 256 and subtracted from 255.
72
73
74 SUBSECTION
75         Symbol S-Record handling
76
77 DESCRIPTION
78         Some ICE equipment understands an addition to the standard
79         S-Record format; symbols and their addresses can be sent
80         before the data.
81
82         The format of this is:
83         ($$ <modulename>
84                 (<space> <symbol> <address>)*)
85         $$
86
87         so a short symbol table could look like:
88
89 EXAMPLE
90         $$ flash.x
91         $$ flash.c
92           _port6 $0
93           _delay $4
94           _start $14
95           _etext $8036
96           _edata $8036
97           _end $8036
98         $$
99
100 DESCRIPTION
101         We allow symbols to be anywhere in the data stream - the module names
102         are always ignored.
103                 
104 */
105
106 #include "bfd.h"
107 #include "sysdep.h"
108 #include "libbfd.h"
109
110 /* Macros for converting between hex and binary */
111
112 static CONST char digs[] = "0123456789ABCDEF";
113
114 static char hex_value[1 + (unsigned char) ~0];
115
116 #define NOT_HEX 20
117 #define NIBBLE(x) hex_value[(unsigned char)(x)]
118 #define HEX(buffer) ((NIBBLE((buffer)[0])<<4) + NIBBLE((buffer)[1]))
119 #define TOHEX(d, x, ch) \
120         d[1] = digs[(x) & 0xf]; \
121         d[0] = digs[((x)>>4)&0xf]; \
122         ch += ((x) & 0xff);
123 #define ISHEX(x)  (hex_value[(unsigned char)(x)] != NOT_HEX)
124
125
126
127 static void
128 DEFUN_VOID (srec_init)
129 {
130   unsigned int i;
131   static boolean inited = false;
132
133   if (inited == false)
134     {
135
136       inited = true;
137
138       for (i = 0; i < sizeof (hex_value); i++)
139         {
140           hex_value[i] = NOT_HEX;
141         }
142
143       for (i = 0; i < 10; i++)
144         {
145           hex_value[i + '0'] = i;
146
147         }
148       for (i = 0; i < 6; i++)
149         {
150           hex_value[i + 'a'] = i + 10;
151           hex_value[i + 'A'] = i + 10;
152         }
153     }
154 }
155
156
157 /* The maximum number of bytes on a line is FF */
158 #define MAXCHUNK 0xff
159 /* The number of bytes we fit onto a line on output */
160 #define CHUNK 21
161
162 /* We cannot output our srecords as we see them, we have to glue them
163    together, this is done in this structure : */
164
165 struct srec_data_list_struct
166 {
167   unsigned char *data;
168   bfd_vma where;
169   bfd_size_type size;
170   struct srec_data_list_struct *next;
171
172
173 };
174 typedef struct srec_data_list_struct srec_data_list_type;
175
176
177 typedef struct srec_data_struct
178   {
179     srec_data_list_type *head;
180     unsigned int type;
181
182     int done_symbol_read;
183     int count;
184     asymbol *symbols;
185     char *strings;
186     int symbol_idx;
187     int string_size;
188     int string_idx;
189   }
190 tdata_type;
191
192
193 /*
194    called once per input S-Record, used to work out vma and size of data.
195  */
196
197 static bfd_vma low, high;
198
199 /*ARGSUSED*/
200 static void
201 size_symbols (abfd, buf, len, val)
202      bfd *abfd;
203      char *buf;
204      int len;
205      int val;
206 {
207   abfd->symcount++;
208   abfd->tdata.srec_data->string_size += len + 1;
209 }
210
211 static void
212 fillup_symbols (abfd, buf, len, val)
213      bfd *abfd;
214      char *buf;
215      int len;
216      int val;
217 {
218   if (!abfd->tdata.srec_data->done_symbol_read)
219     {
220       asymbol *p;
221       if (abfd->tdata.srec_data->symbols == 0)
222         {
223           abfd->tdata.srec_data->symbols = (asymbol *) bfd_alloc (abfd, abfd->symcount * sizeof (asymbol));
224           abfd->tdata.srec_data->strings = (char *) bfd_alloc (abfd, abfd->tdata.srec_data->string_size);
225           if (!abfd->tdata.srec_data->symbols || !abfd->tdata.srec_data->strings)
226             {
227               bfd_error = no_memory;
228               abort ();         /* FIXME */
229             }
230           abfd->tdata.srec_data->symbol_idx = 0;
231           abfd->tdata.srec_data->string_idx = 0;
232         }
233
234       p = abfd->tdata.srec_data->symbols + abfd->tdata.srec_data->symbol_idx++;
235       p->the_bfd = abfd;
236       p->name = abfd->tdata.srec_data->strings + abfd->tdata.srec_data->string_idx;
237       memcpy ((char *) (p->name), buf, len + 1);
238       abfd->tdata.srec_data->string_idx += len + 1;
239       p->value = val;
240       p->flags = BSF_EXPORT | BSF_GLOBAL;
241       p->section = &bfd_abs_section;
242       p->udata = 0;
243     }
244 }
245 /*ARGSUSED*/
246 static void
247 DEFUN (size_srec, (abfd, section, address, raw, length),
248        bfd * abfd AND
249        asection * section AND
250        bfd_vma address AND
251        bfd_byte * raw AND
252        unsigned int length)
253 {
254   if (address < low)
255     low = address;
256   if (address + length > high)
257     high = address + length - 1;
258 }
259
260
261 /*
262  called once per input S-Record, copies data from input into bfd_alloc'd area
263  */
264
265 /*ARGSUSED*/
266 static void
267 DEFUN (fillup, (abfd, section, address, raw, length),
268        bfd * abfd AND
269        asection * section AND
270        bfd_vma address AND
271        bfd_byte * raw AND
272        unsigned int length)
273 {
274   unsigned int i;
275   bfd_byte *dst =
276   (bfd_byte *) (section->used_by_bfd) + address - section->vma;
277   /* length -1 because we don't read in the checksum */
278   for (i = 0; i < length - 1; i++)
279     {
280       *dst = HEX (raw);
281       dst++;
282       raw += 2;
283     }
284 }
285
286 /* Pass over an S-Record file, calling one of the above functions on each
287    record.  */
288
289 static int 
290 white (x)
291      char x;
292 {
293   return (x == ' ' || x == '\t' || x == '\n' || x == '\r');
294 }
295 static int
296 skipwhite (src, abfd)
297      char *src;
298      bfd *abfd;
299 {
300   int eof = 0;
301   while (white (*src) && !eof)
302     {
303       eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
304     }
305   return eof;
306 }
307
308 static boolean
309 DEFUN (srec_mkobject, (abfd),
310        bfd * abfd)
311 {
312   if (abfd->tdata.srec_data == 0)
313     {
314       tdata_type *tdata = (tdata_type *) bfd_alloc (abfd, sizeof (tdata_type));
315       if (!tdata)
316         {
317           bfd_error = no_memory;
318           return false;
319         }
320       abfd->tdata.srec_data = tdata;
321       tdata->type = 1;
322       tdata->head = (srec_data_list_type *) NULL;
323     }
324   return true;
325
326 }
327
328 static void 
329 pass_over (abfd, func, symbolfunc, section)
330      bfd *abfd;
331      void (*func) ();
332      void (*symbolfunc) ();
333      asection *section;
334 {
335   unsigned int bytes_on_line;
336   boolean eof = false;
337
338   srec_mkobject (abfd);
339   /* To the front of the file */
340   bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
341   while (eof == false)
342     {
343       char buffer[MAXCHUNK];
344       char *src = buffer;
345       char type;
346       bfd_vma address = 0;
347
348       /* Find first 'S' or $ */
349       eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
350       switch (*src)
351         {
352         default:
353           eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
354           if (eof)
355             return;
356           break;
357
358         case '$':
359           /* Inside a symbol definition - just ignore the module name */
360           while (*src != '\n' && !eof)
361             {
362               eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
363             }
364           break;
365
366         case ' ':
367           /* spaces - maybe just before a symbol */
368           while (*src != '\n' && *src != '\r' && white (*src))
369             {
370               eof = skipwhite (src, abfd);
371
372               {
373                 int val = 0;
374                 int slen = 0;
375                 char symbol[MAXCHUNK];
376
377                 /* get the symbol part */
378                 while (!eof && !white (*src) && slen < MAXCHUNK)
379                   {
380                     symbol[slen++] = *src;
381                     eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
382                   }
383                 symbol[slen] = 0;
384                 eof = skipwhite (src, abfd);
385                 /* skip the $ for the hex value */
386                 if (*src == '$')
387                   {
388                     eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
389                   }
390
391                 /* Scan off the hex number */
392                 while (isxdigit (*src))
393                   {
394                     val *= 16;
395                     if (isdigit (*src))
396                       val += *src - '0';
397                     else if (isupper (*src))
398                       {
399                         val += *src - 'A' + 10;
400                       }
401                     else
402                       {
403                         val += *src - 'a' + 10;
404                       }
405                     eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
406                   }
407                 symbolfunc (abfd, symbol, slen, val);
408               }
409             }
410           break;
411         case 'S':
412           src++;
413
414           /* Fetch the type and the length */
415           bfd_read (src, 1, 3, abfd);
416
417           type = *src++;
418
419           if (!ISHEX (src[0]) || !ISHEX (src[1]))
420             break;
421
422           bytes_on_line = HEX (src);
423
424           if (bytes_on_line > MAXCHUNK / 2)
425             break;
426           src += 2;
427
428           bfd_read (src, 1, bytes_on_line * 2, abfd);
429
430           switch (type)
431             {
432             case '0':
433             case '5':
434               /* Prologue - ignore */
435               break;
436             case '3':
437               address = HEX (src);
438               src += 2;
439               bytes_on_line--;
440
441             case '2':
442               address = HEX (src) | (address << 8);
443               src += 2;
444               bytes_on_line--;
445             case '1':
446               address = HEX (src) | (address << 8);
447               src += 2;
448               address = HEX (src) | (address << 8);
449               src += 2;
450               bytes_on_line -= 2;
451               func (abfd, section, address, src, bytes_on_line);
452               break;
453             default:
454               return;
455             }
456         }
457     }
458
459 }
460
461 static bfd_target *
462 object_p (abfd)
463      bfd *abfd;
464 {
465   asection *section;
466   /* We create one section called .text for all the contents,
467      and allocate enough room for the entire file.  */
468
469   section = bfd_make_section (abfd, ".text");
470   section->_raw_size = 0;
471   section->vma = 0xffffffff;
472   low = 0xffffffff;
473   high = 0;
474   pass_over (abfd, size_srec, size_symbols, section);
475   section->_raw_size = high - low;
476   section->vma = low;
477   section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
478
479   if (abfd->symcount)
480     abfd->flags |= HAS_SYMS;
481   return abfd->xvec;
482 }
483
484 static bfd_target *
485 DEFUN (srec_object_p, (abfd),
486        bfd * abfd)
487 {
488   char b[4];
489
490   srec_init ();
491
492   bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
493   bfd_read (b, 1, 4, abfd);
494
495   if (b[0] != 'S' || !ISHEX (b[1]) || !ISHEX (b[2]) || !ISHEX (b[3]))
496     return (bfd_target *) NULL;
497
498   /* We create one section called .text for all the contents,
499      and allocate enough room for the entire file.  */
500
501   return object_p (abfd);
502 }
503
504
505 static bfd_target *
506 DEFUN (symbolsrec_object_p, (abfd),
507        bfd * abfd)
508 {
509   char b[4];
510
511   srec_init ();
512
513   bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
514   bfd_read (b, 1, 4, abfd);
515
516   if (b[0] != '$' || b[1] != '$')
517     return (bfd_target *) NULL;
518
519   return object_p (abfd);
520 }
521
522
523 static boolean
524 DEFUN (srec_get_section_contents, (abfd, section, location, offset, count),
525        bfd * abfd AND
526        asection * section AND
527        PTR location AND
528        file_ptr offset AND
529        bfd_size_type count)
530 {
531   if (section->used_by_bfd == (PTR) NULL)
532     {
533       section->used_by_bfd = (PTR) bfd_alloc (abfd, section->_raw_size);
534       if (!section->used_by_bfd)
535         {
536           bfd_error = no_memory;
537           return false;
538         }
539
540       pass_over (abfd, fillup, fillup_symbols, section);
541     }
542   memcpy ((PTR) location,
543                  (PTR) ((char *) (section->used_by_bfd) + offset),
544                  count);
545   return true;
546 }
547
548
549
550 boolean
551 DEFUN (srec_set_arch_mach, (abfd, arch, machine),
552        bfd * abfd AND
553        enum bfd_architecture arch AND
554        unsigned long machine)
555 {
556   return bfd_default_set_arch_mach (abfd, arch, machine);
557 }
558
559
560 /* we have to save up all the Srecords for a splurge before output,
561    also remember   */
562
563 static boolean
564 DEFUN (srec_set_section_contents, (abfd, section, location, offset, bytes_to_do),
565        bfd * abfd AND
566        sec_ptr section AND
567        PTR location AND
568        file_ptr offset AND
569        bfd_size_type bytes_to_do)
570 {
571   tdata_type *tdata = abfd->tdata.srec_data;
572   srec_data_list_type *entry = (srec_data_list_type *)
573     bfd_alloc (abfd, sizeof (srec_data_list_type));
574
575   if (!entry)
576     {
577       bfd_error = no_memory;
578       return false;
579     }
580
581   if ((section->flags & SEC_ALLOC)
582       && (section->flags & SEC_LOAD))
583     {
584       unsigned char *data = (unsigned char *) bfd_alloc (abfd, bytes_to_do);
585       if (!data)
586         {
587           bfd_error = no_memory;
588           return false;
589         }
590       memcpy (data, location, bytes_to_do);
591
592       if ((section->lma + offset + bytes_to_do) <= 0xffff)
593         {
594
595         }
596       else if ((section->lma + offset + bytes_to_do) <= 0xffffff
597                && tdata->type < 2)
598         {
599           tdata->type = 2;
600         }
601       else
602         {
603           tdata->type = 3;
604         }
605
606       entry->data = data;
607       entry->where = section->lma + offset;
608       entry->size = bytes_to_do;
609       entry->next = tdata->head;
610       tdata->head = entry;
611     }
612   return true;
613 }
614
615 /* Write a record of type, of the supplied number of bytes. The
616    supplied bytes and length don't have a checksum. That's worked out
617    here
618 */
619 static
620 void 
621 DEFUN (srec_write_record, (abfd, type, address, data, end),
622        bfd * abfd AND
623        char type AND
624        bfd_vma address AND
625        CONST unsigned char *data AND
626        CONST unsigned char *end)
627
628 {
629   char buffer[MAXCHUNK];
630
631   unsigned int check_sum = 0;
632   CONST unsigned char *src = data;
633   char *dst = buffer;
634   char *length;
635
636
637   *dst++ = 'S';
638   *dst++ = '0' + type;
639
640   length = dst;
641   dst += 2;                     /* leave room for dst*/
642
643   switch (type)
644     {
645     case 3:
646     case 7:
647       TOHEX (dst, (address >> 24), check_sum);
648       dst += 2;
649     case 8:
650     case 2:
651       TOHEX (dst, (address >> 16), check_sum);
652       dst += 2;
653     case 9:
654     case 1:
655     case 0:
656       TOHEX (dst, (address >> 8), check_sum);
657       dst += 2;
658       TOHEX (dst, (address), check_sum);
659       dst += 2;
660       break;
661
662     }
663   for (src = data; src < end; src++)
664     {
665       TOHEX (dst, *src, check_sum);
666       dst += 2;
667     }
668
669   /* Fill in the length */
670   TOHEX (length, (dst - length) / 2, check_sum);
671   check_sum &= 0xff;
672   check_sum = 255 - check_sum;
673   TOHEX (dst, check_sum, check_sum);
674   dst += 2;
675
676   *dst++ = '\r';
677   *dst++ = '\n';
678   bfd_write ((PTR) buffer, 1, dst - buffer, abfd);
679 }
680
681
682
683 static void
684 DEFUN (srec_write_header, (abfd),
685        bfd * abfd)
686 {
687   unsigned char buffer[MAXCHUNK];
688   unsigned char *dst = buffer;
689   unsigned int i;
690
691   /* I'll put an arbitary 40 char limit on header size */
692   for (i = 0; i < 40 && abfd->filename[i]; i++)
693     {
694       *dst++ = abfd->filename[i];
695     }
696   srec_write_record (abfd, 0, 0, buffer, dst);
697 }
698
699 static void
700 DEFUN (srec_write_section, (abfd, tdata, list),
701        bfd * abfd AND
702        tdata_type * tdata AND
703        srec_data_list_type * list)
704 {
705   unsigned int bytes_written = 0;
706   unsigned char *location = list->data;
707
708   while (bytes_written < list->size)
709     {
710       bfd_vma address;
711
712       unsigned int bytes_this_chunk = list->size - bytes_written;
713
714       if (bytes_this_chunk > CHUNK)
715         {
716           bytes_this_chunk = CHUNK;
717         }
718
719       address = list->where + bytes_written;
720
721       srec_write_record (abfd,
722                          tdata->type,
723                          address,
724                          location,
725                          location + bytes_this_chunk);
726
727       bytes_written += bytes_this_chunk;
728       location += bytes_this_chunk;
729     }
730
731 }
732
733 static void
734 DEFUN (srec_write_terminator, (abfd, tdata),
735        bfd * abfd AND
736        tdata_type * tdata)
737 {
738   unsigned char buffer[2];
739
740   srec_write_record (abfd, 10 - tdata->type,
741                      abfd->start_address, buffer, buffer);
742 }
743
744
745
746 static void
747 srec_write_symbols (abfd)
748      bfd *abfd;
749 {
750   char buffer[MAXCHUNK];
751   /* Dump out the symbols of a bfd */
752   int i;
753   int len = bfd_get_symcount (abfd);
754
755   if (len)
756     {
757       asymbol **table = bfd_get_outsymbols (abfd);
758       sprintf (buffer, "$$ %s\r\n", abfd->filename);
759
760       bfd_write (buffer, strlen (buffer), 1, abfd);
761
762       for (i = 0; i < len; i++)
763         {
764           asymbol *s = table[i];
765 #if 0
766           int len = strlen (s->name);
767
768           /* If this symbol has a .[ocs] in it, it's probably a file name
769          and we'll output that as the module name */
770
771           if (len > 3 && s->name[len - 2] == '.')
772             {
773               int l;
774               sprintf (buffer, "$$ %s\r\n", s->name);
775               l = strlen (buffer);
776               bfd_write (buffer, l, 1, abfd);
777             }
778           else
779 #endif
780             if (s->flags & (BSF_GLOBAL | BSF_LOCAL)
781                 && (s->flags & BSF_DEBUGGING) == 0
782                 && s->name[0] != '.'
783                 && s->name[0] != 't')
784             {
785               /* Just dump out non debug symbols */
786
787               int l;
788               char buf2[40], *p;
789
790               sprintf_vma (buf2,
791                            s->value + s->section->output_section->lma
792                            + s->section->output_offset);
793               p = buf2;
794               while (p[0] == '0' && p[1] != 0)
795                 p++;
796               sprintf (buffer, "  %s $%s\r\n", s->name, p);
797               l = strlen (buffer);
798               bfd_write (buffer, l, 1, abfd);
799             }
800         }
801       sprintf (buffer, "$$ \r\n");
802       bfd_write (buffer, strlen (buffer), 1, abfd);
803     }
804 }
805
806 static boolean
807 internal_srec_write_object_contents (abfd, symbols)
808      bfd *abfd;
809      int symbols;
810 {
811   tdata_type *tdata = abfd->tdata.srec_data;
812   srec_data_list_type *list;
813
814   if (symbols)
815     srec_write_symbols (abfd);
816
817   srec_write_header (abfd);
818
819   /* Now wander though all the sections provided and output them */
820   list = tdata->head;
821
822   while (list != (srec_data_list_type *) NULL)
823     {
824       srec_write_section (abfd, tdata, list);
825       list = list->next;
826     }
827   srec_write_terminator (abfd, tdata);
828   return true;
829 }
830
831 static boolean
832 srec_write_object_contents (abfd)
833      bfd *abfd;
834 {
835   return internal_srec_write_object_contents (abfd, 0);
836 }
837
838 static boolean
839 symbolsrec_write_object_contents (abfd)
840      bfd *abfd;
841 {
842   return internal_srec_write_object_contents (abfd, 1);
843 }
844
845 /*ARGSUSED*/
846 static int
847 DEFUN (srec_sizeof_headers, (abfd, exec),
848        bfd * abfd AND
849        boolean exec)
850 {
851   return 0;
852 }
853
854 static asymbol *
855 DEFUN (srec_make_empty_symbol, (abfd),
856        bfd * abfd)
857 {
858   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
859   if (new)
860     new->the_bfd = abfd;
861   return new;
862 }
863
864 static unsigned int
865 srec_get_symtab_upper_bound (abfd)
866      bfd *abfd;
867 {
868   /* Read in all the info */
869   srec_get_section_contents (abfd, abfd->sections, 0, 0, 0);
870   return (bfd_get_symcount (abfd) + 1) * (sizeof (asymbol *));
871 }
872
873 static unsigned int
874 DEFUN (srec_get_symtab, (abfd, alocation),
875        bfd * abfd AND
876        asymbol ** alocation)
877 {
878   int lim = abfd->symcount;
879   int i;
880   for (i = 0; i < lim; i++)
881     {
882       alocation[i] = abfd->tdata.srec_data->symbols + i;
883     }
884   alocation[i] = 0;
885   return lim;
886 }
887
888 /*ARGSUSED*/
889 void
890 DEFUN (srec_get_symbol_info, (ignore_abfd, symbol, ret),
891        bfd * ignore_abfd AND
892        asymbol * symbol AND
893        symbol_info * ret)
894 {
895   bfd_symbol_info (symbol, ret);
896 }
897
898 /*ARGSUSED*/
899 void
900 DEFUN (srec_print_symbol, (ignore_abfd, afile, symbol, how),
901        bfd * ignore_abfd AND
902        PTR afile AND
903        asymbol * symbol AND
904        bfd_print_symbol_type how)
905 {
906   FILE *file = (FILE *) afile;
907   switch (how)
908     {
909     case bfd_print_symbol_name:
910       fprintf (file, "%s", symbol->name);
911       break;
912     default:
913       bfd_print_symbol_vandf ((PTR) file, symbol);
914       fprintf (file, " %-5s %s",
915                symbol->section->name,
916                symbol->name);
917
918     }
919 }
920
921 #define FOO PROTO
922 #define srec_new_section_hook (FOO(boolean, (*), (bfd *, asection *)))bfd_true
923
924 #define srec_get_reloc_upper_bound (FOO(unsigned int, (*),(bfd*, asection *)))bfd_false
925 #define srec_canonicalize_reloc (FOO(unsigned int, (*),(bfd*,asection *, arelent **, asymbol **))) bfd_0
926
927
928
929 #define srec_openr_next_archived_file (FOO(bfd *, (*), (bfd*,bfd*))) bfd_nullvoidptr
930 #define srec_find_nearest_line (FOO(boolean, (*),(bfd*,asection*,asymbol**,bfd_vma, CONST char**, CONST char**, unsigned int *))) bfd_false
931 #define srec_generic_stat_arch_elt  (FOO(int, (*), (bfd *,struct stat *))) bfd_0
932
933
934 #define srec_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
935 #define srec_core_file_failing_signal (int (*)())bfd_0
936 #define srec_core_file_matches_executable_p (FOO(boolean, (*),(bfd*, bfd*)))bfd_false
937 #define srec_slurp_armap bfd_true
938 #define srec_slurp_extended_name_table bfd_true
939 #define srec_truncate_arname (void (*)())bfd_nullvoidptr
940 #define srec_write_armap  (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
941 #define srec_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
942 #define srec_close_and_cleanup  bfd_generic_close_and_cleanup
943 #define srec_bfd_debug_info_start bfd_void
944 #define srec_bfd_debug_info_end bfd_void
945 #define srec_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *,  asection *))) bfd_void
946 #define srec_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
947 #define srec_bfd_relax_section bfd_generic_relax_section
948 #define srec_bfd_reloc_type_lookup \
949   ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
950 #define srec_bfd_make_debug_symbol \
951   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
952 #define srec_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
953 #define srec_bfd_link_add_symbols _bfd_generic_link_add_symbols
954 #define srec_bfd_final_link _bfd_generic_final_link
955
956 bfd_target srec_vec =
957 {
958   "srec",                       /* name */
959   bfd_target_srec_flavour,
960   true,                         /* target byte order */
961   true,                         /* target headers byte order */
962   (HAS_RELOC | EXEC_P |         /* object flags */
963    HAS_LINENO | HAS_DEBUG |
964    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
965   (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
966    | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
967   0,                            /* leading underscore */
968   ' ',                          /* ar_pad_char */
969   16,                           /* ar_max_namelen */
970   1,                            /* minimum alignment */
971   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
972   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
973   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* data */
974   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
975   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
976   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* hdrs */
977
978   {
979     _bfd_dummy_target,
980     srec_object_p,              /* bfd_check_format */
981     (struct bfd_target * (*)()) bfd_nullvoidptr,
982     (struct bfd_target * (*)()) bfd_nullvoidptr,
983   },
984   {
985     bfd_false,
986     srec_mkobject,
987     _bfd_generic_mkarchive,
988     bfd_false,
989   },
990   {                             /* bfd_write_contents */
991     bfd_false,
992     srec_write_object_contents,
993     _bfd_write_archive_contents,
994     bfd_false,
995   },
996   JUMP_TABLE (srec)
997 };
998
999
1000
1001 bfd_target symbolsrec_vec =
1002 {
1003   "symbolsrec",                 /* name */
1004   bfd_target_srec_flavour,
1005   true,                         /* target byte order */
1006   true,                         /* target headers byte order */
1007   (HAS_RELOC | EXEC_P |         /* object flags */
1008    HAS_LINENO | HAS_DEBUG |
1009    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1010   (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
1011    | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1012   0,                            /* leading underscore */
1013   ' ',                          /* ar_pad_char */
1014   16,                           /* ar_max_namelen */
1015   1,                            /* minimum alignment */
1016   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1017   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1018   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* data */
1019   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1020   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1021   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* hdrs */
1022
1023   {
1024     _bfd_dummy_target,
1025     symbolsrec_object_p,        /* bfd_check_format */
1026     (struct bfd_target * (*)()) bfd_nullvoidptr,
1027     (struct bfd_target * (*)()) bfd_nullvoidptr,
1028   },
1029   {
1030     bfd_false,
1031     srec_mkobject,
1032     _bfd_generic_mkarchive,
1033     bfd_false,
1034   },
1035   {                             /* bfd_write_contents */
1036     bfd_false,
1037     symbolsrec_write_object_contents,
1038     _bfd_write_archive_contents,
1039     bfd_false,
1040   },
1041   JUMP_TABLE (srec),
1042   (PTR) 0
1043 };