public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Problem with D_PAGED handling for ELF
@ 2005-01-25 21:46 Daniel Jacobowitz
  2005-01-26  0:21 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-01-25 21:46 UTC (permalink / raw)
  To: binutils

I was handed an interesting bug where objcopy caused corruption of the
program headers for a binary produced by a third party toolchain.  The VMAs
and alignments got eaten.  After a lot of banging my head on the ground, I
discovered that this happened because the producing toolchain differed from
binutils on its opinion of the page size.

Here's how BFD verifies that a binary is "usefully" dynamic paged:

          /* If the section is loaded, but not page aligned, clear
             D_PAGED.  */
          if (i_shdrp[shindex].sh_size != 0
              && (i_shdrp[shindex].sh_flags & SHF_ALLOC) != 0
              && i_shdrp[shindex].sh_type != SHT_NOBITS
              && (((i_shdrp[shindex].sh_addr - i_shdrp[shindex].sh_offset)
                   % ebd->maxpagesize)
                  != 0))
            abfd->flags &= ~D_PAGED;

The problem is, binutils was configured to generate binaries that would work
on any page size up to 64k, and the third party toolchain was configured to
generate binaries that would work on a particular system where the toolchain
was known to be 4k.  So it only aligned the segments to 4k.

There's two plausible solutions I can see for this:
  - Add a "minimum page size" to the ELF backend, and use that instead for
    this check.  Generate binaries that will work up to MAX, accept binaries
    designed for at least MIN.
  - Disable the check entirely.  Assume any ELF binary with program headers
    is demand paged.  I am not sure about the consequences of this.

(I tried working around it by just "fixing" the page size.  Unfortunately,
the target systems have configurable page sizes, and I don't have a good
interface for telling things like objcopy or strip which one is currently in
use.)

Any comments on the two options?

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-01-27  7:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-25 21:46 Problem with D_PAGED handling for ELF Daniel Jacobowitz
2005-01-26  0:21 ` Alan Modra
2005-01-26 16:27   ` Daniel Jacobowitz
2005-01-27  7:56     ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).