Repository navigation
[AUTOMATED] feat(cli): list a function's warnings in its JSON record - #1601
Conversation
…ies and a diff lint scripts/prepr/aritydiff.py compares the call arities a base and a head build print with decompile-all over pinned public 32-bit MSVC binaries (setuptools 59.6.0 cli-32/gui-32, pip 21.3.1 distlib t32/w32, Ghidra's WinHelloCPP.exe), fetched on demand and checked by SHA-256. It fails on a lost argument, a function that stops decompiling, or a dropped call. scripts/prepr/difflint.py fails on fixtures missing from the fixtures README, local paths in added binaries or test lines, unreferenced build intermediates, and edited stage assertions without an Assertion-change trailer. docs/prepr.md documents both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t be shared Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ame header - ppc_64_le.cspec placed the first stack parameter at SP+112, the ELFv1 offset after a 48-byte header. ELFv2 (every ppc64le target) has a 32-byte header (back chain, CR, LR, TOC), so the ninth doubleword is at SP+96. Callers lost their stack arguments and callees read an unwritten slot. - Stage test kuna-ppc64le-elfv2-stack-args: callee `return i + a;`, caller `f9(n,2,3,4,5,6,7,8,n + 9)`; both fail on main.
… entries - The ELFv2 ABI passes a function's own address in r12 to its global entry, which derives the TOC pointer from it (addis r2,r12,hi; addi r2,r2,lo). Without that fact r2 was an unknown input and TOC-relative globals printed as offsets from an uninitialised register. - New P1 pass ppc64r12 (the analog of mips_gp's t9 seed): r12 = entry at each defined STT_FUNC whose st_other declares a distinct local entry. - CLI test ppc64_global_entry_toc with a 1.4 KB clang fixture; prototype_call_mechanisms' `on` assertion now checks the clobber, since the stored TOC resolves to a constant instead of printing as r2save.
- The extrapop solver equated every input of a stack-pointer merge, so a path lowering SP by a runtime amount took the other path's constant and was rewritten away. - Mark SP values moved by a non-constant amount, and merges they reach, as dynamic: no equation touches them and they are never rewritten. - Regression: Open Watcom DOS alloca behind stackavail() at -od and -ox.
- st_other entry bits mean nothing under ELFv1; the ELFv1 descriptor reader already gates on e_flags & 3.
- The on arm now checks the store's RHS is the constant the return reads back, not only that the local is clobbered.
- Dynamic marks follow COPY, CAST, INDIRECT, INT_SUB and PTRADD/PTRSUB value inputs, not only merges. - Only equations joining a dynamic value to a fixed one are dropped; relations among dynamic values stay, unanchored. - PTRADD's element size is not an amount; INT_SUB(sp, c) gets the equation add sp,-c, so a constant reservation on one arm is solved instead of equated.
… version 2 - Big-endian ELFv2 (musl, -mabi=elfv2) has the same 32-byte frame header as ppc64le, so stack parameters start at SP+96; the default big-endian spec stays ELFv1 (SP+112). - New compiler spec ppc_64_be_elfv2.cspec (id elfv2), chosen by the loader when e_flags & 3 == 2. - Stage test from real clang -mabi=elfv2 output (fails without the selector); loader unit test; baseline re-recorded (4344/4344).
- ELFv2 saves r2 at 0x18(r1); the copied ELFv1 inject wrote 0x28, inside the parameter save area. Only used under callmechanisms on.
- A non-constant adjustment is often a constant not yet propagated (add sp,si with si == 2 after a push): a trial upstream solve implies a nonzero move there, so it stays solved as before. - Only an adjustment whose solved move is zero (the merge equated it away) or that stays unsolved is treated as runtime. FreeDOS sweep: ARJ/GZIP return to main's output; FORMAT and JWASMR keep the Watcom alloca amount.
- mov ax,8; sub sp,ax is a fixed reservation: literal_value sees through the copy, so it is not marked runtime.
…SA-selection contract
- is_const/const_off read literal_value, so mov ax,8; sub sp,ax is solved as an 8-byte adjustment instead of being equated through a merge. - Document that confirm_dynamic is evidence, not proof: a runtime arm merged with a nonzero constant keeps upstream's answer. - The regression test now requires the reservation arm's pointer to use the (n + 1) & ~1 amount.
…e environment before the TOC
A library caller can now pass its compiled specs as bytes instead of shipping a specs/ directory. MemorySpecs holds a spec tree as (path, contents) pairs, over a static table or over owned data such as Vec<u8> or Arc<[u8]>. SpecRoot names a directory or such a tree. Each public bootstrap gains a *_with_specs form that takes any list of spec roots, and the &[String] functions delegate to it. LanguageDatabase owns the trees it was given, so nothing is registered process-wide. A tree need not follow Ghidra's layout: one language's .ldefs, .sla, .pspec and .cspec, flat, form a complete root. Tests check that memory roots decompile the fauxware fixture as the specs directory does, never fall back to the filesystem, and mix with directory roots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Every `--json` function record from `decompile` and `decompile-all`, and from the browser front-end, now has a `warnings` array of `{kind,message,line,address}`. The array is always present and is `[]` for a function with no warnings and for one that failed.
- The printer records an entry each time it writes one of the engine's own warning comments: a header warning, a body warning, an inline slug, or the note on a body it has no structure for. A comment whose text merely reads like a warning is never listed. That covers an `--assert comment`, a storage comment, and the original name a Rust or Go render keeps above the prototype.
- `address` is the instruction the warning was recorded at, or the function's entry for a header warning. It is `null` only for `structuring-declined`. `line` is the line of `code` that holds the comment, and `message` is the warning text without its `WARNING: ` marker.
- `kind` is assigned by matching the warning text. A fixed table covers decode failures, flow cut at the instruction budget, out-of-bounds and unmapped flow, unrecovered jump tables and declined structuring. Any other warning gets the slug `warnstyle inline` prints for it (without its ` xN` count) or a kuna producer tag. Text that matches none of these gets `other`.
- The `--jobs` result wire and the result store carry the records, and the wire format moves to `KUNAJOBRES12`. Both `warnstyle` values give the same records except for `line`.
Library callers can now load several images at once in one process with different settings. LoadOptions holds every load-time option (ppc32picimports, ifuncfpret, ppcapu, kernelcache, goabi, symbolnamechars, libctypes, calltargettype, macho-arm64e, sourcelang, objcivars, objcsdk, dyldimage, dyldcrossrefs), the fat slice, the .pdb, .fid and FLIRT paths, the Go release, and the load-pass and mapping switches that KUNA_LOAD_OBJC, KUNA_LOAD_STRINGS and KUNA_LOAD_MMAP set. bootstrap_from_object_with_options and bootstrap_from_image_with_options put it in force on the loading thread, and each Architecture keeps its options and re-enters them around analysis, decompilation, name lookup and console commands. An explicit-options load neither reads nor writes the environment; environment_fallbacks() counts reads that fell back to it on a thread. The entry points that take no options load from the environment, publish KUNA_GOVERSION, and build programs that read the environment live. set_kuna_option and reset_wire_defaults write the environment for a later load. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A library that loads many binaries can now scan and parse the .ldefs files once. language_database(spec_roots) scans the roots, and bootstrap_from_object_with_db and bootstrap_from_image_with_db take the database in place of the spec roots, alongside LoadOptions. A test loads two images on two threads from one database and shows that a bootstrap over it does not rescan the roots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Kuna has 26 bootstrap_* entry points, one per combination of input format, language source (spec roots or a scanned LanguageDatabase), ARM ISA (environment, explicit) and load options (environment, explicit). Each new setting doubled the set. Bootstrap::new(&languages).target(..).arm_isa(..).options(&opts) now holds those settings, and one method per input loads with them: object, image, file, raw, te, te_bytes, mz_bytes, xml_image, xml_root. LanguageSource, a sealed trait, accepts spec roots as a slice, array or Vec, or a LanguageDatabase. The builder is Copy, so one configured builder can load many inputs, on several threads. Without options, a load puts the environment in force for that load on the calling thread, and an unset ISA comes from KUNA_ARM_ISA. With options it reads neither. Explicit options now also reach raw, TE, MZ and XML loads. Each bootstrap_* function becomes a one-line wrapper over the builder. Tests check that explicit options reach every input without the environment, that a builder without options reads the environment and one with options does not, and that one builder loads the same program on several threads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… through their descriptors
- `libcsigs` gets a `void __stack_chk_fail_local(void)` row, the same contract as `__stack_chk_fail` (glibc `debug/stack_chk_fail_local.c`). It matches only an import with exactly that spelling, such as a relocatable object's call relocation to the undefined symbol. - The known-no-return pass (`noreturn_known`, on by default) ends the flow at that import. It matches the exact name only on import addresses, so `_stack_chk_fail_local`, `stack_chk_fail_local` and a returning callee with any of these spellings keep their return. - In a linked PIE or shared object the helper is defined hidden in the image and is not an import, so the `libcsigs` row does not reach it. `libgccsigs` (analysis tier, off by default) now gives that defined helper the same `void (void)` contract, keyed by its address. - The defined helper gets the contract only if no other function name holds its address. Static glibc aliases it to `__stack_chk_fail`, and that address keeps its inferred contract. - The defined-helper case is opt-in because removing the argument can also remove a caller parameter or an inferred return that was used only by that argument.
…h their relocations
Funcdata::clear stubbed upstream's localmap->clearUnlocked(), resetLocalWindow() and funcp.clearUnlockedOutput(), so a restart began from the symbols and prototype the previous pass recovered. A function that finds a lowered switch late and restarts printed differently from a later decompile that installs the saved switch first. - Port ScopeInternal::clearUnlocked as Database::clear_unlocked: keep type-locked symbols (unlocked name reset, nolocalalias cleared, size-locked type reset to undefined), equates and asserted isolated identities. - Call it from Funcdata::clear, reset the local window, clear the unlocked output, and clear unlocked inputs (the port keeps them in the prototype). - Tests: clear_unlocked unit test; the floatret_restart CLI fixture now prints the restarted pass's unsigned int; the joined-callback stage's second() returns the call directly.
…n the spec The load-time env-bridge section and the KUNA_GOVERSION prose still named the environment as the only channel. They now describe explicit LoadOptions, the precedence between explicit options and the environment, how a program re-enters its own options, spec roots held in memory, and a language database scanned once and shared across loads. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
… for every load without options A LoadScope restored the options it replaced, so dropping two scopes in the wrong order left the thread with options no live scope held. Scopes now sit on a per-thread stack and each removes only its own entry, so the innermost live scope is always the one in force. The guard stays !Send. A Bootstrap without options put the environment in force for object and image loads but let raw, TE, MZ, XML loads and the file classifier inherit whatever options the thread held, so with another program's scope held they built a program frozen to that program's options. Every input without options now loads under the environment. environment_fallbacks() is test instrumentation and is hidden from the docs. New tests: a program re-enters its own options after a later load on the same thread (kernelcache, symbol names, dyld image, slice, pdb, objc sdk, Go release, ARM ISA); a failed load leaves no options in force; a load without options ignores a held scope; the console loads its next image from the environment. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
… builder replaces The fifteen free functions added alongside Bootstrap were one-line calls into it and had no user outside this change's own tests, which now call the builder. The existing bootstrap_* functions keep their signatures. Two inline comments move into their function headers, and the spec-copy test follows symlinked .sla files, as a worktree that links its built specs has. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…he spec The program-preparation chapter now states how the ABI version in e_flags picks the PowerPC64 compiler spec and why the first stack argument sits at SP+96 under ELFv2 and SP+112 under ELFv1; the call-mechanisms paragraph notes that the big-endian ELFv2 model saves the TOC at 0x18(r1). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…xt range Each r12 fact was committed as a [entry, entry+1) tracked range in the context database, and every function's decompile snapshots that whole database, so the cost grew with functions x seeded functions: an 8,000- function ppc64le shared object went from 5.2 s to 23 s of user time. The seeds now go to the architecture's per-entry loader seeds (the table the ELFv1 TOC seed uses), read only at the function's own entry. Output is byte-identical to the context-range form over 226 corpus images. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…ture source The program-preparation chapter now describes the PowerPC64 ELFv2 global-entry r12 seed beside the MIPS t9 seed, and publish_toc_ppc64le gains its C source and build recipe. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…inter solver spec The solver change had no prose in its owning chapter. Add it to docs/spec/06 next to the StackSolver section: which adjustments are runtime-sized, the trial solve, the forward mark, what is never rewritten, the exact equations for constant adjustments, and the known limits (a sibling nonzero constant, a guessed earlier pop, a reservation inside a helper call, and that stack traffic after the reservation stays raw pointer arithmetic so an unlocked callee there takes no stack arguments). The CLI test now also requires the store into the reservation to survive, and its header records the full Open Watcom 2.0 command line; both fixtures rebuild byte for byte with it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The console's `option calltargettype` sets only the decompile-time switch, so a later `load file` still runs the DWARF function-pointer mapping; the spec said every load-time option line reaches the next load. An explicit load leaves the load-time variables alone, not every variable. The Go release is read from the image's bytes, so it is set before the loader parses them, not before the image is opened. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolve the stage-corpus count (757 -> 758) and the stages baseline (synthesized: main's 4342 plus this branch's three kuna-stackchklocal rows). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…C and x86 GCC 14's SPARC -m32 -fPIC stack protector calls __stack_chk_fail, not the hidden local helper, and ARM/MIPS do the same, so the libgccsigs row and the spec name only 32-bit PowerPC and x86. The spec also records that an i386 object's R_386_PC32 call to the helper is not registered as a code extern, so i386 objects are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolve the stage-corpus count (both sides added two stage tests: 760) and re-synthesize docs/baseline-stages.json from both sides' additions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…pass kuna prints a double-quote character as '\"'. Stripping string literals before character literals read that quote as the start of a string and dropped every call up to the next string literal (267 calls in one function of a 32-bit PE). Comments were not stripped at all, so a register comment such as `// eax` or `// branch-flip` followed by a line opening with `(` counted as a call to `eax`/`flip`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The fixture check only read `<fixtures>/README.md`. kuna-cli's fixtures have no such file (their recipes are in sibling notes such as ppc32-pic-imports.md and callwide/README.md), and recently merged fixtures record theirs in a sibling note (byval_pe_i386.txt) or the source's `Build:` line (calleeregcustom_pe_i386.asm), so the check failed on them. It now accepts the name in any text file beside the binary or in a directory above it up to `fixtures/`. Also pass the file name to `git grep` after `-e` so a name starting with `-` is not read as an option, and read git's path lists with `-z`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
aritydiff set KUNA_SPECS to the checkout it runs from whenever the variable was unset. Run from a worktree without built specs (the repo's rule for worktrees) both decompiles failed with "Could not find .sla file", although each kuna finds its own tree's specs; and with a PR that changes a .sinc, the base build was given the head's specs. The environment is now passed through unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
They are not a gate and CI does not run them; what a PR body carries is still decided by docs/pr-bodies.md. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolve the stage-corpus count (758 -> 759) and the stages baseline (synthesized: main's rows plus this branch's three kuna-stackchklocal rows). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
A body warning for flow cut at the budget, out of bounds or into unmapped memory is recorded at the address the flow went to, which for unmapped-flow holds no instruction. Say so instead of calling every address an instruction, and name the partly recovered jump tables the jumptable kind also covers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
|
[AUTOMATED] Pushed 9826721, a docs-only follow-up (11+/9-, |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The problem
When a function decompiles with warnings, its
--jsonrecord does not say so:errorisnull, and the bad-instruction, truncated-flow and unresolved-jump warnings appear only as C comments insidecode. To tell a truncated body from a clean one, a consumer has to parse the C text.The record should also have a
warningsarray giving the kind and instruction address of each warning incode, witherrorstillnull.The fix
--jsonfunction record fromdecompileanddecompile-all, and from the browser front-end, now has awarningsarray of{kind,message,line,address}. The array is always present and is[]for a function with no warnings and for one that failed.--assert comment, a storage comment, and the original name a Rust or Go render keeps above the prototype.addressis the instruction the warning was recorded at, or the function's entry for a header warning. It isnullonly forstructuring-declined.lineis the line ofcodethat holds the comment, andmessageis the warning text without itsWARNING:marker.kindis assigned by matching the warning text. A fixed table covers decode failures, flow cut at the instruction budget, out-of-bounds and unmapped flow, unrecovered jump tables and declined structuring. Any other warning gets the slugwarnstyle inlineprints for it (without itsxNcount) or a kuna producer tag. Text that matches none of these getsother.--jobsresult wire and the result store carry the records, and the wire format moves toKUNAJOBRES12. Bothwarnstylevalues give the same records except forline.Not changed: Warnings change neither
errornor the exit status, and the warning comments incodeprint as before.The tests
Adds 6 tests in
decompiler/crates/kuna-cli/tests/function_warnings_cli.rsand a case todecompiler/crates/kuna-cli/tests/integration.rs. The acceptance case fails without the fix.