Windows 64-bit native compile fails after 1.4.3 to 1.5.1 upgrade - Linker gives incompatible architecture error

1,025 views
Skip to first unread message

jhowa...@gmail.com

unread,
Oct 29, 2015, 4:09:49 PM10/29/15
to golang-nuts, jho...@microsoft.com

Machine: Windows 10 64-bit.

 

Go version: go version go1.5.1 windows/amd64

 

GCC version:

e:\docker\test\sql1.5.1>gcc --version

gcc (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 5.2.0

Copyright (C) 2015 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

Location of repro application: http://github.com/jhowardmsft/sql1.5.1. Source files main.go and sql1.5.1.exe.manifest are attached, as is the rsrc.syso file.


Error from compilation:

e:\docker\test\sql1.5.1>rsrc -manifest sql1.5.1.exe.manifest -o rsrc.syso

Manifest ID:  1

 

e:\docker\test\sql1.5.1>go build

# _/e_/docker/test/sql1.5.1

c:\go1.5.1\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1

C:/Program Files/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../..

/x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `C:\Users\jhoward\AppData\Local\Temp\go-link-951232423/0

00000.o' is incompatible with i386:x86-64 output

collect2.exe: error: ld returned 1 exit status

 

 

I hit this issue only when an application is using both the SQLLite driver from mattn (https://github.com/mattn/go-sqlite3) and RSRC from akavel (https://github.com/akavel/rsrc).  Using just one or just the other (eg by commenting out the import or deleting rsrc.syso), the problem is not seen.

 

RSRC is used to compile a manifest file (and in the real application, docker https://github.com/docker/docker an application icon as well) as a resource into the final binary. So I run rsrc –manifest sql1.5.1.exe.manifest –o rsrc.syso once, before running go build [optionally go build –tags “libsqlite3” for dynamic linking of SQL rather than static] on that repro.

 

 

Using dumpbin from Microsoft Visual Studio to dump the PE/COFF headers of rsrc.syso, it appears that these are valid:

E:\docker\test\sql1.5.1>dumpbin /all rsrc.syso

Microsoft (R) COFF/PE Dumper Version 14.00.23026.0

Copyright (C) Microsoft Corporation.  All rights reserved.

 

 

Dump of file rsrc.syso

 

File Type: COFF OBJECT

 

FILE HEADER VALUES

             14C machine (x86)

               1 number of sections

               0 time date stamp Wed Dec 31 16:00:00 1969

             3F4 file pointer to symbol table

               1 number of symbols

               0 size of optional header

             104 characteristics

                   Line numbers stripped

                   32 bit word machine

 

SECTION HEADER #1

   .rsrc name

       0 physical address

       0 virtual address

     3AE size of raw data

      3C file pointer to raw data (0000003C to 000003E9)

     3EA file pointer to relocation table

       0 file pointer to line numbers

       1 number of relocations

       0 number of line numbers

40000040 flags

         Initialized Data

         (no align specified)

         Read Only

 

RAW DATA #1

  00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00  ................

  00000010: 18 00 00 00 18 00 00 80 00 00 00 00 00 00 00 00  ................

  00000020: 00 00 00 00 00 00 01 00 01 00 00 00 30 00 00 80  ............0...

  00000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00  ................

  00000040: 09 04 00 00 48 00 00 00 58 00 00 00 56 03 00 00  ....H...X...V...

  00000050: 00 00 00 00 00 00 00 00 3C 3F 78 6D 6C 20 76 65  ........<?xml ve

  00000060: 72 73 69 6F 6E 3D 22 31 2E 30 22 20 65 6E 63 6F  rsion="1.0" enco

  00000070: 64 69 6E 67 3D 22 55 54 46 2D 38 22 20 73 74 61  ding="UTF-8" sta

  00000080: 6E 64 61 6C 6F 6E 65 3D 22 79 65 73 22 3F 3E 0D  ndalone="yes"?>.

  00000090: 0A 3C 61 73 73 65 6D 62 6C 79 20 78 6D 6C 6E 73  .<assembly xmlns

  000000A0: 3D 22 75 72 6E 3A 73 63 68 65 6D 61 73 2D 6D 69  ="urn:schemas-mi

  000000B0: 63 72 6F 73 6F 66 74 2D 63 6F 6D 3A 61 73 6D 2E  crosoft-com:asm.

  000000C0: 76 31 22 20 6D 61 6E 69 66 65 73 74 56 65 72 73  v1" manifestVers

  000000D0: 69 6F 6E 3D 22 31 2E 30 22 3E 0D 0A 20 20 20 20  ion="1.0">..

  000000E0: 3C 64 65 73 63 72 69 70 74 69 6F 6E 3E 44 6F 63  <description>Doc

  000000F0: 6B 65 72 3C 2F 64 65 73 63 72 69 70 74 69 6F 6E  ker</description

  00000100: 3E 0D 0A 20 20 20 20 3C 63 6F 6D 70 61 74 69 62  >..    <compatib

  00000110: 69 6C 69 74 79 20 78 6D 6C 6E 73 3D 22 75 72 6E  ility xmlns="urn

  00000120: 3A 73 63 68 65 6D 61 73 2D 6D 69 63 72 6F 73 6F  :schemas-microso

  00000130: 66 74 2D 63 6F 6D 3A 63 6F 6D 70 61 74 69 62 69  ft-com:compatibi

  00000140: 6C 69 74 79 2E 76 31 22 3E 20 0D 0A 20 20 20 20  lity.v1"> ..

  00000150: 20 20 20 20 3C 61 70 70 6C 69 63 61 74 69 6F 6E      <application

  00000160: 3E 20 0D 0A 20 20 20 20 20 20 20 20 20 20 20 20  > ..

  00000170: 3C 21 2D 2D 20 57 69 6E 64 6F 77 73 20 31 30 20  <!-- Windows 10

  00000180: 2D 2D 3E 0D 0A 20 20 20 20 20 20 20 20 20 20 20  -->..

  00000190: 20 3C 73 75 70 70 6F 72 74 65 64 4F 53 20 49 64   <supportedOS Id

  000001A0: 3D 22 7B 38 65 30 66 37 61 31 32 2D 62 66 62 33  ="{8e0f7a12-bfb3

  000001B0: 2D 34 66 65 38 2D 62 39 61 35 2D 34 38 66 64 35  -4fe8-b9a5-48fd5

  000001C0: 30 61 31 35 61 39 61 7D 22 2F 3E 0D 0A 20 20 20  0a15a9a}"/>..

  000001D0: 20 20 20 20 20 20 20 20 20 3C 21 2D 2D 20 57 69           <!-- Wi

  000001E0: 6E 64 6F 77 73 20 38 2E 31 20 2D 2D 3E 0D 0A 20  ndows 8.1 -->..

  000001F0: 20 20 20 20 20 20 20 20 20 20 20 3C 73 75 70 70             <supp

  00000200: 6F 72 74 65 64 4F 53 20 49 64 3D 22 7B 31 66 36  ortedOS Id="{1f6

  00000210: 37 36 63 37 36 2D 38 30 65 31 2D 34 32 33 39 2D  76c76-80e1-4239-

  00000220: 39 35 62 62 2D 38 33 64 30 66 36 64 30 64 61 37  95bb-83d0f6d0da7

  00000230: 38 7D 22 2F 3E 0D 0A 20 20 20 20 20 20 20 20 20  8}"/>..

  00000240: 20 20 20 3C 21 2D 2D 20 57 69 6E 64 6F 77 73 20     <!-- Windows

  00000250: 56 69 73 74 61 20 2D 2D 3E 0D 0A 20 20 20 20 20  Vista -->..

  00000260: 20 20 20 20 20 20 20 3C 73 75 70 70 6F 72 74 65         <supporte

  00000270: 64 4F 53 20 49 64 3D 22 7B 65 32 30 31 31 34 35  dOS Id="{e201145

  00000280: 37 2D 31 35 34 36 2D 34 33 63 35 2D 61 35 66 65  7-1546-43c5-a5fe

  00000290: 2D 30 30 38 64 65 65 65 33 64 33 66 30 7D 22 2F  -008deee3d3f0}"/

  000002A0: 3E 20 0D 0A 20 20 20 20 20 20 20 20 20 20 20 20  > ..

  000002B0: 3C 21 2D 2D 20 57 69 6E 64 6F 77 73 20 37 20 2D  <!-- Windows 7 -

  000002C0: 2D 3E 0D 0A 20 20 20 20 20 20 20 20 20 20 20 20  ->..

  000002D0: 3C 73 75 70 70 6F 72 74 65 64 4F 53 20 49 64 3D  <supportedOS Id=

  000002E0: 22 7B 33 35 31 33 38 62 39 61 2D 35 64 39 36 2D  "{35138b9a-5d96-

  000002F0: 34 66 62 64 2D 38 65 32 64 2D 61 32 34 34 30 32  4fbd-8e2d-a24402

  00000300: 32 35 66 39 33 61 7D 22 2F 3E 0D 0A 20 20 20 20  25f93a}"/>..

  00000310: 20 20 20 20 20 20 20 20 3C 21 2D 2D 20 57 69 6E          <!-- Win

  00000320: 64 6F 77 73 20 38 20 2D 2D 3E 0D 0A 20 20 20 20  dows 8 -->..

  00000330: 20 20 20 20 20 20 20 20 3C 73 75 70 70 6F 72 74          <support

  00000340: 65 64 4F 53 20 49 64 3D 22 7B 34 61 32 66 32 38  edOS Id="{4a2f28

  00000350: 65 33 2D 35 33 62 39 2D 34 34 34 31 2D 62 61 39  e3-53b9-4441-ba9

  00000360: 63 2D 64 36 39 64 34 61 34 61 36 65 33 38 7D 22  c-d69d4a4a6e38}"

  00000370: 2F 3E 0D 0A 20 20 20 20 20 20 20 20 3C 2F 61 70  />..        </ap

  00000380: 70 6C 69 63 61 74 69 6F 6E 3E 20 0D 0A 20 20 20  plication> ..

  00000390: 20 3C 2F 63 6F 6D 70 61 74 69 62 69 6C 69 74 79   </compatibility

  000003A0: 3E 0D 0A 3C 2F 61 73 73 65 6D 62 6C 79 3E        >..</assembly>

 

RELOCATIONS #1

                                                Symbol    Symbol

Offset    Type              Applied To         Index     Name

--------  ----------------  -----------------  --------  ------

00000048  DIR32NB                    00000058         0  .rsrc

 

COFF SYMBOL TABLE

000 00000000 SECT1  notype       Static       | .rsrc

 

String Table Size = 0x0 bytes

 

  Summary

 

         3AE .rsrc

 

I can’t dumpbin the object file generated by go build for the rest of the application (under %temp%\go-link-nnnnnnnnn\) as the go compiler cleans it up too quickly to be able to examine. But I suspect that the PE header being written by the go compiler for that object file is subtly different in 1.5.1 vs 1.4.3, and hence now incompatible with the rsrc.syso file containing the application manifest (and icon in the real-world app) files.

 

I emphasise that if I use both SQL and the rsrc.syso binary in the repro app, and compile using go 1.4.3, it works fine. It also works fine if cross-compiling from Linux (Ubuntu 14.04) to Windows 64-bit using either go 1.5.1 or 1.4.3 for cross-compile. So the issue appears unique to Windows 64 bit native compile using go 1.5.1.

 

 

 

main.go
sql1.5.1.exe.manifest
rsrc.syso

Michael Hudson-Doyle

unread,
Oct 29, 2015, 6:23:21 PM10/29/15
to jhowa...@gmail.com, golang-nuts, jho...@microsoft.com
This looks (without thinking about it at all hard) like
https://github.com/golang/go/issues/13070
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dave Cheney

unread,
Oct 29, 2015, 6:27:15 PM10/29/15
to golang-nuts
Does using -linkmode=internal improve the situation ?

jhowa...@gmail.com

unread,
Oct 29, 2015, 10:10:17 PM10/29/15
to golang-nuts
Yes! That works!!! Thanks so much :)
John.


On Thursday, October 29, 2015 at 3:27:15 PM UTC-7, Dave Cheney wrote:

ped...@cpmech.com

unread,
May 3, 2016, 6:41:25 PM5/3/16
to golang-nuts
Just wondering where can we find those options?
I'm in particular trying to find out how to link libraries in Windows (dynamic or static; whatever it works).
Currently I'm struggling with this issue: https://github.com/golang/go/issues/8756
Any help is much appreciated.
Reply all
Reply to author
Forward
0 new messages