go: cmd/cgo: missing references to symbols in .syso

What version of Go are you using (go version)?

$ go version
go version devel go1.19-2bea43b0e7 Thu May 12 04:47:29 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/binet/.cache/go-build"
GOENV="/home/binet/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/binet/dev/go/gocode/pkg/mod"
GONOPROXY="gitlab.cern.ch/tile-in-one/tio-go"
GONOSUMDB="gitlab.cern.ch/tile-in-one/tio-go"
GOOS="linux"
GOPATH="/home/binet/dev/go/gocode"
GOPRIVATE="gitlab.cern.ch/tile-in-one/tio-go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/binet/sdk/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/binet/sdk/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.19-2bea43b0e7 Thu May 12 04:47:29 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3696923155=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$> cd somewhere
$> git clone git@github.com:gioui/gio gio && cd gio
$> go build ./...
[...]
gioui.org/widget/material
gioui.org/gpu/internal/vulkan
gioui.org/gpu
gioui.org/internal/egl
# gioui.org/internal/egl
/usr/bin/ld: /home/binet/work/gio/pkg/mod/gioui.org/shader@v1.0.6/piet/backdrop_linux_amd64.syso: in function `backdrop_coroutine_begin':
:(.text+0x2b): undefined reference to `coroutine_alloc_frame'
/usr/bin/ld: /home/binet/work/gio/pkg/mod/gioui.org/shader@v1.0.6/piet/backdrop_linux_amd64.syso: in function `backdrop_coroutine_begin.destroy':
:(.text+0x2a42): undefined reference to `coroutine_free_frame'
/usr/bin/ld: /home/binet/work/gio/pkg/mod/gioui.org/shader@v1.0.6/piet/backdrop_linux_amd64.syso: in function `backdrop_coroutine_begin.cleanup':
:(.text+0x2a54): undefined reference to `coroutine_free_frame'
/usr/bin/ld: /home/binet/work/gio/pkg/mod/gioui.org/shader@v1.0.6/piet/binning_linux_amd64.syso: in function `binning_coroutine_begin':
:(.text+0x24): undefined reference to `coroutine_alloc_frame'
/usr/bin/ld: /home/binet/work/gio/pkg/mod/gioui.org/shader@v1.0.6/piet/binning_linux_amd64.syso: in function `binning_coroutine_begin.resume':
:(.text+0x13fe): undefined reference to `floorf'
/usr/bin/ld: :(.text+0x140f): undefined reference to `floorf'
/usr/bin/ld: :(.text+0x1421): undefined reference to `floorf'
/usr/bin/ld: :(.text+0x1434): undefined reference to `floorf'
/usr/bin/ld: :(.text+0x1464): undefined reference to `floorf'

everything works fine w/ Go-1.18.x

What did you expect to see?

a valid build.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I think I have a relatively simple solution: if cgo fails when generating _cgo_import.go, let’s silently hide the failure, and mark the object (somehow) as requiring external linking. Then we can fail at link time if we are internally linking and the object says we can’t do that.

Thanks @dominikh for the information. It seems the error comes from this command

TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -o $WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/backdrop_linux_amd64.syso /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/binning_linux_amd64.syso /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/coarse_linux_amd64.syso /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/elements_linux_amd64.syso /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/kernel4_linux_amd64.syso /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/path_coarse_linux_amd64.syso /home/dominikh/prj/pkg/mod/gioui.org/shader@v1.0.6/piet/tile_alloc_linux_amd64.syso -g -O2 -L/nix/store/7vymg77rj9q42iriksanwzafln601ing-libglvnd-1.4.0/lib -lEGL

which is the cgo tool building _cgo_main.c, instead of the final linking of the binary.

CL https://go-review.googlesource.com/c/go/+/402596 may be related, which makes the cgo tool pass syso files. It appears that when compiling the egl package the cgo tool passes the syso from the piet package (per CL description, it includes transitive dependencies). The Go and C files from the piet package (https://git.sr.ht/~eliasnaur/gio-shader/tree/main/item/piet/backdrop_abi.go#L13 , https://git.sr.ht/~eliasnaur/gio-shader/tree/main/item/piet/support.c#L20) provides the -lm flag and the missing symbols, but they are not included by the cgo tool.

cc @ianlancetaylor @rsc