Module Name: src
Committed By: christos
Date: Wed Mar 29 13:37:10 UTC 2023
Modified Files:
src/include/ssp: ssp.h
Log Message:
PR/57288: Mingye Wang: <ssp/ssp.h>: Use __builtin_dynamic_object_size
for LLVM > 9 and GCC > 12, introducing _SSP_FORTIFY_LEVEL == 3
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/include/ssp/ssp.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/include/ssp/ssp.h
diff -u src/include/ssp/ssp.h:1.13 src/include/ssp/ssp.h:1.14
--- src/include/ssp/ssp.h:1.13 Thu Sep 3 16:43:47 2015
+++ src/include/ssp/ssp.h Wed Mar 29 09:37:10 2023
@@ -1,7 +1,7 @@
-/* $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp $ */
+/* $NetBSD: ssp.h,v 1.14 2023/03/29 13:37:10 christos Exp $ */
/*-
- * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2011, 2023 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -36,7 +36,9 @@
#if !defined(__cplusplus)
# if _FORTIFY_SOURCE > 0 && !defined(__lint__) && \
(__OPTIMIZE__ > 0 || defined(__clang__)) && __GNUC_PREREQ__(4, 1)
-# if _FORTIFY_SOURCE > 1
+# if _FORTIFY_SOURCE > 2 && __has_builtin(__builtin_dynamic_object_size)
+# define __SSP_FORTIFY_LEVEL 3
+# elif _FORTIFY_SOURCE > 1
# define __SSP_FORTIFY_LEVEL 2
# else
# define __SSP_FORTIFY_LEVEL 1
@@ -58,8 +60,13 @@
#define __ssp_inline static __inline __attribute__((__always_inline__))
-#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_check(buf, len, bos) \
if (bos(buf) != (size_t)-1 && len > bos(buf)) \