Skip to content

cmd/link is not working on windows/amd64 with any non-default buildmode #15497

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

Closed
akamensky opened this issue Apr 30, 2016 · 8 comments
Closed

Comments

@akamensky
Copy link

Code used for testing and reporting: https://github.com/akamensky/cgo-example

  1. What version of Go are you using (go version)?
    go version go1.6.1 windows/amd64
  2. What operating system and processor architecture are you using (go env)?
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\TEST\ClionProjects\cgo-example
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
  1. What did you do?
go tool link -o %WORK%\foo\_obj\exe\a.out.a -L %WORK% -extld=gcc -buildmode=c-archive %WORK%\foo.a
  1. What did you expect to see?
    go linker should provide usable archive
  2. What did you see instead?
C:\Users\TEST\ClionProjects\cgo-example>go tool link -o C:\tmp\1\foo\_obj\exe\a.
out.a -L C:\tmp\1 -extld=gcc -buildmode=c-archive C:\tmp\1\foo.a
invalid value "c-archive" for flag -buildmode: buildmode c-archive not supported
 on windows/amd64
@akamensky
Copy link
Author

I understand the patches for this part were already submitted as #13494 is closed now. Is there a way I can apply these specific patches on 1.6 branch or should I be building master branch (which gets a lot of errors on compilation time).

Is there any plan on moving these changes to some release as they are still unplanned and now even in 1.7.Maybe

@alexbrainman
Copy link
Member

Is there a way I can apply these specific patches on 1.6 branch or should I be building master branch

Making a patch that applies to go1.6 would be difficult. I suggest you build current master tip.

which gets a lot of errors on compilation time

It should not happen. If you see any errors, please create new issue.

Is there any plan on moving these changes to some release

The change should be part of go1.7.

Alex

@akamensky
Copy link
Author

@alexbrainman Thank you for prompt followup. Just one question though, if this is planned for 1.7, what is the timeline for 1.7 release? (I understand it is not exactly defined, but should have some ETA)

@alexbrainman
Copy link
Member

what is the timeline for 1.7 release?

Please, see https://golang.org/s/release for details.

Alex

@akamensky
Copy link
Author

akamensky commented Apr 30, 2016

I've compiled master HEAD successfully, it compiles the go part now using just go install -buildmode=c-archive foo (for the code compiled please see code linked in the issue description)

But when I try to compile resulting .a with .c file the gcc output is:

C:\Users\TEST\cgo-example>gcc -m64 -mthreads -fmessage-length=0 -Wl,-no_pie -I pkg\windows_amd64 -o test.exe bar.c pkg\windows_amd64\foo.a
pkg\windows_amd64\foo.a(go.o):(.data+0x800): undefined reference to `NtWaitForSingleObject'
pkg\windows_amd64\foo.a(go.o):(.data+0x868): undefined reference to `WSAGetOverlappedResult'
pkg\windows_amd64\foo.a(go.o):(.data+0x888): undefined reference to `timeBeginPeriod'
collect2.exe: error: ld returned 1 exit status

Not sure if this is fixable without any Go code changes.

UPDATE:
When I use correct gcc command (sigh), I still get undefined reference to error as below:

C:\Users\TEST\ClionProjects\cgo-example>gcc -m64 -mthreads -fmessage-length=0 -Wl,-no_pie -I . -o test.exe foo.a bar.c
C:\Users\TEST\AppData\Local\Temp\ccosPNEh.o:bar.c:(.text+0xe): undefined reference to `DidInitRun'
collect2.exe: error: ld returned 1 exit status

Attached is output from nm foo.a, not sure how can this be fixed on my side...

out.txt

@akamensky
Copy link
Author

Figured this out.

The issue in last comment is caused by the fact that gcc needs to be pointed to each library directly. And of course this has nothing to do with CGo.

Adding -l winmm -l ntdll -l Ws2_32 fixes the problem and lets the final executable to be compiled.

After this I can verify that compiling 'c-archive' with latest master tip code works fine.

I guess will have to use Go installation from source until 1.7 is released.

@minux
Copy link
Member

minux commented May 1, 2016 via email

@alexbrainman
Copy link
Member

@akamensky please reopen, if you think anything else to do here.

Alex

@golang golang locked and limited conversation to collaborators May 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants