Skip to content

[AUTOMATED] Let --assert state where an indirect call goes - #1676

Merged
mahaloz merged 15 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/assert-callee
Nov 19, 2026
Merged

mahaloz merged 15 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/assert-callee

Conversation

@coleleavitt

@coleleavitt coleleavitt commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

[AUTOMATED]

kuna cannot be told where an indirect call goes. A reader who knows the destination still gets the pointer expression, and the callee's name and prototype never reach the call.

struct ops { int (*fn)(void *ctx, int a); };
struct ops *table[4];
int handle_open(void *ctx, int a) { return *(int *)ctx + a; }
int dispatch(void *ctx, int i, int a) { return table[i & 3]->fn(ctx, a); }
int twice(void *ctx, int i, int a) { return table[i & 3]->fn(ctx, a) + handle_open(ctx, 1); }
clang -O2 -fPIC -fno-inline -c ops.c -o ops.o && ld.lld -shared -o ops.so ops.o
kuna decompile ops.so twice
kuna decompile ops.so twice --assert 'callee 0x147a handle_open'

0x147a is the call *(%rax) in twice (objdump -d ops.so). Before (the second command is unknown directive "callee"):

  v1 = (*(int (*)(unsigned long,unsigned int))**(unsigned long **)&table[(a1 & 3) * 8UL])(a0,a2);
  return handle_open(a0,1) + v1;

After:

  v1 = handle_open(a0,a2);
  return handle_open(a0,1) + v1;

dispatch ends in jmp *%rax. --assert 'callee dispatch::0x1457 handle_open' turns its body from a switch over unmapped memory into handle_open(a0,a2); (return handle_open(a0,a2); under decompile-all).

The change

  • New directive callee [<func>::]<callsite> <name|address>, and the console command override indirect <callsite> <name|address> beside override flow. Both plant the per-function indirect-call override the engine already uses when it resolves a call itself, before flow, so the call is built direct and takes the callee's prototype.
  • An indirect jump at the call site is taken as a tail call: no jump-table recovery, a call and a return.
  • Rejected with a reason, and nothing planted: a direct call, an instruction that is not a call or an indirect jump, a destination that is not a function. A call site the function's flow never reaches is refused after the decompile and the run exits non-zero, like a refused flow.
  • No option: the directive is the caller's statement. A run without it does one map lookup per function; a single-function --json decompile executes the same instruction count before and after (837.55 M, difference below run-to-run spread).

Tests

  • tests/stages/kuna-assert-callee.xml: override indirect on the indirect call and on the tail jump, against the unstated output.
  • kuna-cli/tests/assert_callee.rs: text and --json, name and address destinations, decompile-all with qualified directives, each rejection, the post-flow refusal, malformed directives. The fixture is built from tests/fixtures/assert_callee.c.
  • No existing datatest or stage expectation moved.

Fixes #1644

coleleavitt and others added 5 commits November 18, 2026 16:03
…nd print ACLE intrinsics

AARCH64.pspec leaves the ShowMemTag context at 0, under which irg, addg, subg, gmi and ldg lift
as a pointer copy or add and the stg family as nothing, so
`return __arm_mte_create_random_tag(p, 0);` decompiled to `return a0;`. Barriers and hints
printed under their SLEIGH instruction names (`DataMemoryBarrier(2,3)`) instead of the
<arm_acle.h> intrinsic the source called (`__dmb(11)`).

The new option `acleintrinsics` (on|off, default on, AArch64 only) does two things:

- `p2_lift/kuna_memtag.rs` sets ShowMemTag to 1 over the code space before a function is
  lifted. Only the memory-tagging constructors read that context, so code without those
  instructions lifts as before. The ShowMemTag=1 constructors now make the tagged pointer the
  result of the user op (new ops AddPtrTag, ExcludePtrTag, LoadPtrTag, StorePtrTag), and no
  longer branch to AlignmentFault() before a tag store.
- `p9_emit/kuna_acleintrinsics.rs` prints the barrier, hint and memory-tagging user ops as
  __dmb, __dsb, __isb, __wfi, __wfe, __yield, __sev, __sevl and __arm_mte_create_random_tag,
  _increment_tag, _exclude_tag, _get_tag and _set_tag. A barrier's domain and type operands
  recombine into CRm; isb's CRm is read from the instruction. A tag load or store that names
  another granule keeps its user-op name.

`off` restores the previous output byte for byte. make test stays 675/675 with the option on;
the dmb control in kuna-syscallregs-aarch64.xml now reads __dmb(11). The AArch64 compiler
digest and the ccmp lift fixture (unique-space offsets only) are regenerated.

Fixes Noelo-Lab#1626
A new directive, `callee [<func>::]<callsite> <name|address>`, and the
console command `override indirect <callsite> <name|address>` plant the
per-function indirect-call override before flow, so the call is built as
a direct call and takes the callee's name and prototype. An indirect
jump at the call site is taken as a tail call: no jump-table recovery,
a call and a return.

A direct call, an instruction that is not a call or an indirect jump,
and a destination that is not a function are rejected with the reason.
A call site the function's flow does not reach is recorded after the
follow and reported as a refused directive.

Fixes Noelo-Lab#1644
…alls, restated sites

- A destination that is a PLT stub bound to a local definition was applied
  but then refused after flow (exit 1): the call spec is built at the
  definition, so the audit now also accepts the spec's PLT stub.
- A stated indirect jump to a no-return callee printed a dead `return;`
  after the call; the stated tail call now ends there, as a direct tail
  call to the same callee does (stage assertions #6-#7).
- Two `callee` directives for one call site both reported applied; the
  earlier is now reported rejected on both the text and JSON surfaces.
- `callee` is listed in the `--assert` usage vocabulary; the fixture recipe
  records -fcf-protection=full, which the committed ELF was built with.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…ter reads contradict

The shared-push rule took a declared parameter at the pushed slot as proof the
push is an argument on both arms. MinGW GCC passes a static function's
arguments in EAX/EDX/ECX while its debug information lists them as ordinary
parameters, so wine's MSVCRT_longjmp handed the padding slot GCC re-reserves
after IsBadReadPtr to the indirect unwind call: `(*jmp->UnwindFunc)(jmp,frame)`.
A declared list with no register parameter, for a direct callee whose entry
reads EAX, ECX or EDX before writing it, no longer counts as that proof.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz

mahaloz commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed 8998c3a on top of your head, plus a merge of current main (f915cfd). Here is what it fixes:

  • PLT stub as the destination. --assert 'callee 0x147a 0x14c0' names the fixture's handle_open PLT stub. The call was rebuilt, but the run then exited 1 with the function's flow makes no indirect call at this address. The call spec is built at the definition the stub binds to, so the audit now also accepts the spec's PLT stub.
  • Stated tail jump to a no-return callee. jmp *(%rax) stated as die printed die(a1); // no-return followed by a dead return;. A direct jmp die prints no return;. The stated tail call now ends after a no-return callee. Stage assertions ASSERTCALLEE #6/#7 (with option noreturn handle_open) cover this, and Fix test stages #7 fails on the previous head.
  • Two callee directives for one call site. Both reported applied, but only the later one took effect. The earlier one is now reported rejected, on both the text and --json surfaces.
  • Smaller fixes. callee is now in the --assert usage vocabulary. The fixture recipe now records -fcf-protection=full: the committed ELF has endbr64 and .plt.sec. Rebuilding it with clang/LLD 21 and that flag gives the same bytes apart from .comment. The docs now say the statement outranks a destination kuna would resolve itself, such as a GOT-slot import.

mahaloz and others added 10 commits November 19, 2026 01:18
…ead of refusing any

A MinGW thiscall member declared from its mangled name lists `this` as a
stack parameter while its code reads ECX and takes the rest on the stack, so
refusing every declared list whose callee reads an argument register dropped
the speculative-devirtualization gains of the shared-push rule
(std::ctype::do_tolower's virtual call). The callee's stack arguments are the
declared parameters after the r it takes in registers; only a slot above them
is refused. Adds a thiscall control to the fixture and stage test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The option turns ShowMemTag on, so the EL1 bulk tag instructions now lift
with upstream's ShowMemTag=1 LoadMemTag/StoreMemTag loops instead of
ldgm reading as zero; the chapter said they were unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolves the stage-corpus count in kuna-base/src/xml.rs (782) and
re-synthesizes docs/baseline-stages.json (main's 4516 plus this PR's 13).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz
mahaloz merged commit ab1d289 into Noelo-Lab:main Nov 19, 2026
mahaloz added a commit to coleleavitt/kuna that referenced this pull request Nov 19, 2026
Main gained callee (Noelo-Lab#1676) and format/isolate (Noelo-Lab#1679) beside callproto in
the same assertion files: every directive list, Body variant and match arm
keeps both sides, assertions.rs keeps record_rejected_callee_overrides and
record_unbound_call_prototypes whole, project.rs calls both, and
assertion_outcomes runs both restatement passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
mahaloz added a commit to phix33/kuna that referenced this pull request Nov 19, 2026
Keep Noelo-Lab#1676's stated-tail-call check first in recover_jump_tables, then
record whether the table is a re-entry retry. Keep both sides of the
corpus-file and live-field counts; synthesize docs/baseline-stages.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@coleleavitt
coleleavitt deleted the fix/assert-callee branch November 21, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOMATED] Allow --assert to make an indirect call direct

2 participants