diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-06 22:00:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | b2cdd8ee719961b2f037f20bf0f88fad94ca73b4 (patch) | |
| tree | c206553a2600467532ec259400c0d57efb3e80b5 /build.zig | |
| parent | a373fdda0102a99cde988f87f822fc451e0f4391 (diff) | |
| download | pardes-b2cdd8ee719961b2f037f20bf0f88fad94ca73b4.tar.gz pardes-b2cdd8ee719961b2f037f20bf0f88fad94ca73b4.zip | |
fix: every external-scanner grammar crashed pardes on parse (rust/cpp/python/...; e.g. opening agave cpi.rs or any tracy .cpp), Debug AND ReleaseSafe. Root cause: clang -fsanitize=function (in zig's default C UBSan set) traps at the runtime's indirect call of the scanner because grammars declare external_scanner_create() with EMPTY PARENS — a K&R non-prototype whose type hash differs from the void*(*)(void) pointer type. The ud1 trap lands on a bogus inlined line (stack.c:746), which cost the diagnosis a detour through rr (its gdbserver dies replaying past the task exit — core dump + coredumpctl worked; ud1 0x6(%eax) = SanitizerHandler kind 6 = function_type_mismatch; scanner-less c/zig grammars never crashed). Fix per review direction: -fno-sanitize=function on the grammar TUs in build.zig — uninstrumented callees make the runtime's call-site checks skip; the rest of UBSan stays live. Second half: fatal signals (SIGILL/SEGV/BUS/FPE) never run defers and bypassed the panic hook, leaving the terminal raw after a crash — root.debug.handleSegfault override now runs vaxis.recover() before std.debug.defaultHandleSegfault, verified in a raw pty (kill -ILL $PPID: rmcup + mouse resets precede the trace). Verified: rust/cpp/python opens work with real highlighting (snapstyle: keywords/strings/comments colored), agave cpi.js 2.7k-line open fine, suite 30/30, ReleaseSafe build opens rust identically.
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -163,8 +163,17 @@ pub fn build(b: *std.Build) void { .linkage = .static, }); if (libc_file) |f| lib.setLibCFile(f); - lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/parser.c") }); - if (g.scanner) lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/scanner.c") }); + // grammars declare external_scanner_create() with EMPTY PARENS + // (a K&R non-prototype, not (void)): under clang's + // -fsanitize=function the callee's type hash differs from the + // runtime's void*(*)(void) call through the pointer, so the + // first scanner call of ANY parse traps (function_type_mismatch, + // an ud1 blamed on a random inlined line). Uninstrumented + // callees make the runtime's call-site checks skip; the rest + // of UBSan stays live for the grammar code. + const ts_cflags = [_][]const u8{"-fno-sanitize=function"}; + lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/parser.c"), .flags = &ts_cflags }); + if (g.scanner) lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/scanner.c"), .flags = &ts_cflags }); lib.root_module.addIncludePath(dep.path(g.src)); root_mod.linkLibrary(lib); if (is_emscripten) wasm_libs.append(b.allocator, lib.getEmittedBin()) catch @panic("OOM"); |
