Commit Graph

261 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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