https://gcc.gnu.org/g:45af5b62d34ced4fdfd480bbd396cf1ad4d4f464

commit r17-5399-g45af5b62d34ced4fdfd480bbd396cf1ad4d4f464
Author: Siddhesh Poyarekar <[email protected]>
Date:   Sat Oct 17 20:23:34 2026 -0400

    libssp: Support _FORTIFY_SOURCE=3 [PR109270]
    
    Add __builtin_dynamic_object support into libssp header to allow usage
    of _FORTIFY_SOURCE=3 with it.
    
    libssp/ChangeLog:
    
            PR libgcc/109270
            * ssp/ssp.h.in [_FORTIFY_SOURCE > 2]: Set __SSP_FORTIFY_LEVEL to
            3 if compiler supports __builtin_dynamic_object_size.
            [__SSP_FORTIFY_LEVEL > 2]: Use __builtin_dynamic_object_size.
    
    Signed-off-by: Siddhesh Poyarekar <[email protected]>

Diff:
---
 libssp/ssp/ssp.h.in | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/libssp/ssp/ssp.h.in b/libssp/ssp/ssp.h.in
index 0c40fd168b1a..4e29be7c3ca1 100644
--- a/libssp/ssp/ssp.h.in
+++ b/libssp/ssp/ssp.h.in
@@ -41,15 +41,30 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
     && !defined __cplusplus
 # if _FORTIFY_SOURCE == 1
 #  define __SSP_FORTIFY_LEVEL 1
-# elif _FORTIFY_SOURCE > 1
+# elif _FORTIFY_SOURCE == 2
 #  define __SSP_FORTIFY_LEVEL 2
+# elif _FORTIFY_SOURCE > 2
+#  ifdef __has_builtin
+#   if __has_builtin (__builtin_dynamic_object_size)
+#    define __SSP_FORTIFY_LEVEL 3
+#   else
+#    define __SSP_FORTIFY_LEVEL 2
+#   endif
+#  else
+#   define __SSP_FORTIFY_LEVEL 2
+#  endif
 # endif
 #endif
 
 #if __SSP_FORTIFY_LEVEL > 0
 # include <stddef.h>
-# define __ssp_bos(ptr) __builtin_object_size (ptr, __SSP_FORTIFY_LEVEL > 1)
-# define __ssp_bos0(ptr) __builtin_object_size (ptr, 0)
+# if __SSP_FORTIFY_LEVEL > 2
+#  define __ssp_bos(ptr) __builtin_dynamic_object_size (ptr, 1)
+#  define __ssp_bos0(ptr) __builtin_dynamic_object_size (ptr, 0)
+# else
+#  define __ssp_bos(ptr) __builtin_object_size (ptr, __SSP_FORTIFY_LEVEL > 1)
+#  define __ssp_bos0(ptr) __builtin_object_size (ptr, 0)
+# endif
 
 # define __SSP_REDIRECT(name, proto, alias) \
   name proto __asm__ (__SSP_ASMNAME (#alias))

Reply via email to