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/compile: '_rt0_amd64_windows_lib' is not called when linking with VS2015 #30347

Open
andreas-jonsson opened this Issue Feb 22, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@andreas-jonsson
Copy link

andreas-jonsson commented Feb 22, 2019

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

go version go1.11.5 windows/amd64

Does this issue reproduce with the latest release?

Yes (go1.11.5)

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

go env Output
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Andreas Jonsson\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Andreas Jonsson\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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\ANDREA~1\AppData\Local\Temp\go-build314745786=/tmp/go-build -gno-record-gcc-switches

What did you do?

Compile any package with -buildmode=c-archive on Windows using Go1.11.5 and TDM-GCC-64 (mingw64). Link the library with a small application using VisualStudio 2015 and call any C exported Go function in the library.

What did you expect to see?

Function should be executed just like when the application was built with Mingw.

What did you see instead?

The application deadlocks when calling the function because runtime waits for the 'runtime_init_wait' object in src\runtime\cgo\gcc_libinit_windows.c:77. It looks like _rt0_amd64_windows_lib is never called if you link with VisualStudio 2015 (I suspect later versions have the same problem)

I also noted a warning during build "main.a(go.o) : warning LNK4078: multiple '.text' sections found with different attributes (60600060)" I'm not sure if this is the cause of the issue...?

Go_minimal_c-archive.zip

@dmitshur dmitshur added this to the Go1.13 milestone Feb 22, 2019

@dmitshur dmitshur changed the title '_rt0_amd64_windows_lib' is not called when linking with VS2015 cmd/compile: '_rt0_amd64_windows_lib' is not called when linking with VS2015 Feb 22, 2019

@alexbrainman

This comment has been minimized.

Copy link
Member

alexbrainman commented Feb 26, 2019

Link the library with a small application using VisualStudio 2015

I could be wrong, but I don't think this is supported. Go only supports GCC C compiler on Windows.

Alex

@andreas-jonsson

This comment has been minimized.

Copy link
Author

andreas-jonsson commented Feb 26, 2019

Yea... That could be the case. :(

It would be interesting if we could add support for it though. Not sure how much work that would be?

I guess this issue has something to do with that the global constructor(s) in the archive is not recognized by the VS linker. Just as a test I tried to call it manually. Didn't work. :) But I'm not sure what _rt0_amd64_windows_lib expects in terms of register setup etc.

@dmitshur So perhaps this should be tagged question then? Does anyone know what it would take to make this work. (if possible even possible.)

@alexbrainman

This comment has been minimized.

Copy link
Member

alexbrainman commented Feb 26, 2019

It would be interesting if we could add support for it though. Not sure how much work that would be?

I do not know. Sorry.

There is #20982 that might be related to this.

Alex

@andreas-jonsson

This comment has been minimized.

Copy link
Author

andreas-jonsson commented Feb 26, 2019

@alexbrainman Thanks. I must have missed that one.

It is related. I did not try to use the MSVC tools to build it all but if #20982 were to be merged that would be super helpful for my case.

Thanks
/aj

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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.