Repository: go
Issue: misc/cgo/test: link failure with atomics on arm64
Labels: NeedsInvestigation,arch-arm64

<!--
Please answer these questions before submitting your issue. Thanks!
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.19.6 linux/arm64
</pre>

### Does this issue reproduce with the latest release?

Yes, with 1.20.1

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/var/tmp/portage/dev-lang/go-1.19.6/work/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/var/tmp/portage/dev-lang/go-1.19.6/work/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.19.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/var/tmp/portage/dev-lang/go-1.19.6/work/go/src/go.mod"
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-build2755505689=/tmp/go-build -gno-record-gcc-switches"
</pre></details>

- gcc (Gentoo 12.2.1_p20230121-r1 p10) 12.2.1 20230121
- Linux arm64-stable 5.15.64-gentoo-dist aarch64 GNU/Linux

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on go.dev/play is best.
-->
On an arm64 machine, I've used previous bootstrap of 1.19.5 (located at `/usr/lib/go`, had passed the tests) and compiled and ran the test suite:

1. `cd src`
2. `GOROOT_BOOTSTRAP=/usr/lib/go GOOS=linux GOARCH=arm64 ./make.bash`
3. `PATH="$(dirname ${PWD})/bin:${PATH}" ./run.bash -no-rebuild`


### What did you expect to see?

Test suite passing as with previous version 1.19.5

### What did you see instead?

<details><summary>Test suite failure</summary><br><pre>
##### ../misc/cgo/test
ok      misc/cgo/test   2.016s
# misc/cgo/test.test
loadelf: /usr/lib/gcc/aarch64-unknown-linux-gnu/12/libgcc.a(_mulsc3.o/): 147259: sym#128 (wm4.0.2dd2ef601d1ee34f25664efd3ab09129): ignoring symbol in section 1 (type 0)
loadelf: /usr/lib/gcc/aarch64-unknown-linux-gnu/12/libgcc.a(_muldc3.o/): 147264: sym#128 (wm4.0.04c8e0a7cf24532cc22a8c08a8485b50): ignoring symbol in section 1 (type 0)
loadelf: /usr/lib/gcc/aarch64-unknown-linux-gnu/12/libgcc.a(_absvsi2.o/): 147269: sym#127 (wm4.0.8b6811288dcbb7bf8d7935a4ff231675): ignoring symbol in section 1 (type 0)
loadelf: /usr/lib/gcc/aarch64-unknown-linux-gnu/12/libgcc.a(lse-init.o/): 147281: sym#26 (wm4.0.e9dbc2a4f4cd55ed8d876963f7cda273): ignoring symbol in section 1 (type 0)
misc/cgo/test(.text): unknown symbol __mulsc3 in callarm64
misc/cgo/test(.text): unknown symbol __muldc3 in callarm64
misc/cgo/test(.text): unknown symbol __absvsi2 in callarm64
libgcc(.text): unknown symbol __aarch64_have_lse_atomics
misc/cgo/test(.text): relocation target __mulsc3 not defined
misc/cgo/test(.text): relocation target __muldc3 not defined
misc/cgo/test(.text): relocation target __absvsi2 not defined
libgcc(.text): relocation target __aarch64_have_lse_atomics not defined
FAIL    misc/cgo/test [build failed]
FAIL
2023/02/27 20:06:52 Failed: exit status 2
ok      misc/cgo/test   2.084s
ok      misc/cgo/testtls        0.004s
ok      misc/cgo/testtls        0.005s

</pre></details>

The environment where this happened is inside a container, so I can perform extra check or info collection if requested.