aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf-strtab.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2016-06-11 17:22:55 +0930
committerAlan Modra <amodra@gmail.com>2016-06-11 17:24:56 +0930
commitef53be89160126f2fa5dec8f1ec3bd6d99fb0681 (patch)
tree7fa2f5a6331b3bb50d3cca67af00b835d7ddfde6 /bfd/elf-strtab.c
parentde5b02b698cb34f1a7f7f0be87d140f88297da0e (diff)
downloadfsf-binutils-gdb-ef53be89160126f2fa5dec8f1ec3bd6d99fb0681.zip
fsf-binutils-gdb-ef53be89160126f2fa5dec8f1ec3bd6d99fb0681.tar.gz
fsf-binutils-gdb-ef53be89160126f2fa5dec8f1ec3bd6d99fb0681.tar.bz2
Use size_t rather than bfd_size_type
I noticed when writing _bfd_elf_strtab_save/restore that size_t would be better than bfd_size_type for a number of things in elf-strtab.c. Using a 64-bit bfd_size_type on a 32-bit host doesn't make much sense for array sizes and indices. * elf-strtab.c (struct strtab_save): Use size_t for "size". (struct elf_strtab_hash): Likewise for "size" and "alloced". (_bfd_elf_strtab_init): Formatting. (_bfd_elf_strtab_add): Return size_t rather than bfd_size_type. (_bfd_elf_strtab_addref): Take size_t idx param. (_bfd_elf_strtab_delref, _bfd_elf_strtab_refcount): Likewise. (_bfd_elf_strtab_offset): Likewise. (_bfd_elf_strtab_clear_all_refs): Use size_t idx. (_bfd_elf_strtab_save): Use size_t "idx" and "size" vars. (_bfd_elf_strtab_restore, _bfd_elf_strtab_emit): Similarly. (_bfd_elf_strtab_finalize): Similarly. * elf-bfd.h (_bfd_elf_strtab_add): Update prototypes. (_bfd_elf_strtab_addref, _bfd_elf_strtab_delref): Likewise. (_bfd_elf_strtab_refcount, _bfd_elf_strtab_offset): Likewise. * elf.c (bfd_elf_get_elf_syms): Calculate symbol buffer size using bfd_size_type. (bfd_section_from_shdr): Delete amt. (_bfd_elf_init_reloc_shdr): Likewise. (_bfd_elf_link_assign_sym_version): Likewise. (assign_section_numbers): Use size_t reloc_count. * elflink.c (struct elf_symbuf_head): Use size_t "count". (bfd_elf_link_record_dynamic_symbol): Use size_t for some vars. (elf_link_is_defined_archive_symbol): Likewise. (elf_add_dt_needed_tag): Likewise. (elf_finalize_dynstr): Likewise. (elf_link_add_object_symbols): Likewise. (bfd_elf_size_dynamic_sections): Likewise. (elf_create_symbuf): Similarly. (bfd_elf_match_symbols_in_sections): Likewise. (elf_link_swap_symbols_out): Likewise. (elf_link_check_versioned_symbol): Likewise. (bfd_elf_gc_record_vtinherit): Likewise. (bfd_elf_gc_common_finalize_got_offsets): Likewise.
Diffstat (limited to 'bfd/elf-strtab.c')
-rw-r--r--bfd/elf-strtab.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/bfd/elf-strtab.c b/bfd/elf-strtab.c
index 19b0ad8..a91a03d 100644
--- a/bfd/elf-strtab.c
+++ b/bfd/elf-strtab.c
@@ -48,9 +48,9 @@ struct elf_strtab_hash
{
struct bfd_hash_table table;
/* Next available index. */
- bfd_size_type size;
+ size_t size;
/* Number of array entries alloced. */
- bfd_size_type alloced;
+ size_t alloced;
/* Final strtab size. */
bfd_size_type sec_size;
/* Array of pointers to strtab entries. */
@@ -112,8 +112,8 @@ _bfd_elf_strtab_init (void)
table->size = 1;
table->alloced = 64;
amt = sizeof (struct elf_strtab_hasn_entry *);
- table->array = (struct elf_strtab_hash_entry **)
- bfd_malloc (table->alloced * amt);
+ table->array = ((struct elf_strtab_hash_entry **)
+ bfd_malloc (table->alloced * amt));
if (table->array == NULL)
{
free (table);
@@ -138,7 +138,7 @@ _bfd_elf_strtab_free (struct elf_strtab_hash *tab)
/* Get the index of an entity in a hash table, adding it if it is not
already present. */
-bfd_size_type
+size_t
_bfd_elf_strtab_add (struct elf_strtab_hash *tab,
const char *str,
bfd_boolean copy)
@@ -155,7 +155,7 @@ _bfd_elf_strtab_add (struct elf_strtab_hash *tab,
bfd_hash_lookup (&tab->table, str, TRUE, copy);
if (entry == NULL)
- return (bfd_size_type) -1;
+ return (size_t) -1;
entry->refcount++;
if (entry->len == 0)
@@ -170,7 +170,7 @@ _bfd_elf_strtab_add (struct elf_strtab_hash *tab,
tab->array = (struct elf_strtab_hash_entry **)
bfd_realloc_or_free (tab->array, tab->alloced * amt);
if (tab->array == NULL)
- return (bfd_size_type) -1;
+ return (size_t) -1;
}
entry->u.index = tab->size++;
@@ -180,9 +180,9 @@ _bfd_elf_strtab_add (struct elf_strtab_hash *tab,
}
void
-_bfd_elf_strtab_addref (struct elf_strtab_hash *tab, bfd_size_type idx)
+_bfd_elf_strtab_addref (struct elf_strtab_hash *tab, size_t idx)
{
- if (idx == 0 || idx == (bfd_size_type) -1)
+ if (idx == 0 || idx == (size_t) -1)
return;
BFD_ASSERT (tab->sec_size == 0);
BFD_ASSERT (idx < tab->size);
@@ -190,9 +190,9 @@ _bfd_elf_strtab_addref (struct elf_strtab_hash *tab, bfd_size_type idx)
}
void
-_bfd_elf_strtab_delref (struct elf_strtab_hash *tab, bfd_size_type idx)
+_bfd_elf_strtab_delref (struct elf_strtab_hash *tab, size_t idx)
{
- if (idx == 0 || idx == (bfd_size_type) -1)
+ if (idx == 0 || idx == (size_t) -1)
return;
BFD_ASSERT (tab->sec_size == 0);
BFD_ASSERT (idx < tab->size);
@@ -201,7 +201,7 @@ _bfd_elf_strtab_delref (struct elf_strtab_hash *tab, bfd_size_type idx)
}
unsigned int
-_bfd_elf_strtab_refcount (struct elf_strtab_hash *tab, bfd_size_type idx)
+_bfd_elf_strtab_refcount (struct elf_strtab_hash *tab, size_t idx)
{
return tab->array[idx]->refcount;
}
@@ -209,7 +209,7 @@ _bfd_elf_strtab_refcount (struct elf_strtab_hash *tab, bfd_size_type idx)
void
_bfd_elf_strtab_clear_all_refs (struct elf_strtab_hash *tab)
{
- bfd_size_type idx;
+ size_t idx;
for (idx = 1; idx < tab->size; idx++)
tab->array[idx]->refcount = 0;
@@ -219,7 +219,7 @@ _bfd_elf_strtab_clear_all_refs (struct elf_strtab_hash *tab)
struct strtab_save
{
- bfd_size_type size;
+ size_t size;
unsigned int refcount[1];
};
@@ -227,7 +227,7 @@ void *
_bfd_elf_strtab_save (struct elf_strtab_hash *tab)
{
struct strtab_save *save;
- bfd_size_type idx, size;
+ size_t idx, size;
size = sizeof (*save) + (tab->size - 1) * sizeof (save->refcount[0]);
save = bfd_malloc (size);
@@ -245,7 +245,7 @@ _bfd_elf_strtab_save (struct elf_strtab_hash *tab)
void
_bfd_elf_strtab_restore (struct elf_strtab_hash *tab, void *buf)
{
- bfd_size_type idx, curr_size = tab->size;
+ size_t idx, curr_size = tab->size;
struct strtab_save *save = (struct strtab_save *) buf;
BFD_ASSERT (tab->sec_size == 0);
@@ -271,7 +271,7 @@ _bfd_elf_strtab_size (struct elf_strtab_hash *tab)
}
bfd_size_type
-_bfd_elf_strtab_offset (struct elf_strtab_hash *tab, bfd_size_type idx)
+_bfd_elf_strtab_offset (struct elf_strtab_hash *tab, size_t idx)
{
struct elf_strtab_hash_entry *entry;
@@ -288,7 +288,8 @@ _bfd_elf_strtab_offset (struct elf_strtab_hash *tab, bfd_size_type idx)
bfd_boolean
_bfd_elf_strtab_emit (register bfd *abfd, struct elf_strtab_hash *tab)
{
- bfd_size_type off = 1, i;
+ bfd_size_type off = 1;
+ size_t i;
if (bfd_bwrite ("", 1, abfd) != 1)
return FALSE;
@@ -358,16 +359,12 @@ void
_bfd_elf_strtab_finalize (struct elf_strtab_hash *tab)
{
struct elf_strtab_hash_entry **array, **a, *e;
- bfd_size_type size, amt;
-
- /* GCC 2.91.66 (egcs-1.1.2) on i386 miscompiles this function when i is
- a 64-bit bfd_size_type: a 64-bit target or --enable-64-bit-bfd.
- Besides, indexing with a long long wouldn't give anything but extra
- cycles. */
- size_t i;
+ bfd_size_type amt, sec_size;
+ size_t size, i;
/* Sort the strings by suffix and length. */
- amt = tab->size * sizeof (struct elf_strtab_hash_entry *);
+ amt = tab->size;
+ amt *= sizeof (struct elf_strtab_hash_entry *);
array = (struct elf_strtab_hash_entry **) bfd_malloc (amt);
if (array == NULL)
goto alloc_failure;
@@ -426,18 +423,18 @@ alloc_failure:
free (array);
/* Assign positions to the strings we want to keep. */
- size = 1;
+ sec_size = 1;
for (i = 1; i < tab->size; ++i)
{
e = tab->array[i];
if (e->refcount && e->len > 0)
{
- e->u.index = size;
- size += e->len;
+ e->u.index = sec_size;
+ sec_size += e->len;
}
}
- tab->sec_size = size;
+ tab->sec_size = sec_size;
/* Adjust the rest. */
for (i = 1; i < tab->size; ++i)