解决MSVC上类似消毒剂的功能 [英] Address Sanitizer-like functionality on MSVC

查看:92
本文介绍了解决MSVC上类似消毒剂的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自Linux / gcc / clang,我发现自己在Windows / Visual Studio上工作的越来越多。

Coming from Linux/gcc/clang I find myself working more and more on Windows/Visual Studio.

我真正想念的是地址清理程序(范围检查,泄漏,免费使用后...)。我已经进行了一些研究,还尝试了一些尝试,但没有找到一个完整(功能上)且可靠的替代产品。例如,我曾经尝试过Memory.Dr,但了解到它不适用于基于Qt的程序(至少在Windows 10上不起作用)。

What I am really missing there is the address sanitizer (bounds checking, leaks, use after free,...). I've done some research and also tried a few things but haven't found a replacement that is complete (feature-wise) as well as reliable. I've tried Dr. Memory for example but learned it doesn't work for Qt-based programs (at least not on Windows 10).

那我怎么得到在Windows / MSVC上解决类似消毒剂的功能?

So how do I get address sanitizer-like functionality on Windows/MSVC?

推荐答案

至少clang的ASan和Ubsan应该可以在Windows上使用,一些限制。这些可以与使用clang-cl替代cl.exe的msvc工具链一起使用-谷歌似乎是对此进行了研究,mozilla

At least ASan and Ubsan from clang are supposed to work on Windows, with some limitations. These can be used with msvc toolchains using clang-cl as a drop-in replacement for cl.exe - google seems to be working on this, mozilla too.

问题是我知道的(这使我至今无法使用它):

Issues that I am aware of (and that keeped me from using it myself until now):


  • 与所需库的链接不是自动的。它们有两种版本,具体取决于应用程序中CRT的链接方式(/ MT表示静态CRT,/ MD表示动态CRT,后者通常在Qt中使用)。若要查找所需的链接器参数,请打开Visual Studio命令提示符,将clang bin文件夹添加到路径,然后使用clang-cl这样的详细选项编译一个简单的main.cpp(空主函数),如下所示:
    clang-cl -v / MD -fsanitize = address main.cpp
    所需的link.exe命令位于详细输出的末尾,从此处提取所需的链接库

  • linking with the required libraries is not automatic. There are two versions of them, depending on how the CRT is linked in your application ( /MT means static CRT, /MD means dynamic CRT, the latter is typically used in Qt). To find the required linker parameters, open Visual Studio command prompt, add clang bin folder to the path, and compile a simple main.cpp (empty main function) with verbose options with clang-cl like this: clang-cl -v /MD -fsanitize=address main.cpp The required link.exe command is in the end of verbose output, extract the required libs for linking from there.

仅在Windows上支持发行版

only release builds are supported on Windows

在Windows上不支持例外(请参见问题)

no support for exceptions on Windows ( see this issue)

在Windows端口上似乎没有更多的工作, wiki 例如是非常过时的(2015年的最后一次更改),所以我怀疑很多人都在高效地使用它。因此,要在网上获得其他用户的帮助可能会非常困难...

there doesn't seem to be much further work on the Windows port, the wiki e.g. is terribly outdated (last change in 2015), so I doubt that many people are using this productively. So getting help from other users online might be quite hard ...

在Windows上讨论其他替代方案时,有:

Talking about other alternatives on Windows, there are:

  • Appverifier (coming with Windows SDK)
  • Dr Memory(currently unmaintained on Windows according to some comments on its issue tracker, meaning that it's e.g. completely unusable for Qt and everybody who uses SSE 4.2 instructions, see here and here )
  • Intel Inspector (commercial).

Linux IMO上的消毒剂和Valgrind更先进和/或具有比这些工具的性能要好得多,因此保持应用程序在Linux上的构建似乎是最好的主意,至少在使用像Qt这样的跨平台工具包时(如您所提到的)。

Sanitizers and Valgrind on Linux IMO are much more advanced and/or have much better performance than these tools, so keeping an application building on Linux seems the best idea, at least when working with a cross-platform toolkit like Qt (as you are mentioning).

这篇关于解决MSVC上类似消毒剂的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