-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: statically compiling windows/amd64 binary on linux fails on 1.5 #13070
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
Comments
Also this is go 1.5.1 |
Two questions
|
well its weird because the |
so from what I can tell for 32bit |
Still, /tmp/go-link-623415307/000000.o, which I think is a file produced by cgo, seems to be 32 bit when it needs to be 64-bit. Can you run go build -x and stick the output in a gist? |
will do! also this is the docs for mingw http://sourceforge.net/p/mingw-w64/wiki2/Cross%20Win32%20and%20Win64%20compiler/#building-binutils-cross-toolchain |
FWIW this is the output with go 1.4.3 https://gist.github.com/anonymous/5c991873a89319fc958f |
Hm, well one thing that's iirc changed is that there is external linking support for windows now. Can you try adding -v to -ldflags? And maybe -linkmode=internal too? |
That would explain it. The previous 1.4 behaviour is "schmeh, i'll ignore your suggestion for linking and do it myself". |
yay that works omg thanks for the speedy help \o/ |
This still looks like a bug in something or other, fwiw: external linking should work when cross compiling. |
@jfrazelle could you run |
totally will do! On Tue, Oct 27, 2015 at 6:52 PM, Dave Cheney [email protected]
Jessie Frazelle |
this is probably a dumb question but it is deleting that file before i can run file on it... is there something i need to pass?? |
-work On Wed, 28 Oct 2015, 13:13 Jess Frazelle [email protected] wrote:
|
wow i swear i knew that :shame: |
so its still deleting it but keeping the |
add -tmpdir /home/goobjs or something like that to -ldflags (after creating the directory!) |
|
Ain't nobody gonna have time to link that! On Wed, 28 Oct 2015, 13:40 Jess Frazelle [email protected] wrote:
|
Lol I was thinking I have no idea what this means |
I'm wondering if that .o is corrupt. On Wed, 28 Oct 2015, 14:21 Jess Frazelle [email protected] wrote:
|
Could you please make that 00000.o available somewhere so that i can take a
look? Thanks.
|
uploaded to https://s3.j3ss.co/tmp/linker-artifacts.tar.gz On Wed, Oct 28, 2015 at 12:14 PM, Minux Ma [email protected] wrote:
Jessie Frazelle |
Your object file has 1 section (.rsrc) with some resources (icons, bitmaps and similar) in it:
Alex |
If I use simple "go build" command on a simple cgo program, I can see completely different output{
That is all on Windows with whatever version of mingw I have. Alex |
Ya sorry the rsrc tool has an issue filed I guess akavel/rsrc#11 |
We embed an image we can probably remove it ... windows... cute whale but idk if worth the trouble ;) |
@jfrazelle Ah, we can't remove the use of akavel/rsrc as it's also the thing that manifests docker.exe for Windows 10, otherwise version APIs don't work. (PS We hit the same thing - I emailed golang-nuts: https://groups.google.com/forum/#!topic/golang-nuts/pZB_QQQk2Z4) |
@jhowardmsft go1.5 started using external linker on windows. I suspect some functionality we had with internal linker is broken. For example we cannot include dwarf information anymore (see issue #10776). It sounds like we don't link *.syso files properly either. What others said, you can use -linkmode=internal ldflag when building executable. This should revert your build process to what 1.4 use to do. Alex |
@alexbrainman Yes, thank you so much. That's great - I can compile again using 1.5.1 with that workaround on Windows. |
I am pretty sure the problem is akavel/rsrc/issues/11 (hopefully @akavel will fix the issue). Alex |
The rsrc tool seems to use an old trick:
the internal linker doesn't check the file
architecture, so it's possible to link 32-bit
COFF object files into 64-bit programs.
so I think the rsrc tool only creates a 32-bit
syso file to embed the resources, and it
worked fine with internal linking (and prior
to Go 1.5, Go on windows only supports
internal linking). This is safe as the COFF
file contains only resource, not any code.
Now that Go 1.5 supports external linking,
and it uses external linking for any code
that uses cgo, this problem manifests itself.
Before akavel/rsrc#11 is fixed, I suggest
you use a proper tool to generate two
syso files, one for 32-bit and one for 64-bit
and bundle them with docker.
|
If I change rsrc to make 2 .syso files, one for 32-bit and one for 64-bit ARCH, (how) can I then tell the go tool which one of them it should choose for linking? Would naming them foo_amd64.syso and foo_386.syso work? I understand this is not assumed to be a regression; given that, has it now become impossible to have a project with a COFF .syso file be go-gettable on any ARCH? or if it is, how? I'd be grateful for any help here! |
I was thinking about this over the weekend. Building both .syso files would be problematic for linking as obviously only one file is needed. Perhaps an |
@jhowardmsft Yeah, that's what I'll try to do as a quick workaround (?) but the problem is, such a project becomes then somewhat strongly tied to exactly 1 architecture (amd64 in this case), making it significantly more annoying to build on e.g. 386, or potentially some, uhm, Windows RT? or some other arm stuff in the future? Raspberry Pi maybe? As another workaround, I'm thinking if maybe doing something like shown below might maybe work (? untested), but boy is it ugly:
|
Oh yuck! ;) Yeah, that is kind of horrible. I am wondering if that would work unless rsrc.syso had an rsrc_ARCH.syso name. Does go use that as a build tag on an _ARCH postfix for syso files? I'm really not sure if it does or not. |
I think the GOOS_GOARCH naming convention works for syso files too (it's On 3 November 2015 at 07:03, Mateusz Czapliński [email protected]
|
Yeah, build two files
rsrc_windows_amd64.syso
rsrc_windows_386.syso
The linker will pick the right one to link automatically.
|
Previously on go 1.4.3 this used to work:
Now when trying to run the same thing I get:
That's a super gross command I know, but I can make a small go program and try to compile statically for windows on linux and see the same thing.
The text was updated successfully, but these errors were encountered: