-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: definition of GoString is incorrect for exported functions #5548
Labels
Comments
from the go-nuts thread on the subject: if the code is modified to http://play.golang.org/p/J6fUEF4E_9, then the function works just fine, but if we replace strlen(t) on line 10 with the value it returns, 6, the resulting program crashes again. putting a panic() inside hello_from_c in main.go gives this interesting observation: with strlen(t): main.hello_from_c(0x40680b5, 0x6, 0x2a) cgotest/_obj/main.cgo1.go:17 +0x119 with "6" instead: [fp=0x41d1e30] main.hello_from_c(0x40680bd, 0x7fff00000006, 0x2a) cgotest/_obj/main.cgo1.go:16 +0xdd |
Ian Lance Taylor: I see the bug. _cgo_export.c looks like this: void hello_from_c(GoString p0, GoInt p1) { struct { GoString p0; GoInt p1; } __attribute__((packed)) a; a.p0 = p0; a.p1 = p1; crosscall2(_cgoexp_44bb5d457081_hello_from_c, &a, 24); } _cgo_export.h has this: typedef struct { char *p; int n; } GoString; This means that the generated hello_from_c code is going to convert from GoInt to int when setting the string length of p0. That will break if it so happens that the upper 32 bits of the string length are not already zero. |
Labels changed: added priority-soon, go1.1.1, removed priority-triage. Owner changed to @ianlancetaylor. Status changed to Accepted. |
https://golang.org/cl/9643044 Status changed to Started. |
This issue was closed by revision 8f7863d. Status changed to Fixed. |
Issue #5646 has been merged into this issue. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: