fix(relinker): support non-ASCII input paths on Windows #2751

Closed
aplatogg wants to merge 1 commit from upstream-pr/2751 into main
aplatogg commented 2026-10-10 12:51:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by aplatogg on 2026-10-10T12:51:32Z.


What

Fixes #2692. On Windows the relinker could not convert a game whose path contains characters outside the local ANSI code page.

Root cause chain:

  • MinGW delivers argv to main as ANSI code page bytes (main.cpp)
  • Every narrow string became a std::filesystem::path through the same code page (implicit conversion at the GuestModuleBuilder::Build call, FileReader/FileWriter, WindowsPePatcher icon path)
  • Characters unrepresentable in the code page were replaced before any file access, so the game failed to open although the file exists

Fix:

  • Read the command line as Unicode: wmain via -municode, arguments encoded once to UTF-8 (main.cpp)
  • New Io::NativePath / Io::Utf8Path (core/relinker/io) convert between the UTF-8 strings the relinker passes around and native std::filesystem::path values at the filesystem boundaries (FileReader, FileWriter, main.cpp call sites)
  • --autorun on Windows launches the output through CreateProcessW instead of std::system, so it inherits no code page limitation
  • Invalid UTF-8 command lines fail fast with a clear error, consistent with the project's throw policy

Tested

Windows (WinLibs GCC 15.2.0 ucrt, the toolchain from BUILD.md), relinker-only build:

  • ctest: 94/94 passed, including the new input_nonascii test (converts fixtures from a directory named игры with sources named проба.elf, ゲーム.elf, próba m².elf, --windows + --registry, asserts exit 0 and the MZ output)
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed
  • Manual: converting a fixture from a non-ASCII directory now succeeds and names the path correctly in diagnostics; on the unfixed build it fails with Cannot open file

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4811329132 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2751). Originally posted by [aplatogg](https://github.com/aplatogg) on 2026-10-10T12:51:32Z. --- ### What Fixes #2692. On Windows the relinker could not convert a game whose path contains characters outside the local ANSI code page. Root cause chain: - MinGW delivers `argv` to `main` as ANSI code page bytes (`main.cpp`) - Every narrow string became a `std::filesystem::path` through the same code page (implicit conversion at the `GuestModuleBuilder::Build` call, `FileReader`/`FileWriter`, `WindowsPePatcher` icon path) - Characters unrepresentable in the code page were replaced before any file access, so the game failed to open although the file exists Fix: - Read the command line as Unicode: `wmain` via `-municode`, arguments encoded once to UTF-8 (`main.cpp`) - New `Io::NativePath` / `Io::Utf8Path` (`core/relinker/io`) convert between the UTF-8 strings the relinker passes around and native `std::filesystem::path` values at the filesystem boundaries (`FileReader`, `FileWriter`, `main.cpp` call sites) - `--autorun` on Windows launches the output through `CreateProcessW` instead of `std::system`, so it inherits no code page limitation - Invalid UTF-8 command lines fail fast with a clear error, consistent with the project's throw policy ### Tested Windows (WinLibs GCC 15.2.0 ucrt, the toolchain from BUILD.md), relinker-only build: - `ctest`: 94/94 passed, including the new `input_nonascii` test (converts fixtures from a directory named `игры` with sources named `проба.elf`, `ゲーム.elf`, `próba m².elf`, `--windows` + `--registry`, asserts exit 0 and the `MZ` output) - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed - Manual: converting a fixture from a non-ASCII directory now succeeds and names the path correctly in diagnostics; on the unfixed build it fails with `Cannot open file` ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-10 12:51:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T12:51:41Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097689651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2751#issuecomment-6097689651). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T12:51:41Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

Pull request closed

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!2751
No description provided.