Fork me on GitHub
#graalvm
<
2022-04-11
>
ericdallo12:04:03

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?🧵

borkdude12:04:16

See latest issue in the borkdude/jet repo, that might give you an idea 😅

👀 1
lispyclouds12:04:43

@U04V15CAJ and I had a lot of fun over this 😞

lispyclouds13:04:08

@UKFSJSM38 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

lispyclouds13:04:35

the segfault manifests as a cryptic file not found

lispyclouds13:04:54

also when it cannot find the .so file

borkdude13:04:03

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

lispyclouds13:04:50

having a look

ericdallo14:04:00

@U04V15CAJ 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?

ericdallo14:04:34

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?

borkdude14:04:05

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

ericdallo14:04:26

Good, so that's sounds safe enough to me

lispyclouds14:04:37

apart from the stack size issue i think

borkdude14:04:41

There is one caveat with musl concerning the stack size

borkdude14:04:45

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

borkdude14:04:42

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

ericdallo14:04:59

good to know about this workaround, will use it too