[PATCH] program header instability
Nathan Sidwell
nathan@codesourcery.com
Tue Dec 19 15:45:00 GMT 2006
This patch fixes a problem with instability in calculating program headers. The
original testcase came from a vxworks build, but the problem can manifest on any
elf target. The problem occurs when a section boundary happens to lie on a page
boundary, and the previous and next sections differ in the WRITABLE attribute.
This bit of code in elf.c:
else if (! writable
&& (hdr->flags & SEC_READONLY) == 0
&& (((last_hdr->lma + last_size - 1)
& ~(maxpagesize - 1))
!= (hdr->lma & ~(maxpagesize - 1))))
{
/* We don't want to put a writable section in a read only
segment, unless they are on the same page in memory
anyhow. We already know that the last section does not
bring us past the current section on the page, so the
only case in which the new section is not on the same
page as the previous section is when the previous section
ends precisely on a page boundary. */
new_segment = TRUE;
places those two sections in different segments, necessitating an additional
program header. Now, when the new program header is included, the section
boundary is no longer page aligned, and we decide we only need 1 program header
for the two sections. So the section boundary shifts down and we're back where
we started.
The linker bails out with
./ld-new: looping in map_segments
That loop fails because, even though bfd caches the program_header size during
the linking layout phase, we keep changing our minds as to whether the first
segment contains the pheaders or not, depending on whether we think we need N or
N+1 of them.
if ((abfd->flags & D_PAGED) == 0
|| sections[0]->lma < phdr_size
|| sections[0]->lma % maxpagesize < phdr_size % maxpagesize)
phdr_in_segment = FALSE;
This patch changes elf.c to initialize the program_header_size to zero (rather
than the 'unknown' value of -1), and then always recalculate it. furthermore we
never reduce the size of the program headers, to avoid the above instability.
Tested in i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: all.diff
URL: <https://sourceware.org/pipermail/binutils/attachments/20061219/ae1f7490/attachment.ksh>
More information about the Binutils
mailing list