Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --append-null-phdr option #534

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

matheusmoreira
Copy link

@matheusmoreira matheusmoreira commented Nov 21, 2023

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

Adds trailing PT_NULL program header entries to the ELF.
Those entries can then be easily edited by custom tools.
Use readelf to test that the switch appends the expected number
of PT_NULL program header table entries to the ELF file.
Convenience for appending multiple PT_NULL program headers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant