[PATCH] Remove __SIZE_TYPE__ usage (BZ 33969)

Adhemerval Zanella adhemerval.zanella@linaro.org
Tue Mar 10 19:28:25 GMT 2026


It is a compiler-internal __SIZE_TYPE__ macro, and it is used
inconsistently in installed headers.

The ‘fcntl-linux.h’ and ‘cdefs.h’ changes are straightforward
because size_t is already defined.  The glob.h change uses
stddef.h as other installed headers.

In the  ’poll.h’ case, the __SIZE_TYPE__ is only used for calling
fortify headers, and adding size_t might be considered namespace
pollution (since POSIX does not require the type to be defined).
The fortify is a GNU extension, so it should be safe to add the
size_t definition.

Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.
---
 debug/poll_chk.c                           |  3 ++-
 debug/ppoll_chk.c                          |  2 +-
 io/bits/poll2.h                            | 14 ++++++++------
 misc/sys/cdefs.h                           | 14 +++++++-------
 posix/glob.h                               | 15 +++++++--------
 sysdeps/unix/sysv/linux/bits/fcntl-linux.h |  2 +-
 sysdeps/unix/sysv/linux/ppoll_chk.c        |  5 +++--
 7 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/debug/poll_chk.c b/debug/poll_chk.c
index 08a2d72b89..d93b063088 100644
--- a/debug/poll_chk.c
+++ b/debug/poll_chk.c
@@ -16,10 +16,11 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sys/poll.h>
+#include <stddef.h>
 
 
 int
-__poll_chk (struct pollfd *fds, nfds_t nfds, int timeout, __SIZE_TYPE__ fdslen)
+__poll_chk (struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen)
 {
   if (fdslen / sizeof (*fds) < nfds)
     __chk_fail ();
diff --git a/debug/ppoll_chk.c b/debug/ppoll_chk.c
index c8e727013b..a8f452a42f 100644
--- a/debug/ppoll_chk.c
+++ b/debug/ppoll_chk.c
@@ -20,7 +20,7 @@
 
 int
 __ppoll_chk (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
-	     const __sigset_t *ss, __SIZE_TYPE__ fdslen)
+	     const __sigset_t *ss, size_t fdslen)
 {
   if (fdslen / sizeof (*fds) < nfds)
     __chk_fail ();
diff --git a/io/bits/poll2.h b/io/bits/poll2.h
index 918586f95a..b0804a3e79 100644
--- a/io/bits/poll2.h
+++ b/io/bits/poll2.h
@@ -20,16 +20,18 @@
 # error "Never include <bits/poll2.h> directly; use <sys/poll.h> instead."
 #endif
 
+#define __need_size_t
+#include <stddef.h>
 
 __BEGIN_DECLS
 
 extern int __REDIRECT (__poll_alias, (struct pollfd *__fds, nfds_t __nfds,
 				      int __timeout), poll);
 extern int __poll_chk (struct pollfd *__fds, nfds_t __nfds, int __timeout,
-		       __SIZE_TYPE__ __fdslen)
+		       size_t __fdslen)
     __attr_access ((__write_only__, 1, 2));
 extern int __REDIRECT (__poll_chk_warn, (struct pollfd *__fds, nfds_t __nfds,
-					 int __timeout, __SIZE_TYPE__ __fdslen),
+					 int __timeout, size_t __fdslen),
 		       __poll_chk)
   __warnattr ("poll called with fds buffer too small file nfds entries");
 
@@ -54,12 +56,12 @@ extern int __REDIRECT (__ppoll64_alias, (struct pollfd *__fds, nfds_t __nfds,
 				       const __sigset_t *__ss), __ppoll64);
 extern int __ppoll64_chk (struct pollfd *__fds, nfds_t __nfds,
 			  const struct timespec *__timeout,
-			  const __sigset_t *__ss, __SIZE_TYPE__ __fdslen)
+			  const __sigset_t *__ss, size_t __fdslen)
     __attr_access ((__write_only__, 1, 2));
 extern int __REDIRECT (__ppoll64_chk_warn, (struct pollfd *__fds, nfds_t __n,
 					    const struct timespec *__timeout,
 					    const __sigset_t *__ss,
-					    __SIZE_TYPE__ __fdslen),
+					    size_t __fdslen),
 		       __ppoll64_chk)
   __warnattr ("ppoll called with fds buffer too small file nfds entries");
 
@@ -81,12 +83,12 @@ extern int __REDIRECT (__ppoll_alias, (struct pollfd *__fds, nfds_t __nfds,
 				       const __sigset_t *__ss), ppoll);
 extern int __ppoll_chk (struct pollfd *__fds, nfds_t __nfds,
 			const struct timespec *__timeout,
-			const __sigset_t *__ss, __SIZE_TYPE__ __fdslen)
+			const __sigset_t *__ss, size_t __fdslen)
     __attr_access ((__write_only__, 1, 2));
 extern int __REDIRECT (__ppoll_chk_warn, (struct pollfd *__fds, nfds_t __nfds,
 					  const struct timespec *__timeout,
 					  const __sigset_t *__ss,
-					  __SIZE_TYPE__ __fdslen),
+					  size_t __fdslen),
 		       __ppoll_chk)
   __warnattr ("ppoll called with fds buffer too small file nfds entries");
 
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 8d27f26da8..8d7807968f 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -180,20 +180,20 @@
 /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
    condition can be folded to a constant and if it is true, or unknown (-1) */
 #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
-  ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1)	      \
+  ((__builtin_constant_p (__osz) && (__osz) == (size_t) -1)	      \
    || (__glibc_unsigned_or_positive (__l)				      \
-       && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
+       && __builtin_constant_p (__glibc_safe_len_cond ((size_t) (__l), \
 						       (__s), (__osz)))	      \
-       && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), (__s), (__osz))))
+       && __glibc_safe_len_cond ((size_t) (__l), (__s), (__osz))))
 
 /* Conversely, we know at compile time that the length is unsafe if the
    __L * __S <= __OBJSZ condition can be folded to a constant and if it is
    false.  */
 #define __glibc_unsafe_len(__l, __s, __osz) \
   (__glibc_unsigned_or_positive (__l)					      \
-   && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l),     \
+   && __builtin_constant_p (__glibc_safe_len_cond ((size_t) (__l),     \
 						   __s, __osz))		      \
-   && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
+   && !__glibc_safe_len_cond ((size_t) (__l), __s, __osz))
 
 /* To correctly instrument the fortify wrapper clang requires the
    pass_object_size attribute, and the attribute has the restriction that the
@@ -338,7 +338,7 @@
       : __ ## f ## _chk (__VA_ARGS__, __osz)))
 #else
 # define __glibc_fortify(f, __l, __s, __osz, ...) \
-  (__osz == (__SIZE_TYPE__) -1)						      \
+  (__osz == (size_t) -1)						      \
    ? __ ## f ## _alias (__VA_ARGS__)					      \
    : __ ## f ## _chk (__VA_ARGS__, __osz)
 #endif
@@ -355,7 +355,7 @@
       : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))
 # else
 # define __glibc_fortify_n(f, __l, __s, __osz, ...) \
-  (__osz == (__SIZE_TYPE__) -1)						      \
+  (__osz == (size_t) -1)						      \
    ? __ ## f ## _alias (__VA_ARGS__)					      \
    : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))
 #endif
diff --git a/posix/glob.h b/posix/glob.h
index 4c824eb0d3..efedf7ab92 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -23,11 +23,10 @@
 __BEGIN_DECLS
 
 /* We need `size_t' for the following definitions.  */
+#define __need_size_t
+#include <stddef.h>
 #ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+typedef size_t __size_t;
 #else
 /* The GNU CC stddef.h version defines __size_t as empty.  We need a real
    definition.  */
@@ -81,9 +80,9 @@ struct stat;
 #endif
 typedef struct
   {
-    __size_t gl_pathc;		/* Count of paths matched by the pattern.  */
+    size_t gl_pathc;		/* Count of paths matched by the pattern.  */
     char **gl_pathv;		/* List of matched pathnames.  */
-    __size_t gl_offs;		/* Slots to reserve in `gl_pathv'.  */
+    size_t gl_offs;		/* Slots to reserve in `gl_pathv'.  */
     int gl_flags;		/* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
 
     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +109,9 @@ struct stat64;
 # endif
 typedef struct
   {
-    __size_t gl_pathc;
+    size_t gl_pathc;
     char **gl_pathv;
-    __size_t gl_offs;
+    size_t gl_offs;
     int gl_flags;
 
     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
index 221a71aa62..36249144e3 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
@@ -481,7 +481,7 @@ extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,
    The kernel does not support legacy non-LFS interface.  */
 extern int openat2 (int __dfd, const char * __filename,
 		    const struct open_how * __how,
-		    __SIZE_TYPE__ __usize)
+		    size_t __usize)
      __nonnull ((2, 3));
 
 #endif	/* use GNU */
diff --git a/sysdeps/unix/sysv/linux/ppoll_chk.c b/sysdeps/unix/sysv/linux/ppoll_chk.c
index 6f8d0ba08b..3879e71322 100644
--- a/sysdeps/unix/sysv/linux/ppoll_chk.c
+++ b/sysdeps/unix/sysv/linux/ppoll_chk.c
@@ -17,11 +17,12 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <poll.h>
+#include <stddef.h>
 
 int
 __ppoll64_chk (struct pollfd *fds, nfds_t nfds,
 	       const struct __timespec64 *tmo, const __sigset_t *ss,
-	       __SIZE_TYPE__ fdslen)
+	       size_t fdslen)
 {
   if (fdslen / sizeof (*fds) < nfds)
     __chk_fail ();
@@ -32,7 +33,7 @@ __ppoll64_chk (struct pollfd *fds, nfds_t nfds,
 #if __TIMESIZE != 64
 int
 __ppoll_chk (struct pollfd *fds, nfds_t nfds, const struct timespec *tmo,
-	     const __sigset_t *ss, __SIZE_TYPE__ fdslen)
+	     const __sigset_t *ss, size_t fdslen)
 {
   if (fdslen / sizeof (*fds) < nfds)
     __chk_fail ();
-- 
2.43.0



More information about the Libc-alpha mailing list