Elf program header not correctly generated (glibc-2.3.3 and gnu ld on RHLinux 3.0)

Kshitiz JAIN <[email protected]> Tue, 27 Dec 2005 20:06:17 +0530
Newsgroups gmane.linux.redhat.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.

------=_NextPart_000_00B8_01C60B20.FFD620C0
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Hi all ,

I am trying to compile posix testuite on RHLinux using a linker
script with MEMORY constraint (see attached linker script).

I am getting some problems in generated elf files .

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
objdump -p =
../busybox/posixtestsuite/conformance/interfaces/asctime/1-1.test

../busybox/posixtestsuite/conformance/interfaces/asctime/1-1.test:     =
file format elf32-i386

Program Header:
    LOAD off    0x00001000 vaddr 0x00001000 paddr 0x00001000 align 2**12
         filesz 0x00059ed0 memsz 0x0005abf4 flags rwx
    NOTE off    0x00001000 vaddr 0x00001000 paddr 0x00001000 align 2**2
         filesz 0x00000020 memsz 0x00000020 flags r--
   STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
         filesz 0x00000000 memsz 0x00000000 flags rw-
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
As you will notice in the program header, the offset is 0x1000 and vaddr =
is also
0x1000 ,I noticed in the elf loader of linux that the generated program =
header is
put at the address (vaddr - offset) which becomes address 0 .
Now address 0 is NULL page and is not accessible from user address =
space. the glibc
initialization code accesses this program header resulting in a =
segmentation fault.

(I am using glibc-2.3.3 ld version 2.14.90)
Can anybody throw some light on what can be the problem ?

With same ld script for other posix testsuite I get correct headers
(offset =3D 0 , vaddr =3D5b000).
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 objdump -p =
../busybox/posixtestsuite/conformance/interfaces/ctime/1-1.test

../busybox/posixtestsuite/conformance/interfaces/ctime/1-1.test:     =
file format elf32-i386

Program Header:
    LOAD off    0x00000000 vaddr 0x0005b000 paddr 0x0005b000 align 2**12
         filesz 0x0005a2d0 memsz 0x0005aff0 flags rwx
    NOTE off    0x000007f0 vaddr 0x0005b7f0 paddr 0x0005b7f0 align 2**2
         filesz 0x00000020 memsz 0x00000020 flags r--
   STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
         filesz 0x00000000 memsz 0x00000000 flags rw-
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Any help (reference to resources on net) or some direction to go about =
solving this
problem will be useful.
If some more information is required please do let me know.

Thanks & Regards
Kshitiz

------=_NextPart_000_00B8_01C60B20.FFD620C0
Content-Type: application/octet-stream;
	name="script.ld"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="script.ld"

/* Script for -z combreloc: combine and sort reloc sections */=0A=
OUTPUT_FORMAT("elf32-i386", "elf32-i386",=0A=
	      "elf32-i386")=0A=
OUTPUT_ARCH(i386)=0A=
ENTRY(_start)=0A=
SEARCH_DIR("/usr/i386-redhat-linux/lib"); SEARCH_DIR("/usr/lib"); =
SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib");=0A=
/* Do we need any of these for elf?=0A=
   __DYNAMIC =3D 0;    */=0A=
SECTIONS=0A=
{=0A=
  /* Read-only sections, merged into text segment: */=0A=
  /*. =3D 0xb8048000 + SIZEOF_HEADERS;*/=0A=
  . =3D 0x1000 + SIZEOF_HEADERS;=0A=
  .interp         : { *(.interp) }=0A=
  .hash           : { *(.hash) }=0A=
  .dynsym         : { *(.dynsym) }=0A=
  .dynstr         : { *(.dynstr) }=0A=
  .gnu.version    : { *(.gnu.version) }=0A=
  .gnu.version_d  : { *(.gnu.version_d) }=0A=
  .gnu.version_r  : { *(.gnu.version_r) }=0A=
  .rel.dyn        :=0A=
    {=0A=
      *(.rel.init)=0A=
      *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)=0A=
      *(.rel.fini)=0A=
      *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)=0A=
      *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)=0A=
      *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)=0A=
      *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)=0A=
      *(.rel.ctors)=0A=
      *(.rel.dtors)=0A=
      *(.rel.got)=0A=
      *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)=0A=
    }=0A=
  .rela.dyn       :=0A=
    {=0A=
      *(.rela.init)=0A=
      *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)=0A=
      *(.rela.fini)=0A=
      *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)=0A=
      *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)=0A=
      *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)=0A=
      *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)=0A=
      *(.rela.ctors)=0A=
      *(.rela.dtors)=0A=
      *(.rela.got)=0A=
      *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)=0A=
    }=0A=
  .rel.plt        : { *(.rel.plt) }=0A=
  .rela.plt       : { *(.rela.plt) }=0A=
  .init           :=0A=
  {=0A=
    KEEP (*(.init))=0A=
  } =3D0x90909090=0A=
  .plt            : { *(.plt) }=0A=
  .text           :=0A=
  {=0A=
    *(.text .stub .text.* .gnu.linkonce.t.*)=0A=
    /* .gnu.warning sections are handled specially by elf32.em.  */=0A=
    *(.gnu.warning)=0A=
  } =3D0x90909090=0A=
  .fini           :=0A=
  {=0A=
    KEEP (*(.fini))=0A=
  } =3D0x90909090=0A=
  PROVIDE (__etext =3D .);=0A=
  PROVIDE (_etext =3D .);=0A=
  PROVIDE (etext =3D .);=0A=
  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }=0A=
  .rodata1        : { *(.rodata1) }=0A=
  .eh_frame_hdr : { *(.eh_frame_hdr) }=0A=
  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }=0A=
  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table) }=0A=
  /* Adjust the address for the data segment.  We want to adjust up to=0A=
     the same address within the page on the next page up.  */=0A=
  . =3D ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . =3D =
