Access violation on Winlibs MinGW-w64 Clang on Windows
novoseiversia opened this issue · comments
Doctest version: 2.4.11
OS: Windows 10 N LTSC 21H2 x64
Compiler: Winlibs MinGW-w64 Clang 17.0.6 (posix threads)
Hello, I've encountered a problem while trying to build a test with Clang. The program immediately terminates with an access violation:
Loaded 'D:\Users\novoseiversia\Desktop\source\repo\novoseiversia\piece-of-shit\build\test\piece-of-shit-test.exe'.
Loaded 'C:\Windows\System32\ntdll.dll'.
Loaded 'C:\Windows\System32\kernel32.dll'.
Loaded 'C:\Windows\System32\KernelBase.dll'.
Loaded 'C:\Windows\System32\ucrtbase.dll'.
Loaded 'C:\apps\winlibs-mingw-w64-ucrt-11.0.1-r5\bin\libgcc_s_seh-1.dll'.
Loaded 'C:\apps\winlibs-mingw-w64-ucrt-11.0.1-r5\bin\libstdc++-6.dll'. Module was built without symbols.
Loaded 'C:\apps\winlibs-mingw-w64-ucrt-11.0.1-r5\bin\libwinpthread-1.dll'. Module was built without symbols.
Exception thrown at 0x00007FF7A680B1E5 in piece-of-shit-test.exe: 0xC0000005: Access violation writing location 0x00000238105C3728.
Doctest compiles fine on Winlibs MinGW-w64 GCC 13.2.0 (posix threads) and MSVC latest.
I'm not sure what the exact problem is (GDB is not catching any of the breakpoints I've set in the doctest.h), but I've found a similar problem with an open pull request: #560.
Attached are my buildsystem files and the test source file.
Can you compile a simple example without doctest with clang? I don't think it's related to doctest...
Also I love that your test is called piece-of-shit-test
:D
A simple hello world program does compile and run successfully with Clang.
Also piece-of-shit
is the name of the project hehe
I didn't notice this before but building using Clang requires target_link_libraries(... Threads::Threads)
otherwise I get a bunch of undefined reference errors:
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/bin/ld: CMakeFiles\xxinit-test.dir/objects.a(main.cxx.obj): in function `__gthread_mutex_init_function(long long*)':
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/include/c++/13.2.0/x86_64-w64-mingw32/bits/gthr-default.h:733:(.text+0xfc31): undefined reference to `pthread_mutex_init'
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/bin/ld: CMakeFiles\xxinit-test.dir/objects.a(main.cxx.obj): in function `__gthread_mutex_lock(long long*)':
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/include/c++/13.2.0/x86_64-w64-mingw32/bits/gthr-default.h:749:(.text+0x101ed): undefined reference to `pthread_mutex_lock'
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/bin/ld: CMakeFiles\xxinit-test.dir/objects.a(main.cxx.obj): in function `__gthread_mutex_unlock(long long*)':
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/include/c++/13.2.0/x86_64-w64-mingw32/bits/gthr-default.h:779:(.text+0x102dd): undefined reference to `pthread_mutex_unlock'
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/bin/ld: CMakeFiles\xxinit-test.dir/objects.a(main.cxx.obj): in function `__gthread_mutex_destroy(long long*)':
[build] C:/apps/winlibs-mingw-w64-ucrt-11.0.1-r5/include/c++/13.2.0/x86_64-w64-mingw32/bits/gthr-default.h:740:(.text+0x10aed): undefined reference to `pthread_mutex_destroy'
This doesn't happen with the simple hello world program, only with doctest.
Try #define DOCTEST_CONFIG_NO_MULTITHREADING
before including the header or adding it as a define through CMake - that might help - link to docs
That worked, thanks! Now I've got to figure out what the problem is with threads on Clang lol
I assume that if you make a minimal example that uses atomics or anything related to threads (but without doctest included at all) that you'd have problems compiling that as well - so I'm closing this issue
Ah, I forgot to close the issue, thanks.