public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: Bug when generating Program Header in elf files
@ 2001-05-30  4:38 Thomas Petazzoni
  2001-05-30  4:48 ` Andreas Jaeger
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Petazzoni @ 2001-05-30  4:38 UTC (permalink / raw)
  To: binutils

hi,

here are some dumps using objdump of the program header :

good version :
bash-2.03$ objdump -p loader.img.binutils-2.9.5 

loader.img.binutils-2.9.5:     file format elf32-i386

Program Header:
    LOAD off    0x00000080 vaddr 0x00201000 paddr 0x00201000 align 2**5
         filesz 0x00000aa4 memsz 0x00001a60 flags rwx


wrong version :
bash-2.03$ objdump -p loader.img.binutils-2.11.90 

loader.img.binutils-2.11.90:     file format elf32-i386

Program Header:
    LOAD off    0x00000080 vaddr 0x00000080 paddr 0x00000080 align 2**5
         filesz 0x00000140 memsz 0x00000140 flags r--
    LOAD off    0x000001c0 vaddr 0x00201000 paddr 0x00201000 align 2**4
         filesz 0x0000096c memsz 0x00001920 flags rwx



hope it will help :)

thomas
-- 
PETAZZONI Thomas
thomas.petazzoni@meridon.com
ICQ : 34937744
Projet KOS : http://kos.enix.org

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

* Re: Bug when generating Program Header in elf files
  2001-05-30  4:38 Bug when generating Program Header in elf files Thomas Petazzoni
@ 2001-05-30  4:48 ` Andreas Jaeger
  2001-05-30  4:52   ` Thomas Petazzoni
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Jaeger @ 2001-05-30  4:48 UTC (permalink / raw)
  To: thomas.petazzoni; +Cc: binutils

Thomas Petazzoni <thomas.petazzoni@meridon.com> writes:

> hi,
> 
> here are some dumps using objdump of the program header :
> 
> good version :
> bash-2.03$ objdump -p loader.img.binutils-2.9.5 
> 
> loader.img.binutils-2.9.5:     file format elf32-i386
> 
> Program Header:
>     LOAD off    0x00000080 vaddr 0x00201000 paddr 0x00201000 align 2**5
>          filesz 0x00000aa4 memsz 0x00001a60 flags rwx
> 
> 
> wrong version :
> bash-2.03$ objdump -p loader.img.binutils-2.11.90 
> 
> loader.img.binutils-2.11.90:     file format elf32-i386
> 
> Program Header:
>     LOAD off    0x00000080 vaddr 0x00000080 paddr 0x00000080 align 2**5
>          filesz 0x00000140 memsz 0x00000140 flags r--
>     LOAD off    0x000001c0 vaddr 0x00201000 paddr 0x00201000 align 2**4
>          filesz 0x0000096c memsz 0x00001920 flags rwx
> 
> 
> 
> hope it will help :)

Please provide complete code so that we can reproduce this,

Andreas

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

* Re: Bug when generating Program Header in elf files
  2001-05-30  4:48 ` Andreas Jaeger
@ 2001-05-30  4:52   ` Thomas Petazzoni
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2001-05-30  4:52 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: binutils

> Please provide complete code so that we can reproduce this,

http://kos.enix.org/~thomas/pub/binutils_bug.tar.gz

instructions in the archive file.

thomas
-- 
PETAZZONI Thomas
thomas.petazzoni@meridon.com
ICQ : 34937744
Projet KOS : http://kos.enix.org

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

* Re: Bug when generating Program Header in elf files
  2001-05-29  9:08 Thomas Petazzoni
  2001-05-29  9:28 ` H . J . Lu
@ 2001-06-12  7:06 ` Nick Clifton
  1 sibling, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2001-06-12  7:06 UTC (permalink / raw)
  To: thomas.petazzoni; +Cc: binutils

Hi Thomas,

  As you have discovered this problem happens because your linker
  script did not explicitly assign .rodata sections in the input files
  to a section in the output file.

  The algorithm used to decide where to place these unallocated
  sections (called 'orphan sections') changed with binutils 2.11, so
  that were being placed at the start of file rather than the end of
  the file, and this meant a second (correctly specified) program
  header was needed.

  Although you have already solved the problem by fixing your linker
  script, you may also want to try the patch below, which changes the
  orphan placement algorithm slitghtly so that unallocates .rodata
  sections will now be attached to the .data section.

Cheers
        Nick

Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.48
diff -p -r1.48 elf32.em
*** elf32.em	2001/05/25 05:39:22	1.48
--- elf32.em	2001/06/12 14:04:20
*************** gld${EMULATION_NAME}_place_orphan (file,
*** 1097,1105 ****
  	   && (hold_rel.os != NULL
  	       || (hold_rel.os = output_rel_find ()) != NULL))
      place = &hold_rel;
!   else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY
! 	   && HAVE_SECTION (hold_rodata, ".rodata"))
!     place = &hold_rodata;
    else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY)
  	   && hold_text.os != NULL)
      place = &hold_text;
--- 1097,1111 ----
  	   && (hold_rel.os != NULL
  	       || (hold_rel.os = output_rel_find ()) != NULL))
      place = &hold_rel;
!   else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY)
!     {
!       if (HAVE_SECTION (hold_rodata, ".rodata"))
! 	place = &hold_rodata;
!       /* If the script does not provide a .rodata
! 	 section try using the .data section instead.  */
!       else if (HAVE_SECTION (hold_data, ".data"))
! 	place = &hold_data;
!     }
    else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY)
  	   && hold_text.os != NULL)
      place = &hold_text;

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

* Re: Bug when generating Program Header in elf files
  2001-05-29  9:08 Thomas Petazzoni
@ 2001-05-29  9:28 ` H . J . Lu
  2001-06-12  7:06 ` Nick Clifton
  1 sibling, 0 replies; 6+ messages in thread
From: H . J . Lu @ 2001-05-29  9:28 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: binutils

On Tue, May 29, 2001 at 06:09:45PM +0200, Thomas Petazzoni wrote:
> hi,
> 
> i've noticed a bug when generating the program header of elf files with
> recent versions of binutils.
> 

If you can provide a simple, complete testcae, it will be fixed.


H.J.

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

* Bug when generating Program Header in elf files
@ 2001-05-29  9:08 Thomas Petazzoni
  2001-05-29  9:28 ` H . J . Lu
  2001-06-12  7:06 ` Nick Clifton
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2001-05-29  9:08 UTC (permalink / raw)
  To: binutils

hi,

i've noticed a bug when generating the program header of elf files with
recent versions of binutils.

the fields vaddr, paddr, memsz and filesz are correctly set with
binutils version 2.9.5, but are incorrectly set with version 2.11.90.

i think it does not worth much when the executable are runned by Linux,
because programs are always loaded to the same virtual address, but i
use the binary file as a kernel image, loaded and runned by Grub.

and Grub uses this fields of the Program Header to load the image.

i use a link script (.lds), which look like this  :
OUTPUT_FORMAT("elf32-i386","elf32-i386","elf32-i386");
ENTRY(_start)
OUTPUT_ARCH("i386")

SECTIONS {
        . = 0x200000 + SIZEOF_HEADERS;
        _b_loader = .;
        . = ALIGN(4096);
        
        .text : { *(.text)
                  etext = .; _etext = .; }
        .data : { *(.data) 
                  edata = .; _edata = .; }
        .bss :  { *(.bss) *(COMMON) 
                  end = .; _end = .; }
        _e_loader = .;
}

the vaddr and paddr are correctly set to 0x201000 (0x1000 is the
sizeof_headers), but only with old versions of binutils (for instance
2.9.5). here are the two dumps :

correct file, generated by version 2.9.5

0000000 457f 464c 0101 0001 0000 0000 0000 0000
0000010 0002 0003 0001 0000 10f8 0020 0034 0000
0000020 0cd0 0000 0000 0000 0034 0020 0001 0028
0000030 000b 0008 0001 0000 0080 0000 1000 0020
0000040 1000 0020 0aa4 0000 1a60 0000 0007 0000
0000050 0020 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000

byte 60 : vaddr = 0x201000
byte 64 (0x40) : paddr = 0x201000
byte 68 : memsz = 0xAA4
byte 72 : filesz = 0x1A6

thoses values works perfectly with grub

but

incorrect file, generated by version 2.11.90

0000000 457f 464c 0101 0001 0000 0000 0000 0000
0000010 0002 0003 0001 0000 1100 0020 0034 0000
0000020 0cd8 0000 0000 0000 0034 0020 0002 0028
0000030 000b 0008 0001 0000 0080 0000 0080 0000
0000040 0080 0000 0140 0000 0140 0000 0004 0000
0000050 0020 0000 0001 0000 01c0 0000 1000 0020
0000060 1000 0020 096c 0000 1920 0000 0007 0000
0000070 0010 0000 0000 0000 0000 0000 0000 0000

at byte 60 and 64, we have 0x80, and then we have 0x140 for both memsz
and filesz. but you can see that the correct fields are present near
byte 0x60... which is not the right place !!!

why does this happen ?

thomas
-- 
PETAZZONI Thomas
thomas.petazzoni@meridon.com
ICQ : 34937744
Projet KOS : http://kos.enix.org

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

end of thread, other threads:[~2001-06-12  7:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-30  4:38 Bug when generating Program Header in elf files Thomas Petazzoni
2001-05-30  4:48 ` Andreas Jaeger
2001-05-30  4:52   ` Thomas Petazzoni
  -- strict thread matches above, loose matches on Subject: below --
2001-05-29  9:08 Thomas Petazzoni
2001-05-29  9:28 ` H . J . Lu
2001-06-12  7:06 ` Nick Clifton

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).