feat(relinker): support --trace-imports for Linux output #7417
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7417"
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 IshmamDC217 on 2026-10-18T05:23:24Z.
What
--trace-imports(#4547) only worked for Windows output. This adds it for Linux output, as the second half of #3815's Linux support, on top of the libc runtime in #7411.With the flag,
LinuxElfPatchernow:TraceImport_nid_no_patchsymbol and aGLOB_DATrelocation for it, bound eagerly like every other import, so alibc.prxwithout it fails at load with ld.so's undefined symbol error;--linux-fixed-baseoutput alike;TraceImport_nid_no_patch(*slot, name, library)and stores the result back in the slot, then falls through to the usual stub.rdx(ld.so's fini pointer) and the stack are preserved.The same imports are traced as on Windows: functions bound through a PLT slot, or through a GOT slot whose symbol is a function, with no addend, and not weak.
Before storing, the prologue makes each slot's page readable, writable and executable with
mprotect. Today the Linux output dropsPT_GNU_RELRO, but #6406 keeps it, and real eboots have theirJUMP_SLOTtargets inside it. Without this, the store would fault once both are merged. I merged #6406 locally with a RELRO range over the slot's page and the traced output still ran correctly. The trade-off (those pages stay writable, and data pages become executable while tracing) is recorded indocs/dev/debt/relinker.md.Other changes:
--trace-importsno longer requires--windows. It is refused with--macos, and it still requireslibc.prxamong the libraries and conflicts with--lazy-binding.TRACING.mdand the debt entries now cover Linux.Tested
Linux x86-64, GCC 13. Relinker-only build: the full suite of 195 tests passes.
linux_trace_importstest. It builds a fakea.prxand a fakelibc.prxwithcc, likelinux_executable_exports, and runs the relinked fixture. Its hook replacesa.prx'ssharedwith a function that exits with 77.--linux-fixed-base.libc.prxwithout the hook fails at load naming the symbol.libc.prxdependency,--lazy-bindingand--macos.windows_trace_importsloses only its "requires--windows" assertion.libc.prxfrom #7411:APS5_TRACE_CALLS=a ./out.elfon a fixture whose import callsabort()prints:Not tested on a real title, Windows or macOS.
python3 tools/check_conventions.py --base origin/mainpasses.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 MarcZX10 on 2026-10-18T05:26:48Z.
Code review location:
core/libs/prx/libc/src/specifics/x86_64/CallTrace.cpp; line 148The SIGABRT handler calls
fprintfhere, thenReportCallTrace()callsdladdr, stdio, and the trace-copy routines. These are not async-signal-safe; ifabort()is raised while the thread holds a stdio/loader/trace lock, this handler can deadlock before the prior handler runs or the process terminates. Could the trace be emitted from a non-signal-context abort path (or otherwise use a signal-safe handoff) so the diagnostic cannot turn an abort into a hang?Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T05:36:20Z.
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/elfpatcher/src/linux/LinuxElfPatcher.cppL280, L286, L295, L324, L326, L347-348, L398docs/dev/debt/relinker.mdL30-31Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/CMakeLists.txtcore/relinker/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/relinker.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mddocs/user/USAGE.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/GuestCallTrace.cppcore/relinker/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/relinker/CMakeLists.txtdocs/dev/ENVIRONMENT.mddocs/user/USAGE.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/relinker/CMakeLists.txtdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/relinker.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/ENVIRONMENT.mddocs/dev/debt/libc.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/dev/TRACING.mddocs/dev/ENVIRONMENT.mddocs/user/USAGE.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/relinker.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/ENVIRONMENT.mdImported from boykopovar/AnyPS5. Originally posted by IshmamDC217 on 2026-10-18T12:10:25Z.
Code review location:
core/libs/prx/libc/src/specifics/x86_64/CallTrace.cpp; line 148Cheers, sorted in #7411 (f67014106), and this one's now rebased on it. The handler only uses
write(2)now, with no stdio,dladdror locks. There's a regression test for the heldstderrlock case too. Details are over on #7411.