/* 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 <jakub@redhat.com>.
/* 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;
+ /* FIXME: octets_per_byte. */
pos = sec->output_section->filepos + sec->output_offset;
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0)
return FALSE;
secinfo = (struct sec_merge_sec_info *) psecinfo;
+ if (!secinfo)
+ return offset;
+
if (offset >= sec->rawsize)
{
if (offset > sec->rawsize)