This is the mail archive of the binutils@sources.redhat.com 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]

Bug when generating Program Header in elf files


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


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