Browse Source

text-utils: correctly detect ASan under clang

__SANITIZE_ADDRESS__ is not defined when compiling with clang, so cover
both use cases with a special set of macros
pull/1238/head
Frantisek Sumsal 2 years ago
parent
commit
c40b3cd03d
  1. 17
      include/c.h
  2. 2
      include/closestream.h
  3. 3
      text-utils/col.c

17
include/c.h

@ -411,6 +411,23 @@ static inline int xusleep(useconds_t usec)
#define stringify_value(s) stringify(s)
#define stringify(s) #s
/* Detect if we're compiled with Address Sanitizer
* - gcc (__SANITIZE_ADDRESS__)
* - clang (__has_feature(address_sanitizer))
*/
#if !defined(HAS_FEATURE_ADDRESS_SANITIZER)
# ifdef __SANITIZE_ADDRESS__
# define HAS_FEATURE_ADDRESS_SANITIZER 1
# elif defined(__has_feature)
# if __has_feature(address_sanitizer)
# define HAS_FEATURE_ADDRESS_SANITIZER 1
# endif
# endif
# if !defined(HAS_FEATURE_ADDRESS_SANITIZER)
# define HAS_FEATURE_ADDRESS_SANITIZER 0
# endif
#endif
/*
* UL_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time
* instrumentation shipped with Clang and GCC) to not instrument the

2
include/closestream.h

@ -83,7 +83,7 @@ close_stdout_atexit(void)
/*
* Note that close stdout at exit disables ASAN to report memory leaks
*/
#if !defined(__SANITIZE_ADDRESS__)
#if !HAS_FEATURE_ADDRESS_SANITIZER
atexit(close_stdout);
#endif
}

3
text-utils/col.c

@ -61,6 +61,7 @@
#include <string.h>
#include <unistd.h>
#include "c.h"
#include "closestream.h"
#include "nls.h"
#include "optutils.h"
@ -89,7 +90,7 @@
/* number of lines to allocate */
#define NALLOC 64
#if defined(__SANITIZE_ADDRESS__) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
#if HAS_FEATURE_ADDRESS_SANITIZER || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
# define COL_DEALLOCATE_ON_EXIT
#endif

Loading…
Cancel
Save