Commit Graph
302 Commits
Author SHA1 Message Date
Get-fix 6f3e4a147f fix(relinker): read guest TLS relocations against the module's own section symbol
Limbo's bundled libSceFios2.prx (CUSA01664) has DTPMOD64 relocations
against a local section symbol with section index 0 and value 0, in a
module without section headers. As for a TLS relocation without a
symbol, the module and offset are the module's own TLS block, so a
DTPMOD64 or DTPOFF64 against such a symbol is passed on without it. A
section symbol that names a section or has a value, a TPOFF64, a module
without PT_TLS and a DTPMOD64 with an addend still fail.
2026-10-21 19:19:07 +03:00
Dean fbba6e8208 Merge pull request #8845 from rooklz/fix/refs-file-identity
fix(relinker): compare Windows file identities by their 128-bit file ID
2026-10-21 20:57:16 +13:00
Rookie 5748d7ce81 fix(relinker): compare Windows file identities by their 128-bit file ID 2026-10-21 06:09:46 +01:00
Dean 46bfbe4e25 Merge pull request #8063 from AasishDairelSahayaGrinspan/fix/relinker-gs-memory-only-traps
fix(relinker): trap only GS memory accesses in Windows and macOS output
2026-10-21 16:35:25 +13:00
Dean 6056689ad6 Merge pull request #8614 from DavidSamir/fix/relinker-call-zero-padding
fix(relinker): stop the control-flow walk at zero padding after a call
2026-10-21 15:27:12 +13:00
mpratsakiandClaude Opus 5.5 763702c5ce fix(relinker): use the Windows file identity in module and executable checks
Guest module discovery skipped the input executable and the
--executable check rejected an executable converted twice through
std::filesystem::equivalent, which MinGW reports as false for hard links
whose names give different permissions, such as .bin and .exe. Move the
GetFileInformationByHandle comparison to Io::SameFile and use it for
these checks and for SameOutputFile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 02:19:01 +03:00
Dean 29e4c46b4d Merge pull request #7417 from IshmamDC217/feat/relinker-trace-imports-linux
feat(relinker): support --trace-imports for Linux output
2026-10-21 09:03:29 +13:00
David 24c5c8ed5f test(relinker): convert a call before zero padding and a misread FS byte for Windows and macOS 2026-10-20 22:17:45 +04:00
javierUDP cc69253830 fix(relinker): keep the interpreter path out of the scanned code
The code analysis trims an interpreter path from the start of an
executable segment only for images that have a PT_SCE_DYNLIBDATA block.
An executable without one keeps that path in the scanned range, so
/libexec/ld-elf.so.1 is walked as code: a RELATIVE relocation with
addend 0 roots the control flow graph at the first byte of the segment,
and the 0x64 of "ld-elf" decodes as an FS-prefixed instruction that the
Windows and macOS TLS rewriters refuse. The trim now runs for both
layouts, ending at the segment for an image without the block.
2026-10-20 14:56:20 -03:00
Dean Galvin 143ed02750 Merge branch 'main' into #7417
Resolve docs/dev/debt/libc.md: keep main's _Throw_Cpp_error entry and this branch's call tracing entry.
2026-10-21 06:33:59 +13:00
Dean 892a4f1328 Merge pull request #7993 from MarrasFederico/fix/relinker-windows-trampoline-builder-guards
fix(relinker): validate Windows trampoline section placement and sites
2026-10-21 06:30:55 +13:00
Dean 2fee39f1b3 Merge pull request #6684 from SandstromPL/fix/relinker-guest-zero-init
fix(relinker): run a guest DT_INIT of 0 as the module initializer
2026-10-21 06:07:25 +13:00
aasishdairel 0d3f6f7262 test(relinker): split GS trap coverage groups
The Windows gs_traps group grew to 21 relinker invocations and ran close to its 30 s CTest timeout on a loaded host. Split the implicit-memory cases into gs_traps_implicit so each group stays well under the limit, and share the per-case check between them.
2026-10-20 21:54:30 +05:30
Adrià 8afd6ea478 Merge pull request #7660 from savvaniss/fix/sce-code-gaps
fix(relinker): resume scans after undecodable bytes between PS4 unwind functions
2026-10-20 13:17:15 +02:00
Adrià 77c18cefae Merge pull request #6903 from Zinebyte/fix/guest-unused-import-dependencies
fix(relinker): infer guest dependencies from referenced imports
2026-10-20 11:08:47 +02:00
Adrià 3d54c5b2b2 Merge pull request #6448 from DavidSamir/fix/relinker-macos-empty-tls
fix(relinker): convert stack-guard and thread-pointer reads with an empty PT_TLS for macOS
2026-10-20 10:40:07 +02:00
Adrià 5e7c618699 Merge pull request #6607 from jweidenh/codex/overlapping-rela-tables
fix(relinker): handle overlapping relocation tables
2026-10-20 10:38:40 +02:00
Ishmam Ahmed 78634fb0a9 feat(relinker): support --trace-imports for Linux output
The Linux entry stub now passes each traced import through libc.prx's
TraceImport_nid_no_patch before it calls the guest entry, and stores the
returned thunk in the import's slot. The same imports are traced as on
Windows: functions bound through a PLT slot or a GOT slot, without an
addend, and not weak. TraceImport_nid_no_patch is bound eagerly through
an added GLOB_DAT relocation, so a libc.prx without it fails at load.
Each slot's page is made writable with mprotect first, so slots inside a
PT_GNU_RELRO range can be replaced.

--trace-imports now requires libc.prx among the libraries on Linux too,
and is refused with --macos.
2026-10-19 22:56:03 +01:00
Adrià 7c43dc6bfc Merge pull request #7453 from Agnibha007/fix/unused-filter-fallthrough-padding-abort
fix(relinker): stop the unused-filter CFG walk before trailing zero padding
2026-10-19 23:51:02 +02:00
Adrià ae7ad5ff98 Merge pull request #7361 from RockENZO/codex/macos-executable-exports
fix(relinker): preserve executable exports in macOS output
2026-10-19 20:41:17 +02:00
Federico Marras b336f0c4dc fix(relinker): validate Windows trampoline section placement and sites 2026-10-19 18:57:12 +02:00
Agnibha Mukherjee 1f28b37898 fix(relinker): stop the unused-filter CFG walk before trailing zero padding
buildGraph fell through from the entry points into the segment's zero
padding; an odd-length zero tail left a lone 0x00 the decoder needs a
ModRM byte for, and the non-speculative walk let that truncation escape
the pipeline, so unused-filter=1 exited 2 on input the other levels
convert. Bound the walk before the trailing zeros the way
StrictReachability does; mandatory roots still decode strictly.
2026-10-19 17:23:57 +02:00
Dean 5eba12d6bd Merge pull request #7775 from whamre/fix/windows-tls-zero-fill
fix(relinker): keep the PT_TLS zero fill out of memory when converting to Windows
2026-10-20 02:23:39 +13:00
Adrià 0fa6ddb137 Merge pull request #6802 from DavidSamir/feat/relinker-macos-fixed-base
feat(relinker): place macOS executables at a fixed base with --macos-fixed-base
2026-10-19 12:54:31 +02:00
Adrià bcdc5f6b3e Merge pull request #6702 from karimibrahim07/fix/relinker-weak-guest-imports
fix(relinker): leave weak imports of bundled modules unbound on Windows
2026-10-19 10:49:10 +02:00
Adrià e0adc075a2 Merge pull request #6697 from karimibrahim07/feat/relinker-named-host-imports
fix(relinker): resolve symbol-name imports through NIDs on Windows
2026-10-19 10:49:05 +02:00
Adrià 4630318457 Merge pull request #6681 from milescoviello/fix/relinker-bss-page-overlap
fix(relinker): keep a segment's zero-filled tail zero when the next PT_LOAD starts on its page
2026-10-19 10:48:54 +02:00
David 3ea53b5412 test(relinker): check the macOS fixed base layout and option parsing
macos_fixed_base relinks the fixed-base fixture with and without
--macos-fixed-base 0x400000 and checks that every segment and section
moves by the same amount, __PAGEZERO ends 64 KiB below the base, the
lowest load page is at the base, the entry offset is unchanged, and the
metadata load bias and the relocated slot hold base-relative addresses.
It also checks the lowest base and the refused options and images.

