Skip to content

cmd/link: undefined symbol when dynamically linking linux/arm64 -buildmode=shared #70222

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

Closed
qinlonglong123 opened this issue Nov 6, 2024 · 9 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@qinlonglong123
Copy link

Go version

go1.22.1 linux/arm64

Output of go env in your module/workspace:

GO111MODULE='off'
GOARCH='arm64'
GOBIN=''
GOCACHE='/usr1/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/opt/go_workpace/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/opt/go_workpace'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/root/go/'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/root/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD=''
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3307636971=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

I'm trying to use the Golang/go linkshared feature on Linux/ARM64, Here is my command to run:

go version
go install -a -buildmode=shared -linkshared std
go build -a -linkshared -o main_shared main.go
./main_shared

What did you see happen?

./main_shared: symbol lookup error: /root/go/pkg/linux_arm64_dynlink/libstd.so: undefined symbol: __aarch64_ldadd8_acq_rel

What did you expect to see?

Output the expected string Hello, World!

@adonovan adonovan changed the title Error in Linux/ARM64 shared mode cmd/link: undefined symbol when dynamically linking linux/arm64 -buildmode=shared Nov 6, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 6, 2024
@ianlancetaylor
Copy link
Contributor

The symbol __aarch64_ldadd8_acq_rel is normally defined by libgcc. Perhaps somehow the link of the shared library is not linking against libgcc, although I don't see why that would happen. What version of GCC are you using?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 6, 2024
@qinlonglong123
Copy link
Author

@ianlancetaylor thanks for your reply. I used this command gcc --version, it seems the GCC version is 7.3.0, and here is the output:

gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@ianlancetaylor
Copy link
Contributor

That is rather old. I don't know what the problem is, and I don't know whether this would help, but how difficult would it be for you to try a newer version of GCC? The current release is GCC 14.2.

@qinlonglong123
Copy link
Author

After updating GCC to version 10.3.1, the issue disappeared.
At the same time, I recompiled a race_linux_arm64.syso file using GCC 7.3.0 and the latest LLVM(llvmorg-19.1.3), and replacing the original src/runtime/race/race_linux_arm64.syso with the compiled race_linux_arm64.syso also resolved the issue. Would the community consider recompiling the race_linux_arm64.syso file using an older version of GCC?

@ianlancetaylor
Copy link
Contributor

Sorry, it's not really feasible for us to maintain old versions of GCC to use to build those syso files.

That said, we should probably try to document which version we used.

In any case, this bug seems fixed, so closing. Thanks for following up.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2024
@ianlancetaylor
Copy link
Contributor

Oh, actually, we do document what we built the syso files with, in runtime/race/README.

@randall77
Copy link
Contributor

Oh, actually, we do document what we built the syso files with, in runtime/race/README.

We document the version of llvm that we get the race detector code from. But that's not the compiler that was used to build it. I don't think we record that anywhere.

@ianlancetaylor
Copy link
Contributor

Oh, bother. Thanks.

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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
Development

No branches or pull requests

6 participants