GoLang hello example on Yocto Sumo

Viewed 53

I am trying to compile the go-helloworld poky recipe (meta/recipes-extended/go-examples/go-helloworld_0.1.bb) on Yocto Sumo:

DESCRIPTION = "This is a simple example recipe that cross-compiles a Go program."
SECTION = "examples"
HOMEPAGE = "https://golang.org/"

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "git://${GO_IMPORT}"
SRCREV = "46695d81d1fae905a270fb7db8a4d11a334562fe"
UPSTREAM_CHECK_COMMITS = "1"

GO_IMPORT = "github.com/golang/example"
GO_INSTALL = "${GO_IMPORT}/hello"

inherit go

# This is just to make clear where this example is
do_install_append() {
    mv ${D}${bindir}/hello ${D}${bindir}/${BPN}
}

I included it in my image, but the program immediately segfaults:

# /usr/bin/go-helloworld
Segmentation fault (core dumped)

Here is the gdb stacktrace:

(gdb) run
Starting program: /usr/bin/go-helloworld
Loading Go Runtime support.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x0000ffffbddeb660 in __libc_start_main (main=0x0, argc=0, argv=0x0, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=<optimized out>)
    at /usr/src/debug/glibc/2.27-r0/git/csu/libc-start.c:308
#2  0x000000000040133c in _start ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

And the file and ldd output for the executable:

# file /usr/bin/go-helloworld
/usr/bin/go-helloworld: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=43c68f4cf02c2ae885274abad641064dfbc8eb78, stripped
# ldd /usr/bin/go-helloworld
        linux-vdso.so.1 (0x0000ffff84506000)
        libstd.so => /usr/lib/go/pkg/linux_arm64_dynlink/libstd.so (0x0000ffff82d3b000)
        libc.so.6 => /lib/libc.so.6 (0x0000ffff82bd4000)
        libdl.so.2 => /lib/libdl.so.2 (0x0000ffff82bc1000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x0000ffff82b95000)
        /lib/ld-linux-aarch64.so.1 (0x0000ffff844db000)

I was able to get a build working by removing all the flags that go.bbclass specifies... So, now I have a bbappend with these statements:

GO_LINKSHARED = ""
GOBUILDFLAGS = ""

Before this change, these are what the flags were during the build:

export GOBUILDFLAGS="-p 32 -v -ldflags=\"-r /usr/lib/go/pkg/linux_arm64_dynlink  -extldflags ' --sysroot=/project/build-b9-imx8mq/tmp/work/aarch64-poky-linux/go-helloworld/0.1-r0/recipe-sysroot -Wl,-rpath-link=/project/build-b9-imx8mq/tmp/work/aarch64-poky-linux/go-helloworld/0.1-r0/recipe-sysroot/usr/lib/go/pkg/linux_arm64_dynlink -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed'\""

This change seems to work:

# /usr/bin/go-helloworld
Hello, Go examples!
# file /data/hello
/data/hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, with debug_info, not stripped
# ldd /data/hello
        not a dynamic executable

Even though this works, it leaves several artifacts on the yocto system which I do not need.. and I don't feel like rewriting the go.bbclass to behave as I expect it to (unless I absolutely have to). Is there a way I can build the hello world recipe the way it was intended (without overwriting those flags)? I need to start building a much more complex project using Gin and struggling with a hello world program does not give me much hope.

0 Answers
Related