gpt4 book ai didi

c++ - GCC Address Sanitizer - 将库函数列入黑名单(特别是 boost::test)

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:01:56 25 4
gpt4 key购买 nike

我所有的单元测试代码都基于 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)

我想隐藏此消息(因为它是针对测试库中的已知错误),以便我只看到我自己代码中的问题。

有没有办法用 GCC 做到这一点?

注意编译器版本GCC:/opt/gcc-x86-4.9.2/bin/c++

我发现可以使用 -fsanitize-blacklist=blacklist.txt 将 CLANG 文件列入黑名单,但这目前不适用于 GCC。

最佳答案

如果 sanitize-blacklist 不可用,但您可以访问源代码,则可以使用函数属性排除个别函数进行清理:

Clang (3.3+) 和 GCC (4.8+) 支持它。您可以定义以下宏:

#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() {...}

参见 this page了解更多详情。

关于c++ - GCC Address Sanitizer - 将库函数列入黑名单(特别是 boost::test),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27966082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com