Created attachment 12294 [details] Proposed patch When the -s option is supplied to ld for pdp11-aout target to suppress writing the symbol table, the last byte of the .data section is overwritten with 0. There is code explicitly written to do this near the end of the final_link function in bfd/pdp11.c. It appears that the intention of that code was to pad with 0 for a .data section of odd length, but the last data byte is overwritten when the length is even. Furthermore, in normal usage the length is always even because gas pads the .data section in an object file if it is odd. For testing, and odd-length .data section can be forced with a linker script that appends one byte. I am attaching a proposed fix that checks for the file length being odd using the bfd->where member and only appends the 0 pad byte in that case.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dda2980f54a0c9437de047f3020f520dd1e0de6a commit dda2980f54a0c9437de047f3020f520dd1e0de6a Author: Alan Modra <amodra@gmail.com> Date: Thu Feb 20 21:53:44 2020 +1030 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.
Fixed.