public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: add program header to elf
@ 2005-05-19  3:41 Zhenyu Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Zhenyu Guo @ 2005-05-19  3:41 UTC (permalink / raw)
  To: 'Zhenyu Guo'; +Cc: 'Binutils'

I've got it :)
The vma of program header and the vma of the code segment must be
contiguous. I suppose this is because the loader make an assumption that
it can access the program header by simply adding hdr->e_phoffset to the
start vma of code segment. Is is true?
Anyway, it finally runs now, haha.

-----邮件原件-----
发件人: Zhenyu Guo [mailto:guozy03@mails.tsinghua.edu.cn] 
发送时间: 2005年5月19日 10:41
收件人: Binutils (binutils@sources.redhat.com)
主题: add program header to elf


Hi there,
	I am now working on binary rewrite, and I want to add some
customized segment in elf file. I've done this by adding Program Header
in the program header table. As you can see later. As I have to expand
the space for program header table, I make the originial space dirty,
and append new  table at the end of elf file (related entries in elfhdr
are updated).  It seems right when I use readelf to dump things out
about the new binary. However, when it gets into exeuction, the old one
succeeds, 
While the new one fails with error msg
 'Program received signal SIGSEGV, Segmentation fault.
0x2000000000003c80 in ?? ()'.

Any idea? Or some better methods about adding new segment? 
Thanks in advance.
Zhenyu
===============================	
Original Program Header:
(readelf -l bt)
Program Headers: 
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x4000000000000040
0x4000000000000040
                 0x0000000000000188 0x0000000000000188  R E    8
  INTERP         0x00000000000001c8 0x40000000000001c8
0x40000000000001c8
                 0x0000000000000018 0x0000000000000018  R      1
      [Requesting program interpreter: /lib/ld-linux-ia64.so.2]
  LOAD           0x0000000000000000 0x4000000000000000
0x4000000000000000
                 0x0000000000168ca8 0x0000000000168ca8  R E    10000
  LOAD           0x0000000000168ca8 0x6000000000008ca8
0x6000000000008ca8
                 0x000000000000bec8 0x0000000001138cf8  RW     10000
  DYNAMIC        0x00000000001744c8 0x60000000000144c8
0x60000000000144c8
                 0x0000000000000150 0x0000000000000150  RW     8
  NOTE           0x00000000000001e0 0x40000000000001e0
0x40000000000001e0
                 0x0000000000000020 0x0000000000000020  R      4
  IA_64_UNWIND   0x0000000000162c88 0x4000000000162c88
0x4000000000162c88
                 0x0000000000006020 0x0000000000006020  R      8

After Rewrite: 
(readelf -l newbt)
Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x00000000001a7edc 0x40000000a0168d00
0x40000000a0168d00
                 0x00000000000001c0 0x00000000000001c0  R E    8
  INTERP         0x00000000000001c8 0x40000000000001c8
0x40000000000001c8
                 0x0000000000000018 0x0000000000000018  R      1
      [Requesting program interpreter: /lib/ld-linux-ia64.so.2]
  LOAD           0x0000000000000000 0x4000000000000000
0x4000000000000000
                 0x0000000000168ca8 0x0000000000168ca8  R E    10000
  LOAD           0x0000000000168ca8 0x6000000000008ca8
0x6000000000008ca8
                 0x000000000000bec8 0x0000000001138cf8  RW     10000
  DYNAMIC        0x00000000001744c8 0x60000000000144c8
0x60000000000144c8
                 0x0000000000000150 0x0000000000000150  RW     8
  NOTE           0x00000000000001e0 0x40000000000001e0
0x40000000000001e0
                 0x0000000000000020 0x0000000000000020  R      4
  IA_64_UNWIND   0x0000000000162c88 0x4000000000162c88
0x4000000000162c88
                 0x0000000000006020 0x0000000000006020  R      8
  LOAD           0x00000000001a7edc 0x40000000a0168d00
0x40000000a0168d00
                 0x00000000000001c0 0x00000000000001c0  R E    8
========================================================================
============

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

* add program header to elf
@ 2005-05-19  3:04 Zhenyu Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Zhenyu Guo @ 2005-05-19  3:04 UTC (permalink / raw)
  To: Binutils

Hi there,
	I am now working on binary rewrite, and I want to add some
customized segment in elf file.
I've done this by adding Program Header in the program header table. As
you can see later.
As I have to expand the space for program header table, I make the
originial space dirty, and append
new  table at the end of elf file (related entries in elfhdr are
updated).  It seems right when I use readelf
to dump things out about the new binary. However, when it gets into
exeuction, the old one succeeds, 
While the new one fails with error msg
 'Program received signal SIGSEGV, Segmentation fault.
0x2000000000003c80 in ?? ()'.

Any idea? Or some better methods about adding new segment? 
Thanks in advance.
Zhenyu
===============================	
Original Program Header:
(readelf -l bt)
Program Headers: 
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x4000000000000040
0x4000000000000040
                 0x0000000000000188 0x0000000000000188  R E    8
  INTERP         0x00000000000001c8 0x40000000000001c8
0x40000000000001c8
                 0x0000000000000018 0x0000000000000018  R      1
      [Requesting program interpreter: /lib/ld-linux-ia64.so.2]
  LOAD           0x0000000000000000 0x4000000000000000
0x4000000000000000
                 0x0000000000168ca8 0x0000000000168ca8  R E    10000
  LOAD           0x0000000000168ca8 0x6000000000008ca8
0x6000000000008ca8
                 0x000000000000bec8 0x0000000001138cf8  RW     10000
  DYNAMIC        0x00000000001744c8 0x60000000000144c8
0x60000000000144c8
                 0x0000000000000150 0x0000000000000150  RW     8
  NOTE           0x00000000000001e0 0x40000000000001e0
0x40000000000001e0
                 0x0000000000000020 0x0000000000000020  R      4
  IA_64_UNWIND   0x0000000000162c88 0x4000000000162c88
0x4000000000162c88
                 0x0000000000006020 0x0000000000006020  R      8

After Rewrite: 
(readelf -l newbt)
Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x00000000001a7edc 0x40000000a0168d00
0x40000000a0168d00
                 0x00000000000001c0 0x00000000000001c0  R E    8
  INTERP         0x00000000000001c8 0x40000000000001c8
0x40000000000001c8
                 0x0000000000000018 0x0000000000000018  R      1
      [Requesting program interpreter: /lib/ld-linux-ia64.so.2]
  LOAD           0x0000000000000000 0x4000000000000000
0x4000000000000000
                 0x0000000000168ca8 0x0000000000168ca8  R E    10000
  LOAD           0x0000000000168ca8 0x6000000000008ca8
0x6000000000008ca8
                 0x000000000000bec8 0x0000000001138cf8  RW     10000
  DYNAMIC        0x00000000001744c8 0x60000000000144c8
0x60000000000144c8
                 0x0000000000000150 0x0000000000000150  RW     8
  NOTE           0x00000000000001e0 0x40000000000001e0
0x40000000000001e0
                 0x0000000000000020 0x0000000000000020  R      4
  IA_64_UNWIND   0x0000000000162c88 0x4000000000162c88
0x4000000000162c88
                 0x0000000000006020 0x0000000000006020  R      8
  LOAD           0x00000000001a7edc 0x40000000a0168d00
0x40000000a0168d00
                 0x00000000000001c0 0x00000000000001c0  R E    8
========================================================================
============

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

end of thread, other threads:[~2005-05-19  3:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-19  3:41 add program header to elf Zhenyu Guo
  -- strict thread matches above, loose matches on Subject: below --
2005-05-19  3:04 Zhenyu Guo

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