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/compile: It seems go:linkname gopark runtime.gopark and go:linkname goready runtime.goready on arm not work #23080

Closed
FlowerWrong opened this issue Dec 11, 2017 · 8 comments

Comments

@FlowerWrong
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go 1.8.1 and 1.9.2

Does this issue reproduce with the latest release?

yes

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

darwin with golang 1.9.2
archlinux with golang 1.9.2

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/yy/dev/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build997705220=/tmp/go-build -gno-record-gcc-switches"
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"

also Raspberry Pi 3 Model B arm structure with golang 1.8.1

What did you do?

I am crossing compiling google/netstack. It worked fine on linux, darwin and windows.
But failed on arm(eg: android, raspberry pi3).

What did you expect to see?

build success

What did you see instead?

The error log is

GOOS=linux GOARM=7 GOARCH=arm go build -o main main.go

../../netstack/sleep/sleep_unsafe.go:78:6: missing function body
../../netstack/sleep/sleep_unsafe.go:81:6: missing function body

This line

And then, I try it on raspberry pi3 in real device with go build -o main main.go. The same error log.

@davecheney
Copy link
Contributor

davecheney commented Dec 11, 2017 via email

@FlowerWrong
Copy link
Author

FlowerWrong commented Dec 11, 2017

Command GOOS=linux GOARCH=arm GOARM=7 go install github.com/google/netstack/tcpip/sample/tun_tcp_echo

Output

# github.com/google/netstack/sleep
sleep/sleep_unsafe.go:78:6: missing function body
sleep/sleep_unsafe.go:81:6: missing function body
# github.com/google/netstack/tcpip/link/rawfile
tcpip/link/rawfile/rawfile_unsafe.go:20:6: missing function body
tcpip/link/rawfile/rawfile_unsafe.go:75:7: cannot use uint64(len(b1)) (type uint64) as type uint32 in field value
tcpip/link/rawfile/rawfile_unsafe.go:79:7: cannot use uint64(len(b2)) (type uint64) as type uint32 in field value

And error in # github.com/google/netstack/tcpip/link/rawfile, I have solved.

# github.com/google/netstack/tcpip/link/rawfile
tcpip/link/rawfile/rawfile_unsafe.go:20:6: missing function body
tcpip/link/rawfile/rawfile_unsafe.go:75:7: cannot use uint64(len(b1)) (type uint64) as type uint32 in field value
tcpip/link/rawfile/rawfile_unsafe.go:79:7: cannot use uint64(len(b2)) (type uint64) as type uint32 in field value

The only question is go:linkname gopark runtime.gopark and go:linkname goready runtime.goready on arm not work.

# github.com/google/netstack/sleep
sleep/sleep_unsafe.go:78:6: missing function body
sleep/sleep_unsafe.go:81:6: missing function body

@davecheney
Copy link
Contributor

davecheney commented Dec 11, 2017 via email

@FlowerWrong
Copy link
Author

command GOOS=linux GOARCH=arm GOARM=7 go build -x github.com/google/netstack/tcpip/sample/tun_tcp_echo
Output

WORK=/var/folders/zz/3gn7zjp91vdd3dxwgq4b089w0000gn/T/go-build007862576
mkdir -p $WORK/github.com/google/netstack/tcpip/link/rawfile/_obj/
mkdir -p $WORK/github.com/google/netstack/tcpip/link/
mkdir -p $WORK/github.com/google/netstack/sleep/_obj/
cd /Users/kingyang/go/src/github.com/google/netstack/tcpip/link/rawfile
/usr/local/opt/go/libexec/pkg/tool/darwin_amd64/compile -o $WORK/github.com/google/netstack/tcpip/link/rawfile.a -trimpath $WORK -goversion go1.9.2 -p github.com/google/netstack/tcpip/link/rawfile -complete -buildid a98b2111a45a16511e8469fa66450690c48db39b -D _/Users/kingyang/go/src/github.com/google/netstack/tcpip/link/rawfile -I $WORK -I /Users/kingyang/go/pkg/linux_arm -pack ./errors.go ./rawfile_unsafe.go
mkdir -p $WORK/github.com/google/netstack/
cd /Users/kingyang/go/src/github.com/google/netstack/sleep
/usr/local/opt/go/libexec/pkg/tool/darwin_amd64/compile -o $WORK/github.com/google/netstack/sleep.a -trimpath $WORK -goversion go1.9.2 -p github.com/google/netstack/sleep -complete -buildid 91e2d39e252c9958acba4ce484c3bf8be1d6088b -D _/Users/kingyang/go/src/github.com/google/netstack/sleep -I $WORK -pack ./commit_noasm.go ./sleep_unsafe.go
# github.com/google/netstack/sleep
../../../sleep/sleep_unsafe.go:78:6: missing function body
../../../sleep/sleep_unsafe.go:81:6: missing function body
# github.com/google/netstack/tcpip/link/rawfile
../../link/rawfile/rawfile_unsafe.go:20:6: missing function body
../../link/rawfile/rawfile_unsafe.go:75:7: cannot use uint64(len(b1)) (type uint64) as type uint32 in field value
../../link/rawfile/rawfile_unsafe.go:79:7: cannot use uint64(len(b2)) (type uint64) as type uint32 in field value

@davecheney
Copy link
Contributor

davecheney commented Dec 11, 2017 via email

FlowerWrong added a commit to FlowerWrong/netstack that referenced this issue Dec 11, 2017
@FlowerWrong
Copy link
Author

Thanks very much, it is my fault.

@FlowerWrong
Copy link
Author

How did you judge there is missing commit_arm.s?Experience?

@davecheney
Copy link
Contributor

davecheney commented Dec 11, 2017

@FlowerWrong sadly yes, you need to know the magic of how //go:linkmode is implemented in the compiler.

Because the function isn't implemented in Go, there has to be a 'stub' function, a forward declaration that tells the compiler that something else will provide the code for that function -- this is usually done by an assembly function in the same package, but in the case of //go:linkmode the function is actually in another package.

This is what the -complete flag does, it says to the compiler "this package is complete, there are no functions that are not implemented in the .go source files provided on the command line." I forget exactly what -complete is needed for, I think it's to do with the internal packing of various .o files into a single .a file. Hopefully someone else can remind me, //cc @ianlancetaylor

Anyway, the compiler can't figure out complete status on its own, so it relies on the go tool to pass -complete down to it; or leave the flag off if the package contains .s assembly files. So even though you're not using assembly in this package, you need an empty .s file to signal to the go tool that the package is incomplete--there are functions implemented in other packages and brought together in the linking stage (that's why it's called //go:linkmode)--so that it won't generate that "function not defined" error during compilation.

@mikioh mikioh changed the title It seems go:linkname gopark runtime.gopark and go:linkname goready runtime.goready on arm not work cmd/compile: It seems go:linkname gopark runtime.gopark and go:linkname goready runtime.goready on arm not work Jan 5, 2018
@golang golang locked and limited conversation to collaborators Jan 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants