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

runtime/cgo: relocation target _InterlockedExchangeAdd not defined in Windows build. #45180

Closed
Simerax opened this issue Mar 23, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@Simerax
Copy link

Simerax commented Mar 23, 2021

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

$ go version
go version go1.16.2 windows/amd64

Does this issue reproduce with the latest release?

Yes 1.16.2

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xf\AppData\Local\go-build
set GOENV=C:\Users\xf\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\xf\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\xf\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.2
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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\xf\AppData\Local\Temp\go-build1530397974=/tmp/go-build -gno-record-gcc-switches

What did you do?

I tried to build a project.
This project was previously succesfully built in go 1.14.6 on the same machine.

The interesting thing is I then uninstalled 1.16.2 and reinstalled 1.14.6 and it compiled fine again.
I then kept 1.14.6 and installed 1.16.2 as a second version on my system following these instructions. I was then able to build it with go1.16.2.

So to me it seems like the problem is not in the go compiler itself but in something that go uses.
I found a microsoft article which states that

This function is implemented using a compiler intrinsic where possible. For more information, see the WinBase.h header file and _InterlockedExchangeAdd

Does Go implement this Function itself or does go rely on gcc?
My gcc Version is 8.3.0

I don't really know which part of the project is relying on this function and I cannot share the project source code.
If someone knows how to trigger an include of that function just tell me I'll try to build it then.

What did you expect to see?

succesful build like it was on 1.14.6

What did you see instead?

runtime/cgo(.text): relocation target _InterlockedExchangeAdd not defined

@cagedmantis cagedmantis changed the title relocation target _InterlockedExchangeAdd not defined runtime/cgo: relocation target _InterlockedExchangeAdd not defined in Windows build. Mar 25, 2021
@cagedmantis cagedmantis added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Mar 25, 2021
@cagedmantis cagedmantis added this to the Backlog milestone Mar 25, 2021
@cagedmantis
Copy link
Contributor

/cc @ianlancetaylor

@ianlancetaylor
Copy link
Contributor

Go relies on a C compiler to implement the InterlockedExchangeAdd function. This is only used by programs that use cgo, and such programs already require a C compiler anyhow.

I do not know why you only see this error in some cases.

CC @alexbrainman

@alexbrainman
Copy link
Member

I agree with @ianlancetaylor - your program must be using cgo. And cgo requires properly working C compiler - gcc. With all proper libraries installed.

Perhaps you gcc installation is broken.

Perhaps if you show your program and full error output, we could try and reproduce the error ourselves.

Thank you.

Alex

@Simerax
Copy link
Author

Simerax commented Mar 27, 2021

Like I said I cannot share the source code. It's proprietary company code.
I tested a little more the project also builds fine on 1.16.0 but still not on 1.16.2
I am unable to reproduce the error in a small example program.

I will close this now as it is very unlikely to be resolved and probably just a problem with the environment on my work machine.

@Simerax Simerax closed this as completed Mar 27, 2021
@golang golang locked and limited conversation to collaborators Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants