bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

BUG: bfd/elf allows only 2 PT_LOAD phdrs


From: Bhavesh P. Davda
Subject: BUG: bfd/elf allows only 2 PT_LOAD phdrs
Date: Tue, 26 Nov 2002 17:53:20 -0700

IMHO, the following is too restrictive in bfd/elf.c:

static bfd_size_type
get_program_header_size (abfd)
     bfd *abfd;
{
...
  /* Assume we will need exactly two PT_LOAD segments: one for text
     and one for data.  */
  segs = 2;
...

There are times when one would like to allocate a new data/bss segment
to be loaded at a specific virtual address, but since the first pass of
ld has assumed that the program headers will only have 2 PT_LOAD
segments, though the second pass does allocate a new PT_LOAD segment on
encountering the section at the specific virtual address, the following
check fails:

static boolean
assign_file_positions_for_segments (abfd)
     bfd *abfd;
{
...
 /* If we already counted the number of program segments, make sure
     that we allocated enough space.  This happens when SIZEOF_HEADERS
     is used in a linker script.  */
  alloc = elf_tdata (abfd)->program_header_size / bed->s->sizeof_phdr;
  if (alloc != 0 && count > alloc)
    {
      ((*_bfd_error_handler)
       (_("%s: Not enough room for program headers (allocated %u, need
%u)"),
        bfd_get_filename (abfd), alloc, count));
      bfd_set_error (bfd_error_bad_value);
      return false;
    }



So, I am proposing that if there is no good way around this bug, then we
arbitrarily chose a large number of PT_LOAD program headers in the first
pass, and then let the second pass truncate the number of program
headers if there are only 2 PT_LOAD segments, for example.

I tried allowing 3 PT_LOAD segments, and it works for both the normal 2
PT_LOAD segments case and the 3 PT_LOAD segments case.

The final ELF executable produced with this change was identical to that
produced without this change for the normal case.

So, here is a trivial patch:

Thanks!
- Bhavesh
diff -Naur binutils-2.13.1/bfd/elf.c binutils-bpd/bfd/elf.c
--- binutils-2.13.1/bfd/elf.c   Tue Nov 26 17:46:37 2002
+++ binutils-bpd/bfd/elf.c      Tue Nov 26 17:47:46 2002
@@ -4013,9 +4013,9 @@
       return elf_tdata (abfd)->program_header_size;
     }
 
-  /* Assume we will need exactly two PT_LOAD segments: one for text
-     and one for data.  */
-  segs = 2;
+  /* Assume we will need many PT_LOAD segments. We will let the second
+     pass truncate the number of PT_LOAD segments if necessary */
+  segs = 10;
 
   s = bfd_get_section_by_name (abfd, ".interp");
   if (s != NULL && (s->flags & SEC_LOAD) != 0)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]