(srec_write_symbols): Use sprintf_vma, in case bfd_vma is too wide for
[external/binutils.git] / bfd / srec.c
1 /* BFD back-end for s-record objects.
2    Copyright 1990, 1991, 1992, 1993 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 } tdata_type;
190
191
192 /* 
193    called once per input S-Record, used to work out vma and size of data.
194  */
195
196 static bfd_vma low,high;
197
198 static void
199 size_symbols(abfd, buf, len, val)
200 bfd *abfd;
201 char *buf;
202 int len;
203 int val;
204 {
205   abfd->symcount ++;
206   abfd->tdata.srec_data->string_size  += len + 1;
207 }
208
209 static void
210 fillup_symbols(abfd, buf, len, val)
211 bfd *abfd;
212 char *buf;
213 int len;
214 int val;
215 {
216   if (!abfd->tdata.srec_data->done_symbol_read)
217   {
218     asymbol *p;
219     if (abfd->tdata.srec_data->symbols == 0)
220     {
221       abfd->tdata.srec_data->symbols = (asymbol *)bfd_alloc(abfd, abfd->symcount * sizeof(asymbol));
222       abfd->tdata.srec_data->strings = (char*)bfd_alloc(abfd, abfd->tdata.srec_data->string_size);
223       abfd->tdata.srec_data->symbol_idx = 0;
224       abfd->tdata.srec_data->string_idx = 0;
225     }
226
227     p = abfd->tdata.srec_data->symbols + abfd->tdata.srec_data->symbol_idx++;
228     p->the_bfd = abfd;
229     p->name = abfd->tdata.srec_data->strings + abfd->tdata.srec_data->string_idx;
230     memcpy((char *)(p->name), buf, len+1);
231     abfd->tdata.srec_data->string_idx += len + 1;
232     p->value = val;
233     p->flags = BSF_EXPORT | BSF_GLOBAL;
234     p->section = &bfd_abs_section;
235     p->udata = 0;
236   }
237 }
238 static void
239 DEFUN(size_srec,(abfd, section, address, raw, length),
240       bfd *abfd AND
241       asection *section AND
242       bfd_vma address AND
243       bfd_byte *raw AND
244       unsigned int length)
245 {
246   if (address < low)
247     low = address;
248   if (address + length > high) 
249     high = address + length -1;
250 }
251
252
253 /*
254  called once per input S-Record, copies data from input into bfd_alloc'd area
255  */
256
257 static void
258 DEFUN(fillup,(abfd, section, address, raw, length),
259 bfd *abfd AND
260 asection *section AND
261 bfd_vma address AND
262 bfd_byte *raw AND
263 unsigned int length)
264 {
265     unsigned int i;
266     bfd_byte *dst =
267      (bfd_byte *)(section->used_by_bfd) + address - section->vma;
268     /* length -1 because we don't read in the checksum */
269     for (i = 0; i < length -1 ; i++) {
270             *dst = HEX(raw);
271             dst++;
272             raw+=2;
273         }
274 }
275
276 /* Pass over an S-Record file, calling one of the above functions on each
277    record.  */
278
279 static int white(x)
280 char x;
281 {
282 return (x== ' ' || x == '\t' || x == '\n' || x == '\r');
283 }
284 static int
285 skipwhite(src,abfd)
286 char *src;
287 bfd *abfd;
288 {
289   int eof = 0;
290   while (white(*src) && !eof)
291   {
292     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);     
293   }
294   return eof;
295 }
296
297 static boolean
298 DEFUN(srec_mkobject, (abfd), 
299       bfd *abfd)
300 {
301   if (abfd->tdata.srec_data == 0) 
302   {
303     tdata_type *tdata = (tdata_type *)bfd_alloc(abfd,  sizeof(tdata_type));
304     abfd->tdata.srec_data = tdata;
305     tdata->type = 1;
306     tdata->head = (srec_data_list_type *)NULL;
307   }
308   return true;
309     
310 }
311
312 static void
313 DEFUN(pass_over,(abfd, func, symbolfunc, section),
314       bfd *abfd AND
315       void (*func)() AND
316       void (*symbolfunc)() AND
317       asection *section)
318 {
319   unsigned int bytes_on_line;
320   boolean eof = false;
321
322   srec_mkobject(abfd);
323   /* To the front of the file */
324   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
325   while (eof == false)
326   {
327     char buffer[MAXCHUNK];
328     char *src = buffer;
329     char type;
330     bfd_vma address = 0;
331
332     /* Find first 'S' or $ */
333     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
334     switch (*src) 
335     {
336      default:
337       eof = (boolean)(bfd_read(src, 1, 1, abfd) != 1);
338       if (eof)  return;
339       break;
340
341      case '$':
342       /* Inside a symbol definition - just ignore the module name */
343       while (*src != '\n' && !eof) 
344       {
345         eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);         
346       }
347       break;
348
349      case ' ':
350       /* spaces - maybe just before a symbol */
351       while (*src != '\n' && white(*src)) {
352       eof = skipwhite(src, abfd);
353
354 {
355         int val = 0;
356         int slen = 0;
357         char symbol[MAXCHUNK];
358
359         /* get the symbol part */
360         while (!eof && !white(*src) && slen < MAXCHUNK)
361         {
362           symbol[slen++] = *src;
363           eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);       
364         }
365         symbol[slen] = 0;
366         eof = skipwhite(src, abfd);
367         /* skip the $ for the hex value */
368         if (*src == '$') 
369         {
370           eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
371         }
372
373         /* Scan off the hex number */
374         while (isxdigit(*src ))
375         {
376           val *= 16;
377           if (isdigit(*src))
378            val += *src - '0';
379           else if (isupper(*src)) {
380             val += *src - 'A' + 10;
381           }
382           else {
383             val += *src - 'a' + 10;
384           }
385           eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
386         }
387         symbolfunc(abfd, symbol, slen, val);
388       }
389 }
390       break;
391      case 'S':
392       src++;
393
394       /* Fetch the type and the length */
395       bfd_read(src, 1, 3, abfd);
396
397       type = *src++;
398
399       if (!ISHEX (src[0]) || !ISHEX (src[1]))
400        break;
401
402       bytes_on_line = HEX(src);
403
404       if (bytes_on_line > MAXCHUNK/2)
405        break;
406       src+=2 ;
407
408       bfd_read(src, 1 , bytes_on_line * 2, abfd);
409
410       switch (type) {
411        case '0':
412        case '5':
413         /* Prologue - ignore */
414         break;
415        case '3':
416         address = HEX(src);
417         src+=2;
418         bytes_on_line--;
419                 
420        case '2':
421         address = HEX(src) | (address<<8) ;
422         src+=2;
423         bytes_on_line--;
424        case '1':
425         address = HEX(src) | (address<<8) ;
426         src+=2;
427         address = HEX(src) | (address<<8) ;
428         src+=2;
429         bytes_on_line-=2;
430         func(abfd,section, address, src, bytes_on_line);
431         break;
432        default:
433         return;
434       }
435     }
436   }
437
438 }
439
440 static bfd_target *
441 object_p(abfd)
442 bfd *abfd;
443 {
444   asection *section;
445   /* We create one section called .text for all the contents, 
446      and allocate enough room for the entire file.  */
447   
448   section =  bfd_make_section(abfd, ".text");
449   section->_raw_size = 0;
450   section->vma = 0xffffffff;
451   low = 0xffffffff;
452   high = 0;
453   pass_over(abfd, size_srec, size_symbols, section);
454   section->_raw_size = high - low;
455   section->vma = low;
456   section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
457
458   if (abfd->symcount)
459    abfd->flags |= HAS_SYMS;  
460   return abfd->xvec;
461 }
462
463 static bfd_target *
464 DEFUN(srec_object_p, (abfd),
465       bfd *abfd)
466 {
467   char b[4];
468
469   srec_init();
470   
471   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
472   bfd_read(b, 1, 4, abfd);
473
474   if (b[0] != 'S' || !ISHEX(b[1]) || !ISHEX(b[2]) || !ISHEX(b[3]))
475    return (bfd_target*) NULL;
476   
477   /* We create one section called .text for all the contents, 
478      and allocate enough room for the entire file.  */
479
480   return object_p(abfd); 
481 }
482
483
484 static bfd_target *
485 DEFUN(symbolsrec_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] != '$' || b[1] != '$')
496     return (bfd_target*) NULL;
497
498   return object_p(abfd);   
499 }
500
501
502 static boolean
503 DEFUN(srec_get_section_contents,(abfd, section, location, offset, count),
504       bfd *abfd AND
505       asection *section AND
506       PTR location AND
507       file_ptr offset AND
508       bfd_size_type count)
509 {
510     if (section->used_by_bfd == (PTR)NULL) 
511     {
512         section->used_by_bfd = (PTR)bfd_alloc (abfd, section->_raw_size);
513         
514         pass_over(abfd, fillup, fillup_symbols, section);
515     }
516     (void) memcpy((PTR)location,
517                   (PTR)((char *)(section->used_by_bfd) + offset),
518                   count);
519     return true;
520 }
521       
522
523
524 boolean
525 DEFUN(srec_set_arch_mach,(abfd, arch, machine),
526       bfd *abfd AND
527       enum bfd_architecture arch AND
528       unsigned long machine)
529 {
530   return bfd_default_set_arch_mach(abfd, arch, machine);
531 }
532
533
534 /* we have to save up all the Srecords for a splurge before output,
535    also remember   */
536
537 static boolean
538 DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do),
539       bfd *abfd AND
540       sec_ptr section AND
541       PTR location AND
542       file_ptr offset AND
543       bfd_size_type bytes_to_do)
544 {
545   tdata_type  *tdata = abfd->tdata.srec_data;
546   srec_data_list_type *entry = (srec_data_list_type *)
547     bfd_alloc(abfd, sizeof(srec_data_list_type));
548
549   if ((section->flags & SEC_ALLOC)
550       && (section->flags & SEC_LOAD)) 
551     {
552       unsigned  char *data = (unsigned char *) bfd_alloc(abfd, bytes_to_do);
553       memcpy(data, location, bytes_to_do);
554
555       if ((section->lma + offset + bytes_to_do) <= 0xffff)  
556         {
557
558         }
559       else if ((section->lma + offset + bytes_to_do) <= 0xffffff 
560                && tdata->type < 2) 
561         {
562           tdata->type = 2;
563         }
564       else 
565         {
566           tdata->type = 3;
567         }
568
569       entry->data = data;
570       entry->where = section->lma + offset;
571       entry->size = bytes_to_do;
572       entry->next = tdata->head;
573       tdata->head = entry;
574     }
575   return true;    
576 }
577
578 /* Write a record of type, of the supplied number of bytes. The
579    supplied bytes and length don't have a checksum. That's worked out
580    here
581 */
582 static
583 void DEFUN(srec_write_record,(abfd, type, address, data, end),
584            bfd *abfd AND
585            char type AND
586            bfd_vma address AND
587            CONST unsigned char *data AND
588            CONST unsigned char *end)
589
590 {
591     char buffer[MAXCHUNK];
592     
593     unsigned int check_sum = 0;
594     unsigned CONST char *src = data;
595     char *dst =buffer;
596     char *length;
597     
598
599     *dst++ = 'S';
600     *dst++ = '0' + type;
601
602     length = dst;
603     dst+=2;                     /* leave room for dst*/
604     
605     switch (type) 
606     {
607       case 3:
608       case 7:
609         TOHEX(dst, (address >> 24), check_sum);
610         dst+=2;
611       case 8:
612       case 2:
613         TOHEX(dst, (address >> 16), check_sum);
614         dst+=2;
615       case 9:
616       case 1:
617       case 0:
618         TOHEX(dst, (address >> 8), check_sum);
619         dst+=2;
620         TOHEX(dst, (address), check_sum);
621         dst+=2;
622         break;
623
624     }
625     for (src = data; src < end; src++) 
626     {
627         TOHEX(dst, *src, check_sum);
628         dst+=2;
629     }
630
631     /* Fill in the length */
632     TOHEX(length, (dst - length)/2, check_sum);
633     check_sum &= 0xff;
634     check_sum = 255 - check_sum;
635     TOHEX(dst, check_sum, check_sum);
636     dst+=2;
637     
638     *dst ++ = '\r';
639     *dst ++ = '\n';
640     bfd_write((PTR)buffer, 1, dst - buffer , abfd);
641 }
642
643
644
645 static void
646 DEFUN(srec_write_header,(abfd),
647       bfd *abfd)
648 {
649     unsigned char buffer[MAXCHUNK];
650     unsigned char *dst = buffer;
651     unsigned int i;
652
653     /* I'll put an arbitary 40 char limit on header size */
654     for (i = 0; i < 40 && abfd->filename[i];  i++) 
655     {
656         *dst++ = abfd->filename[i];
657     }
658     srec_write_record(abfd,0, 0, buffer, dst);
659 }
660
661 static void
662 DEFUN(srec_write_section,(abfd, tdata, list),
663        bfd *abfd AND
664        tdata_type *tdata AND
665        srec_data_list_type *list)
666 {
667     unsigned int bytes_written = 0;
668     unsigned char *location = list->data;
669
670     while (bytes_written < list->size)
671     {
672         bfd_vma address;
673         
674         unsigned int bytes_this_chunk = list->size - bytes_written;
675
676         if (bytes_this_chunk > CHUNK) 
677         {
678             bytes_this_chunk = CHUNK;
679         }
680
681         address = list->where +  bytes_written;
682
683         srec_write_record(abfd,
684                           tdata->type,
685                           address,
686                           location,
687                           location + bytes_this_chunk);
688
689         bytes_written += bytes_this_chunk;
690         location += bytes_this_chunk;
691     }
692
693 }
694
695 static void
696 DEFUN(srec_write_terminator,(abfd, tdata),
697       bfd *abfd AND
698       tdata_type *tdata)
699 {
700     unsigned    char buffer[2];
701     
702     srec_write_record(abfd, 10 - tdata->type,
703                       abfd->start_address, buffer, buffer);
704 }
705
706
707       
708 static void
709 srec_write_symbols(abfd)
710      bfd *abfd;
711 {
712   char buffer[MAXCHUNK];
713   /* Dump out the symbols of a bfd */
714   int i;
715   int len = bfd_get_symcount(abfd);
716
717   if (len) 
718   {
719     asymbol **table = bfd_get_outsymbols(abfd);
720     sprintf(buffer, "$$ %s\r\n", abfd->filename);
721
722     bfd_write(buffer, strlen(buffer), 1, abfd);
723
724     for (i = 0; i < len; i++) 
725     {
726       asymbol *s = table[i];
727 #if 0
728       int len = strlen(s->name);
729
730       /* If this symbol has a .[ocs] in it, it's probably a file name
731          and we'll output that as the module name */
732
733       if (len > 3 && s->name[len-2] == '.') 
734       {
735         int l;
736         sprintf(buffer, "$$ %s\n\r", s->name);
737         l = strlen(buffer);
738         bfd_write(buffer, l, 1, abfd);
739       }
740       else
741 #endif
742        if (s->flags & (BSF_GLOBAL | BSF_LOCAL) 
743                && (s->flags & BSF_DEBUGGING) == 0
744                && s->name[0] != '.'
745                && s->name[0] != 't')
746       {
747         /* Just dump out non debug symbols */
748
749         int l;
750         char buf2[40], *p;
751
752         sprintf (buffer,"  %s $", s->name);
753         sprintf_vma (buf2, s->value + s->section->lma);
754         p = buf2;
755         while (p[0] == '0' && p[1] != 0)
756           p++;
757         strcat (buffer, p);
758         strcat (buffer, "\n\r");
759         l = strlen(buffer);
760         bfd_write(buffer, l, 1,abfd);
761       }
762     }
763     sprintf(buffer, "$$ \r\n");
764     bfd_write(buffer, strlen(buffer), 1, abfd);
765   }
766 }
767
768 static boolean
769 internal_srec_write_object_contents(abfd, symbols)
770      bfd *abfd;
771      int symbols;
772 {
773     int bytes_written;
774     tdata_type *tdata = abfd->tdata.srec_data;
775     srec_data_list_type *list;
776
777     bytes_written = 0;
778     
779     
780     if (symbols)
781      srec_write_symbols(abfd);
782
783     srec_write_header(abfd);
784
785     /* Now wander though all the sections provided and output them */
786     list = tdata->head;
787
788     while (list != (srec_data_list_type*)NULL) 
789     {
790         srec_write_section(abfd, tdata, list); 
791         list = list->next;
792     }
793     srec_write_terminator(abfd, tdata);
794     return true;
795 }
796
797 static boolean
798 srec_write_object_contents(abfd)
799      bfd *abfd;
800 {
801   return internal_srec_write_object_contents(abfd, 0);
802 }
803
804 static boolean
805 symbolsrec_write_object_contents(abfd)
806      bfd *abfd;
807 {
808   return internal_srec_write_object_contents(abfd, 1);
809 }
810
811 static int 
812 DEFUN(srec_sizeof_headers,(abfd, exec),
813       bfd *abfd AND
814       boolean exec)
815 {
816 return 0;
817 }
818
819 static asymbol *
820 DEFUN(srec_make_empty_symbol, (abfd),
821       bfd*abfd)
822 {
823   asymbol *new=  (asymbol *)bfd_zalloc (abfd, sizeof (asymbol));
824   new->the_bfd = abfd;
825   return new;
826 }
827
828 static unsigned int
829 srec_get_symtab_upper_bound(abfd)
830 bfd *abfd;
831 {
832   /* Read in all the info */
833   srec_get_section_contents(abfd,abfd->sections,0,0,0);
834   return (bfd_get_symcount(abfd) + 1) * (sizeof(asymbol *));
835 }
836
837 static unsigned int
838 DEFUN(srec_get_symtab, (abfd, alocation),
839       bfd            *abfd AND
840       asymbol       **alocation)
841 {
842   int lim = abfd->symcount;
843   int i;
844   for (i = 0; i < lim; i++) {
845     alocation[i] = abfd->tdata.srec_data->symbols + i;
846   }
847   alocation[i] = 0;
848   return lim;
849 }
850
851 void 
852 DEFUN(srec_get_symbol_info,(ignore_abfd, symbol, ret),
853       bfd *ignore_abfd AND
854       asymbol *symbol AND
855       symbol_info *ret)
856 {
857   bfd_symbol_info (symbol, ret);
858 }
859
860 void 
861 DEFUN(srec_print_symbol,(ignore_abfd, afile, symbol, how),
862       bfd *ignore_abfd AND
863       PTR afile AND
864       asymbol *symbol AND
865       bfd_print_symbol_type how)
866 {
867   FILE *file = (FILE *)afile;
868   switch (how) 
869   {
870    case bfd_print_symbol_name:
871     fprintf (file, "%s", symbol->name);
872     break;
873    default:
874     bfd_print_symbol_vandf ((PTR) file, symbol);
875     fprintf (file, " %-5s %s",
876              symbol->section->name,
877              symbol->name);
878
879   }
880 }
881
882 #define FOO PROTO
883 #define srec_new_section_hook (FOO(boolean, (*), (bfd *, asection *)))bfd_true
884
885 #define srec_get_reloc_upper_bound (FOO(unsigned int, (*),(bfd*, asection *)))bfd_false
886 #define srec_canonicalize_reloc (FOO(unsigned int, (*),(bfd*,asection *, arelent **, asymbol **))) bfd_0
887
888
889
890 #define srec_openr_next_archived_file (FOO(bfd *, (*), (bfd*,bfd*))) bfd_nullvoidptr
891 #define srec_find_nearest_line (FOO(boolean, (*),(bfd*,asection*,asymbol**,bfd_vma, CONST char**, CONST char**, unsigned int *))) bfd_false
892 #define srec_generic_stat_arch_elt  (FOO(int, (*), (bfd *,struct stat *))) bfd_0
893
894
895 #define srec_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
896 #define srec_core_file_failing_signal (int (*)())bfd_0
897 #define srec_core_file_matches_executable_p (FOO(boolean, (*),(bfd*, bfd*)))bfd_false
898 #define srec_slurp_armap bfd_true
899 #define srec_slurp_extended_name_table bfd_true
900 #define srec_truncate_arname (void (*)())bfd_nullvoidptr
901 #define srec_write_armap  (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
902 #define srec_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
903 #define srec_close_and_cleanup  bfd_generic_close_and_cleanup
904 #define srec_bfd_debug_info_start bfd_void
905 #define srec_bfd_debug_info_end bfd_void
906 #define srec_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *,  asection *))) bfd_void
907 #define srec_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
908 #define srec_bfd_relax_section bfd_generic_relax_section
909 #define srec_bfd_seclet_link bfd_generic_seclet_link
910 #define srec_bfd_reloc_type_lookup \
911   ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
912 #define srec_bfd_make_debug_symbol \
913   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
914
915 bfd_target srec_vec =
916 {
917     "srec",                     /* name */
918     bfd_target_srec_flavour,
919     true,                       /* target byte order */
920     true,                       /* target headers byte order */
921     (HAS_RELOC | EXEC_P |       /* object flags */
922      HAS_LINENO | HAS_DEBUG |
923      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
924     (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
925      |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
926      0,                         /* leading underscore */
927     ' ',                        /* ar_pad_char */
928     16,                         /* ar_max_namelen */
929     1,                          /* minimum alignment */
930     _do_getb64, _do_getb_signed_64, _do_putb64,
931       _do_getb32, _do_getb_signed_32,     _do_putb32,
932       _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
933     _do_getb64, _do_getb_signed_64, _do_putb64,
934       _do_getb32, _do_getb_signed_32,     _do_putb32,
935       _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
936
937   {
938       _bfd_dummy_target,
939       srec_object_p,            /* bfd_check_format */
940       (struct bfd_target *(*)()) bfd_nullvoidptr,
941       (struct bfd_target *(*)())     bfd_nullvoidptr,
942   },
943   {
944       bfd_false,
945       srec_mkobject,
946       _bfd_generic_mkarchive,
947       bfd_false,
948   },
949   {                             /* bfd_write_contents */
950       bfd_false,
951       srec_write_object_contents,
952       _bfd_write_archive_contents,
953       bfd_false,
954   },
955     JUMP_TABLE(srec)
956  };
957
958
959
960 bfd_target symbolsrec_vec =
961 {
962     "symbolsrec",               /* name */
963     bfd_target_srec_flavour,
964     true,                       /* target byte order */
965     true,                       /* target headers byte order */
966     (HAS_RELOC | EXEC_P |       /* object flags */
967      HAS_LINENO | HAS_DEBUG |
968      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
969     (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
970      |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
971      0,                         /* leading underscore */
972     ' ',                        /* ar_pad_char */
973     16,                         /* ar_max_namelen */
974     1,                          /* minimum alignment */
975     _do_getb64, _do_getb_signed_64, _do_putb64,
976       _do_getb32, _do_getb_signed_32,     _do_putb32,
977       _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
978     _do_getb64, _do_getb_signed_64, _do_putb64,
979       _do_getb32, _do_getb_signed_32,     _do_putb32,
980       _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
981
982   {
983       _bfd_dummy_target,
984       symbolsrec_object_p,              /* bfd_check_format */
985       (struct bfd_target *(*)()) bfd_nullvoidptr,
986       (struct bfd_target *(*)())     bfd_nullvoidptr,
987   },
988   {
989       bfd_false,
990       srec_mkobject,
991       _bfd_generic_mkarchive,
992       bfd_false,
993   },
994   {                             /* bfd_write_contents */
995       bfd_false,
996       symbolsrec_write_object_contents,
997       _bfd_write_archive_contents,
998       bfd_false,
999   },
1000     JUMP_TABLE(srec),
1001     (PTR) 0
1002  };
1003