Repository navigation
[AUTOMATED] fix(analysis): mark the libstdc++ std::__throw_* family no-return (DIV-78) - #311
Merged
Merged
Conversation
…V-78) [AUTOMATED] Every helper in libstdc++'s <bits/functexcept.h> (plus __throw_regex_error from <bits/regex_error.h>) is declared __attribute__((__noreturn__)) and every body ends in _GLIBCXX_THROW_OR_ABORT -- a throw, or abort() under -fno-exceptions -- so none of the 20 can return. Upstream Ghidra's ElfFunctionsThatDoNotReturn names __cxa_throw and the terminate entry points but omits the whole family, and the source attribute survives into no binary artifact: at the decompiler's boundary std::__throw_length_error is an ordinary UND .dynsym import behind a PLT stub, so nothing but the shipped list can prove the call cannot return. Flow followed the fall-through and emitted whatever sat after the call -- clang's `call __stack_chk_fail` unreachable-trap, the next function's entry, or the exception-cleanup landing pad. The gap was masked until #272, when a failed decode of clang's 15-byte alignment NOP stopped forging noreturn_disc evidence. The 20 helpers are appended to the vendored list in place, fenced by a `# (kuna divergence, DIV-78)` block, exactly as DIV-21's libc additions are: tools/sync_upstream.py's vendored scope is tests/datatests/ plus Ghidra/Processors/*/data/languages/, so Ghidra/Features/Base/data/ is never synced and an in-place block cannot conflict. Each helper is listed twice -- the mangled .dynsym spelling the analysis-tier scan matches pre-demangle (a trailing-* wildcard over the Itanium ZSt<len>__throw_<name> prefix, so a signature change cannot age it out) and the demangled base name the flow-time matcher sees. No new option: noreturn_known and noreturn_externmatch are both default-on and both read this file. Witnesses: FileCheck-14 (clang, 1,155 fns) 72 change, 0 grow, no-return annotations 69 -> 102, lines 63,247 -> 63,141; apt-get (gcc, 124 fns) 6 change, 11 -> 17; clang-format-14 (242 fns) 13 change, 12 -> 16. Zero collateral on C binaries (grep 0/449, sort 0/490, faillog 0/69, libselinux.so.1 0/502). Speed min-of-11 68.64 s -> 66.01 s (-3.83%). Fixes #273 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #273
What was wrong
Every helper in libstdc++'s
<bits/functexcept.h>—std::__throw_length_error,__throw_out_of_range,__throw_bad_alloc,__throw_logic_error,__throw_bad_cast,__throw_invalid_argument, … (20 in total, plus__throw_regex_errorfrom<bits/regex_error.h>) — is declared__attribute__((__noreturn__)), and every bodyends in
_GLIBCXX_THROW_OR_ABORT: athrow, orabort()when the library is built-fno-exceptions. None of them can return.Upstream Ghidra's
ElfFunctionsThatDoNotReturnnames__cxa_throwand the terminateentry points but omits the whole family, and the source-level attribute survives into
no binary artifact: at the decompiler's boundary
std::__throw_length_erroris anordinary UND
.dynsymimport reached through a PLT stub. Nothing but the shipped listcan prove the call cannot return. So flow followed the fall-through and emitted whatever
the compiler had parked after the call — clang's
call __stack_chk_failunreachable-trap, the next function's entry, or (apt-get
sub_6480) theexception-cleanup landing pad, rendered as
__cxa_begin_catch(std::__throw_logic_error(...)); … _Unwind_Resume().The gap was masked until #272:
noreturn_disc's evidence tally counts a call site whosefall-through "is not a valid instruction start", and a failed decode satisfied that
test, so clang's 15-byte alignment NOP was silently voting
std::__throw_length_errorno-return. With the padding decoding, the tally drops below its 3-site floor and the dead
code reappeared. That accidental crutch is what this PR replaces with the real fact.
Vendored-in-place vs. a supplementary list — and why in-place won
The 20 helpers are appended to the vendored file in place, fenced by a
# (kuna divergence, DIV-78)comment block. The reasoning, having checked rather thanassumed:
tools/sync_upstream.py's vendored scope isexactly
Ghidra/Features/Decompiler/src/decompile/datatests/→tests/datatests/andGhidra/Processors/*/data/languages/.Ghidra/Features/Base/data/is not inPATH_MAP, not inUPSTREAM_PREFIXES, and there is no verbatim-hash guard anywhere inthe tree. This file is vendored by hand, once, and a future sync will never touch it.
DIV-21 added the BSD
err/errxfamily and the glibc fatal internals the same way,with the same style of comment header. A second, differently-shaped divergence
mechanism alongside it would be less self-documenting, not more.
place for the two matchers to drift apart. Both
include_str!consumers(
kuna-analysis::loader::noreturnfornoreturn_known, andkuna-decomp::p2_lift::kuna_noreturn_externmatchfornoreturn_externmatch) pick thein-place block up with zero code change.
The file's "vendored verbatim" header is preserved as provenance for the upstream half;
both divergence blocks sit below it, each labelled with its DIV number.
Shape of the entries
Each helper is listed twice, because the two matchers see two spellings of the same
symbol:
.dynsymname, which the analysis-tier scan matches beforedemangling — written as a trailing-
*wildcard over the ItaniumZSt<len>__throw_<name>prefix, so a signature change cannot age the entry out (
__throw_ios_failuregained aconst char*, intoverload in GCC 7;__throw_regex_errorgained one in GCC 11). Theprefix is an exact ABI encoding of
std::__throw_<name>, so the wildcard cannot reachany other symbol.
std-onlynamespace guard admits
std::__throw_length_errorand the leading-underscore stripreduces it to
throw_length_error.A same-named method on a user class (
Buf::__throw_length_error) stays out via theexisting namespace guard; both are pinned by tests.
No new option
The behavior is already gated twice over by existing default-ON options, so a third flag
would only add catalog surface for no control:
noreturn_known(analysis tier) reads the file,noreturn_externmatch(flow seam, DIV-13)include_str!s the same file.--option noreturn_known off --option noreturn_externmatch offreproduces the pre-fixrendering byte-identically, and that is exactly the two-pass the new e2e test drives. No
catalog counts move (
kuna catalog --jsonon the rebased tree reports 109, the value#309 left, and
git difftouches none ofphases.toml/options.rs/catalog_bytecompat.rs/phase_catalog.json/docs/options.md/kuna-catalog.xml),no
phases.tomlrow, nodocs/options.mdregen.xml.rs's corpus count is likewiseuntouched at 207 (no stages XML added).
One finding worth recording: contrary to the issue text,
noreturn_extern(DIV-14) doesnot read this file — it carries a frozen hard-coded copy of upstream's 21 names, and
has already drifted (it is missing DIV-21's additions too). It is queried only after
noreturn_externmatchhas declined, so for any name in the file it is subsumed and thefix reaches the undefined-extern path regardless. That pre-existing duplication is left
alone here rather than bundled in.
Witnesses (base =
origin/mainrelease build, fixed = this branch)Witness 1 —
/usr/bin/FileCheck-14(clang-14, 528 KB, 1,155 functions; the GH-273binary), whole-binary
decompile-all --json:// no-returnannotationsAll 72 changed functions contain a
std::__throw_*call in the base output — there is nocollateral change anywhere else in the binary. Normalising away the variable renumbering
cascade, no changed function gains a net line.
The issue's smallest case,
sub_44eb10:(The dead tail itself was already being cut here by
funcboundflow/DIV-67, which landedafter the issue was filed — it papers over the symptom whenever the fall-through happens
to land on a function entry, with a warning comment. This PR supplies the actual fact, and
covers the far more common case where the fall-through lands on an unreachable trap or
mid-function code.)
Witness 2 —
/usr/bin/apt-get(gcc, PIE, 124 functions; a different compiler and adifferent set of family members:
__throw_logic_error,__throw_bad_cast,__throw_out_of_range_fmt,__throw_length_error): 6 changed, all shrink,annotations 11 → 17, lines 2,493 → 2,469. Two of the removals are outright nonsense
disappearing:
Witness 3 —
/usr/bin/clang-format-14(242 functions): 13 changed, all shrink,annotations 12 → 16, lines 6,867 → 6,834.
Collateral
Whole-binary base-vs-branch
decompile-all --json, every changed function reviewed:tests/bug-repro/grep(C)tests/bug-repro/sort(C)tests/bug-repro/faillog(C)tests/bug-repro/libselinux.so.1(C)/usr/bin/FileCheck-14(C++)/usr/bin/apt-get(C++)/usr/bin/clang-format-14(C++)The C binaries are byte-identical, as they must be — no C ELF imports a
std::__throw_*.Three removals spot-checked against
objdump:0x40e5ab: call _ZSt20__throw_length_errorPKc@pltimmediately followed by0x40e5b0: call __stack_chk_fail@plt— clang's unreachable trap, dead by construction.0x44eb35: call _ZSt20__throw_length_errorPKc@plt, then the 15-byte alignmentNOP, then
0x44eb40which is the next function's entry.0x43a7e3: call _ZSt20__throw_system_errori@plt— here the successor0x43a7e8is an independent branch target (0x43a735: jne 43a7e8), and the fixedoutput correctly still emits it. Only the fall-through edge is cut, never reachable code.
Speed
Interleaved min-of-11
kuna decompile-all /usr/bin/FileCheck-14 --json, alternatingbase/branch on the same box (siblings were building concurrently, so the run-to-run spread
is wide and the min is the signal):
A small win, and in the expected direction: 106 fewer emitted lines over 72 functions with
shorter CFGs is less work, not more. The cost side is 40 extra lines parsed out of the list
once per load.
Tests
decompiler/crates/kuna-console/tests/verify_cxx_throw_noreturn.rs— two-pass e2e overa new clang++-built fixture
decompiler/crates/kuna-analysis/tests/fixtures/cxxthrow_noreturn_x86_64(+.cppsource committed alongside): default = the throw terminates the function, both list
consumers off = the dead
* 7/* 11tail returns. Two family members(
__throw_length_error,__throw_out_of_range) so the fix is not proven on one symbol.A
tests/stages/*.xmlcase is not possible here: the no-return list is consumed by theanalysis tier, which the XML
<binaryimage>path does not run — this follows theverify_noreturn_disc.rsprecedent instead, andxml.rs's corpus count stays at 207.kuna-analysisloader::noreturn:div78_cxx_throw_family_present_both_spellings(13 mangled + 13 demangled spellings, the namespace guard, and the "must NOT match"
set),
cxx_throw_family_emits_plt_stub_address(the fixture's real PLT-stub addresses),and
list_parses_to_exact_names_and_cxx_throw_wildcards(the ELF list's only wildcardsare the DIV-78 mangled prefixes).
kuna-decompkuna_noreturn_externmatch:matches_cxx_throw_family_demangled_and_mangled.Gates (all four, local, on this branch)
make test→datatests: 675/675 assertions passed/ PARITY OK (no re-pin — nodatatest imports a libstdc++ throw helper)
make test-stages→datatests: 481/481 assertions passed/ PARITY OKmake rust-test→ green, 4,599 passed / 0 failedmake check-spec→check-spec OK (lenient mode)kuna catalog --check→ OKDocs
docs/history.md— DIV-78 row (see the DIV-number caveat below).docs/spec/01-program-prep.md§1.7 — the divergence in prose, plus a correction: thechapter said
noreturn_externdiffers fromnoreturn_externmatch"only in gate flagand name-resolution path", which is not true — it also has a different, frozen name set.
docs/missing-ghidra-analyses.md— the no-return row now names both divergence blocks.DIV number: claimed DIV-78 (tail on this branch was DIV-77). If another PR claims
it first, the row and its three in-tree references (the data file comment, the spec prose,
missing-ghidra-analyses.md) need renumbering together.Follow-up filed separately
#312 — the issue's secondary point, that
noreturn_disctreating anundecodable fall-through as no-return evidence is fragile (a decode bug can forge the
same signal, which is exactly what happened here), deliberately not bundled.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq