1 /* BFD back-end for s-record objects.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 Ordinary S-Records cannot hold anything but addresses and
30 data, so that's all that we implement.
32 The only interesting thing is that S-Records may come out of
33 order and there is no header, so an initial scan is required
34 to discover the minimum and maximum addresses used to create
35 the vma and size of the only section we create. We
36 arbitrarily call this section ".text".
38 When bfd_get_section_contents is called the file is read
39 again, and this time the data is placed into a bfd_alloc'd
42 Any number of sections may be created for output, we save them
43 up and output them when it's time to close the bfd.
45 An s record looks like:
48 S<type><length><address><data><checksum>
53 is the number of bytes following upto the checksum. Note that
54 this is not the number of chars following, since it takes two
55 chars to represent a byte.
59 1) two byte address data record
60 2) three byte address data record
61 3) four byte address data record
62 7) four byte address termination record
63 8) three byte address termination record
64 9) two byte address termination record
67 is the start address of the data following, or in the case of
68 a termination record, the start address of the image
72 is the sum of all the raw byte data in the record, from the length
73 upwards, modulo 256 and subtracted from 255.
76 Symbol S-Record handling
79 Some ICE equipment understands an addition to the standard
80 S-Record format; symbols and their addresses can be sent
83 The format of this is:
85 (<space> <symbol> <address>)*)
88 so a short symbol table could look like:
102 We allow symbols to be anywhere in the data stream - the module names
110 #include "libiberty.h"
111 #include "safe-ctype.h"
113 static void srec_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
114 static void srec_print_symbol
115 PARAMS ((bfd
*, PTR
, asymbol
*, bfd_print_symbol_type
));
116 static void srec_init
PARAMS ((void));
117 static bfd_boolean srec_mkobject
PARAMS ((bfd
*));
118 static int srec_get_byte
PARAMS ((bfd
*, bfd_boolean
*));
119 static void srec_bad_byte
PARAMS ((bfd
*, unsigned int, int, bfd_boolean
));
120 static bfd_boolean srec_scan
PARAMS ((bfd
*));
121 static const bfd_target
*srec_object_p
PARAMS ((bfd
*));
122 static const bfd_target
*symbolsrec_object_p
PARAMS ((bfd
*));
123 static bfd_boolean srec_read_section
PARAMS ((bfd
*, asection
*, bfd_byte
*));
125 static bfd_boolean srec_write_record
126 PARAMS ((bfd
*, unsigned int, bfd_vma
, const bfd_byte
*, const bfd_byte
*));
127 static bfd_boolean srec_write_header
PARAMS ((bfd
*));
128 static bfd_boolean srec_write_symbols
PARAMS ((bfd
*));
129 static bfd_boolean srec_new_symbol
PARAMS ((bfd
*, const char *, bfd_vma
));
130 static bfd_boolean srec_get_section_contents
131 PARAMS ((bfd
*, asection
*, PTR
, file_ptr
, bfd_size_type
));
132 static bfd_boolean srec_set_arch_mach
133 PARAMS ((bfd
*, enum bfd_architecture
, unsigned long));
134 static bfd_boolean srec_set_section_contents
135 PARAMS ((bfd
*, sec_ptr
, const PTR
, file_ptr
, bfd_size_type
));
136 static bfd_boolean internal_srec_write_object_contents
PARAMS ((bfd
*, int));
137 static bfd_boolean srec_write_object_contents
PARAMS ((bfd
*));
138 static bfd_boolean symbolsrec_write_object_contents
PARAMS ((bfd
*));
139 static int srec_sizeof_headers
PARAMS ((bfd
*, bfd_boolean
));
140 static long srec_get_symtab_upper_bound
PARAMS ((bfd
*));
141 static long srec_canonicalize_symtab
PARAMS ((bfd
*, asymbol
**));
143 /* Macros for converting between hex and binary. */
145 static const char digs
[] = "0123456789ABCDEF";
147 #define NIBBLE(x) hex_value(x)
148 #define HEX(buffer) ((NIBBLE((buffer)[0])<<4) + NIBBLE((buffer)[1]))
149 #define TOHEX(d, x, ch) \
150 d[1] = digs[(x) & 0xf]; \
151 d[0] = digs[((x)>>4)&0xf]; \
153 #define ISHEX(x) hex_p(x)
155 /* Initialize by filling in the hex conversion array. */
160 static bfd_boolean inited
= FALSE
;
169 /* The maximum number of address+data+crc bytes on a line is FF. */
170 #define MAXCHUNK 0xff
172 /* Default size for a CHUNK. */
173 #define DEFAULT_CHUNK 16
175 /* The number of data bytes we actually fit onto a line on output.
176 This variable can be modified by objcopy's --srec-len parameter.
177 For a 0x75 byte record you should set --srec-len=0x70. */
178 unsigned int Chunk
= DEFAULT_CHUNK
;
180 /* The type of srec output (free or forced to S3).
181 This variable can be modified by objcopy's --srec-forceS3
183 bfd_boolean S3Forced
= FALSE
;
185 /* When writing an S-record file, the S-records can not be output as
186 they are seen. This structure is used to hold them in memory. */
188 struct srec_data_list_struct
190 struct srec_data_list_struct
*next
;
196 typedef struct srec_data_list_struct srec_data_list_type
;
198 /* When scanning the S-record file, a linked list of srec_symbol
199 structures is built to represent the symbol table (if there is
204 struct srec_symbol
*next
;
209 /* The S-record tdata information. */
211 typedef struct srec_data_struct
213 srec_data_list_type
*head
;
214 srec_data_list_type
*tail
;
216 struct srec_symbol
*symbols
;
217 struct srec_symbol
*symtail
;
222 static bfd_boolean srec_write_section
223 PARAMS ((bfd
*, tdata_type
*, srec_data_list_type
*));
224 static bfd_boolean srec_write_terminator
225 PARAMS ((bfd
*, tdata_type
*));
227 /* Set up the S-record tdata information. */
238 amt
= sizeof (tdata_type
);
239 tdata
= (tdata_type
*) bfd_alloc (abfd
, amt
);
243 abfd
->tdata
.srec_data
= tdata
;
247 tdata
->symbols
= NULL
;
248 tdata
->symtail
= NULL
;
249 tdata
->csymbols
= NULL
;
254 /* Read a byte from an S record file. Set *ERRORPTR if an error
255 occurred. Return EOF on error or end of file. */
258 srec_get_byte (abfd
, errorptr
)
260 bfd_boolean
*errorptr
;
264 if (bfd_bread (&c
, (bfd_size_type
) 1, abfd
) != 1)
266 if (bfd_get_error () != bfd_error_file_truncated
)
271 return (int) (c
& 0xff);
274 /* Report a problem in an S record file. FIXME: This probably should
275 not call fprintf, but we really do need some mechanism for printing
279 srec_bad_byte (abfd
, lineno
, c
, error
)
288 bfd_set_error (bfd_error_file_truncated
);
295 sprintf (buf
, "\\%03o", (unsigned int) c
);
301 (*_bfd_error_handler
)
302 (_("%s:%d: Unexpected character `%s' in S-record file\n"),
303 bfd_archive_filename (abfd
), lineno
, buf
);
304 bfd_set_error (bfd_error_bad_value
);
308 /* Add a new symbol found in an S-record file. */
311 srec_new_symbol (abfd
, name
, val
)
316 struct srec_symbol
*n
;
317 bfd_size_type amt
= sizeof (struct srec_symbol
);
319 n
= (struct srec_symbol
*) bfd_alloc (abfd
, amt
);
326 if (abfd
->tdata
.srec_data
->symbols
== NULL
)
327 abfd
->tdata
.srec_data
->symbols
= n
;
329 abfd
->tdata
.srec_data
->symtail
->next
= n
;
330 abfd
->tdata
.srec_data
->symtail
= n
;
338 /* Read the S record file and turn it into sections. We create a new
339 section for each contiguous set of bytes. */
346 unsigned int lineno
= 1;
347 bfd_boolean error
= FALSE
;
348 bfd_byte
*buf
= NULL
;
350 asection
*sec
= NULL
;
353 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
356 while ((c
= srec_get_byte (abfd
, &error
)) != EOF
)
358 /* We only build sections from contiguous S-records, so if this
359 is not an S-record, then stop building a section. */
360 if (c
!= 'S' && c
!= '\r' && c
!= '\n')
366 srec_bad_byte (abfd
, lineno
, c
, error
);
377 /* Starting a module name, which we ignore. */
378 while ((c
= srec_get_byte (abfd
, &error
)) != '\n'
383 srec_bad_byte (abfd
, lineno
, c
, error
);
398 /* Starting a symbol definition. */
399 while ((c
= srec_get_byte (abfd
, &error
)) != EOF
400 && (c
== ' ' || c
== '\t'))
403 if (c
== '\n' || c
== '\r')
408 srec_bad_byte (abfd
, lineno
, c
, error
);
413 symbuf
= (char *) bfd_malloc (alc
+ 1);
420 while ((c
= srec_get_byte (abfd
, &error
)) != EOF
423 if ((bfd_size_type
) (p
- symbuf
) >= alc
)
428 n
= (char *) bfd_realloc (symbuf
, alc
+ 1);
431 p
= n
+ (p
- symbuf
);
440 srec_bad_byte (abfd
, lineno
, c
, error
);
445 symname
= bfd_alloc (abfd
, (bfd_size_type
) (p
- symbuf
));
448 strcpy (symname
, symbuf
);
452 while ((c
= srec_get_byte (abfd
, &error
)) != EOF
453 && (c
== ' ' || c
== '\t'))
457 srec_bad_byte (abfd
, lineno
, c
, error
);
461 /* Skip a dollar sign before the hex value. */
464 c
= srec_get_byte (abfd
, &error
);
467 srec_bad_byte (abfd
, lineno
, c
, error
);
476 symval
+= NIBBLE (c
);
477 c
= srec_get_byte (abfd
, &error
);
480 if (! srec_new_symbol (abfd
, symname
, symval
))
483 while (c
== ' ' || c
== '\t')
490 srec_bad_byte (abfd
, lineno
, c
, error
);
504 /* Starting an S-record. */
506 pos
= bfd_tell (abfd
) - 1;
508 if (bfd_bread (hdr
, (bfd_size_type
) 3, abfd
) != 3)
511 if (! ISHEX (hdr
[1]) || ! ISHEX (hdr
[2]))
513 if (! ISHEX (hdr
[1]))
517 srec_bad_byte (abfd
, lineno
, c
, error
);
521 bytes
= HEX (hdr
+ 1);
522 if (bytes
* 2 > bufsize
)
526 buf
= (bfd_byte
*) bfd_malloc ((bfd_size_type
) bytes
* 2);
532 if (bfd_bread (buf
, (bfd_size_type
) bytes
* 2, abfd
) != bytes
* 2)
535 /* Ignore the checksum byte. */
544 /* Prologue--ignore the file name, but stop building a
545 section at this point. */
550 address
= HEX (data
);
555 address
= (address
<< 8) | HEX (data
);
560 address
= (address
<< 8) | HEX (data
);
562 address
= (address
<< 8) | HEX (data
);
567 && sec
->vma
+ sec
->_raw_size
== address
)
569 /* This data goes at the end of the section we are
570 currently building. */
571 sec
->_raw_size
+= bytes
;
579 sprintf (secbuf
, ".sec%d", bfd_count_sections (abfd
) + 1);
580 amt
= strlen (secbuf
) + 1;
581 secname
= (char *) bfd_alloc (abfd
, amt
);
582 strcpy (secname
, secbuf
);
583 sec
= bfd_make_section (abfd
, secname
);
586 sec
->flags
= SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_ALLOC
;
589 sec
->_raw_size
= bytes
;
596 address
= HEX (data
);
600 address
= (address
<< 8) | HEX (data
);
604 address
= (address
<< 8) | HEX (data
);
606 address
= (address
<< 8) | HEX (data
);
609 /* This is a termination record. */
610 abfd
->start_address
= address
;
638 /* Check whether an existing file is an S-record file. */
640 static const bfd_target
*
649 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
650 || bfd_bread (b
, (bfd_size_type
) 4, abfd
) != 4)
653 if (b
[0] != 'S' || !ISHEX (b
[1]) || !ISHEX (b
[2]) || !ISHEX (b
[3]))
655 bfd_set_error (bfd_error_wrong_format
);
659 tdata_save
= abfd
->tdata
.any
;
660 if (! srec_mkobject (abfd
) || ! srec_scan (abfd
))
662 if (abfd
->tdata
.any
!= tdata_save
&& abfd
->tdata
.any
!= NULL
)
663 bfd_release (abfd
, abfd
->tdata
.any
);
664 abfd
->tdata
.any
= tdata_save
;
668 if (abfd
->symcount
> 0)
669 abfd
->flags
|= HAS_SYMS
;
674 /* Check whether an existing file is an S-record file with symbols. */
676 static const bfd_target
*
677 symbolsrec_object_p (abfd
)
685 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
686 || bfd_bread (b
, (bfd_size_type
) 2, abfd
) != 2)
689 if (b
[0] != '$' || b
[1] != '$')
691 bfd_set_error (bfd_error_wrong_format
);
695 tdata_save
= abfd
->tdata
.any
;
696 if (! srec_mkobject (abfd
) || ! srec_scan (abfd
))
698 if (abfd
->tdata
.any
!= tdata_save
&& abfd
->tdata
.any
!= NULL
)
699 bfd_release (abfd
, abfd
->tdata
.any
);
700 abfd
->tdata
.any
= tdata_save
;
704 if (abfd
->symcount
> 0)
705 abfd
->flags
|= HAS_SYMS
;
710 /* Read in the contents of a section in an S-record file. */
713 srec_read_section (abfd
, section
, contents
)
719 bfd_size_type sofar
= 0;
720 bfd_boolean error
= FALSE
;
721 bfd_byte
*buf
= NULL
;
724 if (bfd_seek (abfd
, section
->filepos
, SEEK_SET
) != 0)
727 while ((c
= srec_get_byte (abfd
, &error
)) != EOF
)
734 if (c
== '\r' || c
== '\n')
737 /* This is called after srec_scan has already been called, so we
738 ought to know the exact format. */
739 BFD_ASSERT (c
== 'S');
741 if (bfd_bread (hdr
, (bfd_size_type
) 3, abfd
) != 3)
744 BFD_ASSERT (ISHEX (hdr
[1]) && ISHEX (hdr
[2]));
746 bytes
= HEX (hdr
+ 1);
748 if (bytes
* 2 > bufsize
)
752 buf
= (bfd_byte
*) bfd_malloc ((bfd_size_type
) bytes
* 2);
758 if (bfd_bread (buf
, (bfd_size_type
) bytes
* 2, abfd
) != bytes
* 2)
766 BFD_ASSERT (sofar
== section
->_raw_size
);
772 address
= HEX (data
);
777 address
= (address
<< 8) | HEX (data
);
782 address
= (address
<< 8) | HEX (data
);
784 address
= (address
<< 8) | HEX (data
);
788 if (address
!= section
->vma
+ sofar
)
790 /* We've come to the end of this section. */
791 BFD_ASSERT (sofar
== section
->_raw_size
);
797 /* Don't consider checksum. */
802 contents
[sofar
] = HEX (data
);
814 BFD_ASSERT (sofar
== section
->_raw_size
);
827 /* Get the contents of a section in an S-record file. */
830 srec_get_section_contents (abfd
, section
, location
, offset
, count
)
837 if (section
->used_by_bfd
== NULL
)
839 section
->used_by_bfd
= bfd_alloc (abfd
, section
->_raw_size
);
840 if (section
->used_by_bfd
== NULL
&& section
->_raw_size
!= 0)
843 if (! srec_read_section (abfd
, section
, section
->used_by_bfd
))
847 memcpy (location
, (bfd_byte
*) section
->used_by_bfd
+ offset
,
853 /* Set the architecture. We accept an unknown architecture here. */
856 srec_set_arch_mach (abfd
, arch
, mach
)
858 enum bfd_architecture arch
;
861 if (arch
== bfd_arch_unknown
)
863 abfd
->arch_info
= &bfd_default_arch_struct
;
866 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
869 /* We have to save up all the Srecords for a splurge before output. */
872 srec_set_section_contents (abfd
, section
, location
, offset
, bytes_to_do
)
877 bfd_size_type bytes_to_do
;
879 tdata_type
*tdata
= abfd
->tdata
.srec_data
;
880 register srec_data_list_type
*entry
;
882 entry
= ((srec_data_list_type
*)
883 bfd_alloc (abfd
, (bfd_size_type
) sizeof (srec_data_list_type
)));
888 && (section
->flags
& SEC_ALLOC
)
889 && (section
->flags
& SEC_LOAD
))
893 data
= (bfd_byte
*) bfd_alloc (abfd
, bytes_to_do
);
896 memcpy ((PTR
) data
, location
, (size_t) bytes_to_do
);
898 /* Ff S3Forced is TRUE then always select S3 records,
899 regardless of the siez of the addresses. */
902 else if ((section
->lma
+ offset
+ bytes_to_do
- 1) <= 0xffff)
903 ; /* The default, S1, is OK. */
904 else if ((section
->lma
+ offset
+ bytes_to_do
- 1) <= 0xffffff
911 entry
->where
= section
->lma
+ offset
;
912 entry
->size
= bytes_to_do
;
914 /* Sort the records by address. Optimize for the common case of
915 adding a record to the end of the list. */
916 if (tdata
->tail
!= NULL
917 && entry
->where
>= tdata
->tail
->where
)
919 tdata
->tail
->next
= entry
;
925 register srec_data_list_type
**look
;
927 for (look
= &tdata
->head
;
928 *look
!= NULL
&& (*look
)->where
< entry
->where
;
929 look
= &(*look
)->next
)
933 if (entry
->next
== NULL
)
940 /* Write a record of type, of the supplied number of bytes. The
941 supplied bytes and length don't have a checksum. That's worked out
945 srec_write_record (abfd
, type
, address
, data
, end
)
949 const bfd_byte
*data
;
952 char buffer
[2 * MAXCHUNK
+ 6];
953 unsigned int check_sum
= 0;
954 const bfd_byte
*src
= data
;
963 dst
+= 2; /* Leave room for dst. */
969 TOHEX (dst
, (address
>> 24), check_sum
);
973 TOHEX (dst
, (address
>> 16), check_sum
);
978 TOHEX (dst
, (address
>> 8), check_sum
);
980 TOHEX (dst
, (address
), check_sum
);
985 for (src
= data
; src
< end
; src
++)
987 TOHEX (dst
, *src
, check_sum
);
991 /* Fill in the length. */
992 TOHEX (length
, (dst
- length
) / 2, check_sum
);
994 check_sum
= 255 - check_sum
;
995 TOHEX (dst
, check_sum
, check_sum
);
1000 wrlen
= dst
- buffer
;
1001 if (bfd_bwrite ((PTR
) buffer
, wrlen
, abfd
) != wrlen
)
1007 srec_write_header (abfd
)
1010 unsigned int len
= strlen (abfd
->filename
);
1012 /* I'll put an arbitrary 40 char limit on header size. */
1016 return srec_write_record (abfd
, 0, (bfd_vma
) 0,
1017 abfd
->filename
, abfd
->filename
+ len
);
1021 srec_write_section (abfd
, tdata
, list
)
1024 srec_data_list_type
*list
;
1026 unsigned int octets_written
= 0;
1027 bfd_byte
*location
= list
->data
;
1029 /* Validate number of data bytes to write. The srec length byte
1030 counts the address, data and crc bytes. S1 (tdata->type == 1)
1031 records have two address bytes, S2 (tdata->type == 2) records
1032 have three, and S3 (tdata->type == 3) records have four.
1033 The total length can't exceed 255, and a zero data length will
1034 spin for a long time. */
1037 else if (Chunk
> MAXCHUNK
- tdata
->type
- 2)
1038 Chunk
= MAXCHUNK
- tdata
->type
- 2;
1040 while (octets_written
< list
->size
)
1043 unsigned int octets_this_chunk
= list
->size
- octets_written
;
1045 if (octets_this_chunk
> Chunk
)
1046 octets_this_chunk
= Chunk
;
1048 address
= list
->where
+ octets_written
/ bfd_octets_per_byte (abfd
);
1050 if (! srec_write_record (abfd
,
1054 location
+ octets_this_chunk
))
1057 octets_written
+= octets_this_chunk
;
1058 location
+= octets_this_chunk
;
1065 srec_write_terminator (abfd
, tdata
)
1069 return srec_write_record (abfd
, 10 - tdata
->type
,
1070 abfd
->start_address
, NULL
, NULL
);
1074 srec_write_symbols (abfd
)
1077 /* Dump out the symbols of a bfd. */
1079 int count
= bfd_get_symcount (abfd
);
1084 asymbol
**table
= bfd_get_outsymbols (abfd
);
1085 len
= strlen (abfd
->filename
);
1086 if (bfd_bwrite ("$$ ", (bfd_size_type
) 3, abfd
) != 3
1087 || bfd_bwrite (abfd
->filename
, len
, abfd
) != len
1088 || bfd_bwrite ("\r\n", (bfd_size_type
) 2, abfd
) != 2)
1091 for (i
= 0; i
< count
; i
++)
1093 asymbol
*s
= table
[i
];
1094 if (! bfd_is_local_label (abfd
, s
)
1095 && (s
->flags
& BSF_DEBUGGING
) == 0)
1097 /* Just dump out non debug symbols. */
1100 len
= strlen (s
->name
);
1101 if (bfd_bwrite (" ", (bfd_size_type
) 2, abfd
) != 2
1102 || bfd_bwrite (s
->name
, len
, abfd
) != len
)
1105 sprintf_vma (buf
+ 2, (s
->value
1106 + s
->section
->output_section
->lma
1107 + s
->section
->output_offset
));
1109 while (p
[0] == '0' && p
[1] != 0)
1117 if (bfd_bwrite (p
, len
, abfd
) != len
)
1121 if (bfd_bwrite ("$$ \r\n", (bfd_size_type
) 5, abfd
) != 5)
1129 internal_srec_write_object_contents (abfd
, symbols
)
1133 tdata_type
*tdata
= abfd
->tdata
.srec_data
;
1134 srec_data_list_type
*list
;
1138 if (! srec_write_symbols (abfd
))
1142 if (! srec_write_header (abfd
))
1145 /* Now wander though all the sections provided and output them. */
1148 while (list
!= (srec_data_list_type
*) NULL
)
1150 if (! srec_write_section (abfd
, tdata
, list
))
1154 return srec_write_terminator (abfd
, tdata
);
1158 srec_write_object_contents (abfd
)
1161 return internal_srec_write_object_contents (abfd
, 0);
1165 symbolsrec_write_object_contents (abfd
)
1168 return internal_srec_write_object_contents (abfd
, 1);
1172 srec_sizeof_headers (abfd
, exec
)
1173 bfd
*abfd ATTRIBUTE_UNUSED
;
1174 bfd_boolean exec ATTRIBUTE_UNUSED
;
1179 /* Return the amount of memory needed to read the symbol table. */
1182 srec_get_symtab_upper_bound (abfd
)
1185 return (bfd_get_symcount (abfd
) + 1) * sizeof (asymbol
*);
1188 /* Return the symbol table. */
1191 srec_canonicalize_symtab (abfd
, alocation
)
1193 asymbol
**alocation
;
1195 bfd_size_type symcount
= bfd_get_symcount (abfd
);
1199 csymbols
= abfd
->tdata
.srec_data
->csymbols
;
1200 if (csymbols
== NULL
)
1203 struct srec_symbol
*s
;
1205 csymbols
= (asymbol
*) bfd_alloc (abfd
, symcount
* sizeof (asymbol
));
1206 if (csymbols
== NULL
&& symcount
!= 0)
1208 abfd
->tdata
.srec_data
->csymbols
= csymbols
;
1210 for (s
= abfd
->tdata
.srec_data
->symbols
, c
= csymbols
;
1217 c
->flags
= BSF_GLOBAL
;
1218 c
->section
= bfd_abs_section_ptr
;
1223 for (i
= 0; i
< symcount
; i
++)
1224 *alocation
++ = csymbols
++;
1231 srec_get_symbol_info (ignore_abfd
, symbol
, ret
)
1232 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
1236 bfd_symbol_info (symbol
, ret
);
1240 srec_print_symbol (abfd
, afile
, symbol
, how
)
1244 bfd_print_symbol_type how
;
1246 FILE *file
= (FILE *) afile
;
1249 case bfd_print_symbol_name
:
1250 fprintf (file
, "%s", symbol
->name
);
1253 bfd_print_symbol_vandf (abfd
, (PTR
) file
, symbol
);
1254 fprintf (file
, " %-5s %s",
1255 symbol
->section
->name
,
1261 #define srec_close_and_cleanup _bfd_generic_close_and_cleanup
1262 #define srec_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
1263 #define srec_new_section_hook _bfd_generic_new_section_hook
1265 #define srec_bfd_is_local_label_name bfd_generic_is_local_label_name
1266 #define srec_get_lineno _bfd_nosymbols_get_lineno
1267 #define srec_find_nearest_line _bfd_nosymbols_find_nearest_line
1268 #define srec_make_empty_symbol _bfd_generic_make_empty_symbol
1269 #define srec_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
1270 #define srec_read_minisymbols _bfd_generic_read_minisymbols
1271 #define srec_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
1273 #define srec_get_reloc_upper_bound \
1274 ((long (*) PARAMS ((bfd *, asection *))) bfd_0l)
1275 #define srec_canonicalize_reloc \
1276 ((long (*) PARAMS ((bfd *, asection *, arelent **, asymbol **))) bfd_0l)
1277 #define srec_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
1279 #define srec_get_section_contents_in_window \
1280 _bfd_generic_get_section_contents_in_window
1282 #define srec_bfd_get_relocated_section_contents \
1283 bfd_generic_get_relocated_section_contents
1284 #define srec_bfd_relax_section bfd_generic_relax_section
1285 #define srec_bfd_gc_sections bfd_generic_gc_sections
1286 #define srec_bfd_merge_sections bfd_generic_merge_sections
1287 #define srec_bfd_is_group_section bfd_generic_is_group_section
1288 #define srec_bfd_discard_group bfd_generic_discard_group
1289 #define srec_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
1290 #define srec_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
1291 #define srec_bfd_link_add_symbols _bfd_generic_link_add_symbols
1292 #define srec_bfd_link_just_syms _bfd_generic_link_just_syms
1293 #define srec_bfd_final_link _bfd_generic_final_link
1294 #define srec_bfd_link_split_section _bfd_generic_link_split_section
1296 const bfd_target srec_vec
=
1299 bfd_target_srec_flavour
,
1300 BFD_ENDIAN_UNKNOWN
, /* target byte order */
1301 BFD_ENDIAN_UNKNOWN
, /* target headers byte order */
1302 (HAS_RELOC
| EXEC_P
| /* object flags */
1303 HAS_LINENO
| HAS_DEBUG
|
1304 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
1305 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
1306 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
1307 0, /* leading underscore */
1308 ' ', /* ar_pad_char */
1309 16, /* ar_max_namelen */
1310 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
1311 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
1312 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
1313 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
1314 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
1315 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
1319 srec_object_p
, /* bfd_check_format */
1326 _bfd_generic_mkarchive
,
1329 { /* bfd_write_contents */
1331 srec_write_object_contents
,
1332 _bfd_write_archive_contents
,
1336 BFD_JUMP_TABLE_GENERIC (srec
),
1337 BFD_JUMP_TABLE_COPY (_bfd_generic
),
1338 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
1339 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
1340 BFD_JUMP_TABLE_SYMBOLS (srec
),
1341 BFD_JUMP_TABLE_RELOCS (srec
),
1342 BFD_JUMP_TABLE_WRITE (srec
),
1343 BFD_JUMP_TABLE_LINK (srec
),
1344 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
1351 const bfd_target symbolsrec_vec
=
1353 "symbolsrec", /* name */
1354 bfd_target_srec_flavour
,
1355 BFD_ENDIAN_UNKNOWN
, /* target byte order */
1356 BFD_ENDIAN_UNKNOWN
, /* target headers byte order */
1357 (HAS_RELOC
| EXEC_P
| /* object flags */
1358 HAS_LINENO
| HAS_DEBUG
|
1359 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
1360 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
1361 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
1362 0, /* leading underscore */
1363 ' ', /* ar_pad_char */
1364 16, /* ar_max_namelen */
1365 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
1366 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
1367 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
1368 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
1369 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
1370 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
1374 symbolsrec_object_p
, /* bfd_check_format */
1381 _bfd_generic_mkarchive
,
1384 { /* bfd_write_contents */
1386 symbolsrec_write_object_contents
,
1387 _bfd_write_archive_contents
,
1391 BFD_JUMP_TABLE_GENERIC (srec
),
1392 BFD_JUMP_TABLE_COPY (_bfd_generic
),
1393 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
1394 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
1395 BFD_JUMP_TABLE_SYMBOLS (srec
),
1396 BFD_JUMP_TABLE_RELOCS (srec
),
1397 BFD_JUMP_TABLE_WRITE (srec
),
1398 BFD_JUMP_TABLE_LINK (srec
),
1399 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),