Skip to content

incorrect-duplication-chcon-a0e113: name-match known-no-return externs in ET_REL .o (noreturn_externmatch, DIV-12) - #91

Merged
mahaloz merged 3 commits into
mainfrom
feat/angr-incorrect-duplication-chcon-a0e113
Jun 26, 2026
Merged

mahaloz merged 3 commits into
mainfrom
feat/angr-incorrect-duplication-chcon-a0e113

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

incorrect-duplication-chcon: name-match known-no-return externs in ET_REL .o files

Closes the gap angr's test_decompiling_incorrect_duplication_chcon_main exposes on coreutils
chcon.o (main): kuna emitted ~90 lines of garbage after the no-return __stack_chk_fail()
call — the inter-function alignment padding (00 00 …, decoded as add byte ptr [rax], al)
decompiled as live code. angr emits none.

See docs/features/incorrect-duplication-chcon-a0e113/analysis.md
for the full analysis.

Root cause

stack_chk_fail is in kuna's vendored ELF known-no-return list (option noreturn_known,
default-on), so on a normal dynamically-linked ELF the call is marked no-return and the dead
fall-through never decoded. But in an ET_REL .o, __stack_chk_fail is an undefined extern:
its .symtab entry has address()==0 and there is no PLT stub, so the address-keyed
noreturn_known scan emits no fact for it. The relocobjects loader installs a FunctionSymbol
named __stack_chk_fail at a synthetic target (the call prints the name) but no no-return flag is
set — so flow runs off the end into the padding.

Mechanism

New option noreturn_externmatch (S2 flow-follow, ElementId 4103). When set, the
FlowEnvironment::query_call_no_return seam (infra/decompile_drive.rs) also reports no-return
for a callee whose name matches the same vendored ELF list — flow.rs ORs this with the proto
flag at the artificial-halt site, so a name match plants the halt and the trailing padding is never
decoded. The matcher (s2_lift/kuna_noreturn_externmatch.rs) include_str!s the same list
noreturn_known uses (kuna-analysis/data/ElfFunctionsThatDoNotReturn) and applies the same
leading-_ strip + global/std namespace guard, so it adds no risk class beyond the already
default-on noreturn_known; it merely reaches the ET_REL extern the address scan structurally
misses. A no-op on a normal ELF (the proto flag is already set).

Option & default

  • option noreturn_externmatch on|off — flip via kuna decompile … --option noreturn_externmatch off.
  • Default-ON (DIV-12). The full ablation is clean: 0 / 675 upstream datatest assertions
    change with it default-ON, and it is ~23% faster on the target (chcon.o::main median
    449.8 ms → 344.3 ms, n=5 — there is less dead padding to decompile). Set OFF to restore the prior
    byte-identical rendering.
  • One interaction: option noreturn_known off no longer alone restores the post-exit/__stack_chk_fail
    dead code (this feature is a second name-based gate); disable both to see the raw fall-through.

Verification

  • kuna catalog --check → catalog OK
  • kuna test --datatests --baseline docs/baseline.json → PARITY OK (675/675)
  • make test-stages → PARITY OK (193/193; tests/stages/ghangr-incorrect-duplication-chcon-a0e113.xml, +3)
  • make rust-test → green (3 new matcher unit tests; count/golden fixtures bumped)

🤖 Generated with Claude Code


Before / after — main in chcon.o

Real captured kuna output on the function this feature was built for, with option noreturn_externmatch flipped. Ported from angr — test_decompiling_incorrect_duplication_chcon_main; angr CLE/CFGFast extern no-return tagging; main.

metric noreturn_externmatch off noreturn_externmatch on (default)
gotos 33 33
labels 14 13 ⬇️
loc 313 191 ⬇️
switches 1 1
speed 449.82 ms 344.3 ms — Δ -23.46% (budget 5.0%)
kuna — before (option noreturn_externmatch off)
uint4 main(int4 a0,void *a1)

{
  unsigned int v1;
  void *v10; // rax
  uint1 *v11; // rax
  uint1 *v12; // rax
  int4 *v13; // rax
  uint1 *v14;
  uint1 v16;
  int4 v17;
  int4 v18; // edx
  char *v19; // rdx
  bool v2;
  char v20 [12];
  unsigned long v21; // stack - 0x48
  void *v22;
  void *v23;
  void *v24; // rsp
  void *v25;
  int8 v26; // rax
  int8 v27; // fs_offset
  uint4 v28; // stack - 0x5c
  int4 v29; // stack - 0x58
  uint1 v3; // al
  char v30; // stack - 0x51
  int8 v31; // stack - 0x50
  int8 v32; // stack - 0x40
  bool v4;
  uint1 v5;
  uint4 v6; // eax
  int4 v7;
  unsigned long v8; // rax
  int8 v9; // rax
  
  v2 = 0;
  v26 = (int8)a0;
  v23 = v20;
  v24 = v20;
  v25 = v20;
  v32 = *(int8 *)(v27 + 0x28);
  set_program_name(*a1);
  setlocale(6,0x4019d5);
  bindtextdomain(0x4019e6,0x401a81);
  textdomain(0x4019e6);
  atexit(dat_401d1e);
  v30 = '\0';
  v31 = 0;
  v29 = -1;
  v28 = 0x10;
label_401d48:
  v15 = 0x402200;
  v8 = getopt_long(a0,a1,0x401ab4,0x402200,0);
  v7 = (int4)v8;
  if (v7 == -1) {
label_401ed0:
    v16 = SUB81(v15,1);
    if (dat_400e31 == '\0') {
      v28 = 0x10;
      v4 = v29 != 0;
label_401eeb:
      v9 = (int8)dat_4042b0;
      v17 = a0 - dat_4042b0;
      v7 = dat_4042b0;
      Unique100004c2 = v4;
      if ((v31 != 0) || (v2)) goto label_401f63;
      if (1 < v17) goto label_4020a2;
    }
    else if (v28 == 0x10) {
      v4 = '\0';
      if (v29 == 1) {
        v15 = dcgettext(0,0x4018d8,5);
        error(1,0,v15);
        goto label_402043;
      }
      goto label_401eeb;
    }
    v4 = dat_400e31;
    if (v29 != 0) goto label_401eeb;
    v15 = dcgettext(0,0x401ac3,5);
    v7 = error(1,0,v15);
    v17 = v18;
label_401f63:
    if (1 <= v17) {
      if (v31 == 0) {
        dat_400e20 = 0;
        goto label_401fa5;
      }
      v21 = 0;
      v7 = rpl_getfilecon(v31,&v21);
      if (v7 < 0) goto label_40217c;
      dat_400e20 = v21;
      if (!v2) goto label_401fa5;
      goto label_402116;
    }
    if (v7 < a0) goto label_4021bd;
    v15 = 0x401ad5;
    goto label_402122;
  }
  v22 = v20;
  if (0x83 < v7) goto label_402137;
  if (v7 <= 0x47) {
    if (v7 == -0x83) goto label_402141;
    v22 = v20;
    if (v7 == -0x82) {
      usage(0);
      goto label_401ed0;
    }
    goto label_402137;
  }
  v22 = v20;
  switch(v7) {
    case 0x48:
      v28 = 0x11;
      goto label_401d48;
    default:
      goto label_402137;
    case 0x4c:
      v28 = 2;
      goto label_401d48;
    case 0x50:
      v28 = 0x10;
      goto label_401d48;
    case 0x52:
      dat_400e31 = '\x01';
      goto label_401d48;
    case 0x66:
      goto label_401d48;
    case 0x68:
      v29 = 0;
      goto label_401d48;
    case 0x6c:
      RAX = dat_4042a0;
      v2 = 1;
      goto label_401d48;
    case 0x72:
      RAX = dat_4042a0;
      v2 = 1;
      goto label_401d48;
    case 0x74:
      RAX = dat_4042a0;
      v2 = 1;
      goto label_401d48;
    case 0x75:
      RAX = dat_4042a0;
      v2 = 1;
      goto label_401d48;
    case 0x76:
      dat_400e30 = 1;
      goto label_401d48;
    case 0x80:
      v29 = 1;
      goto label_401d48;
    case 0x81:
      v30 = '\0';
      goto label_401d48;
    case 0x82:
      v30 = '\x01';
      goto label_401d48;
    case 0x83:
      v31 = dat_4042a0;
      goto label_401d48;
    
  }
label_4020a2:
  v16 = SUB81(v15,1);
  EDX = (int4)v9 + 1;
  Unique00023e00 = a1[v9];
  v7 = is_selinux_enabled();
  if ((1 <= v7) && (v7 = security_check_context(dat_400e20), v7 <= -1)) {
    v15 = quote(dat_400e20);
    v8 = dcgettext(0,0x401afe,5);
    v10 = (void *)__errno_location();
    error(1,*v10,v8,v15);
label_402116:
    v15 = 0x401908;
label_402122:
    v15 = dcgettext(0,v15,5);
    error(0,0,v15);
    v22 = v20;
    do {
label_402137:
      *(void *)&v22[-8] = 0x402141;
      v8 = usage(1);
      v23 = v22;
label_402141:
      *(void *)&v23[-8] = v8;
      v24 = &v23[-0x10];
      *(void *)&v23[-0x10] = 0;
      *(void *)&v23[-0x18] = 0x402175;
      version_etc(dat_404000,0x4019be,0x401a54,dat_404300,0x401aa6,0x401a99);
      *(void *)&v23[-0x18] = 0x40217c;
      exit(0);
label_40217c:
      *(void *)&v24[-8] = 0x40218b;
      v15 = quotearg_style(4,*(void *)&v24[0x18]);
      *(void *)&v24[-8] = 0x4021a1;
      v26 = dcgettext(0,0x400ee8,5);
      *(void *)&v24[-8] = 0x4021a9;
      v10 = (void *)__errno_location();
      v1 = *v10;
      *(void *)&v24[-8] = 0x4021bd;
      error(1,v1,v26,v15);
      v25 = v24;
label_4021bd:
      v15 = a1[v26 + -1];
      *(void *)&v25[-8] = 0x4021c7;
      v15 = quote(v15);
      *(void *)&v25[-8] = 0x4021dd;
      v8 = dcgettext(0,0x401ae5,5);
      *(void *)&v25[-8] = 0x4021ee;
      error(0,0,v8,v15);
      v22 = v25;
    } while( true );
  }
label_401fa5:
  if ((dat_400e31 == '\0') || (v30 == '\0')) {
    dat_400e28 = 0;
label_401fc4:
    v14 = (uint1 *)&a1[dat_4042b0];
    v6 = process_files(v14,v28 | 8);
    if (v32 == *(int8 *)(v27 + 0x28)) {
      return (v6 ^ 1) & 0xff;
    }
    __stack_chk_fail();
    v3 = (uint1)v11;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    *v19 = *v19 + (char)v19;
    *v11 = *v11 + v3;
    *v11 = *v11 + v3;
    v5 = *v11;
    *v11 = *v11 + v3;
    v4 = (v3 - 0x1b) - CARRY1(v5,v3);
    v12 = (uint1 *)CONCAT71(SUB87(v11,1),v4);
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    *v12 = *v12 + v4;
    v5 = *v12;
    *v12 = *v12 + v16;
    v6 = ((int4)v12 - *(int4 *)v12) - (uint4)CARRY1(v5,v16);
    v13 = (int4 *)(uint8)v6;
    v4 = (char)v6;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    *(char *)v13 = (char)*v13 + v4;
    v16 = *v14;
    *v14 = *v14 + SUB81(v19,1);
    v6 = (v6 - *v13) - (uint4)CARRY1(v16,SUB81(v19,1));
    v14 = (uint1 *)(uint8)v6;
    v5 = (uint1)v6;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *v14 = *v14 + v5;
    *(void *)v14 = *(void *)v14;
    v16 = *v14;
    *v14 = *v14 + v5;
    v14 = &v14[-(uint8)CARRY1(v16,v5) - *(int8 *)v14];
    v4 = (char)v14;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    *v14 = *v14 + v4;
    return;
  }
label_402043:
  RAX = get_root_dev_ino(0x400df0);
  if (RAX != 0) goto label_401fc4;
  v15 = quotearg_style(4,0x40196c);
  v8 = dcgettext(0,0x401938,5);
  v10 = (void *)__errno_location();
  v9 = error(1,*v10,v8);
  goto label_4020a2;
}
kuna — after (option noreturn_externmatch on)
uint4 main(int4 a0,void *a1)

{
  bool v1;
  int4 v10; // edx
  unsigned long v11; // stack - 0x48
  int8 v13; // rax
  int8 v14; // fs_offset
  uint4 v15; // stack - 0x5c
  int4 v16; // stack - 0x58
  int8 v17; // stack - 0x50
  int8 v18; // stack - 0x40
  bool v2;
  bool v3;
  int4 v4;
  uint4 v5; // eax
  int8 v6; // rax
  void *v7; // rax
  unsigned long v8; // rax
  int4 v9;
  
  v1 = 0;
  v13 = (int8)a0;
  v18 = *(int8 *)(v14 + 0x28);
  set_program_name(*a1);
  setlocale(6,0x4019d5);
  bindtextdomain(0x4019e6,0x401a81);
  textdomain(0x4019e6);
  atexit(dat_401d1e);
  v2 = 0;
  v17 = 0;
  v16 = -1;
  v15 = 0x10;
label_401d48:
  v4 = getopt_long(a0,a1,0x401ab4,0x402200,0);
  if (v4 == -1) {
label_401ed0:
    if (dat_400e31 == '\0') {
      v15 = 0x10;
      v3 = v16 != 0;
label_401eeb:
      v6 = (int8)dat_4042b0;
      v9 = a0 - dat_4042b0;
      v4 = dat_4042b0;
      Unique100003f1 = v3;
      if ((v17 != 0) || (v1)) goto label_401f63;
      if (1 < v9) goto label_4020a2;
label_401f13:
      if (a0 <= v4) {
        v12 = 0x401ad5;
        goto label_402122;
      }
    }
    else {
      if (v15 == 0x10) {
        v3 = '\0';
        if (v16 == 1) {
          v12 = dcgettext(0,0x4018d8,5);
          error(1,0,v12);
          goto label_402043;
        }
        goto label_401eeb;
      }
      v3 = dat_400e31;
      if (v16 != 0) goto label_401eeb;
      v12 = dcgettext(0,0x401ac3,5);
      v4 = error(1,0,v12);
      v9 = v10;
label_401f63:
      if (v9 <= 0) goto label_401f13;
      if (v17 == 0) {
        dat_400e20 = 0;
        goto label_401fa5;
      }
      v11 = 0;
      v4 = rpl_getfilecon(v17,&v11);
      if (0 <= v4) {
        dat_400e20 = v11;
        if (!v1) goto label_401fa5;
        goto label_402116;
      }
      v12 = quotearg_style(4,v17);
      v13 = dcgettext(0,0x400ee8,5);
      v7 = (void *)__errno_location();
      error(1,*v7,v13,v12);
    }
    v12 = quote(a1[v13 + -1]);
    v8 = dcgettext(0,0x401ae5,5);
    error(0,0,v8,v12);
    goto label_402137;
  }
  if (0x83 < v4) goto label_402137;
  if (v4 <= 0x47) {
    if (v4 == -0x83) goto label_402141;
    if (v4 == -0x82) {
      usage(0);
      goto label_401ed0;
    }
    goto label_402137;
  }
  switch(v4) {
    case 0x48:
      v15 = 0x11;
      goto label_401d48;
    default:
      goto label_402137;
    case 0x4c:
      v15 = 2;
      goto label_401d48;
    case 0x50:
      v15 = 0x10;
      goto label_401d48;
    case 0x52:
      dat_400e31 = '\x01';
      goto label_401d48;
    case 0x66:
      goto label_401d48;
    case 0x68:
      v16 = 0;
      goto label_401d48;
    case 0x6c:
      RAX = dat_4042a0;
      v1 = 1;
      goto label_401d48;
    case 0x72:
      RAX = dat_4042a0;
      v1 = 1;
      goto label_401d48;
    case 0x74:
      RAX = dat_4042a0;
      v1 = 1;
      goto label_401d48;
    case 0x75:
      RAX = dat_4042a0;
      v1 = 1;
      goto label_401d48;
    case 0x76:
      dat_400e30 = 1;
      goto label_401d48;
    case 0x80:
      v16 = 1;
      goto label_401d48;
    case 0x81:
      v2 = 0;
      goto label_401d48;
    case 0x82:
      v2 = 1;
      goto label_401d48;
    case 0x83:
      v17 = dat_4042a0;
      goto label_401d48;
    
  }
label_4020a2:
  EDX = (int4)v6 + 1;
  Unique00023e00 = a1[v6];
  v4 = is_selinux_enabled();
  if ((1 <= v4) && (v4 = security_check_context(dat_400e20), v4 <= -1)) {
    v12 = quote(dat_400e20);
    v8 = dcgettext(0,0x401afe,5);
    v7 = (void *)__errno_location();
    error(1,*v7,v8,v12);
label_402116:
    v12 = 0x401908;
label_402122:
    v12 = dcgettext(0,v12,5);
    error(0,0,v12);
label_402137:
    usage(1);
label_402141:
    version_etc(dat_404000,0x4019be,0x401a54,dat_404300,0x401aa6,0x401a99);
                    /* WARNING: Subroutine does not return */
    exit(0);
  }
label_401fa5:
  if ((dat_400e31 == '\0') || (!v2)) {
    dat_400e28 = 0;
label_401fc4:
    v5 = process_files(&a1[dat_4042b0],v15 | 8);
    if (v18 == *(int8 *)(v14 + 0x28)) {
      return (v5 ^ 1) & 0xff;
    }
                    /* WARNING: Subroutine does not return */
    __stack_chk_fail();
  }
label_402043:
  RAX = get_root_dev_ino(0x400df0);
  if (RAX != 0) goto label_401fc4;
  v12 = quotearg_style(4,0x40196c);
  v8 = dcgettext(0,0x401938,5);
  v7 = (void *)__errno_location();
  v6 = error(1,*v7,v8,v12);
  goto label_4020a2;
}
angr reference (the goal, v9.2.213)
typedef struct option {
    char * name;
    int has_arg;
    char padding_c[4];
    int * flag;
    int val;
} option;

extern char .LC25;
extern char Version;
extern char affect_symlink_referent;
extern int dev_ino_buf.0;
extern unsigned long got.close_stdout;
extern char long_options;
extern unsigned long optarg;
extern unsigned int optind;
extern char recurse;
extern unsigned long long root_dev_ino;
extern unsigned long long specified_context;
extern unsigned long long specified_range;
extern unsigned long long specified_role;
extern unsigned long long specified_type;
extern unsigned long long specified_user;
extern unsigned long stdout;
extern char verbose;

int main(unsigned int a0, long long *ptr)
{
    char v6;  // r15b
    unsigned long v7;  // r12
    char *v16;  // rsi
    char *v19;  // rax
    int *err;  // rax
    char *v21;  // rax
    int *err;  // rax
    long long v8;  // rax
    char v9;  // al
    unsigned long idx;  // rax
    unsigned int v12;  // edx
    unsigned long v13;  // rax
    char *v14;  // rax
    int *err;  // rax
    unsigned int v0;  // [bp-0x5c]
    unsigned int flag;  // [bp-0x58]
    char v2;  // [bp-0x51]
    long long v3;  // [bp-0x50]
    unsigned long choice;  // [bp-0x48]

    v6 = 0;
    v7 = a0;
    set_program_name(*(ptr));
    setlocale(6, &.LC25);
    bindtextdomain("coreutils", "/usr/local/share/locale");
    textdomain("coreutils");
    atexit(got.close_stdout);
    v2 = 0;
    v3 = 0;
    flag = 4294967295;
    v0 = 16;
    while (true)
    {
        v8 = getopt_long(v7, ptr, "HLPRhvu:r:t:l:", &long_options, NULL);
        if ((int)v8 == -1)
            break;
        if ((int)v8 > 131)
            goto LABEL_402137;
        if ((int)v8 > 71)
        {
            switch ((int)v8)
            {
            case 72:
                v0 = 17;
                continue;
            case 76:
                v0 = 2;
                continue;
            case 80:
                v0 = 16;
                continue;
            case 82:
                recurse = 1;
                continue;
            case 102:
                continue;
            case 104:
                flag = 0;
                continue;
            case 108:
                v6 = 1;
                specified_range = optarg;
                continue;
            case 114:
                v6 = 1;
                specified_role = optarg;
                continue;
            case 116:
                v6 = 1;
                specified_type = optarg;
                continue;
            case 117:
                v6 = 1;
                specified_user = optarg;
                continue;
            case 118:
                verbose = 1;
                continue;
            case 128:
                flag = 1;
                continue;
            case 129:
                v2 = 0;
                continue;
            case 130:
                v2 = 1;
                continue;
            case 131:
                v3 = optarg;
                continue;
            }
            goto LABEL_402137;
        }
        else if ((int)v8 != -131)
        {
            if ((int)v8 == -130)
                usage(0); /* do not return */
            goto LABEL_402137;
        }
        else
        {
            version_etc(stdout, "chcon", "GNU coreutils", *((long long *)&Version), "Russell Coker", "Jim Meyering", 0, v8);
            exit(0); /* do not return */
        }
    }
    v9 = recurse;
    if (!recurse)
    {
        v0 = 16;
        v9 = flag;
    }
    else if (v0 == 16)
    {
        v9 = 0;
        if (flag == 1)
            error(1, 0, dcgettext(NULL, "-R --dereference requires either -H or -L", 5));
    }
    else if (!flag)
    {
        error(1, 0, dcgettext(NULL, "-R -h requires -P", 5));
    }
    affect_symlink_referent = v9;
    idx = optind;
    v12 = (v7 & 4294967295) - idx;
    if (!v3 && !v6)
    {
        if (v12 > 1)
        {
            v13 = ptr[idx];
            optind = (unsigned int)idx + 1;
            specified_context = v13;
            if ((int)is_selinux_enabled() > 0 && (int)security_check_context(specified_context) < 0)
            {
                quote(specified_context);
                v14 = dcgettext(NULL, "invalid context: %s", 5);
                err = __errno_location();
                error(1, *(err), v14);
            }
LABEL_401fa5:
            if (!recurse || !v2)
            {
                root_dev_ino = 0;
            }
            else
            {
                root_dev_ino = get_root_dev_ino(&dev_ino_buf.0);
                if (!root_dev_ino)
                {
                    quotearg_style(4, "/");
                    v21 = dcgettext(NULL, "failed to get attributes of %s", 5);
                    err = __errno_location();
                    error(1, *(err), v21);
                }
            }
            return (char)process_files(&ptr[optind], v0 | 8) ^ 1;
        }
LABEL_401f13:
        if ((unsigned int)idx >= (unsigned int)v7)
        {
            v16 = "missing operand";
LABEL_402122:
            error(0, 0, dcgettext(NULL, v16, 5));
        }
        else
        {
            quote(ptr[1 + v7]);
            error(0, 0, dcgettext(NULL, "missing operand after %s", 5));
        }
    }
    else
    {
        if (v12 <= 0)
            goto LABEL_401f13;
        if (v3)
        {
            choice = 0;
            if ((int)rpl_getfilecon(v3, &choice) < 0)
            {
                quotearg_style(4, v3);
                v19 = dcgettext(NULL, "failed to get security context of %s", 5);
                err = __errno_location();
                error(1, *(err), v19);
            }
            specified_context = choice;
            if (!v6)
                goto LABEL_401fa5;
            v16 = "conflicting security context specifiers given";
            goto LABEL_402122;
        }
        else
        {
            specified_context = 0;
            goto LABEL_401fa5;
        }
    }
LABEL_402137:
    usage(1); /* do not return */
}

…s in ET_REL .o (option noreturn_externmatch, DIV-12)

Closes the angr test_decompiling_incorrect_duplication_chcon_main gap on
coreutils chcon.o::main: kuna emitted ~90 lines of garbage after the no-return
__stack_chk_fail() call (inter-function alignment padding 00 00 -> add [rax],al
decoded as live code). angr emits none.

Root cause: __stack_chk_fail is in the vendored ELF known-no-return list, but in
an ET_REL .o it is an undefined extern (symtab address()==0, no PLT), so the
address-keyed noreturn_known scan emits no fact. relocobjects installs a
FunctionSymbol at a synthetic target (the call prints the name) but no no-return
flag, so flow runs into the padding.

New option noreturn_externmatch (S2 flow-follow, ElementId 4103): the
query_call_no_return seam also reports no-return when the callee name matches the
same vendored list (include_str! of kuna-analysis/data/ElfFunctionsThatDoNotReturn,
same leading-_ strip + global/std namespace guard). flow.rs ORs it at the
artificial-halt site. A no-op on a normal ELF (proto flag already set); reaches
the ET_REL extern the address scan structurally misses.

Default-ON (DIV-12): clean 0/675 ablation, 23% faster on the target (less dead
padding to decompile), correctness fix, no risk class beyond the already
default-on noreturn_known.

Gates: catalog OK; datatest PARITY OK (675/675); test-stages PARITY OK (193/193,
+3 via ghangr-incorrect-duplication-chcon-a0e113.xml); rust-test green (3 new
matcher unit tests; count/golden fixtures bumped). PE multiformat test updated to
disable both name-based no-return gates to see raw dead code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mahaloz

mahaloz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Overlaps with #90 (parallel-worker collision — please reconcile before merging both).

#90 (option noreturn_extern, branch feat/angr-tail-tail-bytes-ret-dup-f79d1d, found via tail.o) implements the same mechanism this PR does: re-check the callee name against the vendored ELF known-no-return list at the FlowEnvironment::query_call_no_return flow seam when the address-keyed noreturn_known scan missed it (the ET_REL .o undefined-extern case). Both were developed independently — noreturn_extern is not present in this branch's base (main @ fc6dca6), so it did not appear in kuna catalog here.

Key differences for the reviewer to weigh:

Suggested resolution: keep ONE option (one name, one default decision) and close/rebase the other. If default-ON is accepted, this PR's DIV-12 + the noreturn_known off interaction handling (PE multiformat test disables both gates) is the more complete variant; if opt-in is preferred, fold this PR's chcon witness + stage test into #90.

mahaloz and others added 2 commits June 26, 2026 18:26
)

Union-resolve so noreturn_externmatch coexists with #90's noreturn_extern
(both name-match the ELF no-return list at the same flow seam). Deconflicted:
- ElementId 4103 -> 4104 (4103 taken by #90's noreturn_extern on main)
- DIV-12 -> DIV-13 (DIV-12 taken by main's region structurer); renumbered in
  divergences.md, architecture.rs, stages.toml, the module, the testcase XML,
  UPSTREAM.md, stage-mapping.md, PROGRESS.md, feature record/plan/pr_body
- decompile_drive.rs query_call_no_return: BOTH gated checks kept
  (noreturn_extern_match + noreturn_extern_calls)
- s2_lift/mod.rs: both modules declared
- stages.toml header surface=95, settable=56 (33 stage-model knobs); +1 surface +1 settable
- kuna_stages/tests.rs: settable 56, surface 95, json-comma 55, live-value 25;
  test fns renamed (settable_count_is_56 / live_value_present_for_25_suppressed_for_31)
- catalog_bytecompat.rs: fixture_has_all_56_settables
- kuna-base/xml.rs corpus count 147 (83 datatests + 64 stage tests)
- kuna-catalog.xml: source_decompiler angr count 16 (both noreturn_extern + externmatch)
- #90's ghangr-noreturn_extern.xml: pass 1 now also sets `noreturn_externmatch off`
  to isolate the noreturn_extern toggle (externmatch default-on else bounds it first)
- regenerated stage_catalog.json fixture, docs/assertions.md, baseline-stages.json (208 keys)

Gates green: kuna catalog --check OK; make test 675/675 PARITY OK;
make test-stages 208/208 PARITY OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz
mahaloz merged commit 98cfc60 into main Jun 26, 2026
mahaloz added a commit that referenced this pull request Jun 26, 2026
Union-resolve so crossjumprevert (opt-in default-off) coexists with #90's
noreturn_extern and #91's noreturn_externmatch on main. Deconflicted:
- ElementId 4103 -> 4105 (4103=noreturn_extern, 4104=noreturn_externmatch on main)
- stages.toml header surface=95, settable=57 (34 stage-model knobs); +1 settable
- kuna_stages/tests.rs: settable 57, surface 95, json-comma 56, live-value 25
  (crossjumprevert has no live reader, in the suppressed allowlist);
  test fns renamed (settable_count_is_57 / live_value_present_for_25_suppressed_for_32)
- catalog_bytecompat.rs: fixture_has_all_57_settables
- kuna-base/xml.rs corpus count 148 (83 datatests + 65 stage tests)
- kuna-catalog.xml: source_decompiler angr 17, change_kind structure-recovery 9
  (both add crossjumprevert)
- verify_w8_fw_universalaction.rs auto-merged: 262 leaves (252 C++ + branchflip
  + gotoreduce + crossjumprevert + 7 headers); universalaction/seams/architecture/block
  wiring of revert_cross_jumps preserved alongside the noreturn_extern* additions
- regenerated stage_catalog.json fixture, docs/assertions.md, baseline-stages.json (212 keys)

Gates green: kuna catalog --check OK; make test 675/675 PARITY OK;
make test-stages 212/212 PARITY OK.

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-incorrect-duplication-chcon-a0e113 branch July 29, 2026 08:01
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