cli_args covers the parsing, range, repetition and --macos requirement.
2026-10-19 10:32:50 +02:00
Savvanis Spyros 504c41a9ad Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into fix/sce-code-gaps
# Conflicts:
#	core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
2026-10-19 10:06:58 +03:00
Adrià 977ee725b2 Merge pull request #6595 from MarcZX10/codex/ps4-relative-jump-tables-3093
fix(relinker): exclude trailing PS4 relative jump tables
2026-10-19 09:01:03 +02:00
jweidenh 185fa96875 fix(relinker): handle overlapping relocation tables 2026-10-19 02:47:15 -04:00
Werner ea58c903b0 fix(relinker): keep the PT_TLS zero fill out of memory when converting to Windows
WindowsTlsBuilder allocated the whole TLS block and thread control block
for .gtls, so a large p_memsz cost that much memory even though only the
p_filesz template is written. Store the template and reserve the rest as
the section's virtual size; the TLS directory still covers the whole
block, which the loader copies from the zeroed image.
2026-10-19 06:39:49 +00:00
Kovalev Vladislav 269a59e23a fix(relinker): preserve defined RELATIVE symbols with section markers 2026-10-19 09:46:47 +06:00
SandstromPLandClaude Opus 5.5 0500362ff2 test(relinker): run guest_zero_initializer with the ASan host-loading option
#7147 added add_asan_test_options so the CPU-side tests pass in an
ANYPS5_ENABLE_ASAN build, and gave the relinker tests that load the
instrumented guest_module_args_host.prx into Python
verify_asan_link_order=0. guest_zero_initializer's Linux run loads the
same host library with ctypes.CDLL in a Python subprocess, so under ASan
it failed with "ASan runtime does not come first in initial library
list". It now runs with the same option.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 07:33:52 +05:30
SandstromPL 40a2e871a1 Merge remote-tracking branch 'upstream/main' into fix/relinker-guest-zero-init 2026-10-19 07:33:46 +05:30
Adrià 134a3510c8 Merge pull request #6419 from DavidSamir/fix/relinker-macos-tls-alu-reads
fix(relinker): rewrite ALU reads of guest TLS through %fs in macOS output
2026-10-19 03:02:09 +02:00
Adrià 819c5477b9 Merge pull request #6466 from whamre/fix/windows-sparse-load-image
fix(relinker): keep unmapped gaps out of the Windows load image
2026-10-19 03:00:53 +02:00
Adrià 42d8666f29 Merge pull request #6458 from DavidSamir/fix/relinker-trap-macos-guest-gs
fix(relinker): trap guest GS accesses in macOS output instead of refusing the module
2026-10-19 02:56:44 +02:00
Dean 60fb8078c7 Merge pull request #6067 from meh7an/perf/libs-mimalloc-windows
feat(libs): let relinked Windows games opt into mimalloc
2026-10-19 13:09:36 +13:00
David 8da24830ac test(relinker): cover GS loads, stores and ALU reads trapped in macOS output
macos_gs_traps converts the forms Wine's ntdll in Prospero Win (PPSA99995) uses, a store, an ALU read and a register-address form shorter than a jump, and checks that each becomes ud2 and NOP padding of its own length before the next instruction, with none of the original bytes left.
2026-10-19 02:06:43 +02:00
Adrià ea41ee4031 Merge pull request #6410 from DavidSamir/fix/relinker-macos-tls-overlapping-decode
fix(relinker): skip prefixed decodings inside an earlier instruction in the macOS TLS scan
2026-10-19 01:58:54 +02:00
Adrià a9e7267465 Merge pull request #6418 from jweidenh/codex/optional-rela-table
fix(relinker): accept executables without a RELA table
2026-10-19 01:56:53 +02:00
Savvanis Spyros c3d1363df3 Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into fix/sce-code-gaps
# Conflicts:
#	docs/dev/debt/relinker.md
2026-10-19 02:35:44 +03:00
RockENZO ec5c0dcd0c fix(relinker): preserve executable exports in macOS output 2026-10-19 08:59:29 +10:30
Mehran 9824c46fe0 feat(libs): let relinked Windows games opt into mimalloc 2026-10-19 00:08:47 +03:00
Savvanis SpyrosandClaude Opus 5.5 45a2e3dd4a fix(relinker): resume scans after undecodable bytes between PS4 unwind functions
In PS4 executables and modules the bytes between unwind functions are
16-byte slots of function tails and padding, and a tail can begin inside
an instruction, such as a lone REX byte before a 15-byte NOP. The
syscall and call-site scans decode the executable segment linearly, so
such a slot failed the relink with "Cannot decode instruction".

For images with a PT_SCE_DYNLIBDATA segment the scans now receive the
unwind function ranges. Outside every range an undecodable byte is
skipped and decoding resumes at the next byte, and a decoding that would
cross into a range ends at its start, so gap bytes cannot change how a
function is decoded. Inside a range a decode failure still fails the
relink, and images without unwind ranges are scanned as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 23:45:49 +03:00
Dean Galvin c3b9001592 revert(relinker): run guest preinit arrays before the module initializer (#6112)
This reverts commit 376c040294.
2026-10-19 09:38:31 +13:00
Eli Yarson 346b0a92ca feat(relinker): add conversion-time game patches
A per-game relinker-patches.toml (or --patches) replaces verified bytes in
the input executable and bundled modules before conversion. Entries are
checked against the expected bytes and against every in-place writer,
the ELF header range and relocation targets. An <output-stem>.patches.toml
manifest records the applied entries, and --verify-patches checks an input
or a converted output. With no patch file the output is unchanged.
2026-10-18 14:57:13 -03:00
Ayamullah Khan 36baa5fcad test(relinker): run the guest preinit test with verify_asan_link_order=0
guest_preinit loads the instrumented guest_module_args_host.prx into Python, so in an ANYPS5_ENABLE_ASAN build it needs the same verify_asan_link_order=0 as the other module tests; without it, it fails with "ASan runtime does not come first in initial library list". add_asan_test_options does nothing outside ASan builds.

Signed-off-by: Ayamullah Khan <[email protected]>
2026-10-18 19:09:47 +02:00
Ayamullah Khan 9c43211664 fix(relinker): run guest preinit arrays before the module initializer
Converted guest modules never ran their DT_PREINIT_ARRAY entries: the
reader validated the array and the unused-NID filter kept its targets,
but no writer emitted or ran it. ld.so runs a shared object's preinit
array only for the main executable, so the Linux output runs the
entries from the DT_INIT stub before the module initializer; the macOS
and Windows outputs run them before the initializer in their startup
stubs, and the deferred Windows output exports a thunk that runs them
before the initializer for runtime-loaded modules. A module with a
preinit array and no initializer is still rejected, since the Linux
stub exists only with one.
2026-10-18 19:09:46 +02:00