feat(relinker): add --trace-imports for Windows executables #4547
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4547"
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 codingreapermaps on 2026-10-12T15:23:03Z.
What
--trace-importsmakes the Windows entry stub pass each function import throughTraceImport_nid_no_patchin libc.prx (#4546) before writing its slot, so the calls a title makes to the libraries named inAPS5_TRACE_CALLSare recorded and shown by the crash and abort reports. Without the option the output is unchanged. It covers part of #3815: the entry of a call, on Windows; arguments, results and Linux are not done.Traced: every PLT slot, and a GOT slot only when the original symbol is a function. The second rule matters: the rebuilt dynamic symbol table types every import as a function, so the original type is carried from the input relocation. Without it a data import such as
__stdoutpgot a thunk and a homebrew title crashed when it wrote through it.The option conflicts with
--lazy-bindingand needs libc.prx among the libraries; a libc.prx without the export fails at start-up with a message. Weak imports, imports of modules loaded at run time and functions looked up withsceKernelDlsymare not traced. Limits are indocs/dev/debt/libc.mdanddocs/dev/debt/relinker.md, usage in USAGE.md.This branch contains the commit of #4546; only the second commit belongs to this PR.
Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), on main
43e3a70f8.windows_trace_imports(new): a relinked fixture reaches the hook with the import's name and library and runs the address the hook returns; a data-typed GOT import is left alone; a weak import still resolves; a libc.prx without the export fails with the message; the option is rejected without--windows, with--lazy-bindingand without libc.prx.getpagesizefrom the built libkernel.prx returns 0x4000 without the option, with it and the variable unset, and with it andAPS5_TRACE_CALLS=libkernel; only the last prints the call.eboot.binandsce_module/libc.prxunwrapped from fSELF, relinked with--windows --to-intel --trace-imports; Intel i7-1165G7; before the rebase onto current main): with every library traced it reaches the same point as the untraced run (WAD loaded, audio opened at 48000 Hz,ST_Init) and ends with a normal process exit after 901,307,599 recorded calls. The last 64 were 62sin, onepthread_mutex_unlockand onesceAudioOutOutput, which is why #4546 also counts calls per import.--windows --to-intel --trace-imports: the option was used, together withAPS5_HANG_DUMP_SECS, to confirm the start-up hang described in #4280 (main thread inside the mspace allocator, no window), now addressed by #4407. The report from that run was not kept. With local changes outside this PR the title goes on to loaddemo1and present frames; that part does not depend on this option.tools/check_conventions.pyandtools/check_test_registration.pypass.Not tested: either title after the rebase, a commercial title, Linux or macOS output (the option is rejected there).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by codingreapermaps on 2026-10-12T18:11:48Z.
On the overlap comment: none of the four implements the same thing, and this PR does not build on any of them, so
Depends onstays #4546 only. They are edits to neighbouring lines. Each merges cleanly intomainand conflicts with this branch, so whichever goes second needs a rebase; I will rebase this one as they land.core/relinker/CMakeLists.txt. Keep both lines.RelinkerPipeline.cppwhere this PR reads the symbol type. Independent; a null symbol entry reads as not a function here, which is what is wanted.Weakflag in the same four places where this PR addsFunction, read from the samest_infobyte. Both append a positionalboolto the same initializers, so the merged code has to pass each value to its own field; resolved carelessly it would compile and swap them.WindowsPePatcherin the position this PR uses. Same caveat: aboolpassed where its optional address is expected converts without a compile error, so the call inmain.cpphas to be rewritten, not just merged.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:59:18Z.
Rebased onto current
main: the branch still carried the first commit of #4546, which merged separately, so I dropped it, and resolved the conflicts with the refactoredmain.cpp/WindowsPePatcher(traceImportsnow goes throughConversionOptionsintoConversion.cpp) plus theUSAGE.md/debt/libc.mdneighbours.Checked the entry-stub change, the function/data split of imports (
FunctionImports) and the option validation; relinker tests pass (125/125) andwindows_trace_importsfails without the non-test changes. The Windows execution part of that test is covered by the full Build; merging once it is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T15:01:56Z.
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.
main)core/relinker/cli/include/Cli.hppL26core/relinker/cli/src/CliArgs.cppL13, L126docs/user/USAGE.mdL53core/relinker/elfpatcher/include/elfpatcher/windows/WindowsEntryStubBuilder.hppL23core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cppL69core/relinker/elfpatcher/src/windows/WindowsPePatcher.cppL90docs/user/USAGE.mdL159docs/dev/debt/relinker.mdL15core/relinker/cli/src/CliArgs.cppL13docs/dev/debt/libc.mdL67core/relinker/domain/include/domain/Types.hppL64core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cppL96