[PATCH] static-pie: Use the first PT_LOAD segment at offset 0 [BZ #32763]

H.J. Lu hjl.tools@gmail.com
Wed Mar 5 03:02:59 GMT 2025


As shown in

https://sourceware.org/bugzilla/show_bug.cgi?id=32761

linker may generate more than one PT_LOAD segments at offset 0

Elf file type is DYN (Position-Independent Executable file)
Entry point 0x7170
There are 13 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000001c8801 0x00000000001c8801  R E    0x1000
  LOAD           0x00000000001c9000 0x00000000001c9000 0x00000000001c9000
                 0x00000000000fa130 0x00000000000fa130  R      0x1000
  LOAD           0x00000000002c32f0 0x00000000002c42f0 0x00000000002c42f0
                 0x00000000000e8944 0x00000000000e8944  RW     0x1000
  LOAD           0x0000000000000000 0x00000000003b0000 0x00000000003b0000
                 0x0000000000000000 0x0000000000b5dce8  RW     0x10000
  DYNAMIC        0x00000000003a3768 0x00000000003a4768 0x00000000003a4768
                 0x00000000000001d0 0x00000000000001d0  RW     0x8
  NOTE           0x0000000000000318 0x0000000000000318 0x0000000000000318
                 0x0000000000000024 0x0000000000000024  R      0x4
  NOTE           0x00000000002c30d0 0x00000000002c30d0 0x00000000002c30d0
                 0x0000000000000040 0x0000000000000040  R      0x8
  NOTE           0x00000000002c3110 0x00000000002c3110 0x00000000002c3110
                 0x0000000000000020 0x0000000000000020  R      0x4
  TLS            0x00000000002c32f0 0x00000000002c42f0 0x00000000002c42f0
                 0x0000000000000070 0x00000000000001a0  R      0x8
  GNU_PROPERTY   0x00000000002c30d0 0x00000000002c30d0 0x00000000002c30d0
                 0x0000000000000040 0x0000000000000040  R      0x8
  GNU_EH_FRAME   0x0000000000278900 0x0000000000278900 0x0000000000278900
                 0x000000000000afdc 0x000000000000afdc  R      0x4
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10
  GNU_RELRO      0x00000000002c32f0 0x00000000002c42f0 0x00000000002c42f0
                 0x00000000000e0d10 0x00000000000e0d10  R      0x1

 Section to Segment mapping:
  Segment Sections...
   00     .note.gnu.build-id .init .plt .plt.got .text .fini
   01     .gnu.hash .dynsym .dynstr .rela.dyn .rela.plt .rodata
.stapsdt.base rodata.cst32 .eh_frame_hdr .eh_frame .gcc_except_table
.note.gnu.property .note.ABI-tag
   02     .tdata .init_array .fini_array .data.rel.ro .dynamic .got
.got.plt .data
   03     .bss
   04     .dynamic
   05     .note.gnu.build-id
   06     .note.gnu.property
   07     .note.ABI-tag
   08     .tdata .tbss
   09     .note.gnu.property
   10     .eh_frame_hdr
   11
   12     .tdata .init_array .fini_array .data.rel.ro .dynamic .got

Use the first PT_LOAD segment at offset 0, instead of the last one, to
support such binaries.  This fixes BZ #32763.

OK for master?

Thanks.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-static-pie-Use-the-first-PT_LOAD-segment-at-offset-0.patch
Type: text/x-patch
Size: 4270 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250305/954793ba/attachment.bin>


More information about the Libc-alpha mailing list