aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-02-24 16:44:48 +1030
committerAlan Modra <amodra@gmail.com>2019-02-24 18:57:04 +1030
commitf616c36b79d0776e51213b177e45a0f5d386cc58 (patch)
tree565d71b6f7fde2bacedacf2c8be9ddce7ce43b61
parent4323c5ad3cbcb2a3d2178d778278109f24071b26 (diff)
downloadgdb-f616c36b79d0776e51213b177e45a0f5d386cc58.zip
gdb-f616c36b79d0776e51213b177e45a0f5d386cc58.tar.gz
gdb-f616c36b79d0776e51213b177e45a0f5d386cc58.tar.bz2
PR24144, pdp11-ld overwriting section data with zeros
bfd/ PR 24144 * pdp11.c (set_section_contents): Revert 2015-02-24 change. gas/ PR 24144 * config/obj-aout.c (obj_aout_frob_file_before_fix): Write to end of section to ensure file contents cover aligned section size.
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/pdp11.c8
-rw-r--r--gas/ChangeLog6
-rw-r--r--gas/config/obj-aout.c32
4 files changed, 32 insertions, 19 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index ce088c9..e206629 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-24 Alan Modra <amodra@gmail.com>
+
+ PR 24144
+ * pdp11.c (set_section_contents): Revert 2015-02-24 change.
+
2019-02-20 Eric Tsai <erictsai@cadence.com>
* elf32-xtensa.c (is_resolvable_asm_expansion): Scan output
diff --git a/bfd/pdp11.c b/bfd/pdp11.c
index a46775a..b16c78f 100644
--- a/bfd/pdp11.c
+++ b/bfd/pdp11.c
@@ -1146,14 +1146,6 @@ NAME (aout, set_section_contents) (bfd *abfd,
if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
|| bfd_bwrite (location, count, abfd) != count)
return FALSE;
-
- /* If necessary, pad the section to its aligned size. */
- if ((section == obj_datasec (abfd)
- || section == obj_textsec (abfd))
- && count < section->size
- && (bfd_seek (abfd, section->filepos + offset + section->size - 1, SEEK_SET) != 0
- || bfd_bwrite ("", 1, abfd) != 1))
- return FALSE;
}
return TRUE;
diff --git a/gas/ChangeLog b/gas/ChangeLog
index a301c04..03c9b4e 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2019-02-24 Alan Modra <amodra@gmail.com>
+
+ PR 24144
+ * config/obj-aout.c (obj_aout_frob_file_before_fix): Write to end
+ of section to ensure file contents cover aligned section size.
+
2019-02-22 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* config/tc-arm.c (arm_cpus): Add neoverse-n1.
diff --git a/gas/config/obj-aout.c b/gas/config/obj-aout.c
index 22e103b..03e0ef3 100644
--- a/gas/config/obj-aout.c
+++ b/gas/config/obj-aout.c
@@ -118,17 +118,27 @@ obj_aout_frob_file_before_fix (void)
{
/* Relocation processing may require knowing the VMAs of the sections.
Since writing to a section will cause the BFD back end to compute the
- VMAs, fake it out here.... */
- bfd_byte b = 0;
- bfd_boolean x = TRUE;
- if (bfd_section_size (stdoutput, text_section) != 0)
- x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0,
- (bfd_size_type) 1);
- else if (bfd_section_size (stdoutput, data_section) != 0)
- x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0,
- (bfd_size_type) 1);
-
- gas_assert (x);
+ VMAs, fake it out here....
+ Writing to the end of the section ensures the file contents
+ extend to cover the entire aligned size. We possibly won't know
+ the aligned size until after VMAs and sizes are set on the first
+ bfd_set_section_contents call, so it might be necessary to repeat. */
+ asection *sec = NULL;
+ if (data_section->size != 0)
+ sec = data_section;
+ else if (text_section->size != 0)
+ sec = text_section;
+ if (sec)
+ {
+ bfd_size_type size;
+ do
+ {
+ bfd_byte b = 0;
+ size = sec->size;
+ gas_assert (bfd_set_section_contents (stdoutput, sec, &b,
+ size - 1, (bfd_size_type) 1));
+ } while (size != sec->size);
+ }
}
static void