DATA_SEGMENT_ALIGN (0x1000, 0x1000);=0A=
  /* Ensure the __preinit_array_start label is properly aligned.  We=0A=
     could instead move the label definition inside the section, but=0A=
     the linker would then create the section even if it turns out to=0A=
     be empty, which isn't pretty.  */=0A=
  . =3D ALIGN(32 / 8);=0A=
  PROVIDE (__preinit_array_start =3D .);=0A=
  .preinit_array     : { *(.preinit_array) }=0A=
  PROVIDE (__preinit_array_end =3D .);=0A=
  PROVIDE (__init_array_start =3D .);=0A=
  .init_array     : { *(.init_array) }=0A=
  PROVIDE (__init_array_end =3D .);=0A=
  PROVIDE (__fini_array_start =3D .);=0A=
  .fini_array     : { *(.fini_array) }=0A=
  PROVIDE (__fini_array_end =3D .);=0A=
  .data           :=0A=
  {=0A=
    *(.data .data.* .gnu.linkonce.d.*)=0A=
    SORT(CONSTRUCTORS)=0A=
  }=0A=
  .data1          : { *(.data1) }=0A=
  .tdata	  : { *(.tdata .tdata.* .gnu.linkonce.td.*) }=0A=
  .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }=0A=
  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }=0A=
  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table) }=0A=
  .dynamic        : { *(.dynamic) }=0A=
  .ctors          :=0A=
  {=0A=
    /* gcc uses crtbegin.o to find the start of=0A=
       the constructors, so we make sure it is=0A=
       first.  Because this is a wildcard, it=0A=
       doesn't matter if the user does not=0A=
       actually link against crtbegin.o; the=0A=
       linker won't look for a file to match a=0A=
       wildcard.  The wildcard also means that it=0A=
       doesn't matter which directory crtbegin.o=0A=
       is in.  */=0A=
    KEEP (*crtbegin*.o(.ctors))=0A=
    /* We don't want to include the .ctor section from=0A=
       from the crtend.o file until after the sorted ctors.=0A=
       The .ctor section from the crtend file contains the=0A=
       end of ctors marker and it must be last */=0A=
    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))=0A=
    KEEP (*(SORT(.ctors.*)))=0A=
    KEEP (*(.ctors))=0A=
  }=0A=
  .dtors          :=0A=
  {=0A=
    KEEP (*crtbegin*.o(.dtors))=0A=
    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))=0A=
    KEEP (*(SORT(.dtors.*)))=0A=
    KEEP (*(.dtors))=0A=
  }=0A=
  .jcr            : { KEEP (*(.jcr)) }=0A=
  .got            : { *(.got.plt) *(.got) }=0A=
  _edata =3D .;=0A=
  PROVIDE (edata =3D .);=0A=
  __bss_start =3D .;=0A=
  .bss            :=0A=
  {=0A=
   *(.dynbss)=0A=
   *(.bss .bss.* .gnu.linkonce.b.*)=0A=
   *(COMMON)=0A=
   /* Align here to ensure that the .bss section occupies space up to=0A=
      _end.  Align after .bss to ensure correct alignment even if the=0A=
      .bss section disappears because there are no input sections.  */=0A=
   . =3D ALIGN(32 / 8);=0A=
  }=0A=
  . =3D ALIGN(32 / 8);=0A=
  _end =3D .;=0A=
  PROVIDE (end =3D .);=0A=
  . =3D DATA_SEGMENT_END (.);=0A=
  /* Stabs debugging sections.  */=0A=
  .stab          0 : { *(.stab) }=0A=
  .stabstr       0 : { *(.stabstr) }=0A=
  .stab.excl     0 : { *(.stab.excl) }=0A=
  .stab.exclstr  0 : { *(.stab.exclstr) }=0A=
  .stab.index    0 : { *(.stab.index) }=0A=
  .stab.indexstr 0 : { *(.stab.indexstr) }=0A=
  .comment       0 : { *(.comment) }=0A=
  /* DWARF debug sections.=0A=
     Symbols in the DWARF debugging sections are relative to the =
beginning=0A=
     of the section so we begin them at 0.  */=0A=
  /* DWARF 1 */=0A=
  .debug          0 : { *(.debug) }=0A=
  .line           0 : { *(.line) }=0A=
  /* GNU DWARF 1 extensions */=0A=
  .debug_srcinfo  0 : { *(.debug_srcinfo) }=0A=
  .debug_sfnames  0 : { *(.debug_sfnames) }=0A=
  /* DWARF 1.1 and DWARF 2 */=0A=
  .debug_aranges  0 : { *(.debug_aranges) }=0A=
  .debug_pubnames 0 : { *(.debug_pubnames) }=0A=
  /* DWARF 2 */=0A=
  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }=0A=
  .debug_abbrev   0 : { *(.debug_abbrev) }=0A=
  .debug_line     0 : { *(.debug_line) }=0A=
  .debug_frame    0 : { *(.debug_frame) }=0A=
  .debug_str      0 : { *(.debug_str) }=0A=
  .debug_loc      0 : { *(.debug_loc) }=0A=
  .debug_macinfo  0 : { *(.debug_macinfo) }=0A=
  /* SGI/MIPS DWARF 2 extensions */=0A=
  .debug_weaknames 0 : { *(.debug_weaknames) }=0A=
  .debug_funcnames 0 : { *(.debug_funcnames) }=0A=
  .debug_typenames 0 : { *(.debug_typenames) }=0A=
  .debug_varnames  0 : { *(.debug_varnames) }=0A=
  /DISCARD/ : { *(.note.GNU-stack) }=0A=
}=0A=
=0A=
MEMORY=0A=
{=0A=
   SYSTEM (ALIRWX) : ORIGIN =3D 0x1000, LENGTH =3D 0x7fffc000=0A=
}=0A=
=0A=

------=_NextPart_000_00B8_01C60B20.FFD620C0
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Redhat-devel-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/redhat-devel-list
------=_NextPart_000_00B8_01C60B20.FFD620C0--