From da86b9a16073fbd973618e48dacde0973cb0cb08 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Jun 2026 23:10:56 +0000 Subject: [PATCH] fix(kyber-linux): fix ___chkstk_ms link error in cmd shim Large stack array WCHAR[4096] triggered a stack probe (__chkstk_ms) unavailable in -nostdlib builds. Fix: heap-allocate the pass-through command line buffer, and add -mno-stack-arg-probe as a safety net. Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01D8ckUJQtj1pH8jtAddBDZs --- scripts/setup-kyber-linux.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/setup-kyber-linux.sh b/scripts/setup-kyber-linux.sh index 10b3ccf..d172a17 100755 --- a/scripts/setup-kyber-linux.sh +++ b/scripts/setup-kyber-linux.sh @@ -310,11 +310,14 @@ int WINAPI mainCRTStartup(void) { } } /* pass-through to original cmd */ - WCHAR newcl[4096] = L"cmd-real.exe"; LPWSTR rest = GetCommandLineW(); while (*rest && *rest != L' ') rest++; - if ((lstrlenW(newcl) + lstrlenW(rest)) < 4090) - lstrcatW(newcl, rest); + LPCWSTR prefix = L"cmd-real.exe"; + int plen = lstrlenW(prefix), rlen = lstrlenW(rest); + LPWSTR newcl = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + (plen + rlen + 2) * sizeof(WCHAR)); + lstrcpyW(newcl, prefix); + lstrcatW(newcl, rest); STARTUPINFOW si = {sizeof(si)}; PROCESS_INFORMATION pi; CreateProcessW(NULL, newcl, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); @@ -326,6 +329,7 @@ int WINAPI mainCRTStartup(void) { } CEOF x86_64-w64-mingw32-gcc -O2 -ffreestanding -nostdlib \ + -mno-stack-arg-probe \ -e mainCRTStartup -o "$SHIM_EXE" "$SHIM_C" \ -lkernel32 -lshell32 \ && cp "$CMD_SHIM" "$CMD_REAL" \