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: ld: error: duplicate symbol: display #44121

Closed
bohdantrotsenko opened this issue Feb 5, 2021 · 9 comments
Closed

x/mobile: ld: error: duplicate symbol: display #44121

bohdantrotsenko opened this issue Feb 5, 2021 · 9 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@bohdantrotsenko
Copy link

version of Go

$ go version
go version go1.15.8 darwin/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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/bohdan/Library/Caches/go-build"
GOENV="/Users/bohdan/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bohdan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/bohdan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/bohdan/bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/bohdan/bin/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/bohdan/go/src/golang.org/x/mobile/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tg/22k7pc9j2gz_pw5jnt5l4b5r0000gn/T/go-build610192896=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ go get -u golang.org/x/mobile/cmd/gomobile
# the repository in $GOHOME/src/golang.org/x/mobile is at commit e6ae53a27f4fd7cfa2943f2ae47b96cba8eb01c9
$ ANDROID_NDK_HOME=~/Library/Android/sdk/ndk/22.0.7026061 gomobile build -target android golang.org/x/mobile/example/basic

What did you expect to see?

a built apk

What did you see instead?

go mobile Output
gomobile: go build -buildmode=c-shared -o /var/folders/tg/22k7pc9j2gz_pw5jnt5l4b5r0000gn/T/gomobile-work-609980253/lib/armeabi-v7a/libbasic.so golang.org/x/mobile/example/basic failed: exit status 2
# golang.org/x/mobile/app
ld: error: duplicate symbol: display
>>> defined at android.go:38
>>>            $WORK/b023/_x001.o:(display)
>>> defined at android.go:38 (/Users/bohdan/go/src/golang.org/x/mobile/app/android.go:38)
>>>            $WORK/b023/_x002.o:(.bss+0x0)
ld: error: duplicate symbol: surface
>>> defined at android.go:39
>>>            $WORK/b023/_x001.o:(surface)
>>> defined at android.go:39 (/Users/bohdan/go/src/golang.org/x/mobile/app/android.go:39)
>>>            $WORK/b023/_x002.o:(.bss+0x4)
ld: error: duplicate symbol: display
>>> defined at android.go:38
>>>            $WORK/b023/_x001.o:(display)
>>> defined at android.c:135
>>>            $WORK/b023/_x003.o:(.bss+0xC)
ld: error: duplicate symbol: surface
>>> defined at android.go:39
>>>            $WORK/b023/_x001.o:(surface)
>>> defined at android.c:136
>>>            $WORK/b023/_x003.o:(.bss+0x10)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 5, 2021
@gopherbot gopherbot added this to the Unreleased milestone Feb 5, 2021
@bohdantrotsenko
Copy link
Author

@dmitshur can you please take a look (I see the latest commit was targeting MacOS, but for arm64; I'm on Intel).

@dmitshur
Copy link
Contributor

dmitshur commented Feb 5, 2021

Do you know if this used to work and if this is a regression, or is the first time you're trying this? Does it also happen with Go 1.15.7 (the previous minor release)?

@cagedmantis cagedmantis added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 5, 2021
@thanm
Copy link
Contributor

thanm commented Feb 5, 2021

I can reproduce this at tip with the main branch on Linux/amd64.

I think this is similar to the problem in #42655 -- the C/C++ compiler in the new NDK has changed its default from -fcommon to -fno-common , and the gomobile code needs to take this into account (either by cooking the compiler flags or adding a common attribute).

I can try to send a patch if it would help (not sure who owns gomobile).

@thanm
Copy link
Contributor

thanm commented Feb 5, 2021

See also android/ndk#1409

@thanm
Copy link
Contributor

thanm commented Feb 5, 2021

I sent https://go-review.googlesource.com/c/mobile/+/290031 with a tentative fix.

@gopherbot
Copy link

Change https://golang.org/cl/290031 mentions this issue: app: support C compiler that defaults to -fno-common

@bohdantrotsenko
Copy link
Author

I tried 1.15.7, but got what I see in the mentioned #42665

I also tried 1.16rc1 - it's just a bit longer
ANDROID_NDK_HOME=~/Library/Android/sdk/ndk/22.0.7026061 gomobile build -v -target android .                                
generated AndroidManifest.xml:


<application android:label="Basic" android:debuggable="true">
<activity android:name="org.golang.app.GoNativeActivity"
	android:label="Basic"
	android:configChanges="orientation|keyboardHidden">
	<meta-data android:name="android.app.lib_name" android:value="basic" />
	<intent-filter>
		<action android:name="android.intent.action.MAIN" />
		<category android:name="android.intent.category.LAUNCHER" />
	</intent-filter>
</activity>
</application>
internal/unsafeheader internal/race runtime/internal/sys math/bits unicode/utf8 unicode internal/cpu golang.org/x/mobile/app/internal/callfn sync/atomic golang.org/x/mobile/event/paint runtime/internal/math image/color runtime/cgo math runtime/internal/atomic internal/bytealg runtime internal/reflectlite sync internal/testlog errors sort internal/oserror io path strconv syscall bytes strings reflect bufio image internal/syscall/execenv internal/syscall/unix time image/internal/imageutil image/draw io/fs internal/poll internal/fmtsort encoding/binary os fmt golang.org/x/mobile/event/key golang.org/x/mobile/geom golang.org/x/mobile/event/lifecycle golang.org/x/mobile/event/touch log golang.org/x/mobile/exp/f32 golang.org/x/mobile/gl golang.org/x/mobile/event/size golang.org/x/mobile/internal/mobileinit golang.org/x/mobile/exp/gl/glutil golang.org/x/mobile/app golang.org/x/mobile/exp/app/debug # golang.org/x/mobile/app ld: error: duplicate symbol: display >>> defined at android.go:38 >>> $WORK/b023/_x001.o:(display) >>> defined at android.go:38 (/Users/bohdan/go/src/golang.org/x/mobile/app/android.go:38) >>> $WORK/b023/_x002.o:(.bss+0x0)

ld: error: duplicate symbol: surface

defined at android.go:39
$WORK/b023/_x001.o:(surface)
defined at android.go:39 (/Users/bohdan/go/src/golang.org/x/mobile/app/android.go:39)
$WORK/b023/_x002.o:(.bss+0x4)

ld: error: duplicate symbol: display

defined at android.go:38
$WORK/b023/_x001.o:(display)
defined at android.c:135
$WORK/b023/_x003.o:(.bss+0xC)

ld: error: duplicate symbol: surface

defined at android.go:39
$WORK/b023/_x001.o:(surface)
defined at android.c:136
$WORK/b023/_x003.o:(.bss+0x10)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gomobile: go build -v -buildmode=c-shared -o /var/folders/tg/22k7pc9j2gz_pw5jnt5l4b5r0000gn/T/gomobile-work-038330848/lib/armeabi-v7a/libbasic.so golang.org/x/mobile/example/basic failed: exit status 2

@bohdantrotsenko
Copy link
Author

bohdantrotsenko commented Feb 5, 2021

Thanks for the hint, @thanm

Good news: worked with ndk 21.4.7075529, go1.15.8
$ ANDROID_NDK_HOME=~/Library/Android/sdk/ndk/21.4.7075529 gomobile build -v -target android golang.org/x/mobile/example/basic 
generated AndroidManifest.xml:


<application android:label="Basic" android:debuggable="true">
<activity android:name="org.golang.app.GoNativeActivity"
	android:label="Basic"
	android:configChanges="orientation|keyboardHidden">
	<meta-data android:name="android.app.lib_name" android:value="basic" />
	<intent-filter>
		<action android:name="android.intent.action.MAIN" />
		<category android:name="android.intent.category.LAUNCHER" />
	</intent-filter>
</activity>
</application>
runtime/cgo golang.org/x/mobile/internal/mobileinit golang.org/x/mobile/gl golang.org/x/mobile/exp/gl/glutil golang.org/x/mobile/exp/app/debug golang.org/x/mobile/app golang.org/x/mobile/example/basic internal/cpu internal/unsafeheader internal/race unicode/utf8 math/bits runtime/internal/sys runtime/internal/atomic sync/atomic unicode golang.org/x/mobile/app/internal/callfn internal/bytealg runtime/internal/math golang.org/x/mobile/event/paint math image/color internal/testlog runtime/cgo runtime internal/reflectlite sync errors sort internal/oserror io strconv syscall bytes strings reflect bufio image internal/syscall/execenv internal/syscall/unix time image/internal/imageutil image/draw internal/poll internal/fmtsort encoding/binary os fmt golang.org/x/mobile/event/touch golang.org/x/mobile/event/lifecycle golang.org/x/mobile/event/key golang.org/x/mobile/geom log golang.org/x/mobile/exp/f32 golang.org/x/mobile/gl golang.org/x/mobile/event/size golang.org/x/mobile/internal/mobileinit golang.org/x/mobile/exp/gl/glutil golang.org/x/mobile/exp/app/debug golang.org/x/mobile/app golang.org/x/mobile/example/basic internal/unsafeheader internal/race math/bits unicode/utf8 internal/cpu sync/atomic runtime/internal/sys unicode runtime/internal/atomic golang.org/x/mobile/app/internal/callfn golang.org/x/mobile/event/paint image/color math internal/testlog runtime/internal/math internal/bytealg runtime/cgo runtime internal/reflectlite sync errors sort internal/oserror io strconv syscall bytes strings reflect bufio image internal/syscall/execenv internal/syscall/unix time image/internal/imageutil image/draw internal/poll os internal/fmtsort encoding/binary fmt golang.org/x/mobile/event/touch golang.org/x/mobile/geom golang.org/x/mobile/event/key golang.org/x/mobile/event/lifecycle log golang.org/x/mobile/exp/f32 golang.org/x/mobile/gl golang.org/x/mobile/event/size golang.org/x/mobile/internal/mobileinit golang.org/x/mobile/exp/gl/glutil golang.org/x/mobile/exp/app/debug golang.org/x/mobile/app golang.org/x/mobile/example/basic unicode/utf8 math/bits internal/unsafeheader runtime/internal/sys internal/race sync/atomic internal/cpu runtime/internal/atomic unicode golang.org/x/mobile/app/internal/callfn runtime/internal/math golang.org/x/mobile/event/paint image/color internal/testlog runtime/cgo internal/bytealg math runtime internal/reflectlite sync errors sort internal/oserror io strconv syscall bytes strings reflect bufio image internal/syscall/execenv internal/syscall/unix time image/internal/imageutil image/draw internal/poll internal/fmtsort encoding/binary os fmt golang.org/x/mobile/geom golang.org/x/mobile/event/lifecycle golang.org/x/mobile/event/touch log golang.org/x/mobile/event/key golang.org/x/mobile/exp/f32 golang.org/x/mobile/gl golang.org/x/mobile/event/size golang.org/x/mobile/internal/mobileinit golang.org/x/mobile/exp/gl/glutil golang.org/x/mobile/exp/app/debug golang.org/x/mobile/app golang.org/x/mobile/example/basic apk: classes.dex apk: lib/armeabi-v7a/libbasic.so apk: lib/arm64-v8a/libbasic.so apk: lib/x86/libbasic.so apk: lib/x86_64/libbasic.so apk: AndroidManifest.xml

Resulting basic.apk runs successfully on Android 10 (with a warning at start: "this app was built for an earlier version of Android", but that's at least something I can start with).

gopherbot pushed a commit to golang/mobile that referenced this issue Feb 8, 2021
For the Android NDK, between r21 and r22 the NDK compiler switched the
default from "-fcommon" to "-fno-common", which causes duplicate
definitions when building the examples given the current C code. To
fix things, rework the C code to insure that we have a single
definition and an "extern" reference to the objects in question.

Updates golang/go#44121.

Change-Id: If198d5cfd977a7cfd1a37652d3a1916d8c8dbcb7
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/290031
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Than McIntosh <thanm@google.com>
@thanm
Copy link
Contributor

thanm commented Feb 8, 2021

This should be fixed now on tip. Please reopen if not.

@thanm thanm closed this as completed Feb 8, 2021
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
For the Android NDK, between r21 and r22 the NDK compiler switched the
default from "-fcommon" to "-fno-common", which causes duplicate
definitions when building the examples given the current C code. To
fix things, rework the C code to insure that we have a single
definition and an "extern" reference to the objects in question.

Updates golang/go#44121.

Change-Id: If198d5cfd977a7cfd1a37652d3a1916d8c8dbcb7
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/290031
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Than McIntosh <thanm@google.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
For the Android NDK, between r21 and r22 the NDK compiler switched the
default from "-fcommon" to "-fno-common", which causes duplicate
definitions when building the examples given the current C code. To
fix things, rework the C code to insure that we have a single
definition and an "extern" reference to the objects in question.

Updates golang/go#44121.

Change-Id: If198d5cfd977a7cfd1a37652d3a1916d8c8dbcb7
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/290031
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Than McIntosh <thanm@google.com>
@golang golang locked and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants