golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cmd/link: some packages don't build with -buildmode=shared

pebbe opened this issue · comments

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.5 linux/amd64
go version go1.10.1 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=""
GOCACHE="/tmp/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/peter/go"
GORACE=""
GOROOT="/my/opt/go"
GOTMPDIR="/tmp"
GOTOOLDIR="/my/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build569417713=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to install the package github.com/pebbe/util in lgo (github.com/yunabe/lgo). The package installs and works fine as a regular, static package. But lgo tries to build shared packages, and that fails.

I don't know what is going on, but this might be a bug in Go with -buildmode=shared

You can find a detailed description here: yunabe/lgo#57

I created a repository to reproduce this issue with minimum code
https://github.com/yunabe/gobug25065

cmd/link fails when a method A is defined as func (m myType) A() {} and it is referenced by (*myType).A.

Hm my fix for #22998 doesn't seem to fix this. Will need to make some time to dig properly into this.

If I run

go tool compile -shared -o foo.a GOPATH/github.com/yunabe/gobug25065/src.go

then go tool nm shows

    1187 R %22%22.(*myType).A·f

If I run

go tool compile -shared -dynlink -o foo.a GOPATH/github.com/yunabe/gobug25065/src.go

(that is, add the -dynlink option) then go tool nm shows

     U %22%22.(*myType).A·f

So it seems that when using -dynlink the symbol really is undefined.

Change https://golang.org/cl/153297 mentions this issue: cmd/compile: emit a symbol for a method expression when using -dynlink