I encountered a Segmentation Fault when running a Python binary built for loongarch64-unknown-linux-gnu. After investigation, the root cause is that the ELF segments were realigned/restructured using a page size (likely 4KB) that is incompatible with the target system's kernel page size (16KB or 64KB).
This is a similar issue to:
root@linux-loong64:/tmp/build# unzip cpython-3.10-loongarch64-unknown-linux-gnu-lto.zip
Archive: cpython-3.10-loongarch64-unknown-linux-gnu-lto.zip
extracting: cpython-3.10.20-loongarch64-unknown-linux-gnu-lto-20260411T1217.tar.zst
root@linux-loong64:/tmp/build# tar -xf cpython-3.10.20-loongarch64-unknown-linux-gnu-lto-20260411T1217.tar.zst
root@linux-loong64:/tmp/build# cd python/install/bin/
root@linux-loong64:/tmp/build/python/install/bin# /opt/clang/bin/llvm-strip --strip-debug python -o python-strip
root@linux-loong64:/tmp/build/python/install/bin# ./python-strip -V
段错误 ./python-strip -V
root@linux-loong64:/tmp/build/python/install/bin# /opt/clang/bin/readelf -l python python-strip
File: python
Elf file type is DYN (Shared object file)
Entry point 0x151288
There are 13 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0002d8 0x0002d8 R 0x8
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x149640 0x149640 R E 0x4000
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
LOAD 0x150000 0x0000000000150000 0x0000000000150000 0xf4b1b8 0xf4b1b8 R E 0x10000
GNU_EH_FRAME 0xef617c 0x0000000000ef617c 0x0000000000ef617c 0x030b24 0x030b24 R 0x4
NOTE 0x109b120 0x000000000109b120 0x000000000109b120 0x000020 0x000020 R 0x4
NOTE 0x109b140 0x000000000109b140 0x000000000109b140 0x000078 0x000078 R 0x4
LOAD 0x109b6e0 0x000000000109f6e0 0x000000000109f6e0 0x0ff368 0x10f5c8 RW 0x4000
GNU_RELRO 0x109b6e0 0x000000000109f6e0 0x000000000109f6e0 0x09c920 0x09c920 R 0x1
DYNAMIC 0x6196000 0x0000000006196000 0x0000000006196000 0x0001e0 0x0001e0 RW 0x8
LOAD 0x6196000 0x0000000006196000 0x0000000006196000 0x00cee0 0x00cee0 RW 0x1000
INTERP 0x61a2e90 0x00000000061a2e90 0x00000000061a2e90 0x000025 0x000025 R 0x1
[Requesting program interpreter: /lib64/ld-linux-loongarch-lp64d.so.1]
NOTE 0x61a2eb8 0x00000000061a2eb8 0x00000000061a2eb8 0x000024 0x000024 R 0x4
Section to Segment mapping:
Segment Sections...
00
01 .dynsym .gnu.version .gnu.version_r .rela.dyn .rela.plt .plt
02
03 .text .rodata .eh_frame_hdr .eh_frame .note.ABI-tag .note.package
04 .eh_frame_hdr
05 .note.ABI-tag
06 .note.package
07 .init_array .fini_array .data.rel.ro .got .got.plt .data .PyRuntime .sdata .bss
08 .init_array .fini_array .data.rel.ro .got
09 .dynamic
10 .dynamic .dynstr .gnu.hash .interp .note.gnu.build-id
11 .interp
12 .note.gnu.build-id
None .comment .debug_aranges .debug_info .debug_abbrev .debug_line .debug_str .debug_line_str .debug_loclists .debug_rnglists .symtab .strtab .shstrtab
File: python-strip
Elf file type is DYN (Shared object file)
Entry point 0x151288
There are 13 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0002d8 0x0002d8 R 0x8
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x149640 0x149640 R E 0x4000
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
LOAD 0x150000 0x0000000000150000 0x0000000000150000 0xf4b1b8 0xf4b1b8 R E 0x10000
GNU_EH_FRAME 0xef617c 0x0000000000ef617c 0x0000000000ef617c 0x030b24 0x030b24 R 0x4
NOTE 0x109b120 0x000000000109b120 0x000000000109b120 0x000020 0x000020 R 0x4
NOTE 0x109b140 0x000000000109b140 0x000000000109b140 0x000078 0x000078 R 0x4
LOAD 0x109b6e0 0x000000000109f6e0 0x000000000109f6e0 0x0ff368 0x10f5c8 RW 0x4000
GNU_RELRO 0x109b6e0 0x000000000109f6e0 0x000000000109f6e0 0x09c920 0x09c920 R 0x1
DYNAMIC 0x119b000 0x0000000006196000 0x0000000006196000 0x0001e0 0x0001e0 RW 0x8
LOAD 0x119b000 0x0000000006196000 0x0000000006196000 0x00cee0 0x00cee0 RW 0x1000
INTERP 0x11a7e90 0x00000000061a2e90 0x00000000061a2e90 0x000025 0x000025 R 0x1
[Requesting program interpreter: /lib64/ld-linux-loongarch-lp64d.so.1]
NOTE 0x11a7eb8 0x00000000061a2eb8 0x00000000061a2eb8 0x000024 0x000024 R 0x4
Section to Segment mapping:
Segment Sections...
00
01 .dynsym .gnu.version .gnu.version_r .rela.dyn .rela.plt .plt
02
03 .text .rodata .eh_frame_hdr .eh_frame .note.ABI-tag .note.package
04 .eh_frame_hdr
05 .note.ABI-tag
06 .note.package
07 .init_array .fini_array .data.rel.ro .got .got.plt .data .PyRuntime .sdata .bss
08 .init_array .fini_array .data.rel.ro .got
09 .dynamic
10 .dynamic .dynstr .gnu.hash .interp .note.gnu.build-id
11 .interp
12 .note.gnu.build-id
None .comment .symtab .strtab .shstrtab
I encountered a Segmentation Fault when running a Python binary built for
loongarch64-unknown-linux-gnu. After investigation, the root cause is that the ELF segments were realigned/restructured using a page size (likely 4KB) that is incompatible with the target system's kernel page size (16KB or 64KB).This is a similar issue to: