Skip to content

fix(relinker): load Windows executables at a fixed low base - #4237

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-fixed-base-3043
Oct 14, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-fixed-base-3043

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Writes converted Windows executables without DYNAMIC_BASE, so Windows can load the main image at its fixed low base inside the console's 40-bit address window. Guest modules keep DYNAMIC_BASE. The integration test checks both characteristics and confirms the executable fixture has relocations. This addresses the mspace buffer rejection described in #3043 for PRAGMATA.

Tested

Checklist

  • Rebased onto current main; no matching open fix PR
  • Main executables disable dynamic-base relocation; guest modules retain it
  • One topic: fixed-base loading for converted main executables
  • Depends on: none
  • AI-assisted: yes

Limitations

The runtime evidence is from Windows 10 and has not been verified on console hardware or other Windows versions.

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Carried the current-main fix linked in #3043 with the source author preserved. Local conventions and diff checks pass; the branch reports 124 Linux relinker tests and Windows 10 runtime evidence. The PR explicitly records that Windows 11 build 26200 reserves the image range and remains unverified, so this is not claimed as a Windows 11 fix.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Please cut the TechnicalDebt entry to one sentence and drop the Windows 11 build 26200 claim, there and in Limitations. #1955 was RELOCS_STRIPPED, fixed by #1958, and two 26200 machines in that issue load at 0x140000000.

@MarcZX10
MarcZX10 force-pushed the codex/carry-fixed-base-3043 branch from ceaab5f to dbb37ec Compare October 12, 2026 17:17
@MarcZX10
MarcZX10 force-pushed the codex/carry-fixed-base-3043 branch from dbb37ec to 7b7457f Compare October 12, 2026 18:36
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@MarcZX10
MarcZX10 force-pushed the codex/carry-fixed-base-3043 branch from 7b7457f to faba550 Compare October 12, 2026 18:48
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 12, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor Author

Thanks for the correction. The #1955 failure was caused by RELOCS_STRIPPED and was fixed by #1958; I do not have evidence that Windows 11 build 26200 fails to load at the standard base. I will remove that claim from Limitations and shorten the TechnicalDebt entry, then rebase the PR onto current main.

@MarcZX10
MarcZX10 force-pushed the codex/carry-fixed-base-3043 branch from faba550 to 2805df4 Compare October 13, 2026 07:35
@MarcZX10

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and updated the debt entry to one sentence. I removed the Windows 11 build 26200 assertion from both the entry and the limitations section; #1955 was RELOCS_STRIPPED, and its later runs do not support that claim. The PR description now distinguishes the Windows 10 evidence reported in #3043 from testing this rebased head, which has not been rerun locally.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 13, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased this onto current main locally; it builds, but two tests fail:

  • windows_fixed_base: test_windows_fixed_base.py:73 asserts the default output keeps DYNAMIC_BASE (bool(characteristics & 0x40) == (base is None)). #319fa5779 added --windows-fixed-base as the opt-in way to get a non-ASLR main image, and docs/user/USAGE.md says that without it placement is unchanged. This PR changes that default.
  • windows_address_space (this PR's own test): the guest module artifact comes out with DllCharacteristics 0x100, not 0x140. The module goes through the same WindowsPeWriter::Write, so on main's writer the flag can't be dropped for the executable alone; the PR needs to pass the distinction in (executable vs module).

Please rework this on top of main: either document why --windows-fixed-base 0x140000000 is not enough for #3043 (the default image base is already 0x140000000, below 1 TiB), or make the executable/module distinction explicit in WindowsPeWriter::Write, update windows_fixed_base and USAGE.md for the new default, and keep the module case in your test. The debt line should then also reflect the option that exists on main.

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Follow-up to the default-image-base review: the Windows test recorded in issue #3043 using the existing fixed-base option removes the reported allocation crash and reaches the later sceVideoOutGetOutputStatusWithVrr stop. That is evidence the current option handles the reported title case; I do not have evidence that all converted executables should lose DYNAMIC_BASE by default. I agree the current PR needs a distinct use case or a narrower scope before its default change is justified. I have not changed the branch.

@MarcZX10
MarcZX10 force-pushed the codex/carry-fixed-base-3043 branch from 2805df4 to e5c782c Compare October 13, 2026 19:13
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor Author

Thanks for flagging the mismatch. I reworked the rebased writer so dynamicBase is explicit: main executables pass false, while guest modules use the default true and retain relocations. The rebased windows_fixed_base test now asserts the default executable has no DYNAMIC_BASE, while windows_address_space asserts executable 0x100 and module 0x140. Local Linux relinker/windows CTest passed 13/13; the updated Ubuntu CI check also passes. macOS and Windows checks are still running. The current PR body includes the distinction and limitation of the runtime evidence. Could you please re-review once the remaining CI jobs finish?

@MarcZX10

Copy link
Copy Markdown
Contributor Author

I found your later follow-up (comment 6151045069) about the existing --windows-fixed-base option. The current PR still lacks evidence that changing the default is necessary for PRAGMATA: #3043 reports the existing option reaches the next stop. The passing tests establish the executable/module characteristics and address-space behavior, but not a user-visible benefit over opting in. Could you clarify a separate use case where default ASLR prevents loading or causes the low-base requirement to fail? Until then I agree this point remains open; I will not treat green CI as resolving it.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5598 docs/dev/debt/relinker.md L6

@xXPBSXx

xXPBSXx commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Title evidence and Windows test for this PR (Windows 10 19045, MinGW-w64 GCC 15.2.0, Release; head 808b2a83d merged onto main a5f493f90, clean merge; relinker, libkernel and libc built from that merge).

PPSA02530 (SDK word 0x1100004012590001 in its process parameters):

  • On main, converted with relinker --windows --registry --trace-imports: the executable loads at a 0x7ff6... address (DYNAMIC_BASE) and stops about 6 s after the start: FATAL: unhandled exception 0xc0000005 ... rip app.exe+0x26917, write of 0x0000000000000020. The write is mov DWORD PTR [r15+0x20], ebx after the title's first malloc(112) returned NULL. Cause, traced with gdb: the title's libc init callback calls sceLibcMspaceCreate("User Malloc For TLS", <static 256 KiB buffer in the executable image>, 0x40000, 0); the guest libc rejects a base address above 2^40 while sceKernelIsAddressSanitizerEnabled returns 0, the callback returns 1, the libc reports sceKernelDebugRaiseException c1=-1610481644 (0xA0020014) and skips the creation of its default heap, so every later malloc returns NULL.
  • With this PR (converted without any fixed-base flag) the title gets past that point and runs on: threads start (RunThread entry=0x140a03c90 ...), it opens /app0/natives/PS5/runtime.args, and it then stops at what(): sceVideoOutGetOutputStatusWithVrr not implemented (a separate gap; feat(videoout): implement sceVideoOutGetOutputStatusWithVrr #3972 implements that function). The same result is reached on main with relinker --windows-fixed-base 0x400000000.
  • Logs: run_041304.err (main, crash), run_051605.err (this PR, next stop).

Not run: Linux, a console. The relinker tests of this PR were not run by me.

AI-assisted (Claude Code).

@xXPBSXx

xXPBSXx commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Addendum to my Windows test above, for the executable header: objdump -p app.exe of the converted PPSA02530 shows ImageBase 0x0000000140000000 and DllCharacteristics 0x00000100 with this PR, and DllCharacteristics 0x00000140 (the extra 0x40 is DYNAMIC_BASE) when converted from main without it.

AI-assisted (Claude Code).

@xXPBSXx

xXPBSXx commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Correction to my Windows test above: I wrote that the relinker, libkernel and libc were built from the merge of this PR into main. That holds for the relinker only. The .prx libraries used in those title runs were an earlier build of main (the libs directory was not rebuilt from the merge). The crash on main and the result with this PR therefore compare two relinker outputs run with the same earlier libraries, which is the part this PR changes (the header and load address of the converted executable); the objdump -p values in my addendum are from the converted executables and are not affected.

AI-assisted (Claude Code).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

I pushed a docs commit for the two open points: docs/user/USAGE.md now describes the new default (no DYNAMIC_BASE, preferred base 0x140000000, relocations kept; --windows-fixed-base stays for exact addresses), and the debt line says why it is the default (the title's own sceLibcMspaceCreate checks a 40-bit window, #3043) and names the option. xXPBSXx's Windows 10 run on 808b2a8 covers the code; no other change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants