如何确定何时使用-fsanitize =内存?

时间:2016-02-27 03:10:49

标签: c macros c-preprocessor msan

我想在使用内存消毒剂时清除FD_ZEROFD_SET上的误报。清除它有点容易:

#include <sanitizer/msan_interface.h>
...

__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));

但是,我不知道如何检测内存消毒剂何时使用。也就是说,检测命令行上何时指定-fsanitize=memory。预处理器似乎没有帮助:

$ clang -dM -E -fsanitize=memory - </dev/null | egrep -i 'memory|sanitize|msan'
$

如何确定何时使用-fsanitize=memory

1 个答案:

答案 0 :(得分:1)

根据Memory Sanitizer mailing list的Konstantin Serebryany的说法,没有预处理器宏。应使用__has_feature(memory_sanitizer)

#if defined(__has_feature)
#  if __has_feature(memory_sanitizer)
#    define MEMORY_SANITIZER 1
#  endif
#endif
...

#ifdef MEMORY_SANITIZER
#  include <sanitizer/msan_interface.h>
#endif
...

#ifdef MEMORY_SANITIZER
__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));
#endif
...