When the "-s" option is used, the binutils 2.25 linker produces ELF executables with a 4-byte gap between the last section and the section headers. The 2.24 linker doesn't do that, and the gap is not present if a file is linked without "-s" and separately stripped. I'm observing this on i386-pc-linux-uclibc with the normal (not gold) linker.
Please provide a small standalone testcase.
Just the two-line assembler file: .global _start _start: hlt suffices to demonstrate the behavior. If this is assembled (with as directly, no options besides -o) and linked (directly, just -s and -o) on 2.25, the resulting file gives the following under readelf -S: There are 3 section headers, starting at offset 0x6c: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 08048054 000054 000001 00 AX 0 0 1 [ 2] .shstrtab STRTAB 00000000 000055 000011 00 0 0 1 The last section ends just before 0x66 (0x55 + 0x11). With alignment, that should place the section header table at 0x68. But it's actually at 0x6c.
It is caused by commit a485e98ea0cbb61ea9da1e7858da545e0bcf1a46 Author: Alan Modra <amodra@gmail.com> Date: Wed Sep 10 14:26:25 2014 +0930 Move ELF section headers to end of object file Currently, section ordering differs a little for non-loaded reloc sections output by ld -emit-relocs or ld -r and that after passing such objects through objcopy. Not that it really matters, but it would be better for a simple objcopy to produce an unchanged output object file. Also, section headers are put somewhere in the middle of the non-loaded sections, again slightly differently for ld and objcopy. This patch fixes these discrepancies and puts section headers last, which is where gold puts them, and is where bfd_from_remote_memory wrongly assumed they will be found. bfd/ * elf.c (assign_file_positions_except_relocs): Move section header placement to.. (_bfd_elf_assign_file_positions_for_relocs): ..here. Make static. * elf-bfd.h (_bfd_elf_assign_file_positions_for_relocs): Delete. * elflink.c (bfd_elf_final_link): Don't call above function.
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "gdb and binutils". The branch, hjl/pr17773 has been created at b72a529b6aeb4bbd07a393b0e14ea997e8c4b1ae (commit) - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b72a529b6aeb4bbd07a393b0e14ea997e8c4b1ae commit b72a529b6aeb4bbd07a393b0e14ea997e8c4b1ae Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Dec 30 14:01:27 2014 -0800 Assign file position for .strtab only if needed bfd/ PR ld/17773 * elflink.c (bfd_elf_final_link): Assign the file position for the symbol string table only there are symbols to be emitted. ld/testsuite/ PR ld/17773 * ld-elf/binutils.exp (binutils_test): Add an optional readelf_options. Replace -l with $readelf_options. Add a gap test. * ld/testsuite/ld-elf/gap.s: New file. -----------------------------------------------------------------------
A patch is posted at https://sourceware.org/ml/binutils/2014-12/msg00313.html
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "gdb and binutils". The branch, master has been updated via ee3b52e917c3a19850232a6a20f5698090619fc6 (commit) from 24fbeb8dc2c20f86c9940cc62e6af192a9d11b1a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ee3b52e917c3a19850232a6a20f5698090619fc6 commit ee3b52e917c3a19850232a6a20f5698090619fc6 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Dec 30 19:09:11 2014 -0800 Assign file position for .strtab only if needed bfd/ PR ld/17773 * elflink.c (bfd_elf_final_link): Assign the file position for the symbol string table only there are symbols to be emitted. ld/testsuite/ PR ld/17773 * ld-elf/binutils.exp (binutils_test): Add an optional readelf_options. Replace -l with $readelf_options. Add a gap test. * ld/testsuite/ld-elf/gap.s: New file. ----------------------------------------------------------------------- Summary of changes: bfd/ChangeLog | 6 +++++ bfd/elflink.c | 38 +++++++++++++++++---------------- ld/testsuite/ChangeLog | 8 +++++++ ld/testsuite/ld-elf/binutils.exp | 15 ++++++++----- ld/testsuite/ld-elf/{lma.s => gap.s} | 0 5 files changed, 43 insertions(+), 24 deletions(-) copy ld/testsuite/ld-elf/{lma.s => gap.s} (100%)
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "gdb and binutils". The branch, binutils-2_25-branch has been updated via 77ce4dbedbae824d8637e7e55903f7cd0709d49e (commit) from 15a7f882647865ed9c262997915fbb243e54ebb6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=77ce4dbedbae824d8637e7e55903f7cd0709d49e commit 77ce4dbedbae824d8637e7e55903f7cd0709d49e Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jan 5 04:42:37 2015 -0800 Assign file position for .strtab only if needed bfd/ PR ld/17773 * elflink.c (bfd_elf_final_link): Assign the file position for the symbol string table only there are symbols to be emitted. ld/testsuite/ PR ld/17773 * ld-elf/binutils.exp (binutils_test): Add an optional readelf_options. Replace -l with $readelf_options. Add a gap test. * ld/testsuite/ld-elf/gap.s: New file. ----------------------------------------------------------------------- Summary of changes: bfd/ChangeLog | 6 +++++ bfd/elflink.c | 38 +++++++++++++++++---------------- ld/testsuite/ChangeLog | 8 +++++++ ld/testsuite/ld-elf/binutils.exp | 15 ++++++++----- ld/testsuite/ld-elf/{lma.s => gap.s} | 0 5 files changed, 43 insertions(+), 24 deletions(-) copy ld/testsuite/ld-elf/{lma.s => gap.s} (100%)
Fixed for 2.26 and the next 2.25 release.