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

cmd/go: missing or invalid package binary for binary-only package with buildmode=plugin #27694

Closed
twyvip opened this issue Sep 15, 2018 · 7 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@twyvip
Copy link

twyvip commented Sep 15, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN="/test/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/test/adcloud_code/adroot/golang:/test/adcloud_code/tangwenyi/:/test/adframework/golang/trunk:/test/adkfw_application/trunk"
GORACE=""
GOROOT="/test/go"
GOTOOLDIR="/test/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build207457534=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

  1. I have one file in /root/work/go/src/say named say.go
    package say
import "fmt"
func Say(s string) string {
	return fmt.Sprintf("hello %s", s)
}
  1. I try to build it to .a file go build -i -o $GOPATH/pkg/linux_amd64/say.a

  2. change /root/work/go/src/say/say.go to

//go:binary-only-package

package say
  1. another file /root/work/go/src/say/work/v1.go
package v1
import (
	"fmt"
	"say"
)
func SayToBob() {
	fmt.Println(say.Say("Bob"))
}
  1. the main file /root/work/go/src/say/work/main.go
package main
import (
	"say/work/v1"
)
func main() {
	v1.SayToBob()
}
  1. run main.go go run /root/work/go/src/say/work/main.go
go run main.go
hello Bob
that's right
  1. but in fact, i need to build SayToBob as plugin to hot reload,run
    go build -buildmode=plugin -o /root/work/go/src/say/work/v1/plugin.so /root/work/go/src/say/work/v1/v1.go
    missing or invalid package binary for binary-only package say

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

can build plugin

What did you see instead?

can't build plugin
missing or invalid package binary for binary-only package say

@odeke-em odeke-em changed the title missing or invalid package binary for binary-only package when buildmode=plugin cmd/go: missing or invalid package binary for binary-only package with buildmode=plugin Sep 17, 2018
@odeke-em
Copy link
Member

Thank you for filing this issue @twyvip and welcome to Go!

Kindly paging @ianlancetaylor @rsc

@bcmills bcmills added the GoCommand cmd/go label Sep 17, 2018
@bcmills bcmills added this to the Go1.12 milestone Sep 17, 2018
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 17, 2018
@bcmills
Copy link
Contributor

bcmills commented Nov 15, 2018

Binary-only packages are a completely separate mechanism from -buildmode=plugin.

It's not obvious to me what's going in here, but given that binary-only packages are on the way out (#28152), I would suggest using plugins instead (https://golang.org/pkg/plugin/).

I also note that most of the commands you list involve explicit .go source files. I would generally expect to see package paths instead; the use of explicit files instead of packages may be related to the other symptoms you encountered.

@bcmills bcmills closed this as completed Nov 15, 2018
@twyvip
Copy link
Author

twyvip commented Nov 29, 2018

@bcmills Hello, I saw that you closed my question, but I still can't find out how to solve my problem from your answer. Is golang not using Binary-only packages (.a file) in plugin? ? Or is there a problem with my use? How can I solve my problem?
My application scenario is that I have to compile a plugin, but I referenced the .a library in the plugin. At this point I am going to compile plugin go build -buildmode=plugin -o /root/work/go/src/say/work/ V1/plugin.so will report the following error: missing or invalid package binary for binary-only package say
Thank you. I don't know where the problem is? I hope you can give pointers?

@bcmills
Copy link
Contributor

bcmills commented Nov 29, 2018

My application scenario is that I have to compile a plugin, but I referenced the .a library in the plugin.

Sounds like your plugin will need to be changed to load a plugin of its own, then. (Better still, can you build the plugin's dependencies from source?)

@twyvip
Copy link
Author

twyvip commented Nov 30, 2018

@bcmills I use the .a library in the plugin code. When I have the source code of the .a library, I can compile the plugin successfully. However, when I only have the .a library and have no source code, the compiler will give me an error, missing or invalid package binary for binary-only package say。My detailed steps are described above,Can you tell me what's wrong?thanks!

@bcmills
Copy link
Contributor

bcmills commented Nov 30, 2018

If you do have the source code, you should build the plugin against the source code.

If you do not have the source code, you will need to convert the package that was previously binary-only to be a plugin instead.

@dzpt
Copy link

dzpt commented Feb 24, 2019

@bcmills plugin is quite different thing from binary-only package.
If you have ever used C++ or Swift it works like binary-only package. Using plugin in Go is painful, code will be 100 times longer while methods aren't exposed to be used. It's suitable for CLI app rather than large scale framework.

@golang golang locked and limited conversation to collaborators Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants