# Invalid memory access on Alpine

**URL:** <https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385>\
**Category:** Help & Support\
**Created:** [November 16, 2019, 6:12pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385 "2019-11-16T18:12:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DannyB](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/dannyb/32/622_2.png) [@DannyB](https://forum.crystal-lang.org/u/DannyB)\
**Post date:** [November 16, 2019, 6:12pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/1 "2019-11-16T18:12:54Z")

</div>

_This post was extracted from [this thread](https://forum.crystal-lang.org/t/cross-compiling-automatically-to-osx/1330/31), 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`):

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

```

### Here is how to reproduce:

Create this `test.cr` file:

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

```

Running it or building it locally, works as expected:

```nohighlight
$ 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:

```nohighlight
$ 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:

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

```

For reference (in case it matters):

- [Here is the Dockerfile for dannyben/crystal](https://github.com/DannyBen/docker-alpine-crystal/blob/master/Dockerfile)
- [Here is the Dockerfile for the alternative image by jrei](https://github.com/j8r/dockerfiles/blob/master/crystal-alpine/latest.Dockerfile)

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [November 16, 2019, 10:41pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/2 "2019-11-16T22:41:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DannyB](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/dannyb/32/622_2.png) [@DannyB](https://forum.crystal-lang.org/u/DannyB)\
**Post date:** [November 17, 2019, 6:53am UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/3 "2019-11-17T06:53:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![j8r](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/j8r/32/111_2.png) [@j8r](https://forum.crystal-lang.org/u/j8r)\
**Post date:** [November 17, 2019, 5:50pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/4 "2019-11-17T17:50:42Z")

</div>

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](https://github.com/j8r/dockerfiles/tree/master/crystal-alpine) @DannyB.

---

<div class="post-metadata">

**Author:** ![DannyB](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/dannyb/32/622_2.png) [@DannyB](https://forum.crystal-lang.org/u/DannyB)\
**Post date:** [November 17, 2019, 6:26pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/5 "2019-11-17T18:26:08Z")

</div>

> [@j8r](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/rogerdpack/32/117_2.png) [@rogerdpack](https://forum.crystal-lang.org/u/rogerdpack)\
**Post date:** [November 18, 2019, 7:23am UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/6 "2019-11-18T07:23:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [November 18, 2019, 9:12pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/7 "2019-11-18T21:12:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [November 18, 2019, 9:16pm UTC](https://forum.crystal-lang.org/t/invalid-memory-access-on-alpine/1385/8 "2019-11-18T21:16:58Z")

</div>

> [@DannyB](#):
>
> I really hope this changes, but I got the impression that it is unlikely to happen, at least not soon enough.

There is actually a [promising suggestion](https://github.com/crystal-lang/crystal/issues/4276#issuecomment-354197229) that could be employed to solve this. Just needs someone to tackle it.
