Windows: a converted executable stops at start-up when its directory path is outside the ANSI code page #2640
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 justdoston on 2026-10-10T09:43:29Z.
What
A
--windowsexecutable stops before its guest entry when the path of its directory contains a character that the system ANSI code page cannot represent: Japanese, Chinese or Korean folder names on a Western-locale system, any emoji, or scripts without an ANSI code page such as Devanagari.The entry stub (
WindowsEntryStubBuilder) reads its own path withGetModuleFileNameA, which replaces each such character with?, and then uses the result withSetCurrentDirectoryA(since #2574) andLoadLibraryExA. The--windows-diagnosticsstub (WindowsDependencyStubBuilder) does the same withGetFileAttributesA,GetModuleHandleAand thelstr*Afunctions.Measured
The executable and bundled modules from
test_windows_import_modules.py(exit code 11 once the guest entry runs), converted withrelinker --windowsonmaincd73e149and run under Wine 10.0 with theen_USlocale (ANSI code page 1252) from three directories:asciiJosééis in code page 1252)日本FAIL: cannot make the executable directory the current directory,GetLastError: 123(ERROR_INVALID_NAME)GetModuleFileNameAreplaces unrepresentable characters with?on Windows too, so I expect the same result there, but it has not been run on a Windows machine yet.Proposal
Use the wide API in both stubs:
GetModuleFileNameW,SetCurrentDirectoryW,LoadLibraryExW,GetFileAttributesW,GetModuleHandleWand thelstr*Wfunctions, with library names and the--rpathtext stored as UTF-16. A regression case can run the converted executable from a directory such asü日in the Windows relinker tests.I'd like to work on this, unless someone already is.
AI-assisted: yes. An AI agent (Claude Code) did most of this work: it found the problem, ran the measurements and wrote this report.
Imported from boykopovar/AnyPS5. Originally posted by justdoston on 2026-10-10T09:57:56Z.
Fix branch: https://github.com/justdoston/AnyPS5/tree/fix/windows-unicode-executable-path
GetModuleFileNameWand enters its directory and loads its libraries withSetCurrentDirectoryWandLoadLibraryExW. Library paths are stored as UTF-16, decoded from UTF-8 at relink time (invalid UTF-8 throws).--windows-diagnosticswalker still get the paths in the ANSI code page, so their output is unchanged; the walker's ANSI API is recorded in TechnicalDebt and can follow separately.test_windows_working_directorygains aunicode ü日case, which runs on Windows.Tested: Linux relinker
ctest97/97. Under Wine 10.0 (en_US, code page 1252) the converted test executables now start fromascii,José,日本and an emoji directory, with bundled modules, libraries fromlibs\, an absolute--rpathand--windows-diagnostics, and an unresolved import still stops with its message. Not run on a Windows machine.AI-assisted: yes. An AI agent (Claude Code) did most of the work: the code, the tests and this comment.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T10:21:33Z.
Follow-up after the updated branch
Thanks for explaining the executable's current
MAX_PATHbehavior and for updating the test to rename the directory after conversion. I no longer consider my earlier ANSI scratch-buffer observation a substantiated blocker for this change.I applied the author's three commits through
bcb8d644to current upstreammain507f49fbin an isolated worktree. The five-file diff applies cleanly.maingit diff --checkThis Linux run does not execute the generated Windows code. The earlier native Windows run on
bf3bbd91confirmed the executable-directory fix for CJK and Arabic paths, and the author reports the updated diagnostic path passes under MinGW/Wine. The author notes the fixture cleanup failure still needs a native Windows run, so I have not treated that as validated here.No matching pull request exists for this branch as of this check. AI-assisted change; the author has disclosed that in the issue.
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T10:29:11Z.
Native Windows check of
justdoston:fix/windows-unicode-executable-path(bf3bbd91, merges cleanly ontomaina29ef592). Windows 11 Pro 10.0.26200, ANSI code page 1252, WinLibs GCC 15.2.0 r7, relinker-only Release build.The fix works. I converted a fixture in an ASCII directory, copied the tree to a differently named directory, launched
output.exefrom another directory and read the child's current directory:mainasciiücjk-日本GetLastError 123arabic-عربيGetLastError 123So #2640 reproduces on
mainand the stub change resolves it.The new test case fails on this machine, before and after the fix.
ctest --test-dir build-relinkergives 92 of 93;windows_working_directoryfails withFAIL: filesystem error: Cannot convert character sequence: Illegal byte sequence. The failure is in the test driver's own host tool, not the stub:core/relinker/main.cpp:46-55callsstd::filesystem::path(argv).string()on a narrowargv. On a cp1252 system aüpath hits that conversion error (a standalone g++ probe shows the same), and a日path has already become?by the time it reachesargv. Sotest_windows_working_directory.pyline 106 can only pass where the ANSI code page is UTF-8, such as Wine or the UTF-8 beta setting, and not on a default Western Windows install. It may be worth driving that case through the stub directly, as in the table above, or convertingargvthrough the wide command line.On the
writeAnsiquestion raised in review:PathCapacityis 32768 and the ANSI buffers are 32768 bytes, so the byte count matches the buffer and nothing overflows. It only matters for paths over about 16k wide characters on a double-byte ANSI page, and I could not test one here (cp1252 is single-byte).AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by justdoston on 2026-10-10T10:33:32Z.
Thanks both, and @husseinkad for the native Windows run.
@husseinkad You're right about the test: the relinker reads its arguments as narrow strings, so on a cp1252 system that case never reached the stub.
bcb8d644converts it under an ASCII name and renames the directory tounicode ü日before starting the executable, as in your table. Reading the relinker's own arguments through the wide command line (core/relinker/main.cpp) is a separate fix that I've left out of this branch.@MarcZX100 On the text buffers: the executable has no long-path-aware manifest, so the directory it can enter with
SetCurrentDirectoryWis limited toMAX_PATHand that call fails first. A path whose text is longer than the 32 KiB buffer (now more than about 10,900 non-ASCII UTF-16 units, since the text is UTF-8) stops with the existingFAIL: executable or library path is too longrather than overflowing. Sizing the buffers at three bytes per unit would add 64 KiB of file data per library, because they sit before the error strings in.startupand the PE writer only trims trailing zeros. I can do that, or move the buffers to the zero tail, if a maintainer prefers.The branch also now covers the
--windows-diagnosticswalker (4fe56534), so the TechnicalDebt entry from the first commit is gone:GetModuleHandleW,LoadLibraryExW,GetFileAttributesW,GetModuleFileNameWandGetSystemDirectoryW. The entry stub prints and passes its paths as UTF-8, so the messages show the directory name instead of?.windows_dependency_diagnosticsbuilds its fixtures under aü日directory. It drives the stub builders in-process and starts its runner withCreateProcessW, so it does not go through the relinker's arguments.Tested: Linux relinker
ctest97/97.windows_dependency_diagnostics, cross-compiled with MinGW-w64 GCC 16 and run under Wine: with theü日fixtures every check fails onmain(dependency diagnostics Windows API failed) and passes with the branch. Its finalremove_allof the fixture directory fails under Wine withAccess deniedeven on unchangedmainwith the ASCII name, so that step needs a Windows run. Under Wine, a test executable converted underunicode, renamed tounicode ü日and started from another directory runs to its guest entry.AI-assisted: yes. An AI agent (Claude Code) did most of the work: the code, the tests and this comment.
Imported from boykopovar/AnyPS5. Originally posted by harmsluis on 2026-10-10T11:13:11Z.
Native Windows run of
justdoston:fix/windows-unicode-executable-pathatbcb8d644, covering the two points left for a Windows machine (the newwindows_working_directorycase and thewindows_dependency_diagnosticsfixture cleanup).Environment: Windows 11 (10.0.26300), en-US, ANSI code page 1252, WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), CMake 4.3.1, Ninja 1.13.2, Python 3.14. Relinker-only Release build,
TEMP/TMPset to a separate directory.ctest --test-dir build-relinkerbcb8d644mainb5f5362d(no conflicts)windows_working_directory: passed, including the case converted under an ASCII name and renamed tounicode ü日.windows_dependency_diagnostics: passed with theü日fixtures. The finalremove_allthat failed under Wine succeeds here; no files are left in the temp directory after the run.input_magicis registered and passes, so the Python tests ran.Not covered: the relinker's own narrow
argvincore/relinker/main.cpp, which the branch leaves out.AI-assisted: yes. An AI agent ran the build and tests and drafted this comment; I reviewed the results.
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T11:13:53Z.
Thank you @justdoston, and @harmsluis for the second native run. The
bcb8d644change to the test matches what I saw here. I'd like to take the separate piece you left out, reading the relinker's own arguments through the wide command line incore/relinker/main.cpp, as its own change with a test that runs the relinker from a directory with characters outside the ANSI code page. I'll start on it now unless one of you already has it; tell me here if so and I'll leave it to you.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-10T11:22:28Z.
Native Windows run of
justdoston:fix/windows-unicode-executable-pathat bcb8d644 (merges cleanly ontomainb5f5362d). Windows 11 Pro 10.0.26200, ANSI code page 1252, WinLibs GCC 15.2.0 r7, relinker-only Release build.The two updated tests pass on native Windows, including the fixture cleanup that failed under Wine:
windows_dependency_diagnostics(fixtures underü日) andwindows_working_directory(with theunicode ü日case). Noü/日fixture directories were left in%TEMP%.Full relinker ctest: 92 of 93 on the branch and 92 of 93 on
mainb5f5362d. The one failure is the same on both:tls_function_coverage_register_address_loadstimes out at 30 s under--parallel 8; run alone it passes in 14.9 s onmainand 15.8 s on the branch.A converted
test_windows_import_modulesexecutable (exit 11 once the guest entry runs), converted in an ASCII directory, copied to each directory and started from another directory:mainb5f5362dasciiJoséعربي0xc000000d,FAIL: cannot make the executable directory the current directory日本game 🎮--windows-diagnosticson the branch from aعربي 🎮directory: the resolved case exits 11 and theLoading PRX:lines show the directory name as is (no?); an unresolved import stops withFAIL: unresolved ELF import absent from a.prxand0xc0000139, with the same path.ps5-doom (PPSA99666 v1.1.1,
--windows --windows-gui), converted in an ASCII directory, copied into a directory namedعربيand started withStart-Processfrom another directory:mainb5f5362dexits with0xc000000d; the branch runs and the DOOM window renders.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T11:31:41Z.
Update: native Windows validation for the #2692 branch
A native Windows run is now reported in #2692 for justdoston's
f87686c2branch, based on currentmainb5f5362d.bcb8d644f87686c2file_unicode_pathpasses;windows_import_modulesconverts fromJoséand other Unicode paths.José, Arabic, Japanese and emoji directory cases convert and reach the guest entry. The report also says DOOM renders from an Arabic path with both changes.The run reports the expected distinction: #2692 fixes the relinker's own wide arguments and file paths, while #2640 fixes startup working-directory and dependency-path handling inside the converted executable. The two branches were tested together without conflicts. This updates my earlier note that native Windows evidence for #2692 was still pending. Both changes remain linked from issues rather than open PRs while intake is paused.
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T11:32:52Z.
Thank you @MarcZX100, you are right: @justdoston's
f87686c2(#2692) predates my offer and covers the same ground, and I had missed that issue. I'm dropping my ownmain.cppchange and will not open a PR for it. Their branch also handles--autorunthrough_wsystem, which mine left as a documented gap. What I can add instead is a native Windows run off87686c2(the issue says it has only been checked under Wine); I'll post that result on #2692.AI-assisted: yes.