nx_segv_log_001.nx source
↩ module page · 42 lines · 2794 B
1// nx_segv_log_001.nx -- NishiLang-native log entry for the
2// 2026-05-13 nxc2 codegen SEGV (root-cause + fix + verification).
3//
4// Per user directive: "log and plan to address the segvs via using our
5// write read etc." Pure-NishiLang log writer using sys_write to
6// specs/segv_log.jsonl. Substrate documents its own incidents.
7//
8// Genealogy: incident_log_lineage + observability_as_native_primitive.
9//
10// Schema (one JSON line):
11// { "id": "...", "kind": "compiler_segv", "discovered_at": "...",
12// "symptom": "...", "trigger": "...", "root_cause": "...",
13// "evidence": "...", "fix": "...", "verification": "...",
14// "files_touched": [...], "regression_test": "...", "lesson": "..." }
15
16// nx_safety_envelope:
17// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
18// sil_target: SIL1
19// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
20// verdict: NOT_YET_EVALUATED
21
22import "nx_syscalls.nx"
23import "nx_runtime.nx"
24
25const STDOUT: i64 = 1
26
27func main() -> i64 {
28 let path: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/specs/segv_log.jsonl" as *u8
29 // O_CREAT | O_WRONLY | O_APPEND = 0x441; mode 0644 = 0x1A4
30 let fd: i64 = __syscall(SYS_OPENAT, AT_FDCWD, path as i64, 0x441, 0x1A4, 0, 0)
31 if fd < 0 { return 1 }
32
33 let line: *u8 = "{\"id\":\"segv-001-2026-05-13\",\"kind\":\"compiler_segv\",\"discovered_at\":\"2026-05-13T14:33\",\"symptom\":\"nxc2 --target asm exits 139 on any input including bare func main\",\"trigger\":\"any compile path that calls riscv.c:emit_function (Function->name)\",\"root_cause\":\"gcc -std=c11 hides POSIX strdup behind feature-test macro; implicit-decl truncates the returned char* to 32 bits on x86_64; Function->name receives a truncated/null pointer and downstream vfprintf SEGVs on emit(out,\\\" .globl %s\\\",f->name)\",\"evidence\":\"ASAN trace 2026-05-13: SEGV in __sanitizer::internal_strlen via vfprintf via riscv.c:35 emit via riscv.c:684 emit_function via main.c:387; gcc warning parse.c:469 implicit declaration of strdup\",\"fix\":\"Makefile CFLAGS += -D_GNU_SOURCE so <string.h> exposes strdup with its real char* signature\",\"verification\":\"nx_diagram_smoke.sh PASS end-to-end after fix: compile -> RV64 asm -> link -> qemu run exit 0; all 4 emitters operational\",\"files_touched\":[\"nxc2/Makefile\"],\"regression_test\":\"nx_diagram_smoke.sh\",\"lesson\":\"Implicit-declaration warnings on POSIX functions are silent ABI bugs on 64-bit systems; promote to -Werror=implicit-function-declaration in future\"}\n" as *u8
34
35 let n: i64 = strlen(line)
36 sys_write(fd, line, n)
37 sys_close(fd)
38
39 let msg: *u8 = "segv_log.jsonl updated with incident segv-001-2026-05-13\n" as *u8
40 sys_write(STDOUT, msg, strlen(msg))
41 return 0
42}