08c3a6
commit d6a58bd81d07322ff5da8f419d8620ef037b6a36
08c3a6
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
08c3a6
Date:   Wed Jan 12 18:46:28 2022 +0530
08c3a6
08c3a6
    Enable _FORTIFY_SOURCE=3 for gcc 12 and above
08c3a6
    
08c3a6
    gcc 12 now has support for the __builtin_dynamic_object_size builtin.
08c3a6
    Adapt the macro checks to enable _FORTIFY_SOURCE=3 on gcc 12 and above.
08c3a6
    
08c3a6
    Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
08c3a6
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
08c3a6
    (cherry picked from commit 86bf0feb0e3ec8e37872f72499d6ae33406561d7)
08c3a6
08c3a6
diff --git a/include/features.h b/include/features.h
08c3a6
index d974eabfafc24ffb..933499bcff8f1449 100644
08c3a6
--- a/include/features.h
08c3a6
+++ b/include/features.h
08c3a6
@@ -412,7 +412,9 @@
08c3a6
 #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
08c3a6
 # elif !__GNUC_PREREQ (4, 1)
08c3a6
 #  warning _FORTIFY_SOURCE requires GCC 4.1 or later
08c3a6
-# elif _FORTIFY_SOURCE > 2 && __glibc_clang_prereq (9, 0)
08c3a6
+# elif _FORTIFY_SOURCE > 2 && (__glibc_clang_prereq (9, 0)		      \
08c3a6
+			       || __GNUC_PREREQ (12, 0))
08c3a6
+
08c3a6
 #  if _FORTIFY_SOURCE > 3
08c3a6
 #   warning _FORTIFY_SOURCE > 3 is treated like 3 on this platform
08c3a6
 #  endif
08c3a6
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
08c3a6
index 3bb9f38916e30295..515fb681a0547217 100644
08c3a6
--- a/misc/sys/cdefs.h
08c3a6
+++ b/misc/sys/cdefs.h
08c3a6
@@ -142,7 +142,8 @@
08c3a6
 #define __bos0(ptr) __builtin_object_size (ptr, 0)
08c3a6
 
08c3a6
 /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available.  */
08c3a6
-#if __USE_FORTIFY_LEVEL == 3 && __glibc_clang_prereq (9, 0)
08c3a6
+#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0)		      \
08c3a6
+				 || __GNUC_PREREQ (12, 0))
08c3a6
 # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
08c3a6
 # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
08c3a6
 #else