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]
Other format: [Raw text]

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
========================================================================
============


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