-
Notifications
You must be signed in to change notification settings - Fork 17.3k
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
cgo aborts translation for unknown type pointers #126
Labels
Comments
That seems a bit kludgy - the Size is coming back as 0 on the struct, not something referencing it, and so making it a void pointer is actually technically wrong (however, for most intents and purposes, it works until you attempt to dereference it). My solution which needs to be better verified was to make it a 0 byte opaque object, but what it needs to be really is a "Unknown size" opaque object, and checks need to be made that it's never dereferenced through that unknown-size object, and that the object is never copied inside of go code. |
Agreed, cgo already renders some types using Opaque() which turns unknown types into a byte array of fixed size. Maybe we can just treat types with invalid byte sizes as 0-length byte arrays? It seems Go wouldn't be able to copy the object if this is the case. Here's a patch which works for me for when consuming libmysql. diff -r 1d9d926b1aa7 src/cmd/cgo/gcc.go --- a/src/cmd/cgo/gcc.go Thu Nov 12 23:38:48 2009 -0800 +++ b/src/cmd/cgo/gcc.go Fri Nov 13 10:01:45 2009 -0800 @@ -315,11 +315,15 @@ t.Size = dtype.Size(); t.Align = -1; t.C = dtype.Common().Name; + c.m[dtype] = t; + if t.Size < 0 { - fatal("dwarf.Type %s reports unknown size", dtype) + // Treat unsized types as [0]byte + t.Size = 0; + t.Go = c.Opaque(0); + return t; } - c.m[dtype] = t; switch dt := dtype.(type) { default: fatal("unexpected type: %s", dtype) |
Issue #161 has been merged into this issue. |
Owner changed to r...@golang.org. |
This issue was closed by revision b30f753. Status changed to Fixed. Merged into issue #-. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by eden.li:
The text was updated successfully, but these errors were encountered: