Skip to content

Internal ECL error when booting ECL from C compiled to WASM

I'm using ECL 23.9.9.

I'm trying to build a very minimal example of calling Lisp code from a C program that's compiled to WASM. I have followed the Emscripten build instructions by first building the ECL that targets Emscripten with the proper flags, and then compiling ECL via emcc to WASM which resulted in a ecl.js, ecl.wasm, and ecl.html. The ecl.html works fine when I open it in the browser, which opens an ECL REPL. This is not what I need however.

I have the following C, without a Lisp file:

#include <ecl/ecl.h>

int main(int argc, char** argv){
  printf("Hello, World!\n");
  printf("argc: %d\n", argc);
  for (int i = 0; i < argc; ++i){
    printf("argv[%d]: %s\n", i, argv[i]);
  }
  printf("Initializing ECL...\n");
  cl_boot(argc, argv); /* Crashes in browser */
  printf("ECL initialized\n");
  printf("Shutting down ECL...\n");
  cl_shutdown();
  printf("ECL shutdown\n");
  return 0;
}

Using the ECL Emscripten host's static libraries, I try to compile the above via:

[daedsidog@DESKTOP-DABGRDU build]$ ls
asdf.fasc    compile.lsp     ecl-cdb.fasc   gc            libeclgmp.a         modules             test
a.wasm       compile.pre     ecl-help.asd   gmp           libecl-help.a       package-locks.asd   test2
bare.lsp     config.log      ecl-help.fasc  help.doc      libeclmin.a         package-locks.fasc  tests
bin          config.status   ecl_min.html   libasdf.a     libgc.la            pkgconfig           tmp
build-stamp  CROSS-COMPILER  encodings      libcord.a     libgmp.la           prebuilt-asdf.asd
c            CROSS-DPP       ext            libcord.la    liblsp.a            share
cinit.o      doc             foo8w83PW      libecl.a      libpackage-locks.a  simple-html
clos         ecl             foo8w83PW.c    libecl-cdb.a  lsp                 stdin.info
cmp          ecl-cdb.asd     foo8w83PW.i    libeclgc.a    Makefile            TAGS
[daedsidog@DESKTOP-DABGRDU build]$ cd test
[daedsidog@DESKTOP-DABGRDU test]$ alias
alias embuild='emcc -I../. main.c ${ECLSTATICS} -o test.html'
alias ls='ls --color=auto'
[daedsidog@DESKTOP-DABGRDU test]$ echo ${ECLSTATICS}
../libecl.a ../libeclgmp.a ../libeclgc.a
[daedsidog@DESKTOP-DABGRDU test]$ embuild

It compiles fine without errors, but doesn't work. When I run it from the browser or NodeJS (same error) I get:

[daedsidog@DESKTOP-DABGRDU test2]$ node test.js
Hello, World!
argc: 1
argv[0]: /home/daedsidog/test/ecl/build/test2/test.js
Initializing ECL...
warning: unsupported syscall: __syscall_prlimit64


Internal or unrecoverable error in:
Can't set the size of the C stack: sanity check failed
Aborted(native code called abort())
/home/daedsidog/test/ecl/build/test2/test.js:128
      throw ex;
      ^

RuntimeError: Aborted(native code called abort())
    at abort (/home/daedsidog/test/ecl/build/test2/test.js:665:11)
    at _abort (/home/daedsidog/test/ecl/build/test2/test.js:4869:7)
    at wasm://wasm/018e916e:wasm-function[1029]:0xacae3
    at wasm://wasm/018e916e:wasm-function[1829]:0x12a750
    at wasm://wasm/018e916e:wasm-function[1830]:0x12a83a
    at invoke_vi (/home/daedsidog/test/ecl/build/test2/test.js:5406:29)
    at wasm://wasm/018e916e:wasm-function[78]:0x59aa
    at wasm://wasm/018e916e:wasm-function[68]:0x455f
    at /home/daedsidog/test/ecl/build/test2/test.js:696:14
    at callMain (/home/daedsidog/test/ecl/build/test2/test.js:5944:15)

Node.js v21.2.0

I tried to dig around. The error is an internal ECL error thrown because ECL_DOWN_STACK is not defined ECL can't seem to set the stack. I've been stuck trying to deal with that ever since.

Edited by daedsidog