Skip to content

analyze audit:codegen / audit:trait-tables segfault: LLVM FunctionType interior pointer corrupted before create_dyn_wrapper reads it (batch regression) #726

Closed

Description

@ehartford

Repro (deterministic, seconds)

./out/release/bin/with analyze out/deep-debug-tool-tests/ownership-input.w audit:trait-tables   # rc=139
./out/release/bin/with analyze out/deep-debug-tool-tests/ownership-input.w audit:codegen        # rc=139

(The fixture is written by build.w's deep-debug-tool-tests action; any run of that lane regenerates it.) The seed passes both audits (rc=0) — this is a batch-window regression. All other audits pass except audit:receiver-surface (rc=1, pre-existing on the seed too — separate issue).

Blocks reseed: the deep-debug-tool-tests lane is the current red in the :test aggregate, after D23 known-issue dispositions took the spec lane green.

Evidence chain (lldb, release binary)

  • Crash: EXC_BAD_ACCESS inside LLVMGetReturnType (ldr x8,[x0,#0x10]; ldr x0,[x8] — the deref of ContainedTys faults). Fault address varies per run (heap-layout dependent).
  • 37 create_dyn_wrapper calls; the crash is during Imported record types inside Vec fields can make len() hit an internal compiler error #37: __dynwrap_Resource_drop (the fixture's impl Drop for Resource, move self receiver, consumes_self=1). Neither dyn_impl_row_sig nor ensure_concrete_mir_function fires between Enum variant shorthand in generic arguments fails inside non-void helper functions #36 and Imported record types inside Vec fields can make len() hit an internal compiler error #37, so the wrapper's ft comes from the plain fn_values/fn_fn_types map path (CodegenTraits.w:924-939).
  • At wrapper Imported record types inside Vec fields can make len() hit an internal compiler error #37 entry, the handles are VALID in the same run: method_ft == dyn_ft, LLVMGetTypeKind == 9 (FunctionType), an lldb-expr'd LLVMGetReturnType($x6) succeeds, LLVMCountParamTypes == 1.
  • The fatal call is CodegenTraits.w:360 (lr symbolicates to create_dyn_wrapper + 316), with x0 equal to the entry dyn_ft — same handle, same run. Between fn entry and line 360 (intern resolves, name concat, wl_get_named_function, wl_count_param_types, wl_get_param, Vec pushes), the FunctionType object's interior pointer at [type+0x10] goes from dereferenceable to garbage: something overwrites LLVM-context-owned memory.
  • WITH_DEBUG_ALLOC=1: ledger overflows on a full compiler run ("tracking truncated"), no verdict — the ledger needs a bigger capacity tier before it can arbitrate compiler-scale runs.
  • Guard Malloc (DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib): no invalid-free trap, same crash — weakens the freed-then-reused theory; the overwrite comes from a writer that owns (or thinks it owns) a live allocation overlapping the type object.

Suspects

The write happens during the earliest statements of create_dyn_wrapper #37 (string concat + Vec[i64] pushes) — a With-side buffer whose bounds overlap the LLVM bump-allocated FunctionType. Candidate classes: a Vec buffer grown from a stale handle-copy header (pre-flip two-owner class — same family as the foundation-module double frees fixed in 96f1248), or an interior-pointer write from the intern/str layer. Next session: watchpoint on [dyn_ft+0x10] at wrapper #36/#37 boundary to catch the writer PC directly — that names the exact line.

Context

audit:codegen and audit:trait-tables force vtable/wrapper emission for ALL trait impls including Drop; normal codegen doesn't take this path for the fixture, which is why build/behavior lanes stay green.

Activity

  1. ehartford commented on Jul 26, 2026

    @ehartford
    ContributorAuthor

    Fixed in c750e7e. Root cause: analyze_codegen_backend's pre-flip take-and-alias pool handling — bare field reads became moves under #691, and assign-then-overwrite selection dropped a still-viewed InternPool; freed pages recycled into the LLVM context corrupted FunctionType interiors (hence valid-at-entry handles crashing in LLVMGetReturnType with 32-bit-truncated ContainedTys reads, per-run fault addresses, and Guard Malloc silence — the writer owned a live re-allocation). Fix: if-expression selection (no loser dropped), sema ast taken from inside cg, and take_pool/take_intern partners so the backend returns everything it lent. audit:trait-tables and audit:codegen rc 139->0; audit:all rc=0 on the rebuilt stage1.

  2. added 5 commits that reference this issue on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions