This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR ld/4701: binutils generates invalid klibc-based binary on Linux x86_64


On Thu, Jun 28, 2007 at 07:44:06AM -0700, H. J. Lu wrote:
> On Fri, Jun 29, 2007 at 12:07:17AM +0930, Alan Modra wrote:
> > On Thu, Jun 28, 2007 at 06:39:51AM -0700, H. J. Lu wrote:
> > > > FAIL: overlay size
> > > > 
> > > > on Linux/x86-64. You should be able to see it with a cross binutils.
> > 
> > I think this is just that the test needs modifying for x86_64's
> > rather large pagesize.  If I add -z max-page-size=0x1000, it passes.
> 
> Why did it work before?

It passed before because my old code handling bss segments excluded
those with m->includes_filehdr or m->includes_phdrs from the voff
adjustments.

> Why large page size is a problem?

Large page size allows the first segment to contain the file header
and program headers as well as .bss1

> Is the output correct for large page?

The ELF section headers and program headers are correct but not
optimal.  When a bss segment also contains the file or program
headers, the following code allocates file space unnecessarily.

      if (p->p_type == PT_LOAD
	  || (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core))
	{
	  if (! m->includes_filehdr && ! m->includes_phdrs)
	    p->p_offset = off;
	  else
	    {
	      file_ptr adjust;

	      adjust = off - (p->p_offset + p->p_filesz);
	      p->p_filesz += adjust;
	      p->p_memsz += adjust;
	    }
	}

The p_filesz adjust should really only happen if sections mapped to
the segment need file space.  This bug has been around forever, but
note that it's not incorrect to allocated zero-filled file space for
bss sections, just unnecessary.  However, allocating this space
confuses objdump (well, really bfd) into incorrectly calculating
lma for .mtext.  You'll recall that ELF files don't store lmas for
sections, so bfd calculates lma from the section vma and program
header info.  The trouble is that ELF files also don't store section
to segment mapping, and bfd mistakenly thinks that the first program
header is the correct one for .mtext (readelf has similar confusion),
and thus calculates an incorrect lma for .mtext.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]