X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Fsrec.c;h=6d9b9a47fce3569b53917c37311c0c362415cdef;hb=5430098f1807e084fe4ff5057040d68435f3d8a2;hp=1251a7e93c9c353382590203ec8315645c6fe2ea;hpb=1338dd10efb7f5b6ab29142fa07004ff900a20b4;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/srec.c b/bfd/srec.c index 1251a7e93c..6d9b9a47fc 100644 --- a/bfd/srec.c +++ b/bfd/srec.c @@ -1,7 +1,5 @@ /* BFD back-end for s-record objects. - Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright (C) 1990-2017 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support . This file is part of BFD, the Binary File Descriptor library. @@ -131,12 +129,12 @@ static const char digs[] = "0123456789ABCDEF"; /* The number of data bytes we actually fit onto a line on output. This variable can be modified by objcopy's --srec-len parameter. For a 0x75 byte record you should set --srec-len=0x70. */ -unsigned int Chunk = DEFAULT_CHUNK; +unsigned int _bfd_srec_len = DEFAULT_CHUNK; /* The type of srec output (free or forced to S3). This variable can be modified by objcopy's --srec-forceS3 parameter. */ -bfd_boolean S3Forced = FALSE; +bfd_boolean _bfd_srec_forceS3 = FALSE; /* When writing an S-record file, the S-records can not be output as they are seen. This structure is used to hold them in memory. */ @@ -248,16 +246,17 @@ srec_bad_byte (bfd *abfd, } else { - char buf[10]; + char buf[40]; if (! ISPRINT (c)) - sprintf (buf, "\\%03o", (unsigned int) c); + sprintf (buf, "\\%03o", (unsigned int) c & 0xff); else { buf[0] = c; buf[1] = '\0'; } - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B:%d: Unexpected character `%s' in S-record file\n"), abfd, lineno, buf); bfd_set_error (bfd_error_bad_value); @@ -454,8 +453,8 @@ srec_scan (bfd *abfd) case 'S': { file_ptr pos; - char hdr[3]; - unsigned int bytes; + unsigned char hdr[3]; + unsigned int bytes, min_bytes; bfd_vma address; bfd_byte *data; unsigned char check_sum; @@ -478,6 +477,20 @@ srec_scan (bfd *abfd) } check_sum = bytes = HEX (hdr + 1); + min_bytes = 3; + if (hdr[0] == '2' || hdr[0] == '8') + min_bytes = 4; + else if (hdr[0] == '3' || hdr[0] == '7') + min_bytes = 5; + if (bytes < min_bytes) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%B:%d: byte count %d too small\n"), + abfd, lineno, bytes); + bfd_set_error (bfd_error_bad_value); + goto error_return; + } + if (bytes * 2 > bufsize) { if (buf != NULL) @@ -563,7 +576,8 @@ srec_scan (bfd *abfd) check_sum = 255 - (check_sum & 0xff); if (check_sum != HEX (data)) { - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B:%d: Bad checksum in S-record file\n"), abfd, lineno); bfd_set_error (bfd_error_bad_value); @@ -596,7 +610,8 @@ srec_scan (bfd *abfd) check_sum = 255 - (check_sum & 0xff); if (check_sum != HEX (data)) { - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B:%d: Bad checksum in S-record file\n"), abfd, lineno); bfd_set_error (bfd_error_bad_value); @@ -870,6 +885,7 @@ srec_set_section_contents (bfd *abfd, file_ptr offset, bfd_size_type bytes_to_do) { + int opb = bfd_octets_per_byte (abfd); tdata_type *tdata = abfd->tdata.srec_data; srec_data_list_type *entry; @@ -888,20 +904,20 @@ srec_set_section_contents (bfd *abfd, return FALSE; memcpy ((void *) data, location, (size_t) bytes_to_do); - /* Ff S3Forced is TRUE then always select S3 records, - regardless of the siez of the addresses. */ - if (S3Forced) + /* If _bfd_srec_forceS3 is TRUE then always select S3 records, + regardless of the size of the addresses. */ + if (_bfd_srec_forceS3) tdata->type = 3; - else if ((section->lma + offset + bytes_to_do - 1) <= 0xffff) + else if ((section->lma + (offset + bytes_to_do) / opb - 1) <= 0xffff) ; /* The default, S1, is OK. */ - else if ((section->lma + offset + bytes_to_do - 1) <= 0xffffff + else if ((section->lma + (offset + bytes_to_do) / opb - 1) <= 0xffffff && tdata->type <= 2) tdata->type = 2; else tdata->type = 3; entry->data = data; - entry->where = section->lma + offset; + entry->where = section->lma + offset / opb; entry->size = bytes_to_do; /* Sort the records by address. Optimize for the common case of @@ -960,10 +976,12 @@ srec_write_record (bfd *abfd, case 7: TOHEX (dst, (address >> 24), check_sum); dst += 2; + /* Fall through. */ case 8: case 2: TOHEX (dst, (address >> 16), check_sum); dst += 2; + /* Fall through. */ case 9: case 1: case 0: @@ -1022,18 +1040,18 @@ srec_write_section (bfd *abfd, have three, and S3 (tdata->type == 3) records have four. The total length can't exceed 255, and a zero data length will spin for a long time. */ - if (Chunk == 0) - Chunk = 1; - else if (Chunk > MAXCHUNK - tdata->type - 2) - Chunk = MAXCHUNK - tdata->type - 2; + if (_bfd_srec_len == 0) + _bfd_srec_len = 1; + else if (_bfd_srec_len > MAXCHUNK - tdata->type - 2) + _bfd_srec_len = MAXCHUNK - tdata->type - 2; while (octets_written < list->size) { bfd_vma address; unsigned int octets_this_chunk = list->size - octets_written; - if (octets_this_chunk > Chunk) - octets_this_chunk = Chunk; + if (octets_this_chunk > _bfd_srec_len) + octets_this_chunk = _bfd_srec_len; address = list->where + octets_written / bfd_octets_per_byte (abfd); @@ -1243,8 +1261,10 @@ srec_print_symbol (bfd *abfd, #define srec_bfd_is_local_label_name bfd_generic_is_local_label_name #define srec_get_lineno _bfd_nosymbols_get_lineno #define srec_find_nearest_line _bfd_nosymbols_find_nearest_line +#define srec_find_line _bfd_nosymbols_find_line #define srec_find_inliner_info _bfd_nosymbols_find_inliner_info #define srec_make_empty_symbol _bfd_generic_make_empty_symbol +#define srec_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string #define srec_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol #define srec_read_minisymbols _bfd_generic_read_minisymbols #define srec_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol @@ -1252,19 +1272,19 @@ srec_print_symbol (bfd *abfd, #define srec_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents #define srec_bfd_relax_section bfd_generic_relax_section #define srec_bfd_gc_sections bfd_generic_gc_sections +#define srec_bfd_lookup_section_flags bfd_generic_lookup_section_flags #define srec_bfd_merge_sections bfd_generic_merge_sections #define srec_bfd_is_group_section bfd_generic_is_group_section #define srec_bfd_discard_group bfd_generic_discard_group #define srec_section_already_linked _bfd_generic_section_already_linked #define srec_bfd_define_common_symbol bfd_generic_define_common_symbol #define srec_bfd_link_hash_table_create _bfd_generic_link_hash_table_create -#define srec_bfd_link_hash_table_free _bfd_generic_link_hash_table_free #define srec_bfd_link_add_symbols _bfd_generic_link_add_symbols #define srec_bfd_link_just_syms _bfd_generic_link_just_syms -#define srec_bfd_copy_link_hash_symbol_type \ - _bfd_generic_copy_link_hash_symbol_type +#define srec_bfd_copy_link_hash_symbol_type _bfd_generic_copy_link_hash_symbol_type #define srec_bfd_final_link _bfd_generic_final_link #define srec_bfd_link_split_section _bfd_generic_link_split_section +#define srec_bfd_link_check_relocs _bfd_generic_link_check_relocs const bfd_target srec_vec = { @@ -1280,6 +1300,7 @@ const bfd_target srec_vec = 0, /* Leading underscore. */ ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ + 0, /* match priority. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ @@ -1335,6 +1356,7 @@ const bfd_target symbolsrec_vec = 0, /* Leading underscore. */ ' ', /* AR_pad_char. */ 16, /* AR_max_namelen. */ + 0, /* match priority. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */