You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
go version go1.4beta1 linux/amd64
With some make-fu is it possible to have SWIG+CGO build a DLL out of a package. This
fixes the issue of external linking not available in Windows.
Basically, applying the following patches to SWIG does the following:
- Mark all structs as __packed__ [1]
- Bind crosscall2 and _cgo_* via DllMain (instead of extern) [2]
- Mark all wrap functions as SWIGEXPORT [3]
- Mark all the functions in the _gc.c file as dynimport name name "mylib.dll"
Once the file is generated/compiled, to get a .dll, I do the following:
- unpack the library
- repack the library minus the _wrap object file
- cc -shared the _wrap object file into a .dll (with linked needed libraries)
Everything does compile after that with no issues.
The issue is that cgo_import_dynamic doesn't properly resolve the symbol in the DLL, but
in the IAT section of the .exe file. This causes the executing program to crash.
I traced the program with IDA and confirmed that. See the thread of go-nuts with lots of
additional informations and IDA outputs [4].
I have no idea why C code using this pragma works fine, but Go code using the variable
generated to the symbol doesn't. Maybe a bug in the PE linker?
Thank you
[1] steeve/swig@e70fce1
[2] steeve/swig@27bb9bd
[3] steeve/swig@2c55397
[4] https://groups.google.com/forum/#!topic/golang-nuts/-M-8X-PLvOw
The text was updated successfully, but these errors were encountered:
>> ... The issue is that cgo_import_dynamic doesn't properly resolve the symbol in the
DLL, but in the IAT section of the .exe file. This causes the executing program to crash.
I am not clear about what you are trying to do. Please, provide a small program to
demonstrate. Something I can try here. Thank you.
Alex
I don't think that could work around the issue of not having external linking support.
If you are that familiar with internals of PE/COFF, I'd suggest you tackle the external
linking support, rather than make very complicated workaround that is not guaranteed
to work with future versions of Go.
The text was updated successfully, but these errors were encountered: