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/cgo: multiple definition of `_cgo_05dc84caff82_Cfunc_sysconf' #23555

Closed
EricSites opened this issue Jan 25, 2018 · 6 comments

Comments

@EricSites
Copy link

commented Jan 25, 2018

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

go version go1.9.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/eric/dev/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build111158852=/tmp/go-build -gno-record-gcc-switches"
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"

What did you do?

go build

What did you expect to see?

Nothing

What did you see instead?

go build

github.com/dockarray1/agent

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-071896903/000008.o: In function _cgo_05dc84caff82_Cfunc_sysconf': /tmp/go-build/github.com/google/cadvisor/vendor/github.com/opencontainers/runc/libcontainer/system/_obj/cgo-gcc-prolog:32: multiple definition of _cgo_05dc84caff82_Cfunc_sysconf'
/tmp/go-link-071896903/000007.o:/tmp/go-build/github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/system/_obj/cgo-gcc-prolog:32: first defined here
collect2: error: ld returned 1 exit status

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2018

Can you give us a way to recreate the problem?

I don't see any vendor directory in github.com/google/cadvisor.

I can't clone github.com/dockarray1/agent: it says I need a username.

@EricSites

This comment has been minimized.

Copy link
Author

commented Jan 25, 2018

I will see if I can create an example:

But cadvisor vendor dir is here: https://github.com/google/cadvisor/tree/master/vendor

dockarray1/agent is an internal project that I can't share the source.

@ianlancetaylor ianlancetaylor changed the title multiple definition of `_cgo_05dc84caff82_Cfunc_sysconf' cmd/cgo: multiple definition of `_cgo_05dc84caff82_Cfunc_sysconf' Jan 25, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2018

Thanks. I think I see the problem. The cgo command uses a hash of the source files to pick a unique name for the globally visible C function. This strategy fails when the exact same package is vendored into a program in two different locations.

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Jan 25, 2018

@EricSites

This comment has been minimized.

Copy link
Author

commented Jan 25, 2018

I was not having this problem a year ago. Is there a workaround that I can use before the release of go 1.11?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2018

The workaround would be to change one of the copies. Change a file that does import "C" in any way, for example by adding a comment.

@gopherbot

This comment has been minimized.

Copy link

commented Jun 13, 2018

Change https://golang.org/cl/118739 mentions this issue: cmd/cgo: add import path to hash

@gopherbot gopherbot closed this in 3a7cbfa Jun 13, 2018

dna2github added a commit to dna2fork/go that referenced this issue Jun 14, 2018
cmd/cgo: add import path to hash
This avoids name conflicts when two identical packages use cgo.
This can happen in practice when the same package is vendored multiple
times in a single build.

Fixes golang#23555

Change-Id: I9f0ec6db9165dcf9cdf3d314c668fee8ada18f9c
Reviewed-on: https://go-review.googlesource.com/118739
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

@golang golang locked and limited conversation to collaborators Jun 13, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.