Skip to content

BUILD-2035: load mapped images with Unicode basenames - #6287

Merged
shayderrr merged 1 commit into
ProjectLeonida:mainfrom
Hiiva:fix/unicode-module-basename
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ProjectLeonida:mainfrom
Hiiva:fix/unicode-module-basename

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Problem

BUILD-2035. On Windows with MSVC and ACP 1252, an original synthetic executable with a basename containing U+6F22 runs natively but fails before entry in all three loader modes. Loader::load converts its basename through path::string() for the cache key. map_image repeats the conversion for its display name. ACP-representable non-ASCII names do load, but their raw ACP bytes also make the documented UTF-8 map trace invalid.

Claim: #6089 (comment)
The claim carries to #6214.

Changes

  • Keep basename identity in filesystem::path::string_type using native(), with the existing ASCII case folding.
  • Retain a separate lossless narrow alias and its existing bytewise case folding for current narrow API/import lookups. Folded multibyte bytes are not reinterpreted as UTF-8 or widened.
  • Use UTF-8 for Module::name, mapped address labels, and path diagnostics. Two names that cannot round-trip through the narrow code page retain distinct native identities.
  • Preserve repeated-load and same-basename cache behavior, and remove the native identity key when a map/bind or newly loaded module initialization fails.
  • Add native Windows and actual mapped synthetic controls for renamed EXEs/DLLs, imports, cache aliases, path errors, strict trace decoding, and unchanged fixture bytes.

This does not change library_loader API conversions, add Unicode case folding, or implement the separately owned wide module-identity APIs.

Validation

Windows 11 x64, MSVC 19.44.35228, SDK 10.0.26100.0, RelWithDebInfo, ACP 1252. CPU only; no GPU or game files.

The same final fixtures were used for both versions:

  • Main 561b65a8: all seven native children pass. Four mapped launches fail before entry: the non-ACP basename in --dry-run, --init, and --run, plus a non-ACP importing EXE. Four other mapped runs execute successfully but emit invalid UTF-8 map traces for ACP names. The direct Loader test reports seven failed checks.
  • Fixed: all 22 native/mapped children pass, with valid UTF-8 traces and unchanged fixture bytes. The importing EXE executes its original function and data import checks against the renamed synthetic DLL.
  • Focused CTests pass: module_names (59 checks), run_module_names (22 children), pe_loader (79 checks), and loader (86 checks). The last includes failed parent/dependency lookup and retry controls. The optional retail-package checks remain skipped because LEONIDA_GAME_DIR is unset.

Reproduction:

cmake -S runtime -B runtime/build -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.26100.0 -DLEONIDA_SDL3_FETCH=OFF
cmake --build runtime/build --config RelWithDebInfo --target gta6rt module_names_test tiny_module_names tiny_exe pe_loader_test loader_test --parallel 4
ctest --test-dir runtime/build -C RelWithDebInfo -R "^(module_names|run_module_names|pe_loader|loader)$" --output-on-failure

Independent peer source review completed with no actionable findings.

Integration

Depends on: #2075
Depends on: #5302
Depends on: #5565
Depends on: #5805

These are actual source conflicts, not prerequisites for this standalone branch. Exact-head three-way checks were done in separate local trees. The resolved #5565 combination was also built and executed as described below; the other combinations were checked only in source.

The resolved combination with #5565 at the exact head above passes the same four focused Unicode/loader CTests and its unchanged 104-child process_detach suite. The held-loader, registry, and library-cache lock cases complete all expected lookups and native-matching detach checks. The original early-detach negative control also passes. This verifies the alias iteration within the owner's prepared-detach lookup scope; no other dependency combination was executed.

AI-assisted: yes.

@milas6669

Copy link
Copy Markdown

Checked head e88d2730e merged onto main 561b65a83. Windows 11 (ACP 1252), MSVC 19.44 RelWithDebInfo, full build. ctest -R "module_names|loader|pe_loader|run_tiny": 20/20 pass, including module_names, run_module_names, loader, loader_tls-neighbours and the run_tiny_* set.

Extra probes beyond the PR's: I copied tiny_game.exe to five names and ran each with gta6rt --run ... -- hello 42: tiny_😀.exe (a surrogate pair), tiny_漢.exe, tiny_é.exe, TINY_UPPER.EXE, tiny.game.exe. All five exit 0 with 8 PASS lines, 0 FAIL.

New data, a merge-order hazard: this PR changes Loader::by_name_ to std::map<std::filesystem::path::string_type, Module*> (native keys) and rewrites map_image's by_name_[...] line. Two open PRs that merge cleanly with main now conflict with it in runtime/src/pe_loader.cpp:

#3981 and #4313 conflict as well, but both already conflict with main on their own. Not a defect in this PR; this is for whoever merges. No game data. AI-assisted (Claude Code).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

pe_loader.cpp now keys by_name_ on std::filesystem::path::string_type native basenames with ASCII folding instead of narrowed std::string. New module_key, narrow_module_key and path_utf8 helpers keep a lossless narrow alias for legacy GetModuleHandleA/import-name lookups while Module::name, labels and diagnostics carry UTF-8. find_narrow_module backs find_loaded_module/load_runtime_module; failed runtime loads erase by module_key(mapped->path). Adds module_names_test.cpp, tiny_module_names.cpp, check_module_names.py with CMake targets comparing native and mapped renamed DLLs.

Why merge

Unicode-named DLLs now load and dedupe correctly without breaking the narrow-byte API contract, backed by native-vs-mapped tests including ACP imports.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

pe_loader.cpp now keys by_name_ on std::filesystem::path::string_type native basenames with ASCII folding instead of narrowed std::string. New module_key, narrow_module_key and path_utf8 helpers keep a lossless narrow alias for legacy GetModuleHandleA/import-name lookups while Module::name, labels and diagnostics carry UTF-8. find_narrow_module backs find_loaded_module/load_runtime_module; failed runtime loads erase by module_key(mapped->path). Adds module_names_test.cpp, tiny_module_names.cpp, check_module_names.py with CMake targets comparing native and mapped renamed DLLs.

Why merge

Unicode-named DLLs now load and dedupe correctly without breaking the narrow-byte API contract, backed by native-vs-mapped tests including ACP imports.

Verdict: Approve

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