fix(relinker): keep a segment's zero-filled tail zero when the next PT_LOAD starts on its page #6681

Merged
milescoviello merged 1 commit from upstream-pr/6681 into main 2026-10-19 08:48:55 +00:00
milescoviello commented 2026-10-16 04:23:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T04:23:57Z.


What

Nuvio Max'd 0.5.27-native-experimental (PPSA99288, the catalog update of 10-16) segfaults at launch on Linux, before its first log line:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6f3b5bf in scePthreadMutexLock () from .../libs/libkernel.prx
#1  pthread_mutex_lock_nid_postfix () from .../libs/libkernel.prx
=> mov 0x58(%rbx),%rax        rbx 0xfde69bc4f9278673

The mutex is a global in the title's bss at 0x5495038, and it holds 0xfde69bc4f9278673, not zero. The title's last two PT_LOADs are:

PT_LOAD Offset VirtAddr FileSiz MemSiz
data 0x3ac0000 0x3abc000 0xda78 0x19d9c20 (bss up to 0x5495c20)
next 0x3acdc20 0x5495c20 0x1e17b0 0x1e17b0

The next segment starts at 0x5495c20, on the page that holds the last 0xc20 bytes of the data segment's bss. The kernel maps each PT_LOAD from the start of its page, so page 0x5495000 is mapped again from file page 0x3acd000. The bss tail then reads the file bytes in front of the next segment, which are the end of the data segment's own file bytes. 0xfde69bc4f9278673 is the 8 bytes at file offset 0x3acd038. On the console the bss is zero. #4913 described the same page sharing for the relinker's own extra PT_LOAD, which main now starts on a page of its own (GuestLoadPageEnd). Here it's two of the title's own segments. Windows output isn't affected: WindowsLoadImage copies each segment's file bytes into the image and leaves the rest zero.

LinuxElfPatcher now checks each PT_LOAD that starts inside a page. It compares the bytes the kernel maps in front of the segment with what the segments below put there: their file bytes, and zero for their zero-filled part. If they differ, the segment is appended to the output at an offset with the same page offset. In front of it go that page's correct bytes, and its header points there. If they already match, nothing changes.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release), kernel 6.8, RTX 4070 Ti, NVIDIA 595.99.

  • linux_load_pages (new, no GPU): it patches small ELFs through LinuxElfPatcher and maps the output's PT_LOADs the way the kernel does, page by page, zeroing past the file size. Then it requires every segment's memory to hold its file bytes and zeros. It has three cases: bss alone below the next segment, file bytes and bss below it, and zeros already in front of it (the segment must stay where it is). With main's LinuxElfPatcher.cpp it fails with bss sharing a page with the next segment: byte at 0x2000 reads 0xaa, not 0x00. With this change it passes 3 of 3.
  • ctest without the GPU tests (-E "^agc_|shader|spirv|recompiler|request_serializer", 667 tests, the relinker fixture tests included): all pass, and the video-out ones skip as on main.
  • 93 eboots converted here: in 80, the bytes in front of such a segment are already zero, so nothing changes. Of 10 of those relinked with main's relinker and this one (homebrew, plus MGS4 PPSA18194 and Steins;Gate PPSA36591), all 10 outputs are byte-identical. These 13 have nonzero bytes in a bss tail on main and zero with this change (nonzero bytes on main): PPSA99288 (1122), PPSA69420 (122), PPSA99621 (89), PPSA99728 (82), PPSA99015 (62), PPSA99082 (62), PPSA99110 (49), PPSA99305 (31), PPSA99641 (19), PPSA99007 (18), PPSA98766 (16), PPSA99313 (15), PPSA99003 (3). Their outputs grow by the size of the moved segment (0.05 to 2.9 MB). Apart from Nuvio, I don't know whether any of them reads those bytes before writing them.

Nuvio Max'd 0.5.27-native-experimental (PPSA99288), 90 s with scripted pad input. Both builds use the same main 5d9dcc42d libraries and differ only in the relinker that converted the title. Three runs each:

Relinker Result
main 5d9dcc42d segfault at launch, exit 139 (3 of 3)
this PR runs to the limit (3 of 3)

With this PR it goes through the same startup stages as 0.5.23, the previous catalog build, up to startup stage=input-ready (first picture at about 5 s). Its network requests fail only because my sandbox has no network. 0.5.23's file in front of that segment holds zeros, which is why it ran on main.

@simonbbby checked it under the real kernel (Ubuntu 24.04, kernel 7.0.0-38). They built static PIEs from the test's three layouts, kept the patcher's PT_LOADs, and added a checker that reads the earlier segment's file bytes, its whole zero-filled tail and the next segment's bytes. With the parent patcher the two affected layouts exit with the bss mismatch in 5 of 5 runs, and with this PR all three layouts match in 5 of 5. The test also fails on main's LinuxElfPatcher.cpp there at the same 0x2000 reads 0xaa, not 0x00 assertion.

@snoozedDev found a retail title that stops on this: Grand Theft Auto III – The Definitive Edition (PPSA03527 v01.007.000). On main af0fff762 its main thread segfaults about a second after the swapchain is created, and with this PR (head ce0b7672d) it runs (Linux, GCC 16.2.1, RTX 3090).

Not checked on macOS or on a console.

@screamm cross-checked the relinker side on Windows. linux_load_pages passes 3 of 3 and fails with main's LinuxElfPatcher.cpp, and the 102 relinker tests pass. Over 51 local titles, Linux output changes in 6, each by one PT_LOAD moving to a page-congruent offset with its bytes unchanged. Windows output is identical.

  • @babyhuey reproduced it in the current catalog: Régie5 0.6.0 (PPSA99520). On main 0bc3003f8 it hits SIGSEGV in scePthreadMutexLock in 2 of 2 runs. The mutex is in the bss tail of the RW segment, whose page was mapped from the next segment's file page. With this PR (24ec391c0) both runs get past it, to the headless DisplayWindow stop.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04 (title runs; the test needs no GPU)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4883454195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T04:23:57Z. --- ### What Nuvio Max'd 0.5.27-native-experimental (PPSA99288, the catalog update of 10-16) segfaults at launch on Linux, before its first log line: ``` Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6f3b5bf in scePthreadMutexLock () from .../libs/libkernel.prx #1 pthread_mutex_lock_nid_postfix () from .../libs/libkernel.prx => mov 0x58(%rbx),%rax rbx 0xfde69bc4f9278673 ``` The mutex is a global in the title's bss at 0x5495038, and it holds 0xfde69bc4f9278673, not zero. The title's last two PT_LOADs are: | PT_LOAD | Offset | VirtAddr | FileSiz | MemSiz | |---|---|---|---|---| | data | 0x3ac0000 | 0x3abc000 | 0xda78 | 0x19d9c20 (bss up to 0x5495c20) | | next | 0x3acdc20 | 0x5495c20 | 0x1e17b0 | 0x1e17b0 | The next segment starts at 0x5495c20, on the page that holds the last 0xc20 bytes of the data segment's bss. The kernel maps each PT_LOAD from the start of its page, so page 0x5495000 is mapped again from file page 0x3acd000. The bss tail then reads the file bytes in front of the next segment, which are the end of the data segment's own file bytes. 0xfde69bc4f9278673 is the 8 bytes at file offset 0x3acd038. On the console the bss is zero. #4913 described the same page sharing for the relinker's own extra PT_LOAD, which `main` now starts on a page of its own (`GuestLoadPageEnd`). Here it's two of the title's own segments. Windows output isn't affected: `WindowsLoadImage` copies each segment's file bytes into the image and leaves the rest zero. `LinuxElfPatcher` now checks each PT_LOAD that starts inside a page. It compares the bytes the kernel maps in front of the segment with what the segments below put there: their file bytes, and zero for their zero-filled part. If they differ, the segment is appended to the output at an offset with the same page offset. In front of it go that page's correct bytes, and its header points there. If they already match, nothing changes. ### Tested Linux (Ubuntu 24.04, GCC 13.3, Release), kernel 6.8, RTX 4070 Ti, NVIDIA 595.99. - `linux_load_pages` (new, no GPU): it patches small ELFs through `LinuxElfPatcher` and maps the output's PT_LOADs the way the kernel does, page by page, zeroing past the file size. Then it requires every segment's memory to hold its file bytes and zeros. It has three cases: bss alone below the next segment, file bytes and bss below it, and zeros already in front of it (the segment must stay where it is). With `main`'s `LinuxElfPatcher.cpp` it fails with `bss sharing a page with the next segment: byte at 0x2000 reads 0xaa, not 0x00`. With this change it passes 3 of 3. - ctest without the GPU tests (`-E "^agc_|shader|spirv|recompiler|request_serializer"`, 667 tests, the relinker fixture tests included): all pass, and the video-out ones skip as on `main`. - 93 eboots converted here: in 80, the bytes in front of such a segment are already zero, so nothing changes. Of 10 of those relinked with `main`'s relinker and this one (homebrew, plus MGS4 PPSA18194 and Steins;Gate PPSA36591), all 10 outputs are byte-identical. These 13 have nonzero bytes in a bss tail on `main` and zero with this change (nonzero bytes on `main`): PPSA99288 (1122), PPSA69420 (122), PPSA99621 (89), PPSA99728 (82), PPSA99015 (62), PPSA99082 (62), PPSA99110 (49), PPSA99305 (31), PPSA99641 (19), PPSA99007 (18), PPSA98766 (16), PPSA99313 (15), PPSA99003 (3). Their outputs grow by the size of the moved segment (0.05 to 2.9 MB). Apart from Nuvio, I don't know whether any of them reads those bytes before writing them. Nuvio Max'd 0.5.27-native-experimental (PPSA99288), 90 s with scripted pad input. Both builds use the same `main` 5d9dcc42d libraries and differ only in the relinker that converted the title. Three runs each: | Relinker | Result | |---|---| | `main` 5d9dcc42d | segfault at launch, exit 139 (3 of 3) | | this PR | runs to the limit (3 of 3) | With this PR it goes through the same startup stages as 0.5.23, the previous catalog build, up to `startup stage=input-ready` (first picture at about 5 s). Its network requests fail only because my sandbox has no network. 0.5.23's file in front of that segment holds zeros, which is why it ran on `main`. @simonbbby [checked it under the real kernel](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6209513917) (Ubuntu 24.04, kernel 7.0.0-38). They built static PIEs from the test's three layouts, kept the patcher's PT_LOADs, and added a checker that reads the earlier segment's file bytes, its whole zero-filled tail and the next segment's bytes. With the parent patcher the two affected layouts exit with the bss mismatch in 5 of 5 runs, and with this PR all three layouts match in 5 of 5. The test also fails on `main`'s `LinuxElfPatcher.cpp` there at the same `0x2000 reads 0xaa, not 0x00` assertion. @snoozedDev [found a retail title that stops on this](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6228767262): Grand Theft Auto III – The Definitive Edition (PPSA03527 v01.007.000). On `main` af0fff762 its main thread segfaults about a second after the swapchain is created, and with this PR (head `ce0b7672d`) it runs (Linux, GCC 16.2.1, RTX 3090). Not checked on macOS or on a console. @screamm [cross-checked the relinker side on Windows](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6233430658). `linux_load_pages` passes 3 of 3 and fails with `main`'s `LinuxElfPatcher.cpp`, and the 102 relinker tests pass. Over 51 local titles, Linux output changes in 6, each by one PT_LOAD moving to a page-congruent offset with its bytes unchanged. Windows output is identical. - @babyhuey [reproduced it in the current catalog](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6255754691): Régie5 0.6.0 (PPSA99520). On `main` 0bc3003f8 it hits SIGSEGV in `scePthreadMutexLock` in 2 of 2 runs. The mutex is in the bss tail of the `RW` segment, whose page was mapped from the next segment's file page. With this PR (24ec391c0) both runs get past it, to the headless `DisplayWindow` stop. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04 (title runs; the test needs no GPU) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-16 04:35:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T04:35:04Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7417 core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp L95

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7173 core/relinker/CMakeLists.txt
PR 7332 core/relinker/CMakeLists.txt
PR 7453 core/relinker/CMakeLists.txt
PR 7594 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208164018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6208164018). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T04:35:04Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp` [L95](https://github.com/boykopovar/AnyPS5/blob/e12c913571a4054e4098d905ff3af5b60ea5b792/core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp#L95) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `core/relinker/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/CMakeLists.txt` | | [PR 7453](https://www.github.com/boykopovar/AnyPS5/pull/7453) | `core/relinker/CMakeLists.txt` | | [PR 7594](https://www.github.com/boykopovar/AnyPS5/pull/7594) | `core/relinker/CMakeLists.txt` |
simonbbby commented 2026-10-16 06:26:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-16T06:26:44Z.


Independent real Linux kernel loading control at exact head ce0b7672d33157c0eea55281109eb0fd3745e7f4, using synthetic ELF inputs only. Ubuntu 24.04 / kernel 7.0.0-38 / GCC 13.3, Ryzen 9 9950X.

Compiled the production patcher and the same support sources listed for linux_load_pages_tests. The unchanged stock test passes with the PR and fails with only LinuxElfPatcher.cpp replaced by HEAD^ at the reported 0x2000 reads 0xaa, not 0x00 assertion.

I reused the three fixture layout geometries in a separate generator, with a 123-byte position-independent x86-64 checker in an enlarged synthetic text segment and a readable final segment. ELF version/header-size fields are initialized. After Patcher().Patch, the harness changes only the entry point to that checker and changes PT_INTERP to PT_NULL, producing an asset-free static PIE that needs no runtime libraries. The patcher's emitted PT_LOADs are preserved. Each image is executed directly, so the kernel maps those segments.

The checker reads the earlier segment's file bytes, its entire BSS tail and the next segment's file bytes. It exits 41 for an earlier-file mismatch, 42 for a BSS mismatch, 43 for a next-file mismatch, or 0 when all match.

Layout Parent patcher output, 5 fresh execs PR patcher output, 5 fresh execs
BSS below next segment 5/5 exit 42 5/5 exit 0
File bytes and BSS below next segment 5/5 exit 42 5/5 exit 0
Already-correct zero prefix 5/5 exit 0 5/5 exit 0

The already-correct case keeps the next segment at file offset 0x2c20 on both versions. The two affected cases move from 0x1c20 to 0x4c20, and from 0x2c20 to 0x5c20, respectively. A traced execution shows successful execve followed by exit(42) for the parent and exit(0) for the PR.

This confirms the zero-tail repair under the actual kernel's PT_LOAD mapping, with intact file-data controls and an unchanged-layout positive control. No repository source changed. Scope: these synthetic static PIEs and the stock patcher test; no full relinker/runtime, dynamic-linker startup, title replay or macOS run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6209513917 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6209513917). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-16T06:26:44Z. --- Independent **real Linux kernel loading** control at exact head `ce0b7672d33157c0eea55281109eb0fd3745e7f4`, using synthetic ELF inputs only. Ubuntu 24.04 / kernel 7.0.0-38 / GCC 13.3, Ryzen 9 9950X. Compiled the production patcher and the same support sources listed for `linux_load_pages_tests`. The unchanged stock test passes with the PR and fails with only `LinuxElfPatcher.cpp` replaced by `HEAD^` at the reported `0x2000 reads 0xaa, not 0x00` assertion. I reused the three fixture layout geometries in a separate generator, with a 123-byte position-independent x86-64 checker in an enlarged synthetic text segment and a readable final segment. ELF version/header-size fields are initialized. After `Patcher().Patch`, the harness changes only the entry point to that checker and changes `PT_INTERP` to `PT_NULL`, producing an asset-free static PIE that needs no runtime libraries. **The patcher's emitted PT_LOADs are preserved.** Each image is executed directly, so the kernel maps those segments. The checker reads the earlier segment's file bytes, its entire BSS tail and the next segment's file bytes. It exits 41 for an earlier-file mismatch, 42 for a BSS mismatch, 43 for a next-file mismatch, or 0 when all match. | Layout | Parent patcher output, 5 fresh execs | PR patcher output, 5 fresh execs | |---|---|---| | BSS below next segment | 5/5 exit **42** | 5/5 exit **0** | | File bytes and BSS below next segment | 5/5 exit **42** | 5/5 exit **0** | | Already-correct zero prefix | 5/5 exit **0** | 5/5 exit **0** | The already-correct case keeps the next segment at file offset `0x2c20` on both versions. The two affected cases move from `0x1c20` to `0x4c20`, and from `0x2c20` to `0x5c20`, respectively. A traced execution shows successful `execve` followed by `exit(42)` for the parent and `exit(0)` for the PR. This confirms the zero-tail repair under the actual kernel's PT_LOAD mapping, with intact file-data controls and an unchanged-layout positive control. No repository source changed. Scope: these synthetic static PIEs and the stock patcher test; no full relinker/runtime, dynamic-linker startup, title replay or macOS run.
milescoviello commented 2026-10-16 06:28:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T06:28:53Z.


Thanks @simonbbby, that's the check I couldn't do in the test, since the test models the kernel's mapping instead of using it. I added your results to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6209542458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6209542458). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T06:28:53Z. --- Thanks @simonbbby, that's the check I couldn't do in the test, since the test models the kernel's mapping instead of using it. I added your results to the description. AI-assisted: yes
snoozedDev commented 2026-10-17 02:57:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by snoozedDev on 2026-10-17T02:57:19Z.


A retail title that stops on this on main: Grand Theft Auto III – The Definitive Edition (PPSA03527 v01.007.000, retail disc). This PR (head ce0b7672d) fixes it.

Tree: main af0fff762 with #6236 (merged since), using APS5_PLAYGO_UNLISTED_CHUNKS=absent to get past #6205. Linux (kernel 7.2.5), GCC 16.2.1, Release, RTX 3090, NVIDIA 610.57.04, inside gamescope --backend headless.

The stop: the main thread segfaults about a second after the swapchain is created. Cold, that is at 579 s, after 575 s of shader registration. Warm, it is 3 to 9 s after launch. From the kernel log of the cold run:

app.elf[2514698]: segfault at 800000021 ip 0000604b9d87ac21 sp 00007ffe3f7f1ba0 error 4 in app.elf[1c3ac21,604b9bc44000+46c9000]

The fault address was the same in all three runs where I captured it (one cold, two warm, the warm ones through a SIGSEGV handler that the write-watch handler chains to). The faulting instruction is cmpq $0x0,0x20(%rdi) at vaddr 0x1c36c21 in the converted app.elf (file offset 0x1c3ac21, as in the kernel line), with rdi = 0x800000001. The function at 0x45faf20 loads that value from the global at 0x6690020. The title only initializes that global while it reads zero, so it uses the nonzero value as an object pointer.

Why it is nonzero: the last two PT_LOADs of the eboot, whose offsets and addresses main's relinker keeps:

PT_LOAD Offset VirtAddr FileSiz MemSiz Flags in the eboot
data 0x5fa4000 0x5fa0000 0x24430 0x6f0fc0 (bss up to 0x6690fc0) RW
next 0x5fc8fc0 0x6690fc0 0xe24260 0xe24260 none (RWE in app.elf)

The kernel maps page 0x6690000 again from file page 0x5fc8000, so the last 0xfc0 bytes of the bss hold file bytes: 72 nonzero qwords. The qword at file offset 0x5fc8020 is 0x800000001, the value the title reads at 0x6690020.

With this PR (cherry-picked, relinker rebuilt, eboot reconverted), the segment moves to file offset 0x7c78fc0 with zeros in front of it, and the fault did not occur in any of 7 runs (six warm, one cold). Six ran to their time limits (240 to 1500 s), with #6814 or APS5_NO_LIBRARY_PREBUILD=1. The seventh, warm with neither, ended at 9 s on #6805; the run data for that stop is on #6814. An app.elf converted by main's relinker, run with the same libraries and settings as a 900 s APS5_NO_LIBRARY_PREBUILD=1 run, faults again at 0x800000021 3 s in. linux_load_pages passes on Linux.

AI-assisted: yes (Claude Code, Claude Opus 5.5), operating under my supervision; I am accountable for this report and will respond to review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228767262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6228767262). Originally posted by [snoozedDev](https://github.com/snoozedDev) on 2026-10-17T02:57:19Z. --- A retail title that stops on this on `main`: Grand Theft Auto III – The Definitive Edition (PPSA03527 v01.007.000, retail disc). This PR (head ce0b7672d) fixes it. **Tree:** `main` af0fff762 with #6236 (merged since), using `APS5_PLAYGO_UNLISTED_CHUNKS=absent` to get past #6205. Linux (kernel 7.2.5), GCC 16.2.1, Release, RTX 3090, NVIDIA 610.57.04, inside `gamescope --backend headless`. **The stop:** the main thread segfaults about a second after the swapchain is created. Cold, that is at 579 s, after 575 s of shader registration. Warm, it is 3 to 9 s after launch. From the kernel log of the cold run: ``` app.elf[2514698]: segfault at 800000021 ip 0000604b9d87ac21 sp 00007ffe3f7f1ba0 error 4 in app.elf[1c3ac21,604b9bc44000+46c9000] ``` The fault address was the same in all three runs where I captured it (one cold, two warm, the warm ones through a `SIGSEGV` handler that the write-watch handler chains to). The faulting instruction is `cmpq $0x0,0x20(%rdi)` at vaddr 0x1c36c21 in the converted `app.elf` (file offset 0x1c3ac21, as in the kernel line), with `rdi = 0x800000001`. The function at 0x45faf20 loads that value from the global at 0x6690020. The title only initializes that global while it reads zero, so it uses the nonzero value as an object pointer. **Why it is nonzero:** the last two `PT_LOAD`s of the eboot, whose offsets and addresses `main`'s relinker keeps: | PT_LOAD | Offset | VirtAddr | FileSiz | MemSiz | Flags in the eboot | |---|---|---|---|---|---| | data | 0x5fa4000 | 0x5fa0000 | 0x24430 | 0x6f0fc0 (bss up to 0x6690fc0) | RW | | next | 0x5fc8fc0 | 0x6690fc0 | 0xe24260 | 0xe24260 | none (RWE in `app.elf`) | The kernel maps page 0x6690000 again from file page 0x5fc8000, so the last 0xfc0 bytes of the bss hold file bytes: 72 nonzero qwords. The qword at file offset 0x5fc8020 is 0x800000001, the value the title reads at 0x6690020. **With this PR** (cherry-picked, relinker rebuilt, eboot reconverted), the segment moves to file offset 0x7c78fc0 with zeros in front of it, and the fault did not occur in any of 7 runs (six warm, one cold). Six ran to their time limits (240 to 1500 s), with #6814 or `APS5_NO_LIBRARY_PREBUILD=1`. The seventh, warm with neither, ended at 9 s on #6805; the run data for that stop is on #6814. An `app.elf` converted by `main`'s relinker, run with the same libraries and settings as a 900 s `APS5_NO_LIBRARY_PREBUILD=1` run, faults again at 0x800000021 3 s in. `linux_load_pages` passes on Linux. AI-assisted: yes (Claude Code, Claude Opus 5.5), operating under my supervision; I am accountable for this report and will respond to review.
milescoviello commented 2026-10-17 03:31:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T03:31:26Z.


Thanks @snoozedDev, a retail title that stops on this, with the fault address traced back to the zero-filled tail, is the case this was missing. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229071023 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6229071023). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T03:31:26Z. --- Thanks @snoozedDev, a retail title that stops on this, with the fault address traced back to the zero-filled tail, is the case this was missing. I added it to the description. AI-assisted: yes (Claude Code)
screamm commented 2026-10-17 11:37:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T11:37:31Z.


Cross-validation on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2, PR head ce0b7672d, scratch-merged onto main 673f7406c (no conflict). I can only check the relinker side here; I did not run a title on Linux. No GPU is involved in any of this.

  • linux_load_pages, --repeat until-fail:3: 3 of 3. The 102 relinker tests also pass 3 of 3 on a tree with #6681 and #6713 merged.
  • Negative control: with LinuxElfPatcher.cpp from main (test kept) linux_load_pages fails with byte at 0x2000 reads 0xaa, not 0x00; with the change it passes.
  • tools/check_conventions.py --base origin/main and git diff --check: pass.
  • Windows output: main's relinker against this PR's on the 51 local titles that have an eboot.elf (--windows, same flags, registries on): all 312 output files have identical SHA-256, and 50 relink while PPSA99995 stops with the same Unsupported Windows guest TLS instruction in both. The PR touches no Windows code, so this is what I expected.
  • Linux output on the same 51 titles (default target, produced on Windows): 45 are byte-identical and 6 differ (PPSA69420, PPSA99007, PPSA99082, PPSA99110, PPSA99728, PPSA99810). In each of the 6 exactly one PT_LOAD moves to a page-congruent offset (outputs grow by 45 KB to 1.5 MB) and no other program header field changes; every PT_LOAD's file bytes are identical at their new offsets apart from e_shoff and the moved segment's p_offset in the ELF header. A page-by-page model of the kernel mapping finds 122, 18, 62, 49, 82 and 8 nonzero bytes in the bss tails of main's outputs and 0 in the PR's. The same model finds none in the other 45 inputs, which is why they do not change. The counts match your list for the titles we both have.
  • The local PPSA99288 is an older build than the 0.5.27 you describe and gives identical Linux output on main and on the PR, so I could not reproduce the Nuvio crash.

Not checked: running any title on Linux (GTA III and Nuvio 0.5.27 are not available here), macOS, a full-tree build, the non-GPU suite.

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233430658 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6233430658). Originally posted by [screamm](https://github.com/screamm) on 2026-10-17T11:37:31Z. --- Cross-validation on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2, PR head `ce0b7672d`, scratch-merged onto main `673f7406c` (no conflict). I can only check the relinker side here; I did not run a title on Linux. No GPU is involved in any of this. - `linux_load_pages`, `--repeat until-fail:3`: 3 of 3. The 102 relinker tests also pass 3 of 3 on a tree with #6681 and #6713 merged. - Negative control: with `LinuxElfPatcher.cpp` from main (test kept) `linux_load_pages` fails with `byte at 0x2000 reads 0xaa, not 0x00`; with the change it passes. - `tools/check_conventions.py --base origin/main` and `git diff --check`: pass. - Windows output: main's relinker against this PR's on the 51 local titles that have an `eboot.elf` (`--windows`, same flags, registries on): all 312 output files have identical SHA-256, and 50 relink while PPSA99995 stops with the same `Unsupported Windows guest TLS instruction` in both. The PR touches no Windows code, so this is what I expected. - Linux output on the same 51 titles (default target, produced on Windows): 45 are byte-identical and 6 differ (PPSA69420, PPSA99007, PPSA99082, PPSA99110, PPSA99728, PPSA99810). In each of the 6 exactly one PT_LOAD moves to a page-congruent offset (outputs grow by 45 KB to 1.5 MB) and no other program header field changes; every PT_LOAD's file bytes are identical at their new offsets apart from `e_shoff` and the moved segment's `p_offset` in the ELF header. A page-by-page model of the kernel mapping finds 122, 18, 62, 49, 82 and 8 nonzero bytes in the bss tails of main's outputs and 0 in the PR's. The same model finds none in the other 45 inputs, which is why they do not change. The counts match your list for the titles we both have. - The local PPSA99288 is an older build than the 0.5.27 you describe and gives identical Linux output on main and on the PR, so I could not reproduce the Nuvio crash. Not checked: running any title on Linux (GTA III and Nuvio 0.5.27 are not available here), macOS, a full-tree build, the non-GPU suite. Written with Claude Code assistance (validation by a subagent, reviewed in this session).
milescoviello commented 2026-10-18 14:30:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T14:30:38Z.


An update on the title evidence, since the catalog has moved on. Nuvio Max'd builds after 0.5.27 no longer crash on main, so the current catalog build won't show the problem:

Build Bytes in front of the next segment on the shared page main a62c724c38 this PR's relinker
0.5.27 (05.000.027) 3104, 1122 nonzero SIGSEGV at launch (EXIT-139 at 0 s) runs to the 60 s limit
0.5.29 (05.000.029) 2064, all zero runs to the 60 s limit runs to the 60 s limit
0.5.31 (05.000.031, current catalog da69b68) 3984, all zero runs to the 90 s limit runs to the 90 s limit

0.5.28 has the same layout with 1520 bytes, all zero (not run). All four still end the zero-filled tail of the RW segment on the page where the next PT_LOAD (flags 0) starts. In the later builds, though, the file bytes main's relinker maps over that tail are already zero. That's the case the description counts for 80 of the 93 eboots, where nothing changes. Same main libraries for both relinkers, scripted pad input. So 0.5.27 is still the reproducer, and it's the copy the description's numbers come from. The unit test covers the layout either way.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251103036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6251103036). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T14:30:38Z. --- An update on the title evidence, since the catalog has moved on. Nuvio Max'd builds after 0.5.27 no longer crash on `main`, so the current catalog build won't show the problem: | Build | Bytes in front of the next segment on the shared page | `main` a62c724c38 | this PR's relinker | |---|---|---|---| | 0.5.27 (05.000.027) | 3104, 1122 nonzero | SIGSEGV at launch (`EXIT-139` at 0 s) | runs to the 60 s limit | | 0.5.29 (05.000.029) | 2064, all zero | runs to the 60 s limit | runs to the 60 s limit | | 0.5.31 (05.000.031, current catalog da69b68) | 3984, all zero | runs to the 90 s limit | runs to the 90 s limit | 0.5.28 has the same layout with 1520 bytes, all zero (not run). All four still end the zero-filled tail of the `RW` segment on the page where the next `PT_LOAD` (flags 0) starts. In the later builds, though, the file bytes `main`'s relinker maps over that tail are already zero. That's the case the description counts for 80 of the 93 eboots, where nothing changes. Same `main` libraries for both relinkers, scripted pad input. So 0.5.27 is still the reproducer, and it's the copy the description's numbers come from. The unit test covers the layout either way. AI-assisted: yes (Claude Code)
babyhuey commented 2026-10-18 22:08:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T22:08:48Z.


A reproducer in the current catalog: Régie5 0.6.0 (PPSA99520, catalog release of 10-17). Linux, Ubuntu 24.04 container, GCC 13, Release, relinker and every library rebuilt, 30 s per run.

  • main 0bc3003f8, 2 of 2: SIGSEGV right after its own listening port chosen by the system log line, in scePthreadMutexLock (mov 0x58(%rbx),%rax, rbx 0x000002f2000002ae), called from the title's pthread_mutex_lock. The mutex is at 0x1c25228, in the bss of the RW PT_LOAD at 0x18b0000 (FileSiz 0x5550, MemSiz 0x3755c8, so the bss ends at 0x1c255c8). The next PT_LOAD (RWE) starts at 0x1c255d0, on the same page, from file offset 0x18b95d0. So page 0x1c25000 is mapped from file page 0x18b9000, and the 16 bytes at file offset 0x18b9228 are 000002f2000002ae 000002f800000326, exactly what the mutex and the word after it hold.
  • main + this PR at 24ec391c0 (clean merge), 2 of 2: no fault; it gets past that point to the headless DisplayWindow stop, as the earlier Régie5 build did. In the output the RWE segment's file offset is now 0x1a0d5d0, so the bss tail's page no longer comes from the file.

Régie5 0.5.1, the previous catalog build, didn't crash there, so this is the same layout luck as Nuvio Max'd 0.5.27 against its later builds.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255754691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6255754691). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-18T22:08:48Z. --- A reproducer in the current catalog: Régie5 0.6.0 (PPSA99520, catalog release of 10-17). Linux, Ubuntu 24.04 container, GCC 13, Release, relinker and every library rebuilt, 30 s per run. - `main` `0bc3003f8`, 2 of 2: SIGSEGV right after its own `listening port chosen by the system` log line, in `scePthreadMutexLock` (`mov 0x58(%rbx),%rax`, `rbx 0x000002f2000002ae`), called from the title's `pthread_mutex_lock`. The mutex is at `0x1c25228`, in the bss of the `RW` `PT_LOAD` at `0x18b0000` (FileSiz `0x5550`, MemSiz `0x3755c8`, so the bss ends at `0x1c255c8`). The next `PT_LOAD` (`RWE`) starts at `0x1c255d0`, on the same page, from file offset `0x18b95d0`. So page `0x1c25000` is mapped from file page `0x18b9000`, and the 16 bytes at file offset `0x18b9228` are `000002f2000002ae 000002f800000326`, exactly what the mutex and the word after it hold. - `main` + this PR at `24ec391c0` (clean merge), 2 of 2: no fault; it gets past that point to the headless `DisplayWindow` stop, as the earlier Régie5 build did. In the output the `RWE` segment's file offset is now `0x1a0d5d0`, so the bss tail's page no longer comes from the file. Régie5 0.5.1, the previous catalog build, didn't crash there, so this is the same layout luck as Nuvio Max'd 0.5.27 against its later builds. AI-assisted: yes
milescoviello commented 2026-10-19 01:06:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T01:06:12Z.


Thanks @babyhuey, a second title in the current catalog with the same page-sharing layout is good to have. I added the Régie5 0.6.0 run to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257474978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6257474978). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T01:06:12Z. --- Thanks @babyhuey, a second title in the current catalog with the same page-sharing layout is good to have. I added the Régie5 0.6.0 run to the description. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-19 08:50:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:50:42Z.


Checked the new SeparateSharedLoadPages against the diff: file ranges are bounds-checked, moved segments keep the same page offset, and segments whose page already reads right are left in place. linux_load_pages covers the three layouts, including the no-move case, and fails on main's LinuxElfPatcher.cpp. Real-kernel, Windows and title confirmations in the thread (@simonbbby, @screamm, @snoozedDev, @babyhuey) cover the rest. Relinker CI is green on all three platforms; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263391296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6681#issuecomment-6263391296). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T08:50:42Z. --- Checked the new `SeparateSharedLoadPages` against the diff: file ranges are bounds-checked, moved segments keep the same page offset, and segments whose page already reads right are left in place. `linux_load_pages` covers the three layouts, including the no-move case, and fails on `main`'s `LinuxElfPatcher.cpp`. Real-kernel, Windows and title confirmations in the thread (@simonbbby, @screamm, @snoozedDev, @babyhuey) cover the rest. Relinker CI is green on all three platforms; merged.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6681
No description provided.