relinker: --linux-fixed-base rebases the stale program header table when the table has to grow #6393
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 midasmatterhorn on 2026-10-15T13:56:06Z.
When the input's program header table has to grow (fewer free slots than the output needs),
Patchrelocates the table to the end of the file (tableOff = buf.size(),e_phoffrewritten at core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp:311-319). The--linux-fixed-basepass then rebases the wrong table:RebaseProgramHeaders(line 339) still receives the input'sphOff, soPT_LOADp_vaddr/p_paddrkeep un-rebased values whilee_entryand theDT_*tags are rebased, producing a silently inconsistentET_EXECwhose entry point lies outside everyPT_LOAD; andSegmentFilterdropped from the output (FAIL: Program header address ... lies outside the Linux user address space at fixed base 0x400000for aPT_DYNAMICaddress that exists only in the input).Reproduced with a relinker-only build of
main92cdc7b62on macOS 27.0.1 arm64, on a minimalET_EXECfixture (onePT_LOADwith code, aPT_DYNAMIC, extraPT_SCE_VERSIONheaders to controle_phnum):e_phnum = 3(table fits)e_phoff=0x40, entry mappede_phnum = 3(table grows to0x8150)e_phoff=0x8150,entry=0x1118, entry mappede_phnum = 3(table grows)--linux-fixed-base 0x400000e_phoff=0x8150,entry=0x401118, entry not mapped — loads still at0x0/0x1000/0x4000e_phnum = 6(table fits)--linux-fixed-base 0x4000000x400000..., entry mapped (correct)e_phnum = 3, inputPT_DYNAMICat0x7ffffffffff0(dropped from output)--linux-fixed-base 0x400000FAIL: Program header address 0x7ffffffffff0 lies outside the Linux user address space at fixed base 0x400000test_linux_fixed_base.pycovers onlye_phnum == RequiredProgramHeaderCount, where the table never moves, so this is untested.Suggested fix: pass the relocated table position to the rebase pass —
RebaseProgramHeaders(buf, tableOff, phEntSize, writtenPh, base);— and rebase only the headers that were written.Found by an AI-assisted audit (DeepSeek V4.1 Flash via OpenCode); every row above was executed against the real
relinkerbinary. I can send the fix with regression tests covering the grown-table case.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T14:10:03Z.
The growth case reproduces on current main: with a three-entry input table, the fixed-base output puts the entry at
0x401118outside every PT_LOAD. PR #6403 rebases the output table at its new offset and adds a regression check that fails on the unmodified main binary and passes with the fix.