golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.07k stars 17.68k forks source link

gccgo: implement plugin package #36403

Open zhsj opened 4 years ago

zhsj commented 4 years ago

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

$ go version
go version go1.12.2 gccgo (Debian 9.2.1-21) 9.2.1 20191130 linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zhsj/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/zhsj/go"
GOPROXY="https://proxy.golang.org"
GORACE=""
GOROOT="/usr"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/gcc/x86_64-linux-gnu/9"
GCCGO="/usr/bin/x86_64-linux-gnu-gccgo-9"
CC="x86_64-linux-gnu-gcc-9"
CXX="x86_64-linux-gnu-g++-9"
CGO_ENABLED="1"
GOMOD="/home/zhsj/go/src/github.com/containerd/containerd/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build814416476=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

What did you do?

build containerd with gccgo

go-9 build -tags "no_btrfs no_cri" -v ./cmd/containerd
plugin/plugin_go18.go:24:2: cannot find package "plugin" in any of:
        /home/zhsj/go/src/github.com/containerd/containerd/vendor/plugin (vendor tree)
        /usr/src/plugin (from $GOROOT)
        /home/zhsj/go/src/plugin (from $GOPATH)

I'm not sure if it's distribution issue or upstream issue. I didn't see plugin in /usr/lib/x86_64-linux-gnu/go/9/x86_64-linux-gnu/. But I see plugin in https://github.com/golang/gofrontend/tree/master/libgo/go/plugin

Is https://github.com/golang/gofrontend/blob/master/libgo/libgo-packages.txt responsible for it? I didn't see plugin in it too.

What did you expect to see?

What did you see instead?

ianlancetaylor commented 4 years ago

Yes: gccgo does not currently implement the plugin package. Sorry.

advancedwebdeveloper commented 4 years ago

Yes: gccgo does not currently implement the plugin package. Sorry.

@thanm , @ianlancetaylor , @cherrymui :

~/faasd$ make all CGO_ENABLED=0 GOOS=linux go build -o bin/faasd ../go/src/github.com/openfaas/faasd/vendor/github.com/containerd/containerd/plugin/plugin_go18.go:24:2: cannot find package "plugin" in any of: /home/oceanfish81/go/src/github.com/openfaas/faasd/vendor/plugin (vendor tree) /usr/local/src/plugin (from $GOROOT) /home/oceanfish81/go/src/plugin (from $GOPATH) make: *** [Makefile:12: local] Error 1

I was trying to build faasd :

$ go env && go version GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/oceanfish81/.cache/go-build" GOENV="/home/oceanfish81/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/oceanfish81/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/oceanfish81/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/tools" GCCGO="/usr/local/bin/llvm-goc" AR="ar" CC="/usr/bin/clang" CXX="/usr/bin/clang++" CGO_ENABLED="1" GOMOD="" 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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build934338008=/tmp/go-build -gno-record-gcc-switches -funwind-tables" go version go1.15rc2 gollvm LLVM 12.0.0git linux/amd64

YKG commented 3 years ago

Hi @ianlancetaylor , I got the same issue with go1.15.6, were there too much work to implement the plugin package in gccgo? If it's not, could you please give me some guildlines so thant I can implement one?

I'm trying to use coz with go, it seems like only gccgo compiled works fine, not gc. But since plugin package support is not implemented in gccgo, I can't work on those projects that use plugin.

ianlancetaylor commented 3 years ago

@YKG I think it would be a lot of work to implement the plugin package in gccgo. I haven't thought about it in detail.

xiaq commented 3 years ago

Would it make sense to copy the stub implementation to gccgo?

Currently the plugin package does not exist at all with gccgo, so code that imports plugin won't build on gccgo at all. This can be fixed by gating such code with a //+build !gccgo, but it'd be nicer to not have to do that.

ianlancetaylor commented 3 years ago

@xiaq For something that will never work, isn't it slightly better to fail at compile time than at run time? When would it be useful to be able to import "plugin" even though it won't work? Yes, you won't need to use a build tag, but instead your program won't run. That doesn't seem like an improvement.

cherrymui commented 3 years ago

I think there may be program that imports the plugin package but only use it in some code path, and plugin.Open is called only when plugins are actually used at run time. The program can still function (to some extent) if it compiles, just cannot use plugins.

xiaq commented 3 years ago

When would it be useful to be able to import "plugin" even though it won't work? Yes, you won't need to use a build tag, but instead your program won't run. That doesn't seem like an improvement.

I think you're thinking about the case where a program has a hard dependency on plugin.

My use case is that I have a program with a soft dependency on plugin. Without plugins, it will still work, just won't support plugins.

On gc, the plugin package always exists, but if the program was built with CGo disabled, or runs on an unsupported platform, any call will fail. So my code already needs to deal with the fact that despite it being buildable, the plugin package might not actually be available at runtime. But now it also needs to deal with the fact that it might not exist at all - which for my code is dealing with the same failure scenario twice. Having a stub plugin package means that this failure scenario is consistent between gc and gccgo.