Define BFD_ASAN to detect asan avoid memory leaks
Alan Modra
amodra@gmail.com
Tue Mar 3 02:19:24 GMT 2026
Avoid a complaint from older preprocessors about a "missing binary
operator" between an undefined __has_feature macro and its parameter.
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
--
Alan Modra
More information about the Binutils
mailing list