projects
/
deliverable
/
binutils-gdb.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
gas: detect DCTI couples in sparc
[deliverable/binutils-gdb.git]
/
bfd
/
srec.c
diff --git
a/bfd/srec.c
b/bfd/srec.c
index 2b24f46ffb643dc5224b42fc8152079b82997a4a..5fdd68bdd0f8066e019028acb4020a50b024bad5 100644
(file)
--- a/
bfd/srec.c
+++ b/
bfd/srec.c
@@
-1,14
+1,12
@@
/* BFD back-end for s-record objects.
/* BFD back-end for s-record objects.
- Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005
- Free Software Foundation, Inc.
+ Copyright (C) 1990-2016 Free Software Foundation, Inc.
Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version
2
of the License, or
+ the Free Software Foundation; either version
3
of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@
-18,7
+16,9
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
/* SUBSECTION
S-Record handling
/* SUBSECTION
S-Record handling
@@
-101,8
+101,8
@@
We allow symbols to be anywhere in the data stream - the module names
are always ignored. */
We allow symbols to be anywhere in the data stream - the module names
are always ignored. */
-#include "bfd.h"
#include "sysdep.h"
#include "sysdep.h"
+#include "bfd.h"
#include "libbfd.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "libbfd.h"
#include "libiberty.h"
#include "safe-ctype.h"
@@
-196,7
+196,7
@@
srec_mkobject (bfd *abfd)
srec_init ();
srec_init ();
- tdata = bfd_alloc (abfd, sizeof (tdata_type));
+ tdata =
(tdata_type *)
bfd_alloc (abfd, sizeof (tdata_type));
if (tdata == NULL)
return FALSE;
if (tdata == NULL)
return FALSE;
@@
-246,10
+246,10
@@
srec_bad_byte (bfd *abfd,
}
else
{
}
else
{
- char buf[
1
0];
+ char buf[
4
0];
if (! ISPRINT (c))
if (! ISPRINT (c))
- sprintf (buf, "\\%03o", (unsigned int) c);
+ sprintf (buf, "\\%03o", (unsigned int) c
& 0xff
);
else
{
buf[0] = c;
else
{
buf[0] = c;
@@
-269,7
+269,7
@@
srec_new_symbol (bfd *abfd, const char *name, bfd_vma val)
{
struct srec_symbol *n;
{
struct srec_symbol *n;
- n = bfd_alloc (abfd, sizeof (* n));
+ n =
(struct srec_symbol *)
bfd_alloc (abfd, sizeof (* n));
if (n == NULL)
return FALSE;
if (n == NULL)
return FALSE;
@@
-361,7
+361,7
@@
srec_scan (bfd *abfd)
}
alc = 10;
}
alc = 10;
- symbuf = bfd_malloc (alc + 1);
+ symbuf =
(char *)
bfd_malloc (alc + 1);
if (symbuf == NULL)
goto error_return;
if (symbuf == NULL)
goto error_return;
@@
-376,7
+376,7
@@
srec_scan (bfd *abfd)
char *n;
alc *= 2;
char *n;
alc *= 2;
- n = bfd_realloc (symbuf, alc + 1);
+ n =
(char *)
bfd_realloc (symbuf, alc + 1);
if (n == NULL)
goto error_return;
p = n + (p - symbuf);
if (n == NULL)
goto error_return;
p = n + (p - symbuf);
@@
-393,7
+393,7
@@
srec_scan (bfd *abfd)
}
*p++ = '\0';
}
*p++ = '\0';
- symname = bfd_alloc (abfd, (bfd_size_type) (p - symbuf));
+ symname =
(char *)
bfd_alloc (abfd, (bfd_size_type) (p - symbuf));
if (symname == NULL)
goto error_return;
strcpy (symname, symbuf);
if (symname == NULL)
goto error_return;
strcpy (symname, symbuf);
@@
-426,6
+426,11
@@
srec_scan (bfd *abfd)
symval <<= 4;
symval += NIBBLE (c);
c = srec_get_byte (abfd, &error);
symval <<= 4;
symval += NIBBLE (c);
c = srec_get_byte (abfd, &error);
+ if (c == EOF)
+ {
+ srec_bad_byte (abfd, lineno, c, error);
+ goto error_return;
+ }
}
if (! srec_new_symbol (abfd, symname, symval))
}
if (! srec_new_symbol (abfd, symname, symval))
@@
-447,10
+452,11
@@
srec_scan (bfd *abfd)
case 'S':
{
file_ptr pos;
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;
bfd_vma address;
bfd_byte *data;
+ unsigned char check_sum;
/* Starting an S-record. */
/* Starting an S-record. */
@@
-469,12
+475,25
@@
srec_scan (bfd *abfd)
goto error_return;
}
goto error_return;
}
- bytes = HEX (hdr + 1);
+ 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)
+ {
+ (*_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)
free (buf);
if (bytes * 2 > bufsize)
{
if (buf != NULL)
free (buf);
- buf = bfd_malloc ((bfd_size_type) bytes * 2);
+ buf =
(bfd_byte *)
bfd_malloc ((bfd_size_type) bytes * 2);
if (buf == NULL)
goto error_return;
bufsize = bytes * 2;
if (buf == NULL)
goto error_return;
bufsize = bytes * 2;
@@
-498,18
+517,22
@@
srec_scan (bfd *abfd)
break;
case '3':
break;
case '3':
+ check_sum += HEX (data);
address = HEX (data);
data += 2;
--bytes;
/* Fall through. */
case '2':
address = HEX (data);
data += 2;
--bytes;
/* Fall through. */
case '2':
+ check_sum += HEX (data);
address = (address << 8) | HEX (data);
data += 2;
--bytes;
/* Fall through. */
case '1':
address = (address << 8) | HEX (data);
data += 2;
--bytes;
/* Fall through. */
case '1':
+ check_sum += HEX (data);
address = (address << 8) | HEX (data);
data += 2;
address = (address << 8) | HEX (data);
data += 2;
+ check_sum += HEX (data);
address = (address << 8) | HEX (data);
data += 2;
bytes -= 2;
address = (address << 8) | HEX (data);
data += 2;
bytes -= 2;
@@
-526,39
+549,71
@@
srec_scan (bfd *abfd)
char secbuf[20];
char *secname;
bfd_size_type amt;
char secbuf[20];
char *secname;
bfd_size_type amt;
+ flagword flags;
sprintf (secbuf, ".sec%d", bfd_count_sections (abfd) + 1);
amt = strlen (secbuf) + 1;
sprintf (secbuf, ".sec%d", bfd_count_sections (abfd) + 1);
amt = strlen (secbuf) + 1;
- secname = bfd_alloc (abfd, amt);
+ secname =
(char *)
bfd_alloc (abfd, amt);
strcpy (secname, secbuf);
strcpy (secname, secbuf);
- sec = bfd_make_section (abfd, secname);
+ flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
+ sec = bfd_make_section_with_flags (abfd, secname, flags);
if (sec == NULL)
goto error_return;
if (sec == NULL)
goto error_return;
- sec->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
sec->vma = address;
sec->lma = address;
sec->size = bytes;
sec->filepos = pos;
}
sec->vma = address;
sec->lma = address;
sec->size = bytes;
sec->filepos = pos;
}
+
+ while (bytes > 0)
+ {
+ check_sum += HEX (data);
+ data += 2;
+ bytes--;
+ }
+ check_sum = 255 - (check_sum & 0xff);
+ if (check_sum != HEX (data))
+ {
+ (*_bfd_error_handler)
+ (_("%B:%d: Bad checksum in S-record file\n"),
+ abfd, lineno);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
break;
case '7':
break;
case '7':
+ check_sum += HEX (data);
address = HEX (data);
data += 2;
/* Fall through. */
case '8':
address = HEX (data);
data += 2;
/* Fall through. */
case '8':
+ check_sum += HEX (data);
address = (address << 8) | HEX (data);
data += 2;
/* Fall through. */
case '9':
address = (address << 8) | HEX (data);
data += 2;
/* Fall through. */
case '9':
+ check_sum += HEX (data);
address = (address << 8) | HEX (data);
data += 2;
address = (address << 8) | HEX (data);
data += 2;
+ check_sum += HEX (data);
address = (address << 8) | HEX (data);
data += 2;
/* This is a termination record. */
abfd->start_address = address;
address = (address << 8) | HEX (data);
data += 2;
/* This is a termination record. */
abfd->start_address = address;
+ check_sum = 255 - (check_sum & 0xff);
+ if (check_sum != HEX (data))
+ {
+ (*_bfd_error_handler)
+ (_("%B:%d: Bad checksum in S-record file\n"),
+ abfd, lineno);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
if (buf != NULL)
free (buf);
if (buf != NULL)
free (buf);
@@
-694,7
+749,7
@@
srec_read_section (bfd *abfd, asection *section, bfd_byte *contents)
{
if (buf != NULL)
free (buf);
{
if (buf != NULL)
free (buf);
- buf = bfd_malloc ((bfd_size_type) bytes * 2);
+ buf =
(bfd_byte *)
bfd_malloc ((bfd_size_type) bytes * 2);
if (buf == NULL)
goto error_return;
bufsize = bytes * 2;
if (buf == NULL)
goto error_return;
bufsize = bytes * 2;
@@
-778,13
+833,24
@@
srec_get_section_contents (bfd *abfd,
file_ptr offset,
bfd_size_type count)
{
file_ptr offset,
bfd_size_type count)
{
+ if (count == 0)
+ return TRUE;
+
+ if (offset + count < count
+ || offset + count > section->size)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return FALSE;
+ }
+
if (section->used_by_bfd == NULL)
{
section->used_by_bfd = bfd_alloc (abfd, section->size);
if (section->used_by_bfd == NULL)
{
section->used_by_bfd = bfd_alloc (abfd, section->size);
- if (section->used_by_bfd == NULL
&& section->size != 0
)
+ if (section->used_by_bfd == NULL)
return FALSE;
return FALSE;
- if (! srec_read_section (abfd, section, section->used_by_bfd))
+ if (! srec_read_section (abfd, section,
+ (bfd_byte *) section->used_by_bfd))
return FALSE;
}
return FALSE;
}
@@
-815,10
+881,11
@@
srec_set_section_contents (bfd *abfd,
file_ptr offset,
bfd_size_type bytes_to_do)
{
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;
tdata_type *tdata = abfd->tdata.srec_data;
srec_data_list_type *entry;
- entry = bfd_alloc (abfd, sizeof (* entry));
+ entry =
(srec_data_list_type *)
bfd_alloc (abfd, sizeof (* entry));
if (entry == NULL)
return FALSE;
if (entry == NULL)
return FALSE;
@@
-828,7
+895,7
@@
srec_set_section_contents (bfd *abfd,
{
bfd_byte *data;
{
bfd_byte *data;
- data = bfd_alloc (abfd, bytes_to_do);
+ data =
(bfd_byte *)
bfd_alloc (abfd, bytes_to_do);
if (data == NULL)
return FALSE;
memcpy ((void *) data, location, (size_t) bytes_to_do);
if (data == NULL)
return FALSE;
memcpy ((void *) data, location, (size_t) bytes_to_do);
@@
-837,16
+904,16
@@
srec_set_section_contents (bfd *abfd,
regardless of the siez of the addresses. */
if (S3Forced)
tdata->type = 3;
regardless of the siez of the addresses. */
if (S3Forced)
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. */
; /* 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;
&& 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
entry->size = bytes_to_do;
/* Sort the records by address. Optimize for the common case of
@@
-1099,7
+1166,7
@@
symbolsrec_write_object_contents (bfd *abfd)
static int
srec_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
static int
srec_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
-
bfd_boolean exec
ATTRIBUTE_UNUSED)
+
struct bfd_link_info *info
ATTRIBUTE_UNUSED)
{
return 0;
}
{
return 0;
}
@@
-1122,14
+1189,14
@@
srec_canonicalize_symtab (bfd *abfd, asymbol **alocation)
unsigned int i;
csymbols = abfd->tdata.srec_data->csymbols;
unsigned int i;
csymbols = abfd->tdata.srec_data->csymbols;
- if (csymbols == NULL)
+ if (csymbols == NULL
&& symcount != 0
)
{
asymbol *c;
struct srec_symbol *s;
{
asymbol *c;
struct srec_symbol *s;
- csymbols = bfd_alloc (abfd, symcount * sizeof (asymbol));
- if (csymbols == NULL
&& symcount != 0
)
- return
0
;
+ csymbols =
(asymbol *)
bfd_alloc (abfd, symcount * sizeof (asymbol));
+ if (csymbols == NULL)
+ return
-1
;
abfd->tdata.srec_data->csymbols = csymbols;
for (s = abfd->tdata.srec_data->symbols, c = csymbols;
abfd->tdata.srec_data->csymbols = csymbols;
for (s = abfd->tdata.srec_data->symbols, c = csymbols;
@@
-1188,28
+1255,30
@@
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_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_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
#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
-#define srec_get_reloc_upper_bound ((long (*) (bfd *, asection *)) bfd_0l)
-#define srec_canonicalize_reloc ((long (*) (bfd *, asection *, arelent **, asymbol **)) bfd_0l)
-#define srec_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
#define srec_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
#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_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
#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_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_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_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_final_link _bfd_generic_final_link
#define srec_bfd_link_split_section _bfd_generic_link_split_section
#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 =
{
const bfd_target srec_vec =
{
@@
-1225,6
+1294,7
@@
const bfd_target srec_vec =
0, /* Leading underscore. */
' ', /* AR_pad_char. */
16, /* AR_max_namelen. */
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. */
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. */
@@
-1256,7
+1326,7
@@
const bfd_target srec_vec =
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
BFD_JUMP_TABLE_SYMBOLS (srec),
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
BFD_JUMP_TABLE_SYMBOLS (srec),
- BFD_JUMP_TABLE_RELOCS (
srec
),
+ BFD_JUMP_TABLE_RELOCS (
_bfd_norelocs
),
BFD_JUMP_TABLE_WRITE (srec),
BFD_JUMP_TABLE_LINK (srec),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
BFD_JUMP_TABLE_WRITE (srec),
BFD_JUMP_TABLE_LINK (srec),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
@@
-1280,6
+1350,7
@@
const bfd_target symbolsrec_vec =
0, /* Leading underscore. */
' ', /* AR_pad_char. */
16, /* AR_max_namelen. */
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. */
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. */
@@
-1311,7
+1382,7
@@
const bfd_target symbolsrec_vec =
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
BFD_JUMP_TABLE_SYMBOLS (srec),
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
BFD_JUMP_TABLE_SYMBOLS (srec),
- BFD_JUMP_TABLE_RELOCS (
srec
),
+ BFD_JUMP_TABLE_RELOCS (
_bfd_norelocs
),
BFD_JUMP_TABLE_WRITE (srec),
BFD_JUMP_TABLE_LINK (srec),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
BFD_JUMP_TABLE_WRITE (srec),
BFD_JUMP_TABLE_LINK (srec),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
This page took
0.041353 seconds
and
4
git commands to generate.