Skip to content

fix(relinker): log Windows output when standard handles are missing - #4062

Merged
adriadam10 merged 4 commits into
boykopovar:mainfrom
danzaio:fix/windows-log-without-standard-handles
Oct 13, 2026
Merged

adriadam10 merged 4 commits into
boykopovar:mainfrom
danzaio:fix/windows-log-without-standard-handles

Conversation

@danzaio

@danzaio danzaio commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

A Windows executable started without stdout or stderr handles had nowhere to send its startup and failure messages. The entry stub now checks both handles before loading host libraries. It sends each missing stream to anyps5.log beside the executable; both missing streams share the file. Existing handles are preserved, each run replaces the previous log, and a file-creation failure leaves startup unchanged.

The implementation commit retains Doston Abdullayev's authorship. The documentation note in docs/user/USAGE.md is under the Windows runtime launch instructions, separate from the controller input section. That placement also avoids the insertion overlap with #3998.

Closes #3282

Tested

Current branch HEAD: b390831a5808666b39f2899cc5b19575a0ee38d5 on pinned main 5fe4bebec60ae1295aea301be28def2019b332ae.

  • Host: Microsoft Windows 10 Pro 10.0.19045 (64-bit). Toolchain: MinGW-w64 GCC 15.2.0; CMake/CTest 3.31.6-msvc6; Release/Ninja.
  • Built relinker, windows_stdio_host_ucrt, and windows_stdio_host_msvcrt with cmake --build C:/Users/admin/anyps5-build-3282 --target relinker windows_stdio_host_ucrt windows_stdio_host_msvcrt --parallel 1, then completed the full build with cmake --build C:/Users/admin/anyps5-build-3282 --parallel 1.
  • ctest --test-dir C:/Users/admin/anyps5-build-3282 -R "^windows_import_modules$" -V: 1/1 passed. The test exercises actual UCRT and MSVCRT DLL fixtures, missing stdout and/or stderr, and both redirected handles; it validates MSVCRT imports __iob_func and fputs directly from msvcrt.dll and rejects API-set CRT imports.
  • ctest --test-dir C:/Users/admin/anyps5-build-3282 --output-on-failure: 121/121 passed, 0 failed, 0 skipped (53.12 seconds).
  • python -I tools/check_conventions.py --base 5fe4bebec60ae1295aea301be28def2019b332ae --head HEAD: passed. git diff --check 5fe4bebec60ae1295aea301be28def2019b332ae...HEAD: clean.
  • feat(pad): queue timed controller button sequences #3998 doc merge simulation: clean 3-way merge (exit 0); logging paragraph appears once and the controller timeline heading appears once. fix(relinker): preserve load failures of present optional providers #3579 merge-tree composition: clean, tree 885fa1c0a43c0c7c6bdb3a8a9d2e6f87c28ccff8.

The red-green verification (failing without the logging code, passing with it restored) is historical, from the prior base 5aaf26bd325607f65bde28741a4e82ceaaf586c0; it was not rerun on this rebase. No Wine, Explorer launch, or full title/gameplay test. Upstream GitHub CI was not dispatched: our upstream permission is read-only (pull), while dispatch requires write, maintain, or admin permission.

Checklist

justdoston and others added 4 commits October 12, 2026 00:15
…dard handles to anyps5.log

A --windows-gui build started from Explorer, or any Windows executable
started without a standard output or error handle, lost everything it
printed: the entry stub's messages, the libraries' stdout and stderr,
uncaught exception messages and crash reports.

Before it enters its directory or loads a library, the entry stub now
checks the standard output and error handles, and gives each missing one
anyps5.log beside the executable. The C runtime of the libraries it then
loads adopts the file. Executables started with handles are unchanged,
and one that cannot create the file starts as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover successful GUI stdout logging, replacement of stale log, and startup when log path is a directory. AI-assisted: ChatGPT.
@danzaio
danzaio force-pushed the fix/windows-log-without-standard-handles branch from 6458adb to b390831 Compare October 12, 2026 03:54
@danzaio

danzaio commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Head b390831a5808666b39f2899cc5b19575a0ee38d5; the PR now targets main d146ec1b667c3e34bebf817efcc094bdac393423 (our local build/tests used pinned 5fe4bebec60ae1295aea301be28def2019b332ae). The #3998 docs overlap is resolved, and #3579 composes cleanly. windows_import_modules passed 1/1 and the full local CTest suite passed 121/121. The related #3786 launcher captures its own child output with pipes; it does not add the missing-handle fallback. Could an upstream collaborator run the required full build/CI for this head? I don't have dispatch permission.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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
#4739 core/relinker/relinker/tests/test_windows_import_modules.py L79-85
#5083 core/relinker/elfpatcher/src/windows/WindowsImportBuilder.cpp L8

@adriadam10

Copy link
Copy Markdown
Collaborator

Reviewed the entry stub change (WindowsEntryStubBuilder.cpp): the missing-handle check, the path-length bound against PathCapacity, the restored directory terminator and the shared log handle for the two streams are correct. The tests cover missing stdout/stderr/both, redirected handles, replacement of a stale log, unavailable log, and startup errors reaching anyps5.log, on UCRT and MSVCRT DLLs. Local Linux build and ctest in core/relinker pass; the Windows-only cases are covered by the full Build's windows job. Merging once it is green.

@adriadam10
adriadam10 merged commit a2a3a3a into boykopovar:main Oct 13, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: keep the output of an executable started without standard handles in anyps5.log

3 participants