graalvm

ericdallo 2022-04-11T12:26:03.183799Z

Question about musl static binaries (I still not fully understand it ๐Ÿ˜…) Should my program (clojure-lsp) that already compiles linux static with the -H:+StaticExecutableWithDynamicLibC change to --musl , what are the tradeoffs?๐Ÿงต

borkdude 2022-04-11T12:29:16.252629Z

See latest issue in the borkdude/jet repo, that might give you an idea ๐Ÿ˜…

๐Ÿ‘€ 1
lispyclouds 2022-04-11T12:58:43.185239Z

@borkdude and I had a lot of fun over this ๐Ÿ˜ž

lispyclouds 2022-04-11T13:02:08.846459Z

@ericdallo in a gist, when you use StaticExecutableWithDynamicLibC its compiling the binary with syscalls stubbed out to glibc which it may or may not use. So when you run in a non glibc OS like alpine and the binary wants to make such a call, it will segfault and there no saying when it may happen. Hence we use the musl lib which is a full c stdlib impl designed to be static linked unlike glibc

lispyclouds 2022-04-11T13:03:35.062669Z

the segfault manifests as a cryptic file not found

lispyclouds 2022-04-11T13:03:54.026829Z

also when it cannot find the .so file

borkdude 2022-04-11T13:04:03.489619Z

@rahul080327 could you take a peek at that latest jet issue?

lispyclouds 2022-04-11T13:04:50.797479Z

having a look

ericdallo 2022-04-11T14:41:00.758899Z

@borkdude I took a look and it seems to be the same issue on clojure-lsp right? jet didn't have the static binary compiled with musl too, right?

borkdude 2022-04-11T14:41:13.647299Z

exactly

ericdallo 2022-04-11T14:42:34.327539Z

I see, so it just confirm that using musl is always the safest option right? I always thought that but on some conversation recent on some thread, I (miss?)understood that there are cases where musl doesn't work but glibc works, is that right?

borkdude 2022-04-11T14:43:05.511309Z

I haven't encountered a situation where a musl compiled binary doesn't work and glibc did work better

ericdallo 2022-04-11T14:43:26.647889Z

Good, so that's sounds safe enough to me

ericdallo 2022-04-11T14:43:32.322329Z

thank you!

lispyclouds 2022-04-11T14:43:37.357569Z

apart from the stack size issue i think

borkdude 2022-04-11T14:43:41.392039Z

There is one caveat with musl concerning the stack size

borkdude 2022-04-11T14:44:45.950479Z

and:

BABASHKA_STATIC=${BABASHKA_STATIC:-}
BABASHKA_MUSL=${BABASHKA_MUSL:-}

if [ "$BABASHKA_STATIC" = "true" ]; then
    args+=("--static")
    if [ "$BABASHKA_MUSL" = "true" ]; then
        args+=("--libc=musl"
               # see 
               "-H:CCompilerOption=-Wl,-z,stack-size=2097152")
    else
        # see 
        args+=("-H:+StaticExecutableWithDynamicLibC")
    fi
fi

borkdude 2022-04-11T14:45:42.359599Z

So what I do is set the stack size to 2mb and run the main program within a thread

ericdallo 2022-04-11T14:47:59.398909Z

good to know about this workaround, will use it too