"loadinternal: cannot find runtime/cgo" with base: core20, go.mod but no cgo in code

Bug #1883265 reported by Jamie Strandboge
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
New
Undecided
Chris Patterson

Bug Description

Following https://snapcraft.io/docs/go-plugin, with a hello-world type application using golang 1.13, go.mod, base: core20, but with no cgo, using this:

base: core20
parts:
  foo:
    plugin: go
    go-channel: 1.13/stable
    source: .
    source-type: git
    stage-packages:
    - gcc
    build-environment:
    - CGO_ENABLED: "0" # didn't help

Then building I get:
$ snapcraft
...
Pulling foo
Cloning into '/root/parts/foo/src'...
done.
Building foo
+ go mod download
+ go install -p 2 -ldflags -linkmode=external ./...
# github.com/canonical/foo/cmd/foo
loadinternal: cannot find runtime/cgo
/snap/go/5828/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

Failed to build 'foo'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
[2]

I tried staging different things like build-essential and libc6-dev which gave different, but failing output always related to ld.

What did work was:

base: core20
parts:
  foo:
    plugin: go
    go-channel: 1.13/stable
    source: .
    source-type: git
    build-environment:
    - CGO_ENABLED: "0" # may not be required
    override-build: |
      go install -p 2 ./...

(note I was able to drop stage-packages too).

I wonder if it makes sense that if CGO_ENABLED=0, you drop -ldflags -linkmode=external? At the very least there seems to be a documentation opportunity.

Revision history for this message
Chris Patterson (cjp256) wrote :

I was not able to reproduce. Can you share a full example? I tried with https://github.com/snapcore/snapcraft/tree/master/tests/spread/plugins/v2/snaps/go-mod-hello and a modified snapcraft.yaml to mirror what you're using:

name: go-mod-hello
version: "1.0"
summary: A simple go project using go.mod
description: |
  This is a basic go snap. It just prints a hello world brought in from
  a version pinned go package using go.mod.

grade: devel
base: core20
confinement: strict

apps:
  go-mod-hello:
    command: bin/go-mod-hello

parts:
  hello:
    source: .
    plugin: go
    go-channel: 1.13/stable
    stage-packages:
      - gcc
    build-environment:
      - CGO_ENABLED: "0"

Revision history for this message
Chris Patterson (cjp256) wrote :

Could you also try w/o `go-channel`? core20 has go 1.13 package available. I'm curious if that makes a difference in your case.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

$ tar -zxvf ./lp1883265.tar.gz
$ snapcraft
...
Building foo
+ go mod download
+ go install -p 2 -ldflags -linkmode=external ./...
# somewhere/test/lp1883265/cmd
loadinternal: cannot find runtime/cgo
/snap/go/5828/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/root/parts/foo/install/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/root/parts/foo/install/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

Failed to build 'foo'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
[2]
$

Removing go-channel did not make a difference.

Revision history for this message
Sergio Schvezov (sergiusens) wrote : Re: [Bug 1883265] [NEW] "loadinternal: cannot find runtime/cgo" with base: core20, go.mod but no cgo in code

Have you tried adding gcc-multilib or libc6-dev to build-packages?

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Using gcc, lib6-dev or gcc-multilib in build-packages makes no difference.

Changed in snapcraft:
assignee: nobody → Chris Patterson (cjp256)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.