Skip to content
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

affected/package: plugin.Open does not work properly when cross compiled #59654

Closed
nikhilbhandari123 opened this issue Apr 16, 2023 · 8 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@nikhilbhandari123
Copy link

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

$ go version
go version go1.20.2 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/nikhil.bhandari/Library/Caches/go-build"
GOENV="/Users/nikhil.bhandari/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE=~/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users//go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.2/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lr/cfz8g6t12v7dtsn9xsrhxg2r0000gq/T/go-build3990546885=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I wrote a go plugin which needs to call some external C library functions. I compiled this plugin on a linux machine. Then in another go module, I am opening this plugin using plugin.Open and calling one of the functions provided. When I compile this go module (which is calling the plugin.Open) on Linux and run it on another Linux box (where I have put the compiled plugin already at the appropriate location), it works as expected, it is able to call the C function.

But when I cross compile the go module (which is calling plugin.Open) on my Mac for linux and then run this module on the same Linux machine (where the compiled plugin is already present at the correct location), it does not work. The same code, if compiled on Linux, works correctly as explained before. I use the following command to cross-compile on my Mac:

GOOS=linux GOARCH=amd64 go build -mod=vendor -o test ./gomodule

What did you expect to see?

It should have worked similarly whether built on Linux or cross compiled on Mac for Linux. The code is exactly same.

What did you see instead?

I see the following error for the cross compiled module:
plugin: not implemented

@seankhliao
Copy link
Member

Please include this self-contained reproducer in the report, including the commands to run

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 16, 2023
@nikhilbhandari123
Copy link
Author

This has the sample code to reproduce the problem:
https://github.com/nikhilbhandari123/plugin-example

@seankhliao
Copy link
Member

CGo is necessary. CGo is disabled when cross compiling, you'll need to explicitly enable it, and configure an appropriate C cross compiler toolchain.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2023
@nikhilbhandari123
Copy link
Author

CGo code is not the one getting cross compiled. It is the Go module which is getting cross compiled. CGo is compiled as a plugin on Linux. The Go code using this plugin is the one getting cross compiled which should have worked

@nikhilbhandari123
Copy link
Author

BTW, I have updated my example without any cgo dependency but still get the same error. Please reopen this issue

@seankhliao
Copy link
Member

using plugins requires cgo, regardless of whether you use it in your code.

@nikhilbhandari123
Copy link
Author

Ok, but is that is the case for the plugin itself, or also the caller of the plugin ? My problem is with the caller of the plugin. If I try to cross compile the plugin, it is not compiling. But why the plugin calling code (which got cross compiled) is failing ? If that also requires cgo, then it should not have cross compiled successfully in the first place ?

@seankhliao
Copy link
Member

see #19569

@golang golang locked and limited conversation to collaborators Apr 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants