This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [binutils-gdb] Fix the linker so that it will not silently generate ELF binaries with invalid program headers. Fix
- From: Alan Modra <amodra at gmail dot com>
- To: "Maciej W. Rozycki" <macro at imgtec dot com>
- Cc: Nick Clifton <nickc at sourceware dot org>, binutils at sourceware dot org
- Date: Thu, 8 Dec 2016 22:02:38 +1030
- Subject: Re: [binutils-gdb] Fix the linker so that it will not silently generate ELF binaries with invalid program headers. Fix
- Authentication-results: sourceware.org; auth=none
- References: <20161123111226.62132.qmail@sourceware.org> <alpine.DEB.2.00.1612080849380.6743@tp.orcam.me.uk>
On Thu, Dec 08, 2016 at 09:30:04AM +0000, Maciej W. Rozycki wrote:
> Program Headers:
> Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
> PHDR 0x000034 0x00001034 0x00000000 0x000a0 0x000a0 R E 0x4
> INTERP 0x001000 0x00080000 0x00080000 0x00013 0x00013 R 0x1
> [Requesting program interpreter: /usr/lib/libc.so.1]
> LOAD 0x001000 0x00080000 0x00080000 0x00408 0x00408 R E 0x1000
> LOAD 0x002000 0x00081000 0x00081000 0x00804 0x00c00 RW 0x1000
> DYNAMIC 0x002000 0x00081000 0x00081000 0x00078 0x00078 RW 0x4
The gABI says:
PT_PHDR
The array element, if present, specifies the location and size of
the program header table itself, both in the file and in the
memory image of the program. This segment type may not occur more
than once in a file. Moreover, it may occur only if the program
header table is part of the memory image of the program. If it is
present, it must precede any loadable segment entry.
The above clearly violates this part of the spec because PT_PHDR is
present yet is not part of the memory image.
Nick's patch forced the first PT_LOAD to cover the program headers. I
think an equally valid and somewhat better fix would have been to not
emit PT_PHDR when no PT_LOAD header covers the program headers. The
reason I say that is because PT_PHDR is optional. A loader can read
the program headers itself from file using info in the ELF header.
--
Alan Modra
Australia Development Lab, IBM