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

Open
stapelberg opened this issue May 12, 2017 · 3 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@stapelberg
Copy link
Contributor

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 Linking fails once more than one function of a .syso file is called cmd/link: fails once more than one function of a .syso file is called May 12, 2017
@ianlancetaylor
Copy link
Contributor

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

@stapelberg
Copy link
Contributor Author

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 11, 2018
@andybons andybons added this to the Unplanned milestone Apr 11, 2018
@pwaller
Copy link
Contributor

pwaller commented Mar 26, 2019

-linkmode=external giving relocation target * not defined is another issue I have filed: #30890.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants