How to determine if a disinfectant is being built when created with gcc 4.8?

I work on a program written in C, which I sometimes create with a sanitizer for the address, mainly for detecting errors. The program prints a banner in the magazines when it runs information such as: who created it, the branch on which it was built, the compiler, etc. I thought it would be nice to also indicate if the binary was created using sanitizer for the address. I know __has_feature (address_sanitizer) there, but this 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; } 

When building with gcc -Wall -g -fsanitize=address -o asan asan.c this gives:

 We got nothing! 

With clang -Wall -g -fsanitize=address -o asan asan.c I get:

 We has ASAN! 

Is there gcc equivalent of __has_feature?

I know that there are ways to check, for example, the huge value of VSZ for programs created with a sanitizer for the address, just wondering if there is a definition of compilation time or something like that.

+7
c gcc clang address-sanitizer
source share
1 answer

From the GCC 4.8.0 manual :

 __SANITIZE_ADDRESS__ 

This macro is defined with a value of 1 when -fsanitize=address .

+5
source share

All Articles