[binutils-gdb] Re: Define BFD_ASAN to detect asan

Alan Modra amodra@sourceware.org
Tue Mar 3 02:20:02 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0b58bc79598ae63a5b515ac497ade86cd671a5c3

commit 0b58bc79598ae63a5b515ac497ade86cd671a5c3
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Mar 3 12:40:18 2026 +1030

    Re: Define BFD_ASAN to detect asan
    
    Avoid a complaint from older preprocessors about a "missing binary
    operator" between an undefined __has_feature macro and its parameter.

Diff:
---
 bfd/bfd-in.h  | 12 +++++++++---
 bfd/bfd-in2.h | 12 +++++++++---
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 8650fa12d82..8fd45e82c51 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -153,10 +153,16 @@ struct orl;
 
 /* Detect whether we are compiling with -fsanitize=address.  */
 #ifndef BFD_ASAN
-# if ((defined (__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__)		\
-      || (defined __has_feature && __has_feature (address_sanitizer)))
+/* gcc.  */
+# if defined __SANITIZE_ADDRESS__
 #  define BFD_ASAN 1
-# else
+/* clang.  */
+# elif defined __has_feature
+#  if __has_feature(address_sanitizer)
+#   define BFD_ASAN 1
+#  endif
+# endif
+# ifndef BFD_ASAN
 #  define BFD_ASAN 0
 # endif
 #endif
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index cd5307beef4..7e8d0e4053e 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -160,10 +160,16 @@ struct orl;
 
 /* Detect whether we are compiling with -fsanitize=address.  */
 #ifndef BFD_ASAN
-# if ((defined (__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__)		\
-      || (defined __has_feature && __has_feature (address_sanitizer)))
+/* gcc.  */
+# if defined __SANITIZE_ADDRESS__
 #  define BFD_ASAN 1
-# else
+/* clang.  */
+# elif defined __has_feature
+#  if __has_feature(address_sanitizer)
+#   define BFD_ASAN 1
+#  endif
+# endif
+# ifndef BFD_ASAN
 #  define BFD_ASAN 0
 # endif
 #endif


More information about the Binutils-cvs mailing list