You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
migrate: SIGSEGV in with_cimport_macro_name on zlib deflate.c — MacroSession names[idx] holds a garbage pointer (0x2b) #882
$ with build :zlib-reference # fetches zlib-1.3.2 into out/
$ with migrate out/tmp/action-scratch/zlib-migrate/source/deflate.c --no-c-export -o deflate.w
$ echo $?
139
No diagnostic, no output file — the migrator dies silently with SIGSEGV.
Reproduces identically with the installed seed (v0.15.1.6-g4a83a556) and a
stage1 built from HEAD. with build :zlib-migrate therefore cannot re-migrate
zlib today; the committed lib/std/zlib/ was produced by an older migrator.
(Before the fix in #880's branch for the migrate-mode flag, zlib-migrate died
earlier on adler32.c with a loud "untranslatable function" error from the
c_import-only #799 callee filter — that one was the flag being unset on the
directory path and is fixed there. This crash is what's underneath.)
bt unwinds only one frame (fp chain clobbered) and fp - sp ≈ 120 KB, so
the faulting callee sits under a very large frame.
Suspects
MacroSession (ClangBridge.w:415) is hand-rolled: parallel with_alloc'd
arrays (names/values/locations/fn_like/system_flags/params/param_counts)
grown by macro_session_grow (:2170-2200, copies oc * 8 / oc * 4 then
frees the old arrays) and appended by macro_session_add_from_define_line
(:2282-2290) from the @[callconv("c")]collect_macro_def visitor. A names[idx] slot holding a small integer means one of: the session pointer
is stale (session freed/reused — a UAF), count ran past what grow
actually copied, or an append wrote through a pointer the grow had already
freed.
How to run it down
--debug-alloc first (CLAUDE.md memory-bug workflow), then a watchpoint on names[idx] for the idx that faults:
lldb -- ./out/release/bin/with migrate .../deflate.c --no-c-export -o /tmp/d.w
(lldb) b ClangBridge.w:2574
(lldb) run
(lldb) p idx ; p (*ms).count ; p (*ms).cap
deflate.c is the first zlib unit with a large macro surface (#defines with
parameters, local inline helpers); adler32/compress/crc32 migrate fine.
Why it matters
A silent rc=139 from with migrate is a no-silent-fallbacks violation on its
own, and it blocks re-migrating zlib for #880.
Fixed — two bugs, and zlib fully re-migrates (33a14ef, a3cd6a19, 1cf9807e)
1. The SIGSEGV (the issue as filed)
Root-caused with lldb exactly as the debugging notes suggested. The fault was make_str(names[idx]) walking a session that was not a MacroSession — its count field read as garbage (0x06d70010), so the idx < count guard passed.
Migrate mode has two libclang sessions: the translation-unit session threaded
through the cursor walk, and the separate macro session
(g_migrate_macro_session). ci_lookup_macro_value (CImport.w:12622) already
ignored its session param and used g_migrate_macro_session; ci_macro_is_fn_like_name trusted the passed session and so read the TU session
as a MacroSession. Fixed to resolve the macro session the same way its sibling
does. deflate.c was the first zlib unit whose initializers reference object-like
macros.
2. The loud failure underneath it
With the segfault gone, zlib-migrate reached gzwrite.c and failed loudly:
"unsupported assignment rhs in goto CFG (kind=117)" at writ = (int)write(state->fd, ...).
write is a With prelude-collision name, so the migrator renames it to write_.
The goto-CFG call lowerer passed that renamed spelling to the system-symbol
allowlist, which keys on the original C name — so write_ looked like an
unhandled filtered system symbol and bailed. A hand-declared write migrated
fine; only the <unistd.h> system write triggered it. The normal DECL_REF
path (CImport.w:8618) filters on the original name; the goto path now does too.
Result
All 15/15 zlib units migrate (was 4/15). :zlib-test passes ("migrated zlib
example and minigzip tests pass"), and lib/std/zlib is re-promoted from the
current migrator. tools/rt_decl_audit.w dropped 13 -> 7 (the zlib rows
cleared).
Closing once the battery + reseed lands. The remaining #880 work (pcre2) is
blocked on #883, not this.
Correction: the SIGSEGV is fixed; the goto/emission part is #884
Landed and pushed 33a14ef — the macro-session fix. deflate.c (and every
zlib unit through the segfault) now migrates; the crash is gone. Battery green,
reseeded.
I initially bundled a second fix (goto-CFG call filter + zlib re-migration) and
had to revert it: making the goto path allow the write call was
necessary but not sufficient — the emitted callee write_ has no binding and use std.libc wasn't injected, so the regenerated zlib didn't compile
(behav_zlib_std.w caught it). That turned a loud bail into silently-broken
output, so it's out.
The remaining work — the migrator can't migrate calls to prelude-collision
libc functions (write/read/print/...) in either the normal or goto
path, because the system-symbol filter is handed the renamed write_ — is
tracked precisely in #884. That is the real remaining blocker for #880's
zlib half (pcre2 is independently blocked by #883).
Activity
migrate: one source for the alloc/mem pointer spellings; migrate mode…
ehartford commentedon Aug 21, 2026
Fixed — two bugs, and zlib fully re-migrates (33a14ef, a3cd6a19, 1cf9807e)
1. The SIGSEGV (the issue as filed)
Root-caused with lldb exactly as the debugging notes suggested. The fault was
make_str(names[idx])walking a session that was not a MacroSession — itscountfield read as garbage (0x06d70010), so theidx < countguard passed.Migrate mode has two libclang sessions: the translation-unit session threaded
through the cursor walk, and the separate macro session
(
g_migrate_macro_session).ci_lookup_macro_value(CImport.w:12622) alreadyignored its
sessionparam and usedg_migrate_macro_session;ci_macro_is_fn_like_nametrusted the passed session and so read the TU sessionas a MacroSession. Fixed to resolve the macro session the same way its sibling
does. deflate.c was the first zlib unit whose initializers reference object-like
macros.
2. The loud failure underneath it
With the segfault gone, zlib-migrate reached gzwrite.c and failed loudly:
"unsupported assignment rhs in goto CFG (kind=117)" at
writ = (int)write(state->fd, ...).writeis a With prelude-collision name, so the migrator renames it towrite_.The goto-CFG call lowerer passed that renamed spelling to the system-symbol
allowlist, which keys on the original C name — so
write_looked like anunhandled filtered system symbol and bailed. A hand-declared
writemigratedfine; only the
<unistd.h>systemwritetriggered it. The normal DECL_REFpath (CImport.w:8618) filters on the original name; the goto path now does too.
Result
All 15/15 zlib units migrate (was 4/15).
:zlib-testpasses ("migrated zlibexample and minigzip tests pass"), and
lib/std/zlibis re-promoted from thecurrent migrator.
tools/rt_decl_audit.wdropped 13 -> 7 (the zlib rowscleared).
Closing once the battery + reseed lands. The remaining #880 work (pcre2) is
blocked on #883, not this.
migrate: macro-name lookup uses the macro session, not the TU session (…
ehartford commentedon Aug 21, 2026
Correction: the SIGSEGV is fixed; the goto/emission part is #884
Landed and pushed 33a14ef — the macro-session fix. deflate.c (and every
zlib unit through the segfault) now migrates; the crash is gone. Battery green,
reseeded.
I initially bundled a second fix (goto-CFG call filter + zlib re-migration) and
had to revert it: making the goto path allow the
writecall wasnecessary but not sufficient — the emitted callee
write_has no binding anduse std.libcwasn't injected, so the regenerated zlib didn't compile(
behav_zlib_std.wcaught it). That turned a loud bail into silently-brokenoutput, so it's out.
The remaining work — the migrator can't migrate calls to prelude-collision
libc functions (
write/read/print/...) in either the normal or gotopath, because the system-symbol filter is handed the renamed
write_— istracked precisely in #884. That is the real remaining blocker for #880's
zlib half (pcre2 is independently blocked by #883).
This issue (the SIGSEGV) is resolved by 33a14ef.