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/cgo: structure used when calling Go function from C is not properly packed on 32-bit Windows with recent GCC #6833

Closed
gopherbot opened this issue Nov 25, 2013 · 12 comments

Comments

@gopherbot
Copy link

commented Nov 25, 2013

by 0x6a67:

What steps will reproduce the problem?
Run simple test program  https://gist.github.com/anonymous/7644960

What is the expected output?
expected : 4000300020001007
got      : 4000300020001007

What do you see instead?
expected : 4000300020001007
got      :   12feec20001000

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g

Which operating system are you using?
Windows XP 32-bit

Which version are you using?  (run 'go version')
go version go1.2rc5 windows/386
gcc (rev0, Built by MinGW-W64 project) 4.8.2

Please provide any additional information below.
Revision ae83f4b0aa29 fixed packing of structure used when calling C function from Go
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Nov 26, 2013

Comment 1:

I don't see your problem here on windows/386:
C:\go\path\src\issue6833>go build && issue6833.exe
expected : 4000300020001007
got      : 4000300020001007
C:\go\path\src\issue6833>gcc --version
gcc (tdm-1) 4.5.2
Copyright (C) 2010 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.
Alex
@gopherbot

This comment has been minimized.

Copy link
Author

commented Nov 26, 2013

Comment 2 by 0x6a67:

Sorry for too concise report.
Problem shows up starting from gcc 4.7, see issue #5603.
@gopherbot

This comment has been minimized.

Copy link
Author

commented Nov 26, 2013

Comment 3 by salvor.public:

I can reproduce this bug using the following:
OS:  Windows 8 64-bit on Intel Core i7
Go:  go1.2rc5 windows/386
gcc: gcc (tdm-2) 4.8.1
The output I get on windows/386 is:
expected : 4000300020001007
got      :    a000920001000
I installed TDM-GCC (32-bit) from the individual .lzma files at
http://tdm-gcc.tdragon.net/download
I'll help test patches if they become available.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 4:

Labels changed: added go1.3maybe.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Nov 29, 2013

Comment 5:

Yes it is broken with gcc-4.8.1:
C:\go\path\src\issue6833>go build && issue6833.exe
expected : 4000300020001007
got      :   12feec20001000
C:\go\path\src\issue6833>gcc --version
gcc (tdm-2) 4.8.1
Copyright (C) 2013 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.
But I have no idea how to fix it.
Alex
@gopherbot

This comment has been minimized.

Copy link
Author

commented Nov 29, 2013

Comment 6 by 0x6a67:

Applying fix from revision ae83f4b0aa29 to function writeExports in src/cmd/cgo/out.go
fixes issue for me (Windows 32-bit, gcc 4.8.2).
Note that in code and comments in fuction writeExports __attribute__((packed)) is used.
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Dec 2, 2013

Comment 7:

0x6a67, like https://golang.org/cl/35790045 ?
Alex

Status changed to Started.

@gopherbot

This comment has been minimized.

Copy link
Author

commented Dec 2, 2013

Comment 8 by 0x6a67:

Patch looks good.
On 32-bit Windows XP with gcc 4.8.2 :
- ALL TESTS PASSED when building from patched source
- expected : 4000300020001007
  got      : 4000300020001007
  from original test case
Thank you.
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Dec 3, 2013

Comment 9:

Thank you. I will submit once source tree is opened for changes.
Alex
@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 10:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 11:

Labels changed: added repo-main.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Dec 10, 2013

Comment 12:

This issue was closed by revision 6795687.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.