feat(relinker): support ordinal imports from routed DLLs #11

Manually merged
github merged 1 commit from gh-pr/11/head into gh-pr/11/base 2026-11-26 19:13:51 +00:00
Owner

@⁠Callimann8 on GitHub · 2026-11-21 11:44 UTC · original
Callimann8:claude/project-thread-q2c7z8 → main · +139 −13 · 14 files · 1 commits · merged 2026-11-21 11:56 UTC

What

Ordinal imports from a routed DLL failed at load, because AnyBox libraries export by name only.

  • A library can list <Name> @<ordinal> lines in core/libs/xdll/<name>/Ordinals.txt. cmake/LibraryMap.cmake validates them (identifier, 1–65535, no repeated name or ordinal).
  • anybox_add_xdll generates ab_<name>.def when a library has ordinals: Forwards.def lines get their @<ordinal>, and pinned exports that are not forwarded are added as Name @<ordinal>. Libraries without Ordinals.txt build exactly as before.
  • CMake also generates LibraryOrdinalsData.inc. LibraryMap carries it, and Convert refuses an image that imports by ordinal from a routed library at an ordinal no library pins, naming each one (XGameRuntime.dll #5). Host, bundled and unknown DLLs are unaffected.
  • gameinput pins GameInputCreate @1, the ordinal GameInput.lib imports it by (from the pending gdk-inventory debt entry, which this removes).
  • stubgen.py points skipped ordinal imports at Ordinals.txt; CONTRIBUTING, AGENTS, ARCHITECTURE and BUILD mention the file.

Tested

  • Linux, -DANYBOX_RELINKER_ONLY=ON: 21/21 CTest pass, including the new relinker_ordinal case (pinned ordinal is routed and stays an ordinal import; unpinned one is refused and named; unrouted DLL ordinals are ignored). The new case fails with the Convert change reverted.
  • Tool tests: 34 pass. python tools/check_conventions.py: ok. python tools/debt_fold.py --check: 4 fragments apply cleanly.
  • Full library build cross-compiled on Linux with MinGW-w64 GCC 13 (posix): builds. objdump -p ab_gameinput.dll shows the GameInputCreate forwarder at ordinal 1. With a temporary XGameRuntimeInitialize @7 in xgameruntime, ab_xgameruntime.dll exports it at ordinal 7 (temporary file not committed). Bad lines (Foo @0, repeated ordinal) stop configure with a message.
  • Not tested: MSVC build, running a converted title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • python tools/check_conventions.py passes (no comments in code, one declaration per export, Conventional Commit subjects)
  • Unimplemented paths stop (AbxNotImplemented / AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment
  • Known gaps added, changed or removed through docs/dev/debt/changes/relinker-ordinals.md
  • Generic behaviour, not specific to one title
  • No game files, keys, notes or logs added to the repository
  • Depends on: none
  • Fixes: Fixes #5
  • Unblocks: none
  • Source of behaviour: PE/COFF export ordinals and module-definition @ordinal syntax (Microsoft PE format and .def documentation); GameInputCreate ordinal 1 from the GDK GameInput.lib inventory entry already in debt
  • AI-assisted: yes
**@⁠Callimann8** on GitHub · 2026-11-21 11:44 UTC · [original](https://github.com/Dark3581/AnyBox/pull/11) `Callimann8:claude/project-thread-q2c7z8` → `main` · +139 −13 · 14 files · 1 commits · merged 2026-11-21 11:56 UTC ### What Ordinal imports from a routed DLL failed at load, because AnyBox libraries export by name only. - A library can list `<Name> @<ordinal>` lines in `core/libs/xdll/<name>/Ordinals.txt`. `cmake/LibraryMap.cmake` validates them (identifier, 1–65535, no repeated name or ordinal). - `anybox_add_xdll` generates `ab_<name>.def` when a library has ordinals: `Forwards.def` lines get their `@<ordinal>`, and pinned exports that are not forwarded are added as `Name @<ordinal>`. Libraries without `Ordinals.txt` build exactly as before. - CMake also generates `LibraryOrdinalsData.inc`. `LibraryMap` carries it, and `Convert` refuses an image that imports by ordinal from a routed library at an ordinal no library pins, naming each one (`XGameRuntime.dll #5`). Host, bundled and unknown DLLs are unaffected. - `gameinput` pins `GameInputCreate @1`, the ordinal `GameInput.lib` imports it by (from the pending `gdk-inventory` debt entry, which this removes). - `stubgen.py` points skipped ordinal imports at `Ordinals.txt`; CONTRIBUTING, AGENTS, ARCHITECTURE and BUILD mention the file. ### Tested - Linux, `-DANYBOX_RELINKER_ONLY=ON`: 21/21 CTest pass, including the new `relinker_ordinal` case (pinned ordinal is routed and stays an ordinal import; unpinned one is refused and named; unrouted DLL ordinals are ignored). The new case fails with the `Convert` change reverted. - Tool tests: 34 pass. `python tools/check_conventions.py`: ok. `python tools/debt_fold.py --check`: 4 fragments apply cleanly. - Full library build cross-compiled on Linux with MinGW-w64 GCC 13 (posix): builds. `objdump -p ab_gameinput.dll` shows the `GameInputCreate` forwarder at ordinal 1. With a temporary `XGameRuntimeInitialize @7` in xgameruntime, `ab_xgameruntime.dll` exports it at ordinal 7 (temporary file not committed). Bad lines (`Foo @0`, repeated ordinal) stop configure with a message. - Not tested: MSVC build, running a converted title. ### Checklist <!-- Rules behind each item: CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] `python tools/check_conventions.py` passes (no comments in code, one declaration per export, Conventional Commit subjects) - [x] Unimplemented paths stop (`AbxNotImplemented` / `AbxUnsupported`); silent stubs are listed under Silent stubs through a debt fragment - [x] Known gaps added, changed or removed through `docs/dev/debt/changes/relinker-ordinals.md` - [x] Generic behaviour, not specific to one title - [x] No game files, keys, notes or logs added to the repository - [x] Depends on: none - [x] Fixes: Fixes #5 - [x] Unblocks: none - [x] Source of behaviour: PE/COFF export ordinals and module-definition `@ordinal` syntax (Microsoft PE format and .def documentation); GameInputCreate ordinal 1 from the GDK `GameInput.lib` inventory entry already in debt - [x] AI-assisted: yes
A library can now list `<Name> @<ordinal>` lines in an Ordinals.txt.
CMake merges them into the library's export definition file, so the
export is pinned at that ordinal, and generates a table the relinker
uses to refuse, at conversion, any ordinal import from a routed DLL
that no library pins.

gameinput pins GameInputCreate at ordinal 1, as GameInput.lib imports it.

Fixes dark3581/anybox#5

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YZ2PrBn656ni9Yhvif2BQZ
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:13:49 +00:00
github manually merged commit 223249759c into gh-pr/11/base 2026-11-26 19:13:51 +00:00
Author
Owner

@⁠Dark3581 on GitHub · 2026-11-21 11:55 UTC · original · approved these changes

Reviewed — looks good

Merging as it is. Clean design: libraries without Ordinals.txt build exactly as before, and the relinker now fails at conversion instead of at load.

What I ran

Head 2232497, based on current main (81a02cc). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.

Results

Check Result Note
MinGW full build passed no warnings
CTest passed 35/35, including relinker_ordinal
Tool tests passed 34/34
tools/check_conventions.py, tools/debt_fold.py --check passed 4 fragments apply cleanly
ab_gameinput.dll exports passed objdump -p: GameInputCreate forwarder at ordinal 1
Real title DLLs passed relinked a title's 16 bundled DLLs: 13 convert unchanged; one that imports XAudio2_9.dll by ordinal is now refused with XAudio2_9.dll #1 (pin the export ...), where main converted it silently
CI passed Windows, relinker on Linux and macOS, conventions, progress

Findings

Blocking

None.

Non-blocking

  • The Python tools do not read Ordinals.txt yet, so tools/import_audit.py still reports a pinned ordinal import (for example gameinput.dll!#1) as absent, and stubgen.py --from-audit skips it. I'll teach tools/anybox_scan.py to resolve #<ordinal> through Ordinals.txt in a follow-up, together with pinning XAudio2Create @1 for the title above.

Not verified

The MSVC build locally (CI covers it) and running a converted title that imports by ordinal.

Thanks, this closes #5 neatly.

**@⁠Dark3581** on GitHub · 2026-11-21 11:55 UTC · [original](https://github.com/Dark3581/AnyBox/pull/11#pullrequestreview-6005037129) · **approved these changes** # Reviewed — looks good Merging as it is. Clean design: libraries without `Ordinals.txt` build exactly as before, and the relinker now fails at conversion instead of at load. ## What I ran Head `2232497`, based on current `main` (`81a02cc`). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. ## Results | Check | Result | Note | | - | - | - | | MinGW full build | passed | no warnings | | CTest | passed | 35/35, including `relinker_ordinal` | | Tool tests | passed | 34/34 | | `tools/check_conventions.py`, `tools/debt_fold.py --check` | passed | 4 fragments apply cleanly | | `ab_gameinput.dll` exports | passed | `objdump -p`: `GameInputCreate` forwarder at ordinal 1 | | Real title DLLs | passed | relinked a title's 16 bundled DLLs: 13 convert unchanged; one that imports `XAudio2_9.dll` by ordinal is now refused with `XAudio2_9.dll #1 (pin the export ...)`, where `main` converted it silently | | CI | passed | Windows, relinker on Linux and macOS, conventions, progress | ## Findings ### Blocking None. ### Non-blocking - The Python tools do not read `Ordinals.txt` yet, so `tools/import_audit.py` still reports a pinned ordinal import (for example `gameinput.dll!#1`) as `absent`, and `stubgen.py --from-audit` skips it. I'll teach `tools/anybox_scan.py` to resolve `#<ordinal>` through `Ordinals.txt` in a follow-up, together with pinning `XAudio2Create @1` for the title above. ## Not verified The MSVC build locally (CI covers it) and running a converted title that imports by ordinal. Thanks, this closes #5 neatly.
This discussion has been locked. Commenting is limited to contributors.
No description provided.