Invalid memory access on Alpine

This post was extracted from this thread, as it started to become off topic there.


Compiling a code which raises an error, using --static on Alpine produces a binary that runs but shows this error (with or without --release):

Invalid memory access (signal 11) at address 0x0
Segmentation fault (core dumped)

Here is how to reproduce:

Create this test.cr file:

puts "hello"
begin
  raise "some error"
rescue
  puts "suppressed error"
end

Running it or building it locally, works as expected:

$ crystal build --release test.cr && ./test
hello
suppressed error

Building it on alpine, and running it inside Alpine or outside the container (in my case, my Ubuntu) triggers the error:

$ docker run --rm -it -v $PWD:/app dannyben/crystal build --static --release /app/test.cr

$ ./test
hello
Invalid memory access (signal 11) at address 0x0
Segmentation fault (core dumped)

Just for double verification, I tested it with another crystal alpine image, with the exact same results:

$ docker run --rm -it -v $PWD:/app -w /app jrei/crystal-alpine crystal build --static --release test.cr

For reference (in case it matters):

This issue is discussed at https://github.com/crystal-lang/crystal/issues/4276

Thank you. I see it is a long running issue which is “not a priority”.

Too bad, this issue comes out regularly and should have an higher priority, despite being non-trivial to solve, because it is a major selling point for the language, as for Go.

At least, it has to be milestoned for Crystal 1.0.

Note there is a hack described in the README.md @DannyB.

4 Likes

I totally agree.

To be honest, I am not looking for hacks, but thanks for pointing that out.

As much as I wanted to see Crystal as my salvation, I was a little concerned from the get go that it has a small development team and showing signs of deceleration in momentum.

To me, having the ability to easily compile binaries for public consumption is the only reason I am looking anywhere else but Ruby, since Ruby’s performance is completely satisfactory for everything that I do (and I do a lot of Ruby).

I really hope this changes, but I got the impression that it is unlikely to happen, at least not soon enough.

2 Likes

Does -static work on non musl libc distro’s?

No, not really. glibc has issues with static linking. And Crystal doesn’t support any other libc than those two.

There is actually a promising suggestion that could be employed to solve this. Just needs someone to tackle it.

1 Like