Skip to content

test(ghidra): require pending multi-HI16 coverage in the real MIPS relocatable lane - #1974

Merged
morluto merged 2 commits into
morluto:mainfrom
AurelioB:test/mips-relocatable-multiple-hi16
Oct 12, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
AurelioB:test/mips-relocatable-multiple-hi16

Conversation

@AurelioB

@AurelioB AurelioB commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1950, addressing the post-merge Codex review comment on scripts/verify-real-ghidra-mips-relocatable.mjs.

Problem

The relocation oracle exposes coverage.multiple_hi16 (one LO16 resolving several pending HI16s), but the real-Ghidra lane never required it, and Clang's C output never produces that stream. Ghidra's loader could mishandle it while verify:ghidra:mips-relocatable still passed, although it is common in real objects: 24 of the 30 GCC-built kernel modules I checked contain it.

Change

  • tests/conformance/c/mips-relocatable.c: an assembly block with two %hi and exactly one %lo of a dedicated symbol, so any assembler that orders each HI16 before a matching LO16 emits both HI16s ahead of that single LO16 (Clang 21: HI@0 HI@4 LO@8; GNU as 2.45: HI@4 HI@0 LO@8). The first revision relied on Clang 21's sort; see the review thread.
  • scripts/verify-real-ghidra-mips-relocatable.mjs: requires coverage.multiple_hi16.
  • docs/ghidra-mips.md: lists the requirement.

Verification

Host: Linux x64, Ghidra 12.1.4, OpenJDK 21.0.12, Clang 21, GNU readelf.

  • node scripts/verify-real-ghidra-mips-relocatable.mjs: LE, BE and the soft-float -mlong-calls module variant all passed, each with multiple_hi16, shared_hi16 and lo16_carry true; process lineage verified. On the previous fixture the same lane reported multiple_hi16: false, so the new requirement would have failed.
  • vitest on tests/conformance/ghidra and src/ghidra/GhidraMipsProfile.test.ts: 73 passed. oxfmt --check, oxlint and jscpd pass.

Branched from the #1950 merge commit (290d301ec) because syncing my fork past #1963's workflow change needs a token scope I don't have; none of the three files changed on main since, and the branch merges cleanly.

…locatable lane

Post-merge review on morluto#1950: the relocation oracle exposes coverage.multiple_hi16, but the real-Ghidra lane never required it, and Clang's C output never produces a LO16 that resolves several pending HI16s. Ghidra's loader could therefore mishandle that stream while the lane still passed, although most GCC-built kernel modules checked contain it.

The relocatable fixture adds an assembly block with two lui %hi(rea_mips_rel_carry); LLVM's relocation sort then leaves one HI16 pending until a later LO16 that resolves it together with another HI16, including the carry. The lane now requires multiple_hi16: false on the previous fixture, true for all three variants (LE, BE, soft-float module) on real Ghidra 12.1.4.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T22:20:18.613767Z 6c58f89 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56fdfe6d60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/conformance/c/mips-relocatable.c Outdated
Comment on lines +51 to +52
* symbol make LLVM's relocation sort leave one HI16 pending until a later
* LO16 that also resolves another HI16, including the carry.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop depending on LLVM's relocation sort order

With REA_MIPS_CLANG=clang on Clang 17.0.0 (a compiler with MIPS target support that passes compileMipsFixture), GNU readelf reports this block as HI@0, LO@8, HI@4, LO@16 for all three variants. Thus no LO sees more than one pending HI, coverage.multiple_hi16 remains false, and the newly required assertion aborts the advertised real-Ghidra lane; Clang 20/21 sorting differently does not make this fixture portable. Encode the intended relocation stream deterministically instead of relying on LLVM's version-dependent sorting.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed independently: GNU as 2.45 orders the old block as HI@4 LO@8 HI@0 LO@10, so each LO16 resolves one HI16 and multiple_hi16 stays false. Only Clang 21's sort happened to leave a HI16 pending.

Fixed in 6c58f89: the block now uses a dedicated symbol (rea_mips_rel_highs_target) with two %hi and exactly one %lo. Any assembler that places each HI16 before a matching LO16 must emit both HI16s ahead of that single LO16. Clang 21 gives HI@0 HI@4 LO@8; GNU as 2.45, on the full fixture, gives HI@4 HI@0 LO@8. The real-Ghidra lane passes for LE, BE and the soft-float module variant with multiple_hi16 true. I could not test Clang 17 directly, but the single %lo leaves its sort no other valid placement.

@AurelioB

Copy link
Copy Markdown
Contributor Author

Note on the red CI here: the three failing tests are outside this change and fail on main alone. On 55b61485e, without this PR, src/browser/CdpCaptureEvents.redirectBodyShape.test.ts (preserves an already captured response shape…) and tests/boundary/filesystem/qwenClientConfiguration.test.ts (installs and removes the shared skill with a custom home: true/false) fail the same way locally. Everything else in the run passed (28 checks), including static checks and the source-built conformance fixtures.

…ion sorting

Review on morluto#1974: the block used two %lo of rea_mips_rel_carry, a symbol with other %lo uses, so the relocation stream depended on the assembler's HI16/LO16 sort. Clang 21 happened to leave a HI16 pending; Clang 17 (per review) and GNU as 2.45 (checked here: HI@4 LO@8 HI@0 LO@10) pair each HI16 with its own LO16, so multiple_hi16 stays false and the lane fails.

Use a dedicated symbol with two %hi and exactly one %lo. Any assembler that orders each HI16 before a matching LO16 must then emit both HI16s ahead of that single LO16: Clang 21 gives HI@0 HI@4 LO@8, GNU as 2.45 gives HI@4 HI@0 LO@8. The real-Ghidra lane passes for LE, BE and the soft-float module variant with multiple_hi16 true.
@CassieFox23

CassieFox23 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The new check works, on head 6c58f89 against base 290d301 (#1950). On Linux with real Ghidra 12.1.4, the MIPS relocatable lane passes on this PR, and the lane fails with the old fixture. The three red CI tests also fail on main, as AurelioB said.

Check Base Head
npm run verify:ghidra:mips-relocatable exit 0, passed, 3 variants exit 0, passed, 3 variants
multiple_hi16 in the lane's coverage report false in all 3 true in all 3
Lane script requires multiple_hi16 no (0 mentions) yes (1 mention)
Head's lane script run on the old fixture not applicable exit 1, "No LO16 resolved several pending HI16s"
GNU readelf on the new function not applicable HI16 at 0, HI16 at 4, LO16 at 8, same in all 3 variants
Ghidra and profile unit tests (4 files) 73 passed 73 passed
oxfmt --check, oxlint on the lane script not run exit 0 and exit 0

There are three variants. One is little-endian, one is big-endian, and one is a soft-float module. The old-fixture run stopped at the first variant, so it shows the failure for little-endian only. Clang here is 22.1.8; the PR text tested Clang 21. The PR changes no unit tests, so I ran the existing 4 files only.

CI: do the failures match main?

Yes. The same three tests fail on the PR and on main.

CI runs compared
Run Commit Failing tests
PR, 21:48 UTC 56fdfe6 the same three tests
main, 21:44 UTC b777e5d (#1967) the same three tests
PR, 22:16 UTC 6c58f89 the same three tests (shards 2 and 3)
main, 21:58 UTC 55b6148 the same three tests (shards 2 and 3)
  • src/browser/CdpCaptureEvents.redirectBodyShape.test.ts: "preserves an already captured response shape" (the name goes on)
  • tests/boundary/filesystem/qwenClientConfiguration.test.ts: "installs and removes the shared skill with a custom home: true" and "... false"

The CI workflows do not run this MIPS lane, so green CI says nothing about the new check. When I looked, one job on the 22:16 PR run was still pending (macOS x64 package baseline).

Not run

  • Clang 17, or GNU as building the fixture. Only Clang 22.1.8 ran here.
  • A broken Ghidra loader, to see the check catch a real mishandled stream.
  • macOS, Windows, the full test suite.

Thanks, AurelioB, for the quick fix after the Codex review, and for the clear notes on the CI failures.

Commands
export PATH=~/.local/opt/node24/bin:$PATH
export GHIDRA_INSTALL_DIR=~/.local/opt/ghidra_12.1.4_PUBLIC
export JAVA_HOME=~/.local/opt/jdk-21.0.12.1+1
# head 6c58f8903, base 290d301ec (merge-base with main), both from git archive
npm ci && npm run build && npm run test:prepare      # head; base reuses head's node_modules
npm run verify:ghidra:mips-relocatable --prefix HEAD_DIR   # exit 0, 62 s
npm run verify:ghidra:mips-relocatable --prefix BASE_DIR   # exit 0, 70 s
# throwaway copy of head with the base fixture mips-relocatable.c swapped in
npm run verify:ghidra:mips-relocatable --prefix NEG_DIR    # exit 1, 9 s
clang --target=mipsel-linux-gnu -march=mips32r2 -mabi=32 -mno-abicalls -fno-pic -G0 -fno-builtin -O1 -c mips-relocatable.c
readelf -r mips-relocatable.o
node_modules/.bin/vitest run tests/conformance/ghidra src/ghidra/GhidraMipsProfile.test.ts   # 73 passed, both trees
gh pr checks 1974 -R morluto/rea
gh run list -R morluto/rea --branch main --limit 5
gh run view RUN_ID --log-failed

The box was shared with other test agents. The one-minute load average read 4.7 to 8.3 during the lane runs, so the timings are not from an idle machine.

Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@AurelioB AurelioB closed this Oct 11, 2026
@AurelioB AurelioB reopened this Oct 11, 2026
@AurelioB

AurelioB commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @CassieFox23.

Now that #1972 has fixed the three shared failures on main, I triggered a CI run against the updated merge base.

@morluto
morluto merged commit eaf88ac into morluto:main Oct 12, 2026
63 of 67 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added area: tests Test suite and verification area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Oct 15, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Oct 31, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Oct 31, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Nov 10, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Nov 12, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Nov 16, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Nov 18, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Nov 19, 2026
@morluto morluto added the provider: ghidra Analysis provider / engine: ghidra label Nov 23, 2026
zhaikong pushed a commit to zhaikong/rea that referenced this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: tests Test suite and verification provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants