[英]How to make AddressSanitizer not check third party libraries
I am working on a C++ cmake project. 我正在从事C ++ cmake项目。 Apart from my own source code, my project uses a lot of third party libraries.
除了我自己的源代码外,我的项目还使用许多第三方库。 So, I am using shared libraries (with .so extension) which are present in /usr/local/lib and for some the code is present in /usr/local/include.
因此,我正在使用/ usr / local / lib中存在的共享库(带有.so扩展名),而对于某些代码,则存在于/ usr / local / include中。 (like I am using eigen library which is present in /usr/local/include/eigen3/).
(就像我使用的是/ usr / local / include / eigen3 /中的本征库一样)。
How can I make sure that the Address Sanitizer only checks my source code and not any standard or third party libraries ?? 如何确定Address Sanitizer仅检查我的源代码,而不检查任何标准库或第三方库?
PS : Currently, I am using Address Sanitizer like below : PS:目前,我正在使用Address Sanitizer,如下所示:
ADD_COMPILE_OPTIONS(-O0 -g -Wall -fsanitize=address -fno-omit-frame-pointer)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
And I am using gcc with version : 我在版本中使用gcc:
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609 gcc(Ubuntu 5.4.0-6ubuntu1〜16.04.10)5.4.0 20160609
AddressSanitizer works by inserting code during the compilation (with the -fsanitize=address
flag). AddressSanitizer通过在编译过程中插入代码(带有
-fsanitize=address
标志)来工作。 So most code in third party libraries your code links to will be unaffected and not checked by AddressSanitizer, as they are already built into shared library files. 因此,您的代码链接到的第三方库中的大多数代码将不会受到影响,并且不会被AddressSanitizer进行检查,因为它们已经内置在共享库文件中。 If 3rd party calls standard function (memset, etc.), it'll still be checked.
如果第三方调用标准功能(内存集等),则仍会进行检查。
Code in header files and header-only libraries such as Eigen are a special case, as all Eigen code gets directly inserted into your source files (through includes) and thus is also compiled with -fsanitize=address
. 头文件和仅头文件的库(例如Eigen)中的代码是一种特殊情况,因为所有Eigen代码都直接插入到源文件中(通过include),因此也可以使用
-fsanitize=address
编译。
As the compiler doesn't differentiate between your code and included 3rd party code, there is no way to disable sanitizers for header-only 3rd party code. 由于编译器无法区分您的代码和包含的第三方代码,因此无法禁用仅用于标头的第三方代码的清理程序。
In practice this does not usually cause any issues though. 实际上,这通常不会引起任何问题。 When using clang, you can create a sanitize-blacklist file to hide unwanted false positives (that you cannot fix upstream).
使用clang时,您可以创建一个sanitize-blacklist文件来隐藏不需要的误报(您无法在上游修复)。 Unfortunately gcc does not yet support blacklists.
不幸的是,gcc尚不支持黑名单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.