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/link: fails once more than one function of a .syso file is called #20350

Open
stapelberg opened this Issue May 12, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@stapelberg
Contributor

stapelberg commented May 12, 2017

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

go version go1.8.1 linux/amd64

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

GOARCH="arm64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/michael/go"
GORACE=""
GOROOT="/home/michael/go1.8.1"
GOTOOLDIR="/home/michael/go1.8.1/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build551212718=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="0"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

$ head -50 multiple.go both_arm64.s both_arm64.S
==> multiple.go <==
package main

func asm1()

func asm2()

func main() {
	asm1()
	asm2()
}

==> both_arm64.s <==
TEXT ·asm1(SB),$0-0
	JMP asm1ext(SB)

TEXT ·asm2(SB),$0-0
	JMP asm2ext(SB)

==> both_arm64.S <==
.text

.global asm1ext
asm1ext:
    ret

.global asm2ext
asm2ext:
    ret
$ aarch64-linux-gnu-gcc -c -O0 -fPIC -no-pie -o both_arm64.syso both_arm64.S
$ GOARCH=arm64 go build

The issue is reproducible using gcc on an arm64 machine to build the .syso file.

What did you expect to see?

The program should build.

Removing either the call to asm1 or asm2 in the .go file makes it build.

Removing either the JMP asm1ext(SB) or the JMP asm2ext(SB) makes it build.

Adding NOSPLIT to both asm1 and asm2 doesn’t help either.

What did you see instead?

$ GOARCH=arm64 go build
# multiple-syso
asm2ext: call to external function

@ianlancetaylor ianlancetaylor changed the title from Linking fails once more than one function of a .syso file is called to cmd/link: fails once more than one function of a .syso file is called May 12, 2017

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented May 12, 2017

Does it work if you use -ldflags=-linkmode=external?

@stapelberg

This comment has been minimized.

Contributor

stapelberg commented May 12, 2017

Does it work if you use -ldflags=-linkmode=external?

No:

$ GOARCH=arm64 go build -ldflags=-linkmode=external                 
# multiple-syso
warning: unable to find runtime/cgo.a
asm2ext: call to external function
main.asm1: relocation target asm1ext not defined
main.asm2: relocation target asm2ext not defined
main.asm1: undefined: "asm1ext"
main.asm2: undefined: "asm2ext"

@andybons andybons added this to the Unplanned milestone Apr 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment