6ca6e8
commit c5c792092b57687ae3ebecbe8645fa71ddb19f8c
6ca6e8
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
6ca6e8
Date:   Thu Feb 2 07:49:02 2023 -0500
6ca6e8
6ca6e8
    cdefs: Limit definition of fortification macros
6ca6e8
    
6ca6e8
    Define the __glibc_fortify and other macros only when __FORTIFY_LEVEL >
6ca6e8
    0.  This has the effect of not defining these macros on older C90
6ca6e8
    compilers that do not have support for variable length argument lists.
6ca6e8
    
6ca6e8
    Also trim off the trailing backslashes from the definition of
6ca6e8
    __glibc_fortify and __glibc_fortify_n macros.
6ca6e8
    
6ca6e8
    Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
6ca6e8
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
6ca6e8
    (cherry picked from commit 2337e04e21ba6040926ec871e403533f77043c40)
6ca6e8
6ca6e8
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
6ca6e8
index b166f3d209fe361f..92dbd3e1fc68dae7 100644
6ca6e8
--- a/misc/sys/cdefs.h
6ca6e8
+++ b/misc/sys/cdefs.h
6ca6e8
@@ -151,6 +151,7 @@
6ca6e8
 # define __glibc_objsize(__o) __bos (__o)
6ca6e8
 #endif
6ca6e8
 
6ca6e8
+#if __USE_FORTIFY_LEVEL > 0
6ca6e8
 /* Compile time conditions to choose between the regular, _chk and _chk_warn
6ca6e8
    variants.  These conditions should get evaluated to constant and optimized
6ca6e8
    away.  */
6ca6e8
@@ -186,7 +187,7 @@
6ca6e8
    ? __ ## f ## _alias (__VA_ARGS__)					      \
6ca6e8
    : (__glibc_unsafe_len (__l, __s, __osz)				      \
6ca6e8
       ? __ ## f ## _chk_warn (__VA_ARGS__, __osz)			      \
6ca6e8
-      : __ ## f ## _chk (__VA_ARGS__, __osz)))			      \
6ca6e8
+      : __ ## f ## _chk (__VA_ARGS__, __osz)))
6ca6e8
 
6ca6e8
 /* Fortify function f, where object size argument passed to f is the number of
6ca6e8
    elements and not total size.  */
6ca6e8
@@ -196,7 +197,8 @@
6ca6e8
    ? __ ## f ## _alias (__VA_ARGS__)					      \
6ca6e8
    : (__glibc_unsafe_len (__l, __s, __osz)				      \
6ca6e8
       ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s))		      \
6ca6e8
-      : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))		      \
6ca6e8
+      : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))
6ca6e8
+#endif
6ca6e8
 
6ca6e8
 #if __GNUC_PREREQ (4,3)
6ca6e8
 # define __warnattr(msg) __attribute__((__warning__ (msg)))