Skip to content

Commit 426e7f1

Browse files
author
Daniele Briggi
committed
chore(makefile): investigate segmentation fault
1 parent 7062f9a commit 426e7f1

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

.github/workflows/main.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,37 @@ jobs:
152152
if: matrix.name == 'macos'
153153
run: |
154154
echo "Checking if whisper CoreML symbols are present..."
155-
nm -D dist/ai.dylib | grep -i coreml || echo "CoreML symbols not found in binary"
155+
echo "=== Dynamic symbols in ai.dylib ==="
156+
nm -D dist/ai.dylib | grep -i coreml || echo "CoreML symbols not found in dynamic symbol table"
157+
echo "=== All symbols in ai.dylib ==="
158+
nm dist/ai.dylib | grep -i coreml || echo "CoreML symbols not found in symbol table"
159+
echo "=== Linked frameworks ==="
156160
otool -L dist/ai.dylib | grep CoreML || echo "CoreML framework not linked"
157-
nm build/whisper.cpp/src/libwhisper.a | grep coreml
158-
nm build/whisper.cpp/src/libwhisper.coreml.a | grep coreml
161+
echo "=== CoreML symbols in whisper libraries ==="
162+
nm build/whisper.cpp/src/libwhisper.a | grep coreml || echo "No CoreML symbols in libwhisper.a"
163+
nm build/whisper.cpp/src/libwhisper.coreml.a | grep coreml || echo "No CoreML symbols in libwhisper.coreml.a"
164+
165+
- name: test sqlite-ai with crash debugging (macOS)
166+
if: matrix.name == 'macos'
167+
run: |
168+
echo "=== Testing with crash debugging ==="
169+
# Enable core dumps
170+
ulimit -c unlimited
171+
# Run with detailed crash info
172+
echo "Running test with lldb to capture crash info..."
173+
echo "run" | lldb -- sqlite3 ":memory:" -cmd ".bail on" ".load ./dist/ai" "SELECT ai_version();" || {
174+
echo "Test failed, checking for core dump..."
175+
if [ -f core.* ]; then
176+
echo "Core dump found, analyzing..."
177+
echo "bt" | lldb -c core.* sqlite3
178+
fi
179+
# Also try with crash reporter
180+
echo "Checking system crash logs..."
181+
log show --predicate 'eventMessage contains "sqlite3"' --info --last 1m || true
182+
}
183+
# Also try running the test directly to see if it works
184+
echo "=== Direct test run ==="
185+
sqlite3 ":memory:" -cmd ".bail on" ".load ./dist/ai" "SELECT ai_version();" || echo "Direct test also failed"
159186
160187
- name: test sqlite-ai
161188
if: matrix.name == 'linux' || matrix.name == 'macos'

src/sqlite-ai.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#include <string.h>
26+
#include <signal.h>
27+
#include <setjmp.h>
28+
2629

2730
#ifndef SQLITE_CORE
2831
SQLITE_EXTENSION_INIT1
@@ -1947,7 +1950,37 @@ SQLITE_AI_API int sqlite3_ai_init (sqlite3 *db, char **pzErrMsg, const sqlite3_a
19471950
// initialize the llama + ggml backend
19481951
static bool once = false;
19491952
if (once == false) {
1953+
// On macOS, llama_backend_init() can cause issues with CoreML initialization
1954+
// Add safety check to prevent crashes using signal handling
1955+
#ifdef __APPLE__
1956+
static jmp_buf crash_jmp;
1957+
static volatile sig_atomic_t crash_occurred = 0;
1958+
1959+
void crash_handler(int sig) {
1960+
crash_occurred = 1;
1961+
longjmp(crash_jmp, 1);
1962+
}
1963+
1964+
struct sigaction old_action;
1965+
struct sigaction new_action;
1966+
new_action.sa_handler = crash_handler;
1967+
sigemptyset(&new_action.sa_mask);
1968+
new_action.sa_flags = 0;
1969+
1970+
sigaction(SIGSEGV, &new_action, &old_action);
1971+
1972+
if (setjmp(crash_jmp) == 0) {
1973+
llama_backend_init();
1974+
} else {
1975+
sigaction(SIGSEGV, &old_action, NULL);
1976+
if (pzErrMsg) *pzErrMsg = sqlite3_mprintf("Failed to initialize LLAMA backend: segmentation fault occurred");
1977+
return SQLITE_ERROR;
1978+
}
1979+
1980+
sigaction(SIGSEGV, &old_action, NULL);
1981+
#else
19501982
llama_backend_init();
1983+
#endif
19511984
once = true;
19521985
}
19531986

0 commit comments

Comments
 (0)