Commit Graph

443 Commits

Author SHA1 Message Date
ctj01 b7d5f18c41 fix(relinker): drop the input PT_PHDR and PT_INTERP from Linux output
The Linux patcher writes its own PT_PHDR and PT_INTERP but also copied
the input's. glibc takes the load bias from the last PT_PHDR, which was
the input's entry with the pre-relink address, so such an executable
crashed at start. Both copies also took program header slots, so an
input with PT_PHDR and PT_INTERP and no spare slots failed to relink.
2026-10-10 17:33:59 +00:00
MarcZX100 c5ffebe15a fix(relinker): preserve empty Windows arguments 2026-10-10 17:28:07 +00:00
MarcZX100 fe81332b08 test(relinker): cover unicode guest module paths 2026-10-10 17:22:07 +00:00
MarcZX100 8cbebea6b7 fix(relinker): preserve unicode module paths 2026-10-10 17:22:07 +00:00
aplatogg b74774f713 fix(relinker): support non-ASCII input paths on Windows
The MinGW CRT delivers argv to main as ANSI code page bytes, and every narrow string became a filesystem path through the same code page, so a game in a directory with characters outside the code page failed to open (#2692). Read the command line as Unicode (wmain via -municode), keep paths as UTF-8 strings, convert at the filesystem boundaries through Io::NativePath and Io::Utf8Path, and run the --autorun output through CreateProcessW.

(cherry picked from commit 30a5181f8a71b177cf2dc03334e39998938b3472)
2026-10-10 17:22:07 +00:00
AlxcBTW fccfbee72b fix(relinker): convert Windows guest TLS reads after zero alignment padding
The Windows TLS rewriter only patches FS-relative instructions that
CodeInstructionCollector decodes. Code that no symbol, unwind range or
root reaches is covered by a linear sweep that starts after int3 padding
and stops at the first instruction beginning with two zero bytes, so
zero-filled bytes are not read as code.

The .NET NativeAOT homebrew titles pad between functions with zero bytes
instead of int3 and have unwind entries for only part of their code. In
Prospero Vibrate (PPSA99920) the sweep ended at the padding after the
first function. Functions reached only through switch jump tables, which
the control-flow graph does not follow, or through pointers it cannot
resolve kept 105 of 670 FS loads unpatched: 84 `mov reg, fs:[0x28]`
stack-guard reads (65 into rax, 19 into rcx) and 21 `mov rax, fs:[0]`
thread-pointer reads. The title faulted reading address 0x28 within a
second of start.

The sweep now treats a zero run that follows a jump, call, return or
trap and ends at the next 16-byte boundary as alignment padding, and
continues at that boundary. A call counts because a function can end in
a call to a noreturn function. Zero fill after straight-line code, or a
whole zero 16-byte block, still ends the sweep as before.

All 670 FS loads in PPSA99920 are now patched, as are the 102 of 685 in
Prospero Explorer (PPSA99109) and the 103 of 718 in Prospero Multi Tools
(PPSA99110). New tls_function_coverage padding cases: loads behind zero
padding after a return, a call and a jump, with 13, 2, 1 and 5 zero
bytes, are patched; a load behind zero fill after a nop is left
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 0306c677784b6c4272990ce65f6daf9fb2dbc3ca)
2026-10-10 16:08:54 +00:00
tototomate123 ded8b4df23 fix(relinker): preserve executable exports and dynamic lookup tags 2026-10-10 16:58:39 +02:00
tototomate123 7ea423f78b fix(relinker): map executable section addresses through load segments 2026-10-10 16:57:31 +02:00
boykopovar 0bd2e4cb90 test(relinker): align module tests with nonrecursive discovery 2026-10-10 15:31:17 +03:00
boykopovar 336d481bff fix(relinker): default module path to input elf directory 2026-10-10 14:12:04 +03:00
boykopovar bec6d62b29 feat(relinker): add explicit guest module parent path option 2026-10-10 14:10:13 +03:00
boykopovar 776f7738d4 fix(relinker): stop requiring host dependencies in guest module directories 2026-10-10 14:04:37 +03:00
boykopovar 400a496792 refactor(relinker): unify guest module diagnostics 2026-10-10 14:02:00 +03:00
boykopovar 41126bfa5b fix(relinker): restrict guest module discovery to adjacent directories 2026-10-10 13:59:11 +03:00
Adrià ebe6c180bf
Merge pull request #2594 from morten-holm/pr/macos-clear-pie
fix(relinker): leave MH_PIE clear in the macOS executable
2026-10-10 11:15:15 +02:00
Adrià 3d1a7d90c7
Merge pull request #2619 from oneandonlydean/fix/carry-2525
fix(relinker): skip repeated DT_NEEDED libraries
2026-10-10 11:01:22 +02:00
Adrià 69e9a2685a
Merge pull request #2605 from elsi06/fix/relinker-self-guest-modules
fix(relinker): reject guest modules in SELF containers
2026-10-10 10:52:52 +02:00
nyavana 8b008a3e96 test(relinker): cover repeated guest module dependencies
Generate guest PRX dependencies with adjacent and separated repeats, equal names at distinct string offsets, and invalid-name controls. Check acceptance for Linux and Windows conversion and first-seen dependency order in ELF outputs.

Depends on the production fix by Hannah Lyons (babyhuey), c1a6696872153b8e41608f4cc8ab9a0d36f1d206. Written with AI assistance.
2026-10-10 21:23:19 +13:00
Yassine 6158444f71 fix(relinker): leave zero-filled PT_LOAD memory out of Windows files
WindowsPeWriter stored every PE section with SizeOfRawData equal to its
virtual size, so the zero-filled tail of a PT_LOAD segment (p_memsz above
p_filesz, the .bss) was written to the executable byte for byte. A segment
with 256 MiB of .bss produced a 269 MB .exe, while the Linux output of the
same image is under 5 KB.

Each section is now stored up to its last non-zero byte, aligned to the file
alignment, and VirtualSize keeps the full size. The PE loader zero-fills the
part of a section beyond SizeOfRawData (Microsoft PE format, section table:
SizeOfRawData). A section with no non-zero byte gets no raw data and a zero
PointerToRawData.

windows_bss relinks an image with 64 MiB of .bss, checks the section table
and the mapped image, and on Windows runs the executable, which reads the
last word of the .bss.
2026-10-10 21:23:19 +13:00
Hannah Lyons 0e03ad0f95 fix(relinker): skip repeated DT_NEEDED libraries 2026-10-10 21:23:19 +13:00
Patrick Elsasser bc444a675d fix(relinker): reject guest modules in SELF containers
A bundled module whose file starts with a SELF container magic
(4f 15 3d 1d or 54 14 f5 ee) was skipped like any other non-ELF file,
so the relink succeeded without it and the module was missing at run
time. The guest module scan now throws, naming the module, as
ElfReader already does for a SELF executable.

Fixes #2599

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 10:22:58 +02:00
gunerky b2ff4f4b02 test(relinker): split TLS coverage into bounded CTest groups 2026-10-10 10:07:33 +02:00
Hamidreza 41856ea6c5 perf(relinker): single-pass CFG instruction decoding and zero-copy text span 2026-10-10 09:48:02 +02:00
Adrià 2f250f83aa
Merge pull request #1815 from eliasbruno124-dev/fix/nested-required-modules-publication
fix(relinker): discover required modules in nested standard directories
2026-10-10 09:19:07 +02:00
Dean edbf36ad4c
Merge pull request #2574 from oneandonlydean/fix/carry-2464
fix(relinker): start Windows executables in their own directory
2026-10-10 20:07:53 +13:00
Morten Holm 31b6af028f fix(relinker): leave MH_PIE clear in the macOS executable
The executable is linked at a fixed base with a __PAGEZERO that fills the space below it, and
the guest assumes 16 KB pages. With MH_PIE set dyld slides the image by a multiple of 4 KB,
which breaks that assumption and ends in a SIGBUS (KERN_PROTECTION_FAILURE) in about half of
the launches under Rosetta 2. Clearing the flag keeps the image at its linked address.

test_macos_output.py now reads the header flags and checks that MH_PIE is clear.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-10 09:07:14 +02:00
Adrià 653e3d04d7
Merge pull request #2097 from treuenten/fix/relinker-entry-stub-rel32
fix(relinker): reject a Linux entry stub whose call cannot reach the entry
2026-10-10 08:49:35 +02:00
Dean 6f262eb0f4
Merge pull request #2568 from oneandonlydean/fix/relinker-decode-xop-2559
fix(relinker): decode XOP instructions
2026-10-10 19:47:50 +13:00
Get-fix 975475929e fix(relinker): start Windows executables in their own directory
The guest filesystem root and the save data directory are taken from the
current directory, so an executable started from another directory does
not find its title files and keeps saves elsewhere. Make the executable
directory the current directory in the Windows entry stub before the
system libraries are loaded.
2026-10-10 19:44:06 +13:00
Adrià d7f24e7652
Merge pull request #2294 from Vabian124/cursor/fix-relinker-reject-non-regular-input-9077
fix(relinker): reject non-regular input files
2026-10-10 08:35:29 +02:00
Adrià 8f693fc82c
Merge pull request #2274 from jweidenh/codex/fix-linux-program-header-count
fix(relinker): count all synthetic Linux program headers
2026-10-10 08:32:53 +02:00
Achraf Reyani ce8dbc977f fix(relinker): decode XOP instructions
The x86 decoder had no XOP (AMD 8F escape) support and read 8F E8.. as
POP r/m, losing instruction boundaries. Since #2238 roots code addresses
taken by RIP-relative LEA, code analysis reaches CPU-dispatched XOP
paths, such as the vpperm routines in Stremio Plus (PPSA74126), OpenNOW
(PPSA99082) and PPSA99420, and their Windows conversion failed with
"Code analysis: overlapping instruction boundaries". Decode 8F followed
by a map of 8 or more as a three-byte XOP prefix (8F can only be POP r/m
with ModRM.reg 0) with a ModRM operand, an 8-bit immediate in map 8 and
a 32-bit immediate in map 0Ah, in both the length and operand decoders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 19:27:24 +13:00
Cursor Agent eba1dec764 fix(relinker): reject non-regular input files
A directory opens and tellg reports an enormous size, so the relinker
tried to allocate it and failed with std::bad_alloc. Require a regular
file and a non-negative size before allocating the input buffer.
2026-10-10 08:26:32 +02:00
simonbbby fcb0b962a7 fix(relinker): collect init and fini array roots through the containing load segment
The unused-filter=1 entry point collector translated DT_INIT_ARRAY and
DT_FINI_ARRAY through PT_DYNAMIC and skipped arrays placed before it, which is
the usual linker layout, so constructors and destructors were not roots and
imports used only by them were dropped. Arrays are now translated through the
PT_LOAD that holds them, slot targets come from RELATIVE relocations when
present, and DT_PREINIT_ARRAY is collected as in the strict filter.
2026-10-10 08:25:50 +02:00
Adrià 019ca236fb
Merge pull request #1958 from arcwiser/fix/windows-pe-relocs-stripped
fix(relinker): keep Windows images without relocations loadable
2026-10-10 08:06:20 +02:00
eliasbruno124-dev e2401a8dc0 fix(relinker): discover required modules in nested standard directories 2026-10-10 08:05:01 +02:00
Adrià be775231a2
Merge pull request #1651 from emirplus/feat/relinker-tls-register-alu
feat(relinker): support Windows guest TLS reads by ALU register-address instructions
2026-10-10 07:58:52 +02:00
Dean 6635c7abbf
Merge pull request #2117 from krishalivaibhav/codex/relinker-help
feat(relinker): support explicit CLI help
2026-10-10 18:54:09 +13:00
Dean e31154aa90
Merge pull request #2196 from AchrafReyani/fix/relinker-entry-point-bounds
fix(relinker): bound the entry point collector's header and symbol reads
2026-10-10 18:54:02 +13:00
jweidenh c8a23b1ad5 test(relinker): reserve all headers in native execution fixtures 2026-10-10 01:38:08 -04:00
jweidenh 25984a728c fix(relinker): count all synthetic Linux program headers 2026-10-10 01:38:07 -04:00
Dean 3aae312a4b
Merge pull request #1552 from arvindfroi/test/decoder-length-table
test(relinker): check decoder lengths against an LLVM-generated table
2026-10-10 18:36:17 +13:00
Achraf Reyani b1599a94ea fix(relinker): bound the entry point collector's header and symbol reads
The CFG/GOT filter's entry point collector checked header and symbol
positions as `offset + size > file size`, which wraps for offsets
near 2^64. A section header or symbol table offset there passed the
check, read bytes before the input buffer, and could reach an
in-bounds table through the wrapped address, adding entry points that
keep relocations alive. Check every position by subtraction instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 14:23:20 +09:00
JohnM ded18e503f fix(relinker): reject a Linux entry stub whose call cannot reach the entry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 13:22:07 +08:00
krishalivaibhav 1fc31ba358 feat(relinker): support explicit CLI help 2026-10-10 10:31:52 +05:30
Dean cb3aecac97
Merge pull request #2339 from johnmaia/fix/relinker-terminate-frame-chain
fix(relinker): end the guest frame-pointer chain at the entry stub
2026-10-10 17:47:11 +13:00
Dean 2c7d2cec17
Merge pull request #2262 from NumberGuan/codex/validate-elf-identification
fix(relinker): validate ELF identification before parsing
2026-10-10 17:46:17 +13:00
Dean 42a1b1d75a
Merge pull request #2256 from NumberGuan/codex/fix-truncated-eh-frame-headers
fix(relinker): reject truncated EH frame headers
2026-10-10 17:46:09 +13:00
Dean a5a4919746
Merge pull request #2245 from NumberGuan/codex/fix-eh-frame-sleb128-overflow
fix(relinker): reject overflowing signed unwind LEB128 values
2026-10-10 17:45:54 +13:00
Dean e2ba429015
Merge pull request #2243 from NumberGuan/codex/protect-relinker-inputs
fix(relinker): protect executable inputs from output overwrites
2026-10-10 17:45:47 +13:00
Dean ae3574bb0d
Merge pull request #2238 from mrk1987/fix/relinker-address-taken-tls-roots
fix(relinker): root code addresses taken by RIP-relative LEA
2026-10-10 17:45:39 +13:00
Dean 5545196d0e
Merge pull request #2222 from EshaanJaiswal/fix-relative-relocation-bounds
fix(relinker): validate relative relocation table bounds
2026-10-10 17:45:25 +13:00
Dean 661295e736
Merge pull request #2154 from gunerky/codex/diagnostic-fixture
test(relinker): isolate Windows diagnostic fixtures
2026-10-10 17:44:31 +13:00
Dean 1b5ebc6986
Merge pull request #2091 from treuenten/fix/relinker-callsite-range-wrap
fix(relinker): reject a relocation target whose range wraps the address space
2026-10-10 17:43:52 +13:00
Dean 9992a5d5e5
Merge pull request #1944 from babyhuey/fix/relinker-lsda-without-personality
fix(relinker): read LSDA call-site tables only under a personality routine
2026-10-10 17:43:06 +13:00
Dean 300bd79439
Merge pull request #1935 from Zinebyte/fix/prefixed-syscall-validation
fix(relinker): reject prefixed system-call instructions
2026-10-10 17:42:59 +13:00
Dean a92b3db3d9
Merge pull request #1911 from TheAggie/fix/relinker-empty-tls-guard-access
fix(relinker): convert stack-guard and thread-pointer reads with an empty PT_TLS
2026-10-10 17:42:20 +13:00
Dean fdd2d26077
Merge pull request #1830 from tv7/fix/relinker-needed-debug-prx
fix(relinker): match needed module names that differ only in the extension
2026-10-10 17:41:41 +13:00
Dean 8c62529cad
Merge pull request #1822 from eliasbruno124-dev/fix/guest-runpath-depth
fix(relinker): rebase guest runpaths from their output directories
2026-10-10 17:41:33 +13:00
Dean 07633df7fb
Merge pull request #1549 from LeandroLP23/fix/gcc-warnings
fix: clear the GCC warnings in ProfileOutput, fopen, Ajm batch jobs and the SHA-256 test
2026-10-10 17:39:38 +13:00
JohnM d1c14102ab fix(relinker): reject a relocation target whose range wraps the address space
A jump slot whose r_offset is 0xFFFFFFFFFFFFFFF8 or higher makes
targetGotOrPltAddress + 8 wrap, so the upper lower_bound lands before
the lower one and the call-site loop walks past the end of the map
(SIGSEGV; ASan heap-buffer-overflow in ResolveCallSites).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 11:03:16 +08:00
arcwiser a18955ee97 fix(relinker): keep fixed Windows images loadable 2026-10-10 12:26:02 +11:00
Hannah Lyons c970ca73a0 fix(relinker): read LSDA call-site tables only under a personality routine 2026-10-09 21:23:27 -04:00
Adrià c9da0f93cf
Merge pull request #1559 from ctj01/fix/relinker-pt-load-order
fix(relinker): write Linux PT_LOAD headers in ascending address order
2026-10-10 03:16:06 +02:00
Adrià 3181e7116d
Merge pull request #1597 from mugurc/macos-relinker
feat(relinker): write Mach-O output for macOS with --macos
2026-10-10 03:13:21 +02:00
Adrià 69cee68d4b
Merge pull request #1522 from silentone12725/perf/relinker-strict-reachability
perf(relinker): replace O(n²) zero-padding scan in StrictReachability
2026-10-10 03:08:57 +02:00
Adrià 395d24697c
Merge pull request #1506 from kali113/fix/linux-guest-stack-header
fix(relinker): give Linux guest modules a default non-executable stack
2026-10-10 03:05:35 +02:00
Adrià be3441903b
Merge pull request #1503 from eliasbruno124-dev/fix/guest-required-identities
fix(relinker): discover required guest module identities
2026-10-10 03:05:15 +02:00
Adrià b993145df1
Merge pull request #1446 from sktharunbalaji13-cmd/contrib/rela-table-bounds
fix(relinker): bound DT_RELA table range
2026-10-10 03:01:42 +02:00
Adrià ff8961dfbc
Merge pull request #1102 from jeffrey12cali/fix/module-args-on-linux
fix(libkernel): pass module args and argp to runtime-loaded modules on Linux
2026-10-10 01:27:59 +02:00
Tharun Balaji 204a5e7a42 test(relinker): cover relocation table bounds in C++ under both output modes 2026-10-10 01:26:27 +02:00
Tharun Balaji bef3286e81 fix(relinker): bound DT_RELA table range 2026-10-10 01:26:27 +02:00
Adrià 32064d31fc
Merge pull request #1401 from xsvm/perf/relinker-in-place-substitutions
perf(relinker): write in-place --to-intel substitutions directly
2026-10-10 01:21:28 +02:00
Adrià Franch 8868d563b5 test(relinker): make guest_module_args run its native path
The machine check compared against 'x86-64' (uname reports 'x86_64'), so the
native execution was always skipped. With it enabled the fixture itself was
wrong: the initialiser's rip-relative call used the wrong displacement, and
the pending block was set on a different copy of the host library than the
one the module binds to.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-10 00:57:52 +02:00
jeffrey12cali 7d1821e3ab fix(relinker): emit the relocation table when the guest module has none
The DT_RELA tags were still guarded on the input module's relocation table, while the
new accessor relocations were appended to a copy of it. A module with an initialiser and
no imports therefore kept the argument stub but lost both relocations that fill its GOT
slots, so the stub called through a null pointer at load time.

Guard on the extended table instead, and drop the unused start parameter from the
displacement helper. The test now converts a module whose DT_RELASZ is zero and asserts
that the output carries both accessor imports and a 48-byte relocation table.
2026-10-10 00:57:52 +02:00
jeffrey12cali 7b8b2047b8 test(relinker): assert converted modules receive the module argument block
Add a hand-built guest module with an explicit DT_INIT that forwards rdi and rsi to a
host recorder without touching them and returns a known value. The test sets a known
argument count and argument pointer, loads the converted module, and asserts that the
initialiser received both values and that the stub forwarded its return value.

The host recorder also provides the two accessor symbols, so the test resolves them
without loading libkernel. The converted module must import both accessors, which is
what distinguishes the new behaviour from the previous stub that zeroed the arguments.
2026-10-10 00:57:52 +02:00
jeffrey12cali 36c979b369 fix(libkernel): pass module args and argp to runtime-loaded modules on Linux
sceKernelLoadStartModule discarded its arguments, and the relinker's Linux guest writer
synthesized an initialisation trampoline that also cleared the argument registers before
jumping to the module entry point, so a converted module always reached its own start-up
code with args = 0 and argp = NULL.

On PPSA28997 two of the title's own modules validate that parameter block as their first
act and dereference it unconditionally: SaveData faults on `mov (%rsi),%eax` with rsi = 0
beside its `cmp $0x10` size checks, and PSN faults the same way at PSN+0x3ee7 with rbx = 0.
The Windows branch delivers the block, so identical code reports its parameter-version
error and continues instead of faulting.

sceKernelLoadStartModule now records the pair before dlopen and clears it afterwards, and
the emitted DT_INIT stub reads it through two accessors exported by libkernel. The
initialiser is called rather than tail-jumped so its return value can be reported through
*res as the PS5 API specifies. The state is thread_local, which makes the handoff per-call:
ld.so runs a module's initialiser on the thread that called dlopen. DT_FINI keeps a plain
call-through, so unloading neither reads stale arguments nor reports a result.

The accessor names use the _nid_no_patch suffix so the NID resolver leaves them alone and a
guest import can name them exactly.
2026-10-10 00:57:51 +02:00
Adrià cb9734cd8a
Merge pull request #1272 from Dextroid17/fix/relinker-dynamic-table-bounds
fix(relinker): bound the symbol and relocation table reads
2026-10-10 00:42:33 +02:00
john.maia e4dcf3e6c0 fix(relinker): end the guest frame-pointer chain at the entry stub
The entry stubs called the title's entry with rbp left as the process
started it (0 on Linux) or as a loop counter left it (0 on Windows). The
title's start code pushes rbp, so the frame-pointer chain of its main
thread ended in a null frame pointer. Unreal Engine walks that chain to
capture call stacks (for an ensure, for example) and reads the return
address at [rbp + 8], so the walk read address 8 and crashed.

Both stubs now push a zero frame record (saved rbp 0, return address 0)
and point rbp at it before the call, so frame-pointer walks stop at the
entry. The Linux stub pushes it below the aligned stack pointer, keeping
the 16-byte alignment at the call. The Windows stub writes it into free
slots of its own frame at rsp+0x40.

PPSA15657 crashed in its stack walk at the title screen in about half of
its runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0134RWCyiyydJBbfKz8g9Bwe
2026-10-09 23:42:31 +01:00
Adrià 3692f56f09
Merge pull request #1249 from Raghav314/fix/relinker-guest-hash
fix(relinker): write a bucketed hash table for Linux guest modules
2026-10-10 00:37:47 +02:00
Dean b2714175b4
Merge pull request #2227 from rmz-24/test/relinker-gui-fixtures-without-wer
test(relinker): launch the GUI startup fixtures without Windows Error Reporting
2026-10-10 11:06:52 +13:00
Lexroid 0745d803e5 fix(relinker): fold case when matching needed module stems on Windows
Palworld's eboot needs EOSSDK-PS5-Shipping.debug_prx while the dump ships
prx/eossdk-ps5-shipping.prx. On Windows, compare module stems without
ASCII case, and let a name that already resolves to a guest image (exact
or case-folded filename, or soname) win over a stem alias.

Reported and diagnosed by @Rohan03x in #1830.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:29:45 +03:00
Lexroid 1a9ef2f25d fix(relinker): match needed module names that differ only in the extension
A title's executable can name a bundled module differently from the file it
ships: Dying Light 2 needs EOSSDK-PS5-Shipping.debug_prx and ships
EOSSDK-PS5-Shipping.prx. Needed names were matched by exact filename, so the
module was skipped without an error and start-up failed to load it. Renaming
the file does not help either: the title later loads the module at run time
by its shipped name (/app0//EOSSDK-PS5-Shipping.prx), and dlopen looks for
that name's .guest.prx (#1794).

When no file has the needed name, a module whose name differs only in its
.prx, .sprx or .debug_prx extension now satisfies it, in the module
directories or elsewhere under the input. The output keeps the shipped file
name, and the needed name is added as another name of that guest module.
Two such candidates for one needed name are ambiguous, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:24:07 +03:00
mugurc 703989b94b feat(relinker): write Mach-O output for macOS with --macos
The guest image reader and the module builder already produce a
platform-neutral GuestImage; --macos adds a third writer next to the ELF
and PE ones. The executable and every bundled module become x86-64 Mach-O
files (modules as dylibs in app0/sce_module) that run under Rosetta on
Apple silicon.

FreeBSD code reaches its thread pointer through %fs, which macOS cannot
set, so the writer rewrites each %fs access into a stub that reads the
image's thread pointer from a pthread key and allocates the TLS block on
a thread's first access. Dynamic TLS goes through the image's descriptor
instead of __tls_get_addr. Imports bind by NID to the prx libraries
beside the output, exports and TLS imports use the dynamic symbol names,
and the image's metadata lives in __APS5DATA,__meta.

--macos conflicts with --windows. The macOS runtime that consumes the
output (TLS allocation, libraries built for macOS) comes in separate
changes.
2026-10-10 00:13:39 +03:00
gunerky a58fe0cd72 test(relinker): isolate Windows diagnostic fixtures 2026-10-09 23:59:29 +03:00
abderahmane-ai bd750b5954 feat(relinker): write a registry for each converted bundled module
--registry only described the imports of the executable, so a title whose
own modules import system functions (PSN.prx, libc.prx and others) could
not be audited completely. With --registry the relinker now also writes
<output-stem>.<module>.registry.json for every converted guest module.

An entry is written for each relocation against an undefined symbol that
no other bundled module exports, the same test the module builder uses to
decide that a dependency is satisfied by a sibling. Entries carry nid,
library and targetOffset; the symbol name no longer has the # suffix by the
time the module is read, so the NID is the bare 11 characters. The
executable's registry is unchanged.

The test converts two modules where one is provided by its sibling, for
Linux and Windows output, covers the DT_RELA and DT_JMPREL tables, checks
that the same module imports the sibling's function once the sibling is
absent, and that nothing is written without --registry. Registered in
CTest as guest_registry.
2026-10-09 22:44:09 +02:00
Tomás Ortellado a213a26b47 fix(relinker): validate ELF identification before parsing 2026-10-09 10:44:31 -03:00
Tomás Ortellado a406ad4df7 fix(relinker): keep input checks compatible with module discovery 2026-10-09 10:38:17 -03:00
Tomás Ortellado ec5a2019b2 fix(relinker): reject truncated EH frame headers 2026-10-09 10:24:04 -03:00
Tomás Ortellado 682d6f62a3 fix(relinker): reject overflowing signed unwind LEB128 values 2026-10-09 10:05:26 -03:00
Tomás Ortellado dc9c75b576 fix(relinker): protect executable inputs from output overwrites 2026-10-09 09:50:16 -03:00
Andreas ba5256333d fix(relinker): root code addresses taken by RIP-relative LEA
Functions referenced only through a REX.W RIP-relative LEA (constructors,
callbacks, thread entries called indirectly) were not reached by code
analysis, so their guest TLS accesses stayed unpatched on Windows.

Add LEA targets inside executable code as roots, both in the instruction
walk and when following the control-flow graph of unreached code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 14:45:29 +02:00
Ramzi 115a8b050a test(relinker): launch the GUI startup fixtures without Windows Error Reporting
The GUI missing-symbol and missing-module fixtures were started with
ShellExecuteExW. A process the shell starts gets the default error mode,
so the status the entry stub raises reaches Windows Error Reporting as an
APPCRASH. Collecting each report took about 2 s, sometimes over 10 s,
and under a parallel ctest run it could pass the 30 s wait, failing
windows_import_modules with "ShellExecuteExW child did not exit" while
WerFault still held the fixture's files.

The fixtures now start through CreateProcessW with STARTF_USESTDHANDLES
and no standard handles, so the stub's diagnostic still has nowhere to
write, and with the test's error mode, which keeps the report away.
2026-10-09 13:24:01 +01:00
Eshaan Jaiswal 98b449f655 fix(relinker): allow empty relocation tables 2026-10-09 17:52:07 +05:30
Eshaan Jaiswal efe54ad6cb fix(relinker): validate relative relocation table bounds 2026-10-09 17:31:29 +05:30
eliasbruno124-dev 98c47df9e5 fix(relinker): discover required guest module identities 2026-10-09 13:53:48 +02:00
kali113 d5241d282f fix(relinker): give Linux guest modules a default non-executable stack 2026-10-09 13:45:37 +02:00
ctj01 1352b9b34d fix(relinker): write Linux PT_LOAD headers in ascending address order
The header-block PT_LOAD has the highest address but was the first
loadable entry in the table. Linux before 5.18 sizes the ET_DYN mapping
from the first and last PT_LOAD entries in table order, so the output
failed to exec with SIGSEGV. Write PT_PHDR and PT_INTERP first, sort the
kept PT_LOAD entries by address, and place the extra and header blocks
after them.
2026-10-09 06:27:23 -05:00
Dextroid17 84d851bf81 fix(relinker): bound the symbol table entry read 2026-10-09 06:54:33 -04:00
Dean 51f69aa218
Merge pull request #1586 from awake-devel/fix/relinker-keep-eh-frame-hdr
fix(relinker): keep PT_GNU_EH_FRAME in the relinked executable
2026-10-09 23:25:35 +13:00
Dean 2bf781eabb
Merge pull request #1856 from sarohy03/test/cli-args-coverage
test(relinker): cover CLI argument parsing
2026-10-09 22:41:25 +13:00
LeandroLP23 2bdb979e69 fix: clear the GCC warnings in ProfileOutput, fopen, Ajm batch jobs and the SHA-256 test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:37:04 +02:00
Dean b38abc0a69
Merge pull request #1774 from 011010/test/guest-intel-trampolines-e2e
test(relinker): execute the guest Intel trampolines end to end
2026-10-09 21:04:06 +13:00
Dean 7988ed27c9
Merge pull request #1510 from Kikoarl/fix/unique-test-temp-paths-cpu-topology-icon
test: give cpu topology and icon resource temp paths a random suffix
2026-10-09 21:03:51 +13:00
Zinebyte 2381e7fc64 fix(relinker): reject prefixed system-call instructions
Use the decoded opcode offset when checking forbidden system calls.
Add synthetic regressions for prefixed forms, immediate decoys, and the skip option.

AI-assisted: Codex. The submitting author is responsible for every changed line.
2026-10-08 20:34:40 -04:00
Scott Schuster 4bc84d6b44 fix(relinker): convert stack-guard and thread-pointer reads with an empty PT_TLS
A title built with -fstack-protector reads its guard from fs:0x28 even when
it has no thread-local data and its linker emits an empty PT_TLS. The
Windows TLS builder refused any guest TLS access in that case. The guard and
the thread pointer live in the thread control block, which the builder
already emits, so an empty PT_TLS now takes the normal path, where a
zero-sized TLS block still rejects every other displacement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 18:08:06 -05:00
sarohy f765b27cc0 test(relinker): cover CLI argument parsing
Cli::ParseArgs had no test coverage: its only sibling test
(AutorunExitTests) exercises the autorun launcher, not the parser.

Add cli_args_tests covering every option and its side effects, the
--rpath and --exclude-sce-module value consumption (including that the
following token is taken verbatim rather than re-parsed as a flag), the
unused-filter value and single-specification validation, the
--exclude-sce-module/--skip-sce-module conflict in both orders, the
order-independent --windows-diagnostics/--windows-gui requirement on
--windows, unknown-option and extra-positional rejection, and the usage
message when an input or output path is missing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-10-09 02:40:19 +05:00
eliasbruno124-dev ac2b0f5deb fix(relinker): rebase guest runpaths from their output directories 2026-10-08 22:31:03 +02:00
SilentOne 1b5d406a2f fix(relinker): add regression test for fall-through after zero padding and tighten reset condition 2026-10-09 01:02:14 +05:30
SilentOne f8031f7c9e fix(relinker): keep fall-through edge after trailing zero padding in StrictReachability 2026-10-09 00:58:57 +05:30
SilentOne e55209d274 perf(relinker): replace O(n²) zero-padding scan in StrictReachability
addGap and buildEdges each called isZeroPadding(address, end) at every
instruction boundary. isZeroPadding scanned from the current address to
the region end, so the total work for a region with N instructions and a
trailing-zero suffix of length Z was O(N*Z), quadratic in the worst case.

Replace with trailingZeroStart, which scans backwards from the region end
once to find the start of the trailing-zero suffix. The loop then stops at
that position, eliminating the per-instruction zero check entirely.
2026-10-09 00:58:57 +05:30
husari.orozco 4d13e99a0d test(relinker): execute the guest Intel trampolines end to end 2026-10-08 12:46:05 -06:00
emirplus 8c45db7136 fix(relinker): restore full rcx for 32-bit register alu
Restore full 64-bit RCX before 32-bit ALU operation so CMP and other non-writing/carry instructions do not zero-extend and clear upper 32 bits. Add test coverage for 32-bit CMP, ADC, and SBB.
2026-10-08 21:36:42 +03:00
emirplus b4cc6d26b9 feat(relinker): support Windows guest TLS reads by ALU register-address instructions
Recognize read-direction ALU forms (add, or, adc, sbb, and, sub, xor, cmp) that read from fs:[mem] where mem has a base or index register (such as 64 48 33 03, xor rax, fs:[rbx], in #217). The stub loads the TLS value through the computed address, performs the ALU operation, and preserves scratch registers and flags.

Extend test_tls_function_coverage with execution and stub coverage cases for register-addressed ALU operations, including rax, rcx, rbx and r13 destinations, wide and 32-bit forms, and verification of register and flag preservation.

Refs #217

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 18:39:24 +03:00
Adrià 9e2ffe0da4
Merge pull request #1457 from drk1rd/fix/relinker-ud1-trap
fix(relinker): decode UD1 as a trap
2026-10-08 16:17:06 +02:00
Adrià 94d03f29fa
Merge pull request #1454 from mrk1987/fix/windows-internal-guest-libc
fix(relinker): resolve internal libc imports from guest libc
2026-10-08 16:07:33 +02:00
clem-gb d16cac0ab2 fix(relinker): keep PT_GNU_EH_FRAME in the relinked executable
The segment filter dropped every header in the PT_LOOS..PT_HIOS range,
which includes PT_GNU_EH_FRAME. The unwinders find the executable's
unwind tables through that header, so no C++ exception thrown in the
main executable could be caught on Linux.

The header is kept only when the output program header table still fits
in the input's table; otherwise it is dropped as before, with a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
2026-10-08 15:47:39 +02:00
Adrià 63c57d2222
Merge pull request #1432 from ToyuAU/build/standalone-relinker
build(relinker): add a dependency-free conversion build mode
2026-10-08 15:43:51 +02:00
Adrià 033a46360d
Merge pull request #1424 from muhzain05/fix/relinker-jmprel-bounds
fix(relinker): bound the jump relocation table range
2026-10-08 15:39:32 +02:00
Adrià fd5f63a2d0
Merge pull request #1393 from xsvm/fix/relinker-rewriter-reference-sites
fix(relinker): classify rewrite reference sites with the instruction decoder
2026-10-08 15:03:48 +02:00
Adrià 2a906716f9
Merge pull request #1403 from overlordxrz-source/refactor/relinker-read-needed-once
refactor(relinker): read the executable's DT_NEEDED entries in one place
2026-10-08 15:00:52 +02:00
Arvind Frøiland 0858f01429 test(relinker): check decoder lengths against an LLVM-generated table
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 21:09:18 +09:00
muhzain05 19f2fcf059 fix(relinker): bound the jump relocation table range
DT_JMPREL and DT_PLTRELSZ were never range-checked against the input
file. With DT_OS_JMPREL the offset is used raw, so an offset outside the
image reached BuildDynamicSection and CompactPlt. When DT_PLTRELSZ is
zero the per-entry loops never run, so nothing rejected the table and
the relink produced an output executable.

Validate the declared range with the subtraction-based check already
used for DT_STRTAB and DT_STRSZ, next to it and before the table is
read.
2026-10-08 05:25:08 -06:00
Gjon Gojcevic 90dcd6256c fix(relinker): tolerate unwind ranges that split an instruction
A static branch into a skipped function tail is accepted when an
instruction decodes there within its executable segment, so a range that
ends inside an instruction no longer stops code analysis.

The Windows TLS rewriter skips a non-FS segment-prefixed instruction that
starts inside an earlier collected instruction: it is an alternative
decoding from a range that begins mid-instruction, not a TLS access.
2026-10-08 13:20:32 +02:00
Dean Galvin 2096c66a91 revert: undo #1156's bundled libc lifecycle suppression
Since #1156 a title's bundled sce_module/libc.prx is loaded for its
exports but its init is suppressed, while titles still call its malloc,
which then returns NULL (#1500). On Linux, titles that bundle libc crash
at launch: one segfaults within 0.2 s, another stops with bad_alloc.

This reverts commit 2d6aff7a1e, reversing
changes made to e82e03f11e.
2026-10-08 23:49:41 +13:00
Kikoarl 319ac9ba78 test: give cpu topology and icon resource temp paths a random suffix 2026-10-08 12:40:39 +02:00
xsvm 22ebf5e608 fix(relinker): classify rewrite reference sites with the instruction decoder
ClassifyInstruction assumed a ModRM byte right after every opcode that
was not a near branch. A length-changing rewrite therefore adjusted
immediates such as MOVABS imm64 that looked like a RIP-relative ModRM,
and missed RIP-relative operands of VEX and 0F 38 / 0F 3A instructions
and the rel8 targets of LOOP and JRCXZ. Take the RIP-relative
displacement and branch target from DecodeInstruction instead.
2026-10-08 18:20:14 +08:00
Suryansh Prajapati 7a3ec9f015 fix(relinker): decode UD1 as a trap
UD1 (0F B9 /r) always raises #UD, like UD2, but DecodeInstruction
reported it as sequential. Reachability analysis then followed the
bytes after it, so an import reachable only through that fallthrough
was kept by the strict unused NID filter. UD1 keeps its ModRM, so a
RIP-relative operand is still reported.
2026-10-08 15:26:54 +05:30
Adrià 73ac9ef7f4
Merge pull request #1218 from hashaam1217/feat/relinker-rip-relative-stubs
feat(relinker): relocate RIP-relative operands into --to-intel stubs
2026-10-08 11:40:17 +02:00
Dean 1bd8f07ccd
Merge pull request #1317 from Dextroid17/fix/name-both-self-container-magics
fix(relinker): name the second SELF container magic as a SELF input
2026-10-08 22:36:28 +13:00
Dean 9e5ade70fb
Merge pull request #1381 from overlordxrz-source/fix/relinker-decoder-0f-no-modrm
fix(relinker): decode 0F A8-AA without a ModRM and MOV CR/DR without a memory operand
2026-10-08 22:35:44 +13:00
Dean a753d0de45
Merge pull request #1303 from overlordxrz-source/fix/relinker-evex-grp3-immediate
fix(relinker): do not add the F6/F7 TEST immediate to EVEX instructions
2026-10-08 22:35:39 +13:00
Adrià 0802d02713
Merge pull request #1242 from hashaam1217/fix/program-header-entry-size
fix(relinker): reject a program header entry size other than 56 bytes
2026-10-08 11:28:29 +02:00
Adrià 296d68a31d
Merge pull request #1238 from hashaam1217/fix/windows-overlapping-load-segments
fix(relinker): reject overlapping PT_LOAD segments before sizing the Windows image
2026-10-08 11:14:58 +02:00
Adrià 71a0eab968
Merge pull request #1233 from hashaam1217/feat/windows-tls-register-loads
feat(relinker): load Windows guest TLS values through register addresses
2026-10-08 11:11:10 +02:00
Hashaam Zafar a571a7f100 feat(relinker): relocate RIP-relative operands into --to-intel stubs
SHA-1 and SHA-256 instructions with a [rip+disp32] operand, and
instructions with one that a short site absorbs, now move into the
stub. The stub records each displacement as a relocation relative to
the site, and the Linux, guest and Windows placements resolve it once
the stub address is known. Indirect branches through [rip+disp32]
still fail the relink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 11:10:38 +02:00
Adrià 2d6aff7a1e
Merge pull request #1156 from ahir061/fix/linux-bundled-libc-lifecycle
fix(relinker): suppress duplicate system library lifecycle
2026-10-08 11:03:20 +02:00
Adrià 0703d818d0
Merge pull request #1194 from ASVLCII/fix/relinker-input-validation-20261007
fix(relinker): reject incomplete RELA entries
2026-10-08 10:49:19 +02:00
Adrià 2959dc5318
Merge pull request #1168 from oguzhanozfe/fix/decoder-moffs-length
fix(relinker): decode the 64-bit address of MOV moffs instructions
2026-10-08 10:39:59 +02:00
Adrià Franch 402cd1545e test(relinker): give the lifecycle fixture a non-executable stack header
glibc 2.41+ refuses to dlopen a module without PT_GNU_STACK, so the native
part of guest_lifecycle_ownership failed on current distributions.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-08 10:27:52 +02:00
Adrià 8388121a4f
Merge pull request #1153 from ebarr24/codex/windows-gui-error-status
fix(relinker): preserve GUI startup failure status without stderr
2026-10-08 10:26:56 +02:00
Adrià 17440abe24
Merge pull request #1165 from oguzhanozfe/fix/linux-dynstr-runpath-size
fix(relinker): include the run path in the Linux DT_STRSZ
2026-10-08 10:25:19 +02:00
Adrià 61896dea23
Merge pull request #1163 from oguzhanozfe/fix/decoder-rexw-immediate-size
fix(relinker): let REX.W override 0x66 when sizing decoder immediates
2026-10-08 10:23:35 +02:00
Ahir Barman Maji b12022bb4e test(relinker): fix Windows lifecycle fixture build 2026-10-08 10:22:40 +02:00
Ahir Barman Maji 9517cc33f8 fix(relinker): suppress duplicate system library lifecycle 2026-10-08 10:22:40 +02:00
Adrià f51eeff059
Merge pull request #1117 from TideOPL/fix/relinker-tls-unreached-code
fix(relinker): find Windows guest TLS accesses in code no root reaches
2026-10-08 09:54:40 +02:00
mrk1987 2050d84595 test(relinker): isolate guest libc resolution coverage 2026-10-08 09:43:52 +02:00
mrk1987 b64bb679cc fix(relinker): resolve internal libc imports from guest libc 2026-10-08 09:23:13 +02:00
ToyuAU 2d59fffdb7 build(relinker): add a dependency-free conversion build mode 2026-10-08 18:21:30 +11:00
Adrià 66b8abd8e6
Merge pull request #1101 from eliasbruno124-dev/fix/relinker-windows-guest-filenames
fix(relinker): resolve Windows guest filename casing
2026-10-08 08:43:35 +02:00