Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on debian aarch64 (raspberry pi) #89

Open
dylanblokhuis opened this issue Feb 11, 2023 · 13 comments
Open

Segfault on debian aarch64 (raspberry pi) #89

dylanblokhuis opened this issue Feb 11, 2023 · 13 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dylanblokhuis
Copy link

dylanblokhuis commented Feb 11, 2023

Installed sqlite3 3.34.1 and ran:

export DENO_SQLITE_PATH="/usr/lib/aarch64-linux-gnu/libsqlite3.so"
deno run -A --unstable app.ts

Result is a segfault when trying to use any sqlite3 functionality

@DjDeveloperr
Copy link
Member

So loading the binary works fine but trying to create Database object and using it results in segmentation fault? I don't have any Aarch64 Linux machine so this one would be hard to debug for me (VM is an option though).

@DjDeveloperr
Copy link
Member

Could you try building sqlite 3.40.1 locally and try using that binary?

@DjDeveloperr
Copy link
Member

I've managed to make SQLite3 ARM64 builds on CI but from my testing on QEMU locally, trying to load and call any SQLite lib function fails via Deno FFI regardless of its built in or custom built. This might be actually a problem with Deno (or its FFI) on ARM64. Anyhow, I'll try including Linux Arm64 binaries in next release, still worth trying out.

@DjDeveloperr
Copy link
Member

DjDeveloperr commented Mar 13, 2023

The custom-built SQLite works perfectly fine in QEMU Aarch64. This must be a problem with Deno FFI on Aarch64 because even a simple sqlite3_initialize call doesn't work via FFI (but at the same time FFI is not completely broken either, I could call libc malloc easily). It's hard for me to debug this right now, I'll investigate this later.

@jerrygreen
Copy link

I guess you can close this issue now, as since with newer version of sqlite3, at least >=3.41.2, segfault doesn't appear

More info in here:

@DjDeveloperr
Copy link
Member

Oh that's great! I think we should update sqlite3 version in the repo now and publish new build for linux arm64. I'll try doing it over the weekend.

@DjDeveloperr
Copy link
Member

Interesting, it is still seg faulting for me on ArchLinux aarch64 VM.

image

@jerrygreen
Copy link

Where did you get your deno and what version it is? I'm using this one:

deno 1.36.0 (release, aarch64-unknown-linux-gnu)
v8 11.6.189.12
typescript 5.1.6

Since it's not officially supported I humbly stole it from this great guy:

https://github.com/LukeChannings/deno-arm64/releases

@DjDeveloperr
Copy link
Member

DjDeveloperr commented Aug 6, 2023

Got Deno for Linux aarch64 from the same place.
SQLite 3.42.0 was built in CI using cross-compilation. Maybe that could be causing some issues. I'll try compiling it on the Linux VM itself.

@xyzshantaram
Copy link

Hi there, would love to help out with this issue. I have a Hetzner CAX21 aarch64 machine so I'm happy to test anything, and I'm decent at research/debugging/writing code. Currently, I can confirm sqlite 3.44.0 from debian unstable is not working (same issue, segfault). This was on Deno 1.38.2.

sid@arm-chan:~/shans-guestbook$ deno run -A --unstable src/main.ts
Segmentation fault
sid@arm-chan:~/shans-guestbook$ sqlite3 --version
3.44.0 2023-11-01 11:23:50 17129ba1ff7f0daf37100ee82d507aef7827cf38de1866e2633096ae6ad8alt1 (64-bit)
sid@arm-chan:~/shans-guestbook$ deno --version
deno 1.38.2 (release, aarch64-unknown-linux-gnu)
v8 12.0.267.1
typescript 5.2.2

@xyzshantaram
Copy link

sid@arm-chan:~/deno-ffi-test$ ls
add.c  add.o  ffi.ts  libadd.so
sid@arm-chan:~/deno-ffi-test$ deno run --allow-ffi --unstable ffi.ts
Result from external addition of 35 and 34: 69

Can also confirm minimal example from https://docs.deno.com/runtime/manual/runtime/ffi_api works. Will be trying sqlite3 next.

@DjDeveloperr
Copy link
Member

@xyzshantaram did that work? You can try calling sqlite3_version function from both system sqlite and the sqlite aarch64 linux binary from GitHub releases in this repo, using Deno FFI.

@xyzshantaram
Copy link

xyzshantaram commented Nov 28, 2023

#include <stdio.h>
#include <sqlite3.h>

void select_version() {
    sqlite3 *db;
    char *err_msg = 0;

    int rc = sqlite3_open(":memory:", &db);

    if (rc != SQLITE_OK) {
        fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        return;
    }

    rc = sqlite3_exec(db, "SELECT SQLITE_VERSION()", 0, 0, &err_msg);

    if (rc != SQLITE_OK) {
        fprintf(stderr, "Failed to execute query: %s\n", sqlite3_errmsg(db));
        sqlite3_free(err_msg);
    } else {
        printf("err_msg: %s\n", err_msg);
        sqlite3_free(err_msg);
    }

    sqlite3_close(db);
}

While running this via FFI, err_msg is null so I'm guessing this worked.
The system sqlite3 called via library segfaults as usual. Haven't tried the binary from releases yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants