Commit Graph
376 Commits
Author SHA1 Message Date
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
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
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
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
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
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
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
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
Dean 2f5013ec64 Merge pull request #10658 from roboterspinne/fix/relinker-reject-copy-relocations
fix(relinker): reject R_X86_64_COPY relocations
2026-10-25 21:50:12 +13:00
Matheus Herberts 03f382934e fix(relinker): align ELF64 section header tables 2026-10-25 01:57:10 -03:00
Dean c4446bbb09 Merge pull request #9332 from rooklz/fix/windows-console-base
fix(relinker): prefer 0x400000 for Windows executables
2026-10-25 12:57:28 +13:00
Dean 38d463a6cf Merge pull request #10157 from Usama171/fix/relinker-preloaded-crt-log
fix(relinker): rebind a preloaded CRT's standard streams to the startup log
2026-10-25 12:45:29 +13:00
roboterspinne 7424949b8b fix(relinker): refuse branches into trapped guest GS instructions on Windows
Windows output replaced each guest GS memory instruction with UD2 and
NOP fill without checking the decoded direct branch targets, so a branch
past the first byte of such an instruction was converted and landed in
the second UD2 byte or the NOP fill. A branch target strictly inside a
trapped GS instruction is now refused with "Branch enters a guest GS
instruction", the rule macOS applies since #7706 and this builder
already applies to its FS rewrites. The branch targets are sorted before
the trap loop, which runs before the PT_TLS early returns, so images
without PT_TLS are covered; guest modules go through the same builder. A
branch to the first byte still converts and reaches the UD2.
2026-10-24 20:18:50 +02:00
roboterspinne 46f03a9ae1 Merge remote-tracking branch 'upstream/main' into fix/relinker-linux-load-bounds 2026-10-24 18:03:49 +02:00
roboterspinne 9bf8860f87 fix(relinker): drop the COPY width from the Linux load bounds check
RelocationWidth took the width of a COPY relocation from the output
symbol table, where every import has st_size 0, so the width was
always one byte and the two copy-* boundary cases passed for that
reason alone. #10658 rejects R_X86_64_COPY in validation, so the type
no longer reaches this check; until it merges, COPY takes the 8-byte
default like every other type. The three copy-* cases go with it.
2026-10-24 17:44:53 +02:00
muausandClaude Fable 5 eeaf7b03b5 fix(relinker): open the startup log for append so stub writes cannot clobber CRT output
Co-Authored-By: Claude Fable 5 <[email protected]>
2026-10-24 20:30:27 +05:00
roboterspinne 7f58c7a407 fix(relinker): reject R_X86_64_COPY relocations
The Linux output writes every import symbol with st_size 0 and copies
a COPY relocation into the output unchanged, so ld.so copies
MIN(st_size of the definition, 0) = 0 bytes and the variable stays
zero. Windows and macOS already rejected the type in the relocation
builder. ValidationPolicy now rejects type 5 before any target code,
so every target reports the same error, and the COPY case of the
fixed-base rebasing, which validation makes unreachable, is gone.
2026-10-24 17:16:23 +02:00
Rookie 39df8e081c fix(relinker): prefer 0x400000 for Windows executables 2026-10-24 15:58:35 +01:00
Savvanis SpyrosandClaude Opus 5.5 66ccd46909 Merge remote-tracking branch 'origin/main' into feat/log-deferred-imported-modules
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 16:35:28 +03:00
roboterspinne 5362dcaaf0 fix(relinker): validate every entry of the Linux run path
LinuxElfPatcher wrote --rpath into DT_RUNPATH unchanged, so an empty
entry (an empty value, a leading or trailing colon, or a double colon)
reached the output, where glibc searches the working directory for it,
while the macOS and Windows outputs reject empty run paths. The guest
module rule that each entry is absolute or begins with $ORIGIN only
looked at the start of the whole value, so "$ORIGIN/libs:" or
"$ORIGIN:relative/libs" passed. The Linux patcher now rejects an empty
entry with the message the macOS patcher uses, the guest rule checks
every colon-separated entry, and USAGE.md says so.
2026-10-24 12:16:08 +00:00
Adrià ac28b89bd9 Merge pull request #7706 from Destroyers212x/fix/macos-gs-trap-branch-target
fix(relinker): refuse branches into trapped guest GS instructions on macOS
2026-10-24 12:54:07 +02:00
Adrià 50aa1798e7 Merge pull request #7741 from MarcZX10/codex/macos-main-thread-mxcsr
fix(relinker): initialize MXCSR in macOS guest entry
2026-10-24 12:51:40 +02:00
roboterspinne e5697e7f55 fix(relinker): reject overlapping PT_LOAD segments in Linux output
The Linux patcher sorted the PT_LOAD segments by address but never
checked that their memory ranges are disjoint, while the Windows and
macOS images and guest modules reject overlapping loads. The Linux
output kept both headers, the kernel mapped the later segment over the
earlier one, and the program crashed at start. Adjacent loads whose
ranges overlap now fail with "Overlapping PT_LOAD memory ranges", the
message the other targets use.
2026-10-24 10:03:49 +00:00
Dean 34a41ada16 Merge pull request #10341 from Filip722/submit/phnum-20261023
fix(relinker): reject unsupported extended program header counts
2026-10-24 21:08:06 +13:00
Dean a8e32e0017 Merge pull request #9518 from harisibrar1/fix/relinker-tests-nonascii-paths
test(relinker): find the Windows test executables with GetModuleFileNameW
2026-10-24 20:46:17 +13:00