relinker: Linux extra PT_LOAD can share a page with the tail of the last guest segment #4913
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 sudocharlinho on 2026-10-13T03:48:24Z.
On Linux output,
ProgramHeaderLayoutBuilder::ComputeExtraBlockVaddrcan place the relinker's extra RWXPT_LOADin the same 4 KiB page as the tail of the highest guestPT_LOAD. The loader then maps that page from the extra block's file page, so the guest reads file bytes where the end of its.data/.bssshould be.Cause
core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp(main6124bf063):The comparison is on byte addresses, not pages. With
E= highest keptPT_LOADend (p_vaddr + p_memsz) andF= extra block file offset (the unpadded input size,LinuxElfPatcher.cpp), the block shares the last guest page wheneverE % 0x1000 != 0andF % 0x1000 >= E % 0x1000.Example:
E = 0x2800,F = 0x8A00gives0x2A00. The kernel maps page0x2000again,MAP_FIXED, from file page0x8000, after the earlier segment's bss was zero-filled.LinuxGuestModuleWriter.cppdoes not have this: it aligns both the file and the address up to0x4000before appending.Reach
PT_LOADis the file-backed dynlib-data segment ending next to end of file (both mappings then show the same file page).PT_LOADends in.bsswith other data after it in the file: PS4-layout executables and lld-linked homebrew.ProgramLayoutRangeTests.cppuses end0x2000; the Python Linux fixtures have page-aligned sizes).Status
Found by reading the code with AI assistance. Not observed on a title: no real input was relinked, so I have no title ID or log. The arithmetic is confirmed by a unit case: on main,
ComputeExtraBlockVaddrwith a load0x1000..0x2800and offset0x8A00returns0x2A00.Possible fix
With this and two added cases in
ProgramLayoutRangeTests.cpp(0x8A00 -> 0x3A00,0x8100 -> 0x3100), the relinker-only build passes 134/134 tests on macOS (Apple silicon, AppleClang 21); the added cases fail on main. Existing expectations are unchanged (0x2000with offset0x1003still gives0x2003).I am not opening a pull request; anyone is welcome to take this.
Imported from boykopovar/AnyPS5. Originally posted by LeandroSSB on 2026-10-13T04:01:59Z.
Taken:
LeandroSSB/AnyPS5:fix/relinker-extra-ptload-page(one commit,c3aa504ab, on currentmain). Your diff applied as-is; the two regression cases (0x8A00 → 0x3A00,0x8100 → 0x3100) are inProgramLayoutRangeTests.cpp, and the existing expectations are unchanged.Validated on Linux (GCC 13.3, relinker-only build,
BUILD_TESTING=ON): 143/143 tests pass, including the two new cases;tools/check_conventions.py --base origin/mainpasses. Not opened as a PR because of the intake pause; a maintainer is welcome to carry the commit.AI-assisted (Claude Code); I ran the validation above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by mariuszkreft on 2026-10-13T23:01:43Z.
Opened a pull request from this issue: https://github.com/boykopovar/AnyPS5/pull/5534
Imported from boykopovar/AnyPS5. Originally posted by mariuszkreft on 2026-10-13T23:06:44Z.
Opened a pull request from this issue: https://github.com/boykopovar/AnyPS5/pull/5535
Imported from boykopovar/AnyPS5. Originally posted by mariuszkreft on 2026-10-13T23:11:26Z.
Opened a pull request from this issue: https://github.com/boykopovar/AnyPS5/pull/5535
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:53:52Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.