aboutsummaryrefslogtreecommitdiff
path: root/gas/config
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-02-20 21:53:44 +1030
committerAlan Modra <amodra@gmail.com>2020-02-21 10:47:05 +1030
commitdda2980f54a0c9437de047f3020f520dd1e0de6a (patch)
tree0cec5fd8cca1430f9ebf92c851d58dab01c39ba0 /gas/config
parent6565bf67add96edbe99c24acb312fe84079ab6a0 (diff)
downloadgdb-dda2980f54a0c9437de047f3020f520dd1e0de6a.zip
gdb-dda2980f54a0c9437de047f3020f520dd1e0de6a.tar.gz
gdb-dda2980f54a0c9437de047f3020f520dd1e0de6a.tar.bz2
PR25569, PDP11 ld -s clobbers last data byte
This patch fixes an ancient wart in aout support, in that text and data section sizes are rounded up for alignment rather that just the corresponding header sizes. Changing section sizes could conceivably result in buffer overflows if section contents were held in memory. Also, keeping the original section sizes allows this PR to be fixed nicely. bfd/ PR 25569 * aoutx.h (adjust_o_magic, adjust_z_magic, adjust_n_magic): Use "text", "data" and "bss" section pointer vars. Don't update section size, just exec header sizes. (adjust_sizes_and_vmas): Don't update text section size. Set initial exec header a_text. Print exec headers sizes. * pdp11.c (adjust_o_magic, adjust_z_magic, adjust_n_magic), (adjust_sizes_and_vmas): Similarly. Formatting. (final_link): Correct final file extension. gas/ PR 25569 * config/obj-aout.c (obj_aout_frob_file_before_fix): Don't loop on section size adjustment, instead perform another write if exec header size is larger than section size.
Diffstat (limited to 'gas/config')
-rw-r--r--gas/config/obj-aout.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/gas/config/obj-aout.c b/gas/config/obj-aout.c
index bdd46a7..aee7c81 100644
--- a/gas/config/obj-aout.c
+++ b/gas/config/obj-aout.c
@@ -113,31 +113,39 @@ obj_aout_frob_symbol (symbolS *sym, int *punt ATTRIBUTE_UNUSED)
S_GET_NAME (sym));
}
+/* Relocation processing may require knowing the VMAs of the sections.
+ Writing to a section will cause the BFD back end to compute the
+ VMAs. This function also ensures that file size is large enough
+ to cover a_text and a_data should text or data be the last section
+ in the file. */
+
void
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....
- 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)
+ asection *sec;
+ bfd_vma *sizep = NULL;
+ if ((sec = data_section)->size != 0)
+ sizep = &exec_hdr (stdoutput)->a_data;
+ else if ((sec = text_section)->size != 0)
+ sizep = &exec_hdr (stdoutput)->a_text;
+ if (sizep)
{
- bfd_size_type size;
- do
+ bfd_size_type size = sec->size;
+ bfd_byte b = 0;
+
+ gas_assert (bfd_set_section_contents (stdoutput, sec, &b, size - 1, 1));
+
+ /* We don't know the aligned size until after VMAs and sizes are
+ set on the bfd_set_section_contents call. If that size is
+ larger than the section then write again to ensure the file
+ contents extend to cover the aligned size. */
+ if (*sizep > size)
{
- 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);
+ file_ptr pos = sec->filepos + *sizep;
+
+ gas_assert (bfd_seek (stdoutput, pos - 1, SEEK_SET) == 0
+ && bfd_bwrite (&b, 1, stdoutput) == 1);
+ }
}
}