summaryrefslogtreecommitdiffstats
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2009-12-08 03:43:23 +0000
committerAlan Modra <amodra@gmail.com>2009-12-08 03:43:23 +0000
commit3281215912fb595a0530d0abe2bffe4513fc8d6b (patch)
tree06f7f64654520a2f6ced29f2e585d79590ede83c /bfd
parent087d837e042af03a607f1974d32929a129eef806 (diff)
downloadppe42-binutils-3281215912fb595a0530d0abe2bffe4513fc8d6b.tar.gz
ppe42-binutils-3281215912fb595a0530d0abe2bffe4513fc8d6b.zip
* elf.c (write_zeros): New function.
(assign_file_positions_for_load_sections): Allocate file space for NOBITS sections that are followed by PROGBITS sections in a segment.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/elf.c25
2 files changed, 31 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 00ae4cf130..6cbee4ac7b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2009-12-08 Alan Modra <amodra@bigpond.net.au>
+
+ * elf.c (write_zeros): New function.
+ (assign_file_positions_for_load_sections): Allocate file space for
+ NOBITS sections that are followed by PROGBITS sections in a segment.
+
2009-12-03 Tristan Gingold <gingold@adacore.com>
* mach-o.c (bfd_mach_o_make_bfd_section): Force debug flags for
diff --git a/bfd/elf.c b/bfd/elf.c
index 4a329294ce..88ebf71926 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4127,6 +4127,22 @@ print_segment_map (const struct elf_segment_map *m)
putc ('\n',stderr);
}
+static bfd_boolean
+write_zeros (bfd *abfd, file_ptr pos, bfd_size_type len)
+{
+ void *buf;
+ bfd_boolean ret;
+
+ if (bfd_seek (abfd, pos, SEEK_SET) != 0)
+ return FALSE;
+ buf = bfd_zmalloc (len);
+ if (buf == NULL)
+ return FALSE;
+ ret = bfd_bwrite (buf, len, abfd) == len;
+ free (buf);
+ return ret;
+}
+
/* Assign file positions to the sections based on the mapping from
sections to segments. This function also sets up some fields in
the file header. */
@@ -4448,6 +4464,15 @@ assign_file_positions_for_load_sections (bfd *abfd,
if (this_hdr->sh_type != SHT_NOBITS)
{
+ if (p->p_filesz + adjust < p->p_memsz)
+ {
+ /* We have a PROGBITS section following NOBITS ones.
+ Allocate file space for the NOBITS section(s) and
+ zero it. */
+ adjust = p->p_memsz - p->p_filesz;
+ if (!write_zeros (abfd, off, adjust))
+ return FALSE;
+ }
off += adjust;
p->p_filesz += adjust;
}
OpenPOWER on IntegriCloud