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/go: "duplicate symbol" linker error when referencing v1 and v2 of the same module and that module contains CGO #53694

Closed
dylan-bourque opened this issue Jul 5, 2022 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@dylan-bourque
Copy link

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

$ go version
go version go1..18.3 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 (slightly redacted to remove non-public information)
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dbourque/Library/Caches/go-build"
GOENV="/Users/dbourque/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/dbourque/sdk/modcache"
GOOS="darwin"
GOPATH="/Users/dbourque/dev/golang"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/dbourque/sdk/go1.18.3"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/dbourque/sdk/go1.18.3/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOWORK=""
CGO_CFLAGS=""
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="/usr/local/bin/pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3t/4048hqr5459dw83ksmkqxn7r0000gn/T/go-build3495041523=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Unfortunately, these are internal modules so I've had to obfuscate things and cannot provide a runnable example.

I'm attempting to build a module A that is referencing both v1 and v2 of another module C. A depends on C/v2 directly and C indirectly via another internal module B. C contains CGO bindings to several native functions. C/v2 contains the same CGO bindings. We created C/v2 because we needed to make breaking API changes and C was already at a stable v1.x release.

The minified dependency tree is as follows:

   /->     C/v2   \
A                  -> nativecode_mac.a
   \->  B  ->  C  /

Notably, nativecode_mac.a is intentionally identical between C and C/v2. C/v2 was created due to a change in the Go API, not the underlying native code.

What did you expect to see?

A successful build and a runnable binary.

What did you see instead?

Linker errors similar to this for each native function referenced in the CGO code

/Users/dbourque/sdk/go1.18.3/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
duplicate symbol 'C::foo::bar(unsigned long long)' in:
    /Users/dbourque/dev/golang/pkg/mod/.../C@v1.2.0/subpackage/nativecode_mac.a(instance.cpp.o)
    /Users/dbourque/dev/golang/pkg/mod/.../C/v2@v2.0.0/subpackage/nativecode_mac.a(instance.cpp.o)

This seems to be an unsupported edge case at the intersection between SIV (C and C/v2 are completely separate modules) and CGO (there can only be 1 instance of C::foo::bar(unsigned long long) in the final compiled binary).

We were able to upgrade past the problem internally because a newer release of B included updates to use C/v2, but I'm reporting this because I believe that won't work for every project.

@ianlancetaylor
Copy link
Contributor

When both C/v1 and C/v2 use go, it's possible to write them such that both versions can be used in the same project. However, it's also possible to write them such they can't both be used. I don't think there is anything that the Go tools can do to avoid this problem. Happy to hear suggestions.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 6, 2022
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants