golang 1.17.beta1, //go:linkname relocate not defined
Closed this issue · 12 comments
What version of Go are you using (go version
)?
go version go1.17beta1 darwin/amd64
Does this issue reproduce with the latest release?
no
What operating system and processor architecture are you using (go env
)?
go env
Output
GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/Users/pkujhd/Library/Caches/go-build" GOENV="/Users/pkujhd/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/pkujhd/Code/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/pkujhd/Code/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/Users/pkujhd/programs/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/Users/pkujhd/programs/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.17beta1" GCCGO="gccgo" AR="ar" CC="clang" CXX="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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_r/x5c6p7hj7pl8c4n84tp1tj240000gn/T/go-build3226677352=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
pkujhd@pkujhd t % cat main.go
package main
import (
"fmt"
_ "runtime"
"unsafe"
)
type _type struct {
}
type uncommonType struct {
}
//go:linkname (_type).uncommon runtime.(_type).uncommon
func (t *_type) uncommon() *uncommonType
func main() {
a := _type{}
b := unsafe.Pointer(&a)
fmt.Println(a.uncommon(), b)
}
pkujhd@pkujhd t % ls -l *
-rw-r--r-- 1 pkujhd staff 0 6 16 11:56 empty.asm.s
-rw-r--r-- 1 pkujhd staff 294 6 16 13:24 main.go
pkujhd@pkujhd t % go build
What did you expect to see?
build ok
What did you see instead?
main.main: relocation target main.(*_type).uncommon not defined
on golang 1.16.4, build ok
What are you actually trying to accomplish? I don't think linknaming to low-level runtime names is supported or guaranteed to keep working between Go versions.
In general, you should be using reflect
instead.
Using linkname to access to unexported runtime symbols are not supported. Closing as working as intended.
@cherrymui , this is a mini test case. on golang 1.16 or before version, this case compile is ok, on golang 1.17 beta1, it compile errors. Plan to stop support this feature on newer version?
Using //go:linkname
to react into internal runtime names has never been supported. The fact that it worked before was not intended. In general all uses of //go:linkname
are unsafe and not supported. Sorry.
@ianlancetaylor
I see, thanks for your kind interpretation.
I write a module like plugin, use some functions of runtime module, i will replace it with my code.
use the following instead, in golang1.17beta1 is ok
//go:linkname uncommon runtime.(_type).uncommon
func uncommon(t *_type) *uncommonType
I want to be clear that it may work but it is not OK for production code. Writing code like this will break in future releases.
I want to be clear that it may work but it is not OK for production code. Writing code like this will break in future releases.
this package compile on fixed version, on new releases will be try to adapt.
Thanks for your kind interpretation.
use the following instead, in golang1.17beta1 is ok
//go:linkname uncommon runtime.(_type).uncommon
func uncommon(t *_type) *uncommonType
I've tried both when golang 1.16 released. Sad to know this inconvenient change happen to the compiler.
@pkujhd Would you please find related leads inside the NEW compiler, so we can REVERT it or leverage it.
@AZ-X your problem is not same with mine. walltime() is removed from runtime package. my problem is a struct member function can not relocat in golang 1.17.
in addition, I used this for a package like plugin.
I could not know how much changes with newer version. you may ask golang dev-group
@AZ-X your problem is not same with mine. walltime() is removed from runtime package. my problem is a struct member function can not relocat in golang 1.17.
in addition, I used this for a package like plugin.
I could not know how much changes with newer version. you may ask golang dev-group
I don't think they will take responsible for that. Perhaps you didn't get my problem related to this topic.