Navigation Menu

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: -buildmode=plugin -linkshared -> build failure #18671

Closed
navytux opened this issue Jan 15, 2017 · 14 comments
Closed

cmd/go: -buildmode=plugin -linkshared -> build failure #18671

navytux opened this issue Jan 15, 2017 · 14 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@navytux
Copy link
Contributor

navytux commented Jan 15, 2017

Please answer these questions before submitting your issue. Thanks!

What did you do?

Hello up there. I'm trying to build plugin dynamically linked to other go packages and it fails. Details below:

  • we have fresh go checkout + src/all.bash run
  • then go install -buildmode=shared std was run
  • a sample test plugin source:

---- 8< ---- (myplugin.go)

package main

import (
        "fmt"
)

func PlugFunc() {
        fmt.Println("myplugin.PlugFunc")
}

func init() {
        fmt.Println("myplygin.init")
}
  • I'm trying to build it as go build -buildmode=plugin -linkshared myplugin.go

What did you expect to see?

Build succeeds; myplugin.so dynamically links to packages it imports.

What did you see instead?

# command-line-arguments
runtime.islibrary: missing Go type information for global symbol: size 1

(for the reference building without -linkshared succeeds)

Does this issue reproduce with the latest release (go1.7.4)?

No, there is no plugin support in go1.7 at all:

$ go17 build -buildmode=plugin myplugin.go 
buildmode=plugin not supported

Possibly related issues:

#17150

System details

go version devel +76f981c8d8 Sat Jan 14 17:11:31 2017 +0000 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/kirr/go"
GORACE=""
GOROOT="/home/kirr/src/tools/go/go"
GOTOOLDIR="/home/kirr/src/tools/go/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build611710721=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version devel +76f981c8d8 Sat Jan 14 17:11:31 2017 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel +76f981c8d8 Sat Jan 14 17:11:31 2017 +0000 X:framepointer
uname -sr: Linux 4.8.0-2-amd64
Distributor ID:	Debian
Description:	Debian GNU/Linux testing (stretch)
Release:	testing
Codename:	stretch
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC 2.24-8) stable release version 2.24, by Roland McGrath et al.
gdb --version: GNU gdb (Debian 7.12-4) 7.12
@crawshaw
Copy link
Member

This is a feature I couldn't find time for in 1.8, but I would like to see in 1.9. (After darwin support.)

I'm not sure if this warrants a better error message for 1.8. Thoughts, @bradfitz, @ianlancetaylor?

@crawshaw crawshaw added this to the Go1.9 milestone Jan 16, 2017
@navytux
Copy link
Contributor Author

navytux commented Jan 17, 2017

@crawshaw thanks for feedback.

@bradfitz bradfitz modified the milestones: Go1.9, Go1.10 Jun 7, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Dec 1, 2017
@gopherbot gopherbot modified the milestones: Go1.11, Unplanned May 23, 2018
@ssadler
Copy link

ssadler commented Jun 22, 2018

Also ran into this issue, with go 1.10.2 and 1.10.3; downgrading to 1.9.7 it works.

@ghost
Copy link

ghost commented Apr 8, 2019

Hi. We are currently running into this problem. It's quite hard to find out what's the current status of this issue. Was it resolved in 1.9 (doesn't look like) ? Is it definitely dropped ?

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 8, 2019
@ianlancetaylor
Copy link
Contributor

I don't expect -buildmode=plugin -linkshared` to work today. Somebody will have to investigate the problems and figure out whether they can be fixed. I don't know of anybody planning to do that.

@ghost
Copy link

ghost commented Apr 9, 2019

@ianlancetaylor thanks for the feedback

@n454149301
Copy link

Thank you. After reading it, I tried it.
It's true that in the "old style", using the export gopath = ` xxx 'style, I can get the expected results.

But when I use the go. Mod style, there are all kinds of panic.

@n454149301
Copy link

This bug was fixed in 14c92c5

@navytux
Copy link
Contributor Author

navytux commented May 14, 2020

This bug was fixed in 14c92c5

Here is what I get today with Go tip (go version devel +e3ccf40623 Thu May 14 03:10:52 2020 +0000 linux/amd64):

$ gotip build -buildmode=plugin -linkshared myplugin.go
# command-line-arguments
/home/kirr/src/tools/go/gotip/pkg/tool/linux_amd64/link: cannot implicitly include runtime/cgo in a shared library

For gotip install -buildmode=shared std itself:

kirr@deco:~/src/tools/go/gotip/src$ gotip install -buildmode=shared std
# /tmp/go-build759334816/b203/libstd.so
/home/kirr/src/tools/go/gotip/pkg/tool/linux_amd64/link: fingerprint mismatch: errors has 0000000000000000, import from archive/tar expecting 1cce8eaa5db90f7e

(and the same even after rm -rf ~/.cache/go-build/)

Maybe I'm missing something, but I cannot say this issue is fixed.

@n454149301
Copy link

n454149301 commented May 15, 2020

# tree
.
├── a.go
├── pkg
└── src
    └── heheda
        └── heheda.go

3 directories, 2 files

# cat a.go
package main

import "heheda"

func Hehe() {
	heheda.Heheda()
}

# cat src/heheda/heheda.go
package heheda

import "fmt"

func Heheda() {
	fmt.Println("vim-go")
}

# GOPATH=`pwd` go install -buildmode=shared -linkshared heheda
# tree
tree
.
├── a.go
├── pkg
│   └── linux_amd64_dynlink
│       ├── heheda.a
│       ├── heheda.shlibname
│       └── libheheda.so
└── src
    └── heheda
        └── heheda.go

4 directories, 5 files

# GOPATH=`pwd` go build -buildmode=plugin -linkshared a.go
# tree
tree
.
├── a.go
├── a.so
├── pkg
│   └── linux_amd64_dynlink
│       ├── heheda.a
│       ├── heheda.shlibname
│       └── libheheda.so
└── src
    └── heheda
        └── heheda.go

4 directories, 6 files

# ldd a.so 
	linux-vdso.so.1 (0x00007ffe024a9000)
	libstd.so => /home/source/golang/go/pkg/linux_amd64_dynlink/libstd.so (0x00007fb206b84000)
	libheheda.so => /home/test/pkg/linux_amd64_dynlink/libheheda.so (0x00007fb20687f000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb20667b000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb20645c000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb20606b000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fb209742000)

# go version
go version go1.14.2 linux/amd64

# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/test/.cache/go-build"
GOENV="/home/test/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="dc.gitlab.com"
GONOSUMDB="dc.gitlab.com"
GOOS="linux"
GOPATH="/home/test/go"
GOPRIVATE="dc.gitlab.com"
GOPROXY="direct"
GOROOT="/home/source/golang/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/home/source/golang/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build650799967=/tmp/go-build -gno-record-gcc-switches"

I'm useing 14c92c5

So, what's wrong with my understanding?

@navytux
Copy link
Contributor Author

navytux commented May 15, 2020

So, what's wrong with my understanding?

Not sure what it is, but for me your example fails with both gotip and go1.14.3:

$ tree
.
├── a.go
└── src
    └── heheda
        └── heheda.go

2 directories, 2 files

$ cat a.go 
package main

import "heheda"

func Hehe() {
 heheda.Heheda()
}

$ cat src/heheda/heheda.go 
package heheda

import "fmt"

func Heheda() {
 fmt.Println("vim-go")
}

$ GOPATH=`pwd` go install -buildmode=shared -linkshared heheda
installing shared library: cannot use packages heheda and runtime/cgo from different roots /home/kirr/tmp/trashme/goplugin/n/pkg/linux_amd64_dynlink and /home/kirr/src/tools/go/go/pkg/linux_amd64_dynlink

$ GOPATH=`pwd` go build -buildmode=shared -linkshared heheda
# /tmp/go-build179285411/b032/libheheda.so
/home/kirr/src/tools/go/go/pkg/tool/linux_amd64/link: cannot implicitly include runtime/cgo in a shared library

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/kirr/.cache/go-build"
GOENV="/home/kirr/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/kirr/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/kirr/src/tools/go/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/kirr/src/tools/go/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build844377383=/tmp/go-build -gno-record-gcc-switches"

@n454149301
Copy link

$ GOPATH=pwd go install -buildmode=shared -linkshared std
$ GOPATH=pwd go install -buildmode=shared -linkshared heheda
$ GOPATH=pwd go build -buildmode=plugin -linkshared a.go

@seankhliao
Copy link
Member

Obsoleted by #47788

@gopherbot
Copy link

Change https://golang.org/cl/369594 mentions this issue: cmd/{link,compile},runtime: support buildmode=plugin with linkshared

@golang golang locked and limited conversation to collaborators Dec 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

9 participants