Skip to content

shims: log and list a name two shim tables serve with different functions - #7502

Open
pvfreis wants to merge 1 commit into
ItsNotRexed:mainfrom
pvfreis:shim-dup-guard
Open

pvfreis wants to merge 1 commit into
ItsNotRexed:mainfrom
pvfreis:shim-dup-guard

Conversation

@pvfreis

@pvfreis pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: #7231 (comment) (new runtime item, no ID in the tables)

Depends on: none. It reads and writes the map only through table(), so it composes with #7175 (RT-488), which changes table()'s storage but not Table::Table.

What and why

Table::Table in runtime/shims/registry.cpp stored every entry with table()[dll!name] = fn. A second shim table that serves a name already registered replaced the first silently, and which table runs later is static-initialization order across translation units, which nothing controls.

This already happens with two open PRs: #7009 (xapu.cpp, chad.cpp) and #6981 (xapu_chad.cpp) serve the same 10 xapu.dll/chad.dll exports. Built together they compile and link cleanly, and all 10 entries are replaced with no message (measurement). The game would get whichever implementation happened to be constructed later.

Now:

  • The later entry is still the one served, so nothing changes for a build without a collision.
  • A name re-registered with a different function is logged once at startup ([rt] shims: <dll>!<name> is registered by two shim tables with different functions; the later one is served) and listed by the new rt::shims::conflicting_registrations().
  • The same function registered twice (for example one DLL name in two case spellings) is not a collision.
  • The list is an immortal, constant-initialized pointer, not a function-local static, in line with RT-488.

Tests:

  • shim_table_conflict (new executable): two synthetic tables in one file. It checks that only the name with a different function is listed, the later table's function is served, a shared function is not listed, and a name in one table is untouched.
  • shim_tables_unique (CTest on gta6rt): runs gta6rt with no arguments, after every shim table has been constructed, and fails on the collision message. It follows the PASS_REGULAR_EXPRESSION "usage: gta6rt" pattern of gta6rt_rejects_*. main has no collision today, so the test requires zero.

Tested

Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo, RTX 3060 (driver 617.14).

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: runtime only)

🤖 Generated with Claude Code

…ions

Table::Table stored every entry with table()[dll!name] = fn, so a second
table serving a name already registered replaced the first silently, in
static-initialization order across translation units. ItsNotRexed#7009 and ItsNotRexed#6981
serve the same 10 xapu.dll/chad.dll exports; built together they link
cleanly and the game would get whichever table happened to be later.

The later entry is still served (no behaviour change), but the collision
is now logged once at startup and listed by conflicting_registrations().
shim_table_conflict covers the rule with two synthetic tables, and
shim_tables_unique runs gta6rt with no arguments and fails if its own
shim set has any collision (main has none).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified: builds cleanly and passes both shim_table_conflict and shim_tables_unique tests. Detecting conflicting shim registrations at startup prevents silent link-order dependent function overrides across tables.

@SkillIssueXO

Copy link
Copy Markdown

Independent Windows A/B on 7c9e25a8 with the overlapping AcpHal.dll implementations from #6885 (921fa777) and #7009 (ee61180dd). I linked their unmodified acphal.cpp translation units into a small probe with the production registry.

  • Parent 86d1c862: both link orders produced 0 warnings. Reversing the order switched which implementation rt::shims::find served, as observed through the flag-2 allocation and command-slot results.
  • This PR: both link orders produced 9 warnings, one for each overlapping AcpHal export. Each order still selected the same provider as its parent build.
  • Single-shim controls: 0 warnings with either implementation. The PR's shim_table_conflict_test also passed.

This confirms a second real overlap that the diagnostic catches, alongside the XAPU/CHAD pair in the PR description. Windows 11 build 26300, LLVM-MinGW Clang 23.1.6, CPU-only synthetic calls. No game files. AI-assisted testing (Codex).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants