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

golang 1.17.beta1, //go:linkname relocate not defined #46777

Closed
pkujhd opened this issue Jun 16, 2021 · 12 comments
Closed

golang 1.17.beta1, //go:linkname relocate not defined #46777

pkujhd opened this issue Jun 16, 2021 · 12 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@pkujhd
Copy link

pkujhd commented Jun 16, 2021

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

@mvdan
Copy link
Member

mvdan commented Jun 16, 2021

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.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 16, 2021
@cherrymui
Copy link
Member

Using linkname to access to unexported runtime symbols are not supported. Closing as working as intended.

@pkujhd
Copy link
Author

pkujhd commented Jun 17, 2021

@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?

@ianlancetaylor
Copy link
Contributor

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.

@pkujhd
Copy link
Author

pkujhd commented Jun 17, 2021

@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.

@pkujhd
Copy link
Author

pkujhd commented Jun 22, 2021

use the following instead, in golang1.17beta1 is ok

//go:linkname uncommon runtime.(_type).uncommon
func uncommon(t *_type) *uncommonType

@ianlancetaylor
Copy link
Contributor

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.

@pkujhd
Copy link
Author

pkujhd commented Jun 23, 2021

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.

@AZ-X
Copy link

AZ-X commented Aug 29, 2021

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.

@pkujhd
Copy link
Author

pkujhd commented Aug 30, 2021

@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
Copy link

AZ-X commented Sep 6, 2021

@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.

@AZ-X
Copy link

AZ-X commented Oct 13, 2021

I just made these stuff compiled via my custom patch base on the compiler shipped with golang 1.17.2.
BTW, it’s totally beyond my ‘COST’.

@pkujhd FYI.

@golang golang locked and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants