/* 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;
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;
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 *))
secinfo = (struct sec_merge_sec_info *) psecinfo;
+ if (!secinfo)
+ return FALSE;
+
if (secinfo->first_str == NULL)
return TRUE;
secinfo = (struct sec_merge_sec_info *) psecinfo;
+ if (!secinfo)
+ return offset;
+
if (offset >= sec->rawsize)
{
if (offset > sec->rawsize)