Search code examples
gocross-compilingfreebsdcoredump

How to cross compile go application for FreeBSD within a Raspberry pi 1 model B


On a Raspberry Pi 1 model B I installed FreeBSD 10.3 using the SD Card Images RPI-B.

I can boot, get network, ssh into it, etc, all seems to be ok and functional. This is part of the dmesg output:

FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 08:01:14 UTC 2016
    [email protected]:/usr/obj/arm.armv6/usr/src/sys/RPI-B arm
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
VT: init without driver.
CPU: ARM1176JZ-S rev 7 (ARM11J core)
 Supported features: ARM_ISA THUMB2 JAZELLE ARMv4 Security_Ext
 WB enabled LABT branch prediction enabled
  16KB/32B 4-way instruction cache
  16KB/32B 4-way write-back-locking-C data cache
real memory  = 503312384 (479 MB)
avail memory = 483127296 (460 MB)

On a mac os X (10.11.6) with go 1.7.1:

go version go1.7.1 darwin/amd64

I am cross compile this code:

package main

import (
        "fmt"
        "time"
)

func main() {
        t := time.Now().UTC()
        fmt.Println("Location:", t.Location(), ":Time:", t.Format(time.RFC3339Nano))
}

With:

env GOOS=freebsd GOARCH=arm go build

Running the generated binary on the raspberry-pi generates a coredump:

freebsd@rpi-b:~ % ./time 
Illegal instruction (core dumped)

On the time.core after typing:

$ strings time.core

besides many characters I see this:

fatal error: cgo callback before cgo call

Any idea how what flags to use or how to properly cross-compile for FreeBSD within a Raspberry pi ?


Solution

  • Thanks to @putu comment, I was available to cross-compile using GOARM=6

    env GOOS=freebsd GOARCH=arm GOARM=6 go build