fix(mods): a code module the image cannot place is left out with why, instead of stopping the build #3168

Merged
HumanBean merged 2 commits from snaildev99/Longshot:mods/module-parity into main 2026-12-05 17:35:20 +00:00
Member

Summary

main builds a mod's code module (exefs/subsdk*) in after the game's own, and leaves out one that writes code
memory at its start-up. A module with other faults stopped the whole build instead (an unknown relocation, a
relocation pointing outside the module or naming no symbol), or was built in and failed later in the game (a system
call the host does not answer, a .text that isn't whole instructions, segments out of order or overlapping, more
bytes than its header's slot, a relative relocation that overflows at its base, an import nothing provides).

With this change such a mod module is left out, with why in the build log and the Mods tab, and the build goes on. The
game's own modules still stop the build on the same faults, as before. The checks are the ones #984 had on the old
builder:

  • in game-files::modules::refusal: the segment layout, relocation kinds and targets, and system calls against
    HOST_SVCS (a test keeps it equal to the cases host/hos_svc.c's a64_svc answers), in the code the module runs:
    each straight run of .text from a place code starts (its start, unwind starts, symbols, DT_INIT/DT_FINI,
    relative relocation targets, branch and call targets), so an svc's bits in a literal after a return are not one;
  • in image::build::take_modules, once the bases are known: a relative relocation that overflows at the module's
    base, or a name one of its symbol relocations binds (strongly, by the image relocation's own rule) that nothing
    placed before the module exports (the game, an earlier mod's module, or the host). Such a module takes no base,
    exports nothing and takes none of the modules' 128 MB (counted here now, after these checks), and
    exefs_modules.txt is written after these checks so the Mods tab agrees.

The discovery also takes an address in main that a mod's module builds with MOVZ/MOVK, adds to another register
and then calls (BLR) or jumps to (BR), as an entry: a hook that calls into the game that way lands on a function,
and one that jumps back into a game function after its patch's stub lands on an entry. A call strictly inside a
function main's unwind table covers is not taken; a sum only added to a pointer is not an address.

How to see it on main: a_mod_module_the_image_cannot_place_is_left_out_and_the_build_finishes (image) builds a
module with an unknown relocation kind; on main it is built in with an empty note.

This ports the rest of #984's module checks and #940's notes. Read first: builder/crates/game-files/src/modules.rs
(refusal), builder/crates/image/src/build.rs (take_modules), then builder/crates/cfg/src/entries.rs.

Testing

Tested: Windows 11 Pro, RTX 3090, NVIDIA 610.88, in the game, built by longshot-builder play --profile with
this PR and the other mod compatibility ports merged, adult Link in Kakariko, with four code mods: the three valid
modules (HUD of Time, Rupee Counter, Edge-to-Edge) pass every new check, are built in, and work in the game; Ragdoll
Button is left out by main's existing rule (it writes code memory at start-up), with that reason. No mod on this PC
has a module the new checks leave out: those cases are the game-free tests below, which build each fault into a
synthetic module.
After the rebase onto main @ 3a0f7d8f7 and the review's fixes, the same profile again, built with this PR @
2335ed09e and the other ports merged (929bf025a): HUD of Time (subsdk9), Rupee Counter (subsdk7) and
Edge-to-Edge (subsdk6) built in, 7 modules with no unresolved imports, Ragdoll Button left out for its
MapProcessMemory call as before, and the three mods at work in Kakariko.

mise run test, run locally while CI's run waits for approval (Windows 11, tests/run_all.py --strict, 12 checks at
once), here @ 2335ed09e and on main @ 3a0f7d8f7: 847 passed, 12 failed, 52 skipped here; 845 passed, 14 failed, 52
skipped on main. All 12 also fail on main: test_dlssg, test_fsr4_tune, test_lifter, test_no_game_title,
test_no_map_reload, test_present_acquire_ahead, test_present_geometry_trace, test_present_held_image,
test_present_image_free, test_sync_watch_event, test_turf_budget, test_ui_renderer.

After the review (rebased on main @ 3a0f7d8f7), cargo test -p cfg -p game-files -p image on Windows 11 @ 2335ed09e:
cfg 5 + 9, game-files 63 + 1 + 3, image 14 + 1 passed, none failed; cargo clippy -p cfg -p game-files -p image --all-targets --no-deps -- -D warnings and cargo fmt --check of the three are clean. The review's fixes each have a
test that failed on this pull request's code before the fix and fails again with the fix's key line undone:
a_mod_module_s_added_movz_movk_constant_in_main_is_an_entry (cfg: a sum only added to a pointer, read through
before the call, called too late, or called inside an unwound function is no entry; a call of that function's start
and a jump back into it are), a_literal_shaped_like_a_system_call_is_not_one (game-files),
only_a_name_a_relocation_binds_is_an_import and a_module_left_out_at_placement_leaves_its_room_to_later_ones
(image).

Still to test:

  • Windows: a clean and a one-function build with code mods, its time and size against main on the same PC
    (measurement, the review's L5)

Measurements

Verdict: Fixed: each test that fails on main passes, and valid modules are still built in. Nothing changes
per frame; the checks run in the build, once per mod module.

Setup: cargo test of cfg, game-files and image on Windows 11; the before side is the test commit (8dfec6ef0),
which is main's code with the tests.

Before: main @ 3a0f7d8f7 After: this PR @ 2335ed09e
cargo test -p game-files modules:: (system call, segment layout, a literal shaped like a system call) 3 failed 3 passed
cargo test -p image a_mod_module_the_image_cannot_place 1 failed (built in, empty note) 1 passed
cargo test -p cfg a_mod_module_s_added_movz_movk 1 failed (not an entry) 1 passed

The review's two take_modules tests (only_a_name_a_relocation_binds_is_an_import,
a_module_left_out_at_placement_leaves_its_room_to_later_ones) are in the fix commit: main has no take_modules.
Both failed on this pull request's code before the review's fix (21403aad3) and pass here.

Risks

  • A mod module that was built in before and has one of these faults is now left out, with why. One that stopped the
    build now lets it finish without the module.
  • A mod's export can still satisfy one of the game's imports (as on main).
  • What the scans don't see stays as on main: an address of main a module calls or jumps to some other way (a sum
    stored and called later, a call more than eight instructions after its ADD) gets no entry, and the game stops at
    that call; a system call the host lacks in code the module reaches only through a jump table, or from the game's
    patched code, does not leave the module out, and the game stops there if it runs.
  • Players: a broken mod no longer stops their build; its row says why it was left out. A revert is enough.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (run locally, Testing names them; CI's run waits for approval)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened. (tests/test_dlss_nr_forwarder.py reads build-driver/src/build.rs: it passes unchanged)
  • A fix: a game-free test that fails on main and passes here.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary `main` builds a mod's code module (`exefs/subsdk*`) in after the game's own, and leaves out one that writes code memory at its start-up. A module with other faults stopped the whole build instead (an unknown relocation, a relocation pointing outside the module or naming no symbol), or was built in and failed later in the game (a system call the host does not answer, a `.text` that isn't whole instructions, segments out of order or overlapping, more bytes than its header's slot, a relative relocation that overflows at its base, an import nothing provides). With this change such a mod module is left out, with why in the build log and the Mods tab, and the build goes on. The game's own modules still stop the build on the same faults, as before. The checks are the ones #984 had on the old builder: - in `game-files::modules::refusal`: the segment layout, relocation kinds and targets, and system calls against `HOST_SVCS` (a test keeps it equal to the cases `host/hos_svc.c`'s `a64_svc` answers), in the code the module runs: each straight run of `.text` from a place code starts (its start, unwind starts, symbols, `DT_INIT`/`DT_FINI`, relative relocation targets, branch and call targets), so an `svc`'s bits in a literal after a return are not one; - in `image::build::take_modules`, once the bases are known: a relative relocation that overflows at the module's base, or a name one of its symbol relocations binds (strongly, by the image relocation's own rule) that nothing placed before the module exports (the game, an earlier mod's module, or the host). Such a module takes no base, exports nothing and takes none of the modules' 128 MB (counted here now, after these checks), and `exefs_modules.txt` is written after these checks so the Mods tab agrees. The discovery also takes an address in `main` that a mod's module builds with `MOVZ`/`MOVK`, adds to another register and then calls (`BLR`) or jumps to (`BR`), as an entry: a hook that calls into the game that way lands on a function, and one that jumps back into a game function after its patch's stub lands on an entry. A call strictly inside a function `main`'s unwind table covers is not taken; a sum only added to a pointer is not an address. How to see it on `main`: `a_mod_module_the_image_cannot_place_is_left_out_and_the_build_finishes` (image) builds a module with an unknown relocation kind; on `main` it is built in with an empty note. This ports the rest of #984's module checks and #940's notes. Read first: `builder/crates/game-files/src/modules.rs` (`refusal`), `builder/crates/image/src/build.rs` (`take_modules`), then `builder/crates/cfg/src/entries.rs`. ## Testing **Tested:** Windows 11 Pro, RTX 3090, NVIDIA 610.88, in the game, built by `longshot-builder play --profile` with this PR and the other mod compatibility ports merged, adult Link in Kakariko, with four code mods: the three valid modules (HUD of Time, Rupee Counter, Edge-to-Edge) pass every new check, are built in, and work in the game; Ragdoll Button is left out by `main`'s existing rule (it writes code memory at start-up), with that reason. No mod on this PC has a module the new checks leave out: those cases are the game-free tests below, which build each fault into a synthetic module. After the rebase onto `main` @ 3a0f7d8f7 and the review's fixes, the same profile again, built with this PR @ 2335ed09e and the other ports merged (929bf025a): HUD of Time (`subsdk9`), Rupee Counter (`subsdk7`) and Edge-to-Edge (`subsdk6`) built in, 7 modules with no unresolved imports, Ragdoll Button left out for its `MapProcessMemory` call as before, and the three mods at work in Kakariko. `mise run test`, run locally while CI's run waits for approval (Windows 11, `tests/run_all.py --strict`, 12 checks at once), here @ 2335ed09e and on `main` @ 3a0f7d8f7: 847 passed, 12 failed, 52 skipped here; 845 passed, 14 failed, 52 skipped on `main`. All 12 also fail on `main`: test_dlssg, test_fsr4_tune, test_lifter, test_no_game_title, test_no_map_reload, test_present_acquire_ahead, test_present_geometry_trace, test_present_held_image, test_present_image_free, test_sync_watch_event, test_turf_budget, test_ui_renderer. After the review (rebased on `main` @ 3a0f7d8f7), `cargo test -p cfg -p game-files -p image` on Windows 11 @ 2335ed09e: cfg 5 + 9, game-files 63 + 1 + 3, image 14 + 1 passed, none failed; `cargo clippy -p cfg -p game-files -p image --all-targets --no-deps -- -D warnings` and `cargo fmt --check` of the three are clean. The review's fixes each have a test that failed on this pull request's code before the fix and fails again with the fix's key line undone: `a_mod_module_s_added_movz_movk_constant_in_main_is_an_entry` (cfg: a sum only added to a pointer, read through before the call, called too late, or called inside an unwound function is no entry; a call of that function's start and a jump back into it are), `a_literal_shaped_like_a_system_call_is_not_one` (game-files), `only_a_name_a_relocation_binds_is_an_import` and `a_module_left_out_at_placement_leaves_its_room_to_later_ones` (image). **Still to test:** - Windows: a clean and a one-function build with code mods, its time and size against `main` on the same PC (measurement, the review's L5) ## Measurements **Verdict:** Fixed: each test that fails on `main` passes, and valid modules are still built in. Nothing changes per frame; the checks run in the build, once per mod module. Setup: `cargo test` of `cfg`, `game-files` and `image` on Windows 11; the before side is the test commit (8dfec6ef0), which is `main`'s code with the tests. | | Before: main @ 3a0f7d8f7 | After: this PR @ 2335ed09e | |---|---|---| | `cargo test -p game-files modules::` (system call, segment layout, a literal shaped like a system call) | 3 failed | 3 passed | | `cargo test -p image a_mod_module_the_image_cannot_place` | 1 failed (built in, empty note) | 1 passed | | `cargo test -p cfg a_mod_module_s_added_movz_movk` | 1 failed (not an entry) | 1 passed | The review's two `take_modules` tests (`only_a_name_a_relocation_binds_is_an_import`, `a_module_left_out_at_placement_leaves_its_room_to_later_ones`) are in the fix commit: `main` has no `take_modules`. Both failed on this pull request's code before the review's fix (21403aad3) and pass here. ## Risks - A mod module that was built in before and has one of these faults is now left out, with why. One that stopped the build now lets it finish without the module. - A mod's export can still satisfy one of the game's imports (as on `main`). - What the scans don't see stays as on `main`: an address of `main` a module calls or jumps to some other way (a sum stored and called later, a call more than eight instructions after its `ADD`) gets no entry, and the game stops at that call; a system call the host lacks in code the module reaches only through a jump table, or from the game's patched code, does not leave the module out, and the game stops there if it runs. - Players: a broken mod no longer stops their build; its row says why it was left out. A revert is enough. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). (run locally, Testing names them; CI's run waits for approval) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. (`tests/test_dlss_nr_forwarder.py` reads `build-driver/src/build.rs`: it passes unchanged) - [x] A fix: a game-free test that fails on `main` and passes here. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The checks of the fix that follows, on main's code. Each fails there for the bug's reason:

- a module with a system call the host does not answer (svc #0x7F) is still taken;
- a module whose .text is not a whole number of instructions is built in;
- a module with an unknown relocation kind is built in, with an empty note, where the build should leave it out
  and finish;
- a mod module's MOVZ/MOVK constant added to a register is not an entry in main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(mods): a code module the image cannot place is left out with why, instead of stopping the build
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
4a22e212d8
The rest of #984's module checks on the Rust builder (main already places a mod's exefs/subsdk* after the game's
modules and leaves out one that writes code memory).

A mod's code module is now left out, with why in the log and the Mods tab, and the build goes on, when:

- its .text does not start and end on a 4-byte boundary, its segments are out of order or overlap, or it loads more
  bytes than its header's slot;
- it has a relocation of a kind the build does not apply, one that points outside the module, or a symbol relocation
  with no symbol (any of these stopped the build);
- it uses a system call the host does not answer (`HOST_SVCS`, which a test keeps equal to host/hos_svc.c's
  `a64_svc` cases);
- a relative relocation overflows at the base it would get, or it imports a (non-weak) symbol that nothing placed
  before it exports: not the game, an earlier mod's module, or the host. Such a module takes no base and exports
  nothing, and exefs_modules.txt is written after these checks so the Mods tab agrees.

The discovery also takes an address in main that a mod's module builds with MOVZ and MOVK and adds to another
register, as an entry: a hook that calls into the game that way lands on a function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11 Pro, RTX 3090, NVIDIA 610.88, adult Link in Kakariko, built by longshot-builder play --profile with the mod compatibility ports merged: HUD of Time, Rupee Counter and Edge-to-Edge's modules passed the new checks, were built in and worked in the game; Ragdoll Button was left out by main's existing rule (code memory written at start-up), with its reason. No mod on this PC trips the new checks: those cases are the game-free tests.

Tested in game: Windows 11 Pro, RTX 3090, NVIDIA 610.88, adult Link in Kakariko, built by longshot-builder play --profile with the mod compatibility ports merged: HUD of Time, Rupee Counter and Edge-to-Edge's modules passed the new checks, were built in and worked in the game; Ragdoll Button was left out by main's existing rule (code memory written at start-up), with its reason. No mod on this PC trips the new checks: those cases are the game-free tests.
Member

Possibly related, for context:

  • PR #2533 fix(builder): the bss end, table extents and eh-frame count of an untrusted module are refused — Open safety fixes for untrusted modules in game-files; inspect validation overlap.
  • issue #2497 Mods that ship extra ExeFS modules (subsdkN) are not loaded: the .ips applies but its code is missing — Open report on mods shipping extra subsdk modules, useful compatibility context.
Possibly related, for context: - PR #2533 fix(builder): the bss end, table extents and eh-frame count of an untrusted module are refused — Open safety fixes for untrusted modules in game-files; inspect validation overlap. - issue #2497 Mods that ship extra ExeFS modules (subsdkN) are not loaded: the .ips applies but its code is missing — Open report on mods shipping extra subsdk modules, useful compatibility context.
Author
Member

mise run test, run locally while CI's run waits for approval (Windows 11, run_all --strict, 12 checks at once), here @ 4a22e212d and on main @ f577a1aea: 833 passed, 12 failed, 51 skipped here; 820 passed, 25 failed, 51 skipped on main. All 12 also fail on main (named in Testing). Box ticked; the check that reads build-driver's build.rs (test_dlss_nr_forwarder) passes unchanged, box added.

mise run test, run locally while CI's run waits for approval (Windows 11, run_all --strict, 12 checks at once), here @ 4a22e212d and on main @ f577a1aea: 833 passed, 12 failed, 51 skipped here; 820 passed, 25 failed, 51 skipped on main. All 12 also fail on main (named in Testing). Box ticked; the check that reads build-driver's build.rs (test_dlss_nr_forwarder) passes unchanged, box added.
snaildev99 changed title from WIP: fix(mods): a code module the image cannot place is left out with why, instead of stopping the build to fix(mods): a code module the image cannot place is left out with why, instead of stopping the build 2026-12-05 00:57:51 +00:00
BeanBot left a comment

Recommendation: Request changes. The new checks can leave out usable modules, and the entry heuristic can split a game function at an unrelated address. These regressions need fixes before merge.

The change leaves out several kinds of faulty mod module with a reason, allowing the build to continue, and adds discovery of some game addresses used by mods. It also adds rejection and discovery heuristics that can affect otherwise usable mods and game code.

Blocking (3): must change before merging.

  1. L1 builder/crates/cfg/src/entries.rs:109: An arbitrary arithmetic constant is treated as a game function entry without establishing that the other operand is main's base or that the result is called. (more on the line) Do: Establish that the value forms a game code address used as a call target before adding it, and exclude addresses inside known function spans unless they are known function starts.
  2. L2 builder/crates/image/src/build.rs:168: The missing-import check rejects every undefined strong symbol, including symbols that no relocation actually uses. (more on the line) Do: Check the symbols referenced by applicable relocations, using the same binding rules as image relocation, rather than all undefined symbol-table entries.
  3. L3 builder/crates/game-files/src/modules.rs:152: Scanning every word of text as an instruction can mistake embedded data for an unsupported system call. (more on the line) Do: Use code discovery or another reliable indication of executable instructions before rejecting a module for an unsupported SVC; add a test with an SVC-shaped literal.

Should fix (1): not blocking, but worth doing before merging.

  • L4 builder/crates/image/src/build.rs:125: A module rejected during placement has already consumed the collection limit, so its space is not made available to later modules. (more on the line) Do: Apply the aggregate limit after placement checks, counting only modules actually taken, and reconsider later modules in list order.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 builder/crates/cfg/src/entries.rs:94: The added discovery scan and any additional lifted entries have no build-time or build-size comparison. (more on the line) Do: Compare clean build time and size and a one-function incremental build against the base with representative code mods on the same machine. (@fix does its part first: Avoid allocating a complete word vector for each mod's text and avoid adding candidates that are not needed.)

@fix can do L1, L2, L3, L4 and L5.

Checks: Still running: 11 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes for the synthetic cases: the description reports four previously failing tests passing, and three valid modules working in a Windows game run. No real module triggering a new rejection was tested in game, and build-time cost was not measured.

Other systems: The builder and discovery changes apply on Windows and Linux and can affect every GPU because they alter the generated game image and code. The reported game run covers Windows with NVIDIA; no Linux build-time comparison was provided.

Switches: None.

Reviewed: 4a22e212d8 against f577a1aeab: Read the repository rules and PR template, commit messages, diff, changed module and discovery logic, image builder, and relevant callers and discovery walk. Skimmed the remaining changed driver and test code and documentation; did not read every changed code file in full. No recorded runs, translations or generated files changed.; nothing run (a code review).

Checked and fine:

  • Both commits record AI assistance in trailers.
  • The module list is written after placement updates its status.
  • No switches, renderer API changes, third-party files or generated files are added.

Testing: No commands from the project or tests were run, as requested. The author reports game-free test results against the base and a Windows in-game run; CI was still running.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as snaildev99 took it out of WIP. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The new checks can leave out usable modules, and the entry heuristic can split a game function at an unrelated address. These regressions need fixes before merge. The change leaves out several kinds of faulty mod module with a reason, allowing the build to continue, and adds discovery of some game addresses used by mods. It also adds rejection and discovery heuristics that can affect otherwise usable mods and game code. **Blocking (3)**: must change before merging. 1. **L1** `builder/crates/cfg/src/entries.rs:109`: An arbitrary arithmetic constant is treated as a game function entry without establishing that the other operand is main's base or that the result is called. (more on the line) **Do:** Establish that the value forms a game code address used as a call target before adding it, and exclude addresses inside known function spans unless they are known function starts. 2. **L2** `builder/crates/image/src/build.rs:168`: The missing-import check rejects every undefined strong symbol, including symbols that no relocation actually uses. (more on the line) **Do:** Check the symbols referenced by applicable relocations, using the same binding rules as image relocation, rather than all undefined symbol-table entries. 3. **L3** `builder/crates/game-files/src/modules.rs:152`: Scanning every word of text as an instruction can mistake embedded data for an unsupported system call. (more on the line) **Do:** Use code discovery or another reliable indication of executable instructions before rejecting a module for an unsupported SVC; add a test with an SVC-shaped literal. **Should fix (1)**: not blocking, but worth doing before merging. - **L4** `builder/crates/image/src/build.rs:125`: A module rejected during placement has already consumed the collection limit, so its space is not made available to later modules. (more on the line) **Do:** Apply the aggregate limit after placement checks, counting only modules actually taken, and reconsider later modules in list order. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `builder/crates/cfg/src/entries.rs:94`: The added discovery scan and any additional lifted entries have no build-time or build-size comparison. (more on the line) **Do:** Compare clean build time and size and a one-function incremental build against the base with representative code mods on the same machine. *(`@fix` does its part first: Avoid allocating a complete word vector for each mod's text and avoid adding candidates that are not needed.)* `@fix` can do L1, L2, L3, L4 and L5. **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the synthetic cases: the description reports four previously failing tests passing, and three valid modules working in a Windows game run. No real module triggering a new rejection was tested in game, and build-time cost was not measured. **Other systems:** The builder and discovery changes apply on Windows and Linux and can affect every GPU because they alter the generated game image and code. The reported game run covers Windows with NVIDIA; no Linux build-time comparison was provided. **Switches:** None. **Reviewed:** 4a22e212d835 against f577a1aeabdb: Read the repository rules and PR template, commit messages, diff, changed module and discovery logic, image builder, and relevant callers and discovery walk. Skimmed the remaining changed driver and test code and documentation; did not read every changed code file in full. No recorded runs, translations or generated files changed.; nothing run (a code review). **Checked and fine:** - Both commits record AI assistance in trailers. - The module list is written after placement updates its status. - No switches, renderer API changes, third-party files or generated files are added. **Testing:** No commands from the project or tests were run, as requested. The author reports game-free test results against the base and a Windows in-game run; CI was still running. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as snaildev99 took it out of WIP. Nothing was run; a maintainer decides.</sub>
@ -74,0 +91,4 @@
return BTreeSet::new();
};
let mut found = BTreeSet::new();
for m in modules.iter().filter(|m| is_mod_module(&m.name)) {
Member

L5 (should fix): The added discovery scan and any additional lifted entries have no build-time or build-size comparison.

When: A build with code mods scans their text and can generate additional game functions; the submitted results do not show the effect on a clean build or an incremental build.

Do: Compare clean build time and size and a one-function incremental build against the base with representative code mods on the same machine.

**L5** (should fix): The added discovery scan and any additional lifted entries have no build-time or build-size comparison. *When:* A build with code mods scans their text and can generate additional game functions; the submitted results do not show the effect on a clean build or an incremental build. **Do:** Compare clean build time and size and a one-function incremental build against the base with representative code mods on the same machine.
@ -74,0 +106,4 @@
if w3 & 0xFF20_FC00 == 0x8B00_0000 && (reg == rm || reg == rn) && rm != rn {
let v = u64::from(((w >> 5) & 0xFFFF) | (((next >> 5) & 0xFFFF) << 16));
if v % 4 == 0 && (lo..hi).contains(&v) {
found.insert(main.base + v);
Member

L1 (blocking): An arbitrary arithmetic constant is treated as a game function entry without establishing that the other operand is main's base or that the result is called.

When: A mod constructs a four-aligned size or structure offset that happens to fall inside main's text and adds it to a data pointer. The resulting candidate can land inside a game function; discovery stops walking at entries, splitting that function and potentially changing its generated control flow.

Do: Establish that the value forms a game code address used as a call target before adding it, and exclude addresses inside known function spans unless they are known function starts.

**L1** (blocking): An arbitrary arithmetic constant is treated as a game function entry without establishing that the other operand is main's base or that the result is called. *When:* A mod constructs a four-aligned size or structure offset that happens to fall inside main's text and adds it to a data pointer. The resulting candidate can land inside a game function; discovery stops walking at entries, splitting that function and potentially changing its generated control flow. **Do:** Establish that the value forms a game code address used as a call target before adding it, and exclude addresses inside known function spans unless they are known function starts.
@ -87,0 +149,4 @@
let code = nso.image.get(text.offset as usize..(text.offset + text.size) as usize).unwrap_or_default();
let mut writers = Vec::new();
let mut missing = std::collections::BTreeSet::new();
for w in code.as_chunks::<4>().0.iter().map(|b| u32::from_le_bytes(*b)) {
Member

L3 (blocking): Scanning every word of text as an instruction can mistake embedded data for an unsupported system call.

When: A working module has a literal or other non-executed word in its text segment whose bits encode SVC 0x7f. The module is left out even though execution never invokes that system call.

Do: Use code discovery or another reliable indication of executable instructions before rejecting a module for an unsupported SVC; add a test with an SVC-shaped literal.

**L3** (blocking): Scanning every word of text as an instruction can mistake embedded data for an unsupported system call. *When:* A working module has a literal or other non-executed word in its text segment whose bits encode SVC 0x7f. The module is left out even though execution never invokes that system call. **Do:** Use code discovery or another reliable indication of executable instructions before rejecting a module for an unsupported SVC; add a test with an SVC-shaped literal.
@ -93,0 +122,4 @@
if let Some(why) = cannot_place(&nso, base, &exports, &opts.hle) {
file.built = false;
file.note = why.clone();
log(format!("exefs: left out {}/exefs/{} ({why})", file.mod_name, file.file));
Member

L4 (should fix): A module rejected during placement has already consumed the collection limit, so its space is not made available to later modules.

When: Earlier modules fill the 128 MiB collection limit, but one is subsequently rejected for a missing import. A later valid module was already marked left out for exceeding the limit and is skipped here, even though the rejected module takes no image space.

Do: Apply the aggregate limit after placement checks, counting only modules actually taken, and reconsider later modules in list order.

**L4** (should fix): A module rejected during placement has already consumed the collection limit, so its space is not made available to later modules. *When:* Earlier modules fill the 128 MiB collection limit, but one is subsequently rejected for a missing import. A later valid module was already marked left out for exceeding the limit and is skipped here, even though the rejected module takes no image space. **Do:** Apply the aggregate limit after placement checks, counting only modules actually taken, and reconsider later modules in list order.
@ -93,0 +165,4 @@
let own: BTreeSet<&str> =
nso.symbols.iter().filter(|s| s.defined && !s.name.is_empty()).map(|s| s.name.as_str()).collect();
let mut lost = BTreeSet::new();
for s in &nso.symbols {
Member

L2 (blocking): The missing-import check rejects every undefined strong symbol, including symbols that no relocation actually uses.

When: A module contains an unused undefined strong symbol in its dynamic symbol table but has no relocation referencing it. Image relocation never resolves that symbol, so the module could run on the base; this check instead leaves the whole module out.

Do: Check the symbols referenced by applicable relocations, using the same binding rules as image relocation, rather than all undefined symbol-table entries.

**L2** (blocking): The missing-import check rejects every undefined strong symbol, including symbols that no relocation actually uses. *When:* A module contains an unused undefined strong symbol in its dynamic symbol table but has no relocation referencing it. Image relocation never resolves that symbol, so the module could run on the base; this check instead leaves the whole module out. **Do:** Check the symbols referenced by applicable relocations, using the same binding rules as image relocation, rather than all undefined symbol-table entries.
snaildev99 force-pushed mods/module-parity from 4a22e212d8
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to 2335ed09ed
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
2026-12-05 08:20:52 +00:00
Compare
Author
Member

Rebased onto main @ 3a0f7d8f7 for the base conflict; here @ 2335ed09e. Tested (the game again on this head), mise run test (against main @ 3a0f7d8f7: every failure also fails on main) and Measurements are updated. Answers to the review below.

Rebased onto main @ 3a0f7d8f7 for the base conflict; here @ 2335ed09e. Tested (the game again on this head), `mise run test` (against main @ 3a0f7d8f7: every failure also fails on main) and Measurements are updated. Answers to the review below.
Author
Member

L1 Fixed in 2335ed09e (cfg/src/entries.rs, mod_address_constants). A mod's MOVZ+MOVK constant added to another
register is now an entry only when the sum is then called (BLR) or jumped to (BR) within eight instructions, with
nothing writing that register or branching in between: a size or field offset added to a data pointer, or a sum read
through before a call, no longer counts. A called address strictly inside a function main's unwind table covers is
dropped (a span's own start is kept; it is the filter code_address_refs already had, now shared as drop_inside).
A jump (BR) into such a function is kept on purpose, so that part of the "Do" is not taken: the scan is there for a
module that jumps back into a game function after its patch's stub (#984's reason for it in the old
nx2/exefs_modules.py: "a module jumps back into the middle of a game function after its patch's stub, and an
indirect jump needs an entry"), and without that entry the jump stops the game at the lookup. Whether the other
operand is main's base can't be shown from the code alone; being branched to is what the check can see. Cases in
a_mod_module_s_added_movz_movk_constant_in_main_is_an_entry (8dfec6ef0).

L2 Fixed in 2335ed09e (image/src/build.rs, missing_imports). The check now walks the module's ABS64, GLOB_DAT and
JUMP_SLOT relocations and asks only about the names they bind, with the image relocation's rule for weak (the module's
last symbol of that name: one helper, weak_bindings, that relocate now uses too). An undefined symbol no
relocation names is never bound and no longer leaves the module out. Test (2335ed09e: it calls take_modules, which
main lacks): only_a_name_a_relocation_binds_is_an_import, an unbound undefined symbol and a name bound weak, then
the image built from them with nothing unresolved.

L3 Fixed in 2335ed09e (game-files/src/modules.rs, runs). A system call the host lacks now counts only in code the
module runs: each straight run of .text from a place code starts (its start, unwind starts, symbols, DT_INIT and
DT_FINI, relative relocation targets, the target of any branch or call) up to a B, BR, RET, BRK, HLT or UDF. A literal
after a function's return is in no run. No decoder dependency: the few branch encodings are read by mask, as the SVC
already was. The code-memory system calls are still looked for in every word, as on main. Test (8dfec6ef0):
a_literal_shaped_like_a_system_call_is_not_one, an svc #0x7f word after a ret that an ldr reads is taken; the
same word as a branch target leaves the module out.

L4 It held: collect counted a module against the 128 MB before take_modules could leave it out. Fixed in 2335ed09e:
the limit moved from collect into take_modules, after the placement checks, counting only the modules taken, in
the list's order. Test: a_module_left_out_at_placement_leaves_its_room_to_later_ones (64 MB files: the room of one
left out for its import goes to a later module, and one past the limit is still left out).

L5 The code part is in 2335ed09e: the scan reads each mod module's .text in place (no word vector per module) and
takes only sums that are called or jumped to, so it adds fewer candidates; a call that the unwind table already starts
adds nothing new. The clean and one-function build time and size with code mods, against main, is still to run on
the same PC.

**L1** Fixed in 2335ed09e (`cfg/src/entries.rs`, `mod_address_constants`). A mod's MOVZ+MOVK constant added to another register is now an entry only when the sum is then called (BLR) or jumped to (BR) within eight instructions, with nothing writing that register or branching in between: a size or field offset added to a data pointer, or a sum read through before a call, no longer counts. A called address strictly inside a function main's unwind table covers is dropped (a span's own start is kept; it is the filter `code_address_refs` already had, now shared as `drop_inside`). A jump (BR) into such a function is kept on purpose, so that part of the "Do" is not taken: the scan is there for a module that jumps back into a game function after its patch's stub (#984's reason for it in the old `nx2/exefs_modules.py`: "a module jumps back into the middle of a game function after its patch's stub, and an indirect jump needs an entry"), and without that entry the jump stops the game at the lookup. Whether the other operand is main's base can't be shown from the code alone; being branched to is what the check can see. Cases in `a_mod_module_s_added_movz_movk_constant_in_main_is_an_entry` (8dfec6ef0). **L2** Fixed in 2335ed09e (`image/src/build.rs`, `missing_imports`). The check now walks the module's ABS64, GLOB_DAT and JUMP_SLOT relocations and asks only about the names they bind, with the image relocation's rule for weak (the module's last symbol of that name: one helper, `weak_bindings`, that `relocate` now uses too). An undefined symbol no relocation names is never bound and no longer leaves the module out. Test (2335ed09e: it calls `take_modules`, which `main` lacks): `only_a_name_a_relocation_binds_is_an_import`, an unbound undefined symbol and a name bound weak, then the image built from them with nothing unresolved. **L3** Fixed in 2335ed09e (`game-files/src/modules.rs`, `runs`). A system call the host lacks now counts only in code the module runs: each straight run of `.text` from a place code starts (its start, unwind starts, symbols, DT_INIT and DT_FINI, relative relocation targets, the target of any branch or call) up to a B, BR, RET, BRK, HLT or UDF. A literal after a function's return is in no run. No decoder dependency: the few branch encodings are read by mask, as the SVC already was. The code-memory system calls are still looked for in every word, as on `main`. Test (8dfec6ef0): `a_literal_shaped_like_a_system_call_is_not_one`, an `svc #0x7f` word after a `ret` that an `ldr` reads is taken; the same word as a branch target leaves the module out. **L4** It held: `collect` counted a module against the 128 MB before `take_modules` could leave it out. Fixed in 2335ed09e: the limit moved from `collect` into `take_modules`, after the placement checks, counting only the modules taken, in the list's order. Test: `a_module_left_out_at_placement_leaves_its_room_to_later_ones` (64 MB files: the room of one left out for its import goes to a later module, and one past the limit is still left out). **L5** The code part is in 2335ed09e: the scan reads each mod module's `.text` in place (no word vector per module) and takes only sums that are called or jumped to, so it adds fewer candidates; a call that the unwind table already starts adds nothing new. The clean and one-function build time and size with code mods, against `main`, is still to run on the same PC.
Author
Member

Still to test now lists the measurement the review asked for, which the answers above say is still to run.

Still to test now lists the measurement the review asked for, which the answers above say is still to run.
Owner
@rebase
Member

I rebased this pull request onto main (5d7e0668c8): the new head is c38103b145.

Conflicts resolved

  • builder/crates/build-driver/tests/driver.rs: Updated SwitchedGame::image to accept &mut Patches, matching the GameFiles trait.
  • Also changed, beyond the conflict: builder/crates/build-driver/tests/driver.rs

Nothing was built or run: read the resolution before merging.


Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I rebased this pull request onto `main` (5d7e0668c8d2): the new head is c38103b1451b. **Conflicts resolved** - builder/crates/build-driver/tests/driver.rs: Updated SwitchedGame::image to accept &mut Patches, matching the GameFiles trait. - Also changed, beyond the conflict: `builder/crates/build-driver/tests/driver.rs` Nothing was built or run: read the resolution before merging. --- <sub>Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed mods/module-parity from 2335ed09ed
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
to c38103b145
Some checks failed
PR description / Title and description (pull_request_target) Failing after 6s
CI / What the change needs (pull_request) Successful in 8s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Waiting to run
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Waiting to run
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Waiting to run
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Waiting to run
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Waiting to run
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Waiting to run
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Waiting to run
CI / Website build and checks (pull_request) Waiting to run
CI / Third-party parts and guide screenshots (pull_request) Successful in 13s
2026-12-05 17:32:59 +00:00
Compare
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The fixes address the reported code defects, and the reported synthetic tests show the intended behavior. The build-time and build-size comparison remains outstanding. Recommend approval; not approved on the forge.

Mod modules the builder cannot place are left out with a reason, allowing the build to continue. The additional scans and placement checks add build work whose cost has not yet been measured.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 builder/crates/cfg/src/entries.rs:94: The added discovery scan and any additional lifted entries have no build-time or build-size comparison. When: A build with code mods scans their text and can generate additional game functions; the submitted results do not show the effect on a clean build or an incremental build. Do: Compare clean build time and size and a one-function incremental build against the base with representative code mods on the same machine. (@fix does its part first: Avoid allocating a complete word vector for each mod's text and avoid adding candidates that are not needed.)

@fix can do L5.

Since the last review (on 4a22e212d8)
Resolved: L1 (An arbitrary arithmetic constant is treated as a game function entry without establishing…); L2 (The missing-import check rejects every undefined strong symbol, including symbols that no…); L3 (Scanning every word of text as an instruction can mistake embedded data for an unsupported…); L4 (A module rejected during placement has already consumed the collection limit, so its space…)
Still open: L5 (The added discovery scan and any additional lifted entries have no build-time or build-siz…)

Checks: they run again on this head; a failure shows on the pull request.

More: does it help, other systems, switches, what was read

Does it help: Yes for the reported synthetic cases: the description reports three game-files tests, one image test and one cfg test failing on main and passing with the change. Three valid code mods also reportedly worked in game; no real mod tested triggered the new refusal checks.

Other systems: The checks affect code-mod collection, image placement and entry discovery on Windows and Linux; the reported game run is on Windows. GPU rendering, audio, input and saves are not directly changed.

Switches: None.

Reviewed: c38103b145 against 5d7e0668c8: Read the repository rules and pull request template, the supplied comments, ledger and range-diff. Read cfg/src/entries.rs; the combined output for game-files/src/modules.rs and image/src/build.rs was truncated, and the remaining changed files and dependent code were not read in full.; nothing run (a code review).

Checked and fine:

  • The reported placement-limit test covers a rejected module leaving room for a later module.
  • The reported import test covers an undefined symbol that no relocation binds.

Testing: No commands that build or run tests were executed. The author reports Windows game and synthetic test results; CI has not run on this head.

Overlaps and merge order: Not established.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The fixes address the reported code defects, and the reported synthetic tests show the intended behavior. The build-time and build-size comparison remains outstanding. Recommend approval; not approved on the forge. Mod modules the builder cannot place are left out with a reason, allowing the build to continue. The additional scans and placement checks add build work whose cost has not yet been measured. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `builder/crates/cfg/src/entries.rs:94`: The added discovery scan and any additional lifted entries have no build-time or build-size comparison. *When:* A build with code mods scans their text and can generate additional game functions; the submitted results do not show the effect on a clean build or an incremental build. **Do:** Compare clean build time and size and a one-function incremental build against the base with representative code mods on the same machine. *(`@fix` does its part first: Avoid allocating a complete word vector for each mod's text and avoid adding candidates that are not needed.)* `@fix` can do L5. **Since the last review** (on 4a22e212d835) Resolved: L1 (An arbitrary arithmetic constant is treated as a game function entry without establishing…); L2 (The missing-import check rejects every undefined strong symbol, including symbols that no…); L3 (Scanning every word of text as an instruction can mistake embedded data for an unsupported…); L4 (A module rejected during placement has already consumed the collection limit, so its space…) Still open: L5 (The added discovery scan and any additional lifted entries have no build-time or build-siz…) **Checks:** they run again on this head; a failure shows on the pull request. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the reported synthetic cases: the description reports three game-files tests, one image test and one cfg test failing on main and passing with the change. Three valid code mods also reportedly worked in game; no real mod tested triggered the new refusal checks. **Other systems:** The checks affect code-mod collection, image placement and entry discovery on Windows and Linux; the reported game run is on Windows. GPU rendering, audio, input and saves are not directly changed. **Switches:** None. **Reviewed:** c38103b1451b against 5d7e0668c8d2: Read the repository rules and pull request template, the supplied comments, ledger and range-diff. Read cfg/src/entries.rs; the combined output for game-files/src/modules.rs and image/src/build.rs was truncated, and the remaining changed files and dependent code were not read in full.; nothing run (a code review). **Checked and fine:** - The reported placement-limit test covers a rejected module leaving room for a later module. - The reported import test covers an undefined symbol that no relocation binds. **Testing:** No commands that build or run tests were executed. The author reports Windows game and synthetic test results; CI has not run on this head. **Overlaps and merge order:** Not established. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch mods/module-parity 2026-12-05 17:35:20 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!3168
No description provided.