Fix SIGSEGV in -dnull extraction/DEF read: guard Tk_RestrictEvents with TxTkConsole#534
Conversation
|
@RTimothyEdwards With the latest Magic I have a crash on |
…th TxTkConsole The Tk_RestrictEvents() calls added to extraction (ExtSubtree.c), CIF/GDS hierarchy generation (CIFhier.c) and DEF read (defRead.c) are guarded by `if (SigInterruptOnSigIO != -1)`, intended to skip them in batch mode. That check is insufficient for `magic -dnull -noconsole`: this mode is not "batch mode" (SigInterruptOnSigIO == 0), so the guard passes, but magicdnull never initializes the Tk package. Calling into Tk with a NULL stubs table segfaults. It is reliably fatal on aarch64 (Pointer Authentication faults the bad indirect call) while x86_64 often survives it. This breaks headless extraction/LVS flows (e.g. SAK / LibreLane / open_pdks regression). Guard these call sites with TxTkConsole (RuntimeFlags & MAIN_TK_CONSOLE) instead, which is true only when a Tk console is actually present, and add the missing `#include "utils/main.h"` where needed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
e4d01b7 to
3a1d63b
Compare
RTimothyEdwards
left a comment
There was a problem hiding this comment.
Yes, this looks good to me (good catch, Claude!)
|
On second thought, that's not quite right. Running |
|
@RTimothyEdwards I tested the fix and can confirm it works. Maybe the issue is only with |
|
Okay, I realize now that Claude is just dead wrong. The problem is that on aarch64, Claude's "fix" works because it is a valid substitute when in The underlying error is my long-term misunderstanding that |
|
@RTimothyEdwards So still expert knowledge is required, which is a good thing. :-) I happily take your fix, as long as the segfault is gone.. |
@RTimothyEdwards And so we know which systems you have programmed in the past :-)
|
|
So modern! Think further back: HP/UX, DEC Ultrix, IRIX, A/UX, Sun OS. . . |
Problem
Running magic headless (
magic -dnull -noconsole) segfaults duringextract/ DEF read. Minimal repro (sky130A, any cell with subcells):It is reliably fatal on aarch64 (the bad indirect call trips Pointer Authentication); on x86_64 it often survives, so it can go unnoticed. This breaks headless extraction/LVS in SAK / LibreLane / open_pdks-style flows.
Cause
Commit d8046fb added
Tk_RestrictEvents()toextract/ExtSubtree.c,cif/CIFhier.candlef/defRead.c, guarded by:SigInterruptOnSigIOis only-1for truebatchmode(SigInit(TRUE)). The-dnull -noconsoleinterpreter (magicdnull) is not batch mode (SigInterruptOnSigIO == 0), so the guard passes — butmagicdnullnever initializes the Tk package, so the Tk stubs table is NULL and the call dereferences it.Fix
Guard the six call sites with
TxTkConsole(RuntimeFlags & MAIN_TK_CONSOLE, fromutils/main.h) — true only when a Tk console is actually present — and add the missing#include "utils/main.h"to the two files that lacked it.Verified on aarch64 (Ubuntu 24.04, magic 8.3.670):
extract all+ext2spiceon a sky130A inverter now completes cleanly and LVS passes; previously it segfaulted.