Skip to content

go build with runtime/cgo package works on darwin, fails on linux and freebsd #47753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mvertes opened this issue Aug 17, 2021 · 1 comment
Closed

Comments

@mvertes
Copy link

mvertes commented Aug 17, 2021

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

$ go version
go version go1.17 darwin/arm64

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="arm64"
GOBIN=""
GOCACHE="/Users/marc/Library/Caches/go-build"
GOENV="/Users/marc/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/marc/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/marc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/marc/sdk/go1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/marc/sdk/go1.17/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/marc/go/src/github.com/mvertes/go-runtime-cgo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s1/my6xdm4x5vsdmn7n310zj55m0000gn/T/go-build3106423419=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Consider the following program:

package main

import (
	"fmt"
	"runtime/cgo"
)

func main() {
	var handle cgo.Handle

	fmt.Println(handle)
}

or https://play.golang.org/p/Ix5EtYeTTPD

Building it on darwin works, on freebsd or linux it fails:

What did you expect to see?

$ GOOS=darwin go build
$ GOOS=linux go build

What did you see instead?

$ GOOS=darwin go build
$ GOOS=linux go build
runtime.gcdata: missing Go type information for global symbol .dynsym: size 72
_cgo_init: relocation target x_cgo_init not defined
_cgo_mmap: relocation target x_cgo_mmap not defined
_cgo_munmap: relocation target x_cgo_munmap not defined
_cgo_notify_runtime_init_done: relocation target x_cgo_notify_runtime_init_done not defined
_cgo_sigaction: relocation target x_cgo_sigaction not defined
_cgo_thread_start: relocation target x_cgo_thread_start not defined
runtime._cgo_setenv: relocation target x_cgo_setenv not defined
runtime._cgo_unsetenv: relocation target x_cgo_unsetenv not defined
runtime.cgo_yield: relocation target _cgo_yield not defined
@randall77
Copy link
Contributor

In order to cross-compile a cgo-using Go program, you need a cross-compiling C compiler set up.
See https://pkg.go.dev/cmd/cgo look for "cross-compiling".

@golang golang locked and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants