-
Notifications
You must be signed in to change notification settings - Fork 403
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
CMake code to run ASAN for Windows tests #463
Conversation
HIDAPI_ENABLE_ASAN is no set platform independent
windows/CMakeLists.txt
Outdated
if(HIDAPI_ENABLE_ASAN) | ||
# Option /MTd needed to embedd ASAN library | ||
add_compile_options(/MTd) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: in my other project(s) I didn't it. for ASAN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static linking is not needed in general, you could als add the ASAN DLL, that comes in various flavors with VisualStudio, to your DLL search path.
But it's placed in a directory with a name like this:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x86\clang_rt.asan_dbg_dynamic-i386.dll
I'm not able to determine this path using CMake. It depends on many things like VisualStudio installation path, Visual Studio version and the build type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is rather easy to get this path:
- it is
MSVC
-specitic (so unserif(MSVC)
); - as per documentation - on MSVC the support is limited to x86 and x64 on Windows 10, so only one of two possible suffixes:
i386
orx86_64
; - the location is documented and it matches the path to
CMAKE_C_COMPILER
directory;
But in any case - I don't believe we need to handle that in our CMake. ASAN runs are designed to be executed only in development builds (e.g. no "production" scenarios).
The runtime is always available from MSVC development sonsole, so I believe that is just enough.
D:\a\hidapi\hidapi\hidapisrc\windows\hid.c : error C2220: the following warning is treated as an error D:\a\hidapi\hidapi\hidapisrc\windows\hid.c : warning C5072: ASAN enabled without debug information emission. Enable debug info for better ASAN error reporting
Agree |
So we better make RelWithDebInfo builds on CI for ASAN. I'm working in this right now. Will post an update shortly. |
This looks much better than my attemp! Works well for me on local VS2022 as on CI.
|
Hm, interesting. I haven't seen this warning locally. But I use MSVC 2019 though. With gcc this linker option even required (otherwise the ASAN library is not linked). |
As for:
I don't have a quick solution for it right now, and I'll probably keep it as is. |
Why not setting |
AFAIK MSVC compiler/linker usually complains if the same option is passed multiple times, and and I like simple/elegant solutions but OK, I'll try |
probably time to merge it, before it gets ugly again |
This PR extends the CMake lists to run ASAN address sanitzer for tests under Windows (requires Win10 or 11).