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: fatal error: cannot find 'ld' without binutils-gold on alpine linux/arm64 #52399

Closed
yakkle opened this issue Apr 18, 2022 · 1 comment

Comments

@yakkle
Copy link

yakkle commented Apr 18, 2022

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.

@yakkle
Copy link
Author

yakkle commented Apr 18, 2022

This issue duplicated and already patched. See #22040

@yakkle yakkle closed this as completed Apr 18, 2022
ti-chi-bot added a commit to tikv/pd that referenced this issue Feb 13, 2023
close #5968, ref golang/go#52399

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Co-authored-by: lhy1024 <admin@liudos.us>
@golang golang locked and limited conversation to collaborators Apr 18, 2023
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

2 participants