Skip to content

missing-function-call-1101b1: recover guard-bounded GCC PIC jump tables (option switchguardbound) - #60

Merged
mahaloz merged 3 commits into
mainfrom
feat/angr-missing-function-call-1101b1
Jun 25, 2026
Merged

mahaloz merged 3 commits into
mainfrom
feat/angr-missing-function-call-1101b1

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

missing-function-call: recover a guard-bounded GCC PIC jump table (option switchguardbound)

Closes one gap where angr's decompiler beats kuna: angr
test_decompiling_missing_function_call (binary adams, function main, x86-64 GCC PIE).

angr recovers main's getopt() dispatch as a proper switch (6 cases + default). kuna
fails to recover the jump table and emits /* WARNING: Treating indirect jump as call */,
collapsing the entire switch and the surrounding getopt loop into one bogus computed
(*(code *)…)() call — so every case body (strdup/fprintf/atoi/…) vanishes. The angr
test asserts exactly this is wrong (fileno present, the -e/strdup case present).

See analysis.md for the full instrumented root-cause.

Root cause

The table at 0x96ac is a textbook GCC PIC jump table whose index is range-guarded by
sub 0x36; ja DEFAULT (idx LEu 0x36, 55 entries) and spilled to the stack before the
table load. kuna's jump-table recovery runs early on the partial/truncated function, before
the sub;ja flag idiom is simplified and before the stack spill is collapsed, so
JumpBasic::analyzeGuards cannot bound the index (jrange.size = 2^31 GT maxtablesize).
The basic model is declined → recoverAddresses throws "Too many branches" →
truncateIndirectJump rewrites the BRANCHIND into a CALLIND.

Mechanism

A new option-gated JumpBasic model-extension kuna_try_guard_bound_table (S2
switch-model), sibling of the GH-9191 switchmodbound modulo bound, invoked from
recover_model_basic after the normal model (and the modulo extension) fail. It EVALUATES
the guard boolean as a function of the index varnode v (resolving register-reused siblings
like m = v + 0x3f via a linear-offset map) and takes N = the first v whose routing
flips from v = 0's — composing the simplifier's idx GT 0x35 and m != 0x75 form to the
correct N = 0x37 (55, including the boundary 'u'/userlist case at idx 0x36, which a
naive constant scan would miss). It re-binds the table index to [0, N); the normal
buildAddresses + structurer then emit the switch.

Option

option switchguardbound on|off (default OFF, opt-in; kuna catalog discoverable).
Flip per decompilation: kuna decompile ./adams main --option switchguardbound on.

Ablation / parity / speed

  • Ablation (flag default-ON over the 675-datatest corpus): 0/675 assertions changed —
    the heuristic over-bounds no corpus switch.
  • Parity: make test PARITY OK (675/675, byte-identical when off);
    make test-stages PARITY OK (164/164, incl. the new test).
  • Speed (target main, off vs on): off ≈ 192.9 ms, on ≈ 259.1 ms (+34.3%, over the +5%
    budget — the ON cost is doing the full switch+loop recovery instead of truncating to a
    call; the gate-OFF path is unchanged). Per the speed gate the option ships default-OFF
    opt-in
    (speed_forced_off; no DIV entry — output byte-identical when off), matching the
    switchmodbound precedent + risk profile (the guard-to-index correspondence is asserted
    across a memory spill it cannot prove in dataflow).

A two-pass stage test tests/stages/ghangr-missing-function-call-1101b1.xml pins both
states (off = the computed-call bug; on = the recovered switch incl. the boundary
case 0x36).

make rust-test is green except the pre-existing verify_w10_proto_unlock failure (a
removed-C++-oracle test that fails identically on this branch without these changes —
confirmed via git stash).

🤖 Generated with Claude Code


Before / after — main in adams

Real captured kuna output on the function this feature was built for, with option switchguardbound flipped. Ported from angr — test_decompiling_missing_function_call; angr jump-table / VSA guard bounding; main.

metric switchguardbound off (default) switchguardbound on
gotos 0 2 ⬆️
labels 0 1 ⬆️
loc 123 274 ⬆️
switches 0 1 ⬆️
speed 192.9 ms 259.06 ms — Δ 34.3% (budget 5.0%) ⚠️ over budget → opt-in
kuna — before (option switchguardbound off)
unsigned long main(int4 a0,unsigned long a1)

{
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  unsigned long e; // stack - 0x18
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  unsigned int t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 u; // stack - 0x20
  int4 u; // stack - 0x20
  int4 v1; // eax
  unsigned long v2; // rax
  char v3 [16];
  char *v4; // stack - 0x38
  unsigned int v5; // stack - 0x30
  unsigned int v6; // stack - 0x2c
  
  c = 0;
  assert_execution_on_testbed();
  t._4_4_ = 0;
  t._0_4_ = 0;
  v6 = 0;
  v5 = 0;
  v4 = (char *)getenv(0xa037);
  if (v4 == (char *)0x0) {
    dat_20b230 = 0x539;
  }
  else {
    EAX = atoi(v4);
  }
  memset(client_data,0,0x178);
  m = getopt(fd,e,"e:m:u:p:s");
  if (m == -1) {
    v1 = ingest_emaillist();
    if (v1 != 0) {
      if (t._4_4_ == 0) {
        u = setup_socket(dat_20b230);
        if (u <= -1) {
                    /* WARNING: Subroutine does not return */
          exit(1);
        }
        accept_loop(u);
      }
      else {
        memset(v3,0,0x10);
        v1 = fileno(*Unique10000152);
        read_loop(v1,(sockaddr_in *)v3);
      }
    }
    return 0;
  }
  if (0x36 <= (uint4)(m - 0x3fU) && m != 0x75) {
                    /* WARNING: Subroutine does not return */
    abort();
  }
                    /* WARNING: Treating indirect jump as call */
  v2 = (*(code *)((int8)*(int4 *)((uint8)(uint4)(m - 0x3fU) * 4 + 0x96ac) + 0x96ac))();
  return v2;
}
kuna — after (option switchguardbound on)
unsigned int main(int4 a0,void *a1)

{
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  int4 c; // stack - 0xc
  void *e; // stack - 0x18
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 fd; // stack - 0x10
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 m; // stack - 0x1c
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 t; // stack - 0x28
  int4 u; // stack - 0x20
  int4 u; // stack - 0x20
  int4 v1; // eax
  char v2 [16];
  char *v3; // stack - 0x38
  int4 v4; // stack - 0x30
  int4 v5; // stack - 0x2c
  
  c = 0;
  assert_execution_on_testbed();
  t._4_4_ = 0;
  t._0_4_ = 0;
  v5 = 0;
  v4 = 0;
  v3 = (char *)getenv(0xa037);
  if (v3 == (char *)0x0) {
    dat_20b230 = 0x539;
  }
  else {
    EAX = atoi(v3);
  }
  memset(client_data,0,0x178);
  do {
    m = getopt(fd,e,"e:m:u:p:s");
    if (m == -1) {
      v1 = ingest_emaillist();
      if (v1 == 0) {
        return 0;
      }
      if (t._4_4_ == 0) {
        u = setup_socket(dat_20b230);
        if (u <= -1) {
                    /* WARNING: Subroutine does not return */
          exit(1);
        }
        accept_loop(u);
      }
      else {
        memset(v2,0,0x10);
        v1 = fileno(*Unique10000285);
        read_loop(v1,(sockaddr_in *)v2);
      }
      return 0;
    }
    if (0x36 <= (uint4)(m - 0x3fU) && m != 0x75) goto label_9106;
    switch(m - 0x3fU) {
      case 0:
        if ((*dat_20afe0 == 0x65) || (*dat_20afe0 == 0x75)) {
          fprintf((void *)*dat_20aff8,"-%c argument required\n",(uint8)*dat_20afe0);
          usage((char *)*e);
        }
        else {
          fprintf((void *)*dat_20aff8,"Unknown option\n");
          usage((char *)*e);
        }
        goto label_9106;
      default:
label_9106:
                    /* WARNING: Subroutine does not return */
        abort();
      case 0x26:
        if ((int4)t != 0) {
          fprintf((void *)*dat_20aff8,"Only one -e option permitted\n");
          usage((char *)*e);
        }
        t._0_4_ = 1;
        RAX = strdup(*dat_20afd0);
        if (RAX == 0) {
          dat_20afc0 = dat_20afc0;
          return 1;
        }
        break;
      case 0x2e:
        if (v5 != 0) {
          fprintf((void *)*dat_20aff8,"Only one -m option permitted\n");
          usage((char *)*e);
        }
        v5 = 1;
        RAX = strdup(*dat_20afd0);
        if (RAX == 0) {
          dat_20afc0 = dat_20afc0;
          return 1;
        }
        break;
      case 0x31:
        EAX = atoi((char *)*dat_20afd0);
        break;
      case 0x34:
        t._4_4_ = 1;
        break;
      case 0x36:
        if (v4 != 0) {
          usage((char *)*e);
          fprintf((void *)*dat_20aff8,"Only one -u option permitted\n");
        }
        v4 = 1;
        RAX = strdup(*dat_20afd0);
        if (RAX == 0) {
          dat_20afc0 = dat_20afc0;
          return 1;
        }
      
    }
  } while( true );
}
angr reference (the goal, v9.2.213)
typedef struct FILE {
} FILE;

extern void client_data;
extern unsigned long long emaillist;
extern unsigned long long maillist;
extern unsigned long optarg;
extern char optopt;
extern unsigned int port;
extern unsigned long stderr;
extern unsigned long stdin;
extern unsigned long long userlist;

unsigned int main(int a0, long long *a1)
{
    unsigned int v0;  // [bp-0x7c]
    FILE **v1;  // [bp-0x78]
    unsigned int v2;  // [bp-0x6c]
    unsigned int v3;  // [bp-0x68]
    unsigned int v4;  // [bp-0x64]
    unsigned int v5;  // [bp-0x5c]
    unsigned int v6;  // [bp-0x58]
    unsigned int v7;  // [bp-0x54]
    unsigned long v8;  // [bp-0x50]
    char v9;  // [bp-0x48]
    char *v10;  // [bp-0x38]
    unsigned int v11;  // [bp-0x30]
    unsigned int v12;  // [bp-0x2c]
    unsigned int v13;  // [bp-0x28]
    unsigned int v14;  // [bp-0x24]
    unsigned int v15;  // [bp-0x20]
    unsigned int v16;  // [bp-0x1c]
    unsigned int flag;  // [bp-0xc]

    flag = 0;
    assert_execution_on_testbed();
    v14 = 0;
    v13 = 0;
    v12 = 0;
    v11 = 0;
    v10 = getenv("PORT");
    if (v10)
        port = atoi(v10);
    else
        port = 1337;
    memset(&client_data, 0, 376);
    while (true)
    {
        v16 = getopt(a0, a1, "e:m:u:p:s");
        if (v16 == 4294967295)
            break;
        v8 = v16 - 63;
        v7 = (unsigned int)v8 - 54;
        switch ((unsigned int)v8)
        {
        case 0:
            if (*((int *)&optopt) != 101 && *((int *)&optopt) != 117)
            {
                v3 = fprintf(stderr, "Unknown option\n");
                usage(*(a1), a1); /* do not return */
            }
            v4 = fprintf(stderr, "-%c argument required\n", (char)*((int *)&optopt));
            usage(*(a1)); /* do not return */
        case 38:
            if (v13)
            {
                v6 = fprintf(stderr, "Only one -e option permitted\n");
                usage(*(a1), a1); /* do not return */
            }
            v13 = 1;
            emaillist = strdup(optarg);
            if (!emaillist)
            {
                flag = 1;
                return flag;
            }
        case 46:
            if (v12)
            {
                v5 = fprintf(stderr, "Only one -m option permitted\n");
                usage(*(a1), a1); /* do not return */
            }
            v12 = 1;
            maillist = strdup(optarg);
            if (!maillist)
            {
                flag = 1;
                return flag;
            }
        case 49:
            port = atoi(optarg);
            break;
        case 52:
            v14 = 1;
            break;
        case 54:
            if (v11)
                usage(*(a1)); /* do not return */
            v11 = 1;
            userlist = strdup(optarg);
            if (!userlist)
            {
                flag = 1;
                return flag;
            }
        default:
            abort(); /* do not return */
        }
    }
    if (!ingest_emaillist())
    {
        flag = 0;
        return flag;
    }
    if (!v14)
    {
        v15 = setup_socket(port);
        if (v15 < 0)
            exit(1); /* do not return */
        v2 = accept_loop(v15);
    }
    else
    {
        v1 = &stdin;
        memset(&v9, 0, 16);
        v0 = read_loop(fileno(*(v1)) & 4294967295, &v9);
    }
    flag = 0;
    return flag;
}

…es (option switchguardbound)

Closes the angr `test_decompiling_missing_function_call` gap (binary `adams`,
`main`): kuna failed to recover a getopt() jump-table switch and emitted
`/* WARNING: Treating indirect jump as call */`, collapsing the whole switch and
its surrounding loop into one bogus computed `(*(code *)…)()` call.

Root cause (instrumented): the table at 0x96ac is range-guarded by `sub 0x36; ja`
(idx LEu 0x36, 55 entries) with the index spilled to the stack. Jump-table
recovery runs early on the partial function, before the flag idiom is simplified
and the spill collapsed, so JumpBasic::analyzeGuards cannot bound the index
(jrange.size = 2^31) and recoverAddresses throws "Too many branches".

Mechanism: a new gated JumpBasic model-extension `kuna_try_guard_bound_table`
(sibling of GH-9191 switchmodbound), invoked from recover_model_basic after the
normal/modulo models fail. It EVALUATES the guard boolean as a function of the
index varnode (resolving register-reused siblings like m = v + 0x3f via a
linear-offset map) and takes N = the first value whose routing flips from 0's,
composing the simplifier's `idx GT 0x35 && m != 0x75` form to N = 0x37 (incl. the
boundary 'u' case); then re-binds the index to [0, N) so the normal
buildAddresses/structurer emit the switch.

Option `switchguardbound on|off`, default OFF opt-in (LLM-discoverable). Ablation
flag-on over the 675 datatests: 0 assertions changed; PARITY OK. Speed +34% on
the target (full switch+loop recovery vs truncation; gate-off byte-identical) so
forced opt-in per the speed gate (no DIV entry). New module
kuna_switchguardbound.rs (ELEM 4022); two-pass stage test
tests/stages/ghangr-missing-function-call-1101b1.xml.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mahaloz mahaloz self-assigned this Jun 25, 2026
@mahaloz

mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

We need the following update on this:

  1. Document for another agent this example as having WAY too many defined varibales on the top? Why is it duplicated so many times.
  2. We must investigate why this new features is so incredibly slow. If it is not-fixable, keep it disabled by default.

mahaloz and others added 2 commits June 25, 2026 17:06
…ction-call-1101b1

# Conflicts:
#	decompiler/crates/kuna-base/src/xml.rs
#	decompiler/crates/kuna-decomp/src/p0_knowledge/kuna_stages/tests.rs
#	decompiler/crates/kuna-decomp/tests/catalog_bytecompat.rs
#	docs/PROGRESS.md
#	docs/baseline-stages.json
#	tests/stages/kuna-catalog.xml
…loop recovery), keep default-OFF; document declaration-duplication

Reviewer asked why `option switchguardbound` is "incredibly slow" and to document
the over-declared-variables observation. Investigation (no source change needed):

Speed (target adams/main, slope-isolated per-decompile cost, which cancels the
~190 ms fixed process-spawn/load/SLEIGH-mmap that the PR-body +34 % wall-clock
figure was diluted by):

  switchguardbound off  ≈ 23.9 ms
  switchguardbound on   ≈ 63.2 ms   (+164 %, ~2.6x)

Root cause is downstream and INHERENT, not the heuristic. Instrumented:
kuna_try_guard_bound_table runs 3x at ~7 µs each (~22 µs total, <0.1 % of the
ON<->OFF gap); 0x with the gate off (confirmed). The cost is that the gate-ON path
keeps the real 55-entry switch + getopt while-loop and runs CFG-build / dataflow /
structuring / type-inference over a ~2.6x larger function, instead of truncating
the BRANCHIND to one CALLIND. Ruled out (cf. the prior ActionPool O(N^2)
regression): no O(n^2)/O(n^3), no per-op / per-CFG-node recomputation, no repeated
dominator/region rebuild; scan_guard_tree is already triple-bounded (64-step walk,
4096-step eval budget, v-loop capped at maxtablesize=1024) and resolves in µs.

No localized algorithmic fix exists — the extra time is the decompiler correctly
doing more work. Kept DEFAULT-OFF opt-in (speed_forced_off=true) per the +5 % speed
gate, matching its over-bound risk profile. Output byte-identical with the gate off
(675/675 datatests unchanged) -> no docs/divergences.md entry.

"Too many declared variables on top": NOT caused by this feature. It is a
pre-existing render artifact already mitigated on main by `dedupvardecls` (DIV-7,
default-on, landed after this branch). With dedupvardecls off the ON output renders
67x int4 t / 34x int4 m / 34x int4 c / 33x int4 fd; with it on (default) the
declaration block is ~12 clean lines. Cause: one stack slot maps onto many
un-merged same-named scalar HighVariables (one per loop/switch-phi SSA merge point);
the printer emits one decl per HighVariable. dedupvardecls de-dups identical
rendered lines (render-side) — it hides the symptom, the engine still carries N
HighVariables. The residual `int4 t` x2 is a legitimate sub-piece split
(t._0_4_ / t._4_4_ of the 8-byte -0x28 slot), correctly not collapsed. Follow-up
(separate agent): the s6_merge HighVariable-merge pass. Full write-up in
docs/features/missing-function-call-1101b1/{analysis.md,record.json}.

Gates: make test PARITY OK (675/675), make test-stages PARITY OK (176/176),
make rust-test green, kuna catalog --check OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz

mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Perf review + variable-duplication follow-up

Merged origin/main (union-resolved the option-registry files; regenerated docs/assertions.md, the catalog fixture, and docs/baseline-stages.json). All gates green: make test PARITY OK (675/675), make test-stages PARITY OK (176/176), make rust-test green, kuna catalog --check OK.

Why it's slow — measured, and it's inherent (not the heuristic)

Re-measured with a slope method that cancels the ~190 ms fixed process-spawn/load/SLEIGH-mmap cost the PR-body +34 % wall-clock figure was diluted by (load once in one decomp_dbg session, decompile main N times, per-decompile = (T(N₂)−T(N₁))/(N₂−N₁); 5-rep median):

per-decompile (slope-isolated)
switchguardbound off ≈ 23.9 ms
switchguardbound on ≈ 63.2 ms (+164 %, ~2.6×)

Root cause is downstream and inherent, not the new code. Instrumented: kuna_try_guard_bound_table is invoked 3× at ~7 µs each (~22 µs total, < 0.1 % of the ON↔OFF gap); 0× with the gate off (confirmed). The slow-down is that with the gate ON the real 55-entry switch + getopt while loop survives (instead of being truncated to one CALLIND), so CFG-build / dataflow / structuring / type-inference process a ~2.6× larger function — the cost of correctness. Ruled out (cf. the prior ActionPool O(N²) regression): no O(n²)/O(n³), no per-op or per-CFG-node recomputation, no repeated dominator/region rebuild; scan_guard_tree is already triple-bounded (64-step walk, 4096-step eval budget, v-loop capped at maxtablesize=1024).

There is no localized algorithmic fix → the option stays DEFAULT-OFF, opt-in (speed_forced_off), per the +5 % speed gate and its over-bound risk profile. Output is byte-identical with the gate off, so no DIV entry. No source change was needed.

"WAY too many defined variables on top"

This is not caused by switchguardbound — it's a pre-existing render artifact, and it's already mitigated on main by dedupvardecls (DIV-7, default-on, which landed after this branch was cut; the PR-body before/after blocks were captured pre-merge). On the post-merge tree:

  • --option dedupvardecls off (the old behavior the PR shows): the ON output renders 67× int4 t, 34× int4 m, 34× int4 c, 33× int4 fd.
  • dedupvardecls on (current default): the declaration block collapses to a clean ~12 lines.

Hypothesis: one stack slot maps onto many distinct same-named scalar HighVariables — one per loop/switch-phi SSA merge point the HighVariable-merge pass didn't unify — and the printer emits one declaration per HighVariable. dedupvardecls collapses identical rendered lines (render-side); it hides the symptom, the engine still carries N HighVariables. The residual int4 t ×2 is a legitimate sub-piece split (t._0_4_ / t._4_4_ of the 8-byte −0x28 slot), correctly not collapsed. Follow-up (separate agent, out of scope): the s6_merge HighVariable-merge pass.

Full write-up: docs/features/missing-function-call-1101b1/analysis.md + record.json (speed_investigation).

@mahaloz
mahaloz merged commit bc08534 into main Jun 25, 2026
mahaloz added a commit that referenced this pull request Jun 25, 2026
Resolve union conflicts with main (which landed #60 switchguardbound +
#68/#60 region work). Both opt-in/default-off knobs coexist:

- stages.toml: union [[settable]]/[[surface]] -> surface 91->93, settable
  45->47 (29 stage-model + 15 analysis + 3 loader); header counts updated.
- kuna_stages/tests.rs: surface_count 93, settable_count 47,
  live_value present-for-23 (switch_guard_bound + tail_call_jumps both
  field-backed), catalog-json trailing-commas 46.
- catalog_bytecompat.rs: fixture_has_all_47_settables; stage_catalog.json
  fixture auto-unioned (byte-for-byte test green).
- xml.rs corpus count 138->139 (83 datatests + 56 stage tests: both the
  missing-function-call and tee-o2-tail-jumps stage tests present).
- kuna-catalog.xml: source_decompiler=angr 12, structure-recovery 7,
  opt-in-tool 8.
- PROGRESS.md: union both session entries.
- tailcalljump ElementId stays 4101 (no collision; gotoreduce=4100 on main).

Regenerated docs/assertions.md + docs/baseline-stages.json (180/180).
Gates: kuna catalog --check OK; make test PARITY OK 675/675; make
test-stages PARITY OK 180/180. docs/baseline.json untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz added a commit that referenced this pull request Jun 25, 2026
Resolve union conflicts with main (which since this branch's base landed
gotoreduce, loopbreak_recovery/DIV-10, switchguardbound/#60, tailcalljump/#59,
macho-arm64e, and more). branchflip (S8 readability, opt-in/default-off,
ElementId-free) coexists with all of them:

- stages.toml: union [[settable]]/[[surface]] -> surface 93->94, settable
  47->48 (30 stage-model + 15 analysis + 3 loader); branchflip inserted
  after stackguard, before loopbreak_recovery; header counts updated.
- options.rs KUNA_OPTION_NAMES: union (branchflip + loopbreak_recovery).
- architecture.rs: union the set_kuna_option arm (branchflip on_off! +
  loopbreak_recovery); branch_flip field/ctor/reset/seam-copy all preserved.
- kuna_stages/tests.rs: surface_count 94, settable_count 48, live_value
  present-for-23 / suppressed-for-25 (branchflip is NOT field-backed),
  catalog-json trailing-commas 47.
- catalog_bytecompat.rs: fixture_has_all_48_settables; stage_catalog.json
  fixture regenerated from the binary (byte-for-byte test green).
- verify_w8_fw_universalaction.rs: nonblank 261 (252 C++ + branchflip +
  gotoreduce + 7 headers); list_action_decompile_oracle.txt re-numbered
  for the branchflip + gotoreduce leaves (byte-equal test green).
- xml.rs corpus count 139->140 (83 datatests + 57 stage tests).
- kuna-catalog.xml: source_decompiler=angr 13, structure-recovery 7,
  opt-in-tool 9.
- PROGRESS.md: union both session sets.

No DIV entry (opt-in/default-off; output byte-identical when off).
Regenerated docs/assertions.md + docs/baseline-stages.json (183/183).
Gates: kuna catalog --check OK; make test PARITY OK 675/675; make
test-stages PARITY OK 183/183. docs/baseline.json untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz
mahaloz deleted the feat/angr-missing-function-call-1101b1 branch July 29, 2026 08:01
mahaloz added a commit that referenced this pull request Aug 5, 2026
…eldb type_match 9 -> 35 of 525, +26 with 0 lost) (#266)

* [AUTOMATED] feat(p1): cppsig - apply the demangled C++ signature (leveldb type_match 9 -> 35 of 525, +26 with 0 lost)

kuna applied no demangled C++ signature at all. The demangler reduces a mangled
symbol to its qualified NAME only - a hard requirement of the `::`-scope
splitter - and `demangle_raw`, the full c++filt form, had shipped with NO
production caller since the demangler landed, its own header recording the
signature application as "a deferred follow-up".

The cost is a STRIPPED C++ shared library, where the exported `.dynsym` mangled
name is the only signature source left. On stripped google/leveldb -O0,
functions whose first parameter is a named pointer ran ghidra 188 / ida 150 /
binja 60 / angr 0 / kuna 0 across 527 functions.

New `analyzers/demangle/kuna_cppsig.rs` parses the demangled STRING, the same
shape as upstream's GnuDemanglerParser, and parks a prototype by entry address.
A C++ reference maps to a pointer; a by-value aggregate, array, function pointer
or overloaded operator refuses the whole signature. The return type is
deliberately NOT applied - Itanium encodes one only for a template function, so
upstream returns null and keeps what the analysis recovered; kuna expresses that
as `outtype: None`, read as "lock the INPUT half only".

Three-valued because Itanium mangles a static member function exactly like a
non-static one: `proven` (the default) applies only what the mangling entails
and measures precision 1.0000 / recall 0.7093 on 1329 symbols with DWARF ground
truth; `inferred` decides the rest from class evidence at precision 0.9278 /
recall 1.0000. Ghidra 12.1's own `this` decision on the same binary is 0.85.

Benchmark, decbench leveldb O0 (n=525) with the fixed scorer (decbench
origin/main @325046f, PR #60): type_match perfects 9 -> 35 at the default
(+26, zero lost), 38 under `inferred`. Rivals on the same scorer: ghidra 44,
ida 35, binja 11, angr 8 - kuna moves from last to second.

Plain C is untouched: 11 binaries / 1,351 functions, 0 changed.

Gated `cppsig`, default `proven` (DIV-62); the pass runs at load, so both
certainty tiers are stashed apart and the mode applies at the analysis commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN

* [AUTOMATED] docs(cppsig): complete the feature bundle with analysis.md + plan.md

The standing requirement is a docs/features/<slug>/ bundle of analysis.md,
plan.md and record.json; only record.json was written. Content is the
measured material from the PR body: the leveldb type_match standing, the
precision/recall table behind the three-valued `this` rule, the three
defects the whole-binary sweep found, and the refusals.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: mahaloz <[email protected]>
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.

1 participant