Skip to content

feat(ghidra): admit Xtensa ELF through a pinned lane - #7486

Closed
Entrpi wants to merge 55 commits into
morluto:mainfrom
Entrpi:feat-ghidra-xtensa-elf
Closed

Entrpi wants to merge 55 commits into
morluto:mainfrom
Entrpi:feat-ghidra-xtensa-elf

Conversation

@Entrpi

@Entrpi Entrpi commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ESP32, ESP32-S2 and ESP32-S3 ELF builds (EM_XTENSA, 94) are refused before any provider runs, although Ghidra ships Xtensa:LE:32:default. This PR admits them through a pinned Ghidra lane, checked after import and verified on real Ghidra by npm run verify:ghidra:xtensa. Refs #3483; ESP .bin images remain out of scope.

Maintainer decision requested: C1, the new xtensa value in three closed output enums (see below). Hexagon (#4819) and PowerPC (#1747) set the precedent.

Problem and expected behavior

  • Before: elfArchitecture has no case for machine 94, so parseElf refuses the file as "unsupported ELF architecture: e_machine 94". Go and Rust reports call the machine elf-machine-94.
  • After: the target resolves as xtensa. Ghidra admits little-endian ELF32 ET_EXEC images that declare the windowed ABI and PC-relative literals; every other shape gets a specific refusal.

Change and scope

Not included: call0/ESP8266, absolute literals (USE_ABSOLUTE_LITERALS=1; ESP-IDF declares 0), raw and ESP image input, and EM_XTENSA_OLD. The older RISC-V, MIPS and PowerPC lanes share the language-only override gap; their persisted profiles are unchanged.

Contract and boundary impact

  • Semantic owner: elfArchitecture → parseElf → readElfMetadata (readXtensaElfInfo, parseXtensaInfo, shared readElfNoteFrame) → ghidraXtensaUnsupportedReason/ghidraXtensaLanguage → profile and limitations.
  • C1 (compatibility decision requested): additive xtensa in the Evidence subject, snapshot target and live target summary enums; exhaustive readers must accept it. Other machine-94 outputs: inspect_go_binary, inspect_rust_binary and inspect_native_exports report xtensa instead of elf-machine-94, and the subjects of the Go, Rust, inspect_elf_notes and inspect_kernel_module Evidence gain architecture: "xtensa".
  • Profile parameters: xtensa_elf (header facts, ABI and literal addressing) and xtensa_support_lane: elf32-le-exec-windowed-generic. No tools, inputs, bridge or package changes. Windows Ghidra P0 still refuses ELF.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

Real-Ghidra lane. verify:ghidra:xtensa writes a windowed Xtensa ELF from annotated bytes, so it needs no Xtensa compiler. Through stdio MCP and the CLI, with schema-validated results, it checks the header, symbols, ABI and literal declaration against readelf, the pinned identity, each instruction, the call8 target and l32r literal, decompiled dataflow (uVar1 = rea_xtensa_leaf(0x12345678); return uVar1;), snapshot reopen, five header-mutated refusals, unchanged source bytes and owned cleanup. Its workspace comes from VerifierFixture and is kept on failure; its compiler, readelf and CLI commands run through createVerifierCommands, each an owned process tree with a deadline that SIGINT and SIGTERM interrupt. The xtensa fixture toolchain lane refuses a host without readelf before allocating anything. REA_XTENSA_CC adds a C fixture built with Espressif's GCC, and the lane requires the compiled callee's l32r to reference a literal holding its constant.

Decompiler quality (U1). ESP-IDF 5.5.2 hello_world (Espressif GCC 14.2.0, -Og), DWARF analyzer off, against DWARF: on ESP32, Ghidra finds 738 of 738 functions and 1376 of 1377 direct call edges, and 653 of 709 parameter counts equal DWARF's; on ESP32-S3, 915 of 915, 1559 of 1598 and 802 of 881. On ESP32-S3, 36 of the 39 missed edges are in functions using SALT/SALTU, which Ghidra does not decode (#9095). Most parameter differences are one unused parameter; 64-bit arguments decompile as two. Call-site argument values were not compared; the images are not committed.

Tests cover the gate, the pin and post-import check, every refusal, the note reader and malformed notes, the override, the summary schema, Go/Rust spelling and the lane's dataflow assertions. Mutating the machine-field check, the ABI=1 mapping or the override resolution makes them fail; the literal-declaration cases fail on fed438458, whose gate did not read the key.

Validation performed

  • On the head 6645fcd8f, which follows 839cbd1b5 with a fix to the review thread on casts. The pseudocode checks now strip only casts to a 32-bit integer type of Xtensa's ILP32 ABI, so a narrowing or pointer cast, such as rea_xtensa_leaf((char)0x12345678), stays in the operand and no check matches through it. New refusal cases fail against the previous checker. Linux x64 container, Ghidra 12.2 with JDK 25, Node 24.22.1, run as root: npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused passed 2,012 tests, 11 skipped, 1 failed, the same root-only kunaProvider case; verify:ghidra:bridge-sources passed; and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed, "mocked": false. CI on this head: 30 checks passed, 23 skipped, none failed.
  • On the head 839cbd1b5, which follows f47866bfe with a fix to the review thread on control flow. The straight-line check now refuses labels, goto, branches and loops, and requires the body's only return to be its last statement. New refusal cases fail against the previous checker. Linux x64 container, Ghidra 12.2 with JDK 25, Node 24.22.1, run as root: npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused passed 2,010 tests with the same one root-only failure; verify:ghidra:bridge-sources and the real verify:ghidra:xtensa passed, "mocked": false. CI on this head: 30 checks passed, 23 skipped, none failed.
  • On the head f47866bfe, which merges main 5142124ca cleanly into a40564b7c. It brings main's refactor(server): replace server.close and onclose monkey-patching with lifecycle hooks #13882, which fixes the cliStartupImports failure ([Bug] analyze-javascript-application loads AnalysisViewService at CLI startup since #13861 #13940) that 1a0e6515d's CI hit. Linux x64 container, Ghidra 12.2 with JDK 25, Node 24.22.1, run as root: npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused passed 2,002 tests with the same one root-only failure; verify:ghidra:bridge-sources and the real verify:ghidra:xtensa passed, "mocked": false; and tests/boundary/cli/cliStartupImports.test.ts passed 10 of 10.
  • On the head a40564b7c, which follows 1a0e6515d with a fix to the review thread on parenthesized lvalues. The pseudocode checks now test structure rather than spelling: the leaf and C callee may hold only declarations and their one return, and a caller's assignment from the call must be followed directly by the return of that temporary, so any intervening statement is refused. New refusal cases fail against the previous checker. Linux x64 container, Ghidra 12.2 with JDK 25, Node 24.22.1, run as root: npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused over 85 files passed 2,005 tests, 11 skipped, 1 failed, the same root-only kunaProvider case; verify:ghidra:bridge-sources passed; and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed, "mocked": false.
  • On the head 1a0e6515d, which merges main 686bb097f into 2b4a7438a. main's refactor(application): extract BinaryTargetExecutableProbes from BinaryTargetResolver #13826 moved the executable probes from BinaryTargetResolver.ts into BinaryTargetExecutableProbes.ts. This PR's xtensa branch, which reads .xtensa.info through readXtensaElfInfo with its cancellation check, moved with readElfMetadata and sits beside the RISC-V branch; the resolver now equals main's. Linux x64 container, Ghidra 12.2 with JDK 25, Node 24.22.1, run as root: npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused over 85 files passed 2,001 tests, 11 skipped, 1 failed, the same root-only kunaProvider case; verify:ghidra:bridge-sources passed; and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed, "mocked": false. CI on this head failed only tests/boundary/cli/cliStartupImports.test.ts › "loads summary projection and bundle delivery only when requested", in shard 11 and Portable tests. That test fails on main itself since refactor(application): migrate 7 standalone format services onto executeArtifactInspection #13861 ([Bug] analyze-javascript-application loads AnalysisViewService at CLI startup since #13861 #13940).
  • On the head 2b4a7438a, which merges main 43f5d2a78 into 83bf26b8f. main's perf(elf): cache BinaryReader and support offset reads in elfNoteLayout #13688 added a cached BinaryReader and an offset parameter to elfNoteLayout.ts where this PR adds declaredElfNoteAlignment; the merge keeps both, and xtensaInfo.ts still calls readElfNoteFrame with its own note slice. On Ghidra 12.2 with JDK 25 (Linux x64 container, Node 24.22.1, run as root): npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused over 137 files passed 2,744 tests, 22 skipped, 1 failed, the same root-only kunaProvider case; verify:ghidra:bridge-sources passed; and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed, "mocked": false. CI passed on this head: 30 checks passed, 23 skipped, none failed.
  • On the head 83bf26b8f, which merges main 36997555d cleanly into 259d614e1. 259d614e1 answers the Codex thread on the pseudocode checks: returnedExpression now refuses any statement that writes a parameter, and the call-result check shares that test, so it also catches increments and decrements. Six new refusal cases fail against the previous checker. The previous head 5cf6688ff merged main d35e14270 cleanly. On Ghidra 12.2 with JDK 25 (Linux x64 container, Node 24.22.1, run as root): npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed; npm run test:focused over 137 files passed 2,747 tests, 22 skipped, 1 failed, the same root-only kunaProvider case; verify:ghidra:bridge-sources passed; and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed, "mocked": false. CI passed on this head: 30 checks passed, 23 skipped, none failed.
  • On the head 45936008f, which merges main dff9b479e cleanly into d32bf7c7a. main changed none of this PR's files between 39ccb1d3b and dff9b479e. On Ghidra 12.2 with JDK 25 (Linux x64 container, Node 24.22.1, run as root): npm run check:fast, build:cached, docs:check and node scripts/verify-advertised-schemas.mjs passed (no stale summary); npm run test:focused over 138 files passed 2,730 tests, 22 skipped, 1 failed: kunaProvider "retries the abandoned export's file cleanup", which fails only as root because root ignores the chmod 0o500 it relies on. The same test passes as a non-root user in the fork's integration check:pr. CI passed on this head: 30 checks passed, 23 skipped, none failed.
  • On d32bf7c7a, which merges main 39ccb1d3b (2ba558556), ports the verifier to main's VerifierFixture, command owner, interruption and output-schema conventions (7a1bc561d), and names Ghidra 12.2 as the verified release (d32bf7c7a). main now requires Ghidra 12.2 and JDK 25 (feat(ghidra)!: verify the bridge on Ghidra 12.2 #12081), keeps specs in PR discussion instead of docs/specs (docs: remove tracked planning and architecture records #12856), drops -vN from profile-only values (refactor(providers)!: key Ghidra and Hopper analysis profiles on the producer identity instead of hand-bumped markers #11320), and moved Evidence subjects and snapshot targets under identity (feat(evidence)!: name the Evidence subject by its target identity (format revision 2) #11416); this head follows each. On Ghidra 12.2 with JDK 25 (Linux x64 container, Node 24.22.1, Espressif GCC 14.2.0): npm run check:fast, build:cached and docs:check passed; npm run test:focused passed 3,020 tests with 1 failure, the same root-only kunaProvider case; verify:ghidra:bridge-sources passed; and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed, "mocked": false, cleanup complete. Ghidra 12.2 decompiles the entry and C fixtures exactly as the recorded 12.1.4 samples show. CI on d32bf7c7a: 30 checks passed, 23 skipped, none failed.
  • On the head fabeb9734, which merges main fb453f293. 122a3dc00 merged main 560674e2d, where feat(native): report binary hardening for ELF, PE and Mach-O #8524 added the same section alignment field with 1 for PE; this PR takes that value, because elfNoteAlignment gives 4 for 0 and 1 and only ELF sections are read. No Ghidra digest pin changed.
    • npm run check:fast, format:check, docs:check, knip and 68 test files (this PR's, src/ghidra, src/contracts and toolSchemaValidity; 1,534 passed, 3 skipped) passed. CI passed on this head.
    • On 122a3dc00: verify:ghidra:xtensa passed in a Linux container (Ghidra 12.1.4, Espressif GCC 14.2.0), "mocked": false, cleanup complete, and verify:ghidra:bridge-sources passed. main changed no Ghidra, bridge or verifier file between the two merges, so they did not run again on fabeb9734.
  • On 01d819be6, after 20555a992 merged main c3647ade1 without conflicts: npm run check:fast and docs:check passed, and REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed on Ghidra 12.1.4 (Linux container, Espressif GCC 14.2.0, not mocked, cleanup complete), finding the compiled l32r 81fcff at 0x400082. On 963d2da36, the 5 test files of the .xtensa.info reader, the section directory, the note parser and the Xtensa profile passed (123 tests); the 8-aligned note test fails with alignment fixed at 4. CI passed on 01d819be6.
  • On af09c9fda, whose tests check refusals by the facts they name rather than their wording (macOS arm64, Node 24.22.1): npm run check:fast passed, and npm run test:focused over this PR's 8 test files passed (139 tests). Rewording three refusals passes the three affected test files; admitting big-endian, call0 or absolute literals, or dropping the reader's diagnostic, fails 15 tests. CI on 74908378a failed only where main's own CI on 0354145a2 and 6d60db195 fails: format:check on 16 unformatted files, and the Frida cases of providerVerifierCleanup.test.ts, whose stub provides dist/contracts/fridaRemoteAddress.js while scripts/verify-frida.mjs imports dist/domain/fridaRemoteAddress.js.
  • On 74908378a, which refuses absolute literals after fed438458 merged main 0354145a2 (macOS arm64, Node 24.22.1): npm run check:fast and docs:check passed, and npm run test:focused over this PR's 8 test files passed (139 tests). Before its last edit, a verifier check label, npx knip was clean and 20 files with the Ghidra profile, provider, client and target-resolution tests passed (719 tests). format:check reports only 16 files byte-identical to main 0354145a2, which fails the same check; CI's Static checks failed on fed438458 for that reason.
  • On b8722fd58, three review fixes on 2197f202b (macOS arm64, Node 24.22.1): npm run check:fast, format:check, docs:check, verify:module-boundaries, verify:test-discovery (2,941 files) and lint:typed passed, and npm run test:focused over this PR's 8 test files passed (131 tests). npx knip reports only DarwinHelperCache, as on main. CI passed (run).
  • On 2197f202b, which merges main 6e9ee97a6 (macOS arm64, Node 24.22.1): npm run check:fast, format:check, docs:check and verify:module-boundaries passed. npm run test:focused over 43 files: 1,105 passed, 2 skipped. The files are this PR's tests and the tests of the modules that this PR or the merge changes: ELF target resolution for MIPS, RISC-V, PowerPC and Xtensa, ELF notes, the Ghidra profiles and client, and Hopper and IDA admission. npx knip reports one unused exported type, DarwinHelperCache, which it also reports on main 6e9ee97a6. CI passed (run).
  • CI passed on the previous head cb6fdfe8f, which merged main c0c390220 (run).
  • Real Ghidra 12.1.4, Linux x64 container (OpenJDK 21.0.12, Node 24.22.1): REA_XTENSA_CC=xtensa-esp32-elf-gcc npm run verify:ghidra:xtensa passed on af09c9fda and 74908378a (2 Nov, Espressif GCC 14.2.0, GNU readelf 2.44; their five refusals include the USE_ABSOLUTE_LITERALS=1 copy), on 3929ae21e (1 Nov, same tools, with the lane's commands owned; b8722fd58 adds only a refusal the lane does not exercise), on 2197f202b (1 Nov, same tools), on cb6fdfe8f (30 Oct, same tools), on 93c39da8a (dataflow checks) with GNU readelf, and on e3df5cca2 with GNU readelf 2.44 and with llvm-readelf (LLVM 19). Both fixtures passed each time; no descendant processes; cleanup complete.
  • Earlier heads passed check:fast, docs:check, lint:typed, test discovery and the local and focused tests; npm run check passed except knip, which reports three exports already unused on main.
  • Not run: check:pr, macOS real-Ghidra lanes, and Windows.

Compatibility, safety, and release

  • Breaking changes: none intended; C1 is additive (release note).
  • Real coverage: Ghidra 12.2 with JDK 25 on Linux x64. Earlier runs used Ghidra 12.1.4, which main no longer accepts; 12.2 ships the same Xtensa SLEIGH and compiler-spec sources.
  • Gaps: SALT/SALTU truncation on ESP32-S3; call-site argument values; DWARF-applied default analysis not measured.
  • Security and containment: reads stay in the resolver's descriptor within explicit bounds; no new processes, network access or writes.

Author readiness

Human owner: @Entrpi

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Recognize EM_XTENSA (94) as the provider-neutral `xtensa` family with its
ELF class, byte order, e_type and e_flags, so ESP32, ESP32-S2 and ESP32-S3
builds are no longer refused as an unsupported ELF architecture. Xtensa
e_flags carry no ABI, so target resolution reads the `ABI=` declaration in
the `.xtensa.info` note that GNU as and ld write. Section names come from
the native section directory that already owns them, and the note is
walked by a shared ELF note reader that `inspect_elf_notes` now also uses,
so both apply the same padding and bounds rules.

Ghidra admits little-endian ELF32 ET_EXEC with known e_flags (machine field
0, XT_INSN, XT_LIT) that declares the windowed ABI. It pins
Xtensa:LE:32:default with the `default` compiler specification, because
xtensa.ldefs defines no `gcc` id, and the session handshake asserts that
language after import. ELF64, big-endian, ET_REL and ET_DYN, unknown flag
bits, a non-zero machine field, call0, undefined or missing ABI
declarations and an unreadable or malformed `.xtensa.info` are refused with
specific reasons. Every result carries an unverified-lane limitation until
a real-Ghidra lane exists.

Hopper and IDA name Xtensa when they decline it. IDA labels move to a typed
map, so a new family can no longer be labelled "Hexagon", and Hopper no
longer calls the Ghidra profile it recommends "verified".

Output changes for machine 94: the Evidence subject, snapshot target and
live target summary enums gain `xtensa`; Go and Rust reports and the
`inspect_native_exports` report say `xtensa` instead of `elf-machine-94`;
and the Evidence subjects of `inspect_go_binary`, `inspect_rust_binary`,
`inspect_elf_notes` and `inspect_kernel_module` gain
`architecture: "xtensa"`.

Refs morluto#3483
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no blocking findings remain.

Summary

The PR adds a bounded Xtensa ELF lane with pinned Ghidra language and compiler choices. The latest change fixes the reported narrowing-cast gap in its verification checks.

  • Xtensa ELF files keep their architecture and declared format facts.
  • Ghidra opens only Xtensa ELF files with verified declarations.
  • A Ghidra verification lane exercises Xtensa imports and results.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  ELF["Xtensa ELF"] --> Notes["Read .xtensa.info within bounds"]
  Notes --> Gate{"Declarations supported?"}
  Gate -->|No| Refusal["Return specific refusal"]
  Gate -->|Yes| Pin["Pin language and compiler"]
  Pin --> Import["Import private copy"]
  Import --> Check{"Imported choices match?"}
  Check -->|No| Reject["Reject session"]
  Check -->|Yes| Evidence["Return evidence with limitations"]
Loading

Reviews (36) · Last reviewed commit: "test(ghidra): keep narrowing casts in Xt..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraAnalysisProfile.ts Resolved
Comment thread src/ghidra/GhidraXtensaProfile.test.ts Resolved
Comment thread src/application/XtensaElfMetadata.ts Resolved
…dir owner

xtensaInstallation created its own temporary root and deletion hook. It now
uses createTestTempDirectory, which docs/testing.md requires for exact-path
cleanup. The Windows drive-relative path handling is dropped: this test is
not in the curated Windows lane, and GhidraDolProfile.test.ts already builds
its language fixture the same way.
…verrides

With only REA_GHIDRA_LANGUAGE_ID=Xtensa:LE:32:default set, the profile
recorded `language-default`, the launch passed no -cspec, and the session
check left expectedCompilerSpecId unset, so the pinned `default`
specification was no longer enforced.

ghidraEffectiveLanguageOverride resolves such a partial override against the
Xtensa pin once. The committed profile, and therefore the launch, and the
session-open comparison all use that result.

The same gap exists in the older RISC-V, MIPS and PowerPC pinned lanes on
main. Their committed `language-default` profiles are left unchanged,
because changing them would alter persisted profile identity.
An oversized `.xtensa.info` was refused with a sentence that named the
4096-byte bound but not that callers cannot raise it. The declaration now
carries structured limit facts (boundary, maximum and declared bytes, and
`runtime_override: false`). The reason says this release has no runtime
override and that runtime analysis settings do not raise the bound, as
docs/design/limits-and-recovery.md requires. Tests assert the facts, not
the sentence.
`npm run verify:ghidra:xtensa` writes a windowed-ABI Xtensa ELF from
annotated instruction bytes (entry, l32r, call8, retw.n), so the base lane
needs no Xtensa compiler. GNU or LLVM readelf is the independent oracle for
the header, symbols and the `.xtensa.info` ABI.

Through the public stdio MCP server and CLI, with every result validated
against the advertised output schema, it checks the pinned
Xtensa:LE:32:default/default identity; decoding of each instruction, the
call8 target and the l32r literal reference; decompiled code that passes the
literal through call8 and returns the callee's result; snapshot save and
reopen; refusals for header-mutated copies (unknown flag bits, machine
field, ET_DYN, call0); unchanged source bytes; and owned cleanup.

REA_XTENSA_CC adds a C fixture built with Espressif's GCC and checks its
call8 callee and l32r constant in decompiled code.

Refs morluto#3483
…red scope

verify:ghidra:xtensa now checks this lane against Ghidra 12.1.4, so results
no longer say that no real-Ghidra lane exists. The limitation states what the
lane establishes (windowed-call fixtures) and that decompiled code for other
images is not verified function by function.

REA also measured Ghidra 12.1.4 on ESP-IDF 5.5.2 hello_world builds with the
DWARF analyzer disabled. It found every DWARF function, 1376 of 1377 (ESP32)
and 1559 of 1598 (ESP32-S3) direct call edges, and matched 653 of 709 and
802 of 881 decompiled parameter counts. On ESP32-S3, 36 of the 39 missed
edges are in functions that use SALT/SALTU, which Ghidra does not decode
(Ghidra morluto#9095), so that gap is now labelled measured rather than reported
upstream. The guide records the method and results; the images are not
committed.

Refs morluto#3483
…ine test

The real-Ghidra Xtensa lane now verifies the Ghidra lane, so Hopper's
decline advice may call that lane verified. The test still requires the
reason to name Xtensa and point at Ghidra. Also reword the health-result
comment that still called the limitations an unverified-lane note.
Comment thread src/ghidra/GhidraXtensaProfile.test.ts Resolved
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 27, 2026
# Conflicts:
#	tests/conformance/ghidra/README.md
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 27, 2026
With the real-Ghidra Xtensa lane in morluto#7486, Hopper's declined
family table marks Xtensa verified, like MIPS, RISC-V and PowerPC. The
table comes from morluto#7484, so whichever of the two lands second
carries this line.
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 27, 2026
@greptile-apps

greptile-apps Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

The pseudocode check matched the callee name and the l32r literal
anywhere in the caller, so a decompilation that returned the literal or
dropped the call result still passed. The C fixture check only looked
for the constant in the callee and did not decompile the caller.

Parse each straight-line function into parameters and statements and
assert the dataflow: the caller passes exactly the expected operands to
its single call and returns the result, directly or through a temporary
nothing reassigns; the leaf returns its argument plus the addend; the C
callee returns value * factor plus its constant. Casts, redundant
parentheses, operand order and integer radix may vary.
The limitation test froze explanatory sentences, array positions and a
banned obsolete phrase, so a harmless rewording failed it. Compare the
limitations a result delivers with ghidraXtensaLimitations, and assert
two facts independently: the pinned language id, and the SALT/SALTU gap
under the "Measured by REA" provenance label.
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 27, 2026
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 28, 2026
Q11 meets Xtensa (morluto#7486) and the Cortex-M raw load branch:

- readElfMetadata keeps both architecture steps: Xtensa reads the
  .xtensa.info ABI, RISC-V reads the .riscv.attributes ISA declaration.
- The ELF parser, provider client and RISC-V profile test import both
  branches' names; docs/testing.md lists both lanes.
- Q11's launcher test builds its conflicting raw import with the
  entryPoint that the Cortex-M branch made required beside baseAddr.
Real ESP-IDF 5.5 app ELFs make the default complete results large and
the first Ghidra query slow. Point agents at summaries and
inspect_analysis_view pages, give the measured first-query times and
the MCP timeout they exceed, and state that each CLI command repeats
the analysis.

A repeated `rea decompile --procedure app_main` with the same
`--snapshot` ran the full analysis again (54.4 s on the ESP32 app, and
16.5 s on both runs on an ESP-IDF hello_world), while a repeated
`rea analyze` replayed its snapshot (18.3 s, then 0.9 s).
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 28, 2026
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 28, 2026
Q10's ARM DWARF calling-convention correction meets Q11's RISC-V one,
Xtensa (morluto#7486) and the comparison and ESP branches:

- Both calling-convention reports stay: the bridge writes each, the
  session schema accepts both, and the provider client chains the MIPS
  soft-float, RISC-V and ARM DWARF failures into one reason.
- readElfMetadata keeps all three architecture steps (Xtensa ABI, RISC-V
  ISA, ARM build attributes); the pinned-language chain adds the ARM
  M-profile pin before PowerPC and Xtensa.
- The override rule in docs/ghidra-provider.md lists Xtensa among the
  pins that refuse a different override, as morluto#7486 does.
- Bridge sources, the package file list, the lane table and the docs
  index list both branches' entries.
@Entrpi
Entrpi marked this pull request as ready for review October 28, 2026 14:41
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T06:12:36.714832Z 6645fcd 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: 34363348e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/application/XtensaElfMetadata.ts Resolved
…adable

readElfSectionDirectory reports a section_names_limitation when a name
offset is outside its string table or the table cannot be read. The reader
consulted it only when no .xtensa.info was visible, so one visible note was
accepted as the declaration although an unreadable name could hide a second
.xtensa.info. Uniqueness, and with it the declaration, now stays unavailable
whenever a section name is unreadable.

@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: cfb66dfb42

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/ghidra/GhidraProviderClient.ts Resolved
Every admitted Xtensa ELF pins Xtensa:LE:32:default, so the language
checks accepted a profile resolved for another image, such as one with
e_flags 0 instead of 0x300, and every Evidence record then carried the first
image's xtensa_elf facts. The client now compares the committed xtensa_elf
facts and lane with those the current target produces before startup, as it
already does for MIPS, and refuses a mismatch without launching Ghidra.
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 28, 2026
# Conflicts:
#	src/ghidra/GhidraProviderClient.ts
…command owner

Main now requires every verifier to allocate its root through
VerifierFixture, validate tools against the canonical output schemas, and
refuse a host without its fixture toolchain before allocating. The Xtensa
lane now does all three: readelf is declared as the xtensa lane's toolchain
(REA_XTENSA_READELF still selects it), its commands run through the shared
owner with SIGINT/SIGTERM interruption, and a failed run retains its
workspace.

Main also removed the -vN suffix from runtime-selected profile values, so
the Xtensa profile records language_selection provider-pinned/configured
and lane elf32-le-exec-windowed-generic. The .xtensa.info refusal test now
uses an ET_EXEC header so it reaches the ABI check rather than the e_type
refusal.

Main also names the Evidence subject and snapshot target by their
identity (morluto#11416), so the lane reads subject.identity and
target.identity.
verify:ghidra:xtensa passes on Ghidra 12.2 with JDK 25 for both the
annotated-instruction and the Espressif GCC fixtures, and the entry and
C-fixture pseudocode match the 12.1.4 recordings. The runtime limitations,
the language pin note and the conformance README now name 12.2. The
SALT/SALTU measurement stays attributed to 12.1.4, whose Xtensa language
sources 12.2 ships unchanged.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 22, 2026
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 22, 2026

@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: 5cf6688ff5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 22, 2026
… returning

The leaf and C-callee checks compared only the returned expression, so
decompiled output that reassigned a parameter first still passed and the
report claimed dataflow the pseudocode did not show. Reject any write to
a parameter, and share the write test with the call-result check, which
now also catches increments and decrements.
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 23, 2026

@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: 1a0e6515de

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

… checks

The previous fix matched writes to a parameter or call-result temporary
with a regex, which missed lvalue spellings such as (param_1) = ... or
*(&param_1) = .... Check the structure instead: the leaf and C callee may
hold only declarations and their return, and a caller's assignment from
the call must be followed directly by the return of that temporary. Any
intervening statement, however written, is refused, and the write regex
is gone.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 23, 2026
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 23, 2026

@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: a40564b7c1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

decompiledFunction claimed a straight-line body but accepted labels,
jumps and braceless branches, so a caller printed as
`goto done; return leaf(...); done: return 0;` still passed and the lane
reported a returned call that the observed path skips. It now refuses
any label, goto, branch or loop statement and requires the body's only
return to be its last statement, which every dataflow check relies on.
operand stripped every cast before comparing, so
rea_xtensa_leaf((char)0x12345678) read as passing 0x12345678 and
(char)param_1 + 7 as returning the argument plus 7, though both compute
a different value. Strip only casts to a 32-bit integer type of Xtensa's
ILP32 ABI; any other cast stays in the operand's text, so the check
cannot match through it. Split the windowed and C dataflow tests into
their own blocks.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 23, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for the contribution! Closing this PR because Xtensa ELF (EM_XTENSA, machine 94) admission through Ghidra has already landed on main in #11178 (1995ab7fce, updating src/domain/elfFixedHeader.ts, src/ghidra/GhidraProvider.ts, and src/ghidra/GhidraProvider.behavior.test.ts), and the referenced issue #3483 has been closed as completed.

@morluto morluto closed this Nov 24, 2026
morluto added a commit that referenced this pull request Nov 24, 2026
…on (#8401)

* feat(ghidra): record the RISC-V float-ABI calling-convention decision

Decision D3 (#7477), provisional: admit ELF32 soft-float (ilp32) RISC-V
images through a lane that keeps the pinned RISCV:LE:32:default language and
corrects the calling convention in the bridge.

This commit is the contract only; admission is unchanged.

- The domain owns the e_flags float-ABI vocabulary and parses
  .riscv.attributes and Tag_RISCV_arch into a declared, absent or
  unavailable ISA declaration.
- The Ghidra profile owns the lane table (class and float ABI), lane ids
  built from fields, the ilp32-prototype-v1 policy and its __rea_ilp32
  prototype, and the extensions Ghidra 12.1.4 decodes with p-code.
- The session handshake accepts the bridge's calling-convention report.
- docs/ghidra-riscv.md keeps the decision record and per-ABI policies for
  ilp32 and ilp32f; a test keeps it in step with the tables.
- tests/conformance/c/riscv-float-abi.c is the source the policies were
  measured on.

* feat(ghidra): admit RISC-V ilp32 ELF with a derived calling convention

ESP32-C2, C3, C5, C6, C61, H2 and H21 builds are ELF32 soft-float (ilp32)
images, which the RISC-V lane refused at its double-float check. Ghidra
12.1.4's generic RV32 compiler specification models ilp32d, so its stock
prototype would read float and double arguments from fa0-fa7.

- Target resolution reads the one SHT_RISCV_ATTRIBUTES section through the
  same bounded ELF declaration reader as range validation, and records
  Tag_RISCV_arch as declared, absent or unavailable.
- Admission selects a lane from the class and float-ABI table. The soft-float
  lane also requires an RV32I Tag_RISCV_arch that declares only extensions
  Ghidra decodes with p-code; the refusal names any others (Zcb, Zcmp, Zcmt,
  Zb*, xesp*).
- Soft-float profiles commit float_abi, arch, riscv_calling_convention
  ilp32-prototype-v1 and the lane elf32-exec-le-soft-float-generic-v1.
  Double-float profiles are unchanged.
- ReaGhidraRiscvCallingConvention.java runs after analysis. It derives
  __rea_ilp32 from the default prototype without floating-point entries and
  rules, with fs0-fs11 killed by calls, self-checks its storage and assigns
  it to every non-thunk function, external function and function
  definition. Its report is written last.
- The provider client requires that report exactly when the profile commits
  the policy, before any operation, and keeps it as session limitations and
  caller-project history.

ELF32 single-float (ilp32f), quad-float and ELF64 soft- or single-float
images stay refused, now with a reason built from the lane table.

* test(ghidra): verify RISC-V ilp32 against real Ghidra

verify:ghidra:riscv now also builds tests/conformance/c/riscv-float-abi.c
with ESP32-C3's -march=rv32imc_zicsr_zifencei -mabi=ilp32, typed with DWARF
and linked again with --strip-all. Every allocated section of the stripped
image must keep its address and bytes.

- riscv-checks.mjs holds the ilp32 storage of each fixture function together
  with the words the compiler's call site writes there. An LLVM objdump
  reading of the caller must find every word at its stated location: an
  unaligned named double, the a7/stack split, two floats in an integer pair,
  a large structure by reference, aligned variadic pairs and an indirect
  call.
- Through CLI and stdio MCP, the soft-float builds must report the soft-float
  lane and ilp32-prototype-v1, __rea_ilp32 with exactly that storage (one
  integer word per location when stripped), caller pseudocode that passes the
  source constants and names no floating-point register, the prototype
  outcome in retained Evidence, and decoded fence.i and csrr.
- The RV32 double-float image relabelled as soft-float, refused before, is
  admitted through the new lane. RV64 soft-float, single-float and unsupported
  bits are refused with their reasons.
- riscv-checks.test.ts runs the checks offline against recorded LLVM and
  Ghidra output, including Ghidra's stock ilp32d prototypes as a negative
  control.

* fix(ghidra): pass RISC-V ilp32 values over 8 bytes by reference

The psABI passes any value wider than 2 x XLEN by reference, scalars
included. __rea_ilp32 converted only structures and unions over 8 bytes to
pointers, so a long double (16 bytes) was joined into a1-a4. Measured on
Ghidra 12.1.4, rea_riscv_abi_quad(long double value, int sel) read value
from a4:4,a3:4,a2:4,a1:4 and sel from a5, where clang passes a pointer in
a1 and sel in a2.

- ReaGhidraRiscvCallingConvention.java now has one derivation driven by a
  per-policy row (floating-point entry size, preserved floating-point
  registers). Every policy inserts a rule before the input list's final
  join that converts any value of 9 bytes or more to a pointer; a return
  that size already becomes a caller buffer. The self-check requires a
  16-byte value to pass by reference.
- The fixture gains rea_riscv_abi_quad. The call-site oracle now checks the
  words the by-reference pointers point at, for the large structure and the
  long double, and the recorded data comes from an LLVM 19 build.
- docs/ghidra-riscv.md: the decision record and the ilp32 policy row.

ilp32-prototype-v1 keeps its id: no release carries it yet.

* feat(ghidra): record the RISC-V ilp32f calling-convention decision

Decision D3 (#7477), provisional, gains its ilp32f row: ELF32 images that
declare the single-float ABI are admitted through the lane
elf32-exec-le-single-float-generic-v1 with policy ilp32f-prototype-v1 and
the __rea_ilp32f prototype, keeping the pinned RISCV:LE:32:default language.

- The lane table gains the row, and admission requires the F extension in
  Tag_RISCV_arch beside the decoded-extension check.
- docs/ghidra-riscv.md records how the one-float-one-integer rule is
  realised: the shared derivation's row limits float entries to 4 bytes,
  keeps fs0-fs11 preserved and adds Ghidra 12.1.4's join_dual_class with
  fillalternate for structures of up to 8 bytes. The prototype is the only
  thing that assigns storage: a check of every typed function and
  function-pointer type against the psABI refuses the image when one uses a
  shape the prototype misplaces (a float with two shorts, a pointer or a
  union, _Float16, packed or over-aligned float structures). float _Complex,
  which Ghidra imports as a qword, stays unmodelled. Custom storage for typed
  functions and an unverified-signature admission are recorded alternatives.
- The session report for ilp32f can carry the bridge's refusal instead of
  the outcome; the handshake turns it into the user-facing reason.
- tests/conformance/c/riscv-float-abi.c gains single-float-only shapes and a
  refused variant; the ilp32 build's code is unchanged.

Until the bridge implements the policy (next commit), its post-analysis
script rejects the new policy id and REA refuses ilp32f sessions.

* feat(ghidra): apply the RISC-V ilp32f calling convention in the bridge

ReaGhidraRiscvCallingConvention.java gains ilp32f-prototype-v1 as a row of
its one derivation: float entries limited to 4 bytes, fs0-fs11 preserved,
and structures that Ghidra's dual-class join splits between register files.
The ilp32 row and its checks are unchanged.

- For that row the derivation inserts, before the input and output lists'
  final join, a rule giving structures of up to 8 bytes join_dual_class
  with fillalternate. The shared rule still passes values of 9 bytes or
  more by reference.
- The self-check also pins the storage of a float, double, two-float and
  float-and-int signature, and requires fs0-fs11 preserved.
- After assigning the prototype to every function and function definition,
  the script compares the storage class it gives each signature type, as a
  first argument or return, with the psABI's from the flattened fields. It
  checks every typed function and every definition a pointer type refers
  to. When any signature uses a shape the prototype misplaces, the report
  carries a refusal naming up to eight signatures instead of the outcome,
  and REA refuses the session with that reason.

The launcher test covers both policy ids.

* test(ghidra): verify RISC-V ilp32f against real Ghidra

verify:ghidra:riscv now also builds tests/conformance/c/riscv-float-abi.c
with ESP32-H4's -march=rv32imafc_zicsr_zifencei -mabi=ilp32f, typed with
DWARF and linked again with --strip-all, and a typed build with
REA_RISCV_ABI_UNMODELLED that the bridge must refuse.

- riscv-checks.mjs holds per-ABI tables: the ilp32 and ilp32f storage of
  each fixture function with the words its caller's call site writes there
  (and, for by-reference values, the words the pointer points at), the
  callers, and the indirect calls. Stripped builds record where Ghidra's
  inference differs from one word per typed location.
- The objdump call-site oracle now follows fa registers (flw, fsw, fmv.w.x)
  and tracks stack memory per byte, so word loads see byte and halfword
  stores, across both callers.
- Through CLI and stdio MCP the single-float builds must report the lane,
  ilp32f-prototype-v1 and __rea_ilp32f with the table's storage, including
  float-and-integer structures both ways round, float registers running
  out, long double by reference and an indirect float-and-integer call.
- riscv-isa-probe.S adds fmv.w.x and fmv.x.w when the build has F.
- The unmodelled build opens, then its first analysis call over MCP and the
  CLI fails with the bridge's reason naming its three signatures: a
  function passing a three-field structure, a _Float16 function and a
  function-pointer type passing the three-field structure.
- Header mutations: RV32 double-float relabelled single-float is admitted;
  the soft-float image relabelled single-float lacks F and is refused; RV64
  lp64f and high bits are refused.

* test(ghidra): check RISC-V lane limitations by their facts

The limitation tests froze a full explanatory sentence, the note count and
array positions, so a harmless rewording failed them: the pattern Greptile
flagged on #7486. Assert the facts the notes must carry instead: the pinned
language, the static-linkage boundary, one note naming the declared ABI,
the ABI the pinned language models and the prototype REA applies, and the
declared ISA.

* test(ghidra): check the ilp32f limitations by their facts

Like the ilp32 tests, the ilp32f test froze its explanatory sentence, the
note count and array positions. Assert one note naming the declared ilp32f
ABI, the modelled ilp32d and the applied `__rea_ilp32f` prototype, and the
declared ISA.

* test(ghidra): check return storage in stripped RISC-V ilp32 builds

The stripped branch of assertRiscvIlp32Storage compared parameter storage
only, so an inferred return that lost the high word of a register pair,
such as rea_riscv_abi_wide at a0:4 instead of a1:4,a0:4, still passed.

Stripped returns must now use the typed build's storage, or none when the
result goes through caller memory. Recovered type names are still not
compared: a test accepts other type names and refuses the dropped high word.

* docs(ghidra): record decision D3 as decided in #7477

* fix(ghidra): flatten RISC-V arrays and bit-fields as the psABI does

The ilp32f signature check flattened a by-value type differently from
GCC and Clang in two shapes. A nonzero array of empty C++ classes added
no fields, so struct { E e[1]; char c; float f; } looked like a char and
a float, and the policy admitted a float-and-integer split for a value
both compilers pass in two integer registers. A bit-field was bounded by
its declared type, so a float beside unsigned long long b : 1 used the
integer convention, and the image was refused although __rea_ilp32f
places it as the compilers do. An array element with no fields now makes
the array use the integer convention, and a bit-field counts by its
width.

Arrays are also classified once per element type, so an array of empty
structures no longer costs one visit per element, and a refusal keeps
its counts and at most eight shortened examples instead of every
description.

The unmodelled build gains a C++ source with the empty-class array,
which the refusal must name, and a bit-field function it must not.

* fix(ghidra): refuse flexible array members in ilp32f signatures

A float beside a flexible array member flattened to a single float, so
the policy admitted fa0 for a value Clang passes in a0. Ghidra imports
the member as a trailing array without elements, which the walk skipped
as a zero-length member. A trailing array without elements now makes the
value use the integer convention. Ghidra imports a trailing [0] the same
way, and Clang passes that in fa0, so such a structure fails closed too.
The unmodelled build gains a flexible-array function the refusal must
name.

* docs(ghidra): state that hidden-reference C++ classes are not modelled

Compilers pass a C++ class with a non-trivial copy constructor or
destructor through a hidden pointer, but Ghidra 12.1.4 keeps only its
fields, and GCC 14.2 writes no DW_AT_calling_convention, so the ilp32f
check cannot detect such a signature. Sessions now state this as a
limitation, and the guide lists it as not modelled.

* fix(ghidra): refuse ilp32f shapes and D hardware the prototype misplaces

A flexible array that starts inside a structure's padding passed the
offset check, so its float took fa0 where GCC and Clang use a0. The
position among the members now decides. A bare array in a signature can
only be a GNU vector, which uses the integer convention, so the policy
stops flattening it.

With D the ABI preserves only the low 32 bits of fs0-fs11 and Ghidra's
model preserves all 64, so the lane refuses d and zcd.

Ghidra's import erases float _Complex, a vector inside a structure and
_Atomic, so ilp32f sessions now state those limits.

* fix(ghidra): refuse ilp32f values Ghidra left untyped

Ghidra's DWARF import gives an encoding it does not map an untyped
byte, word, dword or qword, so float _Complex, which takes two float
registers, showed as an integer in a0 and a1. The policy cannot know
such a value's class, so it now refuses any value of up to 8 bytes that
holds one, alone or inside a structure. The session limitation no
longer lists complex values.

* docs(ghidra): match the RISC-V verification notes to the lane

* fix(ghidra): refuse padded untyped RISC-V values

An over-aligned structure of one float _Complex is 16 bytes, so the
8-byte guard let it fall through to a reference, although GCC and Clang
pass it in fa0 and fa1. Decide on the bytes the fields hold, which is
what the float convention limits, not on the padded length.

* fix(ghidra): walk each RISC-V field type once

The held-bytes and untyped checks revisited a nested type for every
member, so a chain of structures that each hold two of the last one
cost about 2^29 calls before any size check. One cached walk now
answers both, once per type.

* fix(ghidra): refuse ilp32f values whose bytes may hide a bit-field

DWARF omits unnamed bit-fields of nonzero width, which the psABI counts:
Clang 19 passes struct { float f; unsigned : 1; } in fa0 and a0, and a
following int in a1, while Ghidra sees one float in 8 bytes. A value
with a float whose structure has bytes that no member and no natural
alignment padding explain now has an unknown class, so the policy
refuses the image. Over-aligned structures of up to 8 bytes are refused
too. verify:ghidra:riscv's unmodelled build passes such a structure.

* perf(ghidra): cache the ilp32f layout checks per type, document padding

unexplainedBytes and naturalAlignment recomputed nested types on every
chain, so a deeper nesting cost quadratically more. Both now keep one
result per stripped DataType, as held() does.

The guide now states that an unnamed bit-field in natural padding, as in
struct { char c; unsigned : 1; float f; }, leaves no DWARF trace: Clang 19
passes it in a0 and a1 but the lane admits it with the float in fa0.
Refusing every padded float value would also refuse common layouts.

* fix(ghidra): refuse ilp32f union parameters that may be transparent

A transparent union passes as its first member, but DWARF does not record
the attribute: Clang 19 passes union { struct { float f; } s; unsigned u; }
with transparent_union in fa0, while Ghidra and the psABI class see an
ordinary union in a0, so the lane admitted wrong storage. A union parameter
whose first member would take a float register now refuses the policy,
unless Clang would ignore the attribute: a floating-point first member, or
another member of a different size or alignment. Returns are unaffected.
verify:ghidra:riscv's unmodelled build passes one such union and three
ordinary ones.

* fix(ghidra): refuse ilp32f float parameters of old-style C definitions

Callers of an old-style (K&R) definition such as float f(x) float x;
promote the argument to double: Clang 19 passes it in integer registers
and narrows it with __truncdfsf2. DWARF still declares a float and only
omits DW_AT_prototyped, which Ghidra 12.1.4's DWARF import drops, so the
lane placed it in fa0. When a typed signature has a float parameter, the
script now reads DWARF again for C subprograms without DW_AT_prototyped
and refuses the policy for their float parameters. C++ and other
languages never mark the attribute and are not checked.
verify:ghidra:riscv's unmodelled build passes one such definition.

* fix(ghidra): admit a direct C++ empty-class member in an ilp32f structure

Ghidra imports a C++ empty class as a one-byte structure without
components, so the unexplained-bytes check counted its byte as an omitted
field. A structure such as `struct S { E e; char c; float f; }` was then
UNKNOWN and refused the whole ilp32f image, although GCC 14.2 (ESP-IDF)
and Clang 21.1.8 ignore the member when flattening and pass S in a0 and
fa0, the storage the derived float-and-integer rule gives it.

The check now treats a one-byte structure without components as that
storage. A nonzero array of empty classes still uses the integer
convention and stays refused. The unmodelled fixture gains
rea_riscv_abi_member, which the real-Ghidra verifier requires to be
admitted, and the guide names the shape.

* fix(ghidra): refuse RISC-V functions compiled from a language without the C psABI

Both RISC-V calling-convention policies apply a C psABI prototype to every
function, so code from a language with another calling convention, such as
Rust's default ABI, was silently given the wrong storage. Before either
policy installs its prototype, the bridge now reads the image's DWARF once
and refuses the image when a compile unit outside C, C++ and assembly, or
one without DW_AT_language, defines a function with code, naming each
language. The same pass collects the old-style C definitions the ilp32f
check needs, which were read lazily before. This also changes main's ilp32
policy, which had no refusal path. Code that no DWARF compile unit
describes cannot be checked, and every session that applies a policy now
states that limitation.

* test(verify): refuse RISC-V fixtures whose C compile units are labelled Rust

The real RISC-V lane rewrites the DW_AT_language of each C compile unit in
the typed soft- and single-float builds to Rust, with a bounds-checked
reader of the units' abbreviations, and checks that each policy refuses the
image and names the language. The unlabelled builds are the controls.

* fix(ghidra): refuse ilp32f values whose register fields do not start their parts

The psABI puts each flattened field of a structure passed in float
registers at bit 0 of its own register, while __rea_ilp32f's dual-class
join gives each register a 4-byte part of the value as laid out in memory.
Both agree only when every such field starts its part. A C++ empty member
keeps its byte although the psABI ignores it as a field, so the char of
struct { E e; char c; float f; } passes in bits 0-7 of a0 while the
prototype reads bits 8-15; the policy compared only storage classes, which
match, and admitted it. Flattening now records each field's bit position,
and a value whose float-register fields do not each start their own part
is refused, which also covers packed layouts and bit-fields above bit 0.
The unmodelled fixture's caller now shows where the compiler puts that char.

* docs(ghidra): keep RISC-V guide focused on ABI rules and compatibility

---------

Co-authored-by: morluto <[email protected]>
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 enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants