aboutsummaryrefslogtreecommitdiff
path: root/bfd/ecofflink.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2001-09-18 09:57:26 +0000
committerAlan Modra <amodra@gmail.com>2001-09-18 09:57:26 +0000
commitdc810e3900d47ab2eea86d50231ff2e70b596847 (patch)
tree13fc3d267fb99c450380f08a0775b2dff076b8d7 /bfd/ecofflink.c
parent417412a27c87b0e738a21122a38d48aa35317eb8 (diff)
downloadgdb-dc810e3900d47ab2eea86d50231ff2e70b596847.zip
gdb-dc810e3900d47ab2eea86d50231ff2e70b596847.tar.gz
gdb-dc810e3900d47ab2eea86d50231ff2e70b596847.tar.bz2
Touches most files in bfd/, so likely will be blamed for everything..
o bfd_read and bfd_write lose an unnecessary param and become bfd_bread and bfd_bwrite. o bfd_*alloc now all take a bfd_size_type arg, and will error if size_t is too small. eg. 32 bit host, 64 bit bfd, verrry big files or bugs in linker scripts etc. o file_ptr becomes a bfd_signed_vma. Besides matching sizes with various other types involved in handling sections, this should make it easier for bfd to support a 64 bit off_t on 32 bit hosts that provide it. o I've made the H_GET_* and H_PUT_* macros (which invoke bfd_h_{get,put}_*) generally available. They now cast their args to bfd_vma and bfd_byte * as appropriate, which removes a swag of casts from the source. o Bug fixes to bfd_get8, aix386_core_vec, elf32_h8_relax_section, and aout-encap.c. o Zillions of formatting and -Wconversion fixes.
Diffstat (limited to 'bfd/ecofflink.c')
-rw-r--r--bfd/ecofflink.c120
1 files changed, 64 insertions, 56 deletions
diff --git a/bfd/ecofflink.c b/bfd/ecofflink.c
index 37b3538..633a9e6 100644
--- a/bfd/ecofflink.c
+++ b/bfd/ecofflink.c
@@ -1,5 +1,5 @@
/* Routines to link ECOFF debugging information.
- Copyright 1993, 1994, 1995, 1996, 1997, 2000
+ Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001
Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
@@ -272,7 +272,7 @@ ecoff_add_bytes (buf, bufend, need)
if (want < ALLOC_SIZE)
want = ALLOC_SIZE;
}
- newbuf = (char *) bfd_realloc (*buf, have + want);
+ newbuf = (char *) bfd_realloc (*buf, (bfd_size_type) have + want);
if (newbuf == NULL)
return false;
*buf = newbuf;
@@ -497,8 +497,9 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
struct bfd_link_info *info;
{
struct accumulate *ainfo;
+ bfd_size_type amt = sizeof (struct accumulate);
- ainfo = (struct accumulate *) bfd_malloc (sizeof (struct accumulate));
+ ainfo = (struct accumulate *) bfd_malloc (amt);
if (!ainfo)
return NULL;
if (! bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
@@ -621,6 +622,7 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
long newrfdbase = 0;
long oldrfdbase = 0;
bfd_byte *fdr_out;
+ bfd_size_type amt;
/* Use section_adjust to hold the value to add to a symbol in a
particular section. */
@@ -661,9 +663,9 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
}
fdr_end = fdr_start + input_symhdr->ifdMax * fdr_add;
- input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd,
- (input_symhdr->ifdMax
- * sizeof (RFDT)));
+ amt = input_symhdr->ifdMax;
+ amt *= sizeof (RFDT);
+ input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd, amt);
sz = (input_symhdr->crfd + input_symhdr->ifdMax) * external_rfd_size;
rfd_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
@@ -712,7 +714,7 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
merged. */
name = input_debug->ss + fdr.issBase + fdr.rss;
- lookup = (char *) bfd_malloc (strlen (name) + 20);
+ lookup = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 20);
if (lookup == NULL)
return false;
sprintf (lookup, "%s %lx %lx", name, fdr.csym, fdr.caux);
@@ -937,10 +939,9 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
stabs are adjusted correctly. */
if (fdr.cbLine > 0)
{
+ file_ptr pos = input_symhdr->cbLineOffset + fdr.cbLineOffset;
if (!add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
- input_bfd,
- input_symhdr->cbLineOffset + fdr.cbLineOffset,
- fdr.cbLine))
+ input_bfd, pos, (unsigned long) fdr.cbLine))
return false;
fdr.ilineBase = output_symhdr->ilineMax;
fdr.cbLineOffset = output_symhdr->cbLine;
@@ -949,10 +950,10 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
}
if (fdr.caux > 0)
{
+ file_ptr pos = (input_symhdr->cbAuxOffset
+ + fdr.iauxBase * sizeof (union aux_ext));
if (!add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
- input_bfd,
- (input_symhdr->cbAuxOffset
- + fdr.iauxBase * sizeof (union aux_ext)),
+ input_bfd, pos,
fdr.caux * sizeof (union aux_ext)))
return false;
fdr.iauxBase = output_symhdr->iauxMax;
@@ -970,10 +971,9 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
}
else if (fdr.cbSs > 0)
{
+ file_ptr pos = input_symhdr->cbSsOffset + fdr.issBase;
if (!add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
- input_bfd,
- input_symhdr->cbSsOffset + fdr.issBase,
- fdr.cbSs))
+ input_bfd, pos, (unsigned long) fdr.cbSs))
return false;
fdr.issBase = output_symhdr->issMax;
output_symhdr->issMax += fdr.cbSs;
@@ -989,21 +989,21 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
BFD_ASSERT (external_pdr_size == input_swap->external_pdr_size);
if (fdr.cpd > 0)
{
+ file_ptr pos = (input_symhdr->cbPdOffset
+ + fdr.ipdFirst * external_pdr_size);
+ unsigned long size = fdr.cpd * external_pdr_size;
if (!add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
- input_bfd,
- (input_symhdr->cbPdOffset
- + fdr.ipdFirst * external_pdr_size),
- fdr.cpd * external_pdr_size))
+ input_bfd, pos, size))
return false;
}
BFD_ASSERT (external_opt_size == input_swap->external_opt_size);
if (fdr.copt > 0)
{
+ file_ptr pos = (input_symhdr->cbOptOffset
+ + fdr.ioptBase * external_opt_size);
+ unsigned long size = fdr.copt * external_opt_size;
if (!add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
- input_bfd,
- (input_symhdr->cbOptOffset
- + fdr.ioptBase * external_opt_size),
- fdr.copt * external_opt_size))
+ input_bfd, pos, size))
return false;
}
}
@@ -1210,7 +1210,7 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
symsize = bfd_get_symtab_upper_bound (input_bfd);
if (symsize < 0)
return false;
- symbols = (asymbol **) bfd_alloc (output_bfd, symsize);
+ symbols = (asymbol **) bfd_alloc (output_bfd, (bfd_size_type) symsize);
if (symbols == (asymbol **) NULL)
return false;
symcount = bfd_canonicalize_symtab (input_bfd, symbols);
@@ -1254,7 +1254,8 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
}
(*swap_sym_out) (output_bfd, &internal_sym, external_sym);
add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end,
- external_sym, output_swap->external_sym_size);
+ external_sym,
+ (unsigned long) output_swap->external_sym_size);
++fdr.csym;
++output_symhdr->isymMax;
}
@@ -1274,7 +1275,8 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
}
(*output_swap->swap_fdr_out) (output_bfd, &fdr, external_fdr);
add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end,
- external_fdr, output_swap->external_fdr_size);
+ external_fdr,
+ (unsigned long) output_swap->external_fdr_size);
++output_symhdr->ifdMax;
@@ -1386,7 +1388,7 @@ bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
{
if (ecoff_add_bytes ((char **) &debug->external_ext,
(char **) &debug->external_ext_end,
- (symhdr->iextMax + 1) * external_ext_size)
+ (symhdr->iextMax + 1) * (size_t) external_ext_size)
== false)
return false;
}
@@ -1546,12 +1548,12 @@ ecoff_write_symhdr (abfd, debug, swap, where)
SET (cbExtOffset, iextMax, swap->external_ext_size);
#undef SET
- buff = (PTR) bfd_malloc ((size_t) swap->external_hdr_size);
+ buff = (PTR) bfd_malloc (swap->external_hdr_size);
if (buff == NULL && swap->external_hdr_size != 0)
goto error_return;
(*swap->swap_hdr_out) (abfd, symhdr, buff);
- if (bfd_write (buff, 1, swap->external_hdr_size, abfd)
+ if (bfd_bwrite (buff, swap->external_hdr_size, abfd)
!= swap->external_hdr_size)
goto error_return;
@@ -1585,7 +1587,7 @@ bfd_ecoff_write_debug (abfd, debug, swap, where)
#define WRITE(ptr, count, size, offset) \
BFD_ASSERT (symhdr->offset == 0 \
|| (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
- if (bfd_write ((PTR) debug->ptr, size, symhdr->count, abfd) \
+ if (bfd_bwrite ((PTR) debug->ptr, (bfd_size_type) size * symhdr->count, abfd)\
!= size * symhdr->count) \
return false;
@@ -1594,7 +1596,8 @@ bfd_ecoff_write_debug (abfd, debug, swap, where)
WRITE (external_pdr, ipdMax, swap->external_pdr_size, cbPdOffset);
WRITE (external_sym, isymMax, swap->external_sym_size, cbSymOffset);
WRITE (external_opt, ioptMax, swap->external_opt_size, cbOptOffset);
- WRITE (external_aux, iauxMax, sizeof (union aux_ext), cbAuxOffset);
+ WRITE (external_aux, iauxMax, (bfd_size_type) sizeof (union aux_ext),
+ cbAuxOffset);
WRITE (ss, issMax, sizeof (char), cbSsOffset);
WRITE (ssext, issExtMax, sizeof (char), cbSsExtOffset);
WRITE (external_fdr, ifdMax, swap->external_fdr_size, cbFdOffset);
@@ -1626,14 +1629,16 @@ ecoff_write_shuffle (abfd, swap, shuffle, space)
{
if (! l->filep)
{
- if (bfd_write (l->u.memory, 1, l->size, abfd) != l->size)
+ if (bfd_bwrite (l->u.memory, (bfd_size_type) l->size, abfd)
+ != l->size)
return false;
}
else
{
if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
- || bfd_read (space, 1, l->size, l->u.file.input_bfd) != l->size
- || bfd_write (space, 1, l->size, abfd) != l->size)
+ || bfd_bread (space, (bfd_size_type) l->size,
+ l->u.file.input_bfd) != l->size
+ || bfd_bwrite (space, (bfd_size_type) l->size, abfd) != l->size)
return false;
}
total += l->size;
@@ -1645,12 +1650,12 @@ ecoff_write_shuffle (abfd, swap, shuffle, space)
bfd_byte *s;
i = swap->debug_align - (total & (swap->debug_align - 1));
- s = (bfd_byte *) bfd_malloc (i);
+ s = (bfd_byte *) bfd_malloc ((bfd_size_type) i);
if (s == NULL && i != 0)
return false;
memset ((PTR) s, 0, i);
- if (bfd_write ((PTR) s, 1, i, abfd) != i)
+ if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
{
free (s);
return false;
@@ -1675,11 +1680,13 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
{
struct accumulate *ainfo = (struct accumulate *) handle;
PTR space = NULL;
+ bfd_size_type amt;
if (! ecoff_write_symhdr (abfd, debug, swap, where))
goto error_return;
- space = (PTR) bfd_malloc (ainfo->largest_file_shuffle);
+ amt = ainfo->largest_file_shuffle;
+ space = (PTR) bfd_malloc (amt);
if (space == NULL && ainfo->largest_file_shuffle != 0)
goto error_return;
@@ -1706,7 +1713,7 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
BFD_ASSERT (ainfo->ss == (struct shuffle *) NULL);
null = 0;
- if (bfd_write ((PTR) &null, 1, 1, abfd) != 1)
+ if (bfd_bwrite ((PTR) &null, (bfd_size_type) 1, abfd) != 1)
goto error_return;
total = 1;
BFD_ASSERT (ainfo->ss_hash == NULL || ainfo->ss_hash->val == 1);
@@ -1717,7 +1724,8 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
size_t len;
len = strlen (sh->root.string);
- if (bfd_write ((PTR) sh->root.string, 1, len + 1, abfd) != len + 1)
+ amt = len + 1;
+ if (bfd_bwrite ((PTR) sh->root.string, amt, abfd) != amt)
goto error_return;
total += len + 1;
}
@@ -1728,11 +1736,11 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
bfd_byte *s;
i = swap->debug_align - (total & (swap->debug_align - 1));
- s = (bfd_byte *) bfd_malloc (i);
+ s = (bfd_byte *) bfd_malloc ((bfd_size_type) i);
if (s == NULL && i != 0)
goto error_return;
memset ((PTR) s, 0, i);
- if (bfd_write ((PTR) s, 1, i, abfd) != i)
+ if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
{
free (s);
goto error_return;
@@ -1743,8 +1751,8 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
/* The external strings and symbol are not converted over to using
shuffles. FIXME: They probably should be. */
- if (bfd_write (debug->ssext, 1, debug->symbolic_header.issExtMax, abfd)
- != (bfd_size_type) debug->symbolic_header.issExtMax)
+ amt = debug->symbolic_header.issExtMax;
+ if (bfd_bwrite (debug->ssext, amt, abfd) != amt)
goto error_return;
if ((debug->symbolic_header.issExtMax & (swap->debug_align - 1)) != 0)
{
@@ -1753,11 +1761,11 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
i = (swap->debug_align
- (debug->symbolic_header.issExtMax & (swap->debug_align - 1)));
- s = (bfd_byte *) bfd_malloc (i);
+ s = (bfd_byte *) bfd_malloc ((bfd_size_type) i);
if (s == NULL && i != 0)
goto error_return;
memset ((PTR) s, 0, i);
- if (bfd_write ((PTR) s, 1, i, abfd) != i)
+ if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
{
free (s);
goto error_return;
@@ -1773,9 +1781,8 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
|| (debug->symbolic_header.cbExtOffset
== (bfd_vma) bfd_tell (abfd)));
- if (bfd_write (debug->external_ext, swap->external_ext_size,
- debug->symbolic_header.iextMax, abfd)
- != debug->symbolic_header.iextMax * swap->external_ext_size)
+ amt = debug->symbolic_header.iextMax * swap->external_ext_size;
+ if (bfd_bwrite (debug->external_ext, amt, abfd) != amt)
goto error_return;
if (space != NULL)
@@ -1829,6 +1836,7 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
FDR *fdr_end;
boolean stabs;
long len;
+ bfd_size_type amt;
fdr_start = debug_info->fdr;
fdr_end = fdr_start + debug_info->symbolic_header.ifdMax;
@@ -1843,9 +1851,8 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
/* Now, create and fill in the table: */
- line_info->fdrtab = ((struct ecoff_fdrtab_entry*)
- bfd_zalloc (abfd,
- len * sizeof (struct ecoff_fdrtab_entry)));
+ amt = (bfd_size_type) len * sizeof (struct ecoff_fdrtab_entry);
+ line_info->fdrtab = (struct ecoff_fdrtab_entry*) bfd_zalloc (abfd, amt);
if (line_info->fdrtab == NULL)
return false;
line_info->fdrtab_len = len;
@@ -1902,7 +1909,7 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
The table is mostly sorted already, but there are cases (e.g.,
static functions in include files), where this does not hold.
Use "odump -PFv" to verify... */
- qsort ((PTR) line_info->fdrtab, len,
+ qsort ((PTR) line_info->fdrtab, (size_t) len,
sizeof (struct ecoff_fdrtab_entry), cmp_fdrtab_entry);
return true;
@@ -2004,7 +2011,7 @@ lookup_line (abfd, debug_info, debug_swap, line_info)
char *pdr_ptr;
char *best_pdr = NULL;
FDR *best_fdr;
- bfd_vma best_dist = ~0;
+ bfd_vma best_dist = ~(bfd_vma) 0;
PDR pdr;
unsigned char *line_ptr;
unsigned char *line_end;
@@ -2330,7 +2337,7 @@ lookup_line (abfd, debug_info, debug_swap, line_info)
{
if (line_info->find_buffer != NULL)
free (line_info->find_buffer);
- buffer = (char *) bfd_malloc (len);
+ buffer = (char *) bfd_malloc ((bfd_size_type) len);
if (buffer == NULL)
return false;
line_info->find_buffer = buffer;
@@ -2429,7 +2436,8 @@ ecoff_collect_shuffle (l, buff)
else
{
if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
- || bfd_read (buff, 1, l->size, l->u.file.input_bfd) != l->size)
+ || (bfd_bread (buff, (bfd_size_type) l->size, l->u.file.input_bfd)
+ != l->size))
return false;
}
total += l->size;