fix(relinker): export Windows executable symbols #11432
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11432"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by muhmuhkuh on 2026-10-26T13:15:22Z.
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
231336e48cand 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 main7903201bb426f7f1e8565e98cc3df299d849edc7, 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)Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T15:35:55Z.
Review: APPROVED
Reviewed
f11378f4d880against7903201bb426. 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_exportsandwindows_guest_export_aliasespassed (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.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T19:01:56Z.
Review: COMMENTED
Merge check of head
f11378f4d880against currentmain4570612f40(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
mainsince this PR's base7903201bb4, with the PR merged at each step, points to46031052fc, the merge of #11381 ("validate executable export names and attributes like guest modules", 28/10). #11381 checks executable exports inRelinkerPipelinebefore any target-specific code:#-stripped aliases now fail earlier withConflicting executable exports after stripping #: alpha, so theconflictcase never reachesDuplicate executable export.STT_GNU_IFUNCexport now fails withUnsupported executable export attributes: bad, notUnsupported executable export type.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,ValueandSizeall match, since #11381 has already rejected the conflicting ones. Also update the two expected messages in the test: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 currentmainshould show the same failures in CI.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T20:31:49Z.
Review: COMMENTED
Re-checked
77cb5f907con Linux: both relinker failures are gone.Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Head merged (--no-commit) onto currentmain16345cad6a; clean merge, full build OK.windows_executable_exportsandexecutable_export_attributes: pass 3/3.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.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-02T17:37:55Z.
Review: APPROVED
Windows run of head
77cb5f907cmerged onto currentmainb28bb77217(clean merge, local only), including the native part ofwindows_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.mainb28bb77217windows_executable_exports,executable_export_attributes,windows_guest_export_aliasesnative_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.Read through the change: the export table is written through the shared
WindowsExportBuilder::Buildfor both executables and guest modules, names come out sorted from thestd::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 byPT_TLS. I found nothing to change.Overlap: #15032 (opened today) conflicts textually on
WindowsElfPatcher.hppandWindowsPePatcher.cpp. Both add a trailingWindowsPePatcherconstructor parameter, and both change theWindowsTlsBuilder().Build(...)call inPatch: this PR passes&tlsIndexfor thenullptr, #15032 adds afunctionSymbolRootsargument. Whichever lands second keeps both.Conversion.cppmerges cleanly.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T21:14:37Z.
Review: APPROVED
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-ffintomain9090972b7e91fd266819cbd77a8b058e177b5682(merged treed67b2f6cdc144b93f57af155b01a1bcf234d9ff6). Debian 13 VM, GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pylibsOKunwrap_selfalso fails onmain(known failure); no new failures or timeoutswindows_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_moduleswindows_guest_export_aliasesWIN32Negative control
I restored only
WindowsPePatcher.cpp,WindowsElfPatcher.hppandConversion.cppfrommain, which removes the executable export wiring, and rebuiltrelinker.windows_executable_exportsthen failed:output
I then restored the merged files and rebuilt. The tests passed again, and
git status --porcelainshowed 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_OBJECTaliases were rejected and that two expected messages were stale. Both are fixed in this head.BuildExecutablenow compares the whole symbol tuple, andexecutable_export_attributespasses on this merge.Not verified
LoadLibraryExW/GetProcAddresspart ofwindows_executable_exportsorwindows_guest_export_aliases: both run only on Windows. Superseabas's review reports both passing on Windows..edataoutput is byte-identical after the refactor. I compared the code, and the moved block matches the removed one.