[英]GCC Address Sanitizer - blacklisting library functions (specifically boost::test)
All of my unit-test code is based around boost::test
.我所有的单元测试代码都基于
boost::test
。 I have just tried the GCC Address sanitizer and it reports some issues with boost::test:我刚刚尝试了 GCC Address sanitizer,它报告了 boost::test 的一些问题:
==25309==ERROR: AddressSanitizer: heap-use-after-free on address 0xf5801344 at pc 0x8259412 bp 0xff9966c8 sp 0xff9966bc
READ of size 4 at 0xf5801344 thread T0
#0 0x8259411 in boost::unit_test::framework::run(unsigned long, bool) ../common/lib/boost/boost/test/impl/framework.ipp:450
#1 0x82732f7 in boost::unit_test::unit_test_main(bool (*)(), int, char**) ../common/lib/boost/boost/test/impl/unit_test_main.ipp:185
#2 0x827b5a3 in main ../common/lib/boost/boost/test/unit_test.hpp:59
#3 0x213ce5 in __libc_start_main (/lib/libc.so.6+0x16ce5)
#4 0x8238680 (/home/marpashl/lte/sw/build/x86/bin/framework_unit_test+0x8238680)
I would like to hide this message (as it is for a known error in a test library) so that I only see issues within my own code.我想隐藏此消息(因为它是针对测试库中的已知错误),以便我只能看到我自己代码中的问题。
Is there a way of doing this with GCC?有没有办法用 GCC 做到这一点?
Note Compiler version GCC: /opt/gcc-x86-4.9.2/bin/c++注意编译器版本 GCC:/opt/gcc-x86-4.9.2/bin/c++
I found that with CLANG files can be blacklisted using -fsanitize-blacklist=blacklist.txt
but this is not currently available for GCC.我发现可以使用
-fsanitize-blacklist=blacklist.txt
将 CLANG 文件-fsanitize-blacklist=blacklist.txt
但这目前不适用于 GCC。
If the sanitize-blacklist is not available, but you have access to the source code, you can exclude individual functions from being sanitized using a function attribute:如果 sanitize-blacklist 不可用,但您可以访问源代码,则可以使用函数属性将单个函数排除在 sanitize 之外:
It is supported by Clang (3.3+) and GCC (4.8+). Clang (3.3+) 和 GCC (4.8+) 支持它。 You can define the following macro:
您可以定义以下宏:
#if defined(__clang__) || defined (__GNUC__)
# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
#else
# define ATTRIBUTE_NO_SANITIZE_ADDRESS
#endif
...
ATTRIBUTE_NO_SANITIZE_ADDRESS
void ThisFunctionWillNotBeInstrumented() {...}
A bit late to the party, but for what it's worth: You can also pass the blacklist file as an option via an environment variable to the sanitizer.聚会有点晚了,但它的价值是:您还可以通过环境变量将黑名单文件作为选项传递给消毒剂。 Which is useful if you do not have access to the source code eg
如果您无权访问源代码,这很有用,例如
LSAN_OPTIONS=suppressions=blacklist.txt ./unit-tests
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.