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: libraries are not resolved with cgo_import_dynamic (arm64) #49789

Open
bc-lee opened this issue Nov 24, 2021 · 1 comment
Open

cmd/link: libraries are not resolved with cgo_import_dynamic (arm64) #49789

bc-lee opened this issue Nov 24, 2021 · 1 comment

Comments

@bc-lee
Copy link

@bc-lee bc-lee commented Nov 24, 2021

What version of Go are you using (go version)?

ToT (b38ab0a)

$ go version
go version devel go1.18-b38ab0ac5f Wed Nov 24 16:01:55 2021 +0000 linux/amd64

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="/path/to/.cache/go-build"
GOENV="/path/to/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/path/to/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="android"
GOPATH="/path/to/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/path/to/redacted_go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/path/to/redacted_go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-b38ab0ac5f Wed Nov 24 16:01:55 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/path/to/redacted/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-build3301990219=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create the two files shown in #39256. (It also exists as a test case for https://golang.org/cl/235257.)

Build it into an executable with the following environment variables:

CGO_ENABLED=1 GOOS=android GOARCH=arm64 CC_FOR_TARGET=/path/to/android_sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang

Run it on the Arm64 Android device.

What did you expect to see?

Works fine.

What did you see instead?

When I run the executable on my device, I get the following error message:

CANNOT LINK EXECUTABLE "./executable_name": cannot locate symbol "getpid" referenced by "/data/local/tmp/executable_name"...

On host machine (Linux / amd64):

$ readelf --dynamic executable_name  | grep NEEDED
$ nm -g executable_name | grep ' U '
                 U close
                 U getpid
                 U kill
                 U open

I think the following line is causing this issue.

if target.Arch.Family == sys.AMD64 && !cgoeDynamic && dil != "" && !seenlib[dil] {

With this patch, the 'DT_NEEDED' entry in the final executable exists as expected and the error goes away.

--- a/src/cmd/link/internal/ld/elf.go
+++ b/src/cmd/link/internal/ld/elf.go
@@ -2257,7 +2257,7 @@ func elfadddynsym(ldr *loader.Loader, target *Target, syms *ArchSyms, s loader.S
 
                dil := ldr.SymDynimplib(s)
 
-               if target.Arch.Family == sys.AMD64 && !cgoeDynamic && dil != "" && !seenlib[dil] {
+               if !cgoeDynamic && dil != "" && !seenlib[dil] {
                        du := ldr.MakeSymbolUpdater(syms.Dynamic)
                        Elfwritedynent(target.Arch, du, elf.DT_NEEDED, uint64(dstru.Addstring(dil)))
                        seenlib[dil] = true
@gopherbot
Copy link

@gopherbot gopherbot commented Nov 24, 2021

Change https://golang.org/cl/366855 mentions this issue: cmd/link: fix for not generating DT_NEEDED entries on non Amd64

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants