Relinker: Linux output keeps the input PT_PHDR and PT_INTERP; an input PT_PHDR crashes at start #2816
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ctj01 on 2026-10-10T16:02:30Z.
What
The Linux output keeps the input's
PT_PHDRandPT_INTERPnext to the onesLinuxElfPatcherwrites, becauseSegmentFilter::ShouldSkip(core/relinker/elfpatcher/src/general/SegmentFilter.cpp) only drops SCE segments,PT_DYNAMICand somePT_NOTEs. Inputs from a standard toolchain carry both entries, for example ELFs linked with lld such as the ps5-payload-dev SDK homebrew in #2136. Raised in the review of #1559.PT_PHDR: glibc'srtld.csets the main map's load bias from everyPT_PHDRin turn (l_addr = phdr - p_vaddr), so the last one wins. That is the input's entry, whosep_vaddris where the table sat before relinking. The load bias comes out wrong and the executable crashes at start.PT_INTERP: the kernel uses the first one, which is the synthetic entry since #1559, so a lone inputPT_INTERPis harmless. The output still has two, which the gABI forbids.Reproduction
Synthetic lld-style inputs (one
PT_LOADcovering the ELF header at address 0, text, data,PT_DYNAMIC, nine header slots), relinked with--skip-sce-moduleonmainba2a0a31and run on WSL2 Ubuntu 24.04 (kernel 5.15.167, glibc 2.39):mainPT_INTERPonlyPT_INTERPin the outputPT_PHDRonlyFAIL: Not enough program header slots: need 10, available 9Proposed fix
Drop both entries in
SegmentFilter::ShouldSkip, as it dropsPT_DYNAMIC:The guest module writer already keeps only
PT_LOAD,PT_TLS,PT_GNU_EH_FRAMEandPT_GNU_STACK, and Windows output does not useSegmentFilter.A branch with the change and a regression test is ready: https://github.com/ctj01/AnyPS5/tree/fix/relinker-drop-input-phdr-interp (commit
5701d048). It was opened as #2814 and closed by the PR intake rule. The testlinux_input_program_headerscovers the four inputs above, plus both entries with exactly eight slots. For each output it checks:PT_PHDRand onePT_INTERP;PT_PHDRis first, covers the table, and matches thePT_LOADthat maps it;PT_INTERPnames the host interpreter and precedes the firstPT_LOAD;It fails without the change and passes with it. The full suite passes with the change: 699/699 on that WSL2 setup.
Anyone who can open pull requests is welcome to take the commit as is.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by danzaio on 2026-10-10T17:19:01Z.
Validated the carried branch on Windows: MinGW 15.2 relinker-only build, linux_input_program_headers passes (structural checks; the run-until-entry half is Linux-only). Red fails without the one-line filter, green passes with it. The branch is here if a collaborator wants to carry it: danzaio/AnyPS5 fix/relinker-phdr-interp. AI-assisted: yes.