Skip to content

fix(relinker): export Windows executable symbols - #11432

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
muhmuhkuh:codex/windows-executable-exports
Nov 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
muhmuhkuh:codex/windows-executable-exports

Conversation

@muhmuhkuh

@muhmuhkuh muhmuhkuh commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Converted Windows executables currently have no PE export directory for their defined dynamic ELF symbols. This prevents the loader from resolving executable definitions such as MainProg. Build the export directory for visible code, data and TLS definitions, using the shared PE export writer for executable and guest-module output. Validate unsupported symbol kinds and conflicting aliases instead of emitting invalid RVAs.

Tested

Current update: rebased onto main 231336e and fixed identical executable export aliases. Windows Release relinker-only build succeeded with GCC 13.1.0; windows_executable_exports, executable_export_attributes and windows_guest_export_aliases passed (3/3). Conventions passed. Full CTest: 530/538 passed; six select_tests cases and two configure_seed cases failed during CMake fixture setup. Their captured logs do not reveal the underlying CMake error; no main comparison was performed. Earlier review update: rebased onto current main 7903201bb426f7f1e8565e98cc3df299d849edc7, which includes the requested 035ac96edd. Updated head: f11378f4d8805f94696beadc7dda6d9484c2023a. The intervening main commits and the rebase leave core/relinker unchanged. Fresh isolated relinker-only Release configure/build succeeded, and all eight focused Windows tests passed with 0 failures and 0 skips: windows_guest_export_aliases, windows_executable_exports, windows_fixed_base, executable_tls_relocations, executable_export_bounds, guest_tls_export_references, guest_absolute_symbols, windows_import_modules. Conventions were rerun against the updated origin/main.

Prior full-suite qualification:

Windows 11 x64, WinLibs GCC 15.2.0, Python 3.9.5. Isolated Release/Ninja build at commit 9e0260be05c9f1195fb86af8c2021ff5a5e63cdc, based on 7b415520b6079ff5a96898487eb91d7650000e49, with ANYPS5_RELINKER_ONLY=ON and BUILD_TESTING=ON: build succeeded. Full CTest run: 306/308 passed. All relinker tests passed, including windows_executable_exports (native LoadLibraryExW/GetProcAddress, function calls, data, TLS descriptors, aliases and invalid-input rejection).

build_eligibility initially used Node 14.16.1 and failed parsing ||=; it passed when rerun with Node 24.22.1. The remaining check_compile_preprocessor failure also reproduces on a clean detached 7b415520 worktree using the same command and environment: 10 assertions count unit.c twice on Windows. Its test and implementation have identical SHA-256 hashes on main and this branch. No source workaround is included.

python tools/check_conventions.py --base origin/main passed. No Linux or macOS run was performed.

In the prior qualified combined workspace, Death Stranding 2 (PPSA02015) converted with 83 named executable exports, including MainProg, and passed its previous executable-symbol lookup failure. The game still stops at a loading arrow; this PR does not claim a menu or gameplay.

tools/pr_overlap.py --branch codex/windows-executable-exports --repo boykopovar/AnyPS5 completed without shared lines or exports among PRs that merge with main. It reported four conflicting PRs for manual shared-file review: #5021, #6713, #10792 and #10861. Their macOS fixtures, Windows process parameters, pathconf routing and syscall continuations do not implement executable PE exports. CMake registrations and debt entries are separate. #10861 touches the same TLS-builder call: a future merge must preserve this PR's &tlsIndex output and its additional dynamicSection.SyscallContinuations argument. No functional dependency is required. Related #11381 validates executable export attributes across targets; it does not emit Windows executable exports.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA02015 Death Stranding 2: On the Beach (PPSA02015) #5424 (Windows executable-symbol lookup prerequisite; no menu confirmed)
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 26, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor

I see the PR head 9e0260be05c is based on 7b415520b60, while current main is 035ac96edd. The intervening main commits do not touch core/relinker and the diff is likely clean, but CONTRIBUTING requires PRs to stay current with main. Please sync to 035ac96edd and rerun conventions before final review; I will inspect the updated head and Windows CI afterward.

@github-actions

github-actions Bot commented Oct 26, 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
PR 10861 core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp L82
PR 15032 core/relinker/elfpatcher/include/elfpatcher/windows/WindowsElfPatcher.hpp L15, L27-28
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp L31, L82
core/relinker/relinker/src/pipeline/Conversion.cpp L164

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 6149 core/relinker/CMakeLists.txt
PR 7531 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 10479 docs/dev/debt/relinker.md
PR 11192 core/relinker/relinker/src/pipeline/Conversion.cpp
docs/dev/debt/relinker.md
PR 13486 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
docs/dev/debt/relinker.md
PR 14085 docs/dev/debt/relinker.md
PR 14212 docs/dev/debt/relinker.md
PR 14241 docs/dev/debt/relinker.md

@muhmuhkuh
muhmuhkuh force-pushed the codex/windows-executable-exports branch from 9e0260b to f11378f Compare October 26, 2026 14:57

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed f11378f4d880 against 7903201bb426. No actionable findings.

The change routes Windows executables through the shared PE export writer while preserving the guest-module export path. It filters non-exportable symbols, validates aliases and mapped RVAs, bounds TLS references to PT_TLS, and derives the export module name from the output filename. The reviewed changes fit the existing writer and symbol model.

Validation: The isolated Windows Release relinker build succeeded; windows_executable_exports and windows_guest_export_aliases passed (2/2). Four review-only checks also passed for output-name encoding, malformed symbol-name offsets and termination, and the PT_TLS end boundary. Hosted conventions and labels jobs passed.

The local checkout used the exact pinned base with GitHub’s patch because the canonical head object could not be fetched. No hosted compile or test job was reported for this head.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Merge check of head f11378f4d880 against current main 4570612f40 (Linux x86-64, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON). The PR merges without text conflicts, but two relinker tests fail after the merge:

  • windows_executable_exports (new here): fails 3/3 on the merge, passes 3/3 on the PR head alone.
  • executable_export_attributes (already on main): fails 3/3 on the merge with FAIL: Duplicate executable export: obj for identical_objects-windows, where the test expects exit 0.

A first-parent bisect over main since this PR's base 7903201bb4, with the PR merged at each step, points to 46031052fc, the merge of #11381 ("validate executable export names and attributes like guest modules", 28/10). #11381 checks executable exports in RelinkerPipeline before any target-specific code:

  • Conflicting #-stripped aliases now fail earlier with Conflicting executable exports after stripping #: alpha, so the conflict case never reaches Duplicate executable export.
  • An STT_GNU_IFUNC export now fails with Unsupported executable export attributes: bad, not Unsupported executable export type.
  • Identical aliases of any type are accepted on every target. WindowsExportBuilder::BuildExecutable still uses IdenticalOrdinaryFunctionExport, which only accepts STT_FUNC. Two identical STT_OBJECT aliases are therefore rejected on Windows only. This is a behavior conflict, not just a message change.

Minimal fix verified on the merge: accept a duplicate whose Info, Visibility, Section, Value and Size all match, since #11381 has already rejected the conflicting ones. Also update the two expected messages in the test:

--- a/core/relinker/elfpatcher/src/windows/WindowsExportBuilder.cpp
+++ b/core/relinker/elfpatcher/src/windows/WindowsExportBuilder.cpp
@@ BuildExecutable
         if (!inserted) {
-            if (!Relinker::IdenticalOrdinaryFunctionExport(previous->second, symbol)) throw Domain::RelinkerException("Duplicate executable export: " + symbolName);
+            const auto& first = previous->second;
+            if (first.Info != symbol.Info || first.Visibility != symbol.Visibility || first.Section != symbol.Section || first.Value != symbol.Value || first.Size != symbol.Size) throw Domain::RelinkerException("Duplicate executable export: " + symbolName);
             continue;
         }
--- a/core/relinker/relinker/tests/test_windows_executable_exports.py
+++ b/core/relinker/relinker/tests/test_windows_executable_exports.py
-                ('conflict', symbols[:2] + [('alpha#C#B', 0x12, 0, 1, 0x4020, 6)], 'Duplicate executable export'),
+                ('conflict', symbols[:2] + [('alpha#C#B', 0x12, 0, 1, 0x4020, 6)], 'Conflicting executable exports after stripping #: alpha'),
@@
-                ('ifunc', [('bad', 0x1a, 0, 1, 0x4000, 6)], 'Unsupported executable export type')):
+                ('ifunc', [('bad', 0x1a, 0, 1, 0x4000, 6)], 'Unsupported executable export attributes: bad')):

With this patch applied to the merge, both tests pass 3/3. The full relinker-only suite (ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON) passes 534/534. A rebase onto current main should show the same failures in CI.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@muhmuhkuh
muhmuhkuh force-pushed the codex/windows-executable-exports branch from f11378f to 77cb5f9 Compare October 30, 2026 19:21

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-checked 77cb5f907c on Linux: both relinker failures are gone.

Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON. Head merged (--no-commit) onto current main 16345cad6a; clean merge, full build OK.

  • windows_executable_exports and executable_export_attributes: pass 3/3.
  • Full non-GPU suite: 1840/1840.
  • Red control: with the old IdenticalOrdinaryFunctionExport check put back in BuildExecutable, executable_export_attributes fails 3/3 with FAIL: Duplicate executable export: obj, so the identical STT_OBJECT alias case stays covered.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@github-actions github-actions Bot added the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 2, 2026

@Superseabas Superseabas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Windows run of head 77cb5f907c merged onto current main b28bb77217 (clean merge, local only), including the native part of windows_executable_exports, which only runs on Windows.

Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Python 3.13, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON.

main b28bb77217 merged
Relinker-only suite 579 of 579 pass 580 of 580 pass
windows_executable_exports, executable_export_attributes, windows_guest_export_aliases - 3 of 3 each
  • native_lookup ran: with os.name == 'nt', LoadLibraryExW loaded the converted lookup.exe, GetProcAddress found alpha, weak, zeta and data, the calls returned 42, 43 and 42, data read 0x123456789abcdef0, and hidden was not found. I wrapped the function in a counting shim to confirm it is called, since the Linux runs above skip it.
  • No new compiler warnings in the changed files with GCC 16.2.

Read through the change: the export table is written through the shared WindowsExportBuilder::Build for both executables and guest modules, names come out sorted from the std::map, local, hidden and internal symbols are skipped, identical duplicates are accepted after #11381's checks, TLS references get a base relocation and are bounded by PT_TLS. I found nothing to change.

Overlap: #15032 (opened today) conflicts textually on WindowsElfPatcher.hpp and WindowsPePatcher.cpp. Both add a trailing WindowsPePatcher constructor parameter, and both change the WindowsTlsBuilder().Build(...) call in Patch: this PR passes &tlsIndex for the nullptr, #15032 adds a functionSymbolRoots argument. Whichever lands second keeps both. Conversion.cpp merges cleanly.

AI-assisted: yes (Claude Code)

@XairRrR XairRrR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — approved

Windows executables now get a PE export directory, written by the export builder that guest modules also use. The merge is clean, conventions pass, the focused relinker tests pass, the new test fails when the production wiring is reverted, and I found nothing blocking.

What I ran

Head 77cb5f907c944984d6a04400f6819d9fd9742c2d, merged with --no-ff into main 9090972b7e91fd266819cbd77a8b058e177b5682 (merged tree d67b2f6cdc144b93f57af155b01a1bcf234d9ff6). Debian 13 VM, GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON.

git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...77cb5f907c944984d6a04400f6819d9fd9742c2d
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "windows_executable_exports|executable_export|windows_guest_export_aliases|windows_fixed_base|executable_tls|guest_tls_export|guest_absolute|windows_import_modules"
# negative control
git show 9090972b7e91:<path> > <path>   # WindowsPePatcher.cpp, WindowsElfPatcher.hpp, Conversion.cpp
ninja -C build -j32 -l32 relinker
ctest --test-dir build --output-on-failure -R "^windows_executable_exports$"
git show d67b2f6cdc14:<path> > <path>   # same three files
ninja -C build -j32 -l32 relinker
ctest --test-dir build --output-on-failure -R "^(windows_executable_exports|executable_export_attributes|windows_fixed_base)$"
git status --porcelain
# edge probe: the test's fixture() with a TLS export (value, size) = (64, 0) and (56, 8), PT_TLS memsz 64
relinker --windows --skip-sce-module a.elf a.exe

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Build (script) configure, build and libs OK
Script test run 703 ran, 701 passed, 1 expected skip; unwrap_self also fails on main (known failure); no new failures or timeouts
Focused relinker tests (10) 10/10 passed: windows_executable_exports, windows_fixed_base, linux_executable_exports, macos_executable_exports, executable_tls_relocations, executable_export_bounds, executable_export_attributes, guest_tls_export_references, guest_absolute_symbols, windows_import_modules
windows_guest_export_aliases not registered on this host: CMake adds it only under WIN32
Vulkan validation skipped: the PR changes no AGC driver, shader recompiler or VideoOut files

Negative control

I restored only WindowsPePatcher.cpp, WindowsElfPatcher.hpp and Conversion.cpp from main, which removes the executable export wiring, and rebuilt relinker. windows_executable_exports then failed:

output
  File ".../test_windows_executable_exports.py", line 102, in main
    assert actual == {'alpha': 0x10000, 'data': 0x10f00,
AssertionError: {}

I then restored the merged files and rebuilt. The tests passed again, and git status --porcelain showed the worktree back at the merged tree.

Findings

Blocking

None.

Non-blocking

  • A zero-size TLS export at the end of PT_TLS is rejected on Windows only. The check is at core/relinker/elfpatcher/src/windows/WindowsExportBuilder.cpp:67 (link). It rejects Value >= MemorySize and treats size 0 as 1. The pipeline check accepts value == MemorySize with size 0 (RelinkerPipeline.cpp L520-L521), and so does the macOS patcher (MacOsMachOPatcher.cpp L91-L92). I ran the relinker on the test's fixture with PT_TLS memsz 64:

    • (value, size) = (64, 0): fails with FAIL: Executable TLS export is outside its TLS block: tls_value.
    • (56, 8): converts.

    This only matters for an end-of-block marker symbol, which is uncommon, so it does not block. Suggested fix: use the same bound as the pipeline (Value > MemorySize || Size > MemorySize - Value), or record the stricter rule in the debt entry the PR adds.

On the existing reviews: jotitadev reported, on the earlier head, that identical STT_OBJECT aliases were rejected and that two expected messages were stale. Both are fixed in this head. BuildExecutable now compares the whole symbol tuple, and executable_export_attributes passes on this merge.

Not verified

  • I could not run the native LoadLibraryExW/GetProcAddress part of windows_executable_exports or windows_guest_export_aliases: both run only on Windows. Superseabas's review reports both passing on Windows.
  • I could not check that the guest-module .edata output is byte-identical after the refactor. I compared the code, and the moved block matches the removed one.
  • I did not reproduce the Death Stranding 2 (PPSA02015) conversion, because titles are not run here.

@oneandonlydean
oneandonlydean merged commit 0c31a0e into boykopovar:main Nov 4, 2026
3 of 5 checks passed
@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs relinker unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants