This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: add program header to elf
- From: "Zhenyu Guo" <guozy03 at mails dot tsinghua dot edu dot cn>
- To: "'Zhenyu Guo'" <guozy03 at mails dot tsinghua dot edu dot cn>
- Cc: "'Binutils'" <binutils at sources dot redhat dot com>
- Date: Thu, 19 May 2005 11:05:57 +0800
- Subject: Re: add program header to elf
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
========================================================================
============