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

x/mobile: problem with multiple definition using gobind #26298

Closed
derekwbrown opened this issue Jul 9, 2018 · 12 comments

Comments

Projects
None yet
4 participants
@derekwbrown
Copy link

commented Jul 9, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.2 linux/amd64
(I have also experienced the problem with go1.10.2/windows)

Does this issue reproduce with the latest release?

reproduced with 1.10.3

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/"
GORACE=""
GOROOT="/root/.gimme/versions/go1.10.3.linux.amd64"
GOTMPDIR=""
GOTOOLDIR="/root/.gimme/versions/go1.10.3.linux.amd64/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build325883252=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Attempting to build a java aar (for a java app) using
`gomobile bind -target android -o .aar github.com/

What did you expect to see?

Compiled aar

What did you see instead?

gomobile: go build -buildmode=c-shared -o=/tmp/gomobile-work-319151112/android/src/main/jniLibs/armeabi-v7a/libgojni.so gobind failed: exit status 2

gobind

/root/.gimme/versions/go1.10.3.linux.amd64/pkg/tool/linux_amd64/link: running /pkg/gomobile/ndk-toolchains/arm/bin/arm-linux-androideabi-clang failed: exit status 1
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000028.o: multiple definition of '_cgo_dc57271482da_Cfunc__Cmalloc'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000024.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of '_cgo_dc57271482da_Cfunc_checkException'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of '_cgo_dc57271482da_Cfunc_free'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of '_cgo_dc57271482da_Cfunc_lockJNI'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of '_cgo_dc57271482da_Cfunc_unlockJNI'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of 'checkException'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of 'lockJNI'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000029.o: multiple definition of 'unlockJNI'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000025.o: previous definition here
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/go-link-973277192/000031.o: multiple definition of '_cgo_dc57271482da_Cfunc___android_log_write'
/pkg/gomobile/ndk-toolchains/arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/go-link-973277192/000027.o: previous definition here
clang60: error: linker command failed with exit code 1 (use -v to see invocation)

using downloaded android ndk r17b & android sdk tools sdk-tools-linux-4333796 (didn't install android studio; attempting to create a command-line only docker build.

@ianlancetaylor ianlancetaylor changed the title problem with multiple definition using gobind x/mobile: problem with multiple definition using gobind Jul 9, 2018

@gopherbot gopherbot added this to the Unreleased milestone Jul 9, 2018

@gopherbot gopherbot added the mobile label Jul 9, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 9, 2018

Likely dup of #23555, which is fixed in the upcoming 1.11 release. Are you vendoring the same package with two different import paths?

@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 9, 2018

It's possible the same package is being vendored by multiple consumers, but (i don't think) on different paths. Also, the problem is not consistent. I saw the problem on windows; started clean and can build. Am now reproducing on linux.

Our source is open, should be able to reproduce with
github.com/DataDog/datadog-agent.git (clone the branch db/apk)
dep ensure
do the gomobile build.

Is there a build of 1.11 I can try?

@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 9, 2018

Retried with latest master (built from source on windows)
go version devel +2acae87416 Mon Jul 9 23:04:30 2018 +0000 windows/amd64

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\db\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\dev\go
set GOPROXY=
set GORACE=
set GOROOT=C:\devtools\Go
set GOTMPDIR=
set GOTOOLDIR=C:\devtools\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\db\AppData\Local\Temp\go-build891562430=/tmp/go-build -gno-record-gcc-switches
set VGOMODROOT=```

Same result

```gomobile bind -target android -o bin/agent/ddagent.aar github.com/DataDog/datadog-agent/cmd/agent/android
gomobile: go build -buildmode=c-shared -o=C:\Users\db\AppData\Local\Temp\gomobile-work-083067355\android\src\main\jniLibs\armeabi-v7a\libgojni.so gobind failed: exit status 2
# gobind
C:\devtools\Go\pkg\tool\windows_amd64\link.exe: running c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin\arm-linux-androideabi-clang failed: exit status 1
c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: C:\Users\db\AppData\Local\Temp\go-link-853799315\000029.o: multiple definition of 'checkException'
c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: C:\Users\db\AppData\Local\Temp\go-link-853799315\000025.o: previous definition here
c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: C:\Users\db\AppData\Local\Temp\go-link-853799315\000029.o: multiple definition of 'lockJNI'
c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: C:\Users\db\AppData\Local\Temp\go-link-853799315\000025.o: previous definition here
c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: C:\Users\db\AppData\Local\Temp\go-link-853799315\000029.o: multiple definition of 'unlockJNI'
c:\dev\go\pkg\gomobile\ndk-toolchains\arm\bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: C:\Users\db\AppData\Local\Temp\go-link-853799315\000025.o: previous definition here
clang60.exe: error: linker command failed with exit code 1 (use -v to see invocation)```
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2018

Thanks. That's not the same result. All of the _cgo_... functions dropped out. You are left with three remaining functions, which I didn't notice before since they were buried: checkException, lockJNI, and unlockJNI.

It looks like those functions are defined in the global C namespace by golang.org/x/mobile/internal/mobileinit/ctx_android.go. @eliasnaur Any idea why those C functions are marked static in that file? @derekwbrown Is there any chance you have a second copy of that ctx_android.go file somewhere in your source code?

@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 10, 2018

I don't believe so...

vendor\golang.org\x\mobile\internal\mobileinit\ctx_android.go```

I have done builds with different source branches; I've done `go clean` and `gomobile clean`; is it possible there's some other remnant around (and if so where would I look to clean it)?
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2018

My understanding is that gobind itself uses golang.org/x/mobileinternal/mobileinit, so if you are also vendoring it that may be causing the multiple definition errors.

Although, as I suggest above, the correct fix is likely to change ctx_android.go to mark the C functions as static. I would try that but I don't use x/mobile so I have no way to test it.

@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 10, 2018

Just for giggles I grepped the entire source tree; the vendored x/mobile/internal/mobileinit/ctx_android.go is the only place lockJNI is defined. They also don't appear to be marked static (unless that's hidden in cgo somewhere that I don't see .

This is the rev that Gopkg.lock indicates that I have:

[[projects]]
  branch = "master"
  name = "golang.org/x/mobile"
  packages = [
    "asset",
    "internal/mobileinit"
  ]
  revision = "6621de06e1e9d52c38a8c542770bdbeac9ecfef6"```
@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 10, 2018

I'm not sure why internal/mobileinit is explicitly vendored; the only packages I'm explicitly including is x/mobile/asset

@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 10, 2018

I was able to make it compile by declaring those 3 fns as static, locally.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 10, 2018

Change https://golang.org/cl/122897 mentions this issue: internal/mobileinit: declare C functions static

@derekwbrown

This comment has been minimized.

Copy link
Author

commented Jul 10, 2018

When is 1.11 supposed to be released; and what is the timeline for mobile? That is, when would https://golang.org/cl/122897 be merged?

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2018

CL 122897 is merged. Go 1.11 is targeted for August.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.