fix(relinker): prefer 0x400000 for Windows executables #9332
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9332"
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 rooklz on 2026-10-21T18:41:27Z.
What
On Windows, Ruffle (PPSA68091), VLC (PPSA85300) and XPSemu (PPSA97358) only start when they're converted with
--windows-fixed-base 0x400000. They read their GOT slots at0x400000plus the offsets inapp0/imports.txt(#4013), but the default executable puts its lowest ELF load page at0x140010000, so the first read faults. babyhuey on #5732, about VLC onmain64a9caa62: with the option it "runs the full 60 s at about 119 fps with no fault. Without--windows-fixed-baseit still faults at start-up as before (#4013)". dantdmdarealguy measured the same for Ruffle on #4013. The web converter has no way to pass the option.This makes
0x400000the preferred address of the executable's lowest ELF load page, which is a PE image base of0x3f0000, since the headers take the 64 KiB before it. Otherwise nothing changes:DYNAMIC_BASE, as since #4237. Windows maps the executable before anything else, so the range is normally free and it loads there. If the range were taken, the kept relocations let Windows move it; no run has shown that happen at either base.--windows-fixed-baseis unchanged: an exact address, no relocations, and an occupied address fails to load.0x200000000. No image can reach the shared user data page at0x7ffe0000from here: Windows refuses aSizeOfImageabove0x77000000(@roboterspinne measured it), and the debt entry now says so.DYNAMIC_BASEand their preferred base0x140000000. macOS output is unchanged.WindowsPeWriter::Writenow takes the image base and whether it's fixed, instead of an optional fixed base, so the patcher can pass a preferred base. Its alignment and lower-bound check now applies to every image, secondary executables converted with--executableget the new preferred base too, andWindowsImportIdentityTests(added onmainsince) passestrue, falseto keep its fixed-base probe.#8973 (merged) does the same on Linux.
Tested
Windows 11, Ryzen 7 5800X, WinLibs GCC 15.2, Release, by @babyhuey: PPSA99099 wiliwili (homebrew), which reads its own import table at its offset plus
0x400000, faults with0xC0000005at 2.5 s onmain(0x140000000base) and runs for the 45 s window with this head and withmainplus--windows-fixed-base 0x400000.No title run on my side. These runs were on the pre-rebase head
14ffbf945(same diff) unless noted. ycbuzi ran VLC (PPSA85300) on this head merged ontomaina849f2516e(comment), Windows 11, RTX 4070 SUPER: onmainthe default conversion crashed at start-up with0xc0000005and 0 presents (2 runs); with this PR the default conversion rendered at 72.6 to 118.9 fps (4 of 5 runs; the fifth stopped presenting after about 20 s, which also happened once with--windows-fixed-base 0x400000). ccleste (PPSA59322) and DriftCheck (PPSA98766) render on the new default too. Ruffle and XPSemu weren't run.windows_fixed_basenow converts itsimports.txt-style fixture without any option and runs it. The fixture reads the slot at0x400300and returns 42 when the slot is filled. With only that check added tomain950388bfd, the converted executable exits with0xC0000005on a GitHub-hosted Windows runner (verifyrun on my fork), which is the fault in #4013. With this change it passes. The header check there and inwindows_tls_protected_entriesnow expects0x3f0000.Windows Server 2025 (GitHub-hosted), WinLibs GCC 15.2.0, relinker-only build, run on my fork: 233/233 with the change and 233/233 on its base
950388bfd. That includeswindows_address_space, which runs the default executable 8 times and checks that its main thread stack stays below the arena.macOS 26.2 (Apple M5), AppleClang 21, relinker-only build: 229/229.
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, relinker-only build, by @BKlaasWerkman on
92fbd0adc1merged intomain990f45e17d: 235 of 235 pass,windows_fixed_baseandwindows_tls_protected_entrieswith their changed expectations among them, and no result differs frommainon the same machine.check_conventions.pypasses.pr_overlap.pyagainst currentmainlists only shared docs files it could not compare.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T20:14:19Z.
Windows run of 14ffbf9450 merged onto
maina849f2516e(189a4bb233, clean), with #7264'stools/title_run.pymerged on top to run the titles (it changes onlytools/anddocs/dev/TRACING.md). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON, RTX 4070 SUPER (NVIDIA 616.92), Ryzen 9 7900.VLC (PPSA85300, 01.000.007), converted by
title_run.pywith--registry, 60 s per run:ImageBasemaina849f2516eFATAL: unhandled exception 0xc0000005, 0 presents0x1400000000x3f0000--windows-fixed-base 0x4000000x3f0000DllCharacteristicsis0x100(NX_COMPATonly, noDYNAMIC_BASE) in all three. Three of the default runs and three of the fixed-base ones alternated (A B B A A B): 118.9, 116.2 and 106.8 fps against 119.8, 99.4 and 107.2, so no difference beyond the run-to-run spread on this machine. The last two of those, one of each, stopped presenting after about 20 and 30 s with no error line (the runner's "stalled"), so it happens with the existing option too.ccleste (PPSA59322) and DriftCheck (PPSA98766) on the new default: 2 of 2 rendering each (116.5 and 117.1 fps; 54.3 and 58.5 fps).
ctest --test-dir core\relinker(162 tests here),--repeat until-fail:2,-j 4: 159 pass on both repeats, includingwindows_fixed_base,windows_tls_protected_entriesandwindows_address_space.guest_none_relocations,guest_relative_section_symbolsandoverlapping_relocationsreached their 20 and 30 s timeouts under that load; run one at a time they pass on both repeats in 1 to 14 s, on this PR and onmainalike.Not run: Ruffle (PPSA68091) and XPSemu (PPSA97358), which I don't have.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T20:17:03Z.
Thanks, that's the title run this PR was missing. Good to see the default and
--windows-fixed-base 0x400000land in the same fps range, and that the stall shows up with the existing option too, so it isn't from this change. I've added your run to the description.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:44:38Z.
Windows and Linux run of 14ffbf945 merged onto
maina6dcea927(merges cleanly). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs MinGW-w64 GCC 15.2.0, Release relinker-onlyBUILD_TESTING=ON; Linux: WSL Ubuntu 24.04, GCC 13.3.0, same configuration.ctest(relinker-only): Windows 233/233 (performance_comparehit its 20 s timeout in the parallel pass and passed on rerun; it passed onmainin the same setup). Linux 237/238, the one failure beingshader_cache_runtime_sources(its internal 15 s CMake configure timed out), which fails the same way onmainhere.test_windows_fixed_base.pyagainstmain's relinker fails;main's version of the test plus only the new default-conversionrun(...)line fails with the converted fixture exiting3221225477(0xC0000005) afterTransferring control to ELF entry point. With this PR both pass.--windows --to-intel,--macos --to-rosettaand Linux--to-intel: macOS and Linux outputs are byte-identical tomain. On Windows onlyapp.exechanges; every bundled module is byte-identical. Inapp.exeonlyImageBasechanges (0x140000000to0x3f0000);SizeOfImage, the size of.reloc,DllCharacteristics0x100(noDYNAMIC_BASE) andCharacteristics0x22(relocations not stripped) matchmain.app.exestarted withCREATE_SUSPENDEDandPEB.ImageBaseAddressread back, 3 times each.main:0x140000000for all four. This PR:0x3f0000for all four, including PPSA99581 (SizeOfImage0x6bf1000, so it ends at0x6fe1000).Not run: the converted titles themselves (my build is relinker-only); ycbuzi's VLC runs above cover that.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:34:26Z.
Rebased onto current
main(8b3e39832a): head92fbd0adc1, same diff.Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T09:53:24Z.
Review: COMMENTED
Reviewed head 92fbd0adc merged onto
upstream/mainaeeaefad9(2026-10-24); the merge is clean (only the two docs files auto-merge).Environment: Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.Results
mainaeeaefad9: 238 tests, 0 failed,long_pathsskipped. PR merged: 238 tests, 0 failed,long_pathsskipped;windows_fixed_base2.7 s,windows_tls_protected_entries0.8 s,windows_address_space0.5 s.windows_fixed_basefails at the header assertion (line 71,0x140000000 != 0x3f0000) andwindows_tls_protected_entriesfails ataccess-start(0x400210); restored, both pass.test_optional_pltfixture:maindefault ImageBase0x140000000; PR default ImageBase0x3f0000, Characteristics0x22, DllCharacteristics0x100,.relocdirectory kept (size0xc), SizeOfImage unchanged. The imports-offset fixture from the test exits0xC0000005withmain's default and 42 with the PR's; started suspended, the PR output reportsPEB.ImageBaseAddress=0x3f0000.--windows-fixed-base 0x400000output is identical onmainand the PR (ImageBase0x3f0000, Characteristics0x23, no.reloc).mainvs PR:app.exediffers only in the ImageBase field (plus the one absolute GOT slot the fixture bakes in); a bundled module converted alongside it is byte-identical with ImageBase0x140000000, and the executable with that module exits 42 on both.check_conventions.pypasses;pr_overlap.pyagainst currentmainlists only the "could not compare" docs entries.Should fix
main, not in this diff):core/relinker/elfpatcher/tests/WindowsImportIdentityTests.cpp:77, added by2657a8121after this branch's merge-base, callsWindowsPeWriter().Write(..., false, ImageBase, false). With the new signature those tokens meanimageBase=0x140000000, fixedBase=false, dynamicBase=true, so the probe losesIMAGE_FILE_RELOCS_STRIPPED(Characteristics0x22instead of0x23). It compiles cleanly (-Wall -Wextra -Wconversion, no diagnostic), and thewindows_import_identitytarget is only built withoutANYPS5_RELINKER_ONLY(CMakeLists.txt:163), so the relinker matrix cannot notice. The test still passes (it only runs the probe, which has no relocation directory), but please change the call toWrite(..., false, ImageBase, true, false)on rebase to keep its fixed-base intent.docs/dev/debt/relinker.md:11and the body: the relocation example cannot occur. From0x3f0000an image needs SizeOfImage ≥0x7fbf0000to reach0x7ffe0000, but the loader refuses any converted image with SizeOfImage above0x77000000: measured here withtest_optional_plt.fixtureandp_memszpatched, SizeOfImage0x77000000loads at0x3f0000and exits 42,0x77001000fails with CreateProcess error 193 (NtCreateSection→STATUS_INVALID_IMAGE_FORMAT), the same atmain's0x140000000and with--windows-fixed-base. So the default executable ends below0x773f0000and never reaches the shared user data page. Also, I found no run in this PR, #4237 or #3043 that observed a relocation of the executable at either base (every reportedPEB.ImageBaseAddresshere was the preferred one, and the only occupancy test uses a fixed base and expectsSTATUS_CONFLICTING_ADDRESSES), while the entry drops its "Verified only on Windows 10" sentence. Suggested wording is in the inline comment; "as it did when0x140000000was taken" in the body would need a pointer to the run that showed it.Nits
44661db26) and is an ancestor of this branch, so "the two don't depend on each other" reads as if it were still open. #8729 was closed unmerged on 2026-10-24, so thepr_overlap.pynote no longer applies.test_windows_fixed_base.py:84/88: the imports-offset fixture (cmp qword ptr [rax+0x400000], 0) only checks that the read at0x400300succeeds and is non-zero; it would also pass if any committed non-zero memory sat there. On the PR build the slot holds the resolved0x400240; comparing against it, or jumping through it asabsolute_jump()does, would make a wrong value fail too (same for the fixed-base variant on line 89).0x140000000is asserted only for the--windows-fixed-base 0x400000conversion (line 128);test_windows_address_space.pychecks the default module'sDYNAMIC_BASEbut not its base. A defaultconvert(..., modules=True)with the same assertion would cover the first case where executable and module bases differ. Pre-existing gap.0x22,.relockept, noDYNAMIC_BASE) is such an image, so on such a machine the imports.txt titles fault again;--windows-fixed-baseoutput is not rebased, but the sub-option "Do not allow stripped images" refuses it. Worth one sentence in USAGE.md's Runtime layout.main's default was rebased the same way, so this is not a regression.--executableget the new preferred base too (main.cpp:67passes no fixed base for them), the alignment/>= 0x10000check inWindowsPeWriter::Writenow applies to every image instead of only a fixed one, and the exception text changed. All harmless as far as I can see.WindowsLoadImagesubtractsfirstAddress), on LinuxConversion.cppplaces virtual address 0 there; the two agree only for ELFs whose firstPT_LOADstarts at vaddr 0, which PS5 executables do.Not checked: no retail title (no dumps here, so oneandonlydean's request for a first-frame run at
0x3f0000stands); no macOS or Linux execution; relocation of the default executable when0x3f0000is actually occupied could not be provoked; Mandatory ASLR was not enabled; the full (non relinker-only) build withwindows_import_identitywas not run; Windows 10 not measured.I found no blocking issue; the code change is correct and complete as far as I can tell, the two should-fix items are a rebase hazard outside this diff and a documentation correction. For disclosure: I have open relinker PRs (#10390, #10391, #10401, #10402, #10403); none shares a file with this one.
Written with AI assistance (Claude Code). I ran the builds, tests and native checks above on my Windows 11 machine.