X-Git-Url: https://oss.titaniummirror.com/gitweb?p=msp430-binutils.git;a=blobdiff_plain;f=bfd%2Fmerge.c;fp=bfd%2Fmerge.c;h=80f80b83a00407f3a8d088ae3cbfadb6501bbbd9;hp=2e805c770e3e6314c3a1065cac037fc01f37bc66;hb=88750007d7869f178f0ba528f41efd3b74c424cf;hpb=6df9443a374e2b81278c61b8afc0a1eef7db280b diff --git a/bfd/merge.c b/bfd/merge.c index 2e805c7..80f80b8 100644 --- a/bfd/merge.c +++ b/bfd/merge.c @@ -1,5 +1,5 @@ /* SEC_MERGE support. - Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Jakub Jelinek . @@ -108,7 +108,8 @@ sec_merge_hash_newfunc (struct bfd_hash_entry *entry, /* Allocate the structure if it has not already been allocated by a subclass. */ if (entry == NULL) - entry = bfd_hash_allocate (table, sizeof (struct sec_merge_hash_entry)); + entry = (struct bfd_hash_entry *) + bfd_hash_allocate (table, sizeof (struct sec_merge_hash_entry)); if (entry == NULL) return NULL; @@ -220,16 +221,11 @@ sec_merge_hash_lookup (struct sec_merge_hash *table, const char *string, return NULL; hashp = ((struct sec_merge_hash_entry *) - sec_merge_hash_newfunc (NULL, &table->table, string)); + bfd_hash_insert (&table->table, string, hash)); if (hashp == NULL) return NULL; - hashp->root.string = string; - hashp->root.hash = hash; hashp->len = len; hashp->alignment = alignment; - hashp->root.next = table->table.table[index]; - table->table.table[index] = (struct bfd_hash_entry *) hashp; - return hashp; } @@ -240,7 +236,7 @@ sec_merge_init (unsigned int entsize, bfd_boolean strings) { struct sec_merge_hash *table; - table = bfd_malloc (sizeof (struct sec_merge_hash)); + table = (struct sec_merge_hash *) bfd_malloc (sizeof (struct sec_merge_hash)); if (table == NULL) return NULL; @@ -298,7 +294,7 @@ sec_merge_emit (bfd *abfd, struct sec_merge_hash_entry *entry) if (alignment_power) { - pad = bfd_zmalloc ((bfd_size_type) 1 << alignment_power); + pad = (char *) bfd_zmalloc ((bfd_size_type) 1 << alignment_power); if (pad == NULL) return FALSE; } @@ -395,7 +391,8 @@ _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, if (sinfo == NULL) { /* Initialize the information we need to keep track of. */ - sinfo = bfd_alloc (abfd, sizeof (struct sec_merge_info)); + sinfo = (struct sec_merge_info *) + bfd_alloc (abfd, sizeof (struct sec_merge_info)); if (sinfo == NULL) goto error_return; sinfo->next = (struct sec_merge_info *) *psinfo; @@ -408,7 +405,12 @@ _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, /* Read the section from abfd. */ - amt = sizeof (struct sec_merge_sec_info) + sec->size - 1; + amt = sizeof (struct sec_merge_sec_info) - 1 + sec->size; + if (sec->flags & SEC_STRINGS) + /* Some versions of gcc may emit a string without a zero terminator. + See http://gcc.gnu.org/ml/gcc-patches/2006-06/msg01004.html + Allocate space for an extra zero. */ + amt += sec->entsize; *psecinfo = bfd_alloc (abfd, amt); if (*psecinfo == NULL) goto error_return; @@ -428,6 +430,8 @@ _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, secinfo->first_str = NULL; sec->rawsize = sec->size; + if (sec->flags & SEC_STRINGS) + memset (secinfo->contents + sec->size, 0, sec->entsize); if (! bfd_get_section_contents (sec->owner, sec, secinfo->contents, 0, sec->size)) goto error_return; @@ -599,7 +603,7 @@ merge_strings (struct sec_merge_info *sinfo) /* Now sort the strings */ amt = sinfo->htab->size * sizeof (struct sec_merge_hash_entry *); - array = bfd_malloc (amt); + array = (struct sec_merge_hash_entry **) bfd_malloc (amt); if (array == NULL) goto alloc_failure; @@ -700,7 +704,7 @@ alloc_failure: with _bfd_merge_section. */ bfd_boolean -_bfd_merge_sections (bfd *abfd ATTRIBUTE_UNUSED, +_bfd_merge_sections (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED, void *xsinfo, void (*remove_hook) (bfd *, asection *)) @@ -784,9 +788,13 @@ _bfd_write_merged_section (bfd *output_bfd, asection *sec, void *psecinfo) secinfo = (struct sec_merge_sec_info *) psecinfo; + if (!secinfo) + return FALSE; + if (secinfo->first_str == NULL) return TRUE; + /* FIXME: octets_per_byte. */ pos = sec->output_section->filepos + sec->output_offset; if (bfd_seek (output_bfd, pos, SEEK_SET) != 0) return FALSE; @@ -812,6 +820,9 @@ _bfd_merged_section_offset (bfd *output_bfd ATTRIBUTE_UNUSED, asection **psec, secinfo = (struct sec_merge_sec_info *) psecinfo; + if (!secinfo) + return offset; + if (offset >= sec->rawsize) { if (offset > sec->rawsize)