googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Dll unloading crashes in Windows

Open FelipeCelsoR opened this issue 2 years ago • 1 comments

I am creating this issue to talk about this similar problem described in: https://github.com/google/googletest/issues/1516.

I'm using windows 11 latest version, visual C++ compiler.

I am working in a code that consumes gmock (gtest 1.12.1 stable) to mock functions/calls, and a different test framework (that is not gtest). The tests are bundled into dlls. The dlls are unloaded right after the tests are executed, and this is triggering a crash in gtest-port.cc line 618: BAD_INSTRUCTION_PTR_c0000005.

We are consuming gtest using vcpkg in our repo, only stable releases are available, but we can use local patches to fix build issues. Unfortunately our team is not allowed to use the most recent commit of this project in our repo, so this issue might or may not be fixed yet.

When the dlls are not unloaded as cited in the reported issue, the crashes do not happen.

Is there any solution for this issue that does not involve keeping the dlls loaded?

Thanks, Celso

FelipeCelsoR avatar Dec 02 '22 23:12 FelipeCelsoR

Thanks for reporting this! Unfortunately this is not something we can provide support for. Unloading code is inherently quite an error-prone process, as many DLLs depend on global state that they have to tear down, and there isn't a good way to do that in many complex programs that depend on global state, especially in a thread-safe manner (but often even in single-threaded cases).

If you can share a small self-contained example source code for a DLL that demonstrates this error (as well as any other code needed to interact with it), I may be able to try and see if I can find a quick fix in this specific instance. But I expect it's unlikely I'll be able to, and in any case this is definitely not something we can support in an ongoing manner.

higher-performance avatar Dec 06 '22 15:12 higher-performance