Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/include/ssp PR/57288: Mingye Wang: <ssp/ssp.h>: Use __builti...



details:   https://anonhg.NetBSD.org/src/rev/c97593df2bf2
branches:  trunk
changeset: 374061:c97593df2bf2
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Mar 29 13:37:10 2023 +0000

description:
PR/57288: Mingye Wang: <ssp/ssp.h>: Use __builtin_dynamic_object_size
for LLVM > 9 and GCC > 12, introducing _SSP_FORTIFY_LEVEL == 3

diffstat:

 include/ssp/ssp.h |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (40 lines):

diff -r b4ec2c55b5f5 -r c97593df2bf2 include/ssp/ssp.h
--- a/include/ssp/ssp.h Wed Mar 29 13:07:46 2023 +0000
+++ b/include/ssp/ssp.h Wed Mar 29 13:37:10 2023 +0000
@@ -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)) \



Home | Main Index | Thread Index | Old Index