aboutsummaryrefslogtreecommitdiff
path: root/binutils/readelf.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2004-06-22 07:58:53 +0000
committerAlan Modra <amodra@gmail.com>2004-06-22 07:58:53 +0000
commit86dba8ee8a31d6d427240ce9b9629ab5e6aadf67 (patch)
tree838e2c28c2d7201c2e6dd9ac072d6971543c7dc2 /binutils/readelf.c
parentbf8b15af149f2508101cf02c171fa817325230bf (diff)
downloadgdb-86dba8ee8a31d6d427240ce9b9629ab5e6aadf67.zip
gdb-86dba8ee8a31d6d427240ce9b9629ab5e6aadf67.tar.gz
gdb-86dba8ee8a31d6d427240ce9b9629ab5e6aadf67.tar.bz2
* readelf.c (dynamic_nent): New variable.
(get_32bit_dynamic_section): Set it. (get_64bit_dynamic_section): Here too. (process_dynamic_section): Use it instead of dynamic_size. (process_syminfo): Likewise.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r--binutils/readelf.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 2739877..3cd6ffb 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -119,6 +119,7 @@ long archive_file_offset;
unsigned long archive_file_size;
unsigned long dynamic_addr;
bfd_size_type dynamic_size;
+unsigned int dynamic_nent;
char *dynamic_strings;
char *string_table;
unsigned long string_table_length;
@@ -4664,7 +4665,8 @@ get_32bit_dynamic_section (FILE *file)
if (!edyn)
return 0;
- dynamic_section = malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
+ dynamic_nent = dynamic_size / sizeof (*ext);
+ dynamic_section = malloc (dynamic_nent * sizeof (*entry));
if (dynamic_section == NULL)
{
@@ -4697,7 +4699,8 @@ get_64bit_dynamic_section (FILE *file)
if (!edyn)
return 0;
- dynamic_section = malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
+ dynamic_nent = dynamic_size / sizeof (*ext);
+ dynamic_section = malloc (dynamic_nent * sizeof (*entry));
if (dynamic_section == NULL)
{
@@ -4757,7 +4760,6 @@ static int
process_dynamic_section (FILE *file)
{
Elf_Internal_Dyn *entry;
- bfd_size_type i;
if (dynamic_size == 0)
{
@@ -4778,9 +4780,9 @@ process_dynamic_section (FILE *file)
/* Find the appropriate symbol table. */
if (dynamic_symbols == NULL)
{
- for (i = 0, entry = dynamic_section;
- i < dynamic_size;
- ++i, ++entry)
+ for (entry = dynamic_section;
+ entry < dynamic_section + dynamic_nent;
+ ++entry)
{
Elf_Internal_Shdr section;
@@ -4824,9 +4826,9 @@ process_dynamic_section (FILE *file)
/* Similarly find a string table. */
if (dynamic_strings == NULL)
{
- for (i = 0, entry = dynamic_section;
- i < dynamic_size;
- ++i, ++entry)
+ for (entry = dynamic_section;
+ entry < dynamic_section + dynamic_nent;
+ ++entry)
{
unsigned long offset;
long str_tab_len;
@@ -4870,9 +4872,9 @@ process_dynamic_section (FILE *file)
{
unsigned long syminsz = 0;
- for (i = 0, entry = dynamic_section;
- i < dynamic_size;
- ++i, ++entry)
+ for (entry = dynamic_section;
+ entry < dynamic_section + dynamic_nent;
+ ++entry)
{
if (entry->d_tag == DT_SYMINENT)
{
@@ -4889,7 +4891,7 @@ process_dynamic_section (FILE *file)
if (dynamic_syminfo_offset != 0 && syminsz != 0)
{
- Elf_External_Syminfo *extsyminfo;
+ Elf_External_Syminfo *extsyminfo, *extsym;
Elf_Internal_Syminfo *syminfo;
/* There is a syminfo section. Read the data. */
@@ -4906,11 +4908,12 @@ process_dynamic_section (FILE *file)
}
dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
- for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
- ++i, ++syminfo)
+ for (syminfo = dynamic_syminfo, extsym = extsyminfo;
+ syminfo < dynamic_syminfo + dynamic_syminfo_nent;
+ ++syminfo, ++extsym)
{
- syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
- syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
+ syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
+ syminfo->si_flags = BYTE_GET (extsym->si_flags);
}
free (extsyminfo);
@@ -4918,14 +4921,14 @@ process_dynamic_section (FILE *file)
}
if (do_dynamic && dynamic_addr)
- printf (_("\nDynamic section at offset 0x%lx contains %ld entries:\n"),
- dynamic_addr, (long) dynamic_size);
+ printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
+ dynamic_addr, dynamic_nent);
if (do_dynamic)
printf (_(" Tag Type Name/Value\n"));
- for (i = 0, entry = dynamic_section;
- i < dynamic_size;
- i++, entry++)
+ for (entry = dynamic_section;
+ entry < dynamic_section + dynamic_nent;
+ entry++)
{
if (do_dynamic)
{
@@ -6282,7 +6285,7 @@ process_syminfo (FILE *file ATTRIBUTE_UNUSED)
break;
default:
if (dynamic_syminfo[i].si_boundto > 0
- && dynamic_syminfo[i].si_boundto < dynamic_size)
+ && dynamic_syminfo[i].si_boundto < dynamic_nent)
{
print_symbol (10,
dynamic_strings