Repository navigation
fix(relinker): export Windows executable symbols - #11432
Conversation
|
I see the PR head |
|
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.
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.
|
9e0260b to
f11378f
Compare
THEMANnt
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 onmain): fails 3/3 on the merge withFAIL: Duplicate executable export: objforidentical_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 withConflicting executable exports after stripping #: alpha, so theconflictcase never reachesDuplicate executable export. - An
STT_GNU_IFUNCexport now fails withUnsupported executable export attributes: bad, notUnsupported executable export type. - Identical aliases of any type are accepted on every target.
WindowsExportBuilder::BuildExecutablestill usesIdenticalOrdinaryFunctionExport, which only acceptsSTT_FUNC. Two identicalSTT_OBJECTaliases 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.
f11378f to
77cb5f9
Compare
jotitadev
left a comment
There was a problem hiding this comment.
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_exportsandexecutable_export_attributes: pass 3/3.- Full non-GPU suite: 1840/1840.
- Red control: with the old
IdenticalOrdinaryFunctionExportcheck put back inBuildExecutable,executable_export_attributesfails 3/3 withFAIL: Duplicate executable export: obj, so the identicalSTT_OBJECTalias case stays covered.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Superseabas
left a comment
There was a problem hiding this comment.
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_lookupran: withos.name == 'nt',LoadLibraryExWloaded the convertedlookup.exe,GetProcAddressfoundalpha,weak,zetaanddata, the calls returned 42, 43 and 42,dataread0x123456789abcdef0, andhiddenwas 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
left a comment
There was a problem hiding this comment.
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 rejectsValue >= MemorySizeand treats size 0 as 1. The pipeline check acceptsvalue == MemorySizewith 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_TLSmemsz64:(value, size) = (64, 0): fails withFAIL: 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/GetProcAddresspart ofwindows_executable_exportsorwindows_guest_export_aliases: both run only on Windows. Superseabas's review reports both passing on Windows. - I could not check that the guest-module
.edataoutput 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.
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 requested035ac96edd. Updated head:f11378f4d8805f94696beadc7dda6d9484c2023a. The intervening main commits and the rebase leavecore/relinkerunchanged. 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 updatedorigin/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 on7b415520b6079ff5a96898487eb91d7650000e49, withANYPS5_RELINKER_ONLY=ONandBUILD_TESTING=ON: build succeeded. Full CTest run: 306/308 passed. All relinker tests passed, includingwindows_executable_exports(nativeLoadLibraryExW/GetProcAddress, function calls, data, TLS descriptors, aliases and invalid-input rejection).build_eligibilityinitially used Node 14.16.1 and failed parsing||=; it passed when rerun with Node 24.22.1. The remainingcheck_compile_preprocessorfailure also reproduces on a clean detached7b415520worktree using the same command and environment: 10 assertions countunit.ctwice 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/mainpassed. 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/AnyPS5completed 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&tlsIndexoutput and its additionaldynamicSection.SyscallContinuationsargument. No functional dependency is required. Related #11381 validates executable export attributes across targets; it does not emit Windows executable exports.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)