Bind system ordinal imports by their stored ordinal #81

Merged
Vonsek merged 2 commits from upstream-pr/82 into main 2026-11-21 16:26:14 +00:00
Vonsek commented 2026-11-21 15:41:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T15:41:09Z.


Change

tools/cpu_call_aot.py decided whether an import was by ordinal from imp.name is None. pefile names ordinal imports from ws2_32.dll, wsock32.dll and oleaut32.dll from its built-in table but keeps import_by_ordinal set. For those providers the translator rejected a correct #N --link-name binding as unbound, and accepted a binding to the table name, resolving it by name in the provider rather than by the ordinal the image calls. The translator now reads import_by_ordinal. call_evidence.py and cpu_chained_aot.py only match fixed named imports outside these DLLs, and pefile's skipped entries do not shift IAT slot addresses, so those tools are unchanged.

Verification

Linux, pefile 2024.8.26, stand-in fixtures built with clang-cl, llvm-ml and lld-link from tests/cpu/direct.asm, import.def, import_provider.cpp and ordinal_provider.def:

  • import_check.system_ordinal before the fix: unbound import ws2_32.dll!WSAInstallServiceClassA at IAT slot RVA 0x2090. After the fix: passes.
  • With a stand-in ws2_32.dll that also exports WSAInstallServiceClassA by name at ordinal 1, --bind ws2_32.dll WSAInstallServiceClassA was accepted before the fix and generated a named dllimport; after the fix it is rejected with unbound import ws2_32.dll!#77.

Windows: ctest --preset dev --no-tests=error -R '^cpu_aot_(ordinal_import|import_call)$' -V at 8289615 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): cpu_aot_import_call and cpu_aot_ordinal_import passed. The Windows CI job also passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/44920494779.

Evidence and follow-up

The regression test reuses the existing ordinal fixtures: it copies the provider to ws2_32.dll and rewrites the image's import DLL name in place, so no new binary inputs are added. The name WSAInstallServiceClassA for ordinal 77 comes from pefile's built-in table. The binding contract stays "ordinal imports require #N and --link-name".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6530893115 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/82). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T15:41:09Z. --- ## Change `tools/cpu_call_aot.py` decided whether an import was by ordinal from `imp.name is None`. pefile names ordinal imports from ws2_32.dll, wsock32.dll and oleaut32.dll from its built-in table but keeps `import_by_ordinal` set. For those providers the translator rejected a correct `#N --link-name` binding as unbound, and accepted a binding to the table name, resolving it by name in the provider rather than by the ordinal the image calls. The translator now reads `import_by_ordinal`. `call_evidence.py` and `cpu_chained_aot.py` only match fixed named imports outside these DLLs, and pefile's skipped entries do not shift IAT slot addresses, so those tools are unchanged. ## Verification Linux, pefile 2024.8.26, stand-in fixtures built with clang-cl, llvm-ml and lld-link from `tests/cpu/direct.asm`, `import.def`, `import_provider.cpp` and `ordinal_provider.def`: - `import_check.system_ordinal` before the fix: `unbound import ws2_32.dll!WSAInstallServiceClassA at IAT slot RVA 0x2090`. After the fix: passes. - With a stand-in `ws2_32.dll` that also exports `WSAInstallServiceClassA` by name at ordinal 1, `--bind ws2_32.dll WSAInstallServiceClassA` was accepted before the fix and generated a named dllimport; after the fix it is rejected with `unbound import ws2_32.dll!#77`. Windows: `ctest --preset dev --no-tests=error -R '^cpu_aot_(ordinal_import|import_call)$' -V` at 8289615 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): `cpu_aot_import_call` and `cpu_aot_ordinal_import` passed. The Windows CI job also passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/44920494779. ## Evidence and follow-up The regression test reuses the existing ordinal fixtures: it copies the provider to `ws2_32.dll` and rewrites the image's import DLL name in place, so no new binary inputs are added. The name `WSAInstallServiceClassA` for ordinal 77 comes from pefile's built-in table. The binding contract stays "ordinal imports require `#N` and `--link-name`".
upstream-sync closed this pull request 2026-11-24 06:41:14 +00:00
R0Y00 commented 2026-11-24 06:47:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T15:46:28Z.


Thanks for covering system ordinal imports. Please mark this ready for review once you're satisfied with the named and ordinal binding tests.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7065132500 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/82#issuecomment-7065132500). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T15:46:28Z. --- Thanks for covering system ordinal imports. Please mark this ready for review once you're satisfied with the named and ordinal binding tests.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!81
No description provided.