Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.18 linux/arm64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="arm64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64" GOVCS="" GOVERSION="go1.18" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1126837739=/tmp/go-build -gno-record-gcc-switches"
What did you do?
go build -ldflags "-v" reproduce.go
with below code in alpine linux/arm64
package main
import (
"fmt"
"plugin"
)
type pluginWallet struct {
plugin *plugin.Plugin
}
func main() {
fmt.Println("hello")
}
What did you expect to see?
successful build without error or show detail log why build failed.
What did you see instead?
~/src/gold # go build -ldflags "-v" reproduce.go
# command-line-arguments
HEADER = -H5 -T0x11000 -R0x10000
host link: "gcc" "-Wl,-znow" "-Wl,-znocopyreloc" "-fuse-ld=gold" "-o" "/tmp/go-build518924850/b001/exe/a.out" "-rdynamic" "/tmp/go-link-2349840200/go.o" "/tmp/go-link-2349840200/000000.o" "/tmp/go-link-2349840200/000001.o" "/tmp/go-link-2349840200/000002.o" "/tmp/go-link-2349840200/000003.o" "/tmp/go-link-2349840200/000004.o" "/tmp/go-link-2349840200/000005.o" "/tmp/go-link-2349840200/000006.o" "/tmp/go-link-2349840200/000007.o" "/tmp/go-link-2349840200/000008.o" "/tmp/go-link-2349840200/000009.o" "/tmp/go-link-2349840200/000010.o" "/tmp/go-link-2349840200/000011.o" "/tmp/go-link-2349840200/000012.o" "/tmp/go-link-2349840200/000013.o" "/tmp/go-link-2349840200/000014.o" "-g" "-O2" "-ldl" "-g" "-O2" "-lpthread"
/usr/local/go/pkg/tool/linux_arm64/link: running gcc failed: exit status 1
collect2: fatal error: cannot find 'ld'
compilation terminated.
related issue : #15696
https://github.com/golang/go/blob/go1.18/src/cmd/link/internal/ld/lib.go#L1406-L1416
if out, err := cmd.CombinedOutput(); err == nil {
if !bytes.Contains(out, []byte("GNU gold")) {
log.Fatalf("ARM external linker must be gold (issue #15696), but is not: %s", out)
}
}
First, in this ld/lib.go
source code, the fatal logs are not printed because of err
is not nil.
// If gold is not installed, gcc will silently switch
// back to ld.bfd. So we parse the version information
// and provide a useful error if gold is missing.
Second, following above comments, I expect successful build using ld.bfd
. but failed. why?
Third, origin relocation bug fixed binutils 2.36+. https://sourceware.org/bugzilla/show_bug.cgi?id=19962
but, still using gold linker because of above code.