Bug 15204

Summary: go-cross-canadian-arm fails to compile
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Tim <tim.vanderstaaij>
Component: devtools / tool chainAssignee: Osama Abdelkader <osama.abdelkader>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: bart.staal, kweihmann, meta.mr.watcher, meta.watcher, osama.abdelkader, raj.khem, randy.macleod, richard.purdie, ross.burton, tgamblin
Version: 4.2.3   
Target Milestone: 5.3 M3   
Hardware: x86   
OS: x86_64   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Attachments:
Description Flags
proposed fix none

Description Tim 2023-09-04 09:00:18 UTC
In my project with a Cortex A7 target, the SDK fails to build after upgrading to Mickledore, because the image includes `go` in `SDK_TOOLCHAIN_LANGS` and go-cross-canadian-arm fails at the do_compile step.

More specifically, in the step where the boostrap Go compiler is invoked to build the standard library and such, the compiler exits with status 1 without printing any output whatsoever.

I can reproduce this failure with poky tags mickledore-4.2.0 and mickledore-4.2.3, as well as the mickledore branch tip and a recent master commit (40f215c). langdale-4.1.4 works fine however.

Tested on Fedora 37 (native), Fedora 38 (native) and Debian Bullseye (containerized).

Excerpts from output of `bitbake go-cross-canadian-arm`:

| DEBUG: Executing shell function do_compile
| Building Go cmd/dist using <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.6-r0/recipe-sysroot-native/usr/lib/go. (go1.20.6 linux/amd64)

| go tool dist: FAILED: <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.6-r0/go/pkg/tool/native_native/go_bootstrap install -ldflags=all=-linkmode external -extld x86_64-pokysdk-linux-gcc -extldflags "--sysroot=<workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.6-r0/recipe-sysroot -no-pie -fno-PIE -march=x86-64 -Wl,-O1            -Wl,-rpath-link,<workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.6-r0/recipe-sysroot/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/..            -Wl,-rpath,/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/.. " std cmd: exit status 1
| WARNING: exit code 2 from a shell command.
NOTE: recipe go-cross-canadian-arm-1.20.6-r0: task do_compile: Failed

Minimal reproducible example:

sources/demo-bsp/conf/layer.conf
---
BBPATH .= ":${LAYERDIR}"
LAYERDEPENDS_meta-demo-bsp = "core"
LAYERSERIES_COMPAT_meta-demo-bsp = "langdale mickledore"
---

sources/demo-bsp/conf/machine/demo.conf
---
require conf/machine/include/arm/armv7a/tune-cortexa7.inc
---

build/conf/bblayers.conf
---
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
YOCTOROOT = "${@os.path.abspath(os.path.join("${TOPDIR}", os.pardir))}"
BBLAYERS ?= " \
  ${YOCTOROOT}/sources/poky/meta \
  ${YOCTOROOT}/sources/poky/meta-poky \
  ${YOCTOROOT}/sources/demo-bsp \
  "
---

build/conf/local.conf as generated by `oe-init-build-env`, except for `MACHINE ??= "demo"`
Comment 1 Richard Purdie 2023-09-07 14:34:51 UTC
Would you be able to reproduce this on a MACHINE from OE-Core? Those are the ones we test the release with.
Comment 2 Tim 2023-09-07 17:02:33 UTC
That's good to know. I ran a clean build of go-cross-canadian-arm with `MACHINE ??= "qemuarm"` and the issue does indeed reproduce.
Comment 3 Ross Burton 2023-09-14 15:38:07 UTC
I confirm that this happens with pristine mickledore and qemuarm, and also happens for master.

| go tool dist: FAILED: /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.7/go/pkg/tool/native_native/go_bootstrap install -ldflags=all=-linkmode external -extld x86_64-pokysdk-linux-gcc -extldflags "--sysroot=/yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.7/recipe-sysroot -no-pie -fno-PIE -march=x86-64 -Wl,-O1            -Wl,-rpath-link,/yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.20.7/recipe-sysroot/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/..            -Wl,-rpath,/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/.. " std cmd: exit status 1

Obviously we don't test a Go SDK...

Copying Khem for any thoughts.
Comment 4 Ross Burton 2023-09-14 15:45:59 UTC
Interestingly with master but targeting qemuarm64:

$ bitbake go-cross-canadian-aaarch64
...
| # cmd/go
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/go/pkg/tool/native_native/link: running x86_64-pokysdk-linux-gcc failed: exit status 1
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: Relocations in generic ELF (EM: 183)
| /yocto/ross/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.20.7/recipe-sysroot-native/usr/bin/x86_64-pokysdk-linux/../../libexec/x86_64-pokysdk-linux/gcc/x86_64-pokysdk-linux/13.2.0/ld: /tmp/go-link-1900630836/go.o: error adding symbols: file in wrong format
| collect2: error: ld returned 1 exit status
|
Comment 5 Ross Burton 2023-09-14 15:56:39 UTC
And for fun, mickledore for qemuarm64 builds but the binaries have buildpaths.
Comment 6 Bart 2023-10-16 14:21:50 UTC
Initially we (I'm a colleague of Tim) didn't find any error messages in the logs. It was only until I was adding some debug prints to the Go sourcecode until I noticed that the following message was already present in the logs:

  HASH[build runtime/cgo]: "import unsafe \n"
  HASH[build runtime/cgo]: e4c00e0cbacff15d748fb4865049cbaa607560ca144fc72071c8112260177214
  # runtime/cgo
  gcc: error: unrecognized command-line option '-marm'; did you mean '-mabm'?

Seems like the Go toolchain uses the right compiler (because it is building a compiler that runs on x86_64, to which SDKMACHINE is set), but somehow thinks it is building for arm?

I checked the environment vars by invoking 'set' in do_compile() in go-cross-canadian.inc, just before make.bash is called. I found this in the output:

  GO386=''
  GOARCH='arm'
  GOARM='7'
  GODEBUG='gocachehash=1'
  GOHOSTARCH='amd64'
  GOHOSTOS='linux'
  GOMIPS=''
  GOOS='linux'

I tried a build where I inserted the settings below in do_compile(). I copied the values from HOST_GOxxx variables I found by running 'bitbake -e':

  export GOARCH="amd64"
  export GOAOS="linux"
  export GOARM=""
  export GO386="sse2"

This fixes the error message. I've not yet been able to check if the resulting toolchain also generates correct binaries (sorry, time was up). I also have no idea how to fix this correctly, probably it should be done somewhere in a .bbclass file?

I tried to identify the commit that introduced this issue by running 'git checkout <commit> -- ../meta/recipes-devtools/go' in the kirkstone branch. It looks like commit 34157b4b 'go-cross-canadian: use gcc-crosssdk, not gcc-native' introduced this problem.
Comment 7 Bart 2023-10-16 14:26:04 UTC
Oh, and also I get warnings about 'references to TMPDIR'.
Comment 8 Randy MacLeod 2023-10-30 15:29:10 UTC
Bulk move to 5.0 M1. -- Randy
Comment 9 Randy MacLeod 2023-12-21 23:28:24 UTC
Bulk move of 52 5.0-M1 bugs to M2.
Comment 10 Randy MacLeod 2024-01-25 14:28:49 UTC
Bulk move of bugs owned by "unassigned" from 5.0-M2 to 5.0-M3.
Comment 11 Randy MacLeod 2024-09-10 16:54:09 UTC
I don't see any commits that fix this issue. Moving to M4.
Comment 12 Randy MacLeod 2025-01-30 16:06:35 UTC
Bulk move to 5.2-M3.
Comment 13 Randy MacLeod 2025-01-30 16:17:02 UTC
Bulk move to 5.2-M3 and this time I'll actually specify M3!
Comment 14 Randy MacLeod 2025-03-18 18:04:59 UTC
I'm reviewing old milestones.
Tim, can you check if this is still a problem one poky/master please?
We'll review this bug on March 20th 10:30 AM ET.
Comment 15 Tim 2025-03-19 12:51:06 UTC
I tried to run `bitbake go-cross-canadian-arm` with poky master (e57dee3). Same minimum reproducible example as in my original report, except with MACHINE=qemuarm and updated LAYERSERIES_COMPAT.

It still fails, but in a different way. Previously the issue was in do_compile. Now there is a problem with do_install:

ERROR: go-cross-canadian-arm-1.24.1-r0 do_install: Execution of '<workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/temp/run.do_install.1109488' failed with exit code 1
ERROR: Logfile of failure stored in: <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/temp/log.do_install.1109488
Log data follows:
| DEBUG: Executing python function extend_recipe_sysroot
| NOTE: Direct dependencies are ['<workspace>/sources/poky/meta/recipes-devtools/gcc/gcc-crosssdk_14.2.bb:do_populate_sysroot', '<workspace>/sources/poky/meta/recipes-devtools/go/go-binary-native_1.24.1.bb:do_populate_sysroot', '<workspace>/sources/poky/meta/recipes-devtools/go/go-crosssdk_1.24.1.bb:do_populate_sysroot', '<workspace>/sources/poky/meta/recipes-devtools/quilt/quilt-native_0.68.bb:do_populate_sysroot', 'virtual:native:<workspace>/sources/poky/meta/recipes-devtools/chrpath/chrpath_0.18.bb:do_populate_sysroot', 'virtual:native:<workspace>/sources/poky/meta/recipes-devtools/pseudo/pseudo_git.bb:do_populate_sysroot', 'virtual:nativesdk:<workspace>/sources/poky/meta/recipes-core/glibc/glibc_2.41.bb:do_populate_sysroot', 'virtual:nativesdk:<workspace>/sources/poky/meta/recipes-devtools/gcc/gcc-runtime_14.2.bb:do_populate_sysroot', 'virtual:nativesdk:<workspace>/sources/poky/meta/recipes-devtools/go/go-runtime_1.24.1.bb:do_populate_sysroot']
| NOTE: Installed into sysroot: []
| NOTE: Skipping as already exists in sysroot: ['gettext-minimal-native', 'binutils-crosssdk-x86_64-pokysdk-linux', 'gcc-crosssdk-x86_64-pokysdk-linux', 'go-binary-native', 'go-crosssdk-x86_64-pokysdk-linux', 'libtool-native', 'm4-native', 'quilt-native', 'texinfo-dummy-native', 'gettext-native', 'zlib-native', 'chrpath-native', 'flex-native', 'gnu-config-native', 'pseudo-native', 'xz-native', 'zstd-native', 'attr-native', 'gmp-native', 'libmpc-native', 'mpfr-native', 'sqlite3-native', 'nativesdk-glibc', 'nativesdk-gcc-runtime', 'nativesdk-libgcc', 'nativesdk-go-runtime', 'nativesdk-linux-libc-headers']
| DEBUG: Python function extend_recipe_sysroot finished
| DEBUG: Executing shell function do_install
| install: omitting directory '<workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/go/bin/linux_arm'
| WARNING: <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/temp/run.do_install.1109488:166 exit 1 from 'install -m755 $f <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/image/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/go/bin'
| WARNING: Backtrace (BB generated script):
| 	#1: do_install, <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/temp/run.do_install.1109488, line 166
| 	#2: main, <workspace>/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-arm/1.24.1/temp/run.do_install.1109488, line 191
Comment 16 Randy MacLeod 2025-05-01 14:09:07 UTC
Bulk move of most 5.2-M4 unassigned bugs to 5.3-M2.
Comment 17 Osama Abdelkader 2025-08-07 23:19:37 UTC
Created attachment 5130 [details]
proposed fix

The do_install issue is that
for f in ${B}/${GO_BUILD_BINDIR}/*
line doesn't work for subdirectories, in the attached patch I fixed that by using 'find -type f'. I just sent the patch few minutes ago.
Comment 18 Randy MacLeod 2025-08-08 13:17:46 UTC
Thanks Osama!

I applied the attached patch to master HEAD without issue.
Can you send the patch to the email list? Is as easy as:

$git send-email - -1 -M --to openembedded-core@lists.openembedded.org

once you've set-up your account and email properly.
https://docs.yoctoproject.org/contributor-guide/index.html
Comment 19 Osama Abdelkader 2025-08-08 16:21:57 UTC
Thanks Randy, I just sent it.
Comment 20 Randy MacLeod 2025-08-08 17:15:22 UTC
*** Bug 15775 has been marked as a duplicate of this bug. ***
Comment 21 Randy MacLeod 2025-08-08 17:18:12 UTC
Excellent, I see that patch on the list and that our patch bot hasn't complained! ;-)

If you don't hear back on your email, check master on Monday or Tuesday
and if merged, add a link here and resolve this issue.

Welcome to Yocto!
Comment 22 Osama Abdelkader 2025-08-08 20:56:45 UTC
Thanks Randy.
Comment 23 Bart 2025-08-12 07:59:51 UTC
Thanks Osama! I can confirm the patch works for us.
Comment 24 Randy MacLeod 2025-08-14 16:00:00 UTC
Fixed by:

https://git.openembedded.org/openembedded-core/commit/?id=31e3bd61c7986bc044e547aa5cb9caba7b32bf22

Osama, 
Thanks for this fix and for the strace update which came in just in time to help with another problem!
Comment 25 Osama Abdelkader 2025-08-15 20:05:42 UTC
Thanks Bart.
Thanks Randy, my pleasure :)