Skip to content

[AUTOMATED] feat(p1): fdeinterior - a C++ landing pad is not a function, it is a point inside one (-1030 spurious entries, 0 real lost) - #263

Merged
mahaloz merged 1 commit into
mainfrom
feat/fdeinterior
Aug 5, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/fdeinterior

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

A kuna FunctionSymbol is an entry address with no extent. Database::add_function
takes an address and find_function answers is a function registered AT this address,
never is this address INSIDE one — so every discovery oracle's dedup is an equality test,
and a candidate 12 bytes into a body sails through it.

Three oracles do exactly that on ordinary compiler output, and --mode auto turns all three
on for anything under 500 KiB by resolving to aggressive:

  • eh_frame_full promotes each .gcc_except_table landing pad to a top-level function
    — it is designed to ("a landing pad sits mid-function"),
  • aif starts one at the first undecoded byte of an unwinder-only region, which is
    routinely not an instruction boundary,
  • the prologue patterns match an aligned push rbp; mov rbp,rsp inside a larger body.

On a g++ -O0 probe, probe_try_catch [0x2acf, 0x2ba7) yields three extra entries, and
they survive stripping, so a per-function benchmark scores them:

0x2acf probe_try_catch
0x2b0b sub_2b0b      <- .gcc_except_table landing pad (catch dispatch)
0x2b1a sub_2b1a      <- second byte of the `je 2b6b` at 0x2b19
0x2b8a sub_2b8a      <- .gcc_except_table landing pad (cleanup)

A mid-frame entry inherits its parent's live frame pointer, so every local is a
dereference of an undefined value:

// BEFORE  (--option fdeinterior off)
unsigned int sub_2b0b(unsigned long a0,unsigned long a1,int8 a2)
{
  int8 v3; // rbp                       <- never assigned
  ...
    *(unsigned int *)(v3 + -0x20) = 0xffffffff;
    printf("caught: %s\n",(*v1)(v2));
}

// AFTER  (default)
// sub_2b0b does not exist; 0x2b0b is part of probe_try_catch @ 0x2acf
int4 probe_try_catch(int4 v)
{
  int4 v1; // eax
  v1 = probe_throws(v);
  return v1 + probe_throws(v + 1);
}

The rivals: IDA Pro 9.2 gives get_func(0x2b0b).start_ea == 0x2acf — the pad belongs to
the function whose FDE covers it. Ghidra 12.1 returns no containing function at all here
(its GccExceptionAnalyzer errored on this PIE — a Ghidra bug, not a model). IDA's model is
the target.

The fix

.eh_frame carries the extent kuna lacks: each FDE records one function's
[pcBegin, pcBegin + pcRange) by construction (one .cfi_startproc/.cfi_endproc pair).
So a discovered entry strictly inside an FDE body is not a function, on the unwinder's own
authority.

analyzers/entry/kuna_fdeinterior.rs reuses scan_eh_frame_starts's record walk and adds
the one field it skips — pcRange, decoded with the CIE R encoding's format bits only
(it is a length, so the pc-relative application must not be applied). The commit filters the
fully merged entry set, after the deferred Listing consumers, because one of the three
producers is aif.

Not every FDE describes one function: the linker gives the whole PLT a single FDE and
every stub inside it is real. The first prototype deleted every import. A range is therefore
used only when no other named function start, no other FDE pcBegin, and no
.plt/.plt.sec/.plt.got/.iplt/.MIPS.stubs section falls inside it. An entry at an
FDE start is never suppressed, so oracle 3's own product is preserved.

Option decision: gated, default-ON (DIV-61)

Changing which functions exist is output-changing, so it ships behind a named option rather
than as a bare bug fix. It is default-ON because the measurement leaves no judgment call:
across 72 C binaries, 8 C++ probes, a static glibc image, 2 PEs, an ET_REL .o and 98 ARM
images, not one removed entry is a real function and not one carries a name, and nothing
is ever added. --option fdeinterior off restores the previous discovery set exactly
(asserted end-to-end).

The sweep — every disappearing entry classified

kuna functions off vs on over 72 stripped x86-64 ELF binaries (decbench O0+O2: coreutils,
bash, gzip, tar, grep, diffutils, openssh, e2fsprogs, gnutls, dpkg, zlib, bzip2, findutils,
kmod). Each dropped entry is classified against the matching unstripped binary's FUNC
symbols — address and size, so "inside a real body" is checkable.

binaries 72
entries off → on 36,568 → 35,538
dropped / added 1,030 / 0
dropped that are a real function's entry 0
dropped that carry a name (PLT stub, symbol) 0
dropped strictly inside a real function body 1,030
…not even an instruction boundary 52

C++ (where the landing pads are):

binary off on dropped landing pads other interior real lost named lost
probe_O0.stripped 189 162 27 14 13 0 0
probe_O2.stripped 71 64 7 4 3 0 0
big_O0.stripped (STL + exceptions) 599 449 150 98 52 0 0
big_O2.stripped (--mode aggressive) 161 86 75 74 1 0 0

25% of big_O0's reported function list was junk.

other population off on note
static glibc, --mode aggressive 1,358 1,087 271 dropped, 0 real, 0 named — static .plt/.iplt untouched
mydoom.exe (PE) 280 280 ELF-only ⇒ inert
dexter.dll (PE) 270 270 inert
big.o (ET_REL, relocobjects) 575 575 every FDE pcBegin is section-relative 0, so the overlapping set is dropped wholesale

Emitted C — whole-binary decompile-all, comparing every surviving function:

binary off on removed added bodies changed names changed
big_O0.stripped (C++) 599 449 150 0 0 0
big_O0 (C++, unstripped) 600 450 150 0 0 0
probe_O0.stripped (C++) 189 162 27 0 0 0
probe_O0 (C++, unstripped) 190 163 27 0 0 0
gzip (C, O0) 263 248 15 0 0 0
b2sum (C, O0) 228 216 12 0 0 0
fmt (C, O0) — the #264 MAX_TYPE_DEPTH target 198 191 7 0 0 0
fmt (C, O2) 151 151 0 0 0 0

A pure removal: of the functions that survive, not one changes its text or its name.

#259 (tailcallentry) non-regression — measured

Same corpus and same surface docs/features/tailcallentry/ used
(kuna functions --mode aggressive), with --option tailcallentry on, fdeinterior
off vs on, over every ARM image in the three decbench optimisation trees:

ARM TOTAL: images=98  failed=0  entries_off=57578  entries_on=57578
           images_with_any_change=0

Byte-identical entry sets on all 98 images. Structural rather than lucky: bare-metal ARM
unwinds through .ARM.exidx, and only 3 of 98 images carry any .eh_frame FDE (riot-os
hello-world.elf, 2 FDEs, containing no discovered entry). The same argument covers the
in-flight ARM entry-granularity work in draft PR #239 — it operates on a population this
option cannot see.

Rebased onto #264, and re-measured rather than carried forward

This branch sits on 890096b6 (#264 cppproto, DIV-60), itself on 1cff8ecb (#262
cppcallnames, DIV-59). Neither is inert with respect to this change, so both were
re-measured:

  • [AUTOMATED] feat(p1): cppproto - ingest C++ function prototypes from DWARF #264 ingests C++ prototypes from DWARF through DW_AT_specification, recovering
    out-of-line member and namespace definitions that were previously dropped entirely
    . On
    an unstripped C++ binary far more addresses now carry a real named function symbol — which
    is exactly the input to this option's "range holds no other named function start"
    condition. The invariant holds against the new symbol set:

    unstripped C++ off on dropped real lost named lost named entries after
    big_O0 600 450 150 0 0 447 / 450
    big_O2 87 87 0 0 0 —
    probe_O0 190 163 27 0 0 161 / 163
    probe_O2 72 65 7 0 0 —

    The stripped counterparts are verified unchanged at 449 and 162 entries (no DWARF for
    cppproto to read), not assumed.

  • [AUTOMATED] fix(p9): cppcallnames - render a C++ callee's qualified name at the call site (DIV-59) #262 changed C++ callee-name rendering everywhere. Both arms of every off/on comparison
    are the same build, so it cancels; the surviving_names_changed / NAMED_LOST counters
    are 0 everywhere.

  • [AUTOMATED] feat(p1): cppproto - ingest C++ function prototypes from DWARF #264 also altered 9 plain-C functions in coreutils fmt via MAX_TYPE_DEPTH, so fmt
    was decompiled whole in both arms specifically to keep the two effects unconflated —
    198 → 191 entries with 0 surviving bodies changed, and fmt-O2 151 → 151 with none.

Catalog counters were derived, not incremented. #264 and this PR had made an identical
off-by-one edit to the same three assertions, so the merge resolution would have shipped the
wrong number had it been trusted. Captured from a fresh post-rebase phase catalog and
counted: 91 settables, 20 core / 41 transform / 30 analysis, 90 catalog rows (the naive
merge would have left 90/29/89). phase_catalog.json re-captured and docs/options.md
regenerated from the post-rebase build; the assertions were then verified by running them.
No tests/stages/*.xml is added, so neither the corpus file count nor
docs/baseline-stages.json moves.

Disclosed interaction

eh_frame_full's product is now constrained by this gate: with both on, a landing pad inside
a single-function FDE is no longer committed. That is the intended composition (the pad is
the thing being rejected). The existing verify_eh_frame_full e2e test now flips
fdeinterior off in its option-on arm so it keeps testing what the LSDA decode produces.

Gates (all re-run after the #264 rebase)

gate result
make test PARITY OK, 675/675, no re-pin, no per-test opt-out
make test-stages PARITY OK, 394/394
make rust-test green, 4,457 tests passed / 0 failed
make check-spec OK (lenient and --strict)
kuna catalog --check OK

The datatest corpus is structurally untouched: the XML <binaryimage> bootstrap never runs
the analyzer tier.

Speed

The added work is one linear .eh_frame record walk — the same section the always-on
FDE-pcBegin oracle already reads — plus one binary search per discovered entry. The savings
are the suppressed entries never being decompiled, so every measurement is negative or
neutral.

measurement off on delta
scripts.pipeline.timeit, probe_O0 probe_try_catch, 15 samples 151.76 ms 107.33 ms -29.28%
interleaved kuna functions gzip-O0, 15 pairs 450.9 ms 449.3 ms -0.35%
interleaved kuna functions tar-O0, 15 pairs 164.9 ms 158.5 ms -3.87%
interleaved kuna functions big_O0.stripped, 15 pairs 343.9 ms 269.3 ms -21.68%
interleaved kuna functions static glibc, 11 pairs 244.0 ms 244.1 ms +0.06%
interleaved decompile-all gzip, 9 pairs 2,867.8 ms 2,746.7 ms -4.22%
interleaved decompile-all b2sum, 9 pairs 5,719.1 ms 5,439.4 ms -4.89%

Honest caveat: an 11-sample timeit run taken while the workspace suite was saturating the
box reported +4.67% and did not reproduce on an idle box.

Tests

decompiler/crates/kuna-console/tests/verify_fdeinterior.rs, two-pass over the vendored
eh_lsda_x86_64 fixture (guarded = FDE [0x4012d6, 0x40137a), catch dispatch at
0x4012e2), eh_frame_full on in both arms:

  1. fdeinterior off — sub_4012e2 registers and decompiles (the bug, and the proof that
    off restores the old set),
  2. default — sub_4012e2 is absent while its FDE owner sub_4012d6 still decompiles,
  3. no named function is lost (the PLT property).

Plus module unit tests for the strictness of is_interior and the empty-bodies no-op. No
tests/stages/*.xml: the XML datatest path never runs the analyzer tier, so the corpus
cannot express this — the same reason tailcallentry (#259) and cortexmvectors shipped
cross-crate e2e tests instead.

Bundle: docs/features/fdeinterior/. Spec: docs/spec/01-program-prep.md §1.5. DIV-61.


Captured before / after — the vendored eh_lsda_x86_64 fixture

The visible product of this feature is which functions exist, so the capture is the
function list, not one body at a forced address. (scripts.pipeline.prdemo decompiles with
--addr, which produces a body at an address whether or not it is in the discovered set, so
its two panes would be identical here by construction — this replaces it.)

guarded occupies the FDE [0x4012d6, 0x40137a); its .gcc_except_table LSDA names the
catch dispatch at 0x4012e2. Both runs pass --option eh_frame_full on.

before — kuna functions eh_lsda_x86_64 --option eh_frame_full on --option fdeinterior off (25 entries)
0x401000	_DT_INIT
0x401020	sub_401020
0x4010d0	__printf_chk	(sub_4010d0)
0x4010e0	std::runtime_error::runtime_error	(sub_4010e0)
0x4010f0	__cxa_begin_catch	(sub_4010f0)
0x401100	__cxa_allocate_exception	(sub_401100)
0x401110	__cxa_free_exception	(sub_401110)
0x401120	std::runtime_error::~runtime_error	(sub_401120)
0x401130	__cxa_end_catch	(sub_401130)
0x401140	__gxx_personality_v0	(sub_401140)
0x401150	__cxa_throw	(sub_401150)
0x401160	_Unwind_Resume	(sub_401160)
0x401170	sub_401170
0x4011a0	sub_4011a0
0x4011b0	sub_4011b0
0x401220	_FINI_0
0x401250	_INIT_0
0x401256	sub_401256
0x4012bf	sub_4012bf
0x4012d6	sub_4012d6
0x4012e2	sub_4012e2
0x401352	sub_401352
0x401366	sub_401366
0x40137a	sub_40137a
0x4013cc	_DT_FINI
after — the same with --option fdeinterior on (the default, 21 entries)
0x401000	_DT_INIT
0x401020	sub_401020
0x4010d0	__printf_chk	(sub_4010d0)
0x4010e0	std::runtime_error::runtime_error	(sub_4010e0)
0x4010f0	__cxa_begin_catch	(sub_4010f0)
0x401100	__cxa_allocate_exception	(sub_401100)
0x401110	__cxa_free_exception	(sub_401110)
0x401120	std::runtime_error::~runtime_error	(sub_401120)
0x401130	__cxa_end_catch	(sub_401130)
0x401140	__gxx_personality_v0	(sub_401140)
0x401150	__cxa_throw	(sub_401150)
0x401160	_Unwind_Resume	(sub_401160)
0x401170	sub_401170
0x4011a0	sub_4011a0
0x4011b0	sub_4011b0
0x401220	_FINI_0
0x401250	_INIT_0
0x401256	sub_401256
0x4012d6	sub_4012d6
0x40137a	sub_40137a
0x4013cc	_DT_FINI

Removed: 0x4012bf, 0x4012e2, 0x401352, 0x401366 — every one strictly inside a
single-function FDE body. Added: none. 0x4012d6 (the FDE start, guarded) and every named
PLT stub survive.

@mahaloz
mahaloz force-pushed the feat/fdeinterior branch 3 times, most recently from 6ec5564 to 902b9fa Compare August 5, 2026 05:36
…on, it is a point inside one (-1030 spurious entries, 0 real lost)

A kuna FunctionSymbol is an entry address with no extent: Database::add_function
takes an address and find_function answers "is a function registered AT this
address", never "is this address INSIDE one". Every discovery oracle's dedup is
therefore an equality test, and a candidate 12 bytes into a body passes it.

Three oracles do exactly that on ordinary compiler output, and --mode auto turns
all three on for anything under 500 KiB by resolving to `aggressive`:
eh_frame_full promotes each .gcc_except_table landing pad to a top-level function
(it is designed to), aif starts one at the first undecoded byte of an
unwinder-only region (routinely not an instruction boundary), and the prologue
patterns match an aligned `push rbp; mov rbp,rsp` inside a larger body. On a
g++ -O0 probe, probe_try_catch [0x2acf,0x2ba7) yields sub_2b0b / sub_2b1a /
sub_2b8a, all three surviving stripping, and sub_2b0b decompiles with an
uninitialised rbp so every local is a garbage dereference. IDA Pro 9.2 gives
get_func(0x2b0b).start_ea == 0x2acf; that is the model.

.eh_frame carries the missing extent: each FDE records ONE function's
[pcBegin, pcBegin+pcRange). kuna_fdeinterior.rs reuses scan_eh_frame_starts's
record walk and adds the one field it skips - pcRange, decoded with the CIE R
encoding's format bits only, since it is a length - and the commit filters the
FULLY MERGED entry set, after the deferred Listing consumers, because one
producer is aif.

Not every FDE describes one function: the linker gives the whole PLT a single
FDE and every stub inside it is real (the first prototype deleted every import).
A range is used only when no other named function start, no other FDE pcBegin,
and no .plt/.plt.sec/.plt.got/.iplt/.MIPS.stubs section falls inside it. An entry
AT an FDE start is never suppressed, so oracle 3's own product is preserved.

Gated and default-ON (DIV-61) because the measurement leaves no judgment call.
kuna functions off vs on over 72 stripped decbench x86-64 binaries, every dropped
entry classified against the matching unstripped binary's FUNC symbols (address
and size): 36,568 -> 35,538 entries, 1,030 dropped, 0 added, ZERO that are a real
function's entry, ZERO that carry a name, all 1,030 strictly inside a real body,
52 not even an instruction boundary. C++: big_O0.stripped 599 -> 449 (25% of the
list was junk), probe_O0.stripped 189 -> 162. Static glibc --mode aggressive
1,358 -> 1,087 with 0 real and 0 named lost. PE and ET_REL are inert.
Whole-binary decompile-all on eight binaries: 0 functions added, 0 surviving
bodies changed and 0 surviving names changed.

#259 (tailcallentry) non-regression, measured on its own corpus and surface with
--option tailcallentry on: all 98 ARM images, entries 57,578 -> 57,578, zero
images changed - bare-metal ARM unwinds through .ARM.exidx and only 3 of 98
carry any .eh_frame FDE. The same argument covers draft PR #239.

Disclosed interaction: eh_frame_full's landing-pad product is now constrained by
this gate, so verify_eh_frame_full's option-on arm flips fdeinterior off to keep
testing what the LSDA decode produces.

Rebased onto 890096b (#264 cppproto, DIV-60) on 1cff8ec (#262 cppcallnames,
DIV-59), and fully re-measured on that tree rather than carried forward, because
neither is inert here. #264 recovers out-of-line C++ member and namespace
definitions from DWARF, so an unstripped C++ binary now carries far more named
function symbols - the input to this option's "range holds no other named
function start" condition. The invariant holds against the new symbol set:
big_O0 now has 447 of its 450 surviving entries named (probe_O0 161 of 163) and
the filter still drops 150 with 0 real and 0 named lost, while the stripped
counterparts are unchanged at 449 / 162 (verified, not assumed - no DWARF there).
Both arms of every comparison are the same build, so #262's renaming and #264's
MAX_TYPE_DEPTH change cancel; coreutils fmt, the binary #264 altered, was
decompiled whole in both arms to keep the two unconflated (198 -> 191 entries, 0
surviving bodies changed; fmt-O2 151 -> 151).

Catalog counters were DERIVED from a fresh post-rebase catalog capture, not
incremented: 91 settables, 20 core / 41 transform / 30 analysis, 90 catalog rows.
#264 and this PR had made an identical off-by-one edit to the same three
assertions, so the merge resolution would have shipped the wrong number had it
been trusted. phase_catalog.json re-captured and docs/options.md regenerated from
the post-rebase build; no stages XML added, so no corpus count or stages baseline
moves.

Bundle: docs/features/fdeinterior/. Gates: make test 675/675 PARITY OK (no
re-pin, no per-test opt-out), make test-stages 394/394 PARITY OK, make rust-test
green, make check-spec OK (strict), kuna catalog --check OK. Speed: timeit
-29.28% (15 samples); interleaved medians -21.68% to +0.06% (functions) and
-4.22% / -4.89% (decompile-all).

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