-
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: Go DLL crashes on Windows 10 #58009
Comments
It is worth mentioning that it crashes on the second time the DLL is loaded. |
Are you loading the same DLL twice in the same process? Currently, the c-shared buildmode assumes the library it produces is the only instance of the Go runtime in the process. It usually doesn't work well if there is another instance of Go runtime in the same process's address space (and this is not supported.). For the same library, it is possible that the Linux dynamic loader deduplicates all the symbols, so it ends up essentially like just a single instance. On Windows, the dynamic loader may not work this way. Could you explain why you want to load the DLL multiple times? Would it be possible not to do that? Thanks. |
Yes, it's been loaded twice but it's also been freed before loaded again. I wanted to load multiples times in order to unload inside a destructor method. I will look into the possibility of doing that. |
I'm also not sure if unloading/freeing works with Go c-shared libraries. From Go runtime's perspective we don't know if there is any dangling reference. Also, not sure unloading really gives a clean state. At least, the Go library doesn't try to clean up anything when it is unloaded. I'd suggest not unloading. Thanks. |
Freeing a Go DLL does not generally work, can confirm that. |
Duplicate of #11100 |
What version of Go are you using (
go version
)?and
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Two operating systems and same architecture.
go env
Outputand
go env
OutputWhat did you do?
Basically, a DLL is built with Go, which is filling a output buffer. DLL is loaded by C++ code. On Windows 10 it crashes and on Ubuntu 20.04 it follows the course. The Go portion of code also verifies if a file extracted by the C++ portion exists or not.
test.go
The executable (the runner) test built with C++:
test.cc
On Ubuntu 20.04 buiit it with:
make.sh
And on Windows 10 built it with:
make.sh
What did you expect to see?
I expected to see an empty output based on a
int
return of DLL exported function and a outputstring
also filled by it.What did you see instead?
Instead, I see a broken sequence os steps.
The text was updated successfully, but these errors were encountered: