]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
text-utils: correctly detect ASan under clang
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 30 Jan 2021 12:12:42 +0000 (13:12 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 1 Feb 2021 10:59:47 +0000 (11:59 +0100)
__SANITIZE_ADDRESS__ is not defined when compiling with clang, so cover
both use cases with a special set of macros

include/c.h
include/closestream.h
text-utils/col.c

index 6b742512b3d62464ebb344ce6efaf82c623819a1..b891ad4808a31f8f4b00541b413dc87820a89a82 100644 (file)
@@ -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
index 41afbe2082a362fb5487c283297bc477d91aaf11..8e5d18d977202b96c655263aa21bbe65f67c5fc2 100644 (file)
@@ -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
 }
index f9e39a2261b1da79dcd606984b90d358b4747ef7..afea8aa62582d4239a8cb9398630ef5deedb3667 100644 (file)
@@ -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