# Can't compile GOLANG on armv7 via balena cross compile or docker edge arm support

**URL:** <https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591>\
**Category:** Product support\
**Created:** [October 29, 2019, 2:24pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591 "2019-10-29T14:24:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jt77](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jt77](https://forums.balena.io/u/jt77)\
**Post date:** [October 29, 2019, 2:24pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/1 "2019-10-29T14:24:28Z")

</div>

I’m trying to build an image of logspout on MacOS for RPi3/armv7 from this repo/branch:

> **[CactusTechnologies/logspout](https://github.com/CactusTechnologies/logspout/tree/joel/docker-buildx)**
>
> Log routing for Docker container logs. Contribute to CactusTechnologies/logspout development by creating an account on GitHub.

I’ve added a simple hello test to run through, because it also doesn’t build correctly but I can’t identify the problem (whether it’s docker or go or what). I’m on MacOS 10.14.6, running Docker Desktop Edge 2.1.4.0 (arm support).

If you checkout that repo/branch and run this, it will build fine:

`docker buildx build --platform linux/arm64 --no-cache -f Dockerfile.hello .`

If you run this however:

`docker buildx build --platform linux/arm/v7 --no-cache -f Dockerfile.hello .`

It throws this error:

```auto

#7 16.03 Linux buildkitsandbox 4.14.131-linuxkit #1 SMP Fri Jul 19 12:31:17 UTC 2019 armv7l Linux

#7 17.32 # command-line-arguments

#7 17.32 runtime: pointer 0xa00020 to unused region of span span.base()=0x800000 span.limit=0x801ff0 span.state=1

#7 17.32 runtime: found in object at *(0xfffc5008+0x7fe8)

#7 17.32 object=0xfffc5008 s=nil

#7 17.32 fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?)

```

So I wanted to see if I could use one of Balena’s images using cross-build-start, this one runs fine:

`docker build --no-cache -f Dockerfile.balenacross .`

So then I made one using cross-build-start to run/build the Go program:

`docker build --no-cache -f Dockerfile.hellobalenacross .`

And it throws the same error:

```auto
Linux 7f692e18a736 4.14.131-linuxkit #1 SMP Fri Jul 19 12:31:17 UTC 2019 armv7l Linux

# command-line-arguments

runtime: pointer 0xa00020 to unused region of span span.base()=0x800000 span.limit=0x809f00 span.state=1

runtime: found in object at *(0xfffc5008+0x7fe8)

object=0xfffc5008 s=nil

fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?)

```

Any ideas on what’s going on? Or even where the problem is so I can open a ticket there?

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [October 29, 2019, 6:28pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/2 "2019-10-29T18:28:09Z")

</div>

Hello,

This seems to be a qemu problem, this thing builds fine on a real armv7.  
You can test it by pushing this code to balena which will do a native build.

---

<div class="post-metadata">

**Author:** ![jt77](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jt77](https://forums.balena.io/u/jt77)\
**Post date:** [October 29, 2019, 6:46pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/4 "2019-10-29T18:46:01Z")

</div>

Yes, I noticed that, just wanted to flag this here because all of the arm/docker code is built around qemu and I had never heard anyone talking about incompatibilities within it. Should I raise this issue with qemu then?

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [October 29, 2019, 7:01pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/5 "2019-10-29T19:01:11Z")

</div>

I guess.  
Not sure if it should be on go or qemu.  
I couldn’t find anyone reporting this issue on the Internet.  
The closest thing I’ve found is [https://github.com/golang/go/issues/19135](https://github.com/golang/go/issues/19135) but it’s on an older version of go (1.8) and cross compiling from mac amd64 to mac i386.

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [October 30, 2019, 1:56pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/11 "2019-10-30T13:56:28Z")

</div>

Hi, I searched for similar issues reported on GitHub and I could find plenty reported on the Go lang repo. Please check whether you are running latest Go version and if that still does not work, I think the Go lang repo is the best place to report this.

Thanks,  
Zahari

---

<div class="post-metadata">

**Author:** ![jt77](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jt77](https://forums.balena.io/u/jt77)\
**Post date:** [October 30, 2019, 2:43pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/13 "2019-10-30T14:43:02Z")

</div>

Just to add two things I discovered yesterday while poking around a little bit more. I decided to try this with ubuntu instead of alpine, and everything built/compiled correctly on the same MacOS/Docker combo that doesn’t work with the alpine image. I created another branch here:

> **[CactusTechnologies/logspout](https://github.com/CactusTechnologies/logspout/tree/joel/docker-buildx-ubuntu)**
>
> Log routing for Docker container logs. Contribute to CactusTechnologies/logspout development by creating an account on GitHub.

`docker buildx build --platform linux/arm/v7 --no-cache -f Dockerfile .`

I also created a real armv7 server at scaleway and ran the ORIGINAL alpine branch code, and as noted by @zvin above, everything ran and compiled correctly. I even checked across that alpine docker image and the image that is being pulled by docker on MacOS, and it’s pulling the same one:

sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a

That server was running this version of Ubuntu:  
Distributor ID: Ubuntu  
Description: Ubuntu 16.04.5 LTS  
Release: 16.04  
Codename: xenial  
Linux scw-elastic-mclaren 4.4.127-mainline-rev1 #1 SMP Sun Apr 8 10:33:17 UTC 2018 armv7l armv7l armv7l GNU/Linux  
Docker version 18.09.0, build 4d60db4

I also tried changing the build image to arm32v7/alpine:latest on MacOS/Docker buildx, but that also failed (I was reading some places that alpine didn’t have real armv7 support?)

So not sure what this narrows it down to? An issue between Alpine/qemu and the linux kernel that comes with MacOS Docker? Linux buildkitsandbox 4.14.131-linuxkit #1 SMP Fri Jul 19 12:31:17 UTC 2019 armv7l Linux

Maybe the next step I will try is to get it to compile using the Docker CE edge buildx stuff on x86 ubuntu to see if it has the same problems? If it works correctly there, then it’s not a qemu problem but something specific to the MacOS docker kernel?

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [October 30, 2019, 3:02pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/14 "2019-10-30T15:02:41Z")

</div>

Possibly the difference is because Alpine uses musl libc instead of glibc. It is worth trying to build that on Ubuntu indeed. I still think it falls into the area of Go language itself though because it deals with those low level allocations. Here is an example recent commit: [https://github.com/golang/go/commit/813d8e886208e5e001df3b55e8bc1c65ca4249ff](https://github.com/golang/go/commit/813d8e886208e5e001df3b55e8bc1c65ca4249ff)

---

<div class="post-metadata">

**Author:** ![jt77](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jt77](https://forums.balena.io/u/jt77)\
**Post date:** [October 30, 2019, 4:58pm UTC](https://forums.balena.io/t/cant-compile-golang-on-armv7-via-balena-cross-compile-or-docker-edge-arm-support/40591/16 "2019-10-30T16:58:26Z")

</div>

Ok, I will open an issue with Go lang.

Also, I tried it on Ubuntu at Scaleway on amd64/x86 and it failed the same as on MacOS. Steps to reproduce…

Spin up Ubuntu version: Ubuntu 18.04.2 LTS

I installed edge docker from .deb for this test:

```auto
wget https://download.docker.com/linux/ubuntu/dists/bionic/pool/edge/amd64/containerd.io_1.2.6-3_amd64.deb
wget https://download.docker.com/linux/ubuntu/dists/bionic/pool/edge/amd64/docker-ce_19.03.3~3-0~ubuntu-bionic_amd64.deb
wget https://download.docker.com/linux/ubuntu/dists/bionic/pool/edge/amd64/docker-ce-cli_19.03.4~3-0~ubuntu-bionic_amd64.deb

dpkg -i *.deb

```

Then follow these instructions to get buildx and gemu setup:

> **[Getting started with Docker for Arm on Linux - Docker Engineering Blog](https://engineering.docker.com/2019/06/getting-started-with-docker-for-arm-on-linux/)**
>
> This blog post is the result of collaboration between Arm and Docker.  Special thanks to Jason Andrews @ Arm for creating much of the original content. Arm and Docker announced a strategic partnership earlier this year to unify software...

I did the buildx binary
