使用gcc 4.8构建时如何检测是否使用地址清理器构建? [英] How to detect if building with address sanitizer when building with gcc 4.8?
问题描述
我正在开发一个用C编写的程序,我偶尔会使用地址清理器来构建该程序,主要是为了捕获错误。该程序在启动时会在日志中显示一条横幅,其中包含以下信息:谁构建了它,构建了它的分支,编译器等。我认为如果二进制文件是使用地址清理器构建的,也可以很好地阐明它。我知道有__has_feature(address_sanitizer),但这仅适用于clang。我尝试了以下简单程序:
I'm working on a program written in C that I occasionally build with address sanitizer, basically to catch bugs. The program prints a banner in the logs when it starts up with info such as: who built it, the branch it was built on, compiler etc. I was thinking it would be nice to also spell out if the binary was built using address sanitizer. I know there's __has_feature(address_sanitizer), but that only works for clang. I tried the following simple program:
#include <stdio.h>
int main()
{
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
printf ("We has ASAN!\n");
# else
printf ("We have has_feature, no ASAN!\n");
# endif
#else
printf ("We got nothing!\n");
#endif
return 0;
}
使用 gcc建造时-gall -g -fsanitize = address -o asan asan.c
,结果为:
We got nothing!
使用 clang -Wall -g -fsanitize = address -o asan asan。 c
我得到:
We has ASAN!
是否存在与__has_feature等效的gcc?
Is there a gcc equivalent to __has_feature?
我知道有很多方法可以检查,例如使用地址清理器构建的程序的巨大VSZ值,只是想知道是否存在编译时定义或其他东西。
I know there are ways to check, like the huge VSZ value for programs built with address sanitizer, just wondering if there's a compile-time define or something.
推荐答案
__SANITIZE_ADDRESS__
定义该宏,当<$ c时值为1 $ c> -fsanitize = address 正在使用。
This macro is defined, with value 1, when -fsanitize=address
is in use.
这篇关于使用gcc 4.8构建时如何检测是否使用地址清理器构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!