Commit Graph
393 Commits
Author SHA1 Message Date
Dean d84a43404d Merge pull request #11959 from roboterspinne/fix/relinker-linux-executable-ident-padding
fix(relinker): zero the e_ident padding of the Linux executable
2026-10-28 22:33:39 +13:00
Dean bd6a4096ff Merge pull request #11958 from roboterspinne/fix/relinker-windows-image-size-limit
fix(relinker): reject Windows images larger than the loader maps
2026-10-28 22:33:22 +13:00
Adrià 46031052fc Merge pull request #11381 from roboterspinne/fix/relinker-executable-export-attributes
fix(relinker): validate executable export names and attributes like guest modules
2026-10-28 06:05:18 +01:00
Adrià 9af563f33d Merge pull request #11284 from iamthehimansh/split/macos-game-start
fix(relinker): reserve space after the Mach-O load commands for the code signature
2026-10-27 19:43:38 +01:00
Adrià 254240c747 Merge pull request #11045 from roboterspinne/fix/relinker-macos-fixups-writable
fix(relinker): reject macOS fixups outside writable segments
2026-10-27 18:29:51 +01:00
Adrià f2f759ae31 Merge pull request #10712 from roboterspinne/fix/relinker-macos-reject-lazy-binding
fix(relinker): reject --lazy-binding for macOS output
2026-10-27 15:35:26 +01:00
roboterspinne c18ee35e52 fix(relinker): reject Windows images larger than the loader maps
The Windows writer accepted any image up to the 2 GiB RVA bound, so an
image with a SizeOfImage above 0x77000000 converted with exit 0 and then
failed to start with ERROR_BAD_EXE_FORMAT (193). WindowsPeWriter::Write
now refuses such an image, matching the loader's SizeOfImage >
MM_SIZE_OF_LARGEST_IMAGE (0x77000000) test, which applies to executables
and to bundled modules alike. Images with a SizeOfImage of at most
0x77000000 are written unchanged.
2026-10-27 14:16:56 +01:00
roboterspinne beb46de57d fix(relinker): zero the e_ident padding of the Linux executable
LinuxElfPatcher::Patch zeroed only e_ident bytes 7 and 8 of the output
executable, and ElfReader checks only bytes 0 to 6, so nonzero EI_PAD
bytes 9 to 15 of the input reached the output in every Linux mode. The
gABI reserves EI_PAD as zero, and glibc's open_verify refuses an object
with nonzero padding when ld.so maps the program itself, as under ldd
or an explicit ld-linux-x86-64.so.2 invocation. The patcher now zeroes
bytes 7 to 15, the rule that #11582 applies to guest modules. Only
reserved bytes change, and a direct exec is unaffected either way.
2026-10-27 14:03:02 +01:00
Dean b4445c5b16 Merge pull request #8118 from RockENZO/codex/macos-guest-weak-exports
fix(relinker): preserve weak guest exports on macOS
2026-10-27 21:04:56 +13:00
roboterspinne e5297264e3 fix(relinker): reject macOS fixups outside writable segments
The macOS image writer emitted dyld rebase and bind opcodes for any
target inside a segment, so an R_X86_64_RELATIVE into an R-X PT_LOAD
became a rebase into a read-execute segment. dyld-1378 refuses fixups
in segments without write access (enforceFixupsInWritableSegments), so
Locate now throws when the target segment lacks VM_PROT_WRITE. Such
inputs now fail the macOS conversion instead of writing an output that
dyld would not load.
2026-10-27 08:18:50 +01:00
Adrià bf83eae375 Merge pull request #10947 from roboterspinne/fix/relinker-windows-tls-template-imports
fix(relinker): reject Windows executable imports bound into the TLS template
2026-10-27 07:59:13 +01:00
Adrià 7f289b53df Merge pull request #10946 from roboterspinne/fix/relinker-macos-tls-export-at-block-end
fix(relinker): accept a zero-size TLS export at the end of the macOS TLS block
2026-10-27 07:59:08 +01:00
Dean f52fcfd749 Merge pull request #11422 from Mherberts/codex/fix-mingw-ucrt-fixture-build
fix(build): link the UCRT test fixture without -mcrtdll
2026-10-27 18:37:16 +13:00
Dean a8bc4474c4 Merge pull request #11090 from roboterspinne/fix/relinker-windows-gs-trap-entry-roots
fix(relinker): refuse GS traps that overwrite a code entry point in Windows output
2026-10-27 18:32:02 +13:00
roboterspinne 3123f92e7b fix(relinker): reject --lazy-binding for macOS output
MacOsMachOPatcher::Patch discarded its lazyBinding argument, so a
module-free `--macos --lazy-binding` conversion exited 0 and wrote the
same eagerly bound Mach-O as a run without the flag. The Mach-O writer
puts every import in the LC_DYLD_INFO_ONLY bind stream and leaves the
lazy_bind stream empty, with no __la_symbol_ptr or stub helper, so the
macOS target cannot honour the flag. The patcher now throws "macOS
target does not support --lazy-binding", in the form of its
--windows-diagnostics check, so such a conversion exits 2 and writes no
output. Conversions with bundled modules were already refused by the
guest module builder.
2026-10-27 05:59:10 +01:00
Dean e48379c7af Merge pull request #11299 from p3n1cillin/claude/relinker-duplicate-relocations
fix(relinker): accept an identical duplicate relocation in Windows executables
2026-10-27 11:07:09 +13:00
Dean 5566e1e097 Merge pull request #10971 from roboterspinne/fix/relinker-linux-nonzero-import-addends
fix(relinker): reject nonzero GLOB_DAT and JUMP_SLOT addends in Linux output
2026-10-27 10:58:17 +13:00
roboterspinne 66f6fa3a32 Merge remote-tracking branch 'upstream/main' into fix/relinker-windows-gs-trap-entry-roots 2026-10-26 19:58:04 +01:00
roboterspinne ca8e16751c Merge remote-tracking branch 'upstream/main' into fix/relinker-windows-tls-template-imports 2026-10-26 19:38:21 +01:00
Adrià aa04180e37 Merge pull request #10391 from roboterspinne/fix/relinker-macos-relocation-message
fix(relinker): drop Windows from errors the macOS target also reports
2026-10-26 19:10:01 +01:00
Dean ae17955d2c Merge pull request #10945 from roboterspinne/fix/relinker-windows-lazy-stub-alignment
fix(relinker): align the stack in Windows lazy import failure stubs
2026-10-27 05:53:57 +13:00
Dean 50ef454b5a Merge pull request #11082 from roboterspinne/fix/relinker-windows-fixed-base-user-limit
fix(relinker): keep fixed Windows images below the highest user address
2026-10-27 05:40:54 +13:00
Dean b73c5659a5 Merge pull request #11000 from plexerPK/fix/windows-empty-tls-file-offset
fix(relinker): accept empty TLS images beyond EOF on Windows
2026-10-27 05:35:55 +13:00
Matheus Herberts ec3cc6b602 fix(build): link the UCRT test fixture without -mcrtdll 2026-10-26 12:29:30 -03:00
p3nicillinandClaude Opus 5.5 9673868d5f fix(relinker): accept an identical duplicate relocation in Windows executables
A RELA entry repeated with the same target, type and addend writes the
same value twice, so applying it once is equivalent. The Windows
relocation builder refused it as overlapping and code analysis as an
invalid relative relocation; the Linux output already passed it through.
Forever Launcher's game-child.bin (PPSA99030) repeats one RELATIVE entry
at 0x2df70 and could not be converted. Distinct entries at one target
are still refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 11:38:33 +00:00
roboterspinne a9d053f4be Merge remote-tracking branch 'upstream/main' into fix/relinker-executable-export-attributes 2026-10-26 12:14:42 +01:00
Himansh Raj 04e66b6d8d Merge remote-tracking branch 'origin/main' into split/macos-game-start
# Conflicts:
#	core/relinker/elfpatcher/src/macos/MacOsImage.cpp
2026-10-26 16:33:43 +05:30
Adrià cbf76e7a6e Merge pull request #9408 from rursache/feat/macos-trace-imports
feat(relinker): trace function imports on macOS
2026-10-26 11:27:51 +01:00
roboterspinne 12ad27b10e Merge remote-tracking branch 'upstream/main' into fix/relinker-executable-export-attributes 2026-10-26 11:10:49 +01:00
Dean ec9256a042 Merge pull request #10852 from Mherberts/codex/fix-elf-section-table-alignment
fix(relinker): align ELF64 section header tables
2026-10-26 22:03:40 +13:00
Himansh Raj 11c88cdfd5 Merge remote-tracking branch 'origin/main' into split/macos-game-start 2026-10-26 14:28:17 +05:30
roboterspinne de709f9e02 Merge remote-tracking branch 'upstream/main' into fix/relinker-executable-export-attributes 2026-10-26 09:16:25 +01:00
Dean e3657de5e4 Merge pull request #10402 from roboterspinne/fix/relinker-linux-load-bounds
fix(relinker): require the Linux entry, relocation offsets and DT_PLTGOT in PT_LOAD memory
2026-10-26 16:30:06 +13:00
Dean dbf4f6aa3f Merge pull request #10607 from roboterspinne/fix/relinker-linux-run-path
fix(relinker): validate every entry of the Linux run path
2026-10-26 14:26:39 +13:00
Himansh Raj 5c134a8fee feat(macos): start relinked games
A relinked macOS game stops in dyld before any guest code runs: libc does not
export the guest entry and TLS functions the macOS relinker's executable
imports, and AppKit only allows windows on the process main thread.

- libc: add Aps5StartGuest, which the relinker's entry stub calls with the
  guest entry and the FreeBSD initial block. It runs the guest on a second
  thread and keeps the main thread serving the main dispatch queue.
- libc: add the guest TLS functions the relinked code imports
  (Aps5GuestTlsRegister, Aps5GuestTlsAllocateBlock, Aps5GuestTlsGetAddr,
  Aps5GuestTlsUseXsave).
- libc: MainThread.hpp's RunOnMainThread runs a call on the main thread,
  waits for it and rethrows its exception. It runs on the calling thread
  when the main thread does not serve the main queue, as in the tests.
- libSceVideoOut: create, resize, retitle and destroy the window, initialise
  SDL video, create the Vulkan surface and pump events through
  RunOnMainThread on macOS.
- libc: find the process parameters through dl_iterate_phdr on macOS too,
  and link CoreFoundation.
- relinker: leave 0x400 bytes after the Mach-O load commands, like ld's
  -headerpad, so codesign's LC_CODE_SIGNATURE no longer overwrites the
  entry stub.

Linux and Windows compile the same libc and libSceVideoOut code as before.
2026-10-26 05:19:42 +05:30
Dean 190aaa23bb Merge pull request #10564 from roboterspinne/fix/relinker-linux-overlapping-loads
fix(relinker): reject overlapping PT_LOAD segments in Linux output
2026-10-26 11:08:08 +13:00
Matheus Herberts d15fe22e98 test(relinker): require the exact section string table size 2026-10-25 14:44:13 -03:00
Adrià FranchandClaude Sonnet 5.5 44ea38fc23 fix(relinker): align the macOS import trace stack and trace only executable segments
Save r12 in the entry walk so TraceImport_nid_no_patch is called with an aligned stack, record only executable Mach-O segments in the module map, and make the test hook check the alignment.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-25 18:37:39 +01:00
Radu Ursache 66ca5c0442 feat(relinker): trace function imports on macOS
Walk each macOS function import before the guest entry and pass it through TraceImport_nid_no_patch, as Linux and Windows already do. An x86-64 libc build records the call and prints it on SIGABRT.
2026-10-25 18:37:23 +01:00
roboterspinne a5327c73b9 fix(relinker): keep fixed Windows images below the highest user address
With --windows-fixed-base the PE writer bounded the end of a fixed
image by 0x7fffffffffff, so an image ending in the top 64 KiB relinked
with exit code 0 and then failed to load with
STATUS_CONFLICTING_ADDRESSES. On x64 Windows 8.1 and later the highest
user address is 0x7ffffffeffff (lpMaximumApplicationAddress), so the
exclusive end of a fixed image must not exceed 0x7fffffff0000. Such
images are now rejected with the existing user address space error;
every image that ends at or below the limit is written unchanged.
2026-10-25 15:35:55 +01:00
roboterspinne 33b48ba39f fix(relinker): refuse GS traps that overwrite a code entry point in Windows output
--windows replaced a guest GS memory instruction with UD2 and NOPs even
when a symbol, a relocation pointer, a lea target or a DT_INIT_ARRAY
entry started inside it, so that entry ran padding instead of the
original code. A trapped instruction that holds a collector entry root
after its first byte now fails with "GS trap would overwrite an
executable entry point" at the root's file offset, the rule that TLS
rewrites already follow. The branch check runs first, so a relative
branch into the instruction keeps its message, and outputs without such
a root are unchanged.
2026-10-25 15:34:15 +01:00
roboterspinne 6247fb1dd6 fix(relinker): validate executable export names and attributes like guest modules
The executable export loop accepted names that are empty after
stripping '#', IFUNC, FILE, COMMON and SECTION types, bindings above
STB_WEAK, st_other bits above the visibility, and same-name exports
that differ, and Linux copied them into .dynsym. It now rejects them
before the location checks with the rule GuestImageReader applies to
non-local guest symbols, while identical aliases stay accepted. Every
target reports the same line at the symbol entry offset, and the macOS
attribute and empty-name checks, now unreachable, are removed.
2026-10-25 15:07:01 +01:00
plexerPK 4f7f3318fa fix(relinker): accept empty TLS images beyond EOF on Windows 2026-10-25 14:54:53 +01:00
roboterspinne 2ac9311745 fix(relinker): reject nonzero GLOB_DAT and JUMP_SLOT addends in Linux output
The Linux output copied a nonzero r_addend of GLOB_DAT and JUMP_SLOT
relocations unchanged into DT_RELA and DT_JMPREL, while the Windows,
macOS and guest module paths refuse it. The x86-64 psABI computes both
types as S, but glibc before f8587a61892c applies S+A when binding
eagerly, so the result depended on the host glibc and, for JUMP_SLOT,
on the binding mode. The Linux patcher now refuses such an entry in all
three Linux modes with the Windows message and the unrebased r_offset.
Entries with a zero addend are emitted as before.
2026-10-25 12:32:48 +01:00
roboterspinne a54a939924 fix(relinker): reject Windows executable imports bound into the TLS template
Windows output accepted an executable import relocation whose target
overlaps the PT_TLS initialization image, and every guest thread read 0
there because the .gtls template is copied before the entry stub binds
the import. In ELF, ld.so relocates the image before copying it into a
thread's TLS block. The PE patcher now refuses such a relocation after
the relocation pass, as the Windows guest module writer already does,
and reports its ELF target address. Linux and macOS outputs are
unchanged, and the gap is recorded in docs/dev/debt/relinker.md.
2026-10-25 12:10:24 +01:00
roboterspinne 81f6b28ae5 fix(relinker): accept a zero-size TLS export at the end of the macOS TLS block
WriteMacOsImage rejected a TLS export whose value equals PT_TLS
p_memsz with "Guest TLS export is outside the TLS block", although
Linux and Windows output convert the same guest module or executable.
The bound is now the one GuestImageReader and MacOsMachOPatcher already
apply before this point: value <= p_memsz and size <= p_memsz - value,
so the deleted check could only reject that boundary case. Such an
export now gets the __APS5DATA entry (TLS descriptor, p_memsz) in
macOS output, also at offset 0 of an empty PT_TLS that code accesses.
2026-10-25 12:10:23 +01:00
roboterspinne 6a66f2a4b2 fix(relinker): align the stack in Windows lazy import failure stubs
With --lazy-binding, guest code calls the stub of an unresolved Windows
import under the SysV ABI, so the stub starts at RSP = 8 mod 16, and it
called lstrlenA, GetStdHandle, WriteFile and RaiseException without
adjusting RSP. RaiseException then faulted with an access violation
instead of raising STATUS_ENTRYPOINT_NOT_FOUND. The Win64 calling
convention requires a 16-byte aligned RSP and 32 bytes of shadow space
at every call. Each stub now starts with and rsp,-16; sub rsp,0x40, so
after the FAIL line the program exits with 0xC0000139.
2026-10-25 12:10:23 +01:00
roboterspinne 4930ee9e55 Merge remote-tracking branch 'upstream/main' into fix/relinker-linux-load-bounds 2026-10-25 11:47:53 +01:00
roboterspinne 66473085c2 fix(relinker): accept a Linux entry in a PT_LOAD without flags
The Linux output maps a PT_LOAD whose p_flags is 0 as RWX, so the
e_entry check now accepts an entry inside such a segment instead of
rejecting it. A new test case relinks that input in both Linux modes
and checks that the output maps the entry's segment RWX. The
R_X86_64_NONE skip in the relocation offset loop is removed, together
with its none-outside case, because extractRela drops NONE before the
relocation tables are rebuilt.
2026-10-25 11:47:52 +01:00
Dean 28d2a461d2 Merge pull request #10710 from roboterspinne/fix/relinker-windows-gs-branch-targets
fix(relinker): refuse branches into trapped guest GS instructions on Windows
2026-10-25 21:50:25 +13:00