Skip to content

llvm-objcopy produces wrong p_offset when PT_INTERP/PT_LOAD offsets are equal #79887

Closed
@chestnykh

Description

@chestnykh

Considering the following layout

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x000268 0x000268 R   0x8
  INTERP         0x195000 0x0000000000195000 0x0000000000195000 0x00000f 0x00000f R   0x1
      [Requesting program interpreter: ]
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x1948c9 0x1948c9 R E 0x1000
  LOAD           0x195000 0x0000000000195000 0x0000000000195000 0x0df960 0x0df960 R   0x1000

llvm-objcopy produces ELF with the output below:

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x000268 0x000268 R   0x8
  INTERP         0x1948c9 0x0000000000195000 0x0000000000195000 0x00000f 0x00000f R   0x1
      [Requesting program interpreter: ]
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x1948c9 0x1948c9 R E 0x1000
  LOAD           >>>>0x1948c9<<<< 0x0000000000195000 0x0000000000195000 0x0df960 0x0df960 R   0x1000

The p_offset of the 2nd PT_LOAD seg has incorrect value obtained from p_memsz of the first PT_LOAD segment
GNU objcopy (on the real ELF i have got) aligns p_offset to p_align of PT_LOAD segment that produces 0x195000 as the value of p_offset for the 2nd PT_LOAD.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions