patchelf
patchelf copied to clipboard
Implement `--append-null-phdr` option
Appends PT_NULL entries to the program header table so that can may be easily targeted by custom tools. Also add automated tests for it. Releated issue: #533.
It works but I can't figure out how to adjust the PT_LOAD segments to cover the expanded PT_PHDR size. Can you give me some pointers?
Output of readelf --file-header --program-headers patched:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x20284c
Start of program headers: 64 (bytes into file)
Start of section headers: 201432 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 16
Section header string table index: 14
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040
0x00000000000001f8 0x00000000000001f8 R 0x8
readelf: Error: the PHDR segment is not covered by a LOAD segment
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x0
LOAD 0x0000000000000000 0x0000000000200000 0x0000000000200000
0x000000000000184c 0x000000000000184c R 0x1000
LOAD 0x000000000000184c 0x000000000020284c 0x000000000020284c
0x000000000000b550 0x000000000000b550 R E 0x1000
LOAD 0x000000000000cda0 0x000000000020eda0 0x000000000020eda0
0x00000000000000b8 0x00000000000000b8 RW 0x1000
GNU_RELRO 0x000000000000cda0 0x000000000020eda0 0x000000000020eda0
0x00000000000000b8 0x0000000000000260 R 0x1
LOAD 0x000000000000ce58 0x000000000020fe58 0x000000000020fe58
0x0000000000001358 0x000000000010136d RW 0x1000
NULL 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0
NULL 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0
Section to Segment mapping:
Segment Sections...
00
01
02 .rodata
03 .text
04 .data.rel.ro .got
05 .data.rel.ro .got
06 .data .bss
07
08