Repository navigation
feat(ghidra): admit RISC-V ilp32 ELF with a derived calling convention - #8229
Conversation
Decision D3 (morluto#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.
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.
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.
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.
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 morluto#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.
Takes main d48e472, which includes the squash merges of morluto#7481-morluto#7485. Conflict, resolved: GhidraRiscvProfile.test.ts imports this branch's lane and policy tables plus ghidraRiscvUnsupportedReason, which morluto#7484's refusal-table assertions use; embedded-integration holds the same list. morluto#7484's readback test merges cleanly and appears once.
[Medium impact] No new merge-blocking issue was found in the documentation-only update. SummaryAdds an ELF32 RISC-V soft-float lane with a derived
Reviews (3) · Last reviewed commit: "docs(ghidra): record decision D3 as deci..." · Reviewed by Greptile |
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
e6d0618 (morluto#8228) is the parent of morluto#8229's squash e669365, which the next merge records. The merge is clean.
Recorded with -s ours: this branch already holds morluto#8229's final head d8ae325, and git patch-id --stable of the squash equals that of d8ae325's own patch (7bc824d8360616b7).
Take main 6e9ee97. morluto#8228's ESP flash inputs join D1's load selection: resolver, session and CLI options carry `loadSelection` and `espFlash`, and `formatHint` comes from the selection. `inspect-artifact` and `extract-artifact` now pass `--target-format esp-flash-image` as a load selection; built from spreads, the old `formatHint` key compiled but was dropped. The open_binary description keeps D1's M-profile sentence and morluto#8361's investigation-record ending. Tests from main move to D1's inputs, as embedded-integration did: morluto#7481's raw vocabulary target carries `rawLoad`, morluto#8228's flash resolver tests pass `loadSelection`, morluto#8229's raw scope case names its entry, and the pairing grid adds esp-flash-image's four rows while the other sixteen keep d6f88be's hash.
Part of the embedded firmware roadmap #7955.
Decision record: D3, RISC-V float ABIs (decided on #7477, 31 Oct 2026)
ET_EXECimages that declare the soft-float ABI (e_flagsfloat-ABI bits0, ilp32) are admitted through a new lane,elf32-exec-le-soft-float-generic-v1. Lane ids are built from their fields,elf<class>-exec-le-<float ABI>-float-generic-v1, so feat(ghidra): admit RISC-V position-independent executables (#4487) #4811's load model becomes one more field.RISCV:LE:32:defaultlanguage with thegcccompiler specification. Every RV32 language in Ghidra 12.1.4, including the deprecated soft-floatRV32I/RV32IC/RV32IMCvariants inold/riscv_deprecated.ldefs, uses the sameriscv.ilp32d.sladecoder; only the compiler specification differs. So REA corrects the calling convention, not the language.ilp32-prototype-v1), written per topic indocs/ghidra-riscv.md#ilp32:floatarguments:a0–a7, then 4-byte stack slots;doubleand other 8-byte scalars: a register pair, low word in the lower register, with no alignment for named arguments; with one register left, the low word ina7and the high word on the stack;a0;long double: by reference;s0–s11andsp; no floating-point register.ReaGhidraRiscvCallingConvention.javaderives__rea_ilp32from the program's own default prototype. It removes every floating-point argument and return entry and every rule that assigns floating-point storage, and movesfs0–fs11from the preserved list to the killed-by-call list. A rule before the input list's final join passes any value of 9 bytes or more by reference. One derivation serves every policy: a policy row sets the floating-point entries and preserved registers, and every row gets the by-reference rule, so ilp32f becomes one more row. The script installs the result as a specification extension and assigns it, with dynamic storage, to every non-thunk function, every external function and every function definition (the prototypes of indirect calls). Thunks follow their targets. The script fails, and writes no report, if the derived prototype or any function still uses a floating-point register, or if the prototype does not pass a 16-byte value by reference.riscv_calling_convention: ilp32-prototype-v1. The bridge reports{policy, functions, definitions}last, and REA requires that report exactly when the profile commits the policy, before serving any operation..riscv.attributesTag_RISCV_archwith an RV32I base and only extensions that Ghidra 12.1.4's generic RV32 language implements with p-code:m,a,f,d,c,zicsr,zifencei, and the subset nameszmmul,zaamo,zalrsc,zca,zcf,zcd. Anything else is refused and named. That covers Zcb, Zcmp and Zcmt (not decoded), Zb*, Zk* and P (draft encodings markedunimpl), and vendor extensions such asxesploop,xespvandxespdsp(custom-opcode placeholders only). A missing section or tag is refused because the extensions are unknown.riscv_elf.float_abi: "soft"andriscv_elf.archbeside the existingfloat_abi_doubleboolean. Double-float profiles keep their exact parameters, so their digests, sessions and snapshots do not change.docs/ghidra-riscv.md#ilp32f) and stays refused until it is implemented and verified; see "Not included". Quad-float, RVE, TSO and ELF64 soft- or single-float images stay refused.RISCV:LE:32:RV32IMCand others,riscv32.cspec): REA's catalog would have to readold/, the variants cover only I, IC and IMC, Ghidra marks them deprecated, and no stock specification models ilp32f.__rea_ilp32only to callables whose types use floating-point values, as the MIPS soft-float lane does: typed storage is identical, but prototypes Ghidra infers for untyped code keep the ilp32d model, which can still claimfa0in an ilp32 image that contains F or D instructions. Switching is one predicate in the script and a new policy id.Tag_RISCV_arch, or refuse a denylist of known extensions: a declaration REA cannot check would count as compatible. Widening the decoded set later is additive.float_abiandarchto double-float profiles too: one shape for all lanes, but every existing RISC-V session and snapshot is invalidated.src/domain/riscvIsaDeclaration.ts: thee_flagsfloat-ABI vocabulary, the.riscv.attributesandTag_RISCV_archparsers, and the section scan.src/ghidra/GhidraRiscvProfile.ts:GHIDRA_RISCV_LANES(admission and lane ids),GHIDRA_RISCV_CALLING_CONVENTIONS(policy ids, ABI and prototype) andGHIDRA_RISCV32_DECODED_EXTENSIONS.bridge/ghidra/ReaGhidraRiscvCallingConvention.java: how a policy becomes a Ghidra prototype.verify:ghidra:riscvanddocs/ghidra-riscv.md(a test keeps the docs in step with the tables). Later work reuses the table: ilp32f adds a row; RISC-V ESP images (F6) pick a row through D5.riscv_elf.float_abi,riscv_elf.archandriscv_calling_conventionare persisted in sessions, snapshots and Evidence. A changed derivation ships as a new policy id (ilp32-prototype-v2), which invalidates soft-float snapshots only.npm run verify:ghidra:riscv(Ghidra 12.1.4, JDK 21, LLVM with RISC-V: clang, lld, readelf, objdump).Summary
ESP32-C2, C3, C5, C6, C61, H2 and H21 builds are ELF32 ilp32 images, which REA refused at the RISC-V lane's double-float check. Ghidra's RV32 compiler specification models ilp32d: on Ghidra 12.1.4 its stock prototype decompiles this PR's fixture call
rea_riscv_abi_pick(1.5f, 2.5f, sel)asrea_riscv_abi_pick(in_fa0,in_fa1,0x3fc00000). With this PR it decompiles asrea_riscv_abi_pick(1.5,2.5,sel), and every argument of the fixture's calls sits where the compiler put it.now opens an ilp32 image in the soft-float lane if its
Tag_RISCV_archdeclares only decoded extensions, as ESP-IDF's base strings for these chips do; other extensions are refused by name.Refs #7477, #2063. Coordinates with #4811 (RISC-V PIE), which edits the same admission and profile functions. Follow-up: ilp32f (ESP32-P4, H4, S31) is stacked on this branch as
feat-ghidra-riscv-ilp32fand opens after it, as proposed in #7477.Problem and expected behavior
e_flags0x1(soft-float) was refused on ELF32 and ELF64.Tag_RISCV_archis admitted with__rea_ilp32; everything else is refused with a reason built from the lane table. Double-float behaviour and identity are unchanged.Change and scope
cc4e86e99: the D3 contract and its table-driven tests; no behaviour change.a11b43c35: admission: the.riscv.attributesscan (range validation's bounded reader, now one generic driver), the post-analysis script, and the handshake.4a097051a: the real lane, and offline tests of its checks.383b87cfb: values over 8 bytes by reference, as per-policy rows.bbe74105f,656badf1f:mainmerges (317bf3fe2,d48e472fa); the two launcher refusals became fix: report provider admission failures as typed codes #8066 typed codes.1515524b7: limitation tests check facts, not wording.d02fc6b78: stripped builds check return storage (review).d8ae325f1: docs record D3 as decided ([Design] Admit RISC-V ilp32 and ilp32f ELF in the Ghidra lane with a per-ABI calling-convention policy #7477).Not included: ilp32f (
EF_RISCV_FLOAT_ABI_SINGLE), the follow-up. With 4-byte floating-point entries, Ghidra 12.1.4 putsstruct { float; int; }ina1:a0instead offa0anda0. Also quad-float, RVE, TSO, ELF64 soft- or single-float,ET_DYN(#4811), and undecoded extensions.Remaining cleanup, for separate PRs
parseRiscvAttributesrepeats the attribute-section walk ofMipsGnuAttributes.ts(jscpd: 16 lines), and feat(ghidra): verify and pin the 32-bit ARM (armhf) lane #1922 adds ARM's. One shared reader would change the MIPS reader.ReaGhidraRiscvCallingConvention.javarepeats the encode, parse and serialize steps ofReaGhidraMipsSoftFloat.java. Sharing them changes the MIPS lane, which needs its own real-Ghidra run.storage="float"(observed on RISC-V), but the MIPS script removes entries whosemetatypeisfloat, so it removes only the rules. Its self-check still passes, because the rules decide typed storage.Contract and boundary impact
riscv.isa).existing_project_riscv_calling_convention(soft-float targets withREA_GHIDRA_PROJECT_PATH, whose project cannot run the post-analysis script) andriscv_calling_convention_scope(an internal guard).riscv_elf.float_abi,riscv_elf.archandriscv_calling_convention; session Evidence states the prototype and its counts. Double-float profiles are byte-identical (tested).docs/public/product-catalog.json), package, or installation impact: one bridge source inpackage.jsonfiles.Expected effects:
Evidence and regression coverage
mainrefuses every float ABI except double-float (GhidraRiscvProfile.ts:68-72atd48e472fa); observed, Ghidra 12.1.4's stock prototype reads the fixture's floating-point arguments fromfaregisters (below).-march); A, F and D under ilp32 are admitted but not exercised; not checked whether older RISC-V toolchains writeTag_RISCV_arch(images without it are refused).Per-file test coverage (counts on the head)
src/domain/riscvIsaDeclaration.test.ts(41 tests): everye_flagsfloat ABI and its psABI name; the attribute parser on LLVM 21's exact bytes in both byte orders, the psABI's tag-parity rule, and 13 malformed sections refused;Tag_RISCV_archstrings from LLVM, GCC/ESP-IDF and non-canonical spellings.src/ghidra/GhidraRiscvProfile.test.ts(49 tests): the lane-id and policy tables, and a check thatdocs/ghidra-riscv.mdnames every lane, policy, prototype and decoded extension; every refused declaration (ELF64 soft, single and quad; ELF32 single and quad; uninspected, absent and unavailable ISA declarations); ESP-IDF's bases admitted, and Zb*, Zcb, Zcmp, Zcmt,xesp*, RV32E, RV64 and non-canonical strings refused with the extensions named; the soft-float profile's exact parameters, and double-float profiles unchanged whatever the ISA declaration; a handshake with a fake bridge (the launch option, the outcome as a session limitation, a missing or unexpected report refused before any call, a policy mismatch refused before start, and caller-project history).src/ghidra/GhidraSessionValues.test.ts: the report accepted exactly; 7 malformed reports refused.tests/boundary/filesystem/riscvIsaDeclaration.test.ts(7 tests): hand-built ELF32 files with the attribute section beyond the 4 KiB probe: declared, absent, another vendor, two sections, an oversized section, and an undecoded extension.tests/boundary/providers/ghidra/ghidraLauncher.test.ts: the post-script's place and argument, and its conflicts with PSP, MIPS soft-float, DOS, raw, DOL and existing projects, by admission code.tests/conformance/ghidra/riscv-checks.test.ts(6 tests): the call-site oracle and the storage and pseudocode checks on recorded LLVM and Ghidra output. They refuse a moved argument, Ghidra's stock ilp32d model,long doublestorage without the by-reference rule, a wrong pointed-to word, and a strippedrea_riscv_abi_widereturn that loses its high word. Recovered type names are not compared.Base reproduction and a negative control
With Ghidra 12.1.4's stock prototype, the fixture's caller decompiles as:
Negative control for values over 8 bytes: without the by-reference rule, the prototype read
rea_riscv_abi_quad'slong doublefroma4:4,a3:4,a2:4,a1:4andselfroma5; clang passes a pointer ina1andselina2, as the derived prototype now reports.CLI output on this PR's tree
For the ilp32 build of the fixture (
-march=rv32imc_zicsr_zifencei), the committed profile:{"language_id":"RISCV:LE:32:default","compiler_spec_id":"gcc", "riscv_support_lane":"elf32-exec-le-soft-float-generic-v1", "riscv_calling_convention":"ilp32-prototype-v1", "riscv_elf":{"elf_class":32,"byte_order":"little","type":2,"flags":1, "float_abi_double":false,"rvc_declared":true,"rve_declared":false, "tso_declared":false,"float_abi":"soft", "arch":"rv32i2p1_m2p0_c2p0_zicsr2p0_zifencei2p0_zmmul1p0"}}An excerpt of the caller's pseudocode:
The limitations include "RISC-V calling-convention outcome: 13 functions and 12 function definitions use __rea_ilp32." The same source built with ESP-IDF's optional
_zcb_zcmpis refused before any provider starts:{"provider_id":"ghidra","origin":"target","code":"architecture_unsupported", "reason":"Tag_RISCV_arch declares extensions outside the set this lane decodes: zcb, zcmp. Ghidra 12.1.4's generic RV32 language implements only m, a, f, d, c, zicsr, zifencei, zmmul, zaamo, zalrsc, zca, zcf, zcd with p-code; see docs/ghidra-riscv.md."}Failed real runs on earlier heads
The first real run failed in the bridge. Untyped functions have unassigned return storage, so the script's storage check threw and wrote no report, and REA refused the session as designed. The check now allows unassigned storage for functions and stays strict for the prototype self-check. The next two runs failed in the verifier:
inspect_native_apiEvidence comes from therea-workflowprovider, and a stripped build also records residual unknowns without a profile. The verifier now checks each by its provider.For evidence-bearing changes:
Validation performed
The head
d8ae325f1changes only the D3 wording indocs/ghidra-riscv.md;npm run docs:checkandformat:checkpassed on it.d02fc6b78checks the stripped build's return storage on top of656badf1f, which mergesmaind48e472fa. The other checks ran on the same tree as656badf1f.d02fc6b78:npm run check:fast,format:check,docs:checkandverify:module-boundaries— passed.npx knip— no findings.npm run jscpd— 3.57% (threshold 4%).npm run test:focused --the RISC-V conformance checks, the RISC-V profile tests and the README consistency test — 64 passed.656badf1f: the same static checks passed, andnpm run test:focused --22 files (the 6 test files this PR changes and tests of the code it shares withmain's latest changes) — 893 passed, 4 skipped (Windows-only).npm ci --ignore-scripts), ond02fc6b78and before that on the same tree as656badf1f:npm run verify:ghidra:bridge-sources— passed: all 11 bridge sources compile against Ghidra's 195 jars.npm run verify:ghidra:riscv— passed:"mocked": false, cleanup complete, process lineage verified with no descendants. The typed ilp32 build has the compiler's storage at all ten calls, the stripped build returns where the typed build does, and other float ABIs are refused.npm run verify:ghidra:mips— not run: onmaind48e472fait fails at its carved fixture before any soft-float code runs; the queued MIPS verify fix repairs that.fast-uri3.1.8 andqs6.16.0 (lockfile: 3.1.9 and 6.16.1).Lane results per fixture on d02fc6b; an earlier head's wider run
0x1) is admitted over MCP and the CLI aself32-exec-le-soft-float-generic-v1with its own ISA string; RV640x1is refused ("soft-float ABI (lp64)");0x80000005is refused on both.rv32imc_zicsr_zifencei): the soft-float lane andilp32-prototype-v1;fence.iandcsrrdecode; everyinspect_native_apiprototype uses__rea_ilp32with the policy's storage (for example an unaligneddoubleata2:4,a1:4, the split atStack[0x0]:4,a7:4, and thelong doublecall ata0:4 (auto),a1:4anda2:4); the caller's pseudocode passes the source constants; 13 functions and 12 function definitions use the prototype. Relabelled single-float (0x3) and0x80000001are refused.a0:4, ora1:4,a0:4for the five 8-byte results. The two results returned through caller memory have no return storage (<VOID>). 13 functions and 0 function definitions.llvm-objdumpof the typed caller places every expected word for all ten calls, including the memory behind both by-reference pointers.656badf1f.An earlier head,
383b87cfb, also passednpm run test:changed(on990a82dee, with the same TypeScript): 393 files, 7,092 passed, 7 skipped.Compatibility, safety, and release
Author readiness
Human owner: @Entrpi
Before merge
type(scope): outcome.