public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 15/25] Don’t rely on stddef.h or stdarg.h for individual type definitions.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (5 preceding siblings ...)
  2019-06-26 17:50 ` [PATCH 12/25] Don’t include sys/cdefs.h directly from public headers Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-06-26 18:06 ` [PATCH 22/25] Minimize includes of unrelated public headers by networking headers Zack Weinberg
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

In the course of developing earlier patches in this series I
discovered that clang’s stddef.h does not implement the __need_*
convention correctly: in C++, under some circumstances __need_NULL
will also cause a definition of nullptr_t, and when the “modules”
feature is enabled, all of the __need macros are ignored and all of
stddef.h is exposed.  (I’m not sure how to actually make either of
these things happen, I discovered the problem by reading the file.)

Worse, clang’s stdarg.h does not implement __need___va_list *at all*;
including its stdarg.h will always expose all of its definitions.

These are bugs in clang but it seems prudent to work around them, and
the simplest way to do so is to have the bits/types/ headers
introduced in the previous patch make definitions themselves, when
possible.  For size_t, ptrdiff_t, and wchar_t, we can use the
predefined macros __SIZE_TYPE__, __PTRDIFF_TYPE__, and __WCHAR_TYPE__,
when available, falling back to the old approach.  For __gnuc_va_list,
we have a whitelist of compilers known to provide __builtin_va_list,
falling back to the old approach.  NULL and va_list are defined
ab initio.

An additional complication is that we must be able to tell stddef.h
and stdarg.h _not_ to define again things we have already defined.  It
appears to me, based on inspection of clang, GCC, and icc stddef.h and
stdarg.h, that we can use the macros _SIZE_T, _PTRDIFF_T, _WCHAR_T,
_VA_LIST, and __GNUC_VA_LIST to accomplish this.

Since we are no longer relying on stdarg.h to define an
implementation-namespace alias for us, I thought it would make sense
also to stop calling it __gnuc_va_list.  The bulk of this patch is
a mechanical substitution of __va_list for __gnuc_va_list throughout
our headers.

Copyright boilerplate is added to stdlib/bits/NULL.h and stdlib/bits/types/*.h
because they now contain enough commentary and code that they could
plausibly be copyrightable.

	* stdlib/bits/NULL.h: Do not use stddef.h to define NULL.
	Define NULL ab initio if not already defined, as `((void *)0)` for C,
	and either `__null` or 0 for C++, depending on compiler support.

	* stdlib/bits/types/__va_list.h: If __builtin_va_list is known to
	be available, use it to define __va_list without including
	stdarg.h.  Otherwise use __need___va_list to request a definition
	of __gnuc_va_list and nothing else from stdarg.h, then use that to
	define __va_list.
	* stdlib/bits/types/va_list.h: Use __va_list, not __gnuc_va_list,
	to define va_list.  Improve commentary.

	* stdlib/bits/types/ptrdiff_t.h: If __PTRDIFF_TYPE__ is defined,
	use it to define ptrdiff_t without including stddef.h.  Otherwise
	use __need_ptrdiff_t to request a definition of ptrdiff_t and
	nothing else from stddef.h.  Use _PTRDIFF_T as guard macro to
	match behavior of common stddef.h implementations.
	* stdlib/bits/types/size_t.h: Similarly for size_t, with
	__SIZE_TYPE__, __need_size_t, and _SIZE_T.
	* stdlib/bits/types/wchar_t.h: Similarly for wchar_t, with
	__WCHAR_TYPE__, __need_wchar_t, and _WCHAR_T.  If __cplusplus
	is defined, do nothing; wchar_t is built-in in C++.

	* conform/data/stdio.h-data, conform/data/wchar.h-data
	* include/err.h, include/stdio.h, include/syslog.h, include/wchar.h
	* libio/bits/stdio.h, libio/bits/stdio2.h, libio/iolibio.h
	* libio/libio.h, libio/stdio.h, libio/vwprintf.c, misc/bits/syslog.h
	* misc/err.c, misc/err.h, misc/syslog.h, stdio-common/printf.h
	* sysdeps/ieee754/ldbl-opt/nldbl-compat.c
	* sysdeps/ieee754/ldbl-opt/nldbl-compat.h
	* wcsmbs/bits/wchar2.h, wcsmbs/wchar.h:
	Replace all uses of __gnuc_va_list with __va_list.

        * scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
        bits/NULL.h is no longer allowed to include stddef.h.
---
 conform/data/stdio.h-data               |  2 +-
 conform/data/wchar.h-data               | 12 ++---
 include/err.h                           |  6 +--
 include/stdio.h                         | 30 ++++++-------
 include/syslog.h                        |  2 +-
 include/wchar.h                         | 14 +++---
 libio/bits/stdio.h                      |  2 +-
 libio/bits/stdio2.h                     | 28 ++++++------
 libio/iolibio.h                         |  2 +-
 libio/libio.h                           |  4 +-
 libio/stdio.h                           | 33 +++++++-------
 libio/vwprintf.c                        |  2 +-
 misc/bits/syslog.h                      |  4 +-
 misc/err.c                              | 12 ++---
 misc/err.h                              |  8 ++--
 misc/syslog.h                           |  2 +-
 scripts/check-obsolete-constructs.py    |  1 -
 stdio-common/printf.h                   |  2 +-
 stdlib/bits/NULL.h                      | 55 +++++++++++++++++++----
 stdlib/bits/types/__va_list.h           | 48 +++++++++++++++++---
 stdlib/bits/types/ptrdiff_t.h           | 54 ++++++++++++++++++----
 stdlib/bits/types/size_t.h              | 54 ++++++++++++++++++----
 stdlib/bits/types/va_list.h             | 31 ++++++++++---
 stdlib/bits/types/wchar_t.h             | 59 +++++++++++++++++++++----
 sysdeps/ieee754/ldbl-opt/nldbl-compat.c |  8 ++--
 sysdeps/ieee754/ldbl-opt/nldbl-compat.h | 16 +++----
 wcsmbs/bits/wchar2.h                    | 14 +++---
 wcsmbs/wchar.h                          | 24 +++++-----
 28 files changed, 367 insertions(+), 162 deletions(-)
 rewrite stdlib/bits/NULL.h (93%)
 rewrite stdlib/bits/types/ptrdiff_t.h (92%)
 rewrite stdlib/bits/types/size_t.h (93%)
 rewrite stdlib/bits/types/wchar_t.h (93%)

diff --git a/conform/data/stdio.h-data b/conform/data/stdio.h-data
index 3ef2460661..60ebea4ee4 100644
--- a/conform/data/stdio.h-data
+++ b/conform/data/stdio.h-data
@@ -41,7 +41,7 @@ type fpos_t
 #if !defined ISO && !defined ISO99 && !defined ISO11 && !defined POSIX
 type va_list
 #else
-#define va_list __gnuc_va_list
+#define va_list __va_list
 #endif
 type size_t
 #if defined XOPEN2K8 || defined POSIX2008
diff --git a/conform/data/wchar.h-data b/conform/data/wchar.h-data
index e414651a33..424c59c819 100644
--- a/conform/data/wchar.h-data
+++ b/conform/data/wchar.h-data
@@ -59,17 +59,17 @@ function wint_t towlower (wint_t)
 function wint_t towupper (wint_t)
 # endif
 function wint_t ungetwc (wint_t, FILE*)
-function int vfwprintf (FILE*, const wchar_t*, __gnuc_va_list)
+function int vfwprintf (FILE*, const wchar_t*, __va_list)
 # ifndef UNIX98
-function int vfwscanf (FILE*, const wchar_t*, __gnuc_va_list)
+function int vfwscanf (FILE*, const wchar_t*, __va_list)
 # endif
-function int vwprintf (const wchar_t*, __gnuc_va_list)
+function int vwprintf (const wchar_t*, __va_list)
 # ifndef UNIX98
-function int vwscanf (const wchar_t*, __gnuc_va_list)
+function int vwscanf (const wchar_t*, __va_list)
 # endif
-function int vswprintf (wchar_t*, size_t, const wchar_t*, __gnuc_va_list)
+function int vswprintf (wchar_t*, size_t, const wchar_t*, __va_list)
 # ifndef UNIX98
-function int vswscanf (const wchar_t*, const wchar_t*, __gnuc_va_list)
+function int vswscanf (const wchar_t*, const wchar_t*, __va_list)
 # endif
 # if defined XOPEN2K8 || defined POSIX2008
 function {wchar_t*} wcpcpy (wchar_t*, const wchar_t*)
diff --git a/include/err.h b/include/err.h
index 7c05cd1dbb..573a0f8ef2 100644
--- a/include/err.h
+++ b/include/err.h
@@ -3,12 +3,10 @@
 
 /* Prototypes for internal err.h functions.  */
 void
-__vwarnx_internal (const char *format, __gnuc_va_list ap,
-		   unsigned int mode_flags);
+__vwarnx_internal (const char *format, __va_list ap, unsigned int mode_flags);
 
 void
-__vwarn_internal (const char *format, __gnuc_va_list ap,
-		   unsigned int mode_flags);
+__vwarn_internal (const char *format, __va_list ap, unsigned int mode_flags);
 
 # ifndef _ISOMAC
 
diff --git a/include/stdio.h b/include/stdio.h
index c72d410013..b25ab6293a 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -16,40 +16,39 @@ extern int __snprintf (char *__restrict __s, size_t __maxlen,
 libc_hidden_proto (__snprintf)
 extern int __vfscanf (FILE *__restrict __s,
 		      const char *__restrict __format,
-		      __gnuc_va_list __arg)
+		      __va_list __arg)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 libc_hidden_proto (__vfscanf)
-extern int __vscanf (const char *__restrict __format,
-		     __gnuc_va_list __arg)
+extern int __vscanf (const char *__restrict __format, __va_list __arg)
      __attribute__ ((__format__ (__scanf__, 1, 0)));
 extern __ssize_t __getline (char **__lineptr, size_t *__n,
                             FILE *__stream) attribute_hidden;
 extern int __vsscanf (const char *__restrict __s,
 		      const char *__restrict __format,
-		      __gnuc_va_list __arg)
+		      __va_list __arg)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 
 extern int __sprintf_chk (char *, int, size_t, const char *, ...) __THROW;
 extern int __snprintf_chk (char *, size_t, int, size_t, const char *, ...)
      __THROW;
 extern int __vsprintf_chk (char *, int, size_t, const char *,
-			   __gnuc_va_list) __THROW;
+			   __va_list) __THROW;
 extern int __vsnprintf_chk (char *, size_t, int, size_t, const char *,
-			    __gnuc_va_list) __THROW;
+			    __va_list) __THROW;
 extern int __printf_chk (int, const char *, ...);
 extern int __fprintf_chk (FILE *, int, const char *, ...);
-extern int __vprintf_chk (int, const char *, __gnuc_va_list);
-extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_va_list);
+extern int __vprintf_chk (int, const char *, __va_list);
+extern int __vfprintf_chk (FILE *, int, const char *, __va_list);
 extern char *__fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp);
 extern char *__fgets_chk (char *buf, size_t size, int n, FILE *fp);
 extern int __asprintf_chk (char **, int, const char *, ...) __THROW;
-extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW;
+extern int __vasprintf_chk (char **, int, const char *, __va_list) __THROW;
 extern int __dprintf_chk (int, int, const char *, ...);
-extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list);
+extern int __vdprintf_chk (int, int, const char *, __va_list);
 extern int __obstack_printf_chk (struct obstack *, int, const char *, ...)
      __THROW;
 extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
-				  __gnuc_va_list) __THROW;
+				  __va_list) __THROW;
 
 extern int __isoc99_fscanf (FILE *__restrict __stream,
 			    const char *__restrict __format, ...) __wur;
@@ -58,12 +57,12 @@ extern int __isoc99_sscanf (const char *__restrict __s,
 			    const char *__restrict __format, ...) __THROW;
 extern int __isoc99_vfscanf (FILE *__restrict __s,
 			     const char *__restrict __format,
-			     __gnuc_va_list __arg) __wur;
+			     __va_list __arg) __wur;
 extern int __isoc99_vscanf (const char *__restrict __format,
-			    __gnuc_va_list __arg) __wur;
+			    __va_list __arg) __wur;
 extern int __isoc99_vsscanf (const char *__restrict __s,
 			     const char *__restrict __format,
-			     __gnuc_va_list __arg) __THROW;
+			     __va_list __arg) __THROW;
 libc_hidden_proto (__isoc99_sscanf)
 libc_hidden_proto (__isoc99_vsscanf)
 libc_hidden_proto (__isoc99_vfscanf)
@@ -132,8 +131,7 @@ extern int __fxprintf (FILE *__fp, const char *__fmt, ...)
      __attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
 extern int __fxprintf_nocancel (FILE *__fp, const char *__fmt, ...)
      __attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
-int __vfxprintf (FILE *__fp, const char *__fmt, __gnuc_va_list,
-		 unsigned int)
+int __vfxprintf (FILE *__fp, const char *__fmt, __va_list, unsigned int)
   attribute_hidden;
 
 /* Read the next line from FP into BUFFER, of LENGTH bytes.  LINE will
diff --git a/include/syslog.h b/include/syslog.h
index 5dc6e76b7e..cd8b6b876b 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -6,7 +6,7 @@ libc_hidden_proto (syslog)
 
 /* __vsyslog_internal uses the same mode_flags bits as
    __v*printf_internal; see libio/libioP.h.  */
-extern void __vsyslog_internal (int pri, const char *fmt, __gnuc_va_list ap,
+extern void __vsyslog_internal (int pri, const char *fmt, __va_list ap,
 				unsigned int mode_flags)
      attribute_hidden
      __attribute__ ((__format__ (__printf__, 2, 0)));
diff --git a/include/wchar.h b/include/wchar.h
index 2cb44954fc..823685326e 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -206,7 +206,7 @@ extern wchar_t *__wmemset_chk (wchar_t *__s, wchar_t __c, size_t __n,
 
 extern int __vfwscanf (__FILE *__restrict __s,
 		       const wchar_t *__restrict __format,
-		       __gnuc_va_list __arg)
+		       __va_list __arg)
      attribute_hidden
      /* __attribute__ ((__format__ (__wscanf__, 2, 0)) */;
 extern int __fwprintf (__FILE *__restrict __s,
@@ -215,12 +215,12 @@ extern int __fwprintf (__FILE *__restrict __s,
      /* __attribute__ ((__format__ (__wprintf__, 2, 3))) */;
 extern int __vfwprintf_chk (FILE *__restrict __s, int __flag,
 			    const wchar_t *__restrict __format,
-			    __gnuc_va_list __arg)
+			    __va_list __arg)
      /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
 extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n,
 			    int __flag, size_t __s_len,
 			    const wchar_t *__restrict __format,
-			    __gnuc_va_list __arg)
+			    __va_list __arg)
      /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */;
 
 extern int __isoc99_fwscanf (__FILE *__restrict __stream,
@@ -231,15 +231,15 @@ extern int __isoc99_swscanf (const wchar_t *__restrict __s,
      __THROW;
 extern int __isoc99_vfwscanf (__FILE *__restrict __s,
 			      const wchar_t *__restrict __format,
-			      __gnuc_va_list __arg);
+			      __va_list __arg);
 extern int __isoc99_vwscanf (const wchar_t *__restrict __format,
-			     __gnuc_va_list __arg);
+			     __va_list __arg);
 extern int __isoc99_vswscanf (const wchar_t *__restrict __s,
 			      const wchar_t *__restrict __format,
-			      __gnuc_va_list __arg) __THROW;
+			      __va_list __arg) __THROW;
 extern int __vswscanf (const wchar_t *__restrict __s,
 		       const wchar_t *__restrict __format,
-		       __gnuc_va_list __arg) __THROW;
+		       __va_list __arg) __THROW;
 libc_hidden_proto (__isoc99_vswscanf)
 libc_hidden_proto (__vswscanf)
 libc_hidden_proto (__isoc99_vfwscanf)
diff --git a/libio/bits/stdio.h b/libio/bits/stdio.h
index 2efa0c5c6b..cdefaf9804 100644
--- a/libio/bits/stdio.h
+++ b/libio/bits/stdio.h
@@ -36,7 +36,7 @@
 # if !(__USE_FORTIFY_LEVEL > 0 && defined __fortify_function)
 /* Write formatted output to stdout from argument list ARG.  */
 __STDIO_INLINE int
-vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
+vprintf (const char *__restrict __fmt, __va_list __arg)
 {
   return vfprintf (stdout, __fmt, __arg);
 }
diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h
index d1456f9927..6068f67f5c 100644
--- a/libio/bits/stdio2.h
+++ b/libio/bits/stdio2.h
@@ -27,7 +27,7 @@ extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen,
 			  const char *__restrict __format, ...) __THROW;
 extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen,
 			   const char *__restrict __format,
-			   __gnuc_va_list __ap) __THROW;
+			   __va_list __ap) __THROW;
 
 #ifdef __va_arg_pack
 __fortify_function int
@@ -44,7 +44,7 @@ __NTH (sprintf (char *__restrict __s, const char *__restrict __fmt, ...))
 
 __fortify_function int
 __NTH (vsprintf (char *__restrict __s, const char *__restrict __fmt,
-		 __gnuc_va_list __ap))
+		 __va_list __ap))
 {
   return __builtin___vsprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
 				   __bos (__s), __fmt, __ap);
@@ -57,7 +57,7 @@ extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag,
 			   ...) __THROW;
 extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag,
 			    size_t __slen, const char *__restrict __format,
-			    __gnuc_va_list __ap) __THROW;
+			    __va_list __ap) __THROW;
 
 # ifdef __va_arg_pack
 __fortify_function int
@@ -75,7 +75,7 @@ __NTH (snprintf (char *__restrict __s, size_t __n,
 
 __fortify_function int
 __NTH (vsnprintf (char *__restrict __s, size_t __n,
-		  const char *__restrict __fmt, __gnuc_va_list __ap))
+		  const char *__restrict __fmt, __va_list __ap))
 {
   return __builtin___vsnprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
 				    __bos (__s), __fmt, __ap);
@@ -89,9 +89,9 @@ extern int __fprintf_chk (FILE *__restrict __stream, int __flag,
 			  const char *__restrict __format, ...);
 extern int __printf_chk (int __flag, const char *__restrict __format, ...);
 extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
-			   const char *__restrict __format, __gnuc_va_list __ap);
+			   const char *__restrict __format, __va_list __ap);
 extern int __vprintf_chk (int __flag, const char *__restrict __format,
-			  __gnuc_va_list __ap);
+			  __va_list __ap);
 
 # ifdef __va_arg_pack
 __fortify_function int
@@ -114,7 +114,7 @@ printf (const char *__restrict __fmt, ...)
 # endif
 
 __fortify_function int
-vprintf (const char *__restrict __fmt, __gnuc_va_list __ap)
+vprintf (const char *__restrict __fmt, __va_list __ap)
 {
 #ifdef __USE_EXTERN_INLINES
   return __vfprintf_chk (stdout, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
@@ -125,7 +125,7 @@ vprintf (const char *__restrict __fmt, __gnuc_va_list __ap)
 
 __fortify_function int
 vfprintf (FILE *__restrict __stream,
-	  const char *__restrict __fmt, __gnuc_va_list __ap)
+	  const char *__restrict __fmt, __va_list __ap)
 {
   return __vfprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
@@ -134,7 +134,7 @@ vfprintf (FILE *__restrict __stream,
 extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
 			  ...) __attribute__ ((__format__ (__printf__, 3, 4)));
 extern int __vdprintf_chk (int __fd, int __flag,
-			   const char *__restrict __fmt, __gnuc_va_list __arg)
+			   const char *__restrict __fmt, __va_list __arg)
      __attribute__ ((__format__ (__printf__, 3, 0)));
 
 #  ifdef __va_arg_pack
@@ -150,7 +150,7 @@ dprintf (int __fd, const char *__restrict __fmt, ...)
 #  endif
 
 __fortify_function int
-vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __ap)
+vdprintf (int __fd, const char *__restrict __fmt, __va_list __ap)
 {
   return __vdprintf_chk (__fd, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
@@ -162,7 +162,7 @@ extern int __asprintf_chk (char **__restrict __ptr, int __flag,
 			   const char *__restrict __fmt, ...)
      __THROW __attribute__ ((__format__ (__printf__, 3, 4))) __wur;
 extern int __vasprintf_chk (char **__restrict __ptr, int __flag,
-			    const char *__restrict __fmt, __gnuc_va_list __arg)
+			    const char *__restrict __fmt, __va_list __arg)
      __THROW __attribute__ ((__format__ (__printf__, 3, 0))) __wur;
 extern int __obstack_printf_chk (struct obstack *__restrict __obstack,
 				 int __flag, const char *__restrict __format,
@@ -171,7 +171,7 @@ extern int __obstack_printf_chk (struct obstack *__restrict __obstack,
 extern int __obstack_vprintf_chk (struct obstack *__restrict __obstack,
 				  int __flag,
 				  const char *__restrict __format,
-				  __gnuc_va_list __args)
+				  __va_list __args)
      __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
 
 #  ifdef __va_arg_pack
@@ -208,14 +208,14 @@ __NTH (obstack_printf (struct obstack *__restrict __obstack,
 
 __fortify_function int
 __NTH (vasprintf (char **__restrict __ptr, const char *__restrict __fmt,
-		  __gnuc_va_list __ap))
+		  __va_list __ap))
 {
   return __vasprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
 
 __fortify_function int
 __NTH (obstack_vprintf (struct obstack *__restrict __obstack,
-			const char *__restrict __fmt, __gnuc_va_list __ap))
+			const char *__restrict __fmt, __va_list __ap))
 {
   return __obstack_vprintf_chk (__obstack, __USE_FORTIFY_LEVEL - 1, __fmt,
 				__ap);
diff --git a/libio/iolibio.h b/libio/iolibio.h
index 9561833655..d956c01630 100644
--- a/libio/iolibio.h
+++ b/libio/iolibio.h
@@ -50,7 +50,7 @@ libc_hidden_proto (_IO_setvbuf)
 extern int _IO_sscanf (const char*, const char*, ...) __THROW;
 extern int _IO_sprintf (char *, const char*, ...) __THROW;
 extern int _IO_ungetc (int, FILE*) __THROW;
-extern int _IO_vsscanf (const char *, const char *, __gnuc_va_list) __THROW;
+extern int _IO_vsscanf (const char *, const char *, __va_list) __THROW;
 
 #define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
 #define _IO_fseek(__fp, __offset, __whence) \
diff --git a/libio/libio.h b/libio/libio.h
index 96fa1062f2..3903097448 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -216,7 +216,7 @@ extern int _IO_ftrylockfile (FILE *) __THROW;
   (((_fp)->_flags2 & _IO_FLAGS2_NEED_LOCK) != 0)
 
 extern int _IO_vfscanf (FILE * __restrict, const char * __restrict,
-			__gnuc_va_list, int *__restrict);
+			__va_list, int *__restrict);
 extern __ssize_t _IO_padn (FILE *, int, __ssize_t);
 extern size_t _IO_sgetn (FILE *, void *, size_t);
 
@@ -257,7 +257,7 @@ weak_extern (_IO_stdin_used);
      __result; })
 
 extern int _IO_vfwscanf (FILE * __restrict, const wchar_t * __restrict,
-			 __gnuc_va_list, int *__restrict);
+			 __va_list, int *__restrict);
 extern __ssize_t _IO_wpadn (FILE *, wint_t, __ssize_t);
 extern void _IO_free_wbackup_area (FILE *) __THROW;
 
diff --git a/libio/stdio.h b/libio/stdio.h
index 275091e416..734fa07008 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -317,15 +317,15 @@ extern int sprintf (char *__restrict __s,
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
-		     __gnuc_va_list __arg);
+		     __va_list __arg);
 /* Write formatted output to stdout from argument list ARG.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
-extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
+extern int vprintf (const char *__restrict __format, __va_list __arg);
 /* Write formatted output to S from argument list ARG.  */
 extern int vsprintf (char *__restrict __s, const char *__restrict __format,
-		     __gnuc_va_list __arg) __THROWNL;
+		     __va_list __arg) __THROWNL;
 
 #if defined __USE_ISOC99 || defined __USE_UNIX98
 /* Maximum chars of output to write in MAXLEN.  */
@@ -334,7 +334,7 @@ extern int snprintf (char *__restrict __s, size_t __maxlen,
      __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
 
 extern int vsnprintf (char *__restrict __s, size_t __maxlen,
-		      const char *__restrict __format, __gnuc_va_list __arg)
+		      const char *__restrict __format, __va_list __arg)
      __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
 #endif
 
@@ -342,7 +342,7 @@ extern int vsnprintf (char *__restrict __s, size_t __maxlen,
 /* Write formatted output to a string dynamically allocated with `malloc'.
    Store the address of the string in *PTR.  */
 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
-		      __gnuc_va_list __arg)
+		      __va_list __arg)
      __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
 extern int __asprintf (char **__restrict __ptr,
 		       const char *__restrict __fmt, ...)
@@ -354,8 +354,7 @@ extern int asprintf (char **__restrict __ptr,
 
 #ifdef __USE_XOPEN2K8
 /* Write formatted output to a file descriptor.  */
-extern int vdprintf (int __fd, const char *__restrict __fmt,
-		     __gnuc_va_list __arg)
+extern int vdprintf (int __fd, const char *__restrict __fmt, __va_list __arg)
      __attribute__ ((__format__ (__printf__, 2, 0)));
 extern int dprintf (int __fd, const char *__restrict __fmt, ...)
      __attribute__ ((__format__ (__printf__, 2, 3)));
@@ -408,19 +407,19 @@ extern int __isoc99_sscanf (const char *__restrict __s,
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
-		    __gnuc_va_list __arg)
+		    __va_list __arg)
      __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
 
 /* Read formatted input from stdin into argument list ARG.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
-extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
+extern int vscanf (const char *__restrict __format, __va_list __arg)
      __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
 
 /* Read formatted input from S into argument list ARG.  */
 extern int vsscanf (const char *__restrict __s,
-		    const char *__restrict __format, __gnuc_va_list __arg)
+		    const char *__restrict __format, __va_list __arg)
      __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
 
 /* Same redirection as above for the v*scanf family.  */
@@ -428,26 +427,26 @@ extern int vsscanf (const char *__restrict __s,
 #  if defined __REDIRECT && !defined __LDBL_COMPAT
 extern int __REDIRECT (vfscanf,
 		       (FILE *__restrict __s,
-			const char *__restrict __format, __gnuc_va_list __arg),
+			const char *__restrict __format, __va_list __arg),
 		       __isoc99_vfscanf)
      __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
 extern int __REDIRECT (vscanf, (const char *__restrict __format,
-				__gnuc_va_list __arg), __isoc99_vscanf)
+				__va_list __arg), __isoc99_vscanf)
      __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
 extern int __REDIRECT_NTH (vsscanf,
 			   (const char *__restrict __s,
 			    const char *__restrict __format,
-			    __gnuc_va_list __arg), __isoc99_vsscanf)
+			    __va_list __arg), __isoc99_vsscanf)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 #  elif !defined __REDIRECT
 extern int __isoc99_vfscanf (FILE *__restrict __s,
 			     const char *__restrict __format,
-			     __gnuc_va_list __arg) __wur;
+			     __va_list __arg) __wur;
 extern int __isoc99_vscanf (const char *__restrict __format,
-			    __gnuc_va_list __arg) __wur;
+			    __va_list __arg) __wur;
 extern int __isoc99_vsscanf (const char *__restrict __s,
 			     const char *__restrict __format,
-			     __gnuc_va_list __arg) __THROW;
+			     __va_list __arg) __THROW;
 #   define vfscanf __isoc99_vfscanf
 #   define vscanf __isoc99_vscanf
 #   define vsscanf __isoc99_vsscanf
@@ -806,7 +805,7 @@ extern int obstack_printf (struct obstack *__restrict __obstack,
      __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
 extern int obstack_vprintf (struct obstack *__restrict __obstack,
 			    const char *__restrict __format,
-			    __gnuc_va_list __args)
+			    __va_list __args)
      __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
 #endif /* Use GNU.  */
 
diff --git a/libio/vwprintf.c b/libio/vwprintf.c
index 96c597de02..35e5ca6a23 100644
--- a/libio/vwprintf.c
+++ b/libio/vwprintf.c
@@ -23,7 +23,7 @@
 /* Write formatted output to stdout according to the
    format string FORMAT, using the argument list in ARG.  */
 int
-__vwprintf (const wchar_t *format, __gnuc_va_list arg)
+__vwprintf (const wchar_t *format, __va_list arg)
 {
   return __vfwprintf_internal (stdout, format, arg, 0);
 }
diff --git a/misc/bits/syslog.h b/misc/bits/syslog.h
index e796955c1c..67e50cd4d0 100644
--- a/misc/bits/syslog.h
+++ b/misc/bits/syslog.h
@@ -41,11 +41,11 @@ syslog (int __pri, const char *__fmt, ...)
 
 #ifdef __USE_MISC
 extern void __vsyslog_chk (int __pri, int __flag, const char *__fmt,
-			   __gnuc_va_list __ap)
+			   __va_list __ap)
      __attribute__ ((__format__ (__printf__, 3, 0)));
 
 __fortify_function void
-vsyslog (int __pri, const char *__fmt, __gnuc_va_list __ap)
+vsyslog (int __pri, const char *__fmt, __va_list __ap)
 {
   __vsyslog_chk (__pri,  __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
diff --git a/misc/err.c b/misc/err.c
index 988ec8f3ee..b9eabb7285 100644
--- a/misc/err.c
+++ b/misc/err.c
@@ -38,7 +38,7 @@ extern char *__progname;
 }
 
 void
-__vwarnx_internal (const char *format, __gnuc_va_list ap,
+__vwarnx_internal (const char *format, __va_list ap,
 		   unsigned int mode_flags)
 {
   flockfile (stderr);
@@ -50,7 +50,7 @@ __vwarnx_internal (const char *format, __gnuc_va_list ap,
 }
 
 void
-__vwarn_internal (const char *format, __gnuc_va_list ap,
+__vwarn_internal (const char *format, __va_list ap,
 		   unsigned int mode_flags)
 {
   int error = errno;
@@ -72,14 +72,14 @@ __vwarn_internal (const char *format, __gnuc_va_list ap,
 }
 
 void
-vwarn (const char *format, __gnuc_va_list ap)
+vwarn (const char *format, __va_list ap)
 {
   __vwarn_internal (format, ap, 0);
 }
 libc_hidden_def (vwarn)
 
 void
-vwarnx (const char *format, __gnuc_va_list ap)
+vwarnx (const char *format, __va_list ap)
 {
   __vwarnx_internal (format, ap, 0);
 }
@@ -100,7 +100,7 @@ warnx (const char *format, ...)
 libc_hidden_def (warnx)
 
 void
-verr (int status, const char *format, __gnuc_va_list ap)
+verr (int status, const char *format, __va_list ap)
 {
   vwarn (format, ap);
   exit (status);
@@ -108,7 +108,7 @@ verr (int status, const char *format, __gnuc_va_list ap)
 libc_hidden_def (verr)
 
 void
-verrx (int status, const char *format, __gnuc_va_list ap)
+verrx (int status, const char *format, __va_list ap)
 {
   vwarnx (format, ap);
   exit (status);
diff --git a/misc/err.h b/misc/err.h
index 2d12cbe68c..153bc112d9 100644
--- a/misc/err.h
+++ b/misc/err.h
@@ -29,23 +29,23 @@ __BEGIN_DECLS
    and a newline, on stderr.  */
 extern void warn (const char *__format, ...)
      __attribute__ ((__format__ (__printf__, 1, 2)));
-extern void vwarn (const char *__format, __gnuc_va_list)
+extern void vwarn (const char *__format, __va_list)
      __attribute__ ((__format__ (__printf__, 1, 0)));
 
 /* Likewise, but without ": " and the standard error string.  */
 extern void warnx (const char *__format, ...)
      __attribute__ ((__format__ (__printf__, 1, 2)));
-extern void vwarnx (const char *__format, __gnuc_va_list)
+extern void vwarnx (const char *__format, __va_list)
      __attribute__ ((__format__ (__printf__, 1, 0)));
 
 /* Likewise, and then exit with STATUS.  */
 extern void err (int __status, const char *__format, ...)
      __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)));
-extern void verr (int __status, const char *__format, __gnuc_va_list)
+extern void verr (int __status, const char *__format, __va_list)
      __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0)));
 extern void errx (int __status, const char *__format, ...)
      __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)));
-extern void verrx (int __status, const char *, __gnuc_va_list)
+extern void verrx (int __status, const char *, __va_list)
      __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0)));
 
 #ifdef __LDBL_COMPAT
diff --git a/misc/syslog.h b/misc/syslog.h
index f7b7a6743f..f7a980bd74 100644
--- a/misc/syslog.h
+++ b/misc/syslog.h
@@ -196,7 +196,7 @@ extern void syslog (int __pri, const char *__fmt, ...)
    cancellation point.  But due to similarity with an POSIX interface
    or due to the implementation it is a cancellation point and
    therefore not marked with __THROW.  */
-extern void vsyslog (int __pri, const char *__fmt, __gnuc_va_list __ap)
+extern void vsyslog (int __pri, const char *__fmt, __va_list __ap)
      __attribute__ ((__format__ (__printf__, 2, 0)));
 #endif
 
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 5cd3867be1..e95e587d3e 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -692,7 +692,6 @@ HEADER_ALLOWED_INCLUDES = {
     "bits/types/ptrdiff_t.h":      [ "stddef.h" ],
     "bits/types/size_t.h":         [ "stddef.h" ],
     "bits/types/wchar_t.h":        [ "stddef.h" ],
-    "bits/NULL.h":                 [ "stddef.h" ],
 }
 
 # As above, but each group of whitelist entries is only used for
diff --git a/stdio-common/printf.h b/stdio-common/printf.h
index 69c9691720..5e0d30dee9 100644
--- a/stdio-common/printf.h
+++ b/stdio-common/printf.h
@@ -86,7 +86,7 @@ typedef int printf_arginfo_function (const struct printf_info *__info,
 
 /* Type of a function to get a value of a user-defined from the
    variable argument list.  */
-typedef void printf_va_arg_function (void *__mem, __gnuc_va_list *__ap);
+typedef void printf_va_arg_function (void *__mem, __va_list *__ap);
 
 
 /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
diff --git a/stdlib/bits/NULL.h b/stdlib/bits/NULL.h
dissimilarity index 93%
index 79285bd7b2..96b75565a1 100644
--- a/stdlib/bits/NULL.h
+++ b/stdlib/bits/NULL.h
@@ -?,? +1,47 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* There is no consensus among compilers as to the proper guard macro
+   for having defined NULL specifically ... except NULL itself.  */
+#ifndef NULL
+
+/* In C, ((void *)0) is the preferred choice for the expansion of
+   NULL, as it cannot be misinterpreted as an integer zero.  */
+#ifndef __cplusplus
+# define NULL ((void *)0)
+
+/* ((void *)0) cannot be used in C++.  In C++2011 and later, nullptr
+   is the preferred alternative, but programs are to be encouraged to
+   migrate away from both bare 0 and NULL to nullptr, so we do not
+   define NULL as nullptr.  Some compilers support an extension
+   keyword __null that will trigger diagnostics when used in a context
+   that expects an integer, but will also be treated as 0 for purposes
+   of diagnostics encouraging migration to nullptr.
+
+   The complexity of this #if is because clang++ always pretends to be
+   G++ and may also pretend to be one of several different Windows
+   compilers.  */
+#elif (defined __GNUG__ || defined __clang__) \
+  && !defined _MSC_VER && !defined __MINGW32__
+# define NULL __null
+
+/* Otherwise a bare 0 will have to do.  */
+#else
+# define NULL 0
+#endif
+
+#endif
diff --git a/stdlib/bits/types/__va_list.h b/stdlib/bits/types/__va_list.h
index e3c53c3e05..ac5ab40fd3 100644
--- a/stdlib/bits/types/__va_list.h
+++ b/stdlib/bits/types/__va_list.h
@@ -1,9 +1,47 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
 #ifndef ____va_list_defined
-#define ____va_list_defined 1
 
-/* We rely on the compiler's stdarg.h to define __gnuc_va_list for us.  */
-#define __need___va_list
-#include <stdarg.h>
-#undef __need___va_list
+/* If __builtin_va_list is available, use it.  There is no predefined
+   macro advertising the availability of this type.  It is known to be
+   available in GCC 3.0 and later.  It is also known to be available
+   in all released versions of clang.  */
+#if defined __clang__ || (defined __GNUC__ && __GNUC__ >= 3)
 
+typedef __builtin_va_list __va_list;
+
+#else
+
+/* Depending on the compiler, we may be able to persuade its stdarg.h
+   to define an implementation-namespace alias for va_list and nothing
+   else.  If this feature is not available, exposing everything
+   defined by stdarg.h is better than not defining __va_list at all.  */
+# define __need___va_list
+# include <stdarg.h>
+# undef __need___va_list
+
+# ifdef __GNUC_VA_LIST
+typedef __gnuc_va_list __va_list;
+# else
+typedef va_list __va_list;
+# endif
+#endif
+
+/* This must not be defined until _after_ possibly including stdarg.h.  */
+#define ____va_list_defined 1
 #endif
diff --git a/stdlib/bits/types/ptrdiff_t.h b/stdlib/bits/types/ptrdiff_t.h
dissimilarity index 92%
index 23a8b986d5..a1cb9d985a 100644
--- a/stdlib/bits/types/ptrdiff_t.h
+++ b/stdlib/bits/types/ptrdiff_t.h
@@ -?,? +1,45 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* The guard macro for this header must match the guard macro used by
+   the compiler's stddef.h for ptrdiff_t specifically.
+   GCC's stddef.h checks a long list of other macros as well as this
+   one, in order to accommodate many different C libraries, but clang's
+   stddef.h only looks for this macro.  Other compilers can reasonably
+   be expected to look for this macro as well.  */
+#ifndef _PTRDIFF_T
+
+#ifdef __PTRDIFF_TYPE__
+
+/* If the predefined macro __PTRDIFF_TYPE__ is available, use it.  */
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+#else
+
+/* Depending on the compiler, we may be able to persuade its stddef.h
+   to define ptrdiff_t and nothing else.  If this feature is not
+   available, exposing everything defined by stddef.h is better than
+   not defining ptrdiff_t at all.  */
+# define __need_ptrdiff_t
+# include <stddef.h>
+# undef __need_ptrdiff_t
+
+#endif
+
+/* This must not be defined until _after_ possibly including stddef.h.  */
+#define _PTRDIFF_T
+#endif
diff --git a/stdlib/bits/types/size_t.h b/stdlib/bits/types/size_t.h
dissimilarity index 93%
index e151458eb3..827ede397c 100644
--- a/stdlib/bits/types/size_t.h
+++ b/stdlib/bits/types/size_t.h
@@ -?,? +1,45 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* The guard macro for this header must match the guard macro used by
+   the compiler's stddef.h for size_t specifically.
+   GCC's stddef.h checks a long list of other macros as well as this
+   one, in order to accommodate many different C libraries, but clang's
+   stddef.h only looks for this macro.  Other compilers can reasonably
+   be expected to look for this macro as well.  */
+#ifndef _SIZE_T
+
+#ifdef __SIZE_TYPE__
+
+/* If the predefined macro __SIZE_TYPE__ is available, use it.  */
+typedef __SIZE_TYPE__ size_t;
+
+#else
+
+/* Depending on the compiler, we may be able to persuade its stddef.h
+   to define size_t and nothing else.  If this feature is not
+   available, exposing everything defined by stddef.h is better than
+   not defining size_t at all.  */
+# define __need_size_t
+# include <stddef.h>
+# undef __need_size_t
+
+#endif
+
+/* This must not be defined until _after_ possibly including stddef.h.  */
+#define _SIZE_T
+#endif
diff --git a/stdlib/bits/types/va_list.h b/stdlib/bits/types/va_list.h
index 6f3acac379..6e1db79280 100644
--- a/stdlib/bits/types/va_list.h
+++ b/stdlib/bits/types/va_list.h
@@ -1,6 +1,26 @@
-/* This guard macro needs to match the one used by at least gcc and
-   clang's stdarg.h to indicate that va_list, specifically, has been
-   defined.  */
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* The guard macro for this header must match the guard macro used by
+   the compiler's stdarg.h for va_list specifically.
+   GCC's stdarg.h checks several other macros as well as this one, in
+   order to accommodate many different C libraries, but clang's
+   stdarg.h only looks for this macro.  Other compilers can reasonably
+   be expected to look for this macro as well.  */
 #ifndef _VA_LIST
 
 #include <bits/types/__va_list.h>
@@ -8,8 +28,9 @@
 /* Check again, __va_list.h may not have been able to avoid including
    all of stdarg.h.  */
 # ifndef _VA_LIST
-typedef __gnuc_va_list va_list;
+typedef __va_list va_list;
 # endif
-# define _VA_LIST
 
+/* This must not be defined until _after_ possibly including stdarg.h.  */
+# define _VA_LIST
 #endif
diff --git a/stdlib/bits/types/wchar_t.h b/stdlib/bits/types/wchar_t.h
dissimilarity index 93%
index 1e44e157cc..ba0f94f803 100644
--- a/stdlib/bits/types/wchar_t.h
+++ b/stdlib/bits/types/wchar_t.h
@@ -?,? +1,50 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* The guard macro for this header must match the guard macro used by
+   the compiler's stddef.h for wchar_t specifically.
+   GCC's stddef.h checks a long list of other macros as well as this
+   one, in order to accommodate many different C libraries, but clang's
+   stddef.h only looks for this macro.  Other compilers can reasonably
+   be expected to look for this macro as well.  */
+#ifndef _WCHAR_T
+
+#ifdef __cplusplus
+/* Do nothing; wchar_t is a built-in type and reserved word in C++.  */
+#else
+
+# ifdef __WCHAR_TYPE__
+
+/* If the predefined macro __WCHAR_TYPE__ is available, use it.  */
+typedef __WCHAR_TYPE__ wchar_t;
+
+# else
+
+/* Depending on the compiler, we may be able to persuade its stddef.h
+   to define wchar_t and nothing else.  If this feature is not
+   available, exposing everything defined by stddef.h is better than
+   not defining wchar_t at all.  */
+#  define __need_wchar_t
+#  include <stddef.h>
+#  undef __need_wchar_t
+
+# endif /* not __WCHAR_TYPE__ */
+#endif /* not __cplusplus */
+
+/* This must not be defined until _after_ possibly including stddef.h.  */
+#define _WCHAR_T
+#endif
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
index 86ac418007..cbe533a685 100644
--- a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
+++ b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
@@ -1036,14 +1036,14 @@ __nldbl_errx (int status, const char *format, ...)
 }
 
 void
-__nldbl_verr (int status, const char *format, __gnuc_va_list ap)
+__nldbl_verr (int status, const char *format, __va_list ap)
 {
   __vwarn_internal (format, ap, PRINTF_LDBL_IS_DBL);
   exit (status);
 }
 
 void
-__nldbl_verrx (int status, const char *format, __gnuc_va_list ap)
+__nldbl_verrx (int status, const char *format, __va_list ap)
 {
   __vwarnx_internal (format, ap, PRINTF_LDBL_IS_DBL);
   exit (status);
@@ -1062,13 +1062,13 @@ __nldbl_warnx (const char *format, ...)
 }
 
 void
-__nldbl_vwarn (const char *format, __gnuc_va_list ap)
+__nldbl_vwarn (const char *format, __va_list ap)
 {
   __vwarn_internal (format, ap, PRINTF_LDBL_IS_DBL);
 }
 
 void
-__nldbl_vwarnx (const char *format, __gnuc_va_list ap)
+__nldbl_vwarnx (const char *format, __va_list ap)
 {
   __vwarnx_internal (format, ap, PRINTF_LDBL_IS_DBL);
 }
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-compat.h b/sysdeps/ieee754/ldbl-opt/nldbl-compat.h
index aed1cc1497..3413c4287a 100644
--- a/sysdeps/ieee754/ldbl-opt/nldbl-compat.h
+++ b/sysdeps/ieee754/ldbl-opt/nldbl-compat.h
@@ -103,23 +103,23 @@ extern ssize_t __nldbl___vstrfmon_l (char *, size_t, locale_t, const char *,
 /* These don't use __typeof because they were not declared by the headers,
    since we don't compile with _FORTIFY_SOURCE.  */
 extern int __nldbl___vfprintf_chk (FILE *__restrict, int,
-				   const char *__restrict, __gnuc_va_list);
+				   const char *__restrict, __va_list);
 extern int __nldbl___vfwprintf_chk (FILE *__restrict, int,
-				    const wchar_t *__restrict, __gnuc_va_list);
+				    const wchar_t *__restrict, __va_list);
 extern int __nldbl___vsprintf_chk (char *__restrict, int, size_t,
-				   const char *__restrict, __gnuc_va_list)
+				   const char *__restrict, __va_list)
   __THROW;
 extern int __nldbl___vsnprintf_chk (char *__restrict, size_t, int, size_t,
-				    const char *__restrict, __gnuc_va_list)
+				    const char *__restrict, __va_list)
   __THROW;
 extern int __nldbl___vswprintf_chk (wchar_t *__restrict, size_t, int, size_t,
-				    const wchar_t *__restrict, __gnuc_va_list)
+				    const wchar_t *__restrict, __va_list)
   __THROW;
-extern int __nldbl___vasprintf_chk (char **, int, const char *, __gnuc_va_list)
+extern int __nldbl___vasprintf_chk (char **, int, const char *, __va_list)
   __THROW;
-extern int __nldbl___vdprintf_chk (int, int, const char *, __gnuc_va_list);
+extern int __nldbl___vdprintf_chk (int, int, const char *, __va_list);
 extern int __nldbl___obstack_vprintf_chk (struct obstack *, int, const char *,
-					  __gnuc_va_list) __THROW;
+					  __va_list) __THROW;
 extern void __nldbl___vsyslog_chk (int, int, const char *, va_list);
 
 /* The original declarations of these were hidden by the including
diff --git a/wcsmbs/bits/wchar2.h b/wcsmbs/bits/wchar2.h
index 81603d560b..4b6b614481 100644
--- a/wcsmbs/bits/wchar2.h
+++ b/wcsmbs/bits/wchar2.h
@@ -303,17 +303,17 @@ __NTH (swprintf (wchar_t *__restrict __s, size_t __n,
 extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n,
 			    int __flag, size_t __s_len,
 			    const wchar_t *__restrict __format,
-			    __gnuc_va_list __arg)
+			    __va_list __arg)
      __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */;
 
 extern int __REDIRECT_NTH_LDBL (__vswprintf_alias,
 				(wchar_t *__restrict __s, size_t __n,
 				 const wchar_t *__restrict __fmt,
-				 __gnuc_va_list __ap), vswprintf);
+				 __va_list __ap), vswprintf);
 
 __fortify_function int
 __NTH (vswprintf (wchar_t *__restrict __s, size_t __n,
-		  const wchar_t *__restrict __fmt, __gnuc_va_list __ap))
+		  const wchar_t *__restrict __fmt, __va_list __ap))
 {
   if (__bos (__s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1)
     return __vswprintf_chk (__s, __n,  __USE_FORTIFY_LEVEL - 1,
@@ -330,9 +330,9 @@ extern int __wprintf_chk (int __flag, const wchar_t *__restrict __format,
 			  ...);
 extern int __vfwprintf_chk (__FILE *__restrict __stream, int __flag,
 			    const wchar_t *__restrict __format,
-			    __gnuc_va_list __ap);
+			    __va_list __ap);
 extern int __vwprintf_chk (int __flag, const wchar_t *__restrict __format,
-			   __gnuc_va_list __ap);
+			   __va_list __ap);
 
 # ifdef __va_arg_pack
 __fortify_function int
@@ -355,14 +355,14 @@ fwprintf (__FILE *__restrict __stream, const wchar_t *__restrict __fmt, ...)
 # endif
 
 __fortify_function int
-vwprintf (const wchar_t *__restrict __fmt, __gnuc_va_list __ap)
+vwprintf (const wchar_t *__restrict __fmt, __va_list __ap)
 {
   return __vwprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
 
 __fortify_function int
 vfwprintf (__FILE *__restrict __stream,
-	   const wchar_t *__restrict __fmt, __gnuc_va_list __ap)
+	   const wchar_t *__restrict __fmt, __va_list __ap)
 {
   return __vfwprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index ceb72b340c..75d0dde675 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -593,20 +593,20 @@ extern int swprintf (wchar_t *__restrict __s, size_t __n,
    marked with __THROW.  */
 extern int vfwprintf (__FILE *__restrict __s,
 		      const wchar_t *__restrict __format,
-		      __gnuc_va_list __arg)
+		      __va_list __arg)
      /* __attribute__ ((__format__ (__wprintf__, 2, 0))) */;
 /* Write formatted output to stdout from argument list ARG.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern int vwprintf (const wchar_t *__restrict __format,
-		     __gnuc_va_list __arg)
+		     __va_list __arg)
      /* __attribute__ ((__format__ (__wprintf__, 1, 0))) */;
 /* Write formatted output of at most N character to S from argument
    list ARG.  */
 extern int vswprintf (wchar_t *__restrict __s, size_t __n,
 		      const wchar_t *__restrict __format,
-		      __gnuc_va_list __arg)
+		      __va_list __arg)
      __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
 
 
@@ -666,19 +666,19 @@ extern int __isoc99_swscanf (const wchar_t *__restrict __s,
    marked with __THROW.  */
 extern int vfwscanf (__FILE *__restrict __s,
 		     const wchar_t *__restrict __format,
-		     __gnuc_va_list __arg)
+		     __va_list __arg)
      /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
 /* Read formatted input from stdin into argument list ARG.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern int vwscanf (const wchar_t *__restrict __format,
-		    __gnuc_va_list __arg)
+		    __va_list __arg)
      /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
 /* Read formatted input from S into argument list ARG.  */
 extern int vswscanf (const wchar_t *__restrict __s,
 		     const wchar_t *__restrict __format,
-		     __gnuc_va_list __arg)
+		     __va_list __arg)
      __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
 
 # if !defined __USE_GNU \
@@ -687,24 +687,24 @@ extern int vswscanf (const wchar_t *__restrict __s,
 #  ifdef __REDIRECT
 extern int __REDIRECT (vfwscanf, (__FILE *__restrict __s,
 				  const wchar_t *__restrict __format,
-				  __gnuc_va_list __arg), __isoc99_vfwscanf)
+				  __va_list __arg), __isoc99_vfwscanf)
      /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
 extern int __REDIRECT (vwscanf, (const wchar_t *__restrict __format,
-				 __gnuc_va_list __arg), __isoc99_vwscanf)
+				 __va_list __arg), __isoc99_vwscanf)
      /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
 extern int __REDIRECT_NTH (vswscanf, (const wchar_t *__restrict __s,
 				      const wchar_t *__restrict __format,
-				      __gnuc_va_list __arg), __isoc99_vswscanf)
+				      __va_list __arg), __isoc99_vswscanf)
      /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
 #  else
 extern int __isoc99_vfwscanf (__FILE *__restrict __s,
 			      const wchar_t *__restrict __format,
-			      __gnuc_va_list __arg);
+			      __va_list __arg);
 extern int __isoc99_vwscanf (const wchar_t *__restrict __format,
-			     __gnuc_va_list __arg);
+			     __va_list __arg);
 extern int __isoc99_vswscanf (const wchar_t *__restrict __s,
 			      const wchar_t *__restrict __format,
-			      __gnuc_va_list __arg) __THROW;
+			      __va_list __arg) __THROW;
 #   define vfwscanf __isoc99_vfwscanf
 #   define vwscanf __isoc99_vwscanf
 #   define vswscanf __isoc99_vswscanf
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 10/25] Swap sys/syslog.h with syslog.h.
@ 2019-06-26 17:50 Zack Weinberg
  2019-06-26 17:50 ` [PATCH 20/25] Don’t include sys/time.h from sys/timex.h Zack Weinberg
                   ` (14 more replies)
  0 siblings, 15 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

Our installed syslog.h is a trivial wrapper around sys/syslog.h, which
is where all the actual declarations are.  This is backward from
POSIX, which specifies syslog.h and its contents, and does not specify
sys/syslog.h.  This arrangement appears to have been inherited from
some BSD-phylum C library, and probably pre-dates any standardization
of syslog.

This patch swaps the contents of syslog.h and sys/syslog.h, so that
the actual declarations appear under the standardized name.  Since it
is necessary to adjust all of syslog.h’s bits headers, I also added
multiple-include guards to those files that didn’t already have
them.  (All installed headers should have multiple-include guards,
even if they are internal and only used in one public header.  The
“never include this file directly” #error convention doesn’t protect
against including the internal header a second time after its parent
header has already been included.)

	* misc/sys/syslog.h: Exchange contents with...
	* misc/syslog.h: ...this file.  Adjust multiple-include guards.

	* include/sys/syslog.h: Exchange contents with...
	* include/syslog.h: ...this file.  Adjust multiple-include guards.

	* bits/syslog-path.h, misc/bits/syslog-ldbl.h
	* misc/bits/syslog.h: Allow inclusion by syslog.h, not sys/syslog.h.
	Add multiple-include guard where not already present.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
        Update.
---
 bits/syslog-path.h                   |   8 +-
 include/sys/syslog.h                 |  19 +--
 include/{sys => }/syslog.h           |   5 +-
 misc/bits/syslog-ldbl.h              |   9 +-
 misc/bits/syslog.h                   |   9 +-
 misc/sys/syslog.h                    | 218 +--------------------------
 misc/{sys => }/syslog.h              |   4 +-
 scripts/check-obsolete-constructs.py |   2 +-
 8 files changed, 29 insertions(+), 245 deletions(-)
 rewrite include/sys/syslog.h (93%)
 copy include/{sys => }/syslog.h (81%)
 rewrite misc/sys/syslog.h (99%)
 copy misc/{sys => }/syslog.h (99%)

diff --git a/bits/syslog-path.h b/bits/syslog-path.h
index 5b97fa7db5..5677f468b5 100644
--- a/bits/syslog-path.h
+++ b/bits/syslog-path.h
@@ -16,13 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_SYSLOG_H
-# error "Never include this file directly.  Use <sys/syslog.h> instead"
-#endif
-
 #ifndef _BITS_SYSLOG_PATH_H
 #define _BITS_SYSLOG_PATH_H 1
 
+#ifndef _SYSLOG_H
+# error "Never include <bits/syslog-path.h> directly.  Use <syslog.h> instead"
+#endif
+
 #define	_PATH_LOG	"/dev/log"
 
 #endif /* bits/syslog-path.h */
diff --git a/include/sys/syslog.h b/include/sys/syslog.h
dissimilarity index 93%
index 89d3479ebc..7d6e3bc46c 100644
--- a/include/sys/syslog.h
+++ b/include/sys/syslog.h
@@ -?,? +1,3 @@
+#ifndef _SYSLOG_H
+#include <misc/sys/syslog.h>
+#endif
diff --git a/include/sys/syslog.h b/include/syslog.h
similarity index 81%
copy from include/sys/syslog.h
copy to include/syslog.h
index 89d3479ebc..5dc6e76b7e 100644
--- a/include/sys/syslog.h
+++ b/include/syslog.h
@@ -1,6 +1,5 @@
-#ifndef _LIBC_SYS_SYSLOG_H
-#define _LIBC_SYS_SYSLOG_H 1
-#include <misc/sys/syslog.h>
+#ifndef _SYSLOG_H
+# include <misc/syslog.h>
 #ifndef _ISOMAC
 
 libc_hidden_proto (syslog)
diff --git a/misc/bits/syslog-ldbl.h b/misc/bits/syslog-ldbl.h
index e3117552ae..4c2eea74e6 100644
--- a/misc/bits/syslog-ldbl.h
+++ b/misc/bits/syslog-ldbl.h
@@ -16,8 +16,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_SYSLOG_H
-# error "Never include <bits/syslog-ldbl.h> directly; use <sys/syslog.h> instead."
+#ifndef _BITS_SYSLOG_LDBL_H
+#define _BITS_SYSLOG_LDBL_H 1
+
+#ifndef _SYSLOG_H
+# error "Never include <bits/syslog-ldbl.h> directly; use <syslog.h> instead."
 #endif
 
 __LDBL_REDIR_DECL (syslog)
@@ -33,3 +36,5 @@ __LDBL_REDIR_DECL (__syslog_chk)
 __LDBL_REDIR_DECL (__vsyslog_chk)
 # endif
 #endif
+
+#endif /* bits/syslog-ldbl.h */
diff --git a/misc/bits/syslog.h b/misc/bits/syslog.h
index 86d94536ee..e796955c1c 100644
--- a/misc/bits/syslog.h
+++ b/misc/bits/syslog.h
@@ -16,8 +16,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_SYSLOG_H
-# error "Never include <bits/syslog.h> directly; use <sys/syslog.h> instead."
+#ifndef _BITS_SYSLOG_H
+#define _BITS_SYSLOG_H 1
+
+#ifndef _SYSLOG_H
+# error "Never include <bits/syslog.h> directly; use <syslog.h> instead."
 #endif
 
 
@@ -47,3 +50,5 @@ vsyslog (int __pri, const char *__fmt, __gnuc_va_list __ap)
   __vsyslog_chk (__pri,  __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
 #endif
+
+#endif /* bits/syslog.h */
diff --git a/misc/sys/syslog.h b/misc/sys/syslog.h
dissimilarity index 99%
index ee01478c4b..9fc15930fb 100644
--- a/misc/sys/syslog.h
+++ b/misc/sys/syslog.h
@@ -?,? +1,3 @@
+#ifndef _SYSLOG_H
+# include <syslog.h>
+#endif
diff --git a/misc/sys/syslog.h b/misc/syslog.h
similarity index 99%
copy from misc/sys/syslog.h
copy to misc/syslog.h
index ee01478c4b..406133ba71 100644
--- a/misc/sys/syslog.h
+++ b/misc/syslog.h
@@ -29,8 +29,8 @@
  *	@(#)syslog.h	8.1 (Berkeley) 6/2/93
  */
 
-#ifndef _SYS_SYSLOG_H
-#define _SYS_SYSLOG_H 1
+#ifndef _SYSLOG_H
+#define _SYSLOG_H 1
 
 #include <features.h>
 #define __need___va_list
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 5efe824b8d..c437c8e00b 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -635,12 +635,12 @@ HEADER_ALLOWED_INCLUDES = {
     "memory.h":                    [ "string.h" ],
     "poll.h":                      [ "sys/poll.h" ],
     "re_comp.h":                   [ "regex.h" ],
-    "syslog.h":                    [ "sys/syslog.h" ],
     "sys/bitypes.h":               [ "sys/types.h" ],
     "sys/dir.h":                   [ "dirent.h" ],
     "sys/errno.h":                 [ "errno.h" ],
     "sys/fcntl.h":                 [ "fcntl.h" ],
     "sys/signal.h":                [ "signal.h" ],
+    "sys/syslog.h":                [ "syslog.h" ],
     "sys/termios.h":               [ "termios.h" ],
     "sys/unistd.h":                [ "unistd.h" ],
     "syscall.h":                   [ "sys/syscall.h" ],
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 12/25] Don’t include sys/cdefs.h directly from public headers.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (4 preceding siblings ...)
  2019-06-26 17:50 ` [PATCH 13/25] Split up endian.h to minimize exposure of BYTE_ORDER Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-06-26 17:50 ` [PATCH 15/25] Don’t rely on stddef.h or stdarg.h for individual type definitions Zack Weinberg
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h.  In a few places, though, it’s been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite).  This patch
makes all installed headers match the glibc convention.

This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.

    #define _XOPEN_SOURCE 700
    #include <glob.h>
    #include <stddef.h>
    int dummy;

declares size_t twice, which is invalid prior to C2011.  I wasn’t able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.

	* posix/glob.h: Include features.h, not sys/cdefs.h.
	When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
	otherwise, issue an immediate #error if __SIZE_TYPE__ is not
	available. Use __gsize_t, not __size_t, as an impl-namespace
	alternative name for size_t.
	* conform/data/glob.h-data: Adjust to match.

	* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
	* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
	* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
	* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
	* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
	* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
        Update.
---
 conform/data/glob.h-data             |  2 +-
 inet/netinet/igmp.h                  |  3 ++-
 mach/lock-intern.h                   |  3 ++-
 misc/ar.h                            |  2 +-
 misc/sys/auxv.h                      |  3 ++-
 posix/glob.h                         | 33 +++++++++++++++-------------
 resolv/resolv.h                      |  3 ++-
 scripts/check-obsolete-constructs.py | 18 ++++++---------
 socket/sys/un.h                      |  2 +-
 sunrpc/rpc/auth_des.h                |  3 ++-
 sunrpc/rpc/rpc_msg.h                 |  2 +-
 sysdeps/generic/memcopy.h            |  3 ++-
 sysdeps/generic/netinet/tcp.h        |  3 +--
 sysdeps/htl/pthread.h                |  1 -
 sysdeps/mach/hurd/net/ethernet.h     |  3 ++-
 sysdeps/mach/hurd/net/if_arp.h       |  4 ++--
 16 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca83937af..6268134b35 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
 #if !defined ISO && !defined ISO99 && !defined ISO11
 #ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
 #endif
 
 type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 451b1abf47..2884db59df 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
 #ifndef _NETINET_IGMP_H
 #define	_NETINET_IGMP_H 1
 
-#include <sys/cdefs.h>
+#include <features.h>
+
 #include <sys/types.h>
 
 #ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89b09..a409abbe62 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
 #ifndef _LOCK_INTERN_H
 #define	_LOCK_INTERN_H
 
-#include <sys/cdefs.h>
+#include <features.h>
+
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 # include <lowlevellock.h>
 #endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303ecfe..adcfda47e2 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
 #ifndef _AR_H
 #define _AR_H 1
 
-#include <sys/cdefs.h>
+#include <features.h>
 
 /* Archive files start with the ARMAG identifying string.  Then follows a
    `struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b364d..404da6f400 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
 #ifndef _SYS_AUXV_H
 #define _SYS_AUXV_H 1
 
+#include <features.h>
+
 #include <elf.h>
-#include <sys/cdefs.h>
 #include <bits/hwcap.h>
 
 __BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80af8f..e49e6c000d 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
 #ifndef	_GLOB_H
 #define	_GLOB_H	1
 
-#include <sys/cdefs.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
-/* We need `size_t' for the following definitions.  */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+   define size_t itself, unless XSI or POSIX.1-2008 features are active.
+   We can't use __size_t as an alternative name, as we do for most types
+   with this kind of constraint, because GCC's stddef.h uses __size_t for
+   a different purpose.  */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
 #else
-/* The GNU CC stddef.h version defines __size_t as empty.  We need a real
-   definition.  */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
 #endif
 
 /* Bits set in the FLAGS argument to `glob'.  */
@@ -81,9 +84,9 @@ struct stat;
 #endif
 typedef struct
   {
-    __size_t gl_pathc;		/* Count of paths matched by the pattern.  */
+    __gsize_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'.  */
+    __gsize_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 +113,9 @@ struct stat64;
 # endif
 typedef struct
   {
-    __size_t gl_pathc;
+    __gsize_t gl_pathc;
     char **gl_pathv;
-    __size_t gl_offs;
+    __gsize_t gl_offs;
     int gl_flags;
 
     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023ae9d..b4ef66fdfa 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
 #ifndef _RESOLV_H_
 #define _RESOLV_H_
 
-#include <sys/cdefs.h>
+#include <features.h>
+
 #include <sys/param.h>
 #include <sys/types.h>
 #include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 08534348d7..e383a304db 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -527,11 +527,9 @@ HEADER_ALLOWED_INCLUDES = {
     #           spawn.h -> sched.h
     "aio.h":                       [ "sys/types.h" ],
     "ftw.h":                       [ "sys/stat.h", "sys/types.h" ],
-    "glob.h":                      [ "sys/cdefs.h" ],
     "langinfo.h":                  [ "nl_types.h" ],
     "mqueue.h":                    [ "fcntl.h", "sys/types.h" ],
-    "pthread.h":                   [ "endian.h", "sched.h", "time.h",
-                                     "sys/cdefs.h" ],
+    "pthread.h":                   [ "sched.h", "time.h" ],
     "regex.h":                     [ "limits.h", "sys/types.h" ],
     "sched.h":                     [ "time.h" ],
     "semaphore.h":                 [ "sys/types.h" ],
@@ -550,7 +548,7 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/time.h":                  [ "sys/select.h" ],
     "sys/types.h":                 [ "endian.h", "sys/select.h" ],
     "sys/uio.h":                   [ "sys/types.h" ],
-    "sys/un.h":                    [ "string.h", "sys/cdefs.h" ],
+    "sys/un.h":                    [ "string.h" ],
     "sys/wait.h":                  [ "signal.h" ],
 
     # POSIX networking headers
@@ -565,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
 
     # Nonstandardized top-level headers
     "aliases.h":                   [ "sys/types.h" ],
-    "ar.h":                        [ "sys/cdefs.h" ],
     "argp.h":                      [ "ctype.h", "errno.h", "getopt.h",
                                      "limits.h", "stdio.h" ],
     "argz.h":                      [ "errno.h", "string.h" ],
@@ -594,7 +591,7 @@ HEADER_ALLOWED_INCLUDES = {
 
     # Nonstandardized sys/ headers
     "sys/acct.h":                  [ "endian.h", "stdint.h", "sys/types.h" ],
-    "sys/auxv.h":                  [ "elf.h", "sys/cdefs.h" ],
+    "sys/auxv.h":                  [ "elf.h" ],
     "sys/elf.h":                   [ "sys/procfs.h" ],
     "sys/epoll.h":                 [ "stdint.h", "sys/types.h" ],
     "sys/eventfd.h":               [ "stdint.h" ],
@@ -649,16 +646,16 @@ HEADER_ALLOWED_INCLUDES = {
     # Nonstandardized networking headers
     "ifaddrs.h":                   [ "sys/socket.h" ],
     "resolv.h":                    [ "arpa/nameser.h", "netinet/in.h",
-                                     "stdio.h", "sys/cdefs.h", "sys/param.h",\
+                                     "stdio.h", "sys/param.h",
                                      "sys/types.h" ],
 
     "arpa/nameser.h":              [ "arpa/nameser_compat.h", "stdint.h",
                                      "sys/param.h", "sys/types.h" ],
     "arpa/nameser_compat.h":       [ "endian.h" ],
-    "net/ethernet.h":              [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+    "net/ethernet.h":              [ "stdint.h", "sys/types.h",
                                      "net/if_ether.h" ],
     "net/if_arp.h":                [ "stdint.h", "sys/socket.h",
-                                     "sys/types.h", "sys/cdefs.h" ],
+                                     "sys/types.h" ],
     "net/if_ppp.h":                [ "net/if.h", "net/ppp_defs.h", "stdint.h",
                                      "sys/ioctl.h", "sys/types.h" ],
     "net/if_shaper.h":             [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -673,8 +670,7 @@ HEADER_ALLOWED_INCLUDES = {
                                      "sys/types.h", "stdint.h" ],
     "netinet/if_fddi.h":           [ "stdint.h", "sys/types.h" ],
     "netinet/if_tr.h":             [ "stdint.h", "sys/types.h" ],
-    "netinet/igmp.h":              [ "netinet/in.h", "sys/cdefs.h",
-                                     "sys/types.h" ],
+    "netinet/igmp.h":              [ "netinet/in.h", "sys/types.h" ],
     "netinet/in_systm.h":          [ "stdint.h", "sys/types.h" ],
     "netinet/ip.h":                [ "netinet/in.h", "sys/types.h" ],
     "netinet/ip6.h":               [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 12683607ce..8c7433a3dc 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
 #ifndef	_SYS_UN_H
 #define	_SYS_UN_H	1
 
-#include <sys/cdefs.h>
+#include <features.h>
 
 /* Get the definition of the macro to define the common sockaddr members.  */
 #include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675ff51..e60e795cad 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
 #ifndef _RPC_AUTH_DES_H
 #define _RPC_AUTH_DES_H	1
 
-#include <sys/cdefs.h>
+#include <features.h>
+
 #include <rpc/auth.h>
 
 __BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516cd6..efd9ee4a2f 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
 #ifndef _RPC_MSG_H
 #define _RPC_MSG_H 1
 
-#include <sys/cdefs.h>
+#include <features.h>
 
 #include <rpc/xdr.h>
 #include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01ea08..de32e56f1a 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
 #ifndef _MEMCOPY_H
 #define _MEMCOPY_H	1
 
+#include <features.h>
+
 /* The strategy of the memory functions is:
 
      1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
    exhaustive in the sense that I tried all alignment and length
    combinations, with and without overlap.  */
 
-#include <sys/cdefs.h>
 #include <endian.h>
 #include <pagecopy.h>
 
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfbc26..3b59e949d8 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
  */
 
 #ifndef _NETINET_TCP_H
-
 #define _NETINET_TCP_H	1
-#include <sys/cdefs.h>
 
+#include <features.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a8205519f2..158a095417 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
 
 #include <features.h>
 
-#include <sys/cdefs.h>
 #ifndef __extern_inline
 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
    inline semantics, unless -fgnu89-inline is used.  */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea347..8956694b59 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
 #ifndef __NET_ETHERNET_H
 #define __NET_ETHERNET_H 1
 
-#include <sys/cdefs.h>
+#include <features.h>
+
 #include <sys/types.h>
 #include <stdint.h>
 #include <net/if_ether.h>     /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c96dd..9e1b2233ce 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
 /* Based on the 4.4BSD and Linux version of this file.  */
 
 #ifndef _NET_IF_ARP_H
-
 #define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 16/25] Limit the set of strings.h functions also exposed in string.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
  2019-06-26 17:50 ` [PATCH 20/25] Don’t include sys/time.h from sys/timex.h Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-06-26 17:50 ` [PATCH 11/25] Swap sys/poll.h with poll.h Zack Weinberg
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

As someone who can remember when you might not be able to include both
string.h and strings.h at the same time, it annoys me that strings.h
still exists and is the only standard source for str(n)casecmp(_l) and
ffs.  I think it’s right that we expose those functions from string.h.
However, there’s no reason we need to keep exposing the other obsolete
functions that strings.h declares from string.h.

This patch creates <bits/strings_x2k8.h>, which declares the
non-obsolete functions whose official home is strings.h.  strings.h
includes it unconditionally, and string.h includes it under
__USE_MISC, instead of strings.h.

Two tests of the obsolete strings.h functions had to be adjusted.

	* string/strings.h (strcasecmp, strncasecmp, strcasecmp_l)
	(strncasecmp_l, ffs, ffsl, ffsll): Move declarations to...
	* string/bits/strings_x2k8.h: ... this new file.
	* string/Makefile: Install bits/strings_x2k8.h.
	* include/bits/strings_x2k8h: New wrapper.
	* string/string.h: Include bits/strings_x2k8.h instead of
	strings.h.

	* debug/tst-chk1.c, string/test-string.h: Include strings.h.
	* scripts/check-obsolete-constructs.py: string.h is no longer
	expected to include strings.h.

	* sysdeps/i386/i686/multiarch/bcopy.c
	* sysdeps/i386/i686/multiarch/bzero.c
	* sysdeps/i386/i686/multiarch/ifunc-impl-list.c
	* sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c
	* sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c
	* sysdeps/powerpc/powerpc64/multiarch/bcopy.c
	* sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
	* sysdeps/s390/bzero.c
	* sysdeps/s390/multiarch/ifunc-impl-list.c
	* sysdeps/sparc/sparc64/multiarch/bzero.c
	* sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c:
        Include strings.h.
---
 NEWS                                          |  3 +
 debug/tst-chk1.c                              |  1 +
 include/bits/strings_x2k8.h                   |  1 +
 scripts/check-obsolete-constructs.py          |  1 -
 string/Makefile                               |  2 +-
 string/bits/strings_x2k8.h                    | 70 +++++++++++++++++++
 string/string.h                               |  2 +-
 string/strings.h                              | 39 +----------
 string/test-string.h                          |  1 +
 sysdeps/i386/i686/multiarch/bcopy.c           |  1 +
 sysdeps/i386/i686/multiarch/bzero.c           |  1 +
 sysdeps/i386/i686/multiarch/ifunc-impl-list.c |  1 +
 .../power4/multiarch/ifunc-impl-list.c        |  1 +
 .../powerpc/powerpc64/multiarch/bcopy-ppc64.c |  1 +
 sysdeps/powerpc/powerpc64/multiarch/bcopy.c   |  1 +
 .../powerpc64/multiarch/ifunc-impl-list.c     |  1 +
 sysdeps/s390/bzero.c                          |  1 +
 sysdeps/s390/multiarch/ifunc-impl-list.c      |  1 +
 sysdeps/sparc/sparc64/multiarch/bzero.c       |  1 +
 .../sparc/sparc64/multiarch/ifunc-impl-list.c |  1 +
 20 files changed, 91 insertions(+), 40 deletions(-)
 create mode 100644 include/bits/strings_x2k8.h
 create mode 100644 string/bits/strings_x2k8.h

diff --git a/NEWS b/NEWS
index edf7739293..974ed39e4d 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,9 @@ Deprecated and removed features, and other changes affecting compatibility:
 * The obsolete and never-implemented XSI STREAMS header files <stropts.h>
   and <sys/stropts.h> have been removed.
 
+* The obsolete functions bcmp, bcopy, bzero, index, and rindex are no
+  longer declared in <string.h>, only <strings.h>.
+
 * The typedefs u_int8_t, u_int16_t, u_int32_t, u_int64_t, and register_t
   are no longer defined by <sys/types.h> in strict conformance modes.
   These types were historically provided by <sys/types.h> on BSD systems,
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index c6f11af1ff..014b08fab7 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <unistd.h>
 #include <wchar.h>
 #include <sys/poll.h>
diff --git a/include/bits/strings_x2k8.h b/include/bits/strings_x2k8.h
new file mode 100644
index 0000000000..7eddd92d93
--- /dev/null
+++ b/include/bits/strings_x2k8.h
@@ -0,0 +1 @@
+#include <string/bits/strings_x2k8.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index e95e587d3e..bd5a97f76b 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -506,7 +506,6 @@ HEADER_ALLOWED_INCLUDES = {
     "inttypes.h":                  [ "stdint.h" ],
     "signal.h":                    [ "sys/ucontext.h" ],
     "stdlib.h":                    [ "alloca.h", "sys/types.h" ],
-    "string.h":                    [ "strings.h" ],
     "tgmath.h":                    [ "complex.h", "math.h" ],
     "threads.h":                   [ "time.h" ],
 
diff --git a/string/Makefile b/string/Makefile
index 3e5721e0f4..c9ebede768 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -23,7 +23,7 @@ subdir	:= string
 include ../Makeconfig
 
 headers		:= string.h bits/string_fortified.h			\
-		   strings.h bits/strings_fortified.h			\
+		   strings.h bits/strings_x2k8.h bits/strings_fortified.h \
 		   byteswap.h bits/byteswap.h				\
 		   endian.h bits/endian.h bits/endianness.h		\
 		   bits/uintn-identity.h				\
diff --git a/string/bits/strings_x2k8.h b/string/bits/strings_x2k8.h
new file mode 100644
index 0000000000..dbcb0b2c31
--- /dev/null
+++ b/string/bits/strings_x2k8.h
@@ -0,0 +1,70 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_STRINGS_X2K8_H
+#define _BITS_STRINGS_X2K8_H 1
+
+/* This header file declares all of the strings.h functions that are
+   not marked as "obsolete" in POSIX.1-2008.  As a GNU extension,
+   these functions are also made available via string.h.  */
+
+#if !defined _STRING_H && !defined _STRINGS_H
+# error "Never include <bits/strings_x2k8.h> directly, use <string(s).h>."
+#endif
+
+__BEGIN_DECLS
+
+/* Compare S1 and S2, ignoring case.  */
+extern int strcasecmp (const char *__s1, const char *__s2)
+     __THROW __attribute_pure__ __nonnull ((1, 2));
+
+/* Compare no more than N chars of S1 and S2, ignoring case.  */
+extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
+     __THROW __attribute_pure__ __nonnull ((1, 2));
+
+#ifdef	__USE_XOPEN2K8
+/* POSIX.1-2008 extended locale interface (see locale.h).  */
+# include <bits/types/locale_t.h>
+
+/* Compare S1 and S2, ignoring case, using collation rules from LOC.  */
+extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc)
+     __THROW __attribute_pure__ __nonnull ((1, 2, 3));
+
+/* Compare no more than N chars of S1 and S2, ignoring case, using
+   collation rules from LOC.  */
+extern int strncasecmp_l (const char *__s1, const char *__s2,
+			  size_t __n, locale_t __loc)
+     __THROW __attribute_pure__ __nonnull ((1, 2, 4));
+#endif
+
+#if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
+/* Return the position of the first bit set in I, or 0 if none are set.
+   The least-significant bit is position 1, the most-significant 32.  */
+extern int ffs (int __i) __THROW __attribute_const__;
+#endif
+
+/* The following two functions are non-standard but necessary for non-32 bit
+   platforms.  */
+#ifdef	__USE_MISC
+extern int ffsl (long int __l) __THROW __attribute_const__;
+__extension__ extern int ffsll (long long int __ll)
+     __THROW __attribute_const__;
+#endif
+
+__END_DECLS
+
+#endif /* bits/strings_x2k8.h */
diff --git a/string/string.h b/string/string.h
index 2cc4f50090..6c9cdc0780 100644
--- a/string/string.h
+++ b/string/string.h
@@ -426,7 +426,7 @@ extern char *strerror_l (int __errnum, locale_t __l) __THROW;
 #endif
 
 #ifdef __USE_MISC
-# include <strings.h>
+# include <bits/strings_x2k8.h>
 
 /* Set N bytes of S to 0.  The compiler will not delete a call to this
    function, even if S is dead after the call.  */
diff --git a/string/strings.h b/string/strings.h
index 17e1bf737f..bec458f1d7 100644
--- a/string/strings.h
+++ b/string/strings.h
@@ -21,6 +21,8 @@
 #include <features.h>
 #include <bits/types/size_t.h>
 
+#include <bits/strings_x2k8.h>
+
 /* Tell the caller that we provide correct C++ prototypes.  */
 #if defined __cplusplus && __GNUC_PREREQ (4, 4)
 # define __CORRECT_ISO_CPP_STRINGS_H_PROTO
@@ -97,43 +99,6 @@ extern char *rindex (const char *__s, int __c)
 # endif
 #endif
 
-#if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
-/* Return the position of the first bit set in I, or 0 if none are set.
-   The least-significant bit is position 1, the most-significant 32.  */
-extern int ffs (int __i) __THROW __attribute_const__;
-#endif
-
-/* The following two functions are non-standard but necessary for non-32 bit
-   platforms.  */
-# ifdef	__USE_MISC
-extern int ffsl (long int __l) __THROW __attribute_const__;
-__extension__ extern int ffsll (long long int __ll)
-     __THROW __attribute_const__;
-# endif
-
-/* Compare S1 and S2, ignoring case.  */
-extern int strcasecmp (const char *__s1, const char *__s2)
-     __THROW __attribute_pure__ __nonnull ((1, 2));
-
-/* Compare no more than N chars of S1 and S2, ignoring case.  */
-extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
-     __THROW __attribute_pure__ __nonnull ((1, 2));
-
-#ifdef	__USE_XOPEN2K8
-/* POSIX.1-2008 extended locale interface (see locale.h).  */
-# include <bits/types/locale_t.h>
-
-/* Compare S1 and S2, ignoring case, using collation rules from LOC.  */
-extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc)
-     __THROW __attribute_pure__ __nonnull ((1, 2, 3));
-
-/* Compare no more than N chars of S1 and S2, ignoring case, using
-   collation rules from LOC.  */
-extern int strncasecmp_l (const char *__s1, const char *__s2,
-			  size_t __n, locale_t __loc)
-     __THROW __attribute_pure__ __nonnull ((1, 2, 4));
-#endif
-
 __END_DECLS
 
 #if __GNUC_PREREQ (3,4) && __USE_FORTIFY_LEVEL > 0 \
diff --git a/string/test-string.h b/string/test-string.h
index befd3e9931..2c1c01699c 100644
--- a/string/test-string.h
+++ b/string/test-string.h
@@ -55,6 +55,7 @@ extern impl_t __start_impls[], __stop_impls[];
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <unistd.h>
diff --git a/sysdeps/i386/i686/multiarch/bcopy.c b/sysdeps/i386/i686/multiarch/bcopy.c
index c2d1d25710..e1cd57c6e9 100644
--- a/sysdeps/i386/i686/multiarch/bcopy.c
+++ b/sysdeps/i386/i686/multiarch/bcopy.c
@@ -21,6 +21,7 @@
 #if IS_IN (libc)
 # define bcopy __redirect_bcopy
 # include <string.h>
+# include <strings.h>
 # undef bcopy
 
 # define SYMBOL_NAME bcopy
diff --git a/sysdeps/i386/i686/multiarch/bzero.c b/sysdeps/i386/i686/multiarch/bzero.c
index 6b4834e9de..182a496af6 100644
--- a/sysdeps/i386/i686/multiarch/bzero.c
+++ b/sysdeps/i386/i686/multiarch/bzero.c
@@ -21,6 +21,7 @@
 #if IS_IN (libc)
 # define bzero __redirect_bzero
 # include <string.h>
+# include <strings.h>
 # undef bzero
 
 # define SYMBOL_NAME bzero
diff --git a/sysdeps/i386/i686/multiarch/ifunc-impl-list.c b/sysdeps/i386/i686/multiarch/ifunc-impl-list.c
index e2428e0b11..5408aec908 100644
--- a/sysdeps/i386/i686/multiarch/ifunc-impl-list.c
+++ b/sysdeps/i386/i686/multiarch/ifunc-impl-list.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ifunc-impl-list.h>
 #include "init-arch.h"
diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c
index 16a64beb33..ac6784a61b 100644
--- a/sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c
+++ b/sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ldsodefs.h>
 #include <ifunc-impl-list.h>
diff --git a/sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c
index 6772e0a867..9ba96f7d45 100644
--- a/sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c
+++ b/sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <strings.h>
 
 extern __typeof (bcopy)   __bcopy_ppc attribute_hidden;
 extern __typeof (memmove) __memmove_ppc attribute_hidden;
diff --git a/sysdeps/powerpc/powerpc64/multiarch/bcopy.c b/sysdeps/powerpc/powerpc64/multiarch/bcopy.c
index 8c6f2fbf8e..b402117cb3 100644
--- a/sysdeps/powerpc/powerpc64/multiarch/bcopy.c
+++ b/sysdeps/powerpc/powerpc64/multiarch/bcopy.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <strings.h>
 #include "init-arch.h"
 
 extern __typeof (bcopy) __bcopy_ppc attribute_hidden;
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
index c0a927d73e..c6a227f0e1 100644
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ldsodefs.h>
 #include <ifunc-impl-list.h>
diff --git a/sysdeps/s390/bzero.c b/sysdeps/s390/bzero.c
index 5477ed4aad..18f7eb8932 100644
--- a/sysdeps/s390/bzero.c
+++ b/sysdeps/s390/bzero.c
@@ -19,6 +19,7 @@
 #include <ifunc-memset.h>
 #if HAVE_MEMSET_IFUNC
 # include <string.h>
+# include <strings.h>
 # include <ifunc-resolve.h>
 
 # if HAVE_MEMSET_Z900_G5
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
index 1948436417..bede348ee5 100644
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ifunc-impl-list.h>
 #include <ifunc-resolve.h>
diff --git a/sysdeps/sparc/sparc64/multiarch/bzero.c b/sysdeps/sparc/sparc64/multiarch/bzero.c
index 2d7c06b325..3801d8d0ef 100644
--- a/sysdeps/sparc/sparc64/multiarch/bzero.c
+++ b/sysdeps/sparc/sparc64/multiarch/bzero.c
@@ -20,6 +20,7 @@
 #if IS_IN (libc)
 # define bzero __redirect_bzero
 # include <string.h>
+# include <strings.h>
 # undef bzero
 
 # include <sparc-ifunc.h>
diff --git a/sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c b/sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c
index 00ed640fbf..8326a7b421 100644
--- a/sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c
+++ b/sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ldsodefs.h>
 #include <sysdep.h>
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 13/25] Split up endian.h to minimize exposure of BYTE_ORDER.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (3 preceding siblings ...)
  2019-06-26 17:50 ` [PATCH 14/25] Add bits/types/ wrappers for stddef.h and stdarg.h types Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-07-24 21:14   ` Joseph Myers
  2019-06-26 17:50 ` [PATCH 12/25] Don’t include sys/cdefs.h directly from public headers Zack Weinberg
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

With only two exceptions (sys/types.h and sys/param.h, both of which
historically might have defined BYTE_ORDER) the public headers that
include <endian.h> only want to be able to test __BYTE_ORDER against
__*_ENDIAN.

This patch creates a new bits/endian.h that can be included by any
header that wants to be able to test __BYTE_ORDER and/or
__FLOAT_WORD_ORDER against the __*_ENDIAN constants, or needs
__LONG_LONG_PAIR.  It only defines macros in the implementation
namespace.

The existing bits/endian.h (which could not be included independently
of endian.h, and only defines __BYTE_ORDER and maybe __FLOAT_WORD_ORDER)
is renamed to bits/endianness.h.  I also took the opportunity to
canonicalize the form of this header, which we are stuck with having
one copy of per architecture.  Since they are so short, this means git
doesn’t understand that they were renamed from existing headers, sigh.

endian.h itself is a nonstandard header and its only remaining use
from a standard header is guarded by __USE_MISC, so I dropped the
__USE_MISC conditionals from around all of the public-namespace things
it defines.  (This means, an application that requests strict library
conformance but includes endian.h will still see the definition of
BYTE_ORDER.)

A few changes to specific bits/endian(ness).h variants deserve
mention:

 - sysdeps/unix/sysv/linux/ia64/bits/endian.h is moved to
   sysdeps/ia64/bits/endianness.h.  If I remember correctly, ia64 did
   have selectable endianness, but we have assembly code in
   sysdeps/ia64 that assumes it’s little-endian, so there is no reason
   to treat the ia64 endianness.h as linux-specific.

 - The C-SKY port does not fully support big-endian mode, but I do
   not think this is sufficient reason to make csky/bits/endian(ness).h
   error out if __CSKYBE__ is defined, so it now defines __BYTE_ORDER
   appropriately for whichever mode the compiler is in.

 - The PowerPC port had extra logic in its bits/endian.h to detect a
   broken compiler, which strikes me as unnecessary, so I removed it.

 - The only files that defined __FLOAT_WORD_ORDER always defined it to
   the same value as __BYTE_ORDER, so I removed those definitions.
   The SH bits/endian(ness).h had comments inconsistent with the
   actual setting of __FLOAT_WORD_ORDER, which I also removed.

 - I *removed* copyright boilerplate from the few bits/endian(ness).h
   headers that had it; these files record a single fact in a fashion
   dictated by an external spec, so I do not think they are copyrightable.

As long as I was changing every copy of ieee754.h in the tree, I
noticed that only the MIPS variant includes float.h, because it uses
LDBL_MANT_DIG to decide among three different versions of
ieee854_long_double.  This patch makes it not include float.h when
GCC’s intrinsic __LDBL_MANT_DIG__ is available.

	* string/endian.h: Unconditionally define LITTLE_ENDIAN,
	BIG_ENDIAN, PDP_ENDIAN, and BYTE_ORDER.	 Condition byteswapping
	macros only on !__ASSEMBLER__.	Move the definitions of
	__BIG_ENDIAN, __LITTLE_ENDIAN, __PDP_ENDIAN, __FLOAT_WORD_ORDER,
	and __LONG_LONG_PAIR to...
	* string/bits/endian.h: ...this new file, which includes
	the renamed header bits/endianness.h for the definition of
	__BYTE_ORDER and possibly __FLOAT_WORD_ORDER.

	* string/Makefile: Install bits/endianness.h.
	* include/bits/endian.h: New wrapper.

	* bits/endian.h: Rename to bits/endianness.h.
	Add multiple-include guard.  Rewrite the comment explaining what
	the machine-specific variants of this file should do.

	* sysdeps/unix/sysv/linux/ia64/bits/endian.h:
	Move to sysdeps/ia64.

	* sysdeps/aarch64/bits/endian.h
	* sysdeps/alpha/bits/endian.h
	* sysdeps/arm/bits/endian.h
	* sysdeps/csky/bits/endian.h
	* sysdeps/hppa/bits/endian.h
	* sysdeps/ia64/bits/endian.h
	* sysdeps/m68k/bits/endian.h
	* sysdeps/microblaze/bits/endian.h
	* sysdeps/mips/bits/endian.h
	* sysdeps/nios2/bits/endian.h
	* sysdeps/powerpc/bits/endian.h
	* sysdeps/riscv/bits/endian.h
	* sysdeps/s390/bits/endian.h
	* sysdeps/sh/bits/endian.h
	* sysdeps/sparc/bits/endian.h
	* sysdeps/x86/bits/endian.h:
	Rename to endianness.h; canonicalize form of file; remove
	redundant definitions of __FLOAT_WORD_ORDER.

	* sysdeps/csky/bits/endianness.h: Do not error out if __CSKYEB__
	is defined.
	* sysdeps/powerpc/bits/endianness.h: Remove logic to check for
	broken compilers.

	* ctype/ctype.h
	* inet/netinet/in.h
	* resolv/arpa/nameser_compat.h
	* sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
	* sysdeps/arm/nptl/bits/pthreadtypes-arch.h
	* sysdeps/csky/nptl/bits/pthreadtypes-arch.h
	* sysdeps/ia64/ieee754.h
	* sysdeps/ieee754/ieee754.h
	* sysdeps/ieee754/ldbl-128/ieee754.h
	* sysdeps/ieee754/ldbl-128ibm/ieee754.h
	* sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
	* sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
	* sysdeps/mips/ieee754/ieee754.h
	* sysdeps/mips/nptl/bits/pthreadtypes-arch.h
	* sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
	* sysdeps/nptl/pthread.h
	* sysdeps/riscv/nptl/bits/pthreadtypes-arch.h
	* sysdeps/sh/nptl/bits/pthreadtypes-arch.h
	* sysdeps/sparc/sparc32/ieee754.h
	* sysdeps/unix/sysv/linux/generic/bits/stat.h
	* sysdeps/unix/sysv/linux/generic/bits/statfs.h
	* sysdeps/unix/sysv/linux/sys/acct.h
	* wctype/bits/wctype-wchar.h:
	Include bits/endian.h, not endian.h.

	* sysdeps/unix/sysv/linux/hppa/pthread.h: Don’t include endian.h.

	* sysdeps/mips/ieee754/ieee754.h: Use __LDBL_MANT_DIG__
	in ifdefs, instead of LDBL_MANT_DIG.  Only include float.h
	when __LDBL_MANT_DIG__ is not predefined, in which case
	define __LDBL_MANT_DIG__ to equal LDBL_MANT_DIG.

	* scripts/check-obsolete-constructs.h: Remove most of the
	whitelist entries for endian.h and float.h.
---
 bits/endian.h                                 | 13 -----
 bits/endianness.h                             | 17 +++++++
 ctype/ctype.h                                 |  2 +-
 include/bits/endian.h                         |  1 +
 inet/netinet/in.h                             |  2 +-
 resolv/arpa/nameser_compat.h                  |  2 +-
 scripts/check-obsolete-constructs.py          | 10 +---
 string/Makefile                               |  3 +-
 string/bits/endian.h                          | 48 +++++++++++++++++++
 string/endian.h                               | 39 +++------------
 sysdeps/aarch64/bits/endian.h                 | 30 ------------
 sysdeps/aarch64/bits/endianness.h             | 15 ++++++
 sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h |  2 +-
 sysdeps/alpha/bits/endian.h                   |  7 ---
 sysdeps/alpha/bits/endianness.h               | 11 +++++
 sysdeps/arm/bits/endian.h                     | 10 ----
 sysdeps/arm/bits/endianness.h                 | 15 ++++++
 sysdeps/arm/nptl/bits/pthreadtypes-arch.h     |  2 +-
 sysdeps/csky/bits/endian.h                    |  9 ----
 sysdeps/csky/bits/endianness.h                | 15 ++++++
 sysdeps/csky/nptl/bits/pthreadtypes-arch.h    |  2 +-
 sysdeps/hppa/bits/endian.h                    |  7 ---
 sysdeps/hppa/bits/endianness.h                | 11 +++++
 sysdeps/ia64/bits/endianness.h                | 11 +++++
 sysdeps/ia64/ieee754.h                        |  4 +-
 sysdeps/ieee754/ieee754.h                     |  4 +-
 sysdeps/ieee754/ldbl-128/ieee754.h            |  4 +-
 sysdeps/ieee754/ldbl-128ibm/ieee754.h         |  4 +-
 sysdeps/m68k/bits/endian.h                    |  7 ---
 sysdeps/m68k/bits/endianness.h                | 11 +++++
 sysdeps/m68k/nptl/bits/pthreadtypes-arch.h    |  2 +-
 sysdeps/microblaze/bits/endian.h              | 30 ------------
 sysdeps/microblaze/bits/endianness.h          | 15 ++++++
 .../microblaze/nptl/bits/pthreadtypes-arch.h  |  2 +-
 sysdeps/mips/bits/endian.h                    | 15 ------
 sysdeps/mips/bits/endianness.h                | 16 +++++++
 sysdeps/mips/ieee754/ieee754.h                | 17 ++++---
 sysdeps/mips/nptl/bits/pthreadtypes-arch.h    |  2 +-
 sysdeps/nios2/bits/endian.h                   | 12 -----
 sysdeps/nios2/bits/endianness.h               | 16 +++++++
 sysdeps/nios2/nptl/bits/pthreadtypes-arch.h   |  2 +-
 sysdeps/nptl/pthread.h                        |  2 +-
 sysdeps/powerpc/bits/endian.h                 | 36 --------------
 sysdeps/powerpc/bits/endianness.h             | 16 +++++++
 sysdeps/riscv/bits/endian.h                   |  5 --
 sysdeps/riscv/bits/endianness.h               | 11 +++++
 sysdeps/riscv/nptl/bits/pthreadtypes-arch.h   |  2 +-
 sysdeps/s390/bits/endian.h                    |  7 ---
 sysdeps/s390/bits/endianness.h                | 11 +++++
 sysdeps/sh/bits/endian.h                      | 13 -----
 sysdeps/sh/bits/endianness.h                  | 15 ++++++
 sysdeps/sh/nptl/bits/pthreadtypes-arch.h      |  2 +-
 sysdeps/sparc/bits/endian.h                   | 12 -----
 sysdeps/sparc/bits/endianness.h               | 16 +++++++
 sysdeps/sparc/sparc32/ieee754.h               |  4 +-
 sysdeps/unix/sysv/linux/generic/bits/stat.h   |  2 +-
 sysdeps/unix/sysv/linux/generic/bits/statfs.h |  2 +-
 sysdeps/unix/sysv/linux/hppa/pthread.h        |  1 -
 sysdeps/unix/sysv/linux/ia64/bits/endian.h    |  7 ---
 sysdeps/unix/sysv/linux/powerpc/htm.h         |  2 +-
 sysdeps/unix/sysv/linux/sys/acct.h            |  2 +-
 sysdeps/x86/bits/endian.h                     |  7 ---
 sysdeps/x86/bits/endianness.h                 | 11 +++++
 wctype/bits/wctype-wchar.h                    |  2 +-
 64 files changed, 330 insertions(+), 305 deletions(-)
 delete mode 100644 bits/endian.h
 create mode 100644 bits/endianness.h
 create mode 100644 include/bits/endian.h
 create mode 100644 string/bits/endian.h
 delete mode 100644 sysdeps/aarch64/bits/endian.h
 create mode 100644 sysdeps/aarch64/bits/endianness.h
 delete mode 100644 sysdeps/alpha/bits/endian.h
 create mode 100644 sysdeps/alpha/bits/endianness.h
 delete mode 100644 sysdeps/arm/bits/endian.h
 create mode 100644 sysdeps/arm/bits/endianness.h
 delete mode 100644 sysdeps/csky/bits/endian.h
 create mode 100644 sysdeps/csky/bits/endianness.h
 delete mode 100644 sysdeps/hppa/bits/endian.h
 create mode 100644 sysdeps/hppa/bits/endianness.h
 create mode 100644 sysdeps/ia64/bits/endianness.h
 delete mode 100644 sysdeps/m68k/bits/endian.h
 create mode 100644 sysdeps/m68k/bits/endianness.h
 delete mode 100644 sysdeps/microblaze/bits/endian.h
 create mode 100644 sysdeps/microblaze/bits/endianness.h
 delete mode 100644 sysdeps/mips/bits/endian.h
 create mode 100644 sysdeps/mips/bits/endianness.h
 delete mode 100644 sysdeps/nios2/bits/endian.h
 create mode 100644 sysdeps/nios2/bits/endianness.h
 delete mode 100644 sysdeps/powerpc/bits/endian.h
 create mode 100644 sysdeps/powerpc/bits/endianness.h
 delete mode 100644 sysdeps/riscv/bits/endian.h
 create mode 100644 sysdeps/riscv/bits/endianness.h
 delete mode 100644 sysdeps/s390/bits/endian.h
 create mode 100644 sysdeps/s390/bits/endianness.h
 delete mode 100644 sysdeps/sh/bits/endian.h
 create mode 100644 sysdeps/sh/bits/endianness.h
 delete mode 100644 sysdeps/sparc/bits/endian.h
 create mode 100644 sysdeps/sparc/bits/endianness.h
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/bits/endian.h
 delete mode 100644 sysdeps/x86/bits/endian.h
 create mode 100644 sysdeps/x86/bits/endianness.h

diff --git a/bits/endian.h b/bits/endian.h
deleted file mode 100644
index 45afd4ae47..0000000000
diff --git a/bits/endianness.h b/bits/endianness.h
new file mode 100644
index 0000000000..b83040ddec
--- /dev/null
+++ b/bits/endianness.h
@@ -0,0 +1,17 @@
+/* This file must be overridden for each supported CPU architecture.
+   It should define __BYTE_ORDER to one of the constants defined in
+   string/bits/endian.h, as appropriate for the machine in
+   question.  If floating-point quantities are not stored in the
+   same byte order as integer quantities, it should also define
+   __FLOAT_WORD_ORDER as appropriate.  */
+
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+#error "Machine byte order unknown."
+
+#endif /* bits/endianness.h */
diff --git a/ctype/ctype.h b/ctype/ctype.h
index 78a455e227..3d070d71bf 100644
--- a/ctype/ctype.h
+++ b/ctype/ctype.h
@@ -36,7 +36,7 @@ __BEGIN_DECLS
    endian).  We define the bit value interpretations here dependent on the
    machine's byte order.  */
 
-# include <endian.h>
+# include <bits/endian.h>
 # if __BYTE_ORDER == __BIG_ENDIAN
 #  define _ISbit(bit)	(1 << (bit))
 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
diff --git a/include/bits/endian.h b/include/bits/endian.h
new file mode 100644
index 0000000000..ad614f1c1a
--- /dev/null
+++ b/include/bits/endian.h
@@ -0,0 +1 @@
+#include <string/bits/endian.h>
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index 24caf3c77d..b411ba939c 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -380,9 +380,9 @@ extern uint32_t htonl (uint32_t __hostlong)
 extern uint16_t htons (uint16_t __hostshort)
      __THROW __attribute__ ((__const__));
 
-#include <endian.h>
 
 /* Get machine dependent optimized versions of byte swapping functions.  */
+#include <bits/endian.h>
 #include <bits/byteswap.h>
 #include <bits/uintn-identity.h>
 
diff --git a/resolv/arpa/nameser_compat.h b/resolv/arpa/nameser_compat.h
index f1c390f3b9..37c178b524 100644
--- a/resolv/arpa/nameser_compat.h
+++ b/resolv/arpa/nameser_compat.h
@@ -29,7 +29,7 @@
 #ifndef _ARPA_NAMESER_COMPAT_
 #define	_ARPA_NAMESER_COMPAT_
 
-#include <endian.h>
+#include <bits/endian.h>
 
 /*%
  * Structure for query header.  The order of the fields is machine- and
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index e383a304db..4ef5775932 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -511,7 +511,6 @@ HEADER_ALLOWED_INCLUDES = {
     # mandated: inttypes.h -> stdint.h
     #           tgmath.h   -> complex.h, math.h
     #           threads.h  -> time.h
-    "ctype.h":                     [ "endian.h" ],
     "inttypes.h":                  [ "stdint.h" ],
     "signal.h":                    [ "sys/ucontext.h" ],
     "stdlib.h":                    [ "alloca.h", "sys/types.h" ],
@@ -557,7 +556,7 @@ HEADER_ALLOWED_INCLUDES = {
     "netdb.h":                     [ "netinet/in.h", "rpc/netdb.h" ],
     "arpa/inet.h":                 [ "netinet/in.h" ],
     "net/if.h":                    [ "sys/socket.h", "sys/types.h" ],
-    "netinet/in.h":                [ "endian.h", "sys/socket.h" ],
+    "netinet/in.h":                [ "sys/socket.h" ],
     "netinet/tcp.h":               [ "stdint.h", "sys/socket.h",
                                      "sys/types.h" ],
 
@@ -570,7 +569,7 @@ HEADER_ALLOWED_INCLUDES = {
     "envz.h":                      [ "argz.h", "errno.h" ],
     "fts.h":                       [ "sys/types.h" ],
     "gshadow.h":                   [ "paths.h" ],
-    "ieee754.h":                   [ "endian.h", "float.h" ],
+    "ieee754.h":                   [ "float.h" ],
     "lastlog.h":                   [ "utmp.h" ],
     "libintl.h":                   [ "locale.h" ],
     "link.h":                      [ "dlfcn.h", "elf.h", "sys/types.h" ],
@@ -651,7 +650,6 @@ HEADER_ALLOWED_INCLUDES = {
 
     "arpa/nameser.h":              [ "arpa/nameser_compat.h", "stdint.h",
                                      "sys/param.h", "sys/types.h" ],
-    "arpa/nameser_compat.h":       [ "endian.h" ],
     "net/ethernet.h":              [ "stdint.h", "sys/types.h",
                                      "net/if_ether.h" ],
     "net/if_arp.h":                [ "stdint.h", "sys/socket.h",
@@ -693,15 +691,11 @@ HEADER_ALLOWED_INCLUDES = {
     "bits/fcntl.h":                [ "sys/types.h" ],
     "bits/ipc.h":                  [ "sys/types.h" ],
     "bits/procfs.h":               [ "signal.h", "sys/ucontext.h" ],
-    "bits/pthreadtypes-arch.h":    [ "endian.h" ],
     "bits/sem.h":                  [ "sys/types.h" ],
     "bits/socket.h":               [ "sys/types.h" ],
-    "bits/stat.h":                 [ "endian.h" ],
-    "bits/statfs.h":               [ "endian.h" ],
     "bits/types/res_state.h":      [ "netinet/in.h", "sys/types.h" ],
     "bits/utmp.h":                 [ "paths.h", "sys/time.h", "sys/types.h" ],
     "bits/utmpx.h":                [ "paths.h", "sys/time.h" ],
-    "bits/wctype-wchar.h":         [ "endian.h" ],
 }
 
 # As above, but each group of whitelist entries is only used for
diff --git a/string/Makefile b/string/Makefile
index 38b26a0f8e..3e5721e0f4 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -25,7 +25,8 @@ include ../Makeconfig
 headers		:= string.h bits/string_fortified.h			\
 		   strings.h bits/strings_fortified.h			\
 		   byteswap.h bits/byteswap.h				\
-		   endian.h bits/endian.h bits/uintn-identity.h		\
+		   endian.h bits/endian.h bits/endianness.h		\
+		   bits/uintn-identity.h				\
 		   memory.h argz.h envz.h
 
 routines	:= strcat strchr strcmp strcoll strcpy strcspn		\
diff --git a/string/bits/endian.h b/string/bits/endian.h
new file mode 100644
index 0000000000..ed2ee578c3
--- /dev/null
+++ b/string/bits/endian.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_ENDIAN_H
+#define _BITS_ENDIAN_H 1
+
+/* Definitions for byte order, according to significance of bytes,
+   from low addresses to high addresses.  The value is what you get by
+   putting '4' in the most significant byte, '3' in the second most
+   significant byte, '2' in the second least significant byte, and '1'
+   in the least significant byte, and then writing down one digit for
+   each byte, starting with the byte at the lowest address at the left,
+   and proceeding to the byte with the highest address at the right.  */
+
+#define	__LITTLE_ENDIAN	1234
+#define	__BIG_ENDIAN	4321
+#define	__PDP_ENDIAN	3412
+
+/* This file defines `__BYTE_ORDER' for the particular machine.  */
+#include <bits/endianness.h>
+
+/* Some machines may need to use a different endianness for floating point
+   values.  */
+#ifndef __FLOAT_WORD_ORDER
+# define __FLOAT_WORD_ORDER __BYTE_ORDER
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# define __LONG_LONG_PAIR(HI, LO) LO, HI
+#elif __BYTE_ORDER == __BIG_ENDIAN
+# define __LONG_LONG_PAIR(HI, LO) HI, LO
+#endif
+
+#endif /* bits/endian.h */
diff --git a/string/endian.h b/string/endian.h
index e62b735625..9d6b10ce62 100644
--- a/string/endian.h
+++ b/string/endian.h
@@ -20,42 +20,15 @@
 
 #include <features.h>
 
-/* Definitions for byte order, according to significance of bytes,
-   from low addresses to high addresses.  The value is what you get by
-   putting '4' in the most significant byte, '3' in the second most
-   significant byte, '2' in the second least significant byte, and '1'
-   in the least significant byte, and then writing down one digit for
-   each byte, starting with the byte at the lowest address at the left,
-   and proceeding to the byte with the highest address at the right.  */
-
-#define	__LITTLE_ENDIAN	1234
-#define	__BIG_ENDIAN	4321
-#define	__PDP_ENDIAN	3412
-
-/* This file defines `__BYTE_ORDER' for the particular machine.  */
+/* Get the definitions of __*_ENDIAN, __BYTE_ORDER, and __FLOAT_WORD_ORDER.  */
 #include <bits/endian.h>
 
-/* Some machines may need to use a different endianness for floating point
-   values.  */
-#ifndef __FLOAT_WORD_ORDER
-# define __FLOAT_WORD_ORDER __BYTE_ORDER
-#endif
+#define LITTLE_ENDIAN	__LITTLE_ENDIAN
+#define BIG_ENDIAN	__BIG_ENDIAN
+#define PDP_ENDIAN	__PDP_ENDIAN
+#define BYTE_ORDER	__BYTE_ORDER
 
-#ifdef	__USE_MISC
-# define LITTLE_ENDIAN	__LITTLE_ENDIAN
-# define BIG_ENDIAN	__BIG_ENDIAN
-# define PDP_ENDIAN	__PDP_ENDIAN
-# define BYTE_ORDER	__BYTE_ORDER
-#endif
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-# define __LONG_LONG_PAIR(HI, LO) LO, HI
-#elif __BYTE_ORDER == __BIG_ENDIAN
-# define __LONG_LONG_PAIR(HI, LO) HI, LO
-#endif
-
-
-#if defined __USE_MISC && !defined __ASSEMBLER__
+#ifndef __ASSEMBLER__
 /* Conversion interfaces.  */
 # include <bits/byteswap.h>
 # include <bits/uintn-identity.h>
diff --git a/sysdeps/aarch64/bits/endian.h b/sysdeps/aarch64/bits/endian.h
deleted file mode 100644
index c0a40e082a..0000000000
diff --git a/sysdeps/aarch64/bits/endianness.h b/sysdeps/aarch64/bits/endianness.h
new file mode 100644
index 0000000000..300ebc8f9c
--- /dev/null
+++ b/sysdeps/aarch64/bits/endianness.h
@@ -0,0 +1,15 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* AArch64 has selectable endianness.  */
+#ifdef __AARCH64EB__
+# define __BYTE_ORDER __BIG_ENDIAN
+#else
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
index 8a2a5155db..5b05111be0 100644
--- a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #ifdef __ILP32__
 # define __SIZEOF_PTHREAD_ATTR_T        32
diff --git a/sysdeps/alpha/bits/endian.h b/sysdeps/alpha/bits/endian.h
deleted file mode 100644
index 8a16e14e24..0000000000
diff --git a/sysdeps/alpha/bits/endianness.h b/sysdeps/alpha/bits/endianness.h
new file mode 100644
index 0000000000..69f9a147f6
--- /dev/null
+++ b/sysdeps/alpha/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* Alpha is little-endian.  */
+#define __BYTE_ORDER __LITTLE_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/arm/bits/endian.h b/sysdeps/arm/bits/endian.h
deleted file mode 100644
index f49f6ab1c9..0000000000
diff --git a/sysdeps/arm/bits/endianness.h b/sysdeps/arm/bits/endianness.h
new file mode 100644
index 0000000000..2d671fff66
--- /dev/null
+++ b/sysdeps/arm/bits/endianness.h
@@ -0,0 +1,15 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* ARM has selectable endianness.  */
+#ifdef __ARMEB__
+#define __BYTE_ORDER __BIG_ENDIAN
+#else
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
index 332b288067..734828a0bb 100644
--- a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
@@ -18,7 +18,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #define __SIZEOF_PTHREAD_ATTR_T 36
 #define __SIZEOF_PTHREAD_MUTEX_T 24
diff --git a/sysdeps/csky/bits/endian.h b/sysdeps/csky/bits/endian.h
deleted file mode 100644
index 51df38d8f9..0000000000
diff --git a/sysdeps/csky/bits/endianness.h b/sysdeps/csky/bits/endianness.h
new file mode 100644
index 0000000000..14652f5b37
--- /dev/null
+++ b/sysdeps/csky/bits/endianness.h
@@ -0,0 +1,15 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* C-SKY has selectable endianness.  */
+#ifdef __CSKYBE__
+# define __BYTE_ORDER __BIG_ENDIAN
+#else
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/csky/nptl/bits/pthreadtypes-arch.h b/sysdeps/csky/nptl/bits/pthreadtypes-arch.h
index 5a49114eac..0f737a1654 100644
--- a/sysdeps/csky/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/csky/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #define __SIZEOF_PTHREAD_ATTR_T			36
 #define __SIZEOF_PTHREAD_MUTEX_T		24
diff --git a/sysdeps/hppa/bits/endian.h b/sysdeps/hppa/bits/endian.h
deleted file mode 100644
index 585db0c0fa..0000000000
diff --git a/sysdeps/hppa/bits/endianness.h b/sysdeps/hppa/bits/endianness.h
new file mode 100644
index 0000000000..96fd5ae5ef
--- /dev/null
+++ b/sysdeps/hppa/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* HP-PA is big-endian.  */
+#define __BYTE_ORDER __BIG_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/ia64/bits/endianness.h b/sysdeps/ia64/bits/endianness.h
new file mode 100644
index 0000000000..70c211e569
--- /dev/null
+++ b/sysdeps/ia64/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* IA64 is little-endian.  */
+#define __BYTE_ORDER __LITTLE_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/ia64/ieee754.h b/sysdeps/ia64/ieee754.h
index 3c533812c5..f9ff748528 100644
--- a/sysdeps/ia64/ieee754.h
+++ b/sysdeps/ia64/ieee754.h
@@ -16,11 +16,11 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _IEEE754_H
-
 #define _IEEE754_H 1
+
 #include <features.h>
 
-#include <endian.h>
+#include <bits/endian.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/ieee754/ieee754.h b/sysdeps/ieee754/ieee754.h
index a88cbb6943..b457a10b41 100644
--- a/sysdeps/ieee754/ieee754.h
+++ b/sysdeps/ieee754/ieee754.h
@@ -16,11 +16,11 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _IEEE754_H
-
 #define _IEEE754_H 1
+
 #include <features.h>
 
-#include <endian.h>
+#include <bits/endian.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/ieee754/ldbl-128/ieee754.h b/sysdeps/ieee754/ldbl-128/ieee754.h
index 0f206db928..bda95aca4d 100644
--- a/sysdeps/ieee754/ldbl-128/ieee754.h
+++ b/sysdeps/ieee754/ldbl-128/ieee754.h
@@ -16,11 +16,11 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _IEEE754_H
-
 #define _IEEE754_H 1
+
 #include <features.h>
 
-#include <endian.h>
+#include <bits/endian.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/ieee754/ldbl-128ibm/ieee754.h b/sysdeps/ieee754/ldbl-128ibm/ieee754.h
index d0438c1bd5..eeb9d37e0c 100644
--- a/sysdeps/ieee754/ldbl-128ibm/ieee754.h
+++ b/sysdeps/ieee754/ldbl-128ibm/ieee754.h
@@ -16,11 +16,11 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _IEEE754_H
-
 #define _IEEE754_H 1
+
 #include <features.h>
 
-#include <endian.h>
+#include <bits/endian.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/m68k/bits/endian.h b/sysdeps/m68k/bits/endian.h
deleted file mode 100644
index bf4ecb60a4..0000000000
diff --git a/sysdeps/m68k/bits/endianness.h b/sysdeps/m68k/bits/endianness.h
new file mode 100644
index 0000000000..7e5f0d2969
--- /dev/null
+++ b/sysdeps/m68k/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* m68k is big-endian.  */
+#define __BYTE_ORDER __BIG_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
index 731cdec69a..a8497d6816 100644
--- a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #define __SIZEOF_PTHREAD_ATTR_T 36
 #define __SIZEOF_PTHREAD_MUTEX_T 24
diff --git a/sysdeps/microblaze/bits/endian.h b/sysdeps/microblaze/bits/endian.h
deleted file mode 100644
index 3650f3d564..0000000000
diff --git a/sysdeps/microblaze/bits/endianness.h b/sysdeps/microblaze/bits/endianness.h
new file mode 100644
index 0000000000..c4bb7e5f2e
--- /dev/null
+++ b/sysdeps/microblaze/bits/endianness.h
@@ -0,0 +1,15 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* MicroBlaze has selectable endianness.  */
+#ifdef _BIG_ENDIAN
+# define __BYTE_ORDER __BIG_ENDIAN
+#else
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
index 838e71f4e1..77b4e6c3d2 100644
--- a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 # define _BITS_PTHREADTYPES_ARCH_H	1
 
-# include <endian.h>
+# include <bits/endian.h>
 
 # define __SIZEOF_PTHREAD_ATTR_T         36
 # define __SIZEOF_PTHREAD_MUTEX_T        24
diff --git a/sysdeps/mips/bits/endian.h b/sysdeps/mips/bits/endian.h
deleted file mode 100644
index 126059799d..0000000000
diff --git a/sysdeps/mips/bits/endianness.h b/sysdeps/mips/bits/endianness.h
new file mode 100644
index 0000000000..09e138b89b
--- /dev/null
+++ b/sysdeps/mips/bits/endianness.h
@@ -0,0 +1,16 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* MIPS has selectable endianness.  */
+#ifdef __MIPSEB
+# define __BYTE_ORDER __BIG_ENDIAN
+#endif
+#ifdef __MIPSEL
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/mips/ieee754/ieee754.h b/sysdeps/mips/ieee754/ieee754.h
index d5fb9fce47..e36ef0f5b8 100644
--- a/sysdeps/mips/ieee754/ieee754.h
+++ b/sysdeps/mips/ieee754/ieee754.h
@@ -16,13 +16,16 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _IEEE754_H
-
 #define _IEEE754_H 1
+
 #include <features.h>
 
-#include <endian.h>
+#include <bits/endian.h>
 
-#include <float.h>
+#ifndef __LDBL_MANT_DIG__
+# include <float.h>
+# define __LDBL_MANT_DIG__ LDBL_MANT_DIG
+#endif
 
 __BEGIN_DECLS
 
@@ -127,7 +130,7 @@ union ieee754_double
 
 #define IEEE754_DOUBLE_BIAS	0x3ff /* Added to exponent.  */
 
-#if LDBL_MANT_DIG == 113
+#if __LDBL_MANT_DIG__ == 113
 
 union ieee854_long_double
   {
@@ -184,7 +187,7 @@ union ieee854_long_double
 
 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent.  */
 
-#elif LDBL_MANT_DIG == 64
+#elif __LDBL_MANT_DIG__ == 64
 
 union ieee854_long_double
   {
@@ -253,7 +256,7 @@ union ieee854_long_double
 
 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
 
-#elif LDBL_MANT_DIG == 53
+#elif __LDBL_MANT_DIG__ == 53
 
 union ieee854_long_double
   {
@@ -316,7 +319,7 @@ union ieee854_long_double
 
 #define IEEE854_LONG_DOUBLE_BIAS	0x3ff /* Added to exponent.  */
 
-#endif /* LDBL_MANT_DIG == 53 */
+#endif /* __LDBL_MANT_DIG__ == 53 */
 
 __END_DECLS
 
diff --git a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
index bebee00258..bf69766897 100644
--- a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #if _MIPS_SIM == _ABI64
 # define __SIZEOF_PTHREAD_ATTR_T 56
diff --git a/sysdeps/nios2/bits/endian.h b/sysdeps/nios2/bits/endian.h
deleted file mode 100644
index 164f9e4d78..0000000000
diff --git a/sysdeps/nios2/bits/endianness.h b/sysdeps/nios2/bits/endianness.h
new file mode 100644
index 0000000000..87e66ebd71
--- /dev/null
+++ b/sysdeps/nios2/bits/endianness.h
@@ -0,0 +1,16 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* Nios II has selectable endianness.  */
+#ifdef __nios2_big_endian__
+# define __BYTE_ORDER __BIG_ENDIAN
+#endif
+#ifdef __nios2_little_endian__
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
index 1091e63eac..459c8bcee0 100644
--- a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #define __SIZEOF_PTHREAD_ATTR_T 36
 #define __SIZEOF_PTHREAD_MUTEX_T 24
diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
index 704a3c48d6..e5a7efcb1d 100644
--- a/sysdeps/nptl/pthread.h
+++ b/sysdeps/nptl/pthread.h
@@ -19,10 +19,10 @@
 #define _PTHREAD_H	1
 
 #include <features.h>
-#include <endian.h>
 #include <sched.h>
 #include <time.h>
 
+#include <bits/endian.h>
 #include <bits/pthreadtypes.h>
 #include <bits/setjmp.h>
 #include <bits/wordsize.h>
diff --git a/sysdeps/powerpc/bits/endian.h b/sysdeps/powerpc/bits/endian.h
deleted file mode 100644
index cd8ae4fc50..0000000000
diff --git a/sysdeps/powerpc/bits/endianness.h b/sysdeps/powerpc/bits/endianness.h
new file mode 100644
index 0000000000..3e7735237e
--- /dev/null
+++ b/sysdeps/powerpc/bits/endianness.h
@@ -0,0 +1,16 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* PowerPC has selectable endianness.  */
+#if defined __BIG_ENDIAN__ || defined _BIG_ENDIAN
+# define __BYTE_ORDER __BIG_ENDIAN
+#endif
+#if defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/riscv/bits/endian.h b/sysdeps/riscv/bits/endian.h
deleted file mode 100644
index 4aaf559d4f..0000000000
diff --git a/sysdeps/riscv/bits/endianness.h b/sysdeps/riscv/bits/endianness.h
new file mode 100644
index 0000000000..952d08595a
--- /dev/null
+++ b/sysdeps/riscv/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* RISC-V is little-endian.  */
+#define __BYTE_ORDER __LITTLE_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h b/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h
index e3fecc3208..22dc949158 100644
--- a/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/riscv/nptl/bits/pthreadtypes-arch.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #if __riscv_xlen == 64
 # define __SIZEOF_PTHREAD_ATTR_T 		56
diff --git a/sysdeps/s390/bits/endian.h b/sysdeps/s390/bits/endian.h
deleted file mode 100644
index ac27f0119a..0000000000
diff --git a/sysdeps/s390/bits/endianness.h b/sysdeps/s390/bits/endianness.h
new file mode 100644
index 0000000000..c2d34e1c3e
--- /dev/null
+++ b/sysdeps/s390/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* S/390 is big-endian.  */
+#define __BYTE_ORDER __BIG_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/sh/bits/endian.h b/sysdeps/sh/bits/endian.h
deleted file mode 100644
index 1fef1ff938..0000000000
diff --git a/sysdeps/sh/bits/endianness.h b/sysdeps/sh/bits/endianness.h
new file mode 100644
index 0000000000..45c7c83a63
--- /dev/null
+++ b/sysdeps/sh/bits/endianness.h
@@ -0,0 +1,15 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* SH has selectable endianness.  */
+#ifdef __LITTLE_ENDIAN__
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#else
+#define __BYTE_ORDER __BIG_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
index 64d9d43b3a..3e2d826b56 100644
--- a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
@@ -18,7 +18,7 @@
 #ifndef _BITS_PTHREADTYPES_ARCH_H
 #define _BITS_PTHREADTYPES_ARCH_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 
 #define __SIZEOF_PTHREAD_ATTR_T 36
 #define __SIZEOF_PTHREAD_MUTEX_T 24
diff --git a/sysdeps/sparc/bits/endian.h b/sysdeps/sparc/bits/endian.h
deleted file mode 100644
index 8acfdf5df6..0000000000
diff --git a/sysdeps/sparc/bits/endianness.h b/sysdeps/sparc/bits/endianness.h
new file mode 100644
index 0000000000..0b6f5bf8b2
--- /dev/null
+++ b/sysdeps/sparc/bits/endianness.h
@@ -0,0 +1,16 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* Sparc is big-endian, but v9 supports endian conversion on loads/stores
+   and GCC supports such a mode.  Be prepared.  */
+#ifdef __LITTLE_ENDIAN__
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#else
+# define __BYTE_ORDER __BIG_ENDIAN
+#endif
+
+#endif /* bits/endianness.h */
diff --git a/sysdeps/sparc/sparc32/ieee754.h b/sysdeps/sparc/sparc32/ieee754.h
index 0f206db928..bda95aca4d 100644
--- a/sysdeps/sparc/sparc32/ieee754.h
+++ b/sysdeps/sparc/sparc32/ieee754.h
@@ -16,11 +16,11 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _IEEE754_H
-
 #define _IEEE754_H 1
+
 #include <features.h>
 
-#include <endian.h>
+#include <bits/endian.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
index e5c2650104..2570c8374a 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -23,7 +23,7 @@
 #ifndef _BITS_STAT_H
 #define _BITS_STAT_H	1
 
-#include <endian.h>
+#include <bits/endian.h>
 #include <bits/wordsize.h>
 
 /* 64-bit libc uses the kernel's 'struct stat', accessed via the
diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index 77de4d2fd0..c85187a1de 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -20,7 +20,7 @@
 # error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
 #endif
 
-#include <endian.h>
+#include <bits/endian.h>
 #include <bits/types.h>
 #include <bits/wordsize.h>
 
diff --git a/sysdeps/unix/sysv/linux/hppa/pthread.h b/sysdeps/unix/sysv/linux/hppa/pthread.h
index 45e706c037..78dad4faca 100644
--- a/sysdeps/unix/sysv/linux/hppa/pthread.h
+++ b/sysdeps/unix/sysv/linux/hppa/pthread.h
@@ -19,7 +19,6 @@
 #define _PTHREAD_H	1
 
 #include <features.h>
-#include <endian.h>
 #include <sched.h>
 #include <time.h>
 
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/endian.h b/sysdeps/unix/sysv/linux/ia64/bits/endian.h
deleted file mode 100644
index 98a5e23991..0000000000
diff --git a/sysdeps/unix/sysv/linux/powerpc/htm.h b/sysdeps/unix/sysv/linux/powerpc/htm.h
index 93b6d403b1..f17c979ff0 100644
--- a/sysdeps/unix/sysv/linux/powerpc/htm.h
+++ b/sysdeps/unix/sysv/linux/powerpc/htm.h
@@ -50,7 +50,7 @@
 
 #else
 
-#include <endian.h>
+#include <bits/endian.h>
 
 /* Official HTM intrinsics interface matching GCC, but works
    on older GCC compatible compilers and binutils.
diff --git a/sysdeps/unix/sysv/linux/sys/acct.h b/sysdeps/unix/sysv/linux/sys/acct.h
index 619824fe4b..4c119dafd2 100644
--- a/sysdeps/unix/sysv/linux/sys/acct.h
+++ b/sysdeps/unix/sysv/linux/sys/acct.h
@@ -20,7 +20,7 @@
 
 #include <sys/types.h>
 #include <stdint.h>
-#include <endian.h>
+#include <bits/endian.h>
 #include <bits/types/time_t.h>
 
 __BEGIN_DECLS
diff --git a/sysdeps/x86/bits/endian.h b/sysdeps/x86/bits/endian.h
deleted file mode 100644
index 5a56c726f7..0000000000
diff --git a/sysdeps/x86/bits/endianness.h b/sysdeps/x86/bits/endianness.h
new file mode 100644
index 0000000000..962a9ae4d6
--- /dev/null
+++ b/sysdeps/x86/bits/endianness.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_ENDIANNESS_H
+#define _BITS_ENDIANNESS_H 1
+
+#ifndef _BITS_ENDIAN_H
+# error "Never use <bits/endianness.h> directly; include <endian.h> instead."
+#endif
+
+/* i386/x86_64 are little-endian.  */
+#define __BYTE_ORDER __LITTLE_ENDIAN
+
+#endif /* bits/endianness.h */
diff --git a/wctype/bits/wctype-wchar.h b/wctype/bits/wctype-wchar.h
index 22ae0abdeb..f3851a7830 100644
--- a/wctype/bits/wctype-wchar.h
+++ b/wctype/bits/wctype-wchar.h
@@ -42,7 +42,7 @@ typedef unsigned long int wctype_t;
    endian).  We define the bit value interpretations here dependent on the
    machine's byte order.  */
 
-#  include <endian.h>
+#  include <bits/endian.h>
 #  if __BYTE_ORDER == __BIG_ENDIAN
 #   define _ISwbit(bit)	(1 << (bit))
 #  else /* __BYTE_ORDER == __LITTLE_ENDIAN */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 11/25] Swap sys/poll.h with poll.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
  2019-06-26 17:50 ` [PATCH 20/25] Don’t include sys/time.h from sys/timex.h Zack Weinberg
  2019-06-26 17:50 ` [PATCH 16/25] Limit the set of strings.h functions also exposed in string.h Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-06-26 17:50 ` [PATCH 14/25] Add bits/types/ wrappers for stddef.h and stdarg.h types Zack Weinberg
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

Similarly to (sys/)syslog.h, poll.h is the header standardized by
POSIX, but we had all of its contents in sys/, for historical reasons.
This patch exchanges the contents of the two headers, and adds
multiple-include guards to all of poll.h’s bits headers.

	* io/poll.h: Exchange contents with...
	* io/sys/poll.h: ...this file.  Adjust guard macros.

	* include/poll.h: Exchange contents with...
	* include/sys/poll.h: ...this file.  Adjust guard macros.

	* bits/poll.h, io/bits/poll2.h
	* sysdeps/unix/sysv/linux/bits/poll.h
	* sysdeps/unix/sysv/linux/m68k/bits/poll.h
	* sysdeps/unix/sysv/linux/mips/bits/poll.h
	* sysdeps/unix/sysv/linux/sparc/bits/poll.h:
        Allow inclusion by poll.h, not sys/poll.h.  Add multiple-
        include guards where not already present.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
        Update.
---
 bits/poll.h                               |  9 ++-
 include/poll.h                            | 12 +++-
 include/sys/poll.h                        | 10 +--
 io/bits/poll2.h                           |  9 ++-
 io/{sys => }/poll.h                       |  6 +-
 io/sys/poll.h                             | 79 +----------------------
 scripts/check-obsolete-constructs.py      |  3 +-
 sysdeps/unix/sysv/linux/bits/poll.h       |  9 ++-
 sysdeps/unix/sysv/linux/m68k/bits/poll.h  |  9 ++-
 sysdeps/unix/sysv/linux/mips/bits/poll.h  |  9 ++-
 sysdeps/unix/sysv/linux/sparc/bits/poll.h |  9 ++-
 11 files changed, 61 insertions(+), 103 deletions(-)
 copy io/{sys => }/poll.h (95%)
 rewrite io/sys/poll.h (99%)

diff --git a/bits/poll.h b/bits/poll.h
index c0d8e82a88..a00ede717e 100644
--- a/bits/poll.h
+++ b/bits/poll.h
@@ -15,8 +15,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_POLL_H
-# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#ifndef _BITS_POLL_H
+#define _BITS_POLL_H 1
+
+#ifndef _POLL_H
+# error "Never use <bits/poll.h> directly; include <poll.h> instead."
 #endif
 
 /* Event types that can be polled for.  These bits may be set in `events'
@@ -40,3 +43,5 @@
 #define POLLERR         010             /* Error condition.  */
 #define POLLHUP         020             /* Hung up.  */
 #define POLLNVAL        040             /* Invalid polling request.  */
+
+#endif /* bits/poll.h */
diff --git a/include/poll.h b/include/poll.h
index 75181925aa..c1d6bbbdee 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -1 +1,11 @@
-#include <include/sys/poll.h>
+#ifndef _POLL_H
+# include <io/poll.h>
+
+#ifndef _ISOMAC
+extern int __poll (struct pollfd *__fds, unsigned long int __nfds,
+		   int __timeout);
+libc_hidden_proto (__poll)
+libc_hidden_proto (ppoll)
+#endif
+
+#endif
diff --git a/include/sys/poll.h b/include/sys/poll.h
index a42bc93873..5365742a4b 100644
--- a/include/sys/poll.h
+++ b/include/sys/poll.h
@@ -1,11 +1,3 @@
-#ifndef	_SYS_POLL_H
+#ifndef	_POLL_H
 # include <io/sys/poll.h>
-
-#ifndef _ISOMAC
-extern int __poll (struct pollfd *__fds, unsigned long int __nfds,
-		   int __timeout);
-libc_hidden_proto (__poll)
-libc_hidden_proto (ppoll)
-#endif
-
 #endif
diff --git a/io/bits/poll2.h b/io/bits/poll2.h
index ff38ef7ae1..335953e21e 100644
--- a/io/bits/poll2.h
+++ b/io/bits/poll2.h
@@ -16,8 +16,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_POLL_H
-# error "Never include <bits/poll2.h> directly; use <sys/poll.h> instead."
+#ifndef _BITS_POLL2_H
+#define _BITS_POLL2_H 1
+
+#ifndef _POLL_H
+# error "Never include <bits/poll2.h> directly; use <poll.h> instead."
 #endif
 
 
@@ -79,3 +82,5 @@ ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout,
 #endif
 
 __END_DECLS
+
+#endif /* bits/poll2.h */
diff --git a/io/sys/poll.h b/io/poll.h
similarity index 95%
copy from io/sys/poll.h
copy to io/poll.h
index 6711a1518d..2e18206c75 100644
--- a/io/sys/poll.h
+++ b/io/poll.h
@@ -1,4 +1,4 @@
-/* Compatibility definitions for System V `poll' interface.
+/* System V `poll' interface.
    Copyright (C) 1994-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,8 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef	_SYS_POLL_H
-#define	_SYS_POLL_H	1
+#ifndef	_POLL_H
+#define	_POLL_H	1
 
 #include <features.h>
 
diff --git a/io/sys/poll.h b/io/sys/poll.h
dissimilarity index 99%
index 6711a1518d..43ee82dcbc 100644
--- a/io/sys/poll.h
+++ b/io/sys/poll.h
@@ -?,? +1,3 @@
+#ifndef _POLL_H
+# include <poll.h>
+#endif
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index c437c8e00b..08534348d7 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -530,7 +530,6 @@ HEADER_ALLOWED_INCLUDES = {
     "glob.h":                      [ "sys/cdefs.h" ],
     "langinfo.h":                  [ "nl_types.h" ],
     "mqueue.h":                    [ "fcntl.h", "sys/types.h" ],
-    "poll.h":                      [ "sys/poll.h" ],
     "pthread.h":                   [ "endian.h", "sched.h", "time.h",
                                      "sys/cdefs.h" ],
     "regex.h":                     [ "limits.h", "sys/types.h" ],
@@ -633,12 +632,12 @@ HEADER_ALLOWED_INCLUDES = {
     # the included header did not exist or didn't provide all the
     # necessary definitions.
     "memory.h":                    [ "string.h" ],
-    "poll.h":                      [ "sys/poll.h" ],
     "re_comp.h":                   [ "regex.h" ],
     "sys/bitypes.h":               [ "sys/types.h" ],
     "sys/dir.h":                   [ "dirent.h" ],
     "sys/errno.h":                 [ "errno.h" ],
     "sys/fcntl.h":                 [ "fcntl.h" ],
+    "sys/poll.h":                  [ "poll.h" ],
     "sys/signal.h":                [ "signal.h" ],
     "sys/syslog.h":                [ "syslog.h" ],
     "sys/termios.h":               [ "termios.h" ],
diff --git a/sysdeps/unix/sysv/linux/bits/poll.h b/sysdeps/unix/sysv/linux/bits/poll.h
index 50f0111fe5..6ea656a488 100644
--- a/sysdeps/unix/sysv/linux/bits/poll.h
+++ b/sysdeps/unix/sysv/linux/bits/poll.h
@@ -15,8 +15,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_POLL_H
-# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#ifndef _BITS_POLL_H
+#define _BITS_POLL_H 1
+
+#ifndef _POLL_H
+# error "Never use <bits/poll.h> directly; include <poll.h> instead."
 #endif
 
 /* Event types that can be polled for.  These bits may be set in `events'
@@ -47,3 +50,5 @@
 #define POLLERR		0x008		/* Error condition.  */
 #define POLLHUP		0x010		/* Hung up.  */
 #define POLLNVAL	0x020		/* Invalid polling request.  */
+
+#endif /* bits/poll.h */
diff --git a/sysdeps/unix/sysv/linux/m68k/bits/poll.h b/sysdeps/unix/sysv/linux/m68k/bits/poll.h
index 8833255c20..f3713d2ede 100644
--- a/sysdeps/unix/sysv/linux/m68k/bits/poll.h
+++ b/sysdeps/unix/sysv/linux/m68k/bits/poll.h
@@ -15,8 +15,11 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_POLL_H
-# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#ifndef _BITS_POLL_H
+#define _BITS_POLL_H 1
+
+#ifndef _POLL_H
+# error "Never use <bits/poll.h> directly; include <poll.h> instead."
 #endif
 
 /* Event types that can be polled for.  These bits may be set in `events'
@@ -47,3 +50,5 @@
 #define POLLERR		0x008		/* Error condition.  */
 #define POLLHUP		0x010		/* Hung up.  */
 #define POLLNVAL	0x020		/* Invalid polling request.  */
+
+#endif /* bits/poll.h */
diff --git a/sysdeps/unix/sysv/linux/mips/bits/poll.h b/sysdeps/unix/sysv/linux/mips/bits/poll.h
index 8833255c20..f3713d2ede 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/poll.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/poll.h
@@ -15,8 +15,11 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_POLL_H
-# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#ifndef _BITS_POLL_H
+#define _BITS_POLL_H 1
+
+#ifndef _POLL_H
+# error "Never use <bits/poll.h> directly; include <poll.h> instead."
 #endif
 
 /* Event types that can be polled for.  These bits may be set in `events'
@@ -47,3 +50,5 @@
 #define POLLERR		0x008		/* Error condition.  */
 #define POLLHUP		0x010		/* Hung up.  */
 #define POLLNVAL	0x020		/* Invalid polling request.  */
+
+#endif /* bits/poll.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/poll.h b/sysdeps/unix/sysv/linux/sparc/bits/poll.h
index c2c0da927f..5070cf4a55 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/poll.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/poll.h
@@ -15,8 +15,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_POLL_H
-# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#ifndef _BITS_POLL_H
+#define _BITS_POLL_H 1
+
+#ifndef _POLL_H
+# error "Never use <bits/poll.h> directly; include <poll.h> instead."
 #endif
 
 /* Event types that can be polled for.  These bits may be set in `events'
@@ -47,3 +50,5 @@
 #define POLLERR		0x008		/* Error condition.  */
 #define POLLHUP		0x010		/* Hung up.  */
 #define POLLNVAL	0x020		/* Invalid polling request.  */
+
+#endif /* bits/poll.h */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 14/25] Add bits/types/ wrappers for stddef.h and stdarg.h types.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (2 preceding siblings ...)
  2019-06-26 17:50 ` [PATCH 11/25] Swap sys/poll.h with poll.h Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-06-26 17:50 ` [PATCH 13/25] Split up endian.h to minimize exposure of BYTE_ORDER Zack Weinberg
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

We rely on the compiler's stddef.h and stdarg.h to define size_t,
ptrdiff_t, wchar_t, NULL, and __gnuc_va_list, and to implement a
convention that allows us to request the definition of a specific one:
for instance

    #define __need_size_t
    #include <stddef.h>

is expected to define size_t but not any of the other things stddef.h
defines.

This patch hides that convention behind a set of bits/types/ headers,
which allows check-obsolete-constructs.py to verify that none of our
headers include these headers unconditionally.  (Both of them define
at least one item in the user namespace that no other header is
supposed to expose.)  It will also facilitate coping with compilers
that don’t implement the __need convention.  (That scenario is not
hypothetical, see the next patch.)

Only public headers use the new bits headers.  Non-public headers and
.c files in our codebase, that were formerly defining __need macros,
now just include stddef.h and/or stdarg.h without any __need macros.
A few files didn’t need to be including stddef.h / stdarg.h at all.

Uses of NULL in public headers that aren’t expected to define NULL
are changed to a bare 0.  bits/NULL.h is only used by headers that
are expected to define NULL.

malloc.h and printf.h were, in fact, including stddef.h and/or
stdarg.h unconditionally; they no longer do that.  This broke a few of
our test cases, which are fixed by adding appropriate inclusions to
the relevant .c files.

	* stdlib/bits/NULL.h
	* stdlib/bits/types/__va_list.h
	* stdlib/bits/types/ptrdiff_t.h
	* stdlib/bits/types/size_t.h
	* stdlib/bits/types/va_list.h
	* stdlib/bits/types/wchar_t.h:
	New headers defining a single type or macro each.
	* stdlib/Makefile: Install new headers.
	* include/bits/NULL.h
	* include/bits/types/__va_list.h
	* include/bits/types/ptrdiff_t.h
	* include/bits/types/size_t.h
	* include/bits/types/va_list.h
	* include/bits/types/wchar_t.h:
	New wrapper headers.

	* malloc/malloc.h: Don’t include stdio.h or stddef.h.
	Include bits/NULL.h, bits/types/size_t.h, bits/types/ptrdiff_t.h,
	and bits/types/FILE.h.
	* stdio-common/printf.h: Don’t include stddef.h or stdarg.h.
	Include bits/types/size_t.h, bits/types/wchar_t.h, and
	bits/types/__va_list.h.  Use __gnuc_va_list instead of va_list
	in prototypes.

	* libio/bits/types/struct_FILE.h: Include bits/types/size_t.h.
	* misc/sys/param.h: Include features.h.

	* sysvipc/sys/msg.h: Include bits/msq.h after all bits/types/ headers.
	* sysvipc/sys/sem.h: Include bits/sem.h after all bits/types/ headers.
	* sysvipc/sys/shm.h: Include bits/shm.h after all bits/types/ headers.

	* hurd/hurd/signal.h: Don’t use NULL.
	* hurd/hurd/ioctl.h: Don’t include stdarg.h.
	* hurd/hurd/userlink.h: Don’t include stddef.h.  Don’t use NULL.
	* intl/libintl.h: Don’t include stddef.h.  Don’t use NULL.

	* intl/gettext.c, intl/ngettext.c: Include stddef.h
	unconditionally.  Don’t define any __need macros first.
	Don’t include stdlib.h.

	* sysdeps/posix/sigignore.c:, sysdeps/posix/sigset.c:
	Don’t include errno.h or string.h.

	* malloc/tst-malloc-thread-fail.c: Include stddef.h.
	* malloc/tst-malloc_info.c: Include stdio.h.
	* stdio-common/tst-vfprintf-user-type.c: Include stdarg.h.
	* string/tst-cmp.c: Include stdio.h.

	* debug/wcpcpy_chk.c, iconv/loop.c, iconv/skeleton.c
	* signal/sighold.c, signal/sigrelse.c, stdio-common/tempname.c
	* sysdeps/generic/ldsodefs.h, sysdeps/nptl/libc-lock.h
	* sysdeps/nptl/libc-lockP.h, sysdeps/posix/waitid.c
	* wcsmbs/wcstol_l.c, wcsmbs/wcstoll_l.c, wcsmbs/wcstoul_l.c
	* wcsmbs/wcstoull_l.c, sysdeps/posix/sigignore.c
	* sysdeps/posix/sigset.c: Don’t define __need macros before
	including stddef.h.

	* bits/socket.h, bits/types/stack_t.h, dirent/dirent.h
	* dlfcn/dlfcn.h, gmon/sys/profil.h, grp/grp.h, gshadow/gshadow.h
        * hurd/hurd/signal.h, hurd/hurd/sigpreempt.h, iconv/gconv.h
        * include/set-hooks.h, include/stdio.h, inet/aliases.h
        * io/sys/sendfile.h, libio/stdio.h, misc/bits/types/struct_iovec.h
	* misc/search.h, misc/sys/mman.h, misc/syslog.h, posix/glob.h
	* posix/sched.h, posix/sys/types.h, posix/unistd.h
	* posix/wordexp.h, pwd/pwd.h, shadow/shadow.h, signal/signal.h
        * socket/sys/socket.h, stdlib/alloca.h, stdlib/monetary.h
	* stdlib/stdlib.h, stdlib/sys/random.h, string/string.h
	* string/strings.h, sunrpc/rpc/netdb.h
	* sysdeps/htl/bits/types/struct___pthread_attr.h
	* sysdeps/mach/hurd/bits/socket.h
	* sysdeps/unix/sysv/linux/bits/socket.h
	* sysdeps/unix/sysv/linux/bits/types/stack_t.h
	* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
	* sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h
	* sysdeps/unix/sysv/linux/scsi/sg.h
	* sysdeps/unix/sysv/linux/sys/sysctl.h
	* sysvipc/sys/msg.h, sysvipc/sys/sem.h, sysvipc/sys/shm.h
        * time/time.h, wcsmbs/uchar.h, wcsmbs/wchar.h:
	Use bits/types/size_t.h instead of __need_size_t.

	* iconv/gconv.h, iconv/iconv.h, libio/libio.h
	* stdlib/inttypes.h, stdlib/stdlib.h, wcsmbs/wchar.h:
	Use bits/types/wchar_t.h instead of __need_wchar_t.

	* libio/stdio.h, locale/locale.h, misc/sys/param.h
	* posix/sched.h, posix/unistd.h, stdlib/stdlib.h
	* string/string.h, sysdeps/unix/sysv/linux/bits/sigcontext.h
	* time/time.h, wcsmbs/wchar.h: Use bits/NULL.h instead of __need_NULL.

	* libio/stdio.h, misc/err.h: Use bits/types/__va_list.h instead
	of __need___va_list.
	* libio/stdio.h: Use bits/types/va_list.h instead of manually
	defining va_list.

	* hurd/hurd/userlink.h, misc/sys/mman.h, posix/sched.h
	* sysdeps/mach/hurd/bits/socket.h
	* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
	* wcsmbs/wchar.h: Reorganize includes; no semantic effect.
	* stdlib/stdlib.h: Normalize format of multiple include guard.
	* sysdeps/unix/sysv/linux/bits/sigcontext.h: Annotate workarounds
	for kernel header bugs.

	* sysdeps/unix/sysv/linux/aarch64/sys/user.h
	* sysdeps/unix/sysv/linux/arm/sys/user.h
	* sysdeps/unix/sysv/linux/m68k/sys/user.h
	* sysdeps/unix/sysv/linux/microblaze/sys/user.h
	* sysdeps/unix/sysv/linux/nios2/sys/user.h
	* sysdeps/unix/sysv/linux/s390/sys/user.h
	* sysdeps/unix/sysv/linux/x86/sys/user.h
	Include features.h.

	* sysdeps/unix/sysv/linux/alpha/sys/user.h
	* sysdeps/unix/sysv/linux/ia64/sys/user.h
	* sysdeps/unix/sysv/linux/mips/sys/user.h
	* sysdeps/unix/sysv/linux/powerpc/sys/user.h
	* sysdeps/unix/sysv/linux/sh/sys/user.h
	* sysdeps/unix/sysv/linux/sparc/sys/user.h
	Include features.h and bits/types/size_t.h, in that order.
	Include kernel headers, if any, after those two.
	Don’t include stddef.h or sys/types.h.

	* scripts/check-obsolete-constructs.py
	(UNIVERSAL_ALLOWED_INCLUDES): Remove stddef.h and stdarg.h.
	(HEADER_ALLOWED_INCLUDES): Update.
---
 bits/socket.h                                 |  4 +---
 bits/types/stack_t.h                          |  3 +--
 debug/wcpcpy_chk.c                            |  2 --
 dirent/dirent.h                               |  3 +--
 dlfcn/dlfcn.h                                 |  4 ++--
 grp/grp.h                                     |  7 +-----
 gshadow/gshadow.h                             |  4 +---
 hurd/hurd/ioctl.h                             |  2 --
 hurd/hurd/signal.h                            | 15 +++++--------
 hurd/hurd/sigpreempt.h                        |  3 +--
 hurd/hurd/userlink.h                          | 18 ++++++---------
 iconv/gconv.h                                 |  6 ++---
 iconv/iconv.h                                 |  3 +--
 iconv/loop.c                                  |  1 -
 iconv/skeleton.c                              |  2 --
 include/bits/NULL.h                           |  1 +
 include/bits/types/__va_list.h                |  1 +
 include/bits/types/ptrdiff_t.h                |  1 +
 include/bits/types/size_t.h                   |  1 +
 include/bits/types/va_list.h                  |  1 +
 include/bits/types/wchar_t.h                  |  1 +
 include/set-hooks.h                           |  3 +--
 include/stdio.h                               |  4 +---
 intl/gettext.c                                |  7 +-----
 intl/libintl.h                                |  8 ++-----
 intl/ngettext.c                               |  7 +-----
 libio/bits/types/struct_FILE.h                |  1 +
 libio/libio.h                                 |  4 +---
 libio/stdio.h                                 | 19 ++++------------
 locale/locale.h                               |  3 +--
 malloc/malloc.h                               |  7 ++++--
 malloc/tst-malloc-thread-fail.c               |  1 +
 malloc/tst-malloc_info.c                      |  1 +
 misc/bits/types/struct_iovec.h                |  3 +--
 misc/err.h                                    |  6 +----
 misc/search.h                                 |  3 +--
 misc/sys/mman.h                               |  8 +++----
 misc/sys/param.h                              |  4 ++--
 misc/syslog.h                                 |  3 +--
 posix/glob.h                                  |  3 +--
 posix/sched.h                                 |  9 +++-----
 posix/sys/types.h                             |  4 +---
 posix/unistd.h                                |  6 ++---
 posix/wordexp.h                               |  3 +--
 pwd/pwd.h                                     |  4 +---
 scripts/check-obsolete-constructs.py          | 17 ++++++--------
 shadow/shadow.h                               |  4 +---
 signal/sighold.c                              |  1 -
 signal/signal.h                               |  4 +---
 signal/sigrelse.c                             |  1 -
 socket/sys/socket.h                           |  3 +--
 stdio-common/printf.h                         | 11 ++++------
 stdio-common/tempname.c                       |  1 -
 stdio-common/tst-vfprintf-user-type.c         |  1 +
 stdlib/Makefile                               |  4 +++-
 stdlib/alloca.h                               |  3 +--
 stdlib/bits/NULL.h                            |  8 +++++++
 stdlib/bits/types/__va_list.h                 |  9 ++++++++
 stdlib/bits/types/ptrdiff_t.h                 |  9 ++++++++
 stdlib/bits/types/size_t.h                    |  9 ++++++++
 stdlib/bits/types/va_list.h                   | 15 +++++++++++++
 stdlib/bits/types/wchar_t.h                   |  9 ++++++++
 stdlib/inttypes.h                             |  3 +--
 stdlib/monetary.h                             |  3 +--
 stdlib/stdlib.h                               | 11 ++++------
 string/string.h                               |  6 ++---
 string/strings.h                              |  3 +--
 string/tst-cmp.c                              |  1 +
 sunrpc/rpc/netdb.h                            |  3 +--
 sysdeps/generic/ldsodefs.h                    |  2 --
 .../htl/bits/types/struct___pthread_attr.h    |  4 +---
 sysdeps/mach/hurd/bits/socket.h               |  5 ++---
 sysdeps/nptl/libc-lock.h                      |  1 -
 sysdeps/nptl/libc-lockP.h                     |  1 -
 sysdeps/posix/sigignore.c                     |  3 ---
 sysdeps/posix/sigset.c                        |  3 ---
 sysdeps/posix/waitid.c                        |  1 -
 sysdeps/unix/sysv/linux/aarch64/sys/user.h    |  2 ++
 sysdeps/unix/sysv/linux/alpha/sys/user.h      |  8 ++++---
 sysdeps/unix/sysv/linux/arm/sys/user.h        |  2 ++
 sysdeps/unix/sysv/linux/bits/sigcontext.h     | 11 ++++++----
 sysdeps/unix/sysv/linux/bits/socket.h         |  3 +--
 sysdeps/unix/sysv/linux/bits/types/stack_t.h  |  3 +--
 .../unix/sysv/linux/ia64/bits/sigcontext.h    |  5 ++---
 sysdeps/unix/sysv/linux/ia64/sys/user.h       |  2 +-
 sysdeps/unix/sysv/linux/m68k/sys/user.h       |  2 ++
 sysdeps/unix/sysv/linux/microblaze/sys/user.h |  2 ++
 .../unix/sysv/linux/mips/bits/types/stack_t.h |  3 +--
 sysdeps/unix/sysv/linux/mips/sys/user.h       |  4 +++-
 sysdeps/unix/sysv/linux/nios2/sys/user.h      |  2 ++
 sysdeps/unix/sysv/linux/powerpc/sys/user.h    |  4 ++--
 sysdeps/unix/sysv/linux/s390/sys/user.h       |  2 ++
 sysdeps/unix/sysv/linux/scsi/sg.h             |  4 +---
 sysdeps/unix/sysv/linux/sh/sys/user.h         |  5 ++++-
 sysdeps/unix/sysv/linux/sparc/sys/user.h      |  3 ++-
 sysdeps/unix/sysv/linux/sys/sysctl.h          |  4 ++--
 sysdeps/unix/sysv/linux/x86/sys/user.h        |  2 ++
 sysvipc/sys/msg.h                             | 10 ++++-----
 sysvipc/sys/sem.h                             | 11 +++++-----
 sysvipc/sys/shm.h                             | 10 ++++-----
 time/time.h                                   | 10 ++++-----
 wcsmbs/uchar.h                                |  4 +---
 wcsmbs/wchar.h                                | 22 ++++++++-----------
 wcsmbs/wcstol_l.c                             |  1 -
 wcsmbs/wcstoll_l.c                            |  1 -
 wcsmbs/wcstoul_l.c                            |  1 -
 wcsmbs/wcstoull_l.c                           |  1 -
 107 files changed, 233 insertions(+), 274 deletions(-)
 create mode 100644 include/bits/NULL.h
 create mode 100644 include/bits/types/__va_list.h
 create mode 100644 include/bits/types/ptrdiff_t.h
 create mode 100644 include/bits/types/size_t.h
 create mode 100644 include/bits/types/va_list.h
 create mode 100644 include/bits/types/wchar_t.h
 create mode 100644 stdlib/bits/NULL.h
 create mode 100644 stdlib/bits/types/__va_list.h
 create mode 100644 stdlib/bits/types/ptrdiff_t.h
 create mode 100644 stdlib/bits/types/size_t.h
 create mode 100644 stdlib/bits/types/va_list.h
 create mode 100644 stdlib/bits/types/wchar_t.h

diff --git a/bits/socket.h b/bits/socket.h
index 6687a47740..8f5b85fa98 100644
--- a/bits/socket.h
+++ b/bits/socket.h
@@ -23,11 +23,9 @@
 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
 #endif
 
-#define	__need_size_t
-#include <stddef.h>
-
 #include <bits/wordsize.h>
 #include <bits/types.h>
+#include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 
 /* Types of sockets.  */
diff --git a/bits/types/stack_t.h b/bits/types/stack_t.h
index c9df26c931..5427cb98a0 100644
--- a/bits/types/stack_t.h
+++ b/bits/types/stack_t.h
@@ -19,8 +19,7 @@
 #ifndef __stack_t_defined
 #define __stack_t_defined 1
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* Structure describing a signal stack.  */
 typedef struct
diff --git a/debug/wcpcpy_chk.c b/debug/wcpcpy_chk.c
index 0dd62560f2..2be0e2c7f4 100644
--- a/debug/wcpcpy_chk.c
+++ b/debug/wcpcpy_chk.c
@@ -17,8 +17,6 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <wchar.h>
-
-#define __need_ptrdiff_t
 #include <stddef.h>
 
 
diff --git a/dirent/dirent.h b/dirent/dirent.h
index 9639ae96d4..3602ed8d40 100644
--- a/dirent/dirent.h
+++ b/dirent/dirent.h
@@ -233,8 +233,7 @@ extern int dirfd (DIR *__dirp) __THROW __nonnull ((1));
 #  endif
 # endif
 
-# define __need_size_t
-# include <stddef.h>
+# include <bits/types/size_t.h>
 
 /* Scan the directory DIR, calling SELECTOR on each directory entry.
    Entries for which SELECT returns nonzero are individually malloc'd,
diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index c550371999..877ec340a2 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -20,8 +20,8 @@
 #define	_DLFCN_H 1
 
 #include <features.h>
-#define __need_size_t
-#include <stddef.h>
+
+#include <bits/types/size_t.h>
 
 /* Collect various system dependent definitions and declarations.  */
 #include <bits/dlfcn.h>
diff --git a/grp/grp.h b/grp/grp.h
index d8f7683d1f..95d7414a80 100644
--- a/grp/grp.h
+++ b/grp/grp.h
@@ -27,9 +27,7 @@
 __BEGIN_DECLS
 
 #include <bits/types.h>
-
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* For the Single Unix specification we must define this type here.  */
 #if defined __USE_XOPEN || defined __USE_XOPEN2K
@@ -167,9 +165,6 @@ extern int fgetgrent_r (FILE *__restrict __stream,
 
 #ifdef	__USE_MISC
 
-# define __need_size_t
-# include <stddef.h>
-
 /* Set the group set for the current user to GROUPS (N of them).  */
 extern int setgroups (size_t __n, const __gid_t *__groups) __THROW;
 
diff --git a/gshadow/gshadow.h b/gshadow/gshadow.h
index c1998083e6..695469ff80 100644
--- a/gshadow/gshadow.h
+++ b/gshadow/gshadow.h
@@ -23,9 +23,7 @@
 #include <features.h>
 #include <paths.h>
 #include <bits/types/FILE.h>
-
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* Path to the user database files.  */
 #define	GSHADOW _PATH_GSHADOW
diff --git a/hurd/hurd/ioctl.h b/hurd/hurd/ioctl.h
index aea2fec1aa..7b5f211d56 100644
--- a/hurd/hurd/ioctl.h
+++ b/hurd/hurd/ioctl.h
@@ -19,8 +19,6 @@
 #ifndef	_HURD_IOCTL_H
 #define	_HURD_IOCTL_H	1
 
-#define	__need___va_list
-#include <stdarg.h>
 #include <bits/ioctls.h>
 #include <mach/port.h>
 
diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 308124c90b..73de52dfc3 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -21,10 +21,6 @@
 #define	_HURD_SIGNAL_H	1
 #include <features.h>
 
-#define __need_size_t
-#define __need_NULL
-#include <stddef.h>
-
 #include <mach/mach_types.h>
 #include <mach/port.h>
 #include <mach/message.h>
@@ -34,6 +30,7 @@
 #include <bits/types/error_t.h>
 #include <bits/types/stack_t.h>
 #include <bits/types/sigset_t.h>
+#include <bits/types/size_t.h>
 #include <bits/sigaction.h>
 #include <hurd/msg.h>
 
@@ -138,7 +135,7 @@ extern struct hurd_sigstate *_hurd_self_sigstate (void)
 _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
 _hurd_self_sigstate (void)
 {
-  if (THREAD_SELF->_hurd_sigstate == NULL)
+  if (! THREAD_SELF->_hurd_sigstate)
     THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ());
   return THREAD_SELF->_hurd_sigstate;
 }
@@ -187,11 +184,11 @@ _hurd_critical_section_lock (void)
 #ifdef __LIBC_NO_TLS
   if (__LIBC_NO_TLS ())
     /* TLS is currently initializing, no need to enter critical section.  */
-    return NULL;
+    return 0;
 #endif
 
   ss = THREAD_SELF->_hurd_sigstate;
-  if (ss == NULL)
+  if (! ss)
     {
       /* The thread variable is unset; this must be the first time we've
 	 asked for it.  In this case, the critical section flag cannot
@@ -202,7 +199,7 @@ _hurd_critical_section_lock (void)
 
   if (! __spin_try_lock (&ss->critical_section_lock))
     /* We are already in a critical section, so do nothing.  */
-    return NULL;
+    return 0;
 
   /* With the critical section lock held no signal handler will run.
      Return our sigstate pointer; this will be passed to
@@ -219,7 +216,7 @@ extern void _hurd_critical_section_unlock (void *our_lock);
 _HURD_SIGNAL_H_EXTERN_INLINE void
 _hurd_critical_section_unlock (void *our_lock)
 {
-  if (our_lock == NULL)
+  if (! our_lock)
     /* The critical section lock was held when we began.  Do nothing.  */
     return;
   else
diff --git a/hurd/hurd/sigpreempt.h b/hurd/hurd/sigpreempt.h
index 44eb614e13..aa61ad9b87 100644
--- a/hurd/hurd/sigpreempt.h
+++ b/hurd/hurd/sigpreempt.h
@@ -19,8 +19,7 @@
 #ifndef	_HURD_SIGPREEMPT_H
 
 #define	_HURD_SIGPREEMPT_H	1
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 #include <errno.h>
 #include <bits/types/error_t.h>
 #include <signal.h>		/* For sighandler_t, SIG_ERR.  */
diff --git a/hurd/hurd/userlink.h b/hurd/hurd/userlink.h
index d70438a48f..0fde97e84b 100644
--- a/hurd/hurd/userlink.h
+++ b/hurd/hurd/userlink.h
@@ -17,20 +17,16 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef	_HURD_USERLINK_H
-
 #define	_HURD_USERLINK_H	1
-#include <features.h>
 
-#define __need_NULL
-#include <stddef.h>
+#include <features.h>
+#include <setjmp.h>
 
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 # if IS_IN (libc)
 #  include <hurd/signal.h>
 # endif
 #endif
-#include <setjmp.h>
-
 
 /* This structure records a link in two doubly-linked lists.
    We call these the per-resource user list and the per-thread
@@ -156,11 +152,11 @@ _hurd_userlink_move (struct hurd_userlink *new_link,
 {
   *new_link = *link;
 
-  if (new_link->resource.next != NULL)
+  if (new_link->resource.next)
     new_link->resource.next->resource.prevp = &new_link->resource.next;
   *new_link->resource.prevp = new_link;
 
-  if (new_link->thread.next != NULL)
+  if (new_link->thread.next)
     new_link->thread.next->thread.prevp = &new_link->thread.next;
   *new_link->thread.prevp = new_link;
 }
@@ -180,13 +176,13 @@ extern int _hurd_userlink_clear (struct hurd_userlink **chainp);
 _HURD_USERLINK_H_EXTERN_INLINE int
 _hurd_userlink_clear (struct hurd_userlink **chainp)
 {
-  if (*chainp == NULL)
+  if (! *chainp)
     return 1;
 
   /* Detach the chain of current users from the cell.  The last user to
      remove his link from that chain will deallocate the old resource.  */
-  (*chainp)->resource.prevp = NULL;
-  *chainp = NULL;
+  (*chainp)->resource.prevp = 0;
+  *chainp = 0;
   return 0;
 }
 # endif
diff --git a/iconv/gconv.h b/iconv/gconv.h
index 7ce79bcbf6..05746e4707 100644
--- a/iconv/gconv.h
+++ b/iconv/gconv.h
@@ -24,12 +24,10 @@
 
 #include <features.h>
 #include <bits/types/__mbstate_t.h>
+#include <bits/types/size_t.h>
+#include <bits/types/wchar_t.h>
 #include <bits/types/wint_t.h>
 
-#define __need_size_t
-#define __need_wchar_t
-#include <stddef.h>
-
 /* ISO 10646 value used to signal invalid value.  */
 #define __UNKNOWN_10646_CHAR	((wchar_t) 0xfffd)
 
diff --git a/iconv/iconv.h b/iconv/iconv.h
index 9585ec268e..dded7ef45b 100644
--- a/iconv/iconv.h
+++ b/iconv/iconv.h
@@ -19,8 +19,7 @@
 #define _ICONV_H	1
 
 #include <features.h>
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 
 __BEGIN_DECLS
diff --git a/iconv/loop.c b/iconv/loop.c
index fa98c1a521..e9cea355e5 100644
--- a/iconv/loop.c
+++ b/iconv/loop.c
@@ -54,7 +54,6 @@
 #include <string.h>
 #include <wchar.h>
 #include <sys/param.h>		/* For MIN.  */
-#define __need_size_t
 #include <stddef.h>
 #include <libc-diag.h>
 
diff --git a/iconv/skeleton.c b/iconv/skeleton.c
index 7c12975de3..c5447708ec 100644
--- a/iconv/skeleton.c
+++ b/iconv/skeleton.c
@@ -140,8 +140,6 @@
 #include <assert.h>
 #include <iconv/gconv_int.h>
 #include <string.h>
-#define __need_size_t
-#define __need_NULL
 #include <stddef.h>
 
 #ifndef STATIC_GCONV
diff --git a/include/bits/NULL.h b/include/bits/NULL.h
new file mode 100644
index 0000000000..0584572ed3
--- /dev/null
+++ b/include/bits/NULL.h
@@ -0,0 +1 @@
+#include <stdlib/bits/NULL.h>
diff --git a/include/bits/types/__va_list.h b/include/bits/types/__va_list.h
new file mode 100644
index 0000000000..436e6ed823
--- /dev/null
+++ b/include/bits/types/__va_list.h
@@ -0,0 +1 @@
+#include <stdlib/bits/types/__va_list.h>
diff --git a/include/bits/types/ptrdiff_t.h b/include/bits/types/ptrdiff_t.h
new file mode 100644
index 0000000000..d16c0d3c2b
--- /dev/null
+++ b/include/bits/types/ptrdiff_t.h
@@ -0,0 +1 @@
+#include <stdlib/bits/types/ptrdiff_t.h>
diff --git a/include/bits/types/size_t.h b/include/bits/types/size_t.h
new file mode 100644
index 0000000000..feaa04363f
--- /dev/null
+++ b/include/bits/types/size_t.h
@@ -0,0 +1 @@
+#include <stdlib/bits/types/size_t.h>
diff --git a/include/bits/types/va_list.h b/include/bits/types/va_list.h
new file mode 100644
index 0000000000..dbc749a752
--- /dev/null
+++ b/include/bits/types/va_list.h
@@ -0,0 +1 @@
+#include <stdlib/bits/types/va_list.h>
diff --git a/include/bits/types/wchar_t.h b/include/bits/types/wchar_t.h
new file mode 100644
index 0000000000..343bd5855d
--- /dev/null
+++ b/include/bits/types/wchar_t.h
@@ -0,0 +1 @@
+#include <stdlib/bits/types/wchar_t.h>
diff --git a/include/set-hooks.h b/include/set-hooks.h
index a0c5101e2d..da24c28435 100644
--- a/include/set-hooks.h
+++ b/include/set-hooks.h
@@ -19,8 +19,7 @@
 #ifndef _SET_HOOKS_H
 #define _SET_HOOKS_H 1
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 #include <sys/cdefs.h>
 #include <libc-symbols.h>
 
diff --git a/include/stdio.h b/include/stdio.h
index 5302e61024..c72d410013 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -81,9 +81,7 @@ libc_hidden_proto (__isoc99_vfscanf)
 extern FILE *__new_tmpfile (void);
 extern FILE *__old_tmpfile (void);
 
-#  define __need_size_t
-#  include <stddef.h>
-
+#  include <bits/types/size_t.h>
 #  include <bits/types/wint_t.h>
 
 /* Generate a unique file name (and possibly open it).  */
diff --git a/intl/gettext.c b/intl/gettext.c
index 5217a589fc..a8240cfb71 100644
--- a/intl/gettext.c
+++ b/intl/gettext.c
@@ -18,12 +18,7 @@
 # include <config.h>
 #endif
 
-#ifdef _LIBC
-# define __need_NULL
-# include <stddef.h>
-#else
-# include <stdlib.h>		/* Just for NULL.  */
-#endif
+#include <stddef.h>		/* Just for NULL.  */
 
 #include "gettextP.h"
 #ifdef _LIBC
diff --git a/intl/libintl.h b/intl/libintl.h
index f03eda0b6f..95cbe2bdbe 100644
--- a/intl/libintl.h
+++ b/intl/libintl.h
@@ -95,10 +95,6 @@ extern char *bind_textdomain_codeset (const char *__domainname,
 /* Optimized version of the function above.  */
 #if defined __OPTIMIZE__ && !defined __cplusplus
 
-/* We need NULL for `gettext'.  */
-# define __need_NULL
-# include <stddef.h>
-
 /* We need LC_MESSAGES for `dgettext'.  */
 # include <locale.h>
 
@@ -106,12 +102,12 @@ extern char *bind_textdomain_codeset (const char *__domainname,
    `__builtin_constant_p' predicate in dcgettext would always return
    false.  */
 
-# define gettext(msgid) dgettext (NULL, msgid)
+# define gettext(msgid) dgettext (0, msgid)
 
 # define dgettext(domainname, msgid) \
   dcgettext (domainname, msgid, LC_MESSAGES)
 
-# define ngettext(msgid1, msgid2, n) dngettext (NULL, msgid1, msgid2, n)
+# define ngettext(msgid1, msgid2, n) dngettext (0, msgid1, msgid2, n)
 
 # define dngettext(domainname, msgid1, msgid2, n) \
   dcngettext (domainname, msgid1, msgid2, n, LC_MESSAGES)
diff --git a/intl/ngettext.c b/intl/ngettext.c
index 98aa2c90b0..ffd99f6604 100644
--- a/intl/ngettext.c
+++ b/intl/ngettext.c
@@ -18,12 +18,7 @@
 # include <config.h>
 #endif
 
-#ifdef _LIBC
-# define __need_NULL
-# include <stddef.h>
-#else
-# include <stdlib.h>		/* Just for NULL.  */
-#endif
+#include <stddef.h>		/* Just for NULL.  */
 
 #include "gettextP.h"
 #ifdef _LIBC
diff --git a/libio/bits/types/struct_FILE.h b/libio/bits/types/struct_FILE.h
index b725459e58..6b7faf8f56 100644
--- a/libio/bits/types/struct_FILE.h
+++ b/libio/bits/types/struct_FILE.h
@@ -31,6 +31,7 @@
 #endif
 
 #include <bits/types.h>
+#include <bits/types/size_t.h>
 
 struct _IO_FILE;
 struct _IO_marker;
diff --git a/libio/libio.h b/libio/libio.h
index b985c386a2..96fa1062f2 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -41,10 +41,8 @@
 # error "Someone forgot to include stdio-lock.h"
 #endif
 
-#define __need_wchar_t
-#include <stddef.h>
-
 #include <bits/types/__mbstate_t.h>
+#include <bits/types/wchar_t.h>
 #include <bits/types/wint_t.h>
 #include <gconv.h>
 
diff --git a/libio/stdio.h b/libio/stdio.h
index 6fabdbedc2..275091e416 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -28,33 +28,22 @@
 
 __BEGIN_DECLS
 
-#define __need_size_t
-#define __need_NULL
-#include <stddef.h>
-
-#define __need___va_list
-#include <stdarg.h>
-
 #include <bits/types.h>
 #include <bits/types/__fpos_t.h>
 #include <bits/types/__fpos64_t.h>
 #include <bits/types/__FILE.h>
+#include <bits/types/__va_list.h>
 #include <bits/types/FILE.h>
 #include <bits/types/struct_FILE.h>
+#include <bits/types/size_t.h>
+#include <bits/NULL.h>
 
 #ifdef __USE_GNU
 # include <bits/types/cookie_io_functions_t.h>
 #endif
 
 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
-# ifdef __GNUC__
-#  ifndef _VA_LIST_DEFINED
-typedef __gnuc_va_list va_list;
-#   define _VA_LIST_DEFINED
-#  endif
-# else
-#  include <stdarg.h>
-# endif
+# include <bits/types/va_list.h>
 #endif
 
 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
diff --git a/locale/locale.h b/locale/locale.h
index 7d8a435fe3..61b904f7b4 100644
--- a/locale/locale.h
+++ b/locale/locale.h
@@ -24,9 +24,8 @@
 
 #include <features.h>
 
-#define __need_NULL
-#include <stddef.h>
 #include <bits/locale.h>
+#include <bits/NULL.h>
 
 __BEGIN_DECLS
 
diff --git a/malloc/malloc.h b/malloc/malloc.h
index 523f1b1af5..be5b2f0e5e 100644
--- a/malloc/malloc.h
+++ b/malloc/malloc.h
@@ -20,8 +20,11 @@
 #define _MALLOC_H 1
 
 #include <features.h>
-#include <stddef.h>
-#include <stdio.h>
+
+#include <bits/NULL.h>
+#include <bits/types/size_t.h>
+#include <bits/types/ptrdiff_t.h>
+#include <bits/types/FILE.h>
 
 #ifdef _LIBC
 # define __MALLOC_HOOK_VOLATILE
diff --git a/malloc/tst-malloc-thread-fail.c b/malloc/tst-malloc-thread-fail.c
index 2ffe848107..50a9aee68d 100644
--- a/malloc/tst-malloc-thread-fail.c
+++ b/malloc/tst-malloc-thread-fail.c
@@ -20,6 +20,7 @@
    related to allocation failures, notably switching to a different
    arena, and falling back to mmap (via sysmalloc).  */
 
+#include <stddef.h>
 #include <errno.h>
 #include <malloc.h>
 #include <pthread.h>
diff --git a/malloc/tst-malloc_info.c b/malloc/tst-malloc_info.c
index d4bbd5c88d..ca886ec7d6 100644
--- a/malloc/tst-malloc_info.c
+++ b/malloc/tst-malloc_info.c
@@ -22,6 +22,7 @@
 #include <array_length.h>
 #include <malloc.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <support/support.h>
 #include <support/xthread.h>
 
diff --git a/misc/bits/types/struct_iovec.h b/misc/bits/types/struct_iovec.h
index 58261ba27f..01a9bc5881 100644
--- a/misc/bits/types/struct_iovec.h
+++ b/misc/bits/types/struct_iovec.h
@@ -19,8 +19,7 @@
 #ifndef __iovec_defined
 #define __iovec_defined 1
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* Structure for scatter/gather I/O.  */
 struct iovec
diff --git a/misc/err.h b/misc/err.h
index 4dfd9a6f5d..2d12cbe68c 100644
--- a/misc/err.h
+++ b/misc/err.h
@@ -21,11 +21,7 @@
 
 #include <features.h>
 
-#define	__need___va_list
-#include <stdarg.h>
-#ifndef	__GNUC_VA_LIST
-# define __gnuc_va_list	void *
-#endif
+#include <bits/types/__va_list.h>
 
 __BEGIN_DECLS
 
diff --git a/misc/search.h b/misc/search.h
index 4659c59877..771b4626f8 100644
--- a/misc/search.h
+++ b/misc/search.h
@@ -21,8 +21,7 @@
 
 #include <features.h>
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 __BEGIN_DECLS
 
diff --git a/misc/sys/mman.h b/misc/sys/mman.h
index 43552c3dfa..41e66a4b77 100644
--- a/misc/sys/mman.h
+++ b/misc/sys/mman.h
@@ -20,13 +20,11 @@
 #define	_SYS_MMAN_H	1
 
 #include <features.h>
+
 #include <bits/types.h>
-
-#define __need_size_t
-#include <stddef.h>
-
-#include <bits/types/off_t.h>
 #include <bits/types/mode_t.h>
+#include <bits/types/off_t.h>
+#include <bits/types/size_t.h>
 
 #include <bits/mman.h>
 
diff --git a/misc/sys/param.h b/misc/sys/param.h
index bf988a9769..bb6478f79b 100644
--- a/misc/sys/param.h
+++ b/misc/sys/param.h
@@ -19,13 +19,13 @@
 #ifndef _SYS_PARAM_H
 #define _SYS_PARAM_H    1
 
-#define __need_NULL
-#include <stddef.h>
+#include <features.h>
 
 #include <sys/types.h>
 #include <limits.h>
 #include <endian.h>                     /* Define BYTE_ORDER et al.  */
 #include <signal.h>                     /* Define NSIG.  */
+#include <bits/NULL.h>
 
 /* This file defines some things in system-specific ways.  */
 #include <bits/param.h>
diff --git a/misc/syslog.h b/misc/syslog.h
index 406133ba71..f7b7a6743f 100644
--- a/misc/syslog.h
+++ b/misc/syslog.h
@@ -33,8 +33,7 @@
 #define _SYSLOG_H 1
 
 #include <features.h>
-#define __need___va_list
-#include <stdarg.h>
+#include <bits/types/__va_list.h>
 
 /* This file defines _PATH_LOG.  */
 #include <bits/syslog-path.h>
diff --git a/posix/glob.h b/posix/glob.h
index e49e6c000d..3b1535e374 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -29,8 +29,7 @@ __BEGIN_DECLS
    a different purpose.  */
 
 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
-# define __need_size_t
-# include <stddef.h>
+#include <bits/types/size_t.h>
 typedef size_t __gsize_t;
 #elif defined __SIZE_TYPE__
 typedef __SIZE_TYPE__ __gsize_t;
diff --git a/posix/sched.h b/posix/sched.h
index 56c1470521..dfcf84da1f 100644
--- a/posix/sched.h
+++ b/posix/sched.h
@@ -22,18 +22,15 @@
 #include <features.h>
 
 /* Get type definitions.  */
+#include <bits/NULL.h>
 #include <bits/types.h>
-
-#define __need_size_t
-#define __need_NULL
-#include <stddef.h>
-
+#include <bits/types/pid_t.h>
+#include <bits/types/size_t.h>
 #include <bits/types/time_t.h>
 #include <bits/types/struct_timespec.h>
 #ifndef __USE_XOPEN2K
 # include <time.h>
 #endif
-#include <bits/types/pid_t.h>
 
 /* Get system specific constant and data structure definitions.  */
 #include <bits/sched.h>
diff --git a/posix/sys/types.h b/posix/sys/types.h
index 8f6d328692..08305cf812 100644
--- a/posix/sys/types.h
+++ b/posix/sys/types.h
@@ -28,9 +28,6 @@ __BEGIN_DECLS
 
 #include <bits/types.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 #include <bits/types/blkcnt_t.h>
 #include <bits/types/clockid_t.h>
 #include <bits/types/dev_t.h>
@@ -42,6 +39,7 @@ __BEGIN_DECLS
 #include <bits/types/nlink_t.h>
 #include <bits/types/off_t.h>
 #include <bits/types/pid_t.h>
+#include <bits/types/size_t.h>
 #include <bits/types/ssize_t.h>
 #include <bits/types/time_t.h>
 #include <bits/types/timer_t.h>
diff --git a/posix/unistd.h b/posix/unistd.h
index 407f2fee5f..1d4c70f897 100644
--- a/posix/unistd.h
+++ b/posix/unistd.h
@@ -214,13 +214,11 @@ __BEGIN_DECLS
 
 /* All functions that are not declared anywhere else.  */
 
+#include <bits/NULL.h>
 #include <bits/types.h>
+#include <bits/types/size_t.h>
 #include <bits/types/ssize_t.h>
 
-#define	__need_size_t
-#define __need_NULL
-#include <stddef.h>
-
 #if defined __USE_XOPEN || defined __USE_XOPEN2K
 /* The Single Unix specification says that some more types are
    available here.  */
diff --git a/posix/wordexp.h b/posix/wordexp.h
index 060f13fe49..f69d143693 100644
--- a/posix/wordexp.h
+++ b/posix/wordexp.h
@@ -19,8 +19,7 @@
 #define	_WORDEXP_H	1
 
 #include <features.h>
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 __BEGIN_DECLS
 
diff --git a/pwd/pwd.h b/pwd/pwd.h
index ccb3bc0ff8..75a598e0db 100644
--- a/pwd/pwd.h
+++ b/pwd/pwd.h
@@ -27,9 +27,7 @@
 __BEGIN_DECLS
 
 #include <bits/types.h>
-
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 #if defined __USE_XOPEN || defined __USE_XOPEN2K
 /* The Single Unix specification says that some more types are
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 4ef5775932..5cd3867be1 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -491,14 +491,6 @@ def ObsoleteTypedefChecker(reporter, fname):
 # but we are not ready to enforce that yet.
 UNIVERSAL_ALLOWED_INCLUDES = {
     "features.h",
-
-    # Technically these should only ever be included with __need
-    # macros active, but some headers deliberately break this rule
-    # when they think they're dealing with freestanding headers from a
-    # non-GNU compiler, so enforcing it would be more trouble than
-    # it's worth.
-    "stddef.h",
-    "stdarg.h",
 }
 
 # Specific headers are allowed to include specific other headers.
@@ -575,7 +567,7 @@ HEADER_ALLOWED_INCLUDES = {
     "link.h":                      [ "dlfcn.h", "elf.h", "sys/types.h" ],
     "mntent.h":                    [ "paths.h" ],
     "nss.h":                       [ "stdint.h" ],
-    "obstack.h":                   [ "string.h" ],
+    "obstack.h":                   [ "stddef.h", "string.h" ],
     "proc_service.h":              [ "sys/procfs.h" ],
     "pty.h":                       [ "sys/ioctl.h", "termios.h" ],
     "sgtty.h":                     [ "sys/ioctl.h" ],
@@ -619,7 +611,6 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/timex.h":                 [ "sys/time.h" ],
     "sys/ttychars.h":              [ "sys/ttydefaults.h" ],
     "sys/ucontext.h":              [ "sys/procfs.h" ],
-    "sys/user.h":                  [ "sys/types.h" ],
     "sys/vfs.h":                   [ "sys/statfs.h" ],
     "sys/xattr.h":                 [ "sys/types.h" ],
 
@@ -696,6 +687,12 @@ HEADER_ALLOWED_INCLUDES = {
     "bits/types/res_state.h":      [ "netinet/in.h", "sys/types.h" ],
     "bits/utmp.h":                 [ "paths.h", "sys/time.h", "sys/types.h" ],
     "bits/utmpx.h":                [ "paths.h", "sys/time.h" ],
+
+    "bits/types/__va_list.h":      [ "stdarg.h" ],
+    "bits/types/ptrdiff_t.h":      [ "stddef.h" ],
+    "bits/types/size_t.h":         [ "stddef.h" ],
+    "bits/types/wchar_t.h":        [ "stddef.h" ],
+    "bits/NULL.h":                 [ "stddef.h" ],
 }
 
 # As above, but each group of whitelist entries is only used for
diff --git a/shadow/shadow.h b/shadow/shadow.h
index d8635db0b1..b36b0c323c 100644
--- a/shadow/shadow.h
+++ b/shadow/shadow.h
@@ -28,10 +28,8 @@
 
 #include <paths.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 #include <bits/types/FILE.h>
+#include <bits/types/size_t.h>
 
 /* Paths to the user database files.  */
 #define	SHADOW _PATH_SHADOW
diff --git a/signal/sighold.c b/signal/sighold.c
index 8154143b36..27add40850 100644
--- a/signal/sighold.c
+++ b/signal/sighold.c
@@ -17,7 +17,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_NULL
 #include <stddef.h>
 #include <signal.h>
 
diff --git a/signal/signal.h b/signal/signal.h
index ec701012e1..2c52466791 100644
--- a/signal/signal.h
+++ b/signal/signal.h
@@ -289,9 +289,7 @@ extern int sigreturn (struct sigcontext *__scp) __THROW;
 
 
 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
-# define __need_size_t
-# include <stddef.h>
-
+# include <bits/types/size_t.h>
 # include <bits/types/stack_t.h>
 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
 /* This will define `ucontext_t' and `mcontext_t'.  */
diff --git a/signal/sigrelse.c b/signal/sigrelse.c
index 433a258dee..8fc657a1cd 100644
--- a/signal/sigrelse.c
+++ b/signal/sigrelse.c
@@ -17,7 +17,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_NULL
 #include <stddef.h>
 #include <signal.h>
 
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index 6f242d088b..1bb90ed67c 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -23,9 +23,8 @@
 
 __BEGIN_DECLS
 
+#include <bits/types/size_t.h>
 #include <bits/types/struct_iovec.h>
-#define	__need_size_t
-#include <stddef.h>
 
 /* This operating system-specific header file defines the SOCK_*, PF_*,
    AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
diff --git a/stdio-common/printf.h b/stdio-common/printf.h
index 0172b234f1..69c9691720 100644
--- a/stdio-common/printf.h
+++ b/stdio-common/printf.h
@@ -23,12 +23,9 @@
 __BEGIN_DECLS
 
 #include <bits/types/FILE.h>
-
-#define	__need_size_t
-#define __need_wchar_t
-#include <stddef.h>
-
-#include <stdarg.h>
+#include <bits/types/size_t.h>
+#include <bits/types/wchar_t.h>
+#include <bits/types/__va_list.h>
 
 
 struct printf_info
@@ -89,7 +86,7 @@ typedef int printf_arginfo_function (const struct printf_info *__info,
 
 /* Type of a function to get a value of a user-defined from the
    variable argument list.  */
-typedef void printf_va_arg_function (void *__mem, va_list *__ap);
+typedef void printf_va_arg_function (void *__mem, __gnuc_va_list *__ap);
 
 
 /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
diff --git a/stdio-common/tempname.c b/stdio-common/tempname.c
index 54c97bf149..b00c14f9df 100644
--- a/stdio-common/tempname.c
+++ b/stdio-common/tempname.c
@@ -15,7 +15,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_size_t
 #include <stddef.h>
 #include <stdio.h>
 #include <errno.h>
diff --git a/stdio-common/tst-vfprintf-user-type.c b/stdio-common/tst-vfprintf-user-type.c
index fed17e4131..8f63e65d6e 100644
--- a/stdio-common/tst-vfprintf-user-type.c
+++ b/stdio-common/tst-vfprintf-user-type.c
@@ -23,6 +23,7 @@
 
 #include <locale.h>
 #include <printf.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/stdlib/Makefile b/stdlib/Makefile
index 32f6050ecc..fbf1b84a4b 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -29,7 +29,9 @@ headers	:= stdlib.h bits/stdlib.h bits/stdlib-ldbl.h bits/stdlib-float.h      \
 	   ucontext.h sys/ucontext.h bits/indirect-return.h		      \
 	   alloca.h fmtmsg.h						      \
 	   bits/stdlib-bsearch.h sys/random.h bits/stdint-intn.h	      \
-	   bits/stdint-uintn.h bits/time64.h				      \
+	   bits/stdint-uintn.h bits/time64.h bits/NULL.h		      \
+	   bits/types/ptrdiff_t.h bits/types/size_t.h bits/types/wchar_t.h    \
+	   bits/types/__va_list.h bits/types/va_list.h
 
 routines	:=							      \
 	atof atoi atol atoll						      \
diff --git a/stdlib/alloca.h b/stdlib/alloca.h
index ff85901357..908f966e53 100644
--- a/stdlib/alloca.h
+++ b/stdlib/alloca.h
@@ -20,8 +20,7 @@
 
 #include <features.h>
 
-#define	__need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 __BEGIN_DECLS
 
diff --git a/stdlib/bits/NULL.h b/stdlib/bits/NULL.h
new file mode 100644
index 0000000000..79285bd7b2
--- /dev/null
+++ b/stdlib/bits/NULL.h
@@ -0,0 +1,8 @@
+#ifndef _BITS_NULL_H
+#define _BITS_NULL_H 1
+
+/* We rely on the compiler's stddef.h to define NULL for us.  */
+#define __need_NULL
+#include <stddef.h>
+
+#endif
diff --git a/stdlib/bits/types/__va_list.h b/stdlib/bits/types/__va_list.h
new file mode 100644
index 0000000000..e3c53c3e05
--- /dev/null
+++ b/stdlib/bits/types/__va_list.h
@@ -0,0 +1,9 @@
+#ifndef ____va_list_defined
+#define ____va_list_defined 1
+
+/* We rely on the compiler's stdarg.h to define __gnuc_va_list for us.  */
+#define __need___va_list
+#include <stdarg.h>
+#undef __need___va_list
+
+#endif
diff --git a/stdlib/bits/types/ptrdiff_t.h b/stdlib/bits/types/ptrdiff_t.h
new file mode 100644
index 0000000000..23a8b986d5
--- /dev/null
+++ b/stdlib/bits/types/ptrdiff_t.h
@@ -0,0 +1,9 @@
+#ifndef __ptrdiff_t_defined
+#define __ptrdiff_t_defined 1
+
+/* We rely on the compiler's stddef.h to define ptrdiff_t for us.  */
+#define __need_ptrdiff_t
+#include <stddef.h>
+#undef __need_ptrdiff_t
+
+#endif
diff --git a/stdlib/bits/types/size_t.h b/stdlib/bits/types/size_t.h
new file mode 100644
index 0000000000..e151458eb3
--- /dev/null
+++ b/stdlib/bits/types/size_t.h
@@ -0,0 +1,9 @@
+#ifndef __size_t_defined
+#define __size_t_defined 1
+
+/* We rely on the compiler's stddef.h to define size_t for us.  */
+#define __need_size_t
+#include <stddef.h>
+#undef __need_size_t
+
+#endif
diff --git a/stdlib/bits/types/va_list.h b/stdlib/bits/types/va_list.h
new file mode 100644
index 0000000000..6f3acac379
--- /dev/null
+++ b/stdlib/bits/types/va_list.h
@@ -0,0 +1,15 @@
+/* This guard macro needs to match the one used by at least gcc and
+   clang's stdarg.h to indicate that va_list, specifically, has been
+   defined.  */
+#ifndef _VA_LIST
+
+#include <bits/types/__va_list.h>
+
+/* Check again, __va_list.h may not have been able to avoid including
+   all of stdarg.h.  */
+# ifndef _VA_LIST
+typedef __gnuc_va_list va_list;
+# endif
+# define _VA_LIST
+
+#endif
diff --git a/stdlib/bits/types/wchar_t.h b/stdlib/bits/types/wchar_t.h
new file mode 100644
index 0000000000..1e44e157cc
--- /dev/null
+++ b/stdlib/bits/types/wchar_t.h
@@ -0,0 +1,9 @@
+#ifndef __wchar_t_defined
+#define __wchar_t_defined 1
+
+/* We rely on the compiler's stddef.h to define wchar_t for us.  */
+#define __need_wchar_t
+#include <stddef.h>
+#undef __need_wchar_t
+
+#endif
diff --git a/stdlib/inttypes.h b/stdlib/inttypes.h
index c5fb12056e..30c9e84cd3 100644
--- a/stdlib/inttypes.h
+++ b/stdlib/inttypes.h
@@ -32,8 +32,7 @@
 #elif defined __WCHAR_TYPE__
 typedef __WCHAR_TYPE__ __gwchar_t;
 #else
-# define __need_wchar_t
-# include <stddef.h>
+#include <bits/types/wchar_t.h>
 typedef wchar_t __gwchar_t;
 #endif
 
diff --git a/stdlib/monetary.h b/stdlib/monetary.h
index 1f3347a6ec..1150f11486 100644
--- a/stdlib/monetary.h
+++ b/stdlib/monetary.h
@@ -22,9 +22,8 @@
 #include <features.h>
 
 /* Get needed types.  */
-#define __need_size_t
-#include <stddef.h>
 #include <bits/types.h>
+#include <bits/types/size_t.h>
 #include <bits/types/ssize_t.h>
 
 __BEGIN_DECLS
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 34996e3ee7..1f26f3639e 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -20,20 +20,17 @@
  */
 
 #ifndef	_STDLIB_H
+#define	_STDLIB_H	1
 
 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
 #include <bits/libc-header-start.h>
 
-/* Get size_t, wchar_t and NULL from <stddef.h>.  */
-#define __need_size_t
-#define __need_wchar_t
-#define __need_NULL
-#include <stddef.h>
+#include <bits/types/size_t.h>
+#include <bits/types/wchar_t.h>
+#include <bits/NULL.h>
 
 __BEGIN_DECLS
 
-#define	_STDLIB_H	1
-
 #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
 /* XPG requires a few symbols from <sys/wait.h> being defined.  */
 # include <bits/waitflags.h>
diff --git a/string/string.h b/string/string.h
index c38eea971f..2cc4f50090 100644
--- a/string/string.h
+++ b/string/string.h
@@ -27,10 +27,8 @@
 
 __BEGIN_DECLS
 
-/* Get size_t and NULL from <stddef.h>.  */
-#define	__need_size_t
-#define	__need_NULL
-#include <stddef.h>
+#include <bits/types/size_t.h>
+#include <bits/NULL.h>
 
 /* Tell the caller that we provide correct C++ prototypes.  */
 #if defined __cplusplus && __GNUC_PREREQ (4, 4)
diff --git a/string/strings.h b/string/strings.h
index 5428bc4feb..17e1bf737f 100644
--- a/string/strings.h
+++ b/string/strings.h
@@ -19,8 +19,7 @@
 #define	_STRINGS_H	1
 
 #include <features.h>
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* Tell the caller that we provide correct C++ prototypes.  */
 #if defined __cplusplus && __GNUC_PREREQ (4, 4)
diff --git a/string/tst-cmp.c b/string/tst-cmp.c
index 939cf28275..ccdd1e3cec 100644
--- a/string/tst-cmp.c
+++ b/string/tst-cmp.c
@@ -23,6 +23,7 @@
 #include <limits.h>
 #include <malloc.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sunrpc/rpc/netdb.h b/sunrpc/rpc/netdb.h
index 529a4ada21..a5aa340e1a 100644
--- a/sunrpc/rpc/netdb.h
+++ b/sunrpc/rpc/netdb.h
@@ -38,8 +38,7 @@
 
 #include <features.h>
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index b1fc5c31f9..88fc64df63 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -22,8 +22,6 @@
 #include <features.h>
 
 #include <stdbool.h>
-#define __need_size_t
-#define __need_NULL
 #include <stddef.h>
 #include <string.h>
 #include <stdint.h>
diff --git a/sysdeps/htl/bits/types/struct___pthread_attr.h b/sysdeps/htl/bits/types/struct___pthread_attr.h
index b2c5c63f27..25cf45ecdb 100644
--- a/sysdeps/htl/bits/types/struct___pthread_attr.h
+++ b/sysdeps/htl/bits/types/struct___pthread_attr.h
@@ -19,11 +19,9 @@
 #ifndef _BITS_TYPES_STRUCT___PTHREAD_ATTR
 #define _BITS_TYPES_STRUCT___PTHREAD_ATTR	1
 
+#include <bits/types/size_t.h>
 #include <bits/types/struct_sched_param.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 enum __pthread_detachstate;
 enum __pthread_inheritsched;
 enum __pthread_contentionscope;
diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
index 429e66c56a..ad590af3f6 100644
--- a/sysdeps/mach/hurd/bits/socket.h
+++ b/sysdeps/mach/hurd/bits/socket.h
@@ -24,12 +24,11 @@
 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
 #endif
 
-#define	__need_size_t
-#include <stddef.h>
 
-#include <bits/wordsize.h>
 #include <sys/types.h>
+#include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
+#include <bits/wordsize.h>
 
 /* Types of sockets.  */
 enum __socket_type
diff --git a/sysdeps/nptl/libc-lock.h b/sysdeps/nptl/libc-lock.h
index a1fe9a766b..3840cc7eda 100644
--- a/sysdeps/nptl/libc-lock.h
+++ b/sysdeps/nptl/libc-lock.h
@@ -20,7 +20,6 @@
 #define _LIBC_LOCK_H 1
 
 #include <pthread.h>
-#define __need_NULL
 #include <stddef.h>
 
 
diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h
index 07d583f11a..1e7d95ca60 100644
--- a/sysdeps/nptl/libc-lockP.h
+++ b/sysdeps/nptl/libc-lockP.h
@@ -20,7 +20,6 @@
 #define _LIBC_LOCKP_H 1
 
 #include <pthread.h>
-#define __need_NULL
 #include <stddef.h>
 
 
diff --git a/sysdeps/posix/sigignore.c b/sysdeps/posix/sigignore.c
index 46748fd0ab..8b1fa3ae16 100644
--- a/sysdeps/posix/sigignore.c
+++ b/sysdeps/posix/sigignore.c
@@ -17,11 +17,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#define __need_NULL
 #include <stddef.h>
 #include <signal.h>
-#include <string.h>	/* For the real memset prototype.  */
 #include <sigsetops.h>
 
 int
diff --git a/sysdeps/posix/sigset.c b/sysdeps/posix/sigset.c
index dfc0b35b65..4142a500fa 100644
--- a/sysdeps/posix/sigset.c
+++ b/sysdeps/posix/sigset.c
@@ -15,11 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#define __need_NULL
 #include <stddef.h>
 #include <signal.h>
-#include <string.h>	/* For the real memset prototype.  */
 #include <sigsetops.h>
 
 /* Set the disposition for SIG.  */
diff --git a/sysdeps/posix/waitid.c b/sysdeps/posix/waitid.c
index d49a2f7883..5cd1352ef0 100644
--- a/sysdeps/posix/waitid.c
+++ b/sysdeps/posix/waitid.c
@@ -20,7 +20,6 @@
 #include <assert.h>
 #include <errno.h>
 #include <signal.h>
-#define __need_NULL
 #include <stddef.h>
 #include <sys/wait.h>
 #include <sys/types.h>
diff --git a/sysdeps/unix/sysv/linux/aarch64/sys/user.h b/sysdeps/unix/sysv/linux/aarch64/sys/user.h
index 7f6d8bea89..949484a533 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sys/user.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sys/user.h
@@ -19,6 +19,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+
 struct user_regs_struct
 {
   unsigned long long regs[31];
diff --git a/sysdeps/unix/sysv/linux/alpha/sys/user.h b/sysdeps/unix/sysv/linux/alpha/sys/user.h
index 38fcb51c9a..52bc3a287c 100644
--- a/sysdeps/unix/sysv/linux/alpha/sys/user.h
+++ b/sysdeps/unix/sysv/linux/alpha/sys/user.h
@@ -18,13 +18,15 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+#include <bits/types/size_t.h>
+
+#include <asm/reg.h>
+
 /* The whole purpose of this file is for gdb/strace and gdb/strace
    only. Don't read too much into it. Don't use it for anything other
    than gdb/strace unless you know what you are doing. */
 
-#include <asm/reg.h>
-#include <stddef.h>
-
 struct user
 {
   unsigned long	int regs[EF_SIZE / 8 + 32];	/* integer and fp regs */
diff --git a/sysdeps/unix/sysv/linux/arm/sys/user.h b/sysdeps/unix/sysv/linux/arm/sys/user.h
index aae8a99e56..55db6ca181 100644
--- a/sysdeps/unix/sysv/linux/arm/sys/user.h
+++ b/sysdeps/unix/sysv/linux/arm/sys/user.h
@@ -18,6 +18,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
    you know what you are doing.  */
diff --git a/sysdeps/unix/sysv/linux/bits/sigcontext.h b/sysdeps/unix/sysv/linux/bits/sigcontext.h
index bd33c42a49..a420e20792 100644
--- a/sysdeps/unix/sysv/linux/bits/sigcontext.h
+++ b/sysdeps/unix/sysv/linux/bits/sigcontext.h
@@ -24,14 +24,17 @@
 
 #ifndef sigcontext_struct
 /* Kernel headers before 2.1.1 define a struct sigcontext_struct, but
-   we need sigcontext.  */
+   we need sigcontext.  FIXME: Is this workaround still necessary?
+   2.1.1 was many years ago.  */
 # define sigcontext_struct sigcontext
 
 # include <asm/sigcontext.h>
 
-/* The Linux kernel headers redefine NULL wrongly, so cleanup afterwards.  */
-# define __need_NULL
-# include <stddef.h>
+/* The Linux kernel headers redefine NULL wrongly, so cleanup afterwards.
+   FIXME: This won't work if bits/NULL.h or stddef.h has already been
+   included.  Is this workaround still necessary?  Current (4.19) uapi
+   headers do not redefine NULL.  */
+#include <bits/NULL.h>
 #endif
 
 #endif /* bits/sigcontext.h */
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index cf3c03a9ec..19e664842f 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -23,10 +23,9 @@
 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
 #endif
 
-#define __need_size_t
-#include <stddef.h>
 
 #include <sys/types.h>
+#include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 
 /* Get the architecture-dependent definition of enum __socket_type.  */
diff --git a/sysdeps/unix/sysv/linux/bits/types/stack_t.h b/sysdeps/unix/sysv/linux/bits/types/stack_t.h
index 5af7a91df0..4c1828ea90 100644
--- a/sysdeps/unix/sysv/linux/bits/types/stack_t.h
+++ b/sysdeps/unix/sysv/linux/bits/types/stack_t.h
@@ -19,8 +19,7 @@
 #ifndef __stack_t_defined
 #define __stack_t_defined 1
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* Structure describing a signal stack.  */
 typedef struct
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h b/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
index 8dba935b15..b1b45ee5de 100644
--- a/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
@@ -23,11 +23,10 @@
 # error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
 #endif
 
-#define __need_size_t
-#include <stddef.h>
-#include <bits/sigstack.h>
+#include <bits/types/size_t.h>
 #include <bits/types/struct_sigstack.h>
 #include <bits/types/stack_t.h>
+#include <bits/sigstack.h>
 #include <bits/ss_flags.h>
 
 struct __ia64_fpreg
diff --git a/sysdeps/unix/sysv/linux/ia64/sys/user.h b/sysdeps/unix/sysv/linux/ia64/sys/user.h
index f409e237c9..4e4aae5120 100644
--- a/sysdeps/unix/sysv/linux/ia64/sys/user.h
+++ b/sysdeps/unix/sysv/linux/ia64/sys/user.h
@@ -19,7 +19,7 @@
 #define _SYS_USER_H	1
 
 #include <features.h>
-#include <sys/types.h>
+#include <bits/types/size_t.h>
 
 /* This definition comes directly from the kernel headers.  If
    anything changes in them this header has to be changed, too.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/sys/user.h b/sysdeps/unix/sysv/linux/m68k/sys/user.h
index 210d88f901..e8cdf8b35f 100644
--- a/sysdeps/unix/sysv/linux/m68k/sys/user.h
+++ b/sysdeps/unix/sysv/linux/m68k/sys/user.h
@@ -18,6 +18,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
    you know what you are doing.  */
diff --git a/sysdeps/unix/sysv/linux/microblaze/sys/user.h b/sysdeps/unix/sysv/linux/microblaze/sys/user.h
index adf08ca275..baf6a28247 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sys/user.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sys/user.h
@@ -19,6 +19,8 @@
 #ifndef _SYS_USER_H
 # define _SYS_USER_H	1
 
+#include <features.h>
+
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
    you know what you are doing.  */
diff --git a/sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h b/sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h
index 4424398528..ad9bd9056f 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h
@@ -19,8 +19,7 @@
 #ifndef __stack_t_defined
 #define __stack_t_defined 1
 
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
 
 /* Structure describing a signal stack.  */
 typedef struct
diff --git a/sysdeps/unix/sysv/linux/mips/sys/user.h b/sysdeps/unix/sysv/linux/mips/sys/user.h
index 29a6c36785..8ed0df7aad 100644
--- a/sysdeps/unix/sysv/linux/mips/sys/user.h
+++ b/sysdeps/unix/sysv/linux/mips/sys/user.h
@@ -18,8 +18,10 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+#include <bits/types/size_t.h>
+
 #include <sgidefs.h>
-#include <stddef.h>
 
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
diff --git a/sysdeps/unix/sysv/linux/nios2/sys/user.h b/sysdeps/unix/sysv/linux/nios2/sys/user.h
index 8670f77b45..4adb789004 100644
--- a/sysdeps/unix/sysv/linux/nios2/sys/user.h
+++ b/sysdeps/unix/sysv/linux/nios2/sys/user.h
@@ -19,6 +19,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
    you know what you are doing.  */
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/user.h b/sysdeps/unix/sysv/linux/powerpc/sys/user.h
index c6f36d79b8..2d90235a14 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/user.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/user.h
@@ -16,10 +16,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _SYS_USER_H
-
 #define _SYS_USER_H	1
-#include <stddef.h>
+
 #include <features.h>
+#include <bits/types/size_t.h>
 
 #include <asm/ptrace.h>
 
diff --git a/sysdeps/unix/sysv/linux/s390/sys/user.h b/sysdeps/unix/sysv/linux/s390/sys/user.h
index ab56f513c4..3fc03f3171 100644
--- a/sysdeps/unix/sysv/linux/s390/sys/user.h
+++ b/sysdeps/unix/sysv/linux/s390/sys/user.h
@@ -18,6 +18,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
    you know what you are doing.  */
diff --git a/sysdeps/unix/sysv/linux/scsi/sg.h b/sysdeps/unix/sysv/linux/scsi/sg.h
index 1f0b5a156a..9a250a9d7e 100644
--- a/sysdeps/unix/sysv/linux/scsi/sg.h
+++ b/sysdeps/unix/sysv/linux/scsi/sg.h
@@ -26,9 +26,7 @@
 #define _SCSI_SG_H	1
 
 #include <features.h>
-#define __need_size_t
-#include <stddef.h>
-
+#include <bits/types/size_t.h>
 
 /* New interface introduced in the 3.x SG drivers follows */
 
diff --git a/sysdeps/unix/sysv/linux/sh/sys/user.h b/sysdeps/unix/sysv/linux/sh/sys/user.h
index 54d3d701eb..37d0c0eb5e 100644
--- a/sysdeps/unix/sysv/linux/sh/sys/user.h
+++ b/sysdeps/unix/sysv/linux/sh/sys/user.h
@@ -18,8 +18,11 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+#include <bits/types/size_t.h>
+
 #include <asm/ptrace.h>
-#include <stddef.h>
+
 
 /* asm/ptrace.h polutes the namespace.  */
 #undef PTRACE_GETREGS
diff --git a/sysdeps/unix/sysv/linux/sparc/sys/user.h b/sysdeps/unix/sysv/linux/sparc/sys/user.h
index c9c486a7d7..9e3057af93 100644
--- a/sysdeps/unix/sysv/linux/sparc/sys/user.h
+++ b/sysdeps/unix/sysv/linux/sparc/sys/user.h
@@ -18,7 +18,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
-#include <stddef.h>
+#include <features.h>
+#include <bits/types/size_t.h>
 
 struct sunos_regs
 {
diff --git a/sysdeps/unix/sysv/linux/sys/sysctl.h b/sysdeps/unix/sysv/linux/sys/sysctl.h
index be34555668..6ca4aaa488 100644
--- a/sysdeps/unix/sysv/linux/sys/sysctl.h
+++ b/sysdeps/unix/sysv/linux/sys/sysctl.h
@@ -21,8 +21,8 @@
 #warning "The <sys/sysctl.h> header is deprecated and will be removed."
 
 #include <features.h>
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
+
 /* Prevent more kernel headers than necessary to be included.  */
 #ifndef _LINUX_KERNEL_H
 # define _LINUX_KERNEL_H	1
diff --git a/sysdeps/unix/sysv/linux/x86/sys/user.h b/sysdeps/unix/sysv/linux/x86/sys/user.h
index b462a00e57..9de2572dac 100644
--- a/sysdeps/unix/sysv/linux/x86/sys/user.h
+++ b/sysdeps/unix/sysv/linux/x86/sys/user.h
@@ -18,6 +18,8 @@
 #ifndef _SYS_USER_H
 #define _SYS_USER_H	1
 
+#include <features.h>
+
 /* The whole purpose of this file is for GDB and GDB only.  Don't read
    too much into it.  Don't use it for anything other than GDB unless
    you know what you are doing.  */
diff --git a/sysvipc/sys/msg.h b/sysvipc/sys/msg.h
index f2f18f4dc5..d6d0610dff 100644
--- a/sysvipc/sys/msg.h
+++ b/sysvipc/sys/msg.h
@@ -20,20 +20,18 @@
 
 #include <features.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 /* Get common definition of System V style IPC.  */
 #include <sys/ipc.h>
 
-/* Get system dependent definition of `struct msqid_ds' and more.  */
-#include <bits/msq.h>
-
 /* Define types required by the standard.  */
 #include <bits/types/time_t.h>
 #include <bits/types/pid_t.h>
+#include <bits/types/size_t.h>
 #include <bits/types/ssize_t.h>
 
+/* Get system dependent definition of `struct msqid_ds' and more.  */
+#include <bits/msq.h>
+
 /* The following System V style IPC functions implement a message queue
    system.  The definition is found in XPG2.  */
 
diff --git a/sysvipc/sys/sem.h b/sysvipc/sys/sem.h
index ea9b66e1ee..6b5d43d71c 100644
--- a/sysvipc/sys/sem.h
+++ b/sysvipc/sys/sem.h
@@ -20,19 +20,18 @@
 
 #include <features.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 /* Get common definition of System V style IPC.  */
 #include <sys/ipc.h>
 
-/* Get system dependent definition of `struct semid_ds' and more.  */
-#include <bits/sem.h>
-
+/* Define types required by the standard.  */
+#include <bits/types/size_t.h>
 #ifdef __USE_GNU
 # include <bits/types/struct_timespec.h>
 #endif
 
+/* Get system dependent definition of `struct semid_ds' and more.  */
+#include <bits/sem.h>
+
 /* The following System V style IPC functions implement a semaphore
    handling.  The definition is found in XPG2.  */
 
diff --git a/sysvipc/sys/shm.h b/sysvipc/sys/shm.h
index bf836a75f1..b935f2789e 100644
--- a/sysvipc/sys/shm.h
+++ b/sysvipc/sys/shm.h
@@ -20,21 +20,19 @@
 
 #include <features.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 /* Get common definition of System V style IPC.  */
 #include <sys/ipc.h>
 
-/* Get system dependent definition of `struct shmid_ds' and more.  */
-#include <bits/shm.h>
-
 /* Define types required by the standard.  */
+#include <bits/types/size_t.h>
 #include <bits/types/time_t.h>
 #ifdef __USE_XOPEN
 # include <bits/types/pid_t.h>
 #endif
 
+/* Get system dependent definition of `struct shmid_ds' and more.  */
+#include <bits/shm.h>
+
 __BEGIN_DECLS
 
 /* The following System V style IPC functions implement a shared memory
diff --git a/time/time.h b/time/time.h
index 232531c6f0..45a02589ec 100644
--- a/time/time.h
+++ b/time/time.h
@@ -24,17 +24,15 @@
 
 #include <features.h>
 
-#define __need_size_t
-#define __need_NULL
-#include <stddef.h>
-
 /* This defines CLOCKS_PER_SEC, which is the number of processor clock
    ticks per second, and possibly a number of other constants.   */
 #include <bits/time.h>
 
-/* Many of the typedefs and structs whose official home is this header
-   may also need to be defined by other headers.  */
+/* Typedefs and structs required to be defined by this header.
+   Many are also defined by other headers.  */
+#include <bits/NULL.h>
 #include <bits/types/clock_t.h>
+#include <bits/types/size_t.h>
 #include <bits/types/time_t.h>
 #include <bits/types/struct_tm.h>
 
diff --git a/wcsmbs/uchar.h b/wcsmbs/uchar.h
index 315a01540f..690a25d7cf 100644
--- a/wcsmbs/uchar.h
+++ b/wcsmbs/uchar.h
@@ -25,10 +25,8 @@
 
 #include <features.h>
 
-#define __need_size_t
-#include <stddef.h>
-
 #include <bits/types.h>
+#include <bits/types/size_t.h>
 #include <bits/types/mbstate_t.h>
 
 #ifndef __USE_ISOCXX11
diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index 20deca90bf..ceb72b340c 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -27,20 +27,16 @@
 #include <bits/libc-header-start.h>
 
 /* Gather machine dependent type support.  */
-#include <bits/floatn.h>
-
-#define __need_size_t
-#define __need_wchar_t
-#define __need_NULL
-#include <stddef.h>
-
-#define __need___va_list
-#include <stdarg.h>
-
-#include <bits/wchar.h>
-#include <bits/types/wint_t.h>
-#include <bits/types/mbstate_t.h>
 #include <bits/types/__FILE.h>
+#include <bits/types/__va_list.h>
+#include <bits/types/mbstate_t.h>
+#include <bits/types/size_t.h>
+#include <bits/types/wchar_t.h>
+#include <bits/types/wint_t.h>
+
+#include <bits/NULL.h>
+#include <bits/floatn.h>
+#include <bits/wchar.h>
 
 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
 # include <bits/types/FILE.h>
diff --git a/wcsmbs/wcstol_l.c b/wcsmbs/wcstol_l.c
index 71e9cd4e90..219381d1f7 100644
--- a/wcsmbs/wcstol_l.c
+++ b/wcsmbs/wcstol_l.c
@@ -17,7 +17,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_wchar_t
 #include <stddef.h>
 #include <locale.h>
 
diff --git a/wcsmbs/wcstoll_l.c b/wcsmbs/wcstoll_l.c
index aba48ffcae..9bea4afc7c 100644
--- a/wcsmbs/wcstoll_l.c
+++ b/wcsmbs/wcstoll_l.c
@@ -17,7 +17,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_wchar_t
 #include <stddef.h>
 #include <locale.h>
 
diff --git a/wcsmbs/wcstoul_l.c b/wcsmbs/wcstoul_l.c
index 07d2e18a05..1811cbfafe 100644
--- a/wcsmbs/wcstoul_l.c
+++ b/wcsmbs/wcstoul_l.c
@@ -17,7 +17,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_wchar_t
 #include <stddef.h>
 #include <locale.h>
 
diff --git a/wcsmbs/wcstoull_l.c b/wcsmbs/wcstoull_l.c
index 179771e24c..cd0ef9c955 100644
--- a/wcsmbs/wcstoull_l.c
+++ b/wcsmbs/wcstoull_l.c
@@ -17,7 +17,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __need_wchar_t
 #include <stddef.h>
 #include <locale.h>
 
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 20/25] Don’t include sys/time.h from sys/timex.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
@ 2019-06-26 17:50 ` Zack Weinberg
  2019-06-26 17:50 ` [PATCH 16/25] Limit the set of strings.h functions also exposed in string.h Zack Weinberg
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 17:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

The interfaces defined in sys/timex.h only need struct timeval, not
any of the other things defined in sys/time.h.

While I was at it I moved stuff around so that sysdeps/…/linux/bits/timex.h
defines everything that uapi linux/timex.h defines (as of version 5.0;
alas, we still cannot use linux/timex.h directly) plus the
MOD_CLKA and MOD_CLKB constants.  In particular, the TIME_* constants
are relevant to users of clock_adjtime as well as adjtimex (I presume—
clock_adjtime is not very well documented) so they should be visible
from time.h as well as sys/timex.h.  Conversely, as far as I can tell,
struct ntptimeval was never a kernel interface on Linux, and MAXTC is
not part of the exposed API and also has the wrong value for current
kernels.   Also I removed a thoroughly obsolete bug workaround from
ntp_gettime.c and ntp_gettimex.c.

	* sysdeps/unix/sysv/linux/sys/timex.h: Don’t include sys/time.h.
	Update commentary.  Don’t define MAXTC.  Move definition of
	NTP_API and the TIME_* constants...
	* sysdeps/unix/sysv/linux/bits/timex.h: ...here.
	Allow inclusion only by sys/timex.h and bits/time.h.
	Update commentary.

        * sysdeps/unix/sysv/linux/ntp_gettime.c
        * sysdeps/unix/sysv/linux/ntp_gettimex.c: Remove obsolete
	check for MOD_OFFSET not being defined.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
	Update.
---
 scripts/check-obsolete-constructs.py   |  1 -
 sysdeps/unix/sysv/linux/bits/timex.h   | 20 ++++++++++++++++++--
 sysdeps/unix/sysv/linux/ntp_gettime.c  |  4 ----
 sysdeps/unix/sysv/linux/ntp_gettimex.c |  4 ----
 sysdeps/unix/sysv/linux/sys/timex.h    | 18 ++----------------
 5 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index d230fcf892..f456c98def 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -605,7 +605,6 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/signalfd.h":              [ "stdint.h" ],
     "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/timerfd.h":               [ "time.h" ],
-    "sys/timex.h":                 [ "sys/time.h" ],
     "sys/ttychars.h":              [ "sys/ttydefaults.h" ],
     "sys/ucontext.h":              [ "sys/procfs.h" ],
     "sys/vfs.h":                   [ "sys/statfs.h" ],
diff --git a/sysdeps/unix/sysv/linux/bits/timex.h b/sysdeps/unix/sysv/linux/bits/timex.h
index bb272e8b19..db36759fba 100644
--- a/sysdeps/unix/sysv/linux/bits/timex.h
+++ b/sysdeps/unix/sysv/linux/bits/timex.h
@@ -18,10 +18,16 @@
 #ifndef	_BITS_TIMEX_H
 #define	_BITS_TIMEX_H	1
 
+#if !defined _SYS_TIMEX_H && !defined _BITS_TIME_H
+# error "Never include <bits/timex.h> directly; use <sys/timex.h> instead."
+#endif
+
 #include <bits/types.h>
 #include <bits/types/struct_timeval.h>
 
-/* These definitions from linux/timex.h as of 3.18.  */
+/* These definitions match linux/timex.h as of 5.0.  */
+
+#define NTP_API	4		/* NTP API version */
 
 struct timex
 {
@@ -47,7 +53,7 @@ struct timex
 
   int tai;			/* TAI offset (ro) */
 
-  /* ??? */
+  /* room for future expansion */
   int  :32; int  :32; int  :32; int  :32;
   int  :32; int  :32; int  :32; int  :32;
   int  :32; int  :32; int  :32;
@@ -65,6 +71,7 @@ struct timex
 #define ADJ_MICRO		0x1000	/* select microsecond resolution */
 #define ADJ_NANO		0x2000	/* select nanosecond resolution */
 #define ADJ_TICK		0x4000	/* tick value */
+
 #define ADJ_OFFSET_SINGLESHOT	0x8001	/* old-fashioned adjtime */
 #define ADJ_OFFSET_SS_READ	0xa001	/* read-only adjtime */
 
@@ -107,4 +114,13 @@ struct timex
 #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER \
     | STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK)
 
+/* Clock states (codes returned by adjtimex) */
+#define TIME_OK		0	/* clock synchronized, no leap second */
+#define TIME_INS	1	/* insert leap second */
+#define TIME_DEL	2	/* delete leap second */
+#define TIME_OOP	3	/* leap second in progress */
+#define TIME_WAIT	4	/* leap second has occurred */
+#define TIME_ERROR	5	/* clock not synchronized */
+#define TIME_BAD	TIME_ERROR /* bw compat */
+
 #endif /* bits/timex.h */
diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c b/sysdeps/unix/sysv/linux/ntp_gettime.c
index cff9b603e0..571339f5d7 100644
--- a/sysdeps/unix/sysv/linux/ntp_gettime.c
+++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
@@ -21,10 +21,6 @@
 
 #undef ntp_gettime
 
-#ifndef MOD_OFFSET
-# define modes mode
-#endif
-
 
 int
 ntp_gettime (struct ntptimeval *ntv)
diff --git a/sysdeps/unix/sysv/linux/ntp_gettimex.c b/sysdeps/unix/sysv/linux/ntp_gettimex.c
index 044122bfd0..c83aa1e718 100644
--- a/sysdeps/unix/sysv/linux/ntp_gettimex.c
+++ b/sysdeps/unix/sysv/linux/ntp_gettimex.c
@@ -17,10 +17,6 @@
 
 #include <sys/timex.h>
 
-#ifndef MOD_OFFSET
-# define modes mode
-#endif
-
 
 int
 ntp_gettimex (struct ntptimeval *ntv)
diff --git a/sysdeps/unix/sysv/linux/sys/timex.h b/sysdeps/unix/sysv/linux/sys/timex.h
index c71ace1d3d..ee579466d1 100644
--- a/sysdeps/unix/sysv/linux/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/sys/timex.h
@@ -19,14 +19,11 @@
 #define	_SYS_TIMEX_H	1
 
 #include <features.h>
-#include <sys/time.h>
-
-/* These definitions from linux/timex.h as of 2.6.30.  */
 
+/* Get struct timex and related constants.  */
 #include <bits/timex.h>
 
-#define NTP_API	4	/* NTP API version */
-
+/* Parameter structure used by ntp_gettime(x).  */
 struct ntptimeval
 {
   struct timeval time;	/* current time (ro) */
@@ -40,17 +37,6 @@ struct ntptimeval
   long int __glibc_reserved4;
 };
 
-/* Clock states (time_state) */
-#define TIME_OK		0	/* clock synchronized, no leap second */
-#define TIME_INS	1	/* insert leap second */
-#define TIME_DEL	2	/* delete leap second */
-#define TIME_OOP	3	/* leap second in progress */
-#define TIME_WAIT	4	/* leap second has occurred */
-#define TIME_ERROR	5	/* clock not synchronized */
-#define TIME_BAD	TIME_ERROR /* bw compat */
-
-/* Maximum time constant of the PLL.  */
-#define MAXTC		6
 
 __BEGIN_DECLS
 
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 19/25] Don’t include string.h from sys/un.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (8 preceding siblings ...)
  2019-06-26 18:06 ` [PATCH 25/25] Rename sys/ucontext.h to bits/ucontext.h Zack Weinberg
@ 2019-06-26 18:06 ` Zack Weinberg
  2019-06-26 18:26 ` [PATCH 21/25] Don’t include sys/types.h or stdint.h from most public headers Zack Weinberg
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

sys/un.h needs strlen in order to define SUN_LEN, but does not need
any of the other things declared by string.h; the path of least
resistance is to prototype strlen locally.

Also, the construct being used to get the size of everything up to the
sun_path member contains a formal dereference of a null pointer and
therefore has undefined behavior.  Replace with __SOCKADDR_COMMON_SIZE.

Some old RPC code was relying on sys/un.h to provide all of string.h.

	* sys/un.h [__USE_MISC]: Don’t include string.h.
	Include bits/types/size_t.h.  Prototype strlen locally.
	Use __SOCKADDR_COMMON_SIZE for size of leading members of
	struct sockaddr_un.

	* nis/nis_domain_of.c, nis/yp_xdr.c, sunrpc/svc.c:
	Include string.h.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
	Update.
---
 nis/nis_domain_of.c                  | 1 +
 nis/yp_xdr.c                         | 1 +
 scripts/check-obsolete-constructs.py | 1 -
 socket/sys/un.h                      | 8 +++++---
 sunrpc/svc.c                         | 1 +
 5 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/nis/nis_domain_of.c b/nis/nis_domain_of.c
index 44c5b04c8c..da26df36c7 100644
--- a/nis/nis_domain_of.c
+++ b/nis/nis_domain_of.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <rpcsvc/nis.h>
+#include <string.h>
 #include <shlib-compat.h>
 
 nis_name
diff --git a/nis/yp_xdr.c b/nis/yp_xdr.c
index 3b576731da..4c9f1d22a0 100644
--- a/nis/yp_xdr.c
+++ b/nis/yp_xdr.c
@@ -31,6 +31,7 @@
 
 #include <rpcsvc/yp.h>
 #include <rpcsvc/ypclnt.h>
+#include <string.h>
 #include <shlib-compat.h>
 
 /* The NIS v2 protocol suggests 1024 bytes as a maximum length of all fields.
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index bca0f12c18..d230fcf892 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -539,7 +539,6 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/types.h":                 [ "endian.h" ],
 
     "sys/uio.h":                   [ "sys/types.h" ],
-    "sys/un.h":                    [ "string.h" ],
 
     # POSIX networking headers
     # allowed: netdb.h -> netinet/in.h
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 8c7433a3dc..540560e256 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -34,11 +34,13 @@ struct sockaddr_un
 
 
 #ifdef __USE_MISC
-# include <string.h>		/* For prototype of `strlen'.  */
+#include <bits/types/size_t.h>
+
+extern size_t strlen (const char *__s)
+     __THROW __attribute_pure__ __nonnull ((1));
 
 /* Evaluate to actual length of the `sockaddr_un' structure.  */
-# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)	      \
-		      + strlen ((ptr)->sun_path))
+# define SUN_LEN(ptr) (__SOCKADDR_COMMON_SIZE + strlen ((ptr)->sun_path))
 #endif
 
 __END_DECLS
diff --git a/sunrpc/svc.c b/sunrpc/svc.c
index 95ecfbb2d1..8042019ce9 100644
--- a/sunrpc/svc.c
+++ b/sunrpc/svc.c
@@ -53,6 +53,7 @@
  */
 
 #include <errno.h>
+#include <string.h>
 #include <unistd.h>
 #include <rpc/rpc.h>
 #include <rpc/svc.h>
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 25/25] Rename sys/ucontext.h to bits/ucontext.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (7 preceding siblings ...)
  2019-06-26 18:06 ` [PATCH 22/25] Minimize includes of unrelated public headers by networking headers Zack Weinberg
@ 2019-06-26 18:06 ` Zack Weinberg
  2019-06-26 18:06 ` [PATCH 19/25] Don’t include string.h from sys/un.h Zack Weinberg
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

sys/ucontext.h is effectively a bits header.  Its contents are
extremely system-specific, and it’s strongly associated with a
specific public header (ucontext.h) that provides a superset of its
definitions, but there are other public headers that also require some
of its definitions.  This patch therefore moves it into the bits/
namespace and adjusts all the headers that refer to it.  In case there
are external users, a stub is added that includes ucontext.h.

Most of the fallout changes are trivial, but aarch64, ia64 and riscv
need a little more work.  aarch64 sys/ucontext.h (now bits/ucontext.h)
was including sys/procfs.h for the definition of elf_greg_t etc;
the simplest fix is to have it include bits/procfs.h instead (and then
that needs to include sys/user.h for user_regs_struct).  This is not
ideal but fixing it properly would require disentangling all of the
debugger interface headers which is more than I’m up for at the moment.

ia64 bits/ptrace.h and bits/procfs.h were both including
bits/sigcontext.h, which is only licensed to be included from
signal.h.  (I’m not sure how this ever worked, or why it broke with
this patch and not some previous one.)  This is fixed by creating
another single-type header, bits/types/__ia64_fpreg.h, which provides
the only thing they need from bits/sigcontext.h.

s/u/s/l/riscv/makecontext.c was defining makecontext with a function
head that didn’t agree with its official prototype (in ucontext.h);
formerly that file did not include ucontext.h, only sys/ucontext.h,
so we were getting away with it, but it’s still wrong.  Making the
function head match the prototype actually simplifies the code.

	* sysdeps/generic/sys/ucontext.h: Move to top level bits/ucontext.h.
	Adjust multiple inclusion guard.
	* sysdeps/arm/sys/ucontext.h: Move to sysdeps/arm/bits/ucontext.h.
	Adjust multiple inclusion guard.
	* sysdeps/i386/sys/ucontext.h: Similarly.
	* sysdeps/m68k/sys/ucontext.h: Similarly.
	* sysdeps/mips/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/csky/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/ia64/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/microblaze/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/riscv/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h: Similarly.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h: Similarly.
	* stdlib/Makefile: Install bits/ucontext.h.

	* stdlib/sys/ucontext.h: New backward compatibility stub header,
	includes ucontext.h.
	* include/sys/ucontext.h: New wrapper.

	* sysdeps/unix/sysv/linux/aarch64/bits/procfs.h: Allow inclusion
	by bits/ucontext.h as well as sys/procfs.h.  Include sys/user.h.
	* sysdeps/unix/sysv/linux/aarch64/bits/ucontext.h: Include
	bits/procfs.h instead of sys/procfs.h.

	* sysdeps/unix/sysv/linux/ia64/bits/types/__ia64_fpreg.h:
	New file, contents factored out of ia64/bits/sigcontext.h and
	ia64/bits/ucontext.h.
	* sysdeps/unix/sysv/linux/ia64/Makefile:
	Install bits/types/__ia64_fpreg.h.  Merge subdir=misc blocks.
	* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
	* sysdeps/unix/sysv/linux/ia64/bits/ucontext.h:
	Include bits/types/__ia64_fpreg.h for struct ia64_fpreg.

	* sysdeps/unix/sysv/linux/ia64/bits/procfs.h:
	Include bits/types/__ia64_fpreg.h for struct ia64_fpreg.
	Don’t include bits/sigcontext.h or bits/ucontext.h.
	* sysdeps/unix/sysv/linux/ia64/sys/ptrace.h:
	Don’t include bits/sigcontext.h.

	* sysdeps/unix/sysv/linux/riscv/makecontext.c: Include
	ucontext.h, not sys/ucontext.h. Correct function head to match
	prototype in ucontext.h.  Use va_arg to retrieve all arguments
	past argc.

	* sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c:
	Sort list of includes.

	* signal/signal.h, stdlib/ucontext.h
	* sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
	* sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
	* sysdeps/unix/sysv/linux/riscv/bits/procfs.h
	* sysdeps/unix/sysv/linux/s390/bits/procfs.h:
	Include bits/ucontext.h, not sys/ucontext.h.

	* sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h
	* sysdeps/unix/sysv/linux/arm/sigcontextinfo.h
	* sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h
	* sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h:
	Include signal.h, not sys/ucontext.h.

	* sysdeps/unix/sysv/linux/arm/register-dump.h
	* sysdeps/unix/sysv/linux/csky/register-dump.h:
	Include ucontext.h, not sys/ucontext.h.

	* sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
	* sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
	* sysdeps/unix/sysv/linux/arm/ucontext_i.sym
	* sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym
	* sysdeps/unix/sysv/linux/hppa/ucontext_i.sym
	* sysdeps/unix/sysv/linux/i386/ucontext_i.sym
	* sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
	* sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
	* sysdeps/unix/sysv/linux/mips/ucontext_i.sym
	* sysdeps/unix/sysv/linux/nios2/ucontext_i.sym
	* sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
	* sysdeps/unix/sysv/linux/s390/ucontext_i.sym
	* sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
	* sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
	* sysdeps/unix/sysv/linux/sparc/sparc32/ucontext_i.sym
	* sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym:
	Include stddef.h and signal.h; don’t include any other headers.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES)
	(SYSDEP_ALLOWED_INCLUDES): Update.
---
 {sysdeps/generic/sys => bits}/ucontext.h      |  6 ++---
 include/sys/ucontext.h                        |  1 +
 scripts/check-obsolete-constructs.py          | 25 ++++++++-----------
 signal/signal.h                               |  2 +-
 stdlib/Makefile                               |  2 +-
 stdlib/sys/ucontext.h                         |  1 +
 stdlib/ucontext.h                             |  2 +-
 sysdeps/arm/{sys => bits}/ucontext.h          |  6 ++---
 sysdeps/i386/{sys => bits}/ucontext.h         |  6 ++---
 sysdeps/m68k/{sys => bits}/ucontext.h         |  6 ++---
 sysdeps/mips/{sys => bits}/ucontext.h         |  6 ++---
 sysdeps/unix/sysv/linux/aarch64/bits/procfs.h |  3 ++-
 .../linux/aarch64/{sys => bits}/ucontext.h    |  8 +++---
 .../unix/sysv/linux/aarch64/sigcontextinfo.h  |  2 +-
 .../unix/sysv/linux/aarch64/ucontext_i.sym    |  5 +---
 .../sysv/linux/alpha/bits/procfs-prregset.h   |  4 +--
 .../sysv/linux/alpha/{sys => bits}/ucontext.h |  6 ++---
 .../sysv/linux/alpha/ucontext-offsets.sym     |  2 +-
 .../sysv/linux/arm/{sys => bits}/ucontext.h   |  6 ++---
 sysdeps/unix/sysv/linux/arm/register-dump.h   |  2 +-
 sysdeps/unix/sysv/linux/arm/sigcontextinfo.h  |  2 +-
 sysdeps/unix/sysv/linux/arm/ucontext_i.sym    |  4 +--
 .../unix/sysv/linux/csky/abiv2/ucontext_i.sym |  4 +--
 .../sysv/linux/csky/{sys => bits}/ucontext.h  |  6 ++---
 sysdeps/unix/sysv/linux/csky/register-dump.h  |  2 +-
 .../sysv/linux/hppa/{sys => bits}/ucontext.h  |  6 ++---
 sysdeps/unix/sysv/linux/hppa/ucontext_i.sym   |  1 -
 sysdeps/unix/sysv/linux/i386/ucontext_i.sym   |  1 -
 sysdeps/unix/sysv/linux/ia64/Makefile         |  6 ++---
 sysdeps/unix/sysv/linux/ia64/bits/procfs.h    |  5 +---
 .../unix/sysv/linux/ia64/bits/sigcontext.h    |  9 +------
 .../sysv/linux/ia64/bits/types/__ia64_fpreg.h | 22 ++++++++++++++++
 .../sysv/linux/ia64/{sys => bits}/ucontext.h  | 18 ++++---------
 .../sysv/linux/ia64/sigcontext-offsets.sym    |  2 +-
 sysdeps/unix/sysv/linux/ia64/sys/ptrace.h     |  3 +--
 .../sysv/linux/m68k/{sys => bits}/ucontext.h  |  6 ++---
 .../sysv/linux/m68k/m680x0/ucontext_i.sym     |  1 -
 .../linux/microblaze/{sys => bits}/ucontext.h |  6 ++---
 .../sysv/linux/mips/{sys => bits}/ucontext.h  |  6 ++---
 sysdeps/unix/sysv/linux/mips/ucontext_i.sym   |  2 --
 .../sysv/linux/nios2/{sys => bits}/ucontext.h |  6 ++---
 .../unix/sysv/linux/nios2/sigcontextinfo.h    |  3 +--
 sysdeps/unix/sysv/linux/nios2/ucontext_i.sym  |  2 --
 .../linux/powerpc/{sys => bits}/ucontext.h    |  6 ++---
 .../linux/powerpc/powerpc32/ucontext_i.sym    |  1 -
 .../linux/powerpc/powerpc64/ucontext_i.sym    |  1 -
 sysdeps/unix/sysv/linux/riscv/bits/procfs.h   |  6 ++---
 .../sysv/linux/riscv/{sys => bits}/ucontext.h |  6 ++---
 sysdeps/unix/sysv/linux/riscv/makecontext.c   | 18 ++++---------
 .../unix/sysv/linux/riscv/sigcontextinfo.h    |  2 +-
 sysdeps/unix/sysv/linux/riscv/ucontext_i.sym  |  4 +--
 sysdeps/unix/sysv/linux/s390/bits/procfs.h    |  6 ++---
 .../sysv/linux/s390/{sys => bits}/ucontext.h  |  6 ++---
 .../sysv/linux/s390/tst-ptrace-singleblock.c  | 10 ++++----
 sysdeps/unix/sysv/linux/s390/ucontext_i.sym   |  1 -
 .../sysv/linux/sh/{sys => bits}/ucontext.h    |  6 ++---
 sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym |  1 -
 sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym |  1 -
 .../sysv/linux/sparc/{sys => bits}/ucontext.h |  6 ++---
 .../sysv/linux/sparc/sparc32/ucontext_i.sym   |  1 -
 .../sysv/linux/x86/{sys => bits}/ucontext.h   |  6 ++---
 sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym |  1 -
 62 files changed, 142 insertions(+), 171 deletions(-)
 rename {sysdeps/generic/sys => bits}/ucontext.h (95%)
 create mode 100644 include/sys/ucontext.h
 create mode 100644 stdlib/sys/ucontext.h
 rename sysdeps/arm/{sys => bits}/ucontext.h (96%)
 rename sysdeps/i386/{sys => bits}/ucontext.h (97%)
 rename sysdeps/m68k/{sys => bits}/ucontext.h (96%)
 rename sysdeps/mips/{sys => bits}/ucontext.h (97%)
 rename sysdeps/unix/sysv/linux/aarch64/{sys => bits}/ucontext.h (95%)
 rename sysdeps/unix/sysv/linux/alpha/{sys => bits}/ucontext.h (96%)
 rename sysdeps/unix/sysv/linux/arm/{sys => bits}/ucontext.h (97%)
 rename sysdeps/unix/sysv/linux/csky/{sys => bits}/ucontext.h (96%)
 rename sysdeps/unix/sysv/linux/hppa/{sys => bits}/ucontext.h (96%)
 create mode 100644 sysdeps/unix/sysv/linux/ia64/bits/types/__ia64_fpreg.h
 rename sysdeps/unix/sysv/linux/ia64/{sys => bits}/ucontext.h (91%)
 rename sysdeps/unix/sysv/linux/m68k/{sys => bits}/ucontext.h (97%)
 rename sysdeps/unix/sysv/linux/microblaze/{sys => bits}/ucontext.h (96%)
 rename sysdeps/unix/sysv/linux/mips/{sys => bits}/ucontext.h (97%)
 rename sysdeps/unix/sysv/linux/nios2/{sys => bits}/ucontext.h (95%)
 rename sysdeps/unix/sysv/linux/powerpc/{sys => bits}/ucontext.h (98%)
 rename sysdeps/unix/sysv/linux/riscv/{sys => bits}/ucontext.h (97%)
 rename sysdeps/unix/sysv/linux/s390/{sys => bits}/ucontext.h (96%)
 rename sysdeps/unix/sysv/linux/sh/{sys => bits}/ucontext.h (97%)
 rename sysdeps/unix/sysv/linux/sparc/{sys => bits}/ucontext.h (99%)
 rename sysdeps/unix/sysv/linux/x86/{sys => bits}/ucontext.h (98%)

diff --git a/sysdeps/generic/sys/ucontext.h b/bits/ucontext.h
similarity index 95%
rename from sysdeps/generic/sys/ucontext.h
rename to bits/ucontext.h
index b09bdf6743..5d8ec3469a 100644
--- a/sysdeps/generic/sys/ucontext.h
+++ b/bits/ucontext.h
@@ -21,8 +21,8 @@
    use of struct sigcontext does not conform to POSIX namespace
    requirements.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -51,4 +51,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/include/sys/ucontext.h b/include/sys/ucontext.h
new file mode 100644
index 0000000000..1450bae8f3
--- /dev/null
+++ b/include/sys/ucontext.h
@@ -0,0 +1 @@
+#include <stdlib/sys/ucontext.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 95360158b5..997b73bc36 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -504,24 +504,25 @@ HEADER_ALLOWED_INCLUDES = {
     #           tgmath.h   -> complex.h, math.h
     #           threads.h  -> time.h
     "inttypes.h":                  [ "stdint.h" ],
-    "signal.h":                    [ "sys/ucontext.h" ],
-    "stdlib.h":                    [ "alloca.h", "sys/types.h" ],
     "tgmath.h":                    [ "complex.h", "math.h" ],
     "threads.h":                   [ "time.h" ],
+    # necessary for backward compatibility with old GNU extensions
+    "stdlib.h":                    [ "alloca.h", "sys/types.h" ],
 
     # POSIX top-level headers
     # mandated: pthread.h -> sched.h, time.h
+    "pthread.h":                   [ "sched.h", "time.h" ],
     # allowed:  ftw.h -> sys/stat.h
     #           mqueue.h -> fcntl.h
     #           sched.h -> time.h
     #           spawn.h -> sched.h
     "ftw.h":                       [ "sys/stat.h" ],
-    "langinfo.h":                  [ "nl_types.h" ],
     "mqueue.h":                    [ "fcntl.h" ],
-    "pthread.h":                   [ "sched.h", "time.h" ],
-    "regex.h":                     [ "limits.h", "sys/types.h" ],
     "sched.h":                     [ "time.h" ],
     "spawn.h":                     [ "sched.h" ],
+    # not yet analyzed
+    "langinfo.h":                  [ "nl_types.h" ],
+    "regex.h":                     [ "limits.h", "sys/types.h" ],
     "termios.h":                   [ "sys/ttydefaults.h" ],
     "utmpx.h":                     [ "paths.h" ],
 
@@ -562,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
     "shadow.h":                    [ "paths.h" ],
     "stdio_ext.h":                 [ "stdio.h" ],
     "thread_db.h":                 [ "pthread.h", "stdint.h", "sys/procfs.h" ],
-    "ucontext.h":                  [ "sys/ucontext.h" ],
     "utmp.h":                      [ "paths.h" ],
     "values.h":                    [ "float.h", "limits.h" ],
 
@@ -574,12 +574,10 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/mount.h":                 [ "sys/ioctl.h" ],
     "sys/mtio.h":                  [ "sys/ioctl.h" ],
     "sys/param.h":                 [ "endian.h", "limits.h", "sys/types.h" ],
-    "sys/procfs.h":                [ "sys/ucontext.h", "sys/user.h" ],
-    "sys/ptrace.h":                [ "sys/ucontext.h" ],
+    "sys/procfs.h":                [ "sys/user.h" ],
     "sys/raw.h":                   [ "sys/ioctl.h" ],
     "sys/timerfd.h":               [ "time.h" ],
     "sys/ttychars.h":              [ "sys/ttydefaults.h" ],
-    "sys/ucontext.h":              [ "sys/procfs.h" ],
     "sys/vfs.h":                   [ "sys/statfs.h" ],
 
     # Nonstandardized headers that do nothing but include some other
@@ -597,6 +595,7 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/syslog.h":                [ "syslog.h" ],
     "sys/termios.h":               [ "termios.h" ],
+    "sys/ucontext.h":              [ "ucontext.h" ],
     "sys/unistd.h":                [ "unistd.h" ],
     "syscall.h":                   [ "sys/syscall.h" ],
     "termio.h":                    [ "sys/ioctl.h", "termios.h" ],
@@ -623,8 +622,6 @@ HEADER_ALLOWED_INCLUDES = {
     "features.h":                  [ "gnu/stubs.h", "stdc-predef.h",
                                      "sys/cdefs.h" ],
 
-    "bits/procfs.h":               [ "signal.h", "sys/ucontext.h" ],
-
     "bits/types/__va_list.h":      [ "stdarg.h" ],
     "bits/types/ptrdiff_t.h":      [ "stddef.h" ],
     "bits/types/size_t.h":         [ "stddef.h" ],
@@ -670,8 +667,8 @@ SYSDEP_ALLOWED_INCLUDES = {
         "bits/ioctls.h":           [ "asm/ioctls.h", "linux/sockios.h" ],
         "bits/local_lim.h":        [ "linux/limits.h" ],
         "bits/param.h":            [ "linux/limits.h", "linux/param.h" ],
-        "bits/procfs.h":           [ "asm/elf.h", "asm/ptrace.h" ],
-        "bits/procfs-prregset.h":  [ "sys/ucontext.h" ],
+        "bits/procfs.h":           [ "asm/elf.h", "asm/ptrace.h",
+                                     "sys/user.h" ],
         "bits/sigcontext.h":       [ "asm/sigcontext.h" ],
         "bits/socket.h":           [ "asm/socket.h" ],
     },
@@ -689,7 +686,6 @@ SYSDEP_ALLOWED_INCLUDES = {
         "sys/fpregdef.h":          [ "sgidefs.h" ],
         "sys/regdef.h":            [ "sgidefs.h" ],
         "sys/tas.h":               [ "sgidefs.h" ],
-        "sys/ucontext.h":          [ "sgidefs.h" ],
         "sys/user.h":              [ "sgidefs.h" ],
 
         "bits/fcntl.h":            [ "sgidefs.h" ],
@@ -699,6 +695,7 @@ SYSDEP_ALLOWED_INCLUDES = {
         "bits/setjmp.h":           [ "sgidefs.h" ],
         "bits/sigcontext.h":       [ "sgidefs.h" ],
         "bits/stat.h":             [ "sgidefs.h" ],
+        "bits/ucontext.h":         [ "sgidefs.h" ],
         "bits/wordsize.h":         [ "sgidefs.h" ],
     },
 }
diff --git a/signal/signal.h b/signal/signal.h
index 2c52466791..3ddd7ab9f4 100644
--- a/signal/signal.h
+++ b/signal/signal.h
@@ -293,7 +293,7 @@ extern int sigreturn (struct sigcontext *__scp) __THROW;
 # include <bits/types/stack_t.h>
 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
 /* This will define `ucontext_t' and `mcontext_t'.  */
-#  include <sys/ucontext.h>
+#  include <bits/ucontext.h>
 # endif
 #endif /* Use POSIX.1-2008 or X/Open Unix.  */
 
diff --git a/stdlib/Makefile b/stdlib/Makefile
index fbf1b84a4b..41609a965a 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -26,7 +26,7 @@ headers	:= stdlib.h bits/stdlib.h bits/stdlib-ldbl.h bits/stdlib-float.h      \
 	   monetary.h bits/monetary-ldbl.h				      \
 	   inttypes.h stdint.h bits/wordsize.h bits/timesize.h		      \
 	   errno.h sys/errno.h bits/errno.h bits/types/error_t.h	      \
-	   ucontext.h sys/ucontext.h bits/indirect-return.h		      \
+	   ucontext.h sys/ucontext.h bits/ucontext.h bits/indirect-return.h   \
 	   alloca.h fmtmsg.h						      \
 	   bits/stdlib-bsearch.h sys/random.h bits/stdint-intn.h	      \
 	   bits/stdint-uintn.h bits/time64.h bits/NULL.h		      \
diff --git a/stdlib/sys/ucontext.h b/stdlib/sys/ucontext.h
new file mode 100644
index 0000000000..5fdbd63dbb
--- /dev/null
+++ b/stdlib/sys/ucontext.h
@@ -0,0 +1 @@
+#include <ucontext.h>
diff --git a/stdlib/ucontext.h b/stdlib/ucontext.h
index ab97224e1a..f12587a66e 100644
--- a/stdlib/ucontext.h
+++ b/stdlib/ucontext.h
@@ -26,7 +26,7 @@
 #include <bits/indirect-return.h>
 
 /* Get machine dependent definition of data structures.  */
-#include <sys/ucontext.h>
+#include <bits/ucontext.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/arm/sys/ucontext.h b/sysdeps/arm/bits/ucontext.h
similarity index 96%
rename from sysdeps/arm/sys/ucontext.h
rename to sysdeps/arm/bits/ucontext.h
index bf210f0cc5..0436adb478 100644
--- a/sysdeps/arm/sys/ucontext.h
+++ b/sysdeps/arm/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* System V/ARM ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -107,4 +107,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/i386/sys/ucontext.h b/sysdeps/i386/bits/ucontext.h
similarity index 97%
rename from sysdeps/i386/sys/ucontext.h
rename to sysdeps/i386/bits/ucontext.h
index b1a5ab9156..74fd0e02d3 100644
--- a/sysdeps/i386/sys/ucontext.h
+++ b/sysdeps/i386/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* System V/i386 ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -135,4 +135,4 @@ typedef struct ucontext_t
 #undef __ctx
 #undef __ctxt
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/m68k/sys/ucontext.h b/sysdeps/m68k/bits/ucontext.h
similarity index 96%
rename from sysdeps/m68k/sys/ucontext.h
rename to sysdeps/m68k/bits/ucontext.h
index 2204cae370..9e50996b68 100644
--- a/sysdeps/m68k/sys/ucontext.h
+++ b/sysdeps/m68k/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* System V/m68k ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -122,4 +122,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/mips/sys/ucontext.h b/sysdeps/mips/bits/ucontext.h
similarity index 97%
rename from sysdeps/mips/sys/ucontext.h
rename to sysdeps/mips/bits/ucontext.h
index e5bbb46670..411f8419c3 100644
--- a/sysdeps/mips/sys/ucontext.h
+++ b/sysdeps/mips/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* System V/mips ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -173,4 +173,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h b/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h
index fec2f6a266..9603b025c7 100644
--- a/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h
@@ -20,11 +20,12 @@
 #ifndef _BITS_PROCFS_H
 #define _BITS_PROCFS_H 1
 
-#ifndef _SYS_PROCFS_H
+#if !defined _SYS_PROCFS_H && !defined _BITS_UCONTEXT_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
 #include <bits/types.h>
+#include <sys/user.h>
 
 /* Type for a general-purpose register.  */
 typedef __uint64_t elf_greg_t;
diff --git a/sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h b/sysdeps/unix/sysv/linux/aarch64/bits/ucontext.h
similarity index 95%
rename from sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/aarch64/bits/ucontext.h
index 140d4b3fc8..7be5302038 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/aarch64/bits/ucontext.h
@@ -18,8 +18,8 @@
 
 /* System V/AArch64 ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -33,7 +33,7 @@
 #endif
 
 #ifdef __USE_MISC
-# include <sys/procfs.h>
+# include <bits/procfs.h>
 
 
 typedef elf_greg_t greg_t;
@@ -75,4 +75,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h b/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h
index a0b0002c3d..fa0483f5f9 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h
@@ -17,7 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdint.h>
-#include <sys/ucontext.h>
+#include <signal.h>
 
 #define SIGCONTEXT siginfo_t *_si, ucontext_t *
 #define GET_PC(ctx) ((void *) (uintptr_t) (ctx)->uc_mcontext.pc)
diff --git a/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym b/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
index ab3930c173..7d5c4a1117 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
@@ -1,8 +1,5 @@
-#include <inttypes.h>
-#include <signal.h>
 #include <stddef.h>
-#include <sys/ucontext.h>
-#include <asm/sigcontext.h>
+#include <signal.h>
 
 #include "kernel_rt_sigframe.h"
 
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h b/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
index 58b015fbc6..33bc086b89 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
@@ -25,8 +25,8 @@
 #endif
 
 /* For gregset_t and fpregset_t.  FIXME: sys/procfs.h should not
-   expose all of sys/ucontext.h.  */
-#include <sys/ucontext.h>
+   expose all of bits/ucontext.h.  */
+#include <bits/ucontext.h>
 
 typedef gregset_t __prgregset_t;
 typedef fpregset_t __prfpregset_t;
diff --git a/sysdeps/unix/sysv/linux/alpha/sys/ucontext.h b/sysdeps/unix/sysv/linux/alpha/bits/ucontext.h
similarity index 96%
rename from sysdeps/unix/sysv/linux/alpha/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/alpha/bits/ucontext.h
index d2f93da8a7..284911797e 100644
--- a/sysdeps/unix/sysv/linux/alpha/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/ucontext.h
@@ -15,8 +15,8 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -91,4 +91,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym b/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
index 9e86f8a7ca..f57c779f5b 100644
--- a/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
+++ b/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
@@ -1,5 +1,5 @@
 #include <stddef.h>
-#include <sys/ucontext.h>
+#include <signal.h>
 
 --
 UC_LINK		offsetof (ucontext_t, uc_link)
diff --git a/sysdeps/unix/sysv/linux/arm/sys/ucontext.h b/sysdeps/unix/sysv/linux/arm/bits/ucontext.h
similarity index 97%
rename from sysdeps/unix/sysv/linux/arm/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/arm/bits/ucontext.h
index 76ea4dc343..60c72891c9 100644
--- a/sysdeps/unix/sysv/linux/arm/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/arm/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* System V/ARM ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -141,4 +141,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/arm/register-dump.h b/sysdeps/unix/sysv/linux/arm/register-dump.h
index 44c69a2552..f702c591fa 100644
--- a/sysdeps/unix/sysv/linux/arm/register-dump.h
+++ b/sysdeps/unix/sysv/linux/arm/register-dump.h
@@ -19,7 +19,7 @@
 
 #include <sys/uio.h>
 #include <_itoa.h>
-#include <sys/ucontext.h>
+#include <ucontext.h>
 
 /* We will print the register dump in this format:
 
diff --git a/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h b/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h
index 0bf3beaa0f..37049938b2 100644
--- a/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h
+++ b/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h
@@ -16,7 +16,7 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sys/ucontext.h>
+#include <signal.h>
 
 #define SIGCONTEXT siginfo_t *_si, ucontext_t *
 
diff --git a/sysdeps/unix/sysv/linux/arm/ucontext_i.sym b/sysdeps/unix/sysv/linux/arm/ucontext_i.sym
index 306292f1f8..ccf555d2ab 100644
--- a/sysdeps/unix/sysv/linux/arm/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/arm/ucontext_i.sym
@@ -1,7 +1,5 @@
-#include <inttypes.h>
-#include <signal.h>
 #include <stddef.h>
-#include <sys/ucontext.h>
+#include <signal.h>
 
 SIG_BLOCK
 SIG_SETMASK
diff --git a/sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym b/sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym
index 4581b65e49..0ee6dd0584 100644
--- a/sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym
@@ -1,7 +1,5 @@
-#include <inttypes.h>
-#include <signal.h>
 #include <stddef.h>
-#include <sys/ucontext.h>
+#include <signal.h>
 
 SIG_BLOCK
 SIG_SETMASK
diff --git a/sysdeps/unix/sysv/linux/csky/sys/ucontext.h b/sysdeps/unix/sysv/linux/csky/bits/ucontext.h
similarity index 96%
rename from sysdeps/unix/sysv/linux/csky/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/csky/bits/ucontext.h
index 5eac9e6494..90ee71bfd3 100644
--- a/sysdeps/unix/sysv/linux/csky/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/csky/bits/ucontext.h
@@ -16,8 +16,8 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -86,4 +86,4 @@ typedef struct ucontext_t
 #undef __ctx
 
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/csky/register-dump.h b/sysdeps/unix/sysv/linux/csky/register-dump.h
index 949618911e..47b273ba80 100644
--- a/sysdeps/unix/sysv/linux/csky/register-dump.h
+++ b/sysdeps/unix/sysv/linux/csky/register-dump.h
@@ -19,7 +19,7 @@
 #include <sys/uio.h>
 #include <_itoa.h>
 #include <bits/sigcontext.h>
-#include <sys/ucontext.h>
+#include <ucontext.h>
 
 /* abiv1 register dump in this format:
 
diff --git a/sysdeps/unix/sysv/linux/hppa/sys/ucontext.h b/sysdeps/unix/sysv/linux/hppa/bits/ucontext.h
similarity index 96%
rename from sysdeps/unix/sysv/linux/hppa/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/hppa/bits/ucontext.h
index 9a55d93a06..fe8a82fddc 100644
--- a/sysdeps/unix/sysv/linux/hppa/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* Don't rely on this, the interface is currently messed up and may need to
    be broken to be fixed.  */
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -79,4 +79,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/hppa/ucontext_i.sym b/sysdeps/unix/sysv/linux/hppa/ucontext_i.sym
index ee33029a07..1ec474c759 100644
--- a/sysdeps/unix/sysv/linux/hppa/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/hppa/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/i386/ucontext_i.sym b/sysdeps/unix/sysv/linux/i386/ucontext_i.sym
index b11a5509cd..79d95709f2 100644
--- a/sysdeps/unix/sysv/linux/i386/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/i386/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/ia64/Makefile b/sysdeps/unix/sysv/linux/ia64/Makefile
index 97fc7df0b1..36240a6057 100644
--- a/sysdeps/unix/sysv/linux/ia64/Makefile
+++ b/sysdeps/unix/sysv/linux/ia64/Makefile
@@ -1,5 +1,5 @@
-ifeq ($(subdir),misc)
-sysdep_headers += sys/rse.h
+ifeq ($(subdir),signal)
+sysdep_headers += bits/types/__ia64_fpreg.h
 endif
 
 ifeq ($(subdir),stdlib)
@@ -8,7 +8,7 @@ gen-as-const-headers += sigcontext-offsets.sym
 endif
 
 ifeq ($(subdir),misc)
-sysdep_headers += sys/io.h
+sysdep_headers += sys/io.h sys/rse.h
 sysdep_routines += ioperm clone2
 gen-as-const-headers += sigaltstack-offsets.sym
 endif
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/procfs.h b/sysdeps/unix/sysv/linux/ia64/bits/procfs.h
index 754e9690c9..def7e5b87f 100644
--- a/sysdeps/unix/sysv/linux/ia64/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/procfs.h
@@ -23,10 +23,7 @@
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-/* For struct __ia64_fpreg.  FIXME: sys/procfs.h should not expose all
-   of sys/ucontext.h.  */
-#include <sys/ucontext.h>
-#include <bits/sigcontext.h>
+#include <bits/types/__ia64_fpreg.h>
 
 /* We really need just 72 but let's leave some headroom...  */
 #define ELF_NGREG	128
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h b/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
index b1b45ee5de..54047467a9 100644
--- a/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
@@ -26,17 +26,10 @@
 #include <bits/types/size_t.h>
 #include <bits/types/struct_sigstack.h>
 #include <bits/types/stack_t.h>
+#include <bits/types/__ia64_fpreg.h>
 #include <bits/sigstack.h>
 #include <bits/ss_flags.h>
 
-struct __ia64_fpreg
-  {
-    union
-      {
-	unsigned long bits[2];
-      } u;
-  } __attribute__ ((__aligned__ (16)));
-
 struct sigcontext
 {
   unsigned long int sc_flags;	/* see manifest constants below */
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/types/__ia64_fpreg.h b/sysdeps/unix/sysv/linux/ia64/bits/types/__ia64_fpreg.h
new file mode 100644
index 0000000000..6d69586ab4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ia64/bits/types/__ia64_fpreg.h
@@ -0,0 +1,22 @@
+#ifndef ____ia64_fpreg_defined
+#define ____ia64_fpreg_defined
+
+#include <features.h>
+
+#ifdef __USE_MISC
+# define __ctx(fld) fld
+#else
+# define __ctx(fld) __ ## fld
+#endif
+
+struct __ia64_fpreg
+  {
+    union
+      {
+	unsigned long __ctx(bits)[2];
+      } __ctx(u);
+  } __attribute__ ((__aligned__ (16)));
+
+#undef __ctx
+
+#endif /* __ia64_fpreg */
diff --git a/sysdeps/unix/sysv/linux/ia64/sys/ucontext.h b/sysdeps/unix/sysv/linux/ia64/bits/ucontext.h
similarity index 91%
rename from sysdeps/unix/sysv/linux/ia64/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/ia64/bits/ucontext.h
index 2aeac65346..219526c54b 100644
--- a/sysdeps/unix/sysv/linux/ia64/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/ucontext.h
@@ -15,14 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
 #include <bits/types/sigset_t.h>
 #include <bits/types/stack_t.h>
-
+#include <bits/types/__ia64_fpreg.h>
 
 #ifdef __USE_MISC
 # define __ctx(fld) fld
@@ -36,14 +36,6 @@
  * "ucontext_t" as all the necessary info is inside the former.
  */
 
-struct __ia64_fpreg_mcontext
-  {
-    union
-      {
-	unsigned long __ctx(bits)[2];
-      } __ctx(u);
-  } __attribute__ ((__aligned__ (16)));
-
 typedef struct
   {
     unsigned long int __ctx(sc_flags);
@@ -63,7 +55,7 @@ typedef struct
     unsigned long int __ctx(sc_pr);
     unsigned long int __ctx(sc_br)[8];
     unsigned long int __ctx(sc_gr)[32];
-    struct __ia64_fpreg_mcontext __ctx(sc_fr)[128];
+    struct __ia64_fpreg __ctx(sc_fr)[128];
     unsigned long int __ctx(sc_rbs_base);
     unsigned long int __ctx(sc_loadrs);
     unsigned long int __ctx(sc_ar25);
@@ -103,4 +95,4 @@ ucontext_t;
 #define uc_stack	_u._mc.__ctx(sc_stack)
 #define uc_link		_u._uc._link
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym b/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
index ac3e3c8dea..46459f7ad0 100644
--- a/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
+++ b/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
@@ -1,5 +1,5 @@
 #include <stddef.h>
-#include <sys/ucontext.h>
+#include <signal.h>
 
 --
 SC_NAT		offsetof (mcontext_t, sc_nat)
diff --git a/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h b/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
index 4578ffb50f..9f12f59a71 100644
--- a/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
@@ -20,9 +20,8 @@
 #define _SYS_PTRACE_H	1
 
 #include <features.h>
-#include <sys/ucontext.h>
-#include <bits/sigcontext.h>
 #include <bits/types.h>
+#include <bits/ucontext.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/m68k/sys/ucontext.h b/sysdeps/unix/sysv/linux/m68k/bits/ucontext.h
similarity index 97%
rename from sysdeps/unix/sysv/linux/m68k/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/m68k/bits/ucontext.h
index 8a3b69d60e..11752ce3da 100644
--- a/sysdeps/unix/sysv/linux/m68k/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/m68k/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* System V/m68k ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -127,4 +127,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym b/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
index 46bd4bf15f..400c57b7f3 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/microblaze/sys/ucontext.h b/sysdeps/unix/sysv/linux/microblaze/bits/ucontext.h
similarity index 96%
rename from sysdeps/unix/sysv/linux/microblaze/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/microblaze/bits/ucontext.h
index cbdc677f90..1f168ea0bf 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/microblaze/bits/ucontext.h
@@ -16,8 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -89,4 +89,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/mips/sys/ucontext.h b/sysdeps/unix/sysv/linux/mips/bits/ucontext.h
similarity index 97%
rename from sysdeps/unix/sysv/linux/mips/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/mips/bits/ucontext.h
index 39fe23cb13..0b2c02c7de 100644
--- a/sysdeps/unix/sysv/linux/mips/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/ucontext.h
@@ -16,8 +16,8 @@
 
 /* Don't rely on this, the interface is currently messed up and may need to
    be broken to be fixed.  */
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -121,4 +121,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/mips/ucontext_i.sym b/sysdeps/unix/sysv/linux/mips/ucontext_i.sym
index f14b886407..d9692adcba 100644
--- a/sysdeps/unix/sysv/linux/mips/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/mips/ucontext_i.sym
@@ -1,7 +1,5 @@
-#include <inttypes.h>
 #include <signal.h>
 #include <stddef.h>
-#include <sys/ucontext.h>
 
 #include <kernel_rt_sigframe.h>
 
diff --git a/sysdeps/unix/sysv/linux/nios2/sys/ucontext.h b/sysdeps/unix/sysv/linux/nios2/bits/ucontext.h
similarity index 95%
rename from sysdeps/unix/sysv/linux/nios2/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/nios2/bits/ucontext.h
index e3773ce90c..8549117f32 100644
--- a/sysdeps/unix/sysv/linux/nios2/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/nios2/bits/ucontext.h
@@ -18,8 +18,8 @@
 
 /* System V/Nios II ABI compliant context switching support.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -58,4 +58,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h b/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h
index dbbb47b50d..9a4e5111ee 100644
--- a/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h
+++ b/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h
@@ -16,8 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sys/ucontext.h>
-#include "kernel-features.h"
+#include <signal.h>
 
 #define SIGCONTEXT siginfo_t *_si, ucontext_t *
 #define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.regs[27])
diff --git a/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym b/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym
index a844c96796..5455cdb681 100644
--- a/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym
@@ -1,7 +1,5 @@
-#include <inttypes.h>
 #include <signal.h>
 #include <stddef.h>
-#include <sys/ucontext.h>
 
 #include "kernel_rt_sigframe.h"
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h b/sysdeps/unix/sysv/linux/powerpc/bits/ucontext.h
similarity index 98%
rename from sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/powerpc/bits/ucontext.h
index 640381a5c7..324ec3ce19 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/ucontext.h
@@ -15,8 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -197,4 +197,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
index 293761f260..e1b22b844e 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym b/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
index 8364e4614f..b2d420e15e 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/procfs.h b/sysdeps/unix/sysv/linux/riscv/bits/procfs.h
index 6ab26013a6..4e2dae40dc 100644
--- a/sysdeps/unix/sysv/linux/riscv/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/riscv/bits/procfs.h
@@ -23,10 +23,10 @@
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-/* FIXME: sys/ucontext.h does not define NGREG or NFPREG unless
+/* FIXME: bits/ucontext.h does not define NGREG or NFPREG unless
    __USE_MISC is active, and sys/procfs.h should not expose all of
-   sys/ucontext.h.  */
-#include <sys/ucontext.h>
+   bits/ucontext.h.  */
+#include <bits/ucontext.h>
 
 /* ELF register definitions */
 #define ELF_NGREG	NGREG
diff --git a/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h b/sysdeps/unix/sysv/linux/riscv/bits/ucontext.h
similarity index 97%
rename from sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/riscv/bits/ucontext.h
index 6f62eb3d08..48ff2cd5af 100644
--- a/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/riscv/bits/ucontext.h
@@ -18,8 +18,8 @@
 
 /* Don't rely on this, the interface is currently messed up and may need to
    be broken to be fixed.  */
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -107,4 +107,4 @@ typedef struct ucontext_t
     mcontext_t uc_mcontext;
   } ucontext_t;
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/riscv/makecontext.c b/sysdeps/unix/sysv/linux/riscv/makecontext.c
index 671f20203d..8a929bf54a 100644
--- a/sysdeps/unix/sysv/linux/riscv/makecontext.c
+++ b/sysdeps/unix/sysv/linux/riscv/makecontext.c
@@ -18,14 +18,12 @@
 
 #include <sysdep.h>
 #include <sys/asm.h>
-#include <sys/ucontext.h>
+#include <ucontext.h>
 #include <stdarg.h>
 #include <assert.h>
 
 void
-__makecontext (ucontext_t *ucp, void (*func) (void), int argc,
-	       long int a0, long int a1, long int a2, long int a3, long int a4,
-	       ...)
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
 {
   extern void __start_context (void) attribute_hidden;
   long int i, sp;
@@ -47,19 +45,13 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int argc,
   ucp->uc_mcontext.__gregs[REG_PC] = (long int) &__start_context;
 
   /* Put args in a0-a7, then put any remaining args on the stack.  */
-  ucp->uc_mcontext.__gregs[REG_A0 + 0] = a0;
-  ucp->uc_mcontext.__gregs[REG_A0 + 1] = a1;
-  ucp->uc_mcontext.__gregs[REG_A0 + 2] = a2;
-  ucp->uc_mcontext.__gregs[REG_A0 + 3] = a3;
-  ucp->uc_mcontext.__gregs[REG_A0 + 4] = a4;
-
-  if (__glibc_unlikely (argc > 5))
+  if (argc > 0)
     {
       va_list vl;
-      va_start (vl, a4);
+      va_start (vl, argc);
 
       long reg_args = argc < REG_NARGS ? argc : REG_NARGS;
-      for (i = 5; i < reg_args; i++)
+      for (i = 0; i < reg_args; i++)
         ucp->uc_mcontext.__gregs[REG_A0 + i] = va_arg (vl, long);
 
       long int stack_args = argc - reg_args;
diff --git a/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h b/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h
index 27ed9bdb87..5f7ba368ed 100644
--- a/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h
+++ b/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h
@@ -16,7 +16,7 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sys/ucontext.h>
+#include <signal.h>
 
 #define SIGCONTEXT siginfo_t *_si, ucontext_t *
 #define GET_PC(ctx)	((void *) ctx->uc_mcontext.__gregs[REG_PC])
diff --git a/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym b/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
index be55b26310..105b538684 100644
--- a/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
@@ -1,7 +1,5 @@
-#include <inttypes.h>
-#include <signal.h>
 #include <stddef.h>
-#include <sys/ucontext.h>
+#include <signal.h>
 
 -- Constants used by the rt_sigprocmask call.
 
diff --git a/sysdeps/unix/sysv/linux/s390/bits/procfs.h b/sysdeps/unix/sysv/linux/s390/bits/procfs.h
index 597ccdb754..c2a4b54cb1 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/procfs.h
@@ -23,9 +23,9 @@
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-/* FIXME: sys/ucontext.h does not define NGREG unless __USE_MISC is
-   active, and sys/procfs.h should not expose all of sys/ucontext.h.  */
-#include <sys/ucontext.h>
+/* FIXME: bits/ucontext.h does not define NGREG unless __USE_MISC is
+   active, and sys/procfs.h should not expose all of bits/ucontext.h.  */
+#include <bits/ucontext.h>
 
 typedef greg_t elf_greg_t;
 #define ELF_NGREG NGREG
diff --git a/sysdeps/unix/sysv/linux/s390/sys/ucontext.h b/sysdeps/unix/sysv/linux/s390/bits/ucontext.h
similarity index 96%
rename from sysdeps/unix/sysv/linux/s390/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/s390/bits/ucontext.h
index c1770ca6d4..4ce1ee8717 100644
--- a/sysdeps/unix/sysv/linux/s390/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/ucontext.h
@@ -16,8 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -92,4 +92,4 @@ typedef struct ucontext_t
 #undef __ctx
 
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c b/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c
index e7d36d2d75..1c2aed9ddb 100644
--- a/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c
+++ b/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c
@@ -16,19 +16,19 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <elf.h>
+#include <errno.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/uio.h>
-#include <elf.h>
-#include <support/xunistd.h>
+#include <sys/wait.h>
+
 #include <support/check.h>
-#include <string.h>
-#include <errno.h>
+#include <support/xunistd.h>
 
 /* Ensure that we use the PTRACE_SINGLEBLOCK definition from glibc ptrace.h
    in tracer_func.  We need the kernel ptrace.h for structs ptrace_area
diff --git a/sysdeps/unix/sysv/linux/s390/ucontext_i.sym b/sysdeps/unix/sysv/linux/s390/ucontext_i.sym
index 6cc9f19624..5b98555049 100644
--- a/sysdeps/unix/sysv/linux/s390/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/s390/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/sh/sys/ucontext.h b/sysdeps/unix/sysv/linux/sh/bits/ucontext.h
similarity index 97%
rename from sysdeps/unix/sysv/linux/sh/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/sh/bits/ucontext.h
index 9092103a7d..65b66cea37 100644
--- a/sysdeps/unix/sysv/linux/sh/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/sh/bits/ucontext.h
@@ -17,8 +17,8 @@
 
 /* Where is System V/SH ABI?  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -123,4 +123,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym b/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
index 25f914a93b..4cd312ac5d 100644
--- a/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym b/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
index 130f60cd96..530a06f6d0 100644
--- a/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/sparc/sys/ucontext.h b/sysdeps/unix/sysv/linux/sparc/bits/ucontext.h
similarity index 99%
rename from sysdeps/unix/sysv/linux/sparc/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/sparc/bits/ucontext.h
index a125084c78..9c3f4e3f55 100644
--- a/sysdeps/unix/sysv/linux/sparc/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/ucontext.h
@@ -15,8 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -301,4 +301,4 @@ typedef struct ucontext_t
   } ucontext_t;
 
 #endif /* __WORDSIZE == 32 */
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/ucontext_i.sym b/sysdeps/unix/sysv/linux/sparc/sparc32/ucontext_i.sym
index 8a7cb5ab84..0fe920d35a 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
diff --git a/sysdeps/unix/sysv/linux/x86/sys/ucontext.h b/sysdeps/unix/sysv/linux/x86/bits/ucontext.h
similarity index 98%
rename from sysdeps/unix/sysv/linux/x86/sys/ucontext.h
rename to sysdeps/unix/sysv/linux/x86/bits/ucontext.h
index 3d883c2bf1..e78658394f 100644
--- a/sysdeps/unix/sysv/linux/x86/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/ucontext.h
@@ -15,8 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef _SYS_UCONTEXT_H
-#define _SYS_UCONTEXT_H	1
+#ifndef _BITS_UCONTEXT_H
+#define _BITS_UCONTEXT_H	1
 
 #include <features.h>
 
@@ -259,4 +259,4 @@ typedef struct ucontext_t
 
 #undef __ctx
 
-#endif /* sys/ucontext.h */
+#endif /* bits/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym b/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym
index c08b3b8b47..4bffe048a0 100644
--- a/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym
+++ b/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym
@@ -1,6 +1,5 @@
 #include <stddef.h>
 #include <signal.h>
-#include <sys/ucontext.h>
 
 --
 
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 22/25] Minimize includes of unrelated public headers by networking headers.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (6 preceding siblings ...)
  2019-06-26 17:50 ` [PATCH 15/25] Don’t rely on stddef.h or stdarg.h for individual type definitions Zack Weinberg
@ 2019-06-26 18:06 ` Zack Weinberg
  2019-06-26 18:06 ` [PATCH 25/25] Rename sys/ucontext.h to bits/ucontext.h Zack Weinberg
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

Stop including sys/param.h, sys/types.h, stdint.h, inttypes.h,
stdio.h, and string.h from network-related headers.  This is done
separately from earlier patches because the network headers are extra
messy, and are also more likely to contain quirks inherited verbatim
from 4.xBSD than the bulk of our public headers.

Rose and NetROM are based on AX.25 so it makes practical sense for
netrose/rose.h and netrom/netrom.h to continue including netax25/ax25.h.

The only copies of ip_icmp.h and udp.h in the source tree are moved
from sysdeps/gnu to inet (after which there are no longer any netinet/
headers in sysdeps/gnu).

Much as sys/un.h needs to duplicate the prototype for strlen,
netinet/icmp6.h needs to duplicate the prototype for memset.  I am
open to better ideas on that front.

	* resolv/resolv.h: Include bits/types.h, bits/types/FILE.h,
	and bits/types/size_t.h; don’t include sys/param.h, sys/types.h,
	or stdio.h.  Use __uint16_t and __uint32_t instead of uint16_t and
	uint32_t.
	* resolv/arpa/nameser.h: Include features.h, bits/types.h, and
	bits/types/size_t.h; don’t include sys/param.h, sys/types.h, or
	stdint.h.  Use __uint16_t and __uint32_t instead of uint16_t and
	uint32_t.
	* resolv/arpa/nameser_compat.h: Include features.h.

	* sysdeps/mach/hurd/net/ethernet.h: Include bits/types.h;
	don’t include sys/types.h or stdint.h.  Use __uint8_t and
	__uint16_t instead of uint8_t and uint16_t.
	* sysdeps/unix/sysv/linux/net/ethernet.h: Include features.h and
	bits/types.h; don’t include sys/types.h or stdint.h.
	Use __uint8_t and __uint16_t instead of uint8_t and uint16_t.
	* sysdeps/unix/sysv/linux/netinet/if_ether.h:  Include features.h
	and bits/types.h.  Use __uint8_t instead of uint8_t.

	* sysdeps/mach/hurd/net/if_arp.h: Don’t include sys/types.h or
	stdint.h. Use __uint32_t instead of uint32_t.
	* sysdeps/unix/sysv/linux/net/if_arp.h: Include features.h.
	Don’t include sys/types.h or stdint.h. Use __uint32_t instead of
	uint32_t.

	* sysdeps/mach/hurd/net/route.h: Don’t include sys/types.h.
	* sysdeps/unix/sysv/linux/net/route.h: Don’t include sys/types.h.

	* sysdeps/unix/sysv/linux/net/if_ppp.h: Include features.h and
	bits/types.h.  Don’t include sys/types.h or stdint.h.  Use
	__uint8_t and __uint32_t instead of uint8_t and uint32_t.
	* sysdeps/unix/sysv/linux/net/if_shaper.h: Include features.h and
	bits/types.h.  Don’t include sys/types.h or stdint.h.  Use
	__uint16_t and __uint32_t instead of uint16_t and uint32_t.

	* sysdeps/unix/sysv/linux/netatalk/at.h: Include features.h,
	bits/types.h, and sys/ioctl.h.  Don’t include asm/types.h or
	linux/atalk.h.  Copy over all user-appropriate definitions from
	linux/atalk.h with adjustments for glibc context.

	* grp/initgroups.c, nscd/initgrcache.c, nss/nss_db/db-XXX.c
	* resolv/ns_print.c, resolv/tst-ns_name_compress.c
	* resolv/tst-res_hnok.c, support/resolv_test.c:
	Include stdio.h.

	* nscd/initgrcache.c, nscd/netgroupcache.c
	* nss/nss_compat/compat-grp.c, nss/nss_compat/compat-pwd.c
	* nss/nss_compat/compat-spwd.c, resolv/ns_print.c:
	Include sys/param.h for MIN and/or MAX.

	* resolv/tst-resolv-res_init-skeleton.c: Include signal.h.

	* inet/protocols/rwhod.h: Include features.h and bits/types.h.
	Don’t include sys/types.h.  Use __int32_t instead of int32_t.
	* inet/protocols/talkd.h: Include features.h and bits/types.h.
	Don’t include sys/types.h, sys/socket.h, or stdint.h. Use
	__int32_t and __uint32_t instead of int32_t and uint32_t.
	* inet/protocols/timed.h: Include features.h, bits/types.h,
	and bits/types/struct_timeval.h. Don’t include sys/types.h or
	sys/time.h.
	* sysdeps/unix/sysv/linux/netipx/ipx.h: Include features.h and
	bits/types.h.  Don’t include sys/types.h or stdint.h. Use
	__uint16_t and __uint32_t instead of uint16_t and uint32_t.
	* sysdeps/unix/sysv/linux/netrose/rose.h: Include features.h.
	Don’t include sys/socket.h.

	* inet/netinet/icmp6.h: Include features.h, bits/endian.h,
	bits/types.h, and bits/types/size_t.h.  Don’t include inttypes.h,
	string.h, or sys/types.h.  Duplicate prototype of memset here.
	Use __uintN_t instead of uintN_t types.
	* inet/netinet/igmp.h: Include bits/types.h.  Don’t include sys/types.h.
	Use __uintN_t instead of uintN_t types.
	* inet/netinet/ip.h: Include bits/types.h.  Don’t include
	bits/stdint-uintn.h.  Use __uintN_t instead of uintN_t types.
	* inet/netinet/ip6.h: Include features.h, bits/endian.h, and
	bits/types.h.  Don’t include inttypes.h.  Use __uintN_t instead of
	uintN_t types.

	* inet/netinet/ip_icmp.h: Include features.h and bits/types.h.
	Don’t include sys/types.h or stdint.h.  Use __uintN_t instead of
	uintN_t types.
	* inet/netinet/udp.h: Likewise.
	* sysdeps/generic/netinet/if_ether.h: Likewise.
	* sysdeps/unix/sysv/linux/netinet/if_ether.h: Likewise.
	* sysdeps/unix/sysv/linux/netinet/if_fddi.h: Likewise.
	* sysdeps/unix/sysv/linux/netinet/if_tr.h: Likewise.

	* sysdeps/gnu/netinet/ip_icmp.h: Move to inet/netinet/ip_icmp.h.
	* sysdeps/gnu/netinet/udp.h: Move to inet/netinet/udp.h.
	* include/netinet/ip_icmp.h, include/netinet/udp.h: New wrappers.
	* sysdeps/gnu/Makefile: Remove $(subdir)==inet stanza.
	* inet/Makefile (headers): Add netinet/ip_icmp.h and
	netinet/udp.h. Don’t use $(wildcard *.h) for arpa and protocols
	headers.  Sort list.

	* scripts/check-obsolete-constructs.py
	(HEADER_ALLOWED_INCLUDES, SYSDEP_ALLOWED_INCLUDES): Update.
---
 grp/initgroups.c                           |   1 +
 include/netinet/ip_icmp.h                  |   1 +
 include/netinet/udp.h                      |   1 +
 inet/Makefile                              |  11 +-
 inet/netinet/icmp6.h                       | 123 +++++++++++----------
 inet/netinet/igmp.h                        |   9 +-
 inet/netinet/ip.h                          |  40 +++----
 inet/netinet/ip6.h                         |  86 +++++++-------
 {sysdeps/gnu => inet}/netinet/ip_icmp.h    |  56 +++++-----
 {sysdeps/gnu => inet}/netinet/udp.h        |  20 ++--
 inet/protocols/rwhod.h                     |   5 +-
 inet/protocols/talkd.h                     |  11 +-
 inet/protocols/timed.h                     |   5 +-
 nscd/initgrcache.c                         |   2 +
 nscd/netgroupcache.c                       |   1 +
 nss/nss_compat/compat-grp.c                |   1 +
 nss/nss_compat/compat-pwd.c                |   1 +
 nss/nss_compat/compat-spwd.c               |   1 +
 nss/nss_db/db-XXX.c                        |   1 +
 resolv/arpa/nameser.h                      |  34 +++---
 resolv/arpa/nameser_compat.h               |   1 +
 resolv/ns_print.c                          |   2 +
 resolv/resolv.h                            |  13 ++-
 resolv/tst-ns_name_compress.c              |   1 +
 resolv/tst-res_hnok.c                      |   1 +
 scripts/check-obsolete-constructs.py       |  53 ++++-----
 support/resolv_test.c                      |   1 +
 sysdeps/generic/netinet/if_ether.h         |   6 +-
 sysdeps/gnu/Makefile                       |   5 -
 sysdeps/mach/hurd/net/ethernet.h           |  12 +-
 sysdeps/mach/hurd/net/if_arp.h             |   5 +-
 sysdeps/mach/hurd/net/route.h              |   3 +-
 sysdeps/unix/sysv/linux/net/ethernet.h     |  12 +-
 sysdeps/unix/sysv/linux/net/if_arp.h       |   5 +-
 sysdeps/unix/sysv/linux/net/if_ppp.h       |  10 +-
 sysdeps/unix/sysv/linux/net/if_shaper.h    |   8 +-
 sysdeps/unix/sysv/linux/net/route.h        |   2 +-
 sysdeps/unix/sysv/linux/netatalk/at.h      |  41 ++++++-
 sysdeps/unix/sysv/linux/netinet/if_ether.h |  21 ++--
 sysdeps/unix/sysv/linux/netinet/if_fddi.h  |  14 ++-
 sysdeps/unix/sysv/linux/netinet/if_tr.h    |  68 ++++++------
 sysdeps/unix/sysv/linux/netipx/ipx.h       |  10 +-
 sysdeps/unix/sysv/linux/netrose/rose.h     |   2 +-
 43 files changed, 370 insertions(+), 336 deletions(-)
 create mode 100644 include/netinet/ip_icmp.h
 create mode 100644 include/netinet/udp.h
 rename {sysdeps/gnu => inet}/netinet/ip_icmp.h (91%)
 rename {sysdeps/gnu => inet}/netinet/udp.h (91%)

diff --git a/grp/initgroups.c b/grp/initgroups.c
index a22f33c934..6edfb0a678 100644
--- a/grp/initgroups.c
+++ b/grp/initgroups.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <grp.h>
 #include <limits.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
diff --git a/include/netinet/ip_icmp.h b/include/netinet/ip_icmp.h
new file mode 100644
index 0000000000..f8d0080f68
--- /dev/null
+++ b/include/netinet/ip_icmp.h
@@ -0,0 +1 @@
+#include <inet/netinet/ip_icmp.h>
diff --git a/include/netinet/udp.h b/include/netinet/udp.h
new file mode 100644
index 0000000000..c45cb0bedd
--- /dev/null
+++ b/include/netinet/udp.h
@@ -0,0 +1 @@
+#include <inet/netinet/udp.h>
diff --git a/inet/Makefile b/inet/Makefile
index e2371033a7..a58278a1e1 100644
--- a/inet/Makefile
+++ b/inet/Makefile
@@ -22,10 +22,13 @@ subdir	:= inet
 
 include ../Makeconfig
 
-headers	:= netinet/ether.h netinet/in.h netinet/in_systm.h \
-	   netinet/if_ether.h netinet/igmp.h \
-	   netinet/tcp.h netinet/ip.h $(wildcard arpa/*.h protocols/*.h) \
-	   aliases.h ifaddrs.h netinet/ip6.h netinet/icmp6.h bits/in.h
+headers	:= aliases.h ifaddrs.h bits/in.h				     \
+           netinet/ether.h netinet/icmp6.h netinet/if_ether.h netinet/igmp.h \
+           netinet/in.h netinet/in_systm.h netinet/ip.h netinet/ip6.h	     \
+	   netinet/ip_icmp.h netinet/tcp.h netinet/udp.h		     \
+	   arpa/ftp.h arpa/inet.h arpa/telnet.h arpa/tftp.h		     \
+           protocols/routed.h protocols/rwhod.h protocols/talkd.h	     \
+	   protocols/timed.h
 
 routines := htonl htons		\
 	    inet_lnaof inet_mkadr	\
diff --git a/inet/netinet/icmp6.h b/inet/netinet/icmp6.h
index 92e84cfd21..5119085391 100644
--- a/inet/netinet/icmp6.h
+++ b/inet/netinet/icmp6.h
@@ -18,9 +18,10 @@
 #ifndef _NETINET_ICMP6_H
 #define _NETINET_ICMP6_H 1
 
-#include <inttypes.h>
-#include <string.h>
-#include <sys/types.h>
+#include <features.h>
+#include <bits/endian.h>
+#include <bits/types.h>
+#include <bits/types/size_t.h>
 #include <netinet/in.h>
 
 #define ICMP6_FILTER 1
@@ -32,19 +33,19 @@
 
 struct icmp6_filter
   {
-    uint32_t icmp6_filt[8];
+    __uint32_t icmp6_filt[8];
   };
 
 struct icmp6_hdr
   {
-    uint8_t     icmp6_type;   /* type field */
-    uint8_t     icmp6_code;   /* code field */
-    uint16_t    icmp6_cksum;  /* checksum field */
+    __uint8_t     icmp6_type;   /* type field */
+    __uint8_t     icmp6_code;   /* code field */
+    __uint16_t    icmp6_cksum;  /* checksum field */
     union
       {
-	uint32_t  icmp6_un_data32[1]; /* type-specific field */
-	uint16_t  icmp6_un_data16[2]; /* type-specific field */
-	uint8_t   icmp6_un_data8[4];  /* type-specific field */
+	__uint32_t  icmp6_un_data32[1]; /* type-specific field */
+	__uint16_t  icmp6_un_data16[2]; /* type-specific field */
+	__uint8_t   icmp6_un_data8[4];  /* type-specific field */
       } icmp6_dataun;
   };
 
@@ -96,6 +97,8 @@ struct icmp6_hdr
 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
 	((((filterp)->icmp6_filt[(type) >> 5]) |=  (1 << ((type) & 31))))
 
+extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
+
 #define ICMP6_FILTER_SETPASSALL(filterp) \
 	memset (filterp, 0, sizeof (struct icmp6_filter));
 
@@ -122,8 +125,8 @@ struct nd_router_solicit      /* router solicitation */
 struct nd_router_advert       /* router advertisement */
   {
     struct icmp6_hdr  nd_ra_hdr;
-    uint32_t   nd_ra_reachable;   /* reachable time */
-    uint32_t   nd_ra_retransmit;  /* retransmit timer */
+    __uint32_t   nd_ra_reachable;   /* reachable time */
+    __uint32_t   nd_ra_retransmit;  /* retransmit timer */
     /* could be followed by options */
   };
 
@@ -185,8 +188,8 @@ struct nd_redirect            /* redirect */
 
 struct nd_opt_hdr             /* Neighbor discovery option header */
   {
-    uint8_t  nd_opt_type;
-    uint8_t  nd_opt_len;        /* in units of 8 octets */
+    __uint8_t  nd_opt_type;
+    __uint8_t  nd_opt_len;        /* in units of 8 octets */
     /* followed by option specific data */
   };
 
@@ -200,13 +203,13 @@ struct nd_opt_hdr             /* Neighbor discovery option header */
 
 struct nd_opt_prefix_info     /* prefix information */
   {
-    uint8_t   nd_opt_pi_type;
-    uint8_t   nd_opt_pi_len;
-    uint8_t   nd_opt_pi_prefix_len;
-    uint8_t   nd_opt_pi_flags_reserved;
-    uint32_t  nd_opt_pi_valid_time;
-    uint32_t  nd_opt_pi_preferred_time;
-    uint32_t  nd_opt_pi_reserved2;
+    __uint8_t   nd_opt_pi_type;
+    __uint8_t   nd_opt_pi_len;
+    __uint8_t   nd_opt_pi_prefix_len;
+    __uint8_t   nd_opt_pi_flags_reserved;
+    __uint32_t  nd_opt_pi_valid_time;
+    __uint32_t  nd_opt_pi_preferred_time;
+    __uint32_t  nd_opt_pi_reserved2;
     struct in6_addr  nd_opt_pi_prefix;
   };
 
@@ -216,19 +219,19 @@ struct nd_opt_prefix_info     /* prefix information */
 
 struct nd_opt_rd_hdr          /* redirected header */
   {
-    uint8_t   nd_opt_rh_type;
-    uint8_t   nd_opt_rh_len;
-    uint16_t  nd_opt_rh_reserved1;
-    uint32_t  nd_opt_rh_reserved2;
+    __uint8_t   nd_opt_rh_type;
+    __uint8_t   nd_opt_rh_len;
+    __uint16_t  nd_opt_rh_reserved1;
+    __uint32_t  nd_opt_rh_reserved2;
     /* followed by IP header and data */
   };
 
 struct nd_opt_mtu             /* MTU option */
   {
-    uint8_t   nd_opt_mtu_type;
-    uint8_t   nd_opt_mtu_len;
-    uint16_t  nd_opt_mtu_reserved;
-    uint32_t  nd_opt_mtu_mtu;
+    __uint8_t   nd_opt_mtu_type;
+    __uint8_t   nd_opt_mtu_len;
+    __uint16_t  nd_opt_mtu_reserved;
+    __uint32_t  nd_opt_mtu_mtu;
   };
 
 struct mld_hdr
@@ -248,10 +251,10 @@ struct mld_hdr
 struct icmp6_router_renum    /* router renumbering header */
   {
     struct icmp6_hdr    rr_hdr;
-    uint8_t             rr_segnum;
-    uint8_t             rr_flags;
-    uint16_t            rr_maxdelay;
-    uint32_t            rr_reserved;
+    __uint8_t           rr_segnum;
+    __uint8_t           rr_flags;
+    __uint16_t          rr_maxdelay;
+    __uint32_t          rr_reserved;
   };
 
 #define rr_type		rr_hdr.icmp6_type
@@ -268,13 +271,13 @@ struct icmp6_router_renum    /* router renumbering header */
 
 struct rr_pco_match    /* match prefix part */
   {
-    uint8_t             rpm_code;
-    uint8_t             rpm_len;
-    uint8_t             rpm_ordinal;
-    uint8_t             rpm_matchlen;
-    uint8_t             rpm_minlen;
-    uint8_t             rpm_maxlen;
-    uint16_t            rpm_reserved;
+    __uint8_t           rpm_code;
+    __uint8_t           rpm_len;
+    __uint8_t           rpm_ordinal;
+    __uint8_t           rpm_matchlen;
+    __uint8_t           rpm_minlen;
+    __uint8_t           rpm_maxlen;
+    __uint16_t          rpm_reserved;
     struct in6_addr     rpm_prefix;
   };
 
@@ -285,13 +288,13 @@ struct rr_pco_match    /* match prefix part */
 
 struct rr_pco_use      /* use prefix part */
   {
-    uint8_t             rpu_uselen;
-    uint8_t             rpu_keeplen;
-    uint8_t             rpu_ramask;
-    uint8_t             rpu_raflags;
-    uint32_t            rpu_vltime;
-    uint32_t            rpu_pltime;
-    uint32_t            rpu_flags;
+    __uint8_t           rpu_uselen;
+    __uint8_t           rpu_keeplen;
+    __uint8_t           rpu_ramask;
+    __uint8_t           rpu_raflags;
+    __uint32_t          rpu_vltime;
+    __uint32_t          rpu_pltime;
+    __uint32_t          rpu_flags;
     struct in6_addr     rpu_prefix;
   };
 
@@ -308,10 +311,10 @@ struct rr_pco_use      /* use prefix part */
 
 struct rr_result       /* router renumbering result message */
   {
-    uint16_t            rrr_flags;
-    uint8_t             rrr_ordinal;
-    uint8_t             rrr_matchedlen;
-    uint32_t            rrr_ifid;
+    __uint16_t          rrr_flags;
+    __uint8_t           rrr_ordinal;
+    __uint8_t           rrr_matchedlen;
+    __uint32_t          rrr_ifid;
     struct in6_addr     rrr_prefix;
   };
 
@@ -326,20 +329,20 @@ struct rr_result       /* router renumbering result message */
 /* Mobile IPv6 extension: Advertisement Interval.  */
 struct nd_opt_adv_interval
   {
-    uint8_t   nd_opt_adv_interval_type;
-    uint8_t   nd_opt_adv_interval_len;
-    uint16_t  nd_opt_adv_interval_reserved;
-    uint32_t  nd_opt_adv_interval_ival;
+    __uint8_t   nd_opt_adv_interval_type;
+    __uint8_t   nd_opt_adv_interval_len;
+    __uint16_t  nd_opt_adv_interval_reserved;
+    __uint32_t  nd_opt_adv_interval_ival;
   };
 
 /* Mobile IPv6 extension: Home Agent Info.  */
 struct nd_opt_home_agent_info
   {
-    uint8_t   nd_opt_home_agent_info_type;
-    uint8_t   nd_opt_home_agent_info_len;
-    uint16_t  nd_opt_home_agent_info_reserved;
-    uint16_t  nd_opt_home_agent_info_preference;
-    uint16_t  nd_opt_home_agent_info_lifetime;
+    __uint8_t   nd_opt_home_agent_info_type;
+    __uint8_t   nd_opt_home_agent_info_len;
+    __uint16_t  nd_opt_home_agent_info_reserved;
+    __uint16_t  nd_opt_home_agent_info_preference;
+    __uint16_t  nd_opt_home_agent_info_lifetime;
   };
 
 #endif /* netinet/icmpv6.h */
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 2884db59df..6eafc19a73 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -20,11 +20,10 @@
 
 #include <features.h>
 
-#include <sys/types.h>
-
 #ifdef __USE_MISC
 
 #include <netinet/in.h>
+#include <bits/types.h>
 
 __BEGIN_DECLS
 
@@ -65,9 +64,9 @@ __BEGIN_DECLS
  */
 
 struct igmp {
-  uint8_t igmp_type;             /* IGMP type */
-  uint8_t igmp_code;             /* routing code */
-  uint16_t igmp_cksum;           /* checksum */
+  __uint8_t igmp_type;           /* IGMP type */
+  __uint8_t igmp_code;           /* routing code */
+  __uint16_t igmp_cksum;         /* checksum */
   struct in_addr igmp_group;     /* group address */
 };
 
diff --git a/inet/netinet/ip.h b/inet/netinet/ip.h
index 35f61d1694..fa6b588c42 100644
--- a/inet/netinet/ip.h
+++ b/inet/netinet/ip.h
@@ -22,14 +22,14 @@
 
 #include <netinet/in.h>
 #include <bits/endian.h>
-#include <bits/stdint-uintn.h>
+#include <bits/types.h>
 
 __BEGIN_DECLS
 
 struct timestamp
   {
-    uint8_t len;
-    uint8_t ptr;
+    __uint8_t len;
+    __uint8_t ptr;
 #if __BYTE_ORDER == __LITTLE_ENDIAN
     unsigned int flags:4;
     unsigned int overflow:4;
@@ -39,7 +39,7 @@ struct timestamp
 #else
 # error	"Please fix <bits/endian.h>"
 #endif
-    uint32_t data[9];
+    __uint32_t data[9];
   };
 
 struct iphdr
@@ -53,15 +53,15 @@ struct iphdr
 #else
 # error	"Please fix <bits/endian.h>"
 #endif
-    uint8_t tos;
-    uint16_t tot_len;
-    uint16_t id;
-    uint16_t frag_off;
-    uint8_t ttl;
-    uint8_t protocol;
-    uint16_t check;
-    uint32_t saddr;
-    uint32_t daddr;
+    __uint8_t tos;
+    __uint16_t tot_len;
+    __uint16_t id;
+    __uint16_t frag_off;
+    __uint8_t ttl;
+    __uint8_t protocol;
+    __uint16_t check;
+    __uint32_t saddr;
+    __uint32_t daddr;
     /*The options start here. */
   };
 
@@ -115,7 +115,7 @@ struct ip
     unsigned int ip_v:4;		/* version */
     unsigned int ip_hl:4;		/* header length */
 #endif
-    uint8_t ip_tos;			/* type of service */
+    __uint8_t ip_tos;			/* type of service */
     unsigned short ip_len;		/* total length */
     unsigned short ip_id;		/* identification */
     unsigned short ip_off;		/* fragment offset field */
@@ -123,8 +123,8 @@ struct ip
 #define	IP_DF 0x4000			/* dont fragment flag */
 #define	IP_MF 0x2000			/* more fragments flag */
 #define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
-    uint8_t ip_ttl;			/* time to live */
-    uint8_t ip_p;			/* protocol */
+    __uint8_t ip_ttl;			/* time to live */
+    __uint8_t ip_p;			/* protocol */
     unsigned short ip_sum;		/* checksum */
     struct in_addr ip_src, ip_dst;	/* source and dest address */
   };
@@ -134,9 +134,9 @@ struct ip
  */
 struct ip_timestamp
   {
-    uint8_t ipt_code;			/* IPOPT_TS */
-    uint8_t ipt_len;			/* size of structure (variable) */
-    uint8_t ipt_ptr;			/* index of current entry */
+    __uint8_t ipt_code;			/* IPOPT_TS */
+    __uint8_t ipt_len;			/* size of structure (variable) */
+    __uint8_t ipt_ptr;			/* index of current entry */
 #if __BYTE_ORDER == __LITTLE_ENDIAN
     unsigned int ipt_flg:4;		/* flags, see below */
     unsigned int ipt_oflw:4;		/* overflow counter */
@@ -145,7 +145,7 @@ struct ip_timestamp
     unsigned int ipt_oflw:4;		/* overflow counter */
     unsigned int ipt_flg:4;		/* flags, see below */
 #endif
-    uint32_t data[9];
+    __uint32_t data[9];
   };
 #endif /* __USE_MISC */
 
diff --git a/inet/netinet/ip6.h b/inet/netinet/ip6.h
index 157a27d2df..e2a8d2b356 100644
--- a/inet/netinet/ip6.h
+++ b/inet/netinet/ip6.h
@@ -18,8 +18,10 @@
 #ifndef _NETINET_IP6_H
 #define _NETINET_IP6_H 1
 
-#include <inttypes.h>
+#include <features.h>
 #include <netinet/in.h>
+#include <bits/endian.h>
+#include <bits/types.h>
 
 struct ip6_hdr
   {
@@ -27,13 +29,13 @@ struct ip6_hdr
       {
 	struct ip6_hdrctl
 	  {
-	    uint32_t ip6_un1_flow;   /* 4 bits version, 8 bits TC,
-					20 bits flow-ID */
-	    uint16_t ip6_un1_plen;   /* payload length */
-	    uint8_t  ip6_un1_nxt;    /* next header */
-	    uint8_t  ip6_un1_hlim;   /* hop limit */
+	    __uint32_t ip6_un1_flow;   /* 4 bits version, 8 bits TC,
+					  20 bits flow-ID */
+	    __uint16_t ip6_un1_plen;   /* payload length */
+	    __uint8_t  ip6_un1_nxt;    /* next header */
+	    __uint8_t  ip6_un1_hlim;   /* hop limit */
 	  } ip6_un1;
-	uint8_t ip6_un2_vfc;       /* 4 bits version, top 4 bits tclass */
+	__uint8_t ip6_un2_vfc;       /* 4 bits version, top 4 bits tclass */
       } ip6_ctlun;
     struct in6_addr ip6_src;      /* source address */
     struct in6_addr ip6_dst;      /* destination address */
@@ -49,45 +51,45 @@ struct ip6_hdr
 /* Generic extension header.  */
 struct ip6_ext
   {
-    uint8_t  ip6e_nxt;		/* next header.  */
-    uint8_t  ip6e_len;		/* length in units of 8 octets.  */
+    __uint8_t  ip6e_nxt;	/* next header.  */
+    __uint8_t  ip6e_len;	/* length in units of 8 octets.  */
   };
 
 /* Hop-by-Hop options header.  */
 struct ip6_hbh
   {
-    uint8_t  ip6h_nxt;		/* next header.  */
-    uint8_t  ip6h_len;		/* length in units of 8 octets.  */
+    __uint8_t  ip6h_nxt;	/* next header.  */
+    __uint8_t  ip6h_len;	/* length in units of 8 octets.  */
     /* followed by options */
   };
 
 /* Destination options header */
 struct ip6_dest
   {
-    uint8_t  ip6d_nxt;		/* next header */
-    uint8_t  ip6d_len;		/* length in units of 8 octets */
+    __uint8_t  ip6d_nxt;	/* next header */
+    __uint8_t  ip6d_len;	/* length in units of 8 octets */
     /* followed by options */
   };
 
 /* Routing header */
 struct ip6_rthdr
   {
-    uint8_t  ip6r_nxt;		/* next header */
-    uint8_t  ip6r_len;		/* length in units of 8 octets */
-    uint8_t  ip6r_type;		/* routing type */
-    uint8_t  ip6r_segleft;	/* segments left */
+    __uint8_t  ip6r_nxt;	/* next header */
+    __uint8_t  ip6r_len;	/* length in units of 8 octets */
+    __uint8_t  ip6r_type;	/* routing type */
+    __uint8_t  ip6r_segleft;	/* segments left */
     /* followed by routing type specific data */
   };
 
 /* Type 0 Routing header */
 struct ip6_rthdr0
   {
-    uint8_t  ip6r0_nxt;		/* next header */
-    uint8_t  ip6r0_len;		/* length in units of 8 octets */
-    uint8_t  ip6r0_type;	/* always zero */
-    uint8_t  ip6r0_segleft;	/* segments left */
-    uint8_t  ip6r0_reserved;	/* reserved field */
-    uint8_t  ip6r0_slmap[3];	/* strict/loose bit map */
+    __uint8_t  ip6r0_nxt;	/* next header */
+    __uint8_t  ip6r0_len;	/* length in units of 8 octets */
+    __uint8_t  ip6r0_type;	/* always zero */
+    __uint8_t  ip6r0_segleft;	/* segments left */
+    __uint8_t  ip6r0_reserved;	/* reserved field */
+    __uint8_t  ip6r0_slmap[3];	/* strict/loose bit map */
     /* followed by up to 127 struct in6_addr */
     struct in6_addr ip6r0_addr[0];
   };
@@ -95,10 +97,10 @@ struct ip6_rthdr0
 /* Fragment header */
 struct ip6_frag
   {
-    uint8_t   ip6f_nxt;		/* next header */
-    uint8_t   ip6f_reserved;	/* reserved field */
-    uint16_t  ip6f_offlg;	/* offset, reserved, and flag */
-    uint32_t  ip6f_ident;	/* identification */
+    __uint8_t   ip6f_nxt;	/* next header */
+    __uint8_t   ip6f_reserved;	/* reserved field */
+    __uint16_t  ip6f_offlg;	/* offset, reserved, and flag */
+    __uint32_t  ip6f_ident;	/* identification */
   };
 
 #if __BYTE_ORDER == __BIG_ENDIAN
@@ -114,8 +116,8 @@ struct ip6_frag
 /* IPv6 options */
 struct ip6_opt
   {
-    uint8_t  ip6o_type;
-    uint8_t  ip6o_len;
+    __uint8_t  ip6o_type;
+    __uint8_t  ip6o_len;
   };
 
 /* The high-order 3 bits of the option type define the behavior
@@ -141,19 +143,19 @@ struct ip6_opt
 /* Jumbo Payload Option */
 struct ip6_opt_jumbo
   {
-    uint8_t  ip6oj_type;
-    uint8_t  ip6oj_len;
-    uint8_t  ip6oj_jumbo_len[4];
+    __uint8_t  ip6oj_type;
+    __uint8_t  ip6oj_len;
+    __uint8_t  ip6oj_jumbo_len[4];
   };
 #define IP6OPT_JUMBO_LEN	6
 
 /* NSAP Address Option */
 struct ip6_opt_nsap
   {
-    uint8_t  ip6on_type;
-    uint8_t  ip6on_len;
-    uint8_t  ip6on_src_nsap_len;
-    uint8_t  ip6on_dst_nsap_len;
+    __uint8_t  ip6on_type;
+    __uint8_t  ip6on_len;
+    __uint8_t  ip6on_src_nsap_len;
+    __uint8_t  ip6on_dst_nsap_len;
       /* followed by source NSAP */
       /* followed by destination NSAP */
   };
@@ -161,17 +163,17 @@ struct ip6_opt_nsap
 /* Tunnel Limit Option */
 struct ip6_opt_tunnel
   {
-    uint8_t  ip6ot_type;
-    uint8_t  ip6ot_len;
-    uint8_t  ip6ot_encap_limit;
+    __uint8_t  ip6ot_type;
+    __uint8_t  ip6ot_len;
+    __uint8_t  ip6ot_encap_limit;
   };
 
 /* Router Alert Option */
 struct ip6_opt_router
   {
-    uint8_t  ip6or_type;
-    uint8_t  ip6or_len;
-    uint8_t  ip6or_value[2];
+    __uint8_t  ip6or_type;
+    __uint8_t  ip6or_len;
+    __uint8_t  ip6or_value[2];
   };
 
 /* Router alert values (in network byte order) */
diff --git a/sysdeps/gnu/netinet/ip_icmp.h b/inet/netinet/ip_icmp.h
similarity index 91%
rename from sysdeps/gnu/netinet/ip_icmp.h
rename to inet/netinet/ip_icmp.h
index 2e2bfe9ff6..da7ff3b81b 100644
--- a/sysdeps/gnu/netinet/ip_icmp.h
+++ b/inet/netinet/ip_icmp.h
@@ -18,28 +18,28 @@
 #ifndef __NETINET_IP_ICMP_H
 #define __NETINET_IP_ICMP_H    1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 __BEGIN_DECLS
 
 struct icmphdr
 {
-  uint8_t type;		/* message type */
-  uint8_t code;		/* type sub-code */
-  uint16_t checksum;
+  __uint8_t type;		/* message type */
+  __uint8_t code;		/* type sub-code */
+  __uint16_t checksum;
   union
   {
     struct
     {
-      uint16_t	id;
-      uint16_t	sequence;
+      __uint16_t	id;
+      __uint16_t	sequence;
     } echo;			/* echo datagram */
-    uint32_t	gateway;	/* gateway address */
+    __uint32_t	gateway;	/* gateway address */
     struct
     {
-      uint16_t	__glibc_reserved;
-      uint16_t	mtu;
+      __uint16_t	__glibc_reserved;
+      __uint16_t	mtu;
     } frag;			/* path mtu discovery */
   } un;
 };
@@ -130,38 +130,38 @@ struct icmphdr
  */
 struct icmp_ra_addr
 {
-  uint32_t ira_addr;
-  uint32_t ira_preference;
+  __uint32_t ira_addr;
+  __uint32_t ira_preference;
 };
 
 struct icmp
 {
-  uint8_t  icmp_type;	/* type of message, see below */
-  uint8_t  icmp_code;	/* type sub code */
-  uint16_t icmp_cksum;	/* ones complement checksum of struct */
+  __uint8_t  icmp_type;	/* type of message, see below */
+  __uint8_t  icmp_code;	/* type sub code */
+  __uint16_t icmp_cksum;	/* ones complement checksum of struct */
   union
   {
     unsigned char ih_pptr;	/* ICMP_PARAMPROB */
     struct in_addr ih_gwaddr;	/* gateway address */
     struct ih_idseq		/* echo datagram */
     {
-      uint16_t icd_id;
-      uint16_t icd_seq;
+      __uint16_t icd_id;
+      __uint16_t icd_seq;
     } ih_idseq;
-    uint32_t ih_void;
+    __uint32_t ih_void;
 
     /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
     struct ih_pmtu
     {
-      uint16_t ipm_void;
-      uint16_t ipm_nextmtu;
+      __uint16_t ipm_void;
+      __uint16_t ipm_nextmtu;
     } ih_pmtu;
 
     struct ih_rtradv
     {
-      uint8_t irt_num_addrs;
-      uint8_t irt_wpa;
-      uint16_t irt_lifetime;
+      __uint8_t irt_num_addrs;
+      __uint8_t irt_wpa;
+      __uint16_t irt_lifetime;
     } ih_rtradv;
   } icmp_hun;
 #define	icmp_pptr	icmp_hun.ih_pptr
@@ -178,9 +178,9 @@ struct icmp
   {
     struct
     {
-      uint32_t its_otime;
-      uint32_t its_rtime;
-      uint32_t its_ttime;
+      __uint32_t its_otime;
+      __uint32_t its_rtime;
+      __uint32_t its_ttime;
     } id_ts;
     struct
     {
@@ -188,8 +188,8 @@ struct icmp
       /* options and then 64 bits of data */
     } id_ip;
     struct icmp_ra_addr id_radv;
-    uint32_t   id_mask;
-    uint8_t    id_data[1];
+    __uint32_t  id_mask;
+    __uint8_t   id_data[1];
   } icmp_dun;
 #define	icmp_otime	icmp_dun.id_ts.its_otime
 #define	icmp_rtime	icmp_dun.id_ts.its_rtime
diff --git a/sysdeps/gnu/netinet/udp.h b/inet/netinet/udp.h
similarity index 91%
rename from sysdeps/gnu/netinet/udp.h
rename to inet/netinet/udp.h
index b6822cb3e2..481cbeae60 100644
--- a/sysdeps/gnu/netinet/udp.h
+++ b/inet/netinet/udp.h
@@ -47,8 +47,8 @@
 #ifndef __NETINET_UDP_H
 #define __NETINET_UDP_H    1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 /* UDP header as specified by RFC 768, August 1980. */
 
@@ -58,17 +58,17 @@ struct udphdr
   {
     struct
     {
-      uint16_t uh_sport;	/* source port */
-      uint16_t uh_dport;	/* destination port */
-      uint16_t uh_ulen;		/* udp length */
-      uint16_t uh_sum;		/* udp checksum */
+      __uint16_t uh_sport;	/* source port */
+      __uint16_t uh_dport;	/* destination port */
+      __uint16_t uh_ulen;	/* udp length */
+      __uint16_t uh_sum;	/* udp checksum */
     };
     struct
     {
-      uint16_t source;
-      uint16_t dest;
-      uint16_t len;
-      uint16_t check;
+      __uint16_t source;
+      __uint16_t dest;
+      __uint16_t len;
+      __uint16_t check;
     };
   };
 };
diff --git a/inet/protocols/rwhod.h b/inet/protocols/rwhod.h
index 446d6f97b8..74fe1f926c 100644
--- a/inet/protocols/rwhod.h
+++ b/inet/protocols/rwhod.h
@@ -32,7 +32,8 @@
 #ifndef _PROTOCOLS_RWHOD_H
 #define	_PROTOCOLS_RWHOD_H 1
 
-#include <sys/types.h>
+#include <features.h>
+#include <bits/types.h>
 
 /*
  * rwho protocol packet format.
@@ -40,7 +41,7 @@
 struct	outmp {
 	char	out_line[8];		/* tty name */
 	char	out_name[8];		/* user id */
-	int32_t	out_time;		/* time on */
+	__int32_t out_time;		/* time on */
 };
 
 struct	whod {
diff --git a/inet/protocols/talkd.h b/inet/protocols/talkd.h
index 09bd8a90ba..5068e981b7 100644
--- a/inet/protocols/talkd.h
+++ b/inet/protocols/talkd.h
@@ -50,9 +50,8 @@
  * stream connection through which the conversation takes place.
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 #include <bits/types/struct_osockaddr.h>
 
 /*
@@ -63,10 +62,10 @@ typedef struct {
 	unsigned char	type;	/* request type, see below */
 	unsigned char	answer;	/* not used */
 	unsigned char	pad;
-	uint32_t id_num;	/* message id */
+	__uint32_t	id_num;	/* message id */
 	struct	osockaddr addr;		/* old (4.3) style */
 	struct	osockaddr ctl_addr;	/* old (4.3) style */
-	int32_t	pid;		/* caller's process id */
+	__int32_t	pid;		/* caller's process id */
 #define	NAME_SIZE	12
 	char	l_name[NAME_SIZE];/* caller's name */
 	char	r_name[NAME_SIZE];/* callee's name */
@@ -82,7 +81,7 @@ typedef struct {
 	unsigned char	type;	/* type of request message, see below */
 	unsigned char	answer;	/* response to request message, see below */
 	unsigned char	pad;
-	uint32_t	id_num;	/* message id */
+	__uint32_t	id_num;	/* message id */
 	struct	osockaddr addr;	/* address for establishing conversation */
 } CTL_RESPONSE;
 
diff --git a/inet/protocols/timed.h b/inet/protocols/timed.h
index cabdce44a6..5ec9de87a7 100644
--- a/inet/protocols/timed.h
+++ b/inet/protocols/timed.h
@@ -32,8 +32,9 @@
 #ifndef	_PROTOCOLS_TIMED_H
 #define	_PROTOCOLS_TIMED_H 1
 
-#include <sys/types.h>
-#include <sys/time.h>
+#include <features.h>
+#include <bits/types.h>
+#include <bits/types/struct_timeval.h>
 
 /*
  * Time Synchronization Protocol
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index cf38c59b8e..678666563d 100644
--- a/nscd/initgrcache.c
+++ b/nscd/initgrcache.c
@@ -20,10 +20,12 @@
 #include <errno.h>
 #include <grp.h>
 #include <libintl.h>
+#include <stdio.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 #include <scratch_buffer.h>
 #include <config.h>
 
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index cda276eade..8fcb092657 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 
 #include "../inet/netgroup.h"
 #include "nscd.h"
diff --git a/nss/nss_compat/compat-grp.c b/nss/nss_compat/compat-grp.c
index 8f01e44a72..c46a0dc186 100644
--- a/nss/nss_compat/compat-grp.c
+++ b/nss/nss_compat/compat-grp.c
@@ -24,6 +24,7 @@
 #include <nsswitch.h>
 #include <stdio_ext.h>
 #include <string.h>
+#include <sys/param.h>
 #include <libc-lock.h>
 #include <kernel-features.h>
 
diff --git a/nss/nss_compat/compat-pwd.c b/nss/nss_compat/compat-pwd.c
index 37f883f35a..4b6734acae 100644
--- a/nss/nss_compat/compat-pwd.c
+++ b/nss/nss_compat/compat-pwd.c
@@ -25,6 +25,7 @@
 #include <pwd.h>
 #include <stdio_ext.h>
 #include <string.h>
+#include <sys/param.h>
 #include <libc-lock.h>
 #include <kernel-features.h>
 
diff --git a/nss/nss_compat/compat-spwd.c b/nss/nss_compat/compat-spwd.c
index bd310ab9aa..3eaa6e866b 100644
--- a/nss/nss_compat/compat-spwd.c
+++ b/nss/nss_compat/compat-spwd.c
@@ -25,6 +25,7 @@
 #include <shadow.h>
 #include <stdio_ext.h>
 #include <string.h>
+#include <sys/param.h>
 #include <libc-lock.h>
 #include <kernel-features.h>
 
diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c
index e17bbff52b..ac3586ec67 100644
--- a/nss/nss_db/db-XXX.c
+++ b/nss/nss_db/db-XXX.c
@@ -18,6 +18,7 @@
 
 #include <dlfcn.h>
 #include <fcntl.h>
+#include <stdio.h>
 #include <stdint.h>
 #include <sys/mman.h>
 #include <libc-lock.h>
diff --git a/resolv/arpa/nameser.h b/resolv/arpa/nameser.h
index a99d5ec508..4ce57bd3f9 100644
--- a/resolv/arpa/nameser.h
+++ b/resolv/arpa/nameser.h
@@ -48,9 +48,9 @@
 #ifndef _ARPA_NAMESER_H_
 #define _ARPA_NAMESER_H_
 
-#include <sys/param.h>
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
+#include <bits/types/size_t.h>
 
 /*
  * Define constants based on RFC 883, RFC 1034, RFC 1035
@@ -92,7 +92,7 @@ typedef enum __ns_sect {
  */
 typedef struct __ns_msg {
 	const unsigned char	*_msg, *_eom;
-	uint16_t		_id, _flags, _counts[ns_s_max];
+	__uint16_t		_id, _flags, _counts[ns_s_max];
 	const unsigned char	*_sections[ns_s_max];
 	ns_sect			_sect;
 	int			_rrnum;
@@ -116,10 +116,10 @@ extern const struct _ns_flagdata _ns_flagdata[];
  */
 typedef	struct __ns_rr {
 	char			name[NS_MAXDNAME];
-	uint16_t		type;
-	uint16_t		rr_class;
-	uint32_t		ttl;
-	uint16_t		rdlength;
+	__uint16_t		type;
+	__uint16_t		rr_class;
+	__uint32_t		ttl;
+	__uint16_t		rdlength;
 	const unsigned char *	rdata;
 } ns_rr;
 
@@ -355,24 +355,24 @@ typedef enum __ns_cert_types {
  */
 #define NS_GET16(s, cp) do { \
 	const unsigned char *t_cp = (const unsigned char *)(cp); \
-	(s) = ((uint16_t)t_cp[0] << 8) \
-	    | ((uint16_t)t_cp[1]) \
+	(s) = ((__uint16_t)t_cp[0] << 8) \
+	    | ((__uint16_t)t_cp[1]) \
 	    ; \
 	(cp) += NS_INT16SZ; \
 } while (0)
 
 #define NS_GET32(l, cp) do { \
 	const unsigned char *t_cp = (const unsigned char *)(cp); \
-	(l) = ((uint32_t)t_cp[0] << 24) \
-	    | ((uint32_t)t_cp[1] << 16) \
-	    | ((uint32_t)t_cp[2] << 8) \
-	    | ((uint32_t)t_cp[3]) \
+	(l) = ((__uint32_t)t_cp[0] << 24) \
+	    | ((__uint32_t)t_cp[1] << 16) \
+	    | ((__uint32_t)t_cp[2] << 8) \
+	    | ((__uint32_t)t_cp[3]) \
 	    ; \
 	(cp) += NS_INT32SZ; \
 } while (0)
 
 #define NS_PUT16(s, cp) do { \
-	uint16_t t_s = (uint16_t)(s); \
+	__uint16_t t_s = (__uint16_t)(s); \
 	unsigned char *t_cp = (unsigned char *)(cp); \
 	*t_cp++ = t_s >> 8; \
 	*t_cp   = t_s; \
@@ -380,7 +380,7 @@ typedef enum __ns_cert_types {
 } while (0)
 
 #define NS_PUT32(l, cp) do { \
-	uint32_t t_l = (uint32_t)(l); \
+	__uint32_t t_l = (__uint32_t)(l); \
 	unsigned char *t_cp = (unsigned char *)(cp); \
 	*t_cp++ = t_l >> 24; \
 	*t_cp++ = t_l >> 16; \
@@ -408,7 +408,7 @@ int		ns_sprintrrf (const unsigned char *, size_t, const char *,
 			      const char *, char *, size_t) __THROW;
 int		ns_format_ttl (unsigned long, char *, size_t) __THROW;
 int		ns_parse_ttl (const char *, unsigned long *) __THROW;
-uint32_t	ns_datetosecs (const char *, int *) __THROW;
+__uint32_t	ns_datetosecs (const char *, int *) __THROW;
 int		ns_name_ntol (const unsigned char *, unsigned char *, size_t)
      __THROW;
 int		ns_name_ntop (const unsigned char *, char *, size_t) __THROW;
diff --git a/resolv/arpa/nameser_compat.h b/resolv/arpa/nameser_compat.h
index 37c178b524..8996d376da 100644
--- a/resolv/arpa/nameser_compat.h
+++ b/resolv/arpa/nameser_compat.h
@@ -29,6 +29,7 @@
 #ifndef _ARPA_NAMESER_COMPAT_
 #define	_ARPA_NAMESER_COMPAT_
 
+#include <features.h>
 #include <bits/endian.h>
 
 /*%
diff --git a/resolv/ns_print.c b/resolv/ns_print.c
index d61f5044b1..1dbcfb8910 100644
--- a/resolv/ns_print.c
+++ b/resolv/ns_print.c
@@ -19,6 +19,7 @@
 /* Import. */
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 
 #include <netinet/in.h>
@@ -28,6 +29,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <resolv.h>
+#include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 
diff --git a/resolv/resolv.h b/resolv/resolv.h
index b4ef66fdfa..5783de697d 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -54,11 +54,12 @@
 
 #include <features.h>
 
-#include <sys/param.h>
-#include <sys/types.h>
-#include <stdio.h>
 #include <netinet/in.h>
 #include <arpa/nameser.h>
+
+#include <bits/types.h>
+#include <bits/types/FILE.h>
+#include <bits/types/size_t.h>
 #include <bits/types/res_state.h>
 
 /*
@@ -248,10 +249,10 @@ int		loc_aton (const char *__ascii, unsigned char *__binary) __THROW;
 const char *	loc_ntoa (const unsigned char *__binary, char *__ascii) __THROW;
 int		dn_skipname (const unsigned char *, const unsigned char *)
      __THROW;
-void		putlong (uint32_t, unsigned char *) __THROW;
-void		putshort (uint16_t, unsigned char *) __THROW;
+void		putlong (__uint32_t, unsigned char *) __THROW;
+void		putshort (__uint16_t, unsigned char *) __THROW;
 const char *	p_class (int) __THROW;
-const char *	p_time (uint32_t) __THROW;
+const char *	p_time (__uint32_t) __THROW;
 const char *	p_type (int) __THROW;
 const char *	p_rcode (int) __THROW;
 const unsigned char * p_cdnname (const unsigned char *,
diff --git a/resolv/tst-ns_name_compress.c b/resolv/tst-ns_name_compress.c
index 00b6e811b8..019edf722d 100644
--- a/resolv/tst-ns_name_compress.c
+++ b/resolv/tst-ns_name_compress.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <resolv.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <support/check.h>
diff --git a/resolv/tst-res_hnok.c b/resolv/tst-res_hnok.c
index a85449d284..3bc18163c4 100644
--- a/resolv/tst-res_hnok.c
+++ b/resolv/tst-res_hnok.c
@@ -18,6 +18,7 @@
 
 #include <array_length.h>
 #include <resolv.h>
+#include <stdio.h>
 #include <string.h>
 #include <support/check.h>
 #include <support/test-driver.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 1ecb7c9823..db367e61ae 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -607,44 +607,30 @@ HEADER_ALLOWED_INCLUDES = {
 
     # Nonstandardized networking headers
     "ifaddrs.h":                   [ "sys/socket.h" ],
-    "resolv.h":                    [ "arpa/nameser.h", "netinet/in.h",
-                                     "stdio.h", "sys/param.h",
-                                     "sys/types.h" ],
 
-    "arpa/nameser.h":              [ "arpa/nameser_compat.h", "stdint.h",
-                                     "sys/param.h", "sys/types.h" ],
-    "net/ethernet.h":              [ "stdint.h", "sys/types.h",
-                                     "net/if_ether.h" ],
-    "net/if_arp.h":                [ "stdint.h", "sys/socket.h",
-                                     "sys/types.h" ],
-    "net/if_ppp.h":                [ "net/if.h", "net/ppp_defs.h", "stdint.h",
-                                     "sys/ioctl.h", "sys/types.h" ],
-    "net/if_shaper.h":             [ "net/if.h", "stdint.h", "sys/ioctl.h",
-                                     "sys/types.h" ],
-    "net/route.h":                 [ "netinet/in.h", "sys/socket.h",
-                                     "sys/types.h" ],
-    "netatalk/at.h":               [ "sys/socket.h" ],
+    "resolv.h":                    [ "arpa/nameser.h", "netinet/in.h" ],
+    "arpa/nameser.h":              [ "arpa/nameser_compat.h" ],
+
+    "net/ethernet.h":              [ "net/if_ether.h" ],
+    "net/if_arp.h":                [ "sys/socket.h" ],
+    "net/if_ppp.h":                [ "net/if.h", "net/ppp_defs.h",
+                                     "sys/ioctl.h" ],
+    "net/if_shaper.h":             [ "net/if.h", "sys/ioctl.h" ],
+    "net/route.h":                 [ "netinet/in.h", "sys/socket.h" ],
+    "netatalk/at.h":               [ "sys/socket.h", "sys/ioctl.h" ],
+
     "netinet/ether.h":             [ "netinet/if_ether.h" ],
-    "netinet/icmp6.h":             [ "inttypes.h", "netinet/in.h", "string.h",
-                                     "sys/types.h" ],
-    "netinet/if_ether.h":          [ "net/ethernet.h", "net/if_arp.h",
-                                     "sys/types.h", "stdint.h" ],
-    "netinet/if_fddi.h":           [ "stdint.h", "sys/types.h" ],
-    "netinet/if_tr.h":             [ "stdint.h", "sys/types.h" ],
-    "netinet/igmp.h":              [ "netinet/in.h", "sys/types.h" ],
+    "netinet/icmp6.h":             [ "netinet/in.h" ],
+    "netinet/if_ether.h":          [ "net/ethernet.h", "net/if_arp.h" ],
+    "netinet/igmp.h":              [ "netinet/in.h" ],
     "netinet/ip.h":                [ "netinet/in.h" ],
-    "netinet/ip6.h":               [ "inttypes.h", "netinet/in.h" ],
-    "netinet/ip_icmp.h":           [ "netinet/in.h", "netinet/ip.h",
-                                     "stdint.h", "sys/types.h" ],
-    "netinet/udp.h":               [ "stdint.h", "sys/types.h" ],
-    "netipx/ipx.h":                [ "stdint.h", "sys/types.h" ],
+    "netinet/ip6.h":               [ "netinet/in.h" ],
+    "netinet/ip_icmp.h":           [ "netinet/in.h", "netinet/ip.h" ],
+
     "netrom/netrom.h":             [ "netax25/ax25.h" ],
-    "netrose/rose.h":              [ "netax25/ax25.h", "sys/socket.h" ],
+    "netrose/rose.h":              [ "netax25/ax25.h" ],
     "protocols/routed.h":          [ "sys/socket.h" ],
-    "protocols/rwhod.h":           [ "paths.h", "sys/types.h" ],
-    "protocols/talkd.h":           [ "stdint.h", "sys/socket.h",
-                                     "sys/types.h" ],
-    "protocols/timed.h":           [ "sys/time.h", "sys/types.h" ],
+    "protocols/rwhod.h":           [ "paths.h" ],
 
     # Internal headers
     "features.h":                  [ "gnu/stubs.h", "stdc-predef.h",
@@ -682,7 +668,6 @@ SYSDEP_ALLOWED_INCLUDES = {
         "net/ethernet.h":          [ "linux/if_ether.h" ],
         "net/if_slip.h":           [ "linux/if_slip.h" ],
         "net/ppp_defs.h":          [ "asm/types.h", "linux/ppp_defs.h" ],
-        "netatalk/at.h":           [ "asm/types.h", "linux/atalk.h" ],
         "netinet/if_ether.h":      [ "linux/if_ether.h" ],
         "netinet/if_fddi.h":       [ "linux/if_fddi.h" ],
 
diff --git a/support/resolv_test.c b/support/resolv_test.c
index 903ab2ac05..45d8ec79ea 100644
--- a/support/resolv_test.c
+++ b/support/resolv_test.c
@@ -24,6 +24,7 @@
 #include <nss.h>
 #include <resolv.h>
 #include <search.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <support/check.h>
diff --git a/sysdeps/generic/netinet/if_ether.h b/sysdeps/generic/netinet/if_ether.h
index 985581732e..f4fd66da65 100644
--- a/sysdeps/generic/netinet/if_ether.h
+++ b/sysdeps/generic/netinet/if_ether.h
@@ -18,8 +18,8 @@
 #ifndef __NETINET_IF_ETHER_H
 #define __NETINET_IF_ETHER_H	1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 #define ETH_ALEN	6	/* Octets in one ethernet address.  */
 
@@ -27,7 +27,7 @@
    systems.  */
 struct ether_addr
 {
-  uint8_t ether_addr_octet[ETH_ALEN];
+  __uint8_t ether_addr_octet[ETH_ALEN];
 } __attribute__ ((__packed__));
 
 #endif /* netinet/if_ether.h */
diff --git a/sysdeps/gnu/Makefile b/sysdeps/gnu/Makefile
index fdfbfc45d8..9da12c540d 100644
--- a/sysdeps/gnu/Makefile
+++ b/sysdeps/gnu/Makefile
@@ -59,11 +59,6 @@ $(foreach o,$(object-suffixes) $(object-suffixes:=.d),\
 endif
 
 
-ifeq ($(subdir),inet)
-sysdep_headers += netinet/udp.h netinet/ip_icmp.h
-endif
-
-
 ifeq ($(subdir),csu)
 routines += unwind-resume
 shared-only-routines += unwind-resume
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 8956694b59..3003523869 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -22,9 +22,7 @@
 #define __NET_ETHERNET_H 1
 
 #include <features.h>
-
-#include <sys/types.h>
-#include <stdint.h>
+#include <bits/types.h>
 #include <net/if_ether.h>     /* IEEE 802.3 Ethernet constants */
 
 __BEGIN_DECLS
@@ -33,15 +31,15 @@ __BEGIN_DECLS
    systems.  */
 struct ether_addr
 {
-  uint8_t ether_addr_octet[ETH_ALEN];
+  __uint8_t ether_addr_octet[ETH_ALEN];
 };
 
 /* 10Mb/s ethernet header */
 struct ether_header
 {
-  uint8_t  ether_dhost[ETH_ALEN];	/* destination eth addr	*/
-  uint8_t  ether_shost[ETH_ALEN];	/* source ether addr	*/
-  uint16_t ether_type;		        /* packet type ID field	*/
+  __uint8_t  ether_dhost[ETH_ALEN];	/* destination eth addr	*/
+  __uint8_t  ether_shost[ETH_ALEN];	/* source ether addr	*/
+  __uint16_t ether_type;	        /* packet type ID field	*/
 };
 
 /* Ethernet protocol ID's */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 9e1b2233ce..38665feab4 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -23,10 +23,7 @@
 #define _NET_IF_ARP_H 1
 
 #include <features.h>
-
-#include <sys/types.h>
 #include <sys/socket.h>
-#include <stdint.h>
 
 __BEGIN_DECLS
 
@@ -133,7 +130,7 @@ struct arpreq
 struct arpd_request
   {
     unsigned short int req;		/* Request type.  */
-    uint32_t ip;			/* IP address of entry.  */
+    __uint32_t ip;			/* IP address of entry.  */
     unsigned long int dev;		/* Device entry is tied to.  */
     unsigned long int stamp;
     unsigned long int updated;
diff --git a/sysdeps/mach/hurd/net/route.h b/sysdeps/mach/hurd/net/route.h
index 4924f099b9..fcb79bb33d 100644
--- a/sysdeps/mach/hurd/net/route.h
+++ b/sysdeps/mach/hurd/net/route.h
@@ -18,12 +18,11 @@
 /* Based on the 4.4BSD and Linux version of this file.  */
 
 #ifndef _NET_ROUTE_H
-
 #define _NET_ROUTE_H	1
+
 #include <features.h>
 
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <netinet/in.h>
 
 
diff --git a/sysdeps/unix/sysv/linux/net/ethernet.h b/sysdeps/unix/sysv/linux/net/ethernet.h
index 7e49297de6..1833511c9a 100644
--- a/sysdeps/unix/sysv/linux/net/ethernet.h
+++ b/sysdeps/unix/sysv/linux/net/ethernet.h
@@ -21,8 +21,8 @@
 #ifndef __NET_ETHERNET_H
 #define __NET_ETHERNET_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 #include <linux/if_ether.h>     /* IEEE 802.3 Ethernet constants */
 
@@ -32,15 +32,15 @@ __BEGIN_DECLS
    systems.  */
 struct ether_addr
 {
-  uint8_t ether_addr_octet[ETH_ALEN];
+  __uint8_t ether_addr_octet[ETH_ALEN];
 } __attribute__ ((__packed__));
 
 /* 10Mb/s ethernet header */
 struct ether_header
 {
-  uint8_t  ether_dhost[ETH_ALEN];	/* destination eth addr	*/
-  uint8_t  ether_shost[ETH_ALEN];	/* source ether addr	*/
-  uint16_t ether_type;		        /* packet type ID field	*/
+  __uint8_t  ether_dhost[ETH_ALEN];	/* destination eth addr	*/
+  __uint8_t  ether_shost[ETH_ALEN];	/* source ether addr	*/
+  __uint16_t ether_type;	        /* packet type ID field	*/
 } __attribute__ ((__packed__));
 
 /* Ethernet protocol ID's */
diff --git a/sysdeps/unix/sysv/linux/net/if_arp.h b/sysdeps/unix/sysv/linux/net/if_arp.h
index f64dcfd9d8..5013d085a2 100644
--- a/sysdeps/unix/sysv/linux/net/if_arp.h
+++ b/sysdeps/unix/sysv/linux/net/if_arp.h
@@ -22,9 +22,8 @@
 #ifndef _NET_IF_ARP_H
 #define _NET_IF_ARP_H 1
 
-#include <sys/types.h>
+#include <features.h>
 #include <sys/socket.h>
-#include <stdint.h>
 
 __BEGIN_DECLS
 
@@ -171,7 +170,7 @@ struct arpreq_old
 struct arpd_request
   {
     unsigned short int req;		/* Request type.  */
-    uint32_t ip;			/* IP address of entry.  */
+    __uint32_t ip;			/* IP address of entry.  */
     unsigned long int dev;		/* Device entry is tied to.  */
     unsigned long int stamp;
     unsigned long int updated;
diff --git a/sysdeps/unix/sysv/linux/net/if_ppp.h b/sysdeps/unix/sysv/linux/net/if_ppp.h
index 31a20766f0..1fd813ba8e 100644
--- a/sysdeps/unix/sysv/linux/net/if_ppp.h
+++ b/sysdeps/unix/sysv/linux/net/if_ppp.h
@@ -48,10 +48,10 @@
 #ifndef __NET_IF_PPP_H
 #define __NET_IF_PPP_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
-#include <net/if.h>
+#include <features.h>
+#include <bits/types.h>
 #include <sys/ioctl.h>
+#include <net/if.h>
 #include <net/ppp_defs.h>
 
 __BEGIN_DECLS
@@ -113,8 +113,8 @@ struct npioctl {
 
 /* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
 struct ppp_option_data {
-	uint8_t  *ptr;
-	uint32_t length;
+	__uint8_t  *ptr;
+	__uint32_t length;
 	int	 transmit;
 };
 
diff --git a/sysdeps/unix/sysv/linux/net/if_shaper.h b/sysdeps/unix/sysv/linux/net/if_shaper.h
index 77ab6306ac..0ccc2a90cf 100644
--- a/sysdeps/unix/sysv/linux/net/if_shaper.h
+++ b/sysdeps/unix/sysv/linux/net/if_shaper.h
@@ -18,8 +18,8 @@
 #ifndef _NET_IF_SHAPER_H
 #define _NET_IF_SHAPER_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 
@@ -43,11 +43,11 @@ __BEGIN_DECLS
 
 struct shaperconf
 {
-  uint16_t ss_cmd;
+  __uint16_t ss_cmd;
   union
   {
     char ssu_name[14];
-    uint32_t ssu_speed;
+    __uint32_t ssu_speed;
   } ss_u;
 #define ss_speed ss_u.ssu_speed
 #define ss_name ss_u.ssu_name
diff --git a/sysdeps/unix/sysv/linux/net/route.h b/sysdeps/unix/sysv/linux/net/route.h
index a6bda2157f..a0d9a74af4 100644
--- a/sysdeps/unix/sysv/linux/net/route.h
+++ b/sysdeps/unix/sysv/linux/net/route.h
@@ -21,8 +21,8 @@
 #define _NET_ROUTE_H	1
 
 #include <features.h>
+
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <netinet/in.h>
 #include <bits/wordsize.h>
 
diff --git a/sysdeps/unix/sysv/linux/netatalk/at.h b/sysdeps/unix/sysv/linux/netatalk/at.h
index 61fb67590c..f78d6b8a07 100644
--- a/sysdeps/unix/sysv/linux/netatalk/at.h
+++ b/sysdeps/unix/sysv/linux/netatalk/at.h
@@ -18,11 +18,46 @@
 #ifndef _NETATALK_AT_H
 #define _NETATALK_AT_H 1
 
-#include <asm/types.h>
+#include <features.h>
+#include <bits/types.h>
 #include <bits/sockaddr.h>
-#include <linux/atalk.h>
-#include <sys/socket.h>
 
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+/* Constants from linux/atalk.h as of kernel version 5.0.  */
+
+#define ATPORT_FIRST	1
+#define ATPORT_RESERVED	128
+#define ATPORT_LAST	254	/* 254 is only legal on localtalk */
+#define ATADDR_ANYNET	0
+#define ATADDR_ANYNODE	0
+#define ATADDR_ANYPORT  0
+#define ATADDR_BCAST	255
+#define DDP_MAXSZ	587
+#define DDP_MAXHOPS     15	/* 4 bits of hop counter */
 #define SOL_ATALK       258     /* sockopt level for atalk */
+#define SIOCATALKDIFADDR (SIOCPROTOPRIVATE + 0)
+
+struct atalk_addr
+{
+  __uint16_t	s_net;  /* network byte order */
+  __uint8_t	s_node;
+};
+
+struct atalk_netrange
+{
+  __uint8_t	nr_phase;
+  __uint16_t	nr_firstnet; /* network byte order */
+  __uint16_t	nr_lastnet;  /* network byte order */
+};
+
+struct sockaddr_at
+{
+  __SOCKADDR_COMMON (sat_);
+  __uint8_t sat_port;
+  struct atalk_addr sat_addr;
+  __uint8_t sat_zero[8];
+};
 
 #endif	/* netatalk/at.h */
diff --git a/sysdeps/unix/sysv/linux/netinet/if_ether.h b/sysdeps/unix/sysv/linux/netinet/if_ether.h
index 2c0750000f..51acbfd5b7 100644
--- a/sysdeps/unix/sysv/linux/netinet/if_ether.h
+++ b/sysdeps/unix/sysv/linux/netinet/if_ether.h
@@ -16,10 +16,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef __NETINET_IF_ETHER_H
-
 #define __NETINET_IF_ETHER_H	1
+
 #include <features.h>
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Get definitions from kernel header file.  */
 #include <linux/if_ether.h>
@@ -56,7 +56,6 @@
  *	@(#)if_ether.h	8.3 (Berkeley) 5/2/95
  *	$FreeBSD$
  */
-
 #include <net/ethernet.h>
 #include <net/if_arp.h>
 
@@ -70,10 +69,10 @@ __BEGIN_DECLS
  */
 struct	ether_arp {
 	struct	arphdr ea_hdr;		/* fixed-size header */
-	uint8_t arp_sha[ETH_ALEN];	/* sender hardware address */
-	uint8_t arp_spa[4];		/* sender protocol address */
-	uint8_t arp_tha[ETH_ALEN];	/* target hardware address */
-	uint8_t arp_tpa[4];		/* target protocol address */
+	__uint8_t arp_sha[ETH_ALEN];	/* sender hardware address */
+	__uint8_t arp_spa[4];		/* sender protocol address */
+	__uint8_t arp_tha[ETH_ALEN];	/* target hardware address */
+	__uint8_t arp_tpa[4];		/* target protocol address */
 };
 #define	arp_hrd	ea_hdr.ar_hrd
 #define	arp_pro	ea_hdr.ar_pro
@@ -88,14 +87,14 @@ struct	ether_arp {
  */
 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
 	/* struct in_addr *ipaddr; */ \
-	/* uint8_t enaddr[ETH_ALEN]; */ \
+	/* __uint8_t enaddr[ETH_ALEN]; */ \
 { \
 	(enaddr)[0] = 0x01; \
 	(enaddr)[1] = 0x00; \
 	(enaddr)[2] = 0x5e; \
-	(enaddr)[3] = ((uint8_t *)ipaddr)[1] & 0x7f; \
-	(enaddr)[4] = ((uint8_t *)ipaddr)[2]; \
-	(enaddr)[5] = ((uint8_t *)ipaddr)[3]; \
+	(enaddr)[3] = ((__uint8_t *)ipaddr)[1] & 0x7f; \
+	(enaddr)[4] = ((__uint8_t *)ipaddr)[2]; \
+	(enaddr)[5] = ((__uint8_t *)ipaddr)[3]; \
 }
 
 __END_DECLS
diff --git a/sysdeps/unix/sysv/linux/netinet/if_fddi.h b/sysdeps/unix/sysv/linux/netinet/if_fddi.h
index 2e4bb939f2..6a0e0d82d6 100644
--- a/sysdeps/unix/sysv/linux/netinet/if_fddi.h
+++ b/sysdeps/unix/sysv/linux/netinet/if_fddi.h
@@ -18,16 +18,18 @@
 #ifndef _NETINET_IF_FDDI_H
 #define	_NETINET_IF_FDDI_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
+
 #include <linux/if_fddi.h>
 
 #ifdef __USE_MISC
 
-struct fddi_header {
-  uint8_t fddi_fc;                    /* Frame Control (FC) value */
-  uint8_t fddi_dhost[FDDI_K_ALEN];    /* Destination host */
-  uint8_t fddi_shost[FDDI_K_ALEN];    /* Source host */
+struct fddi_header
+{
+  __uint8_t fddi_fc;                    /* Frame Control (FC) value */
+  __uint8_t fddi_dhost[FDDI_K_ALEN];    /* Destination host */
+  __uint8_t fddi_shost[FDDI_K_ALEN];    /* Source host */
 };
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/netinet/if_tr.h b/sysdeps/unix/sysv/linux/netinet/if_tr.h
index 9db6b7a6b5..6d6fd4f7cf 100644
--- a/sysdeps/unix/sysv/linux/netinet/if_tr.h
+++ b/sysdeps/unix/sysv/linux/netinet/if_tr.h
@@ -16,49 +16,49 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _NETINET_IF_TR_H
-#define	_NETINET_IF_TR_H 1
+#define _NETINET_IF_TR_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 /* IEEE 802.5 Token-Ring magic constants.  The frame sizes omit the preamble
    and FCS/CRC (frame check sequence). */
 #define TR_ALEN		6		/* Octets in one token-ring addr */
-#define TR_HLEN 	(sizeof (struct trh_hdr) + sizeof (struct trllc))
+#define TR_HLEN		(sizeof (struct trh_hdr) + sizeof (struct trllc))
 #define AC		0x10
-#define LLC_FRAME 	0x40
+#define LLC_FRAME	0x40
 
 /* LLC and SNAP constants */
-#define EXTENDED_SAP 	0xAA
-#define UI_CMD       	0x03
+#define EXTENDED_SAP	0xAA
+#define UI_CMD		0x03
 
 /* This is an Token-Ring frame header. */
 struct trh_hdr
 {
-  uint8_t  ac;			/* access control field */
-  uint8_t  fc;			/* frame control field */
-  uint8_t  daddr[TR_ALEN];	/* destination address */
-  uint8_t  saddr[TR_ALEN];	/* source address */
-  uint16_t rcf;			/* route control field */
-  uint16_t rseg[8];		/* routing registers */
+  __uint8_t  ac;		/* access control field */
+  __uint8_t  fc;		/* frame control field */
+  __uint8_t  daddr[TR_ALEN];	/* destination address */
+  __uint8_t  saddr[TR_ALEN];	/* source address */
+  __uint16_t rcf;		/* route control field */
+  __uint16_t rseg[8];		/* routing registers */
 };
 
 /* This is an Token-Ring LLC structure */
 struct trllc
 {
-  uint8_t  dsap;		/* destination SAP */
-  uint8_t  ssap;		/* source SAP */
-  uint8_t  llc;			/* LLC control field */
-  uint8_t  protid[3];		/* protocol id */
-  uint16_t ethertype;		/* ether type field */
+  __uint8_t  dsap;		/* destination SAP */
+  __uint8_t  ssap;		/* source SAP */
+  __uint8_t  llc;		/* LLC control field */
+  __uint8_t  protid[3];		/* protocol id */
+  __uint16_t ethertype;		/* ether type field */
 };
 
 /* Token-Ring statistics collection data. */
 struct tr_statistics
 {
-  unsigned long rx_packets;     /* total packets received	*/
+  unsigned long rx_packets;	/* total packets received	*/
   unsigned long tx_packets;	/* total packets transmitted	*/
-  unsigned long rx_bytes;	/* total bytes received   	*/
+  unsigned long rx_bytes;	/* total bytes received		*/
   unsigned long tx_bytes;	/* total bytes transmitted	*/
   unsigned long rx_errors;	/* bad packets received		*/
   unsigned long tx_errors;	/* packet transmit problems	*/
@@ -84,27 +84,27 @@ struct tr_statistics
 };
 
 /* source routing stuff */
-#define TR_RII 			0x80
-#define TR_RCF_DIR_BIT 		0x80
-#define TR_RCF_LEN_MASK 	0x1f00
-#define TR_RCF_BROADCAST 	0x8000	/* all-routes broadcast */
+#define TR_RII			 0x80
+#define TR_RCF_DIR_BIT		 0x80
+#define TR_RCF_LEN_MASK		 0x1f00
+#define TR_RCF_BROADCAST	 0x8000	/* all-routes broadcast */
 #define TR_RCF_LIMITED_BROADCAST 0xC000	/* single-route broadcast */
-#define TR_RCF_FRAME2K 		0x20
-#define TR_RCF_BROADCAST_MASK 	0xC000
-#define TR_MAXRIFLEN 		18
+#define TR_RCF_FRAME2K		 0x20
+#define TR_RCF_BROADCAST_MASK	 0xC000
+#define TR_MAXRIFLEN		 18
 
 #ifdef __USE_MISC
 
 struct trn_hdr
 {
-  uint8_t trn_ac;                /* access control field */
-  uint8_t trn_fc;                /* field control field */
-  uint8_t trn_dhost[TR_ALEN];    /* destination host */
-  uint8_t trn_shost[TR_ALEN];    /* source host */
-  uint16_t trn_rcf;              /* route control field */
-  uint16_t trn_rseg[8];          /* routing registers */
+  __uint8_t  trn_ac;		   /* access control field */
+  __uint8_t  trn_fc;		   /* field control field */
+  __uint8_t  trn_dhost[TR_ALEN];   /* destination host */
+  __uint8_t  trn_shost[TR_ALEN];   /* source host */
+  __uint16_t trn_rcf;		   /* route control field */
+  __uint16_t trn_rseg[8];	   /* routing registers */
 };
 
 #endif
 
-#endif	/* netinet/if_tr.h */
+#endif /* netinet/if_tr.h */
diff --git a/sysdeps/unix/sysv/linux/netipx/ipx.h b/sysdeps/unix/sysv/linux/netipx/ipx.h
index 6ccbb8846f..fbd3d9f380 100644
--- a/sysdeps/unix/sysv/linux/netipx/ipx.h
+++ b/sysdeps/unix/sysv/linux/netipx/ipx.h
@@ -18,8 +18,8 @@
 #ifndef __NETIPX_IPX_H
 #define __NETIPX_IPX_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 #include <bits/sockaddr.h>
 
 __BEGIN_DECLS
@@ -33,10 +33,10 @@ __BEGIN_DECLS
 struct sockaddr_ipx
   {
     sa_family_t sipx_family;
-    uint16_t sipx_port;
-    uint32_t sipx_network;
+    __uint16_t sipx_port;
+    __uint32_t sipx_network;
     unsigned char sipx_node[IPX_NODE_LEN];
-    uint8_t sipx_type;
+    __uint8_t sipx_type;
     unsigned char sipx_zero;	/* 16 byte fill */
   };
 
diff --git a/sysdeps/unix/sysv/linux/netrose/rose.h b/sysdeps/unix/sysv/linux/netrose/rose.h
index ab2afb383e..1c4bd26a8f 100644
--- a/sysdeps/unix/sysv/linux/netrose/rose.h
+++ b/sysdeps/unix/sysv/linux/netrose/rose.h
@@ -21,7 +21,7 @@
 #ifndef _NETROSE_ROSE_H
 #define _NETROSE_ROSE_H 1
 
-#include <sys/socket.h>
+#include <features.h>
 #include <netax25/ax25.h>
 
 /* Socket level values.  */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 18/25] Don’t include signal.h from sys/wait.h or sys/param.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (10 preceding siblings ...)
  2019-06-26 18:26 ` [PATCH 21/25] Don’t include sys/types.h or stdint.h from most public headers Zack Weinberg
@ 2019-06-26 18:26 ` Zack Weinberg
  2019-06-26 18:26 ` [PATCH 23/25] Don’t include sys/socket.h from public headers Zack Weinberg
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:26 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

Besides the snarl of debugger/ucontext interfaces, these are the only
public headers that include signal.h.

sys/wait.h includes signal.h only for the definition of siginfo_t.
We already have a single-type header for that, so use it.  siginfo_t
contains a field whose type is uid_t, but sys/wait.h is not specified
to define uid_t, so, as is already done for pid_t, the conformance
test is modified to expect that field to have type __uid_t instead.

It is not clear what subset of the definitions from signal.h are
actually expected by historical users of sys/param.h; I’ve chosen to
take the comment at face value and cut it down to bits/signum.h, which
supplies _NSIG and all of the SIG* constants.  This requires adjusting
every copy of bits/signum.h to permit inclusion by sys/param.h as well
as signal.h.

While I was at it I moved the comment about sys/param.h being obsolete
from sysdeps/mach/hurd/bits/param.h, where it’s not likely to be seen,
to the top-level sys/param.h, and edited it to give more useful advice.

This patch partially fixes Hurd-specific bug 23088; sys/wait.h is now
conformant.

	* posix/sys/wait.h: Include bits/types/siginfo_t.h, not signal.h.
	* conform/data/sys/wait.h-data: Do not expect a definition of uid_t.

	* malloc/tst-mallocfork.c, nptl/tst-fork4.c, nptl/tst-getpid3.c
	* nptl/tst-mutex9.c, nptl/tst-rwlock12.c
	* resolv/tst-resolv-res_init-skeleton.c
	* sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c:
        Include signal.h.

	* nptl/tst-cancel4.c, rt/tst-mqueue1.c
	* support/tst-support_capture_subprocess.c
	* sysdeps/unix/sysv/linux/tst-align-clone.c:
	Include signal.h.  Sort includes.

	* misc/sys/param.h: Include bits/signum.h, not signal.h.
	Add comment explaining that this header is obsolete, based on
	a similar comment in Hurd bits/param.h.

	* bits/param.h: Add multiple inclusion guard and defensive #error.
	* sysdeps/mach/hurd/bits/param.h: Add multiple inclusion guard.
	Remove comment explaining that this header is obsolete (see above).
	* sysdeps/mach/i386/bits/mach/param.h: Add multiple inclusion guard.
	* sysdeps/unix/sysv/linux/bits/param.h: Add multiple inclusion guard.

	* bits/signum-generic.h, bits/signum.h
	* sysdeps/unix/bsd/bits/signum.h
	* sysdeps/unix/sysv/linux/alpha/bits/signum.h
	* sysdeps/unix/sysv/linux/bits/signum.h
	* sysdeps/unix/sysv/linux/hppa/bits/signum.h
	* sysdeps/unix/sysv/linux/mips/bits/signum.h:
	Allow inclusion by sys/param.h as well as signal.h.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
	Update.

        * sysdeps/mach/hurd/i386/Makefile: Remove XFAILs for sys/wait.h.
---
 bits/param.h                                  |  7 +++++
 bits/signum-generic.h                         |  2 +-
 bits/signum.h                                 |  2 +-
 conform/data/sys/wait.h-data                  |  1 +
 malloc/tst-mallocfork.c                       |  1 +
 misc/sys/param.h                              |  8 +++++-
 nptl/tst-cancel4.c                            | 27 ++++++++++---------
 nptl/tst-fork4.c                              |  1 +
 nptl/tst-getpid3.c                            |  1 +
 nptl/tst-mutex9.c                             |  1 +
 nptl/tst-rwlock12.c                           |  1 +
 posix/sys/wait.h                              |  2 +-
 resolv/tst-resolv-res_init-skeleton.c         |  1 +
 rt/tst-mqueue1.c                              |  5 ++--
 scripts/check-obsolete-constructs.py          |  7 +++--
 support/tst-support_capture_subprocess.c      | 19 +++++++------
 sysdeps/mach/hurd/bits/param.h                | 13 +++++----
 sysdeps/mach/hurd/i386/Makefile               |  4 ---
 sysdeps/mach/i386/bits/mach/param.h           |  5 ++++
 sysdeps/unix/bsd/bits/signum.h                |  2 +-
 sysdeps/unix/sysv/linux/alpha/bits/signum.h   |  2 +-
 sysdeps/unix/sysv/linux/bits/param.h          |  5 ++++
 sysdeps/unix/sysv/linux/bits/signum.h         |  2 +-
 sysdeps/unix/sysv/linux/hppa/bits/signum.h    |  2 +-
 sysdeps/unix/sysv/linux/mips/bits/signum.h    |  2 +-
 .../sysv/linux/s390/tst-ptrace-singleblock.c  |  1 +
 sysdeps/unix/sysv/linux/sparc/bits/signum.h   |  2 +-
 sysdeps/unix/sysv/linux/tst-align-clone.c     |  5 ++--
 28 files changed, 81 insertions(+), 50 deletions(-)

diff --git a/bits/param.h b/bits/param.h
index e83f60f0b5..44c8505ad0 100644
--- a/bits/param.h
+++ b/bits/param.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PARAM_H
+#define _BITS_PARAM_H 1
+
 #ifndef _SYS_PARAM_H
 # error "Never use <bits/param.h> directly; include <sys/param.h> instead."
 #endif
@@ -31,3 +34,7 @@
 
         EXEC_PAGESIZE
 */
+
+#error "Generic bits/param.h should not have been used."
+
+#endif
diff --git a/bits/signum-generic.h b/bits/signum-generic.h
index 6fbbf20a31..71308d635d 100644
--- a/bits/signum-generic.h
+++ b/bits/signum-generic.h
@@ -19,7 +19,7 @@
 #ifndef	_BITS_SIGNUM_GENERIC_H
 #define _BITS_SIGNUM_GENERIC_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum-generic.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/bits/signum.h b/bits/signum.h
index 8c788c8e7e..90e13c9824 100644
--- a/bits/signum.h
+++ b/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/conform/data/sys/wait.h-data b/conform/data/sys/wait.h-data
index c0761424da..aa3a87ea15 100644
--- a/conform/data/sys/wait.h-data
+++ b/conform/data/sys/wait.h-data
@@ -2,6 +2,7 @@
 #ifdef  POSIX
 # define pid_t __pid_t
 #endif
+#define uid_t __uid_t
 
 constant WNOHANG
 constant WUNTRACED
diff --git a/malloc/tst-mallocfork.c b/malloc/tst-mallocfork.c
index 00851a16c3..d1d973c28b 100644
--- a/malloc/tst-mallocfork.c
+++ b/malloc/tst-mallocfork.c
@@ -2,6 +2,7 @@
    https://sourceware.org/bugzilla/show_bug.cgi?id=838.  */
 #include <assert.h>
 #include <errno.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
diff --git a/misc/sys/param.h b/misc/sys/param.h
index bb6478f79b..1dedc699a4 100644
--- a/misc/sys/param.h
+++ b/misc/sys/param.h
@@ -16,6 +16,12 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+/* This header is provided only for compatibility with historic Unix
+   systems.  New programs should use some combination of <endian.h>,
+   <limits.h>, <signal.h>, <stddef.h>, <stdint.h>, and <sys/types.h>
+   instead, and the names defined in those headers.  The utility
+   macros at the end of this header should not be used at all.  */
+
 #ifndef _SYS_PARAM_H
 #define _SYS_PARAM_H    1
 
@@ -24,7 +30,7 @@
 #include <sys/types.h>
 #include <limits.h>
 #include <endian.h>                     /* Define BYTE_ORDER et al.  */
-#include <signal.h>                     /* Define NSIG.  */
+#include <bits/signum.h>                /* Define NSIG.  */
 #include <bits/NULL.h>
 
 /* This file defines some things in system-specific ways.  */
diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c
index dce93dc03a..575c09d53f 100644
--- a/nptl/tst-cancel4.c
+++ b/nptl/tst-cancel4.c
@@ -19,27 +19,28 @@
 /* NOTE: this tests functionality beyond POSIX.  POSIX does not allow
    exit to be called more than once.  */
 
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <pthread.h>
+#include <signal.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <sys/mman.h>
+#include <sys/msg.h>
+#include <sys/poll.h>
 #include <sys/select.h>
 #include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <pthread.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <sys/mman.h>
-#include <sys/poll.h>
-#include <sys/wait.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/uio.h>
+#include <sys/un.h>
+#include <sys/wait.h>
 
 
 /* Since STREAMS are not supported in the standard Linux kernel and
diff --git a/nptl/tst-fork4.c b/nptl/tst-fork4.c
index b491d3eec8..4deaf2476c 100644
--- a/nptl/tst-fork4.c
+++ b/nptl/tst-fork4.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
diff --git a/nptl/tst-getpid3.c b/nptl/tst-getpid3.c
index f1e77f6b10..3883a471ed 100644
--- a/nptl/tst-getpid3.c
+++ b/nptl/tst-getpid3.c
@@ -1,5 +1,6 @@
 #include <errno.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/nptl/tst-mutex9.c b/nptl/tst-mutex9.c
index e9fd8e2859..4efd97bb45 100644
--- a/nptl/tst-mutex9.c
+++ b/nptl/tst-mutex9.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/nptl/tst-rwlock12.c b/nptl/tst-rwlock12.c
index 2d28a5b1d3..70a678f9eb 100644
--- a/nptl/tst-rwlock12.c
+++ b/nptl/tst-rwlock12.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/posix/sys/wait.h b/posix/sys/wait.h
index 691be2759c..7f8e0693dc 100644
--- a/posix/sys/wait.h
+++ b/posix/sys/wait.h
@@ -30,7 +30,7 @@ __BEGIN_DECLS
 #include <bits/types/pid_t.h>
 
 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
-# include <signal.h>
+# include <bits/types/siginfo_t.h>
 #endif
 
 #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8
diff --git a/resolv/tst-resolv-res_init-skeleton.c b/resolv/tst-resolv-res_init-skeleton.c
index 678f396c4c..32a790774f 100644
--- a/resolv/tst-resolv-res_init-skeleton.c
+++ b/resolv/tst-resolv-res_init-skeleton.c
@@ -25,6 +25,7 @@
 #include <gnu/lib-names.h>
 #include <netdb.h>
 #include <resolv/resolv_context.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <support/capture_subprocess.h>
diff --git a/rt/tst-mqueue1.c b/rt/tst-mqueue1.c
index fb8d2e2ff0..5e5039a14b 100644
--- a/rt/tst-mqueue1.c
+++ b/rt/tst-mqueue1.c
@@ -20,13 +20,14 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <mqueue.h>
+#include <signal.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
-#include <stdint.h>
+#include <sys/wait.h>
 #include "tst-mqueue.h"
 
 static int
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index a051d4e845..bca0f12c18 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -531,15 +531,15 @@ HEADER_ALLOWED_INCLUDES = {
     #           sys/sem.h -> sys/ipc.h
     #           sys/shm.h -> sys/ipc.h
     #           sys/time.h -> sys/select.h (effectively)
-    # allowed:  sys/wait.h -> signal.h
     "sys/msg.h":                   [ "sys/ipc.h" ],
     "sys/sem.h":                   [ "sys/ipc.h" ],
     "sys/shm.h":                   [ "sys/ipc.h" ],
     "sys/time.h":                  [ "sys/select.h" ],
+    # necessary for backward compatibility with BSD
     "sys/types.h":                 [ "endian.h" ],
+
     "sys/uio.h":                   [ "sys/types.h" ],
     "sys/un.h":                    [ "string.h" ],
-    "sys/wait.h":                  [ "signal.h" ],
 
     # POSIX networking headers
     # allowed: netdb.h -> netinet/in.h
@@ -593,8 +593,7 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/ioctl.h":                 [ "sys/ttydefaults.h" ],
     "sys/mount.h":                 [ "sys/ioctl.h" ],
     "sys/mtio.h":                  [ "sys/ioctl.h", "sys/types.h" ],
-    "sys/param.h":                 [ "endian.h", "limits.h", "signal.h",
-                                     "sys/types.h" ],
+    "sys/param.h":                 [ "endian.h", "limits.h", "sys/types.h" ],
     "sys/platform/ppc.h":          [ "stdint.h" ],
     "sys/procfs.h":                [ "sys/time.h", "sys/types.h",
                                      "sys/user.h" ],
diff --git a/support/tst-support_capture_subprocess.c b/support/tst-support_capture_subprocess.c
index ab363e41ac..11e8cb7282 100644
--- a/support/tst-support_capture_subprocess.c
+++ b/support/tst-support_capture_subprocess.c
@@ -16,21 +16,23 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <paths.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <array_length.h>
 #include <support/capture_subprocess.h>
 #include <support/check.h>
 #include <support/support.h>
 #include <support/temp_file.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <paths.h>
-#include <getopt.h>
-#include <limits.h>
-#include <errno.h>
-#include <array_length.h>
 
 /* Nonzero if the program gets called via 'exec'.  */
 static int restart;
@@ -273,7 +275,8 @@ do_multiple_tests (enum test_type type)
                   .out = random_string (lengths[length_idx_stdout]),
                   .err = random_string (lengths[length_idx_stderr]),
                   .write_mode = write_mode,
-                  .signal = signal * SIGTERM, /* 0 or SIGTERM.  */
+                  .signal = signal *
+                  SIGTERM, /* 0 or SIGTERM.  */
                   .status = status * 3,       /* 0 or 3.  */
                 };
               TEST_VERIFY (strlen (test.out) == lengths[length_idx_stdout]);
diff --git a/sysdeps/mach/hurd/bits/param.h b/sysdeps/mach/hurd/bits/param.h
index a0162e9ac8..09485f1d3e 100644
--- a/sysdeps/mach/hurd/bits/param.h
+++ b/sysdeps/mach/hurd/bits/param.h
@@ -16,19 +16,16 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PARAM_H
+#define _BITS_PARAM_H 1
+
 #ifndef _SYS_PARAM_H
 # error "Never use <bits/param.h> directly; include <sys/param.h> instead."
 #endif
 
 #include <bits/mach/param.h>
 
-/* This file is deprecated and is provided only for compatibility with
-   Unix systems.  It is unwise to include this file on programs which
-   are intended only for GNU systems.
-
-   Parts from:
-
- * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
+/* Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -85,3 +82,5 @@
 
 #define	FSHIFT	11		/* Bits to right of fixed binary point.  */
 #define FSCALE	(1<<FSHIFT)
+
+#endif /* bits/param.h */
diff --git a/sysdeps/mach/hurd/i386/Makefile b/sysdeps/mach/hurd/i386/Makefile
index 8404eb086c..bf62a5fc67 100644
--- a/sysdeps/mach/hurd/i386/Makefile
+++ b/sysdeps/mach/hurd/i386/Makefile
@@ -36,7 +36,6 @@ test-xfail-UNIX98/aio.h/conform = yes
 test-xfail-UNIX98/ftw.h/conform = yes
 test-xfail-UNIX98/mqueue.h/conform = yes
 test-xfail-UNIX98/netinet/in.h/conform = yes
-test-xfail-UNIX98/sys/wait.h/conform = yes
 test-xfail-UNIX98/sys/sem.h/conform = yes
 test-xfail-UNIX98/sys/uio.h/conform = yes
 test-xfail-UNIX98/sys/socket.h/conform = yes
@@ -51,7 +50,6 @@ test-xfail-POSIX2008/regex.h/conform = yes
 test-xfail-POSIX2008/aio.h/conform = yes
 test-xfail-POSIX2008/mqueue.h/conform = yes
 test-xfail-POSIX2008/netinet/in.h/conform = yes
-test-xfail-POSIX2008/sys/wait.h/conform = yes
 test-xfail-POSIX2008/sys/socket.h/conform = yes
 test-xfail-POSIX2008/sys/types.h/conform = yes
 test-xfail-POSIX2008/arpa/inet.h/conform = yes
@@ -64,7 +62,6 @@ test-xfail-XOPEN2K/aio.h/conform = yes
 test-xfail-XOPEN2K/ftw.h/conform = yes
 test-xfail-XOPEN2K/mqueue.h/conform = yes
 test-xfail-XOPEN2K/netinet/in.h/conform = yes
-test-xfail-XOPEN2K/sys/wait.h/conform = yes
 test-xfail-XOPEN2K/sys/sem.h/conform = yes
 test-xfail-XOPEN2K/sys/uio.h/conform = yes
 test-xfail-XOPEN2K/sys/socket.h/conform = yes
@@ -80,7 +77,6 @@ test-xfail-XOPEN2K8/aio.h/conform = yes
 test-xfail-XOPEN2K8/ftw.h/conform = yes
 test-xfail-XOPEN2K8/mqueue.h/conform = yes
 test-xfail-XOPEN2K8/netinet/in.h/conform = yes
-test-xfail-XOPEN2K8/sys/wait.h/conform = yes
 test-xfail-XOPEN2K8/sys/sem.h/conform = yes
 test-xfail-XOPEN2K8/sys/uio.h/conform = yes
 test-xfail-XOPEN2K8/sys/socket.h/conform = yes
diff --git a/sysdeps/mach/i386/bits/mach/param.h b/sysdeps/mach/i386/bits/mach/param.h
index 09a549d579..3fbe86aecd 100644
--- a/sysdeps/mach/i386/bits/mach/param.h
+++ b/sysdeps/mach/i386/bits/mach/param.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_MACH_PARAM_H
+#define _BITS_MACH_PARAM_H 1
+
 #ifndef _SYS_PARAM_H
 # error "Never use <bits/mach/param.h> directly; include <sys/param.h> instead."
 #endif
@@ -23,3 +26,5 @@
 #ifndef EXEC_PAGESIZE
 #define EXEC_PAGESIZE	4096
 #endif
+
+#endif
diff --git a/sysdeps/unix/bsd/bits/signum.h b/sysdeps/unix/bsd/bits/signum.h
index 7e3df3273b..e0178e9390 100644
--- a/sysdeps/unix/bsd/bits/signum.h
+++ b/sysdeps/unix/bsd/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/signum.h b/sysdeps/unix/sysv/linux/alpha/bits/signum.h
index da4ff93c9c..4355d35ab9 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/bits/param.h b/sysdeps/unix/sysv/linux/bits/param.h
index 53c0f9f136..f847c51031 100644
--- a/sysdeps/unix/sysv/linux/bits/param.h
+++ b/sysdeps/unix/sysv/linux/bits/param.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PARAM_H
+#define _BITS_PARAM_H 1
+
 #ifndef _SYS_PARAM_H
 # error "Never use <bits/param.h> directly; include <sys/param.h> instead."
 #endif
@@ -40,3 +43,5 @@
    and NCARGS anyway.  */
 #define NOFILE		256
 #define	NCARGS		131072
+
+#endif /* bits/param.h */
diff --git a/sysdeps/unix/sysv/linux/bits/signum.h b/sysdeps/unix/sysv/linux/bits/signum.h
index 25b0d2a6cf..86fde6a7d1 100644
--- a/sysdeps/unix/sysv/linux/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/signum.h b/sysdeps/unix/sysv/linux/hppa/bits/signum.h
index c643626f99..59599668cf 100644
--- a/sysdeps/unix/sysv/linux/hppa/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/mips/bits/signum.h b/sysdeps/unix/sysv/linux/mips/bits/signum.h
index 89a63e4a03..1a430c16ba 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c b/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c
index 89e86ad923..e7d36d2d75 100644
--- a/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c
+++ b/sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/signum.h b/sysdeps/unix/sysv/linux/sparc/bits/signum.h
index ec746fee99..866a1c3d9d 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/signum.h
@@ -19,7 +19,7 @@
 #ifndef _BITS_SIGNUM_H
 #define _BITS_SIGNUM_H 1
 
-#ifndef _SIGNAL_H
+#if !defined _SIGNAL_H && !defined _SYS_PARAM_H
 #error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/tst-align-clone.c b/sysdeps/unix/sysv/linux/tst-align-clone.c
index 82ecf7ba32..100eacfbfe 100644
--- a/sysdeps/unix/sysv/linux/tst-align-clone.c
+++ b/sysdeps/unix/sysv/linux/tst-align-clone.c
@@ -16,14 +16,15 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <sched.h>
+#include <signal.h>
+#include <stackinfo.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
-#include <sys/wait.h>
 #include <unistd.h>
+#include <sys/wait.h>
 #include <tst-stack-align.h>
-#include <stackinfo.h>
 
 static int
 f (void *arg)
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 23/25] Don’t include sys/socket.h from public headers.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (11 preceding siblings ...)
  2019-06-26 18:26 ` [PATCH 18/25] Don’t include signal.h from sys/wait.h or sys/param.h Zack Weinberg
@ 2019-06-26 18:26 ` Zack Weinberg
  2019-06-26 18:26 ` [PATCH 17/25] Don’t include sys/select.h from sys/types.h Zack Weinberg
  2019-06-26 19:06 ` [PATCH 24/25] Minimize inclusion of netinet/in.h from public headers Zack Weinberg
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:26 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

No standard public header is required to include sys/socket.h,
although some are allowed to.  Several public headers need the
definitions of socklen_t, struct sockaddr, and/or struct
sockaddr_storage, but nothing else from sys/socket.h.  We already have
a single-type header for socklen_t, so this patch adds single-type
headers for struct sockaddr and struct sockaddr_storage.

The definition of struct sockaddr_storage is subtly different on Linux
than on the Hurd; in order to not need two copies of
bits/types/struct_sockaddr_storage.h, bits/sockaddr.h is now
responsible for defining __ss_aligntype if ‘unsigned long int’ is not
the correct definition.

I also added a single-type header for struct linger, even though only
sys/socket.h is expected to define that, just because all three copies
of bits/socket.h were defining it exactly the same way.  There would
also be a case for defining it directly in sys/socket.h but this
seemed tidier.

I did *not* create single-type headers for struct msghdr and struct
cmsghdr, because those and their helper macros are not consistent
among the three copies of bits/socket.h, and, again, only sys/socket.h
is expected to define them.

The large number of .c files that add an `#include <sys/socket.h>`
might make this look like it’s not worth doing.  However, after this
change, only half of the files in the glibc source tree that include
netinet/in.h also need to include sys/socket.h, and only a third of
the files that include netdb.h need to include sys/socket.h.  Before,
all of the files in both groups were getting sys/socket.h.  That seems
like enough justification to me.

While I was at it I noticed that sys/socketvar.h is yet another
backward compatibility header that does nothing but include some other
header (sys/socket.h, in this case) and also doesn’t need to be
system-dependent.

	* socket/bits/types/struct_linger.h
	* socket/bits/types/struct_sockaddr.h
	* socket/bits/types/struct_sockaddr_storage.h:
	New single-type headers, factored out of the various bits/socket.h
	headers.

	* include/bits/types/struct_linger.h
	* include/bits/types/struct_sockaddr.h
	* include/bits/types/struct_sockaddr_storage.h:
	New wrappers.

	* socket/Makefile (headers): Add bits/types/struct_linger.h,
	bits/types/struct_sockaddr.h, and bits/types/struct_sockaddr_storage.h.
	Alphabetize the list.

	* bits/socket.h, sysdeps/mach/hurd/bits/socket.h
	* sysdeps/unix/sysv/linux/bits/socket.h:
	Don’t define struct sockaddr, struct sockaddr_storage,
	__ss_aligntype, or struct linger here.  Minimize inclusions.
	* sysdeps/unix/bsd/bits/sockaddr.h: Define __ss_aligntype here.

	* socket/sys/socket.h: Include bits/types/struct_linger.h,
	bits/sockaddr.h, bits/types/struct_sockaddr.h, and
	bits/types/struct_sockaddr_storage.h.  Move inclusion of
	bits/socket.h below forward declaration of struct timespec,
	and update commentary.

	* inet/ifaddrs.h, socket/net/if.h
	* sysdeps/mach/hurd/net/if_arp.h
	* sysdeps/mach/hurd/net/route.h
	* sysdeps/unix/sysv/linux/errqueue.h
	* sysdeps/unix/sysv/linux/net/if_arp.h
	* sysdeps/unix/sysv/linux/net/route.h:
	Include bits/types/struct_sockaddr.h and possibly also bits/types.h,
	not sys/socket.h or sys/types.h.

	* sysdeps/unix/sysv/linux/errqueue.h:
	* sysdeps/unix/sysv/linux/net/route.h:
	Use __uint8_t and __uint32_t instead of uint8_t and uint32_t.

	* inet/arpa/inet.h: Include bits/types/size_t.h.
	* inet/netinet/in.h: Include bits/sockaddr.h,
	bits/types/struct_sockaddr.h, and
	bits/types/struct_sockaddr_storage.h,
	not sys/socket.h.  Use __socklen_t instead of socklen_t.
	* inet/netinet/tcp.h: Include bits/types.h and
	bits/types/struct_sockaddr_storage.h, not sys/socket.h or
	bits/stdint-uintn.h.  Use __uint8_t, __uint16_t, and __uint32_t
	instead of uint8_t, uint16_t and uint32_t.
	* inet/protocols/routed.h: Include features.h and
	bits/types/struct_sockaddr.h, not sys/socket.h.
	* resolv/netdb.h: Include bits/types/socklen_t.h.
	* sysdeps/unix/sysv/linux/netatalk/at.h: Don’t include sys/socket.h.

	* include/ifaddrs.h: Include stddef.h for size_t.
	* include/netdb.h: Use __socklen_t instead of socklen_t.

	* inet/check_pf.c, inet/gethstbynm.c, inet/gethstbynm_r.c
	* inet/getsourcefilter.c, inet/inet6_opt.c, inet/inet6_option.c
        * inet/inet6_rth.c, inet/setsourcefilter.c, inet/test-ifaddrs.c
	* inet/test-inet6_opt.c, inet/tst-inet6_rth.c
	* inet/tst-inet6_scopeid_pton.c, nis/nss_nis/nis-hosts.c
	* nis/nss_nisplus/nisplus-hosts.c, nscd/aicache.c, nscd/cache.c
	* nscd/hstcache.c, nscd/initgrcache.c, nscd/netgroupcache.c
	* nscd/nscd_gethst_r.c, nscd/servicescache.c, nss/digits_dots.c
	* nss/nss_files/files-hosts.c, nss/nss_files/files-network.c
	* nss/tst-nss-files-hosts-erange.c, nss/tst-nss-files-hosts-getent.c
	* nss/tst-nss-files-hosts-multi.c, posix/tst-getaddrinfo3.c
	* resolv/nss_dns/dns-network.c, resolv/resolv_conf.c
	* resolv/tst-bug18665-tcp.c, resolv/tst-bug18665.c
	* resolv/tst-inet_ntop.c, resolv/tst-inet_pton.c
	* resolv/tst-resolv-ai_idn-common.c, resolv/tst-resolv-basic.c
	* resolv/tst-resolv-edns.c, resolv/tst-resolv-network.c
	* resolv/tst-resolv-nondecimal.c, resolv/tst-resolv-search.c
	* resolv/tst-resolv-threads.c, resolv/tst-resolv-trailing.c
	* sunrpc/rpc_gethostbyname.c
	* support/support_format_address_family.c
	* support/support_format_addrinfo.c
	* support/support_format_dns_packet.c
	* support/support_format_hostent.c, support/support_format_netent.c
	* sysdeps/mach/hurd/if_index.c
	* sysdeps/unix/sysv/linux/check_native.c: Include sys/socket.h.

	* resolv/tst-resolv-binary.c: Include sys/types.h.

	* sysdeps/generic/sys/socketvar.h: Move to socket/sys/socketvar.h.
	* include/sys/socketvar.h: New wrapper.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
	Update.
---
 bits/socket.h                                |  39 ----
 include/bits/types/struct_linger.h           |   1 +
 include/bits/types/struct_sockaddr.h         |   1 +
 include/bits/types/struct_sockaddr_storage.h |   1 +
 include/ifaddrs.h                            |   1 +
 include/netdb.h                              |   8 +-
 include/sys/socketvar.h                      |   1 +
 inet/arpa/inet.h                             |   1 +
 inet/check_pf.c                              |   1 +
 inet/gethstbynm.c                            |   1 +
 inet/gethstbynm_r.c                          |   1 +
 inet/getsourcefilter.c                       |   1 +
 inet/ifaddrs.h                               |   2 +-
 inet/inet6_opt.c                             |   1 +
 inet/inet6_option.c                          |   1 +
 inet/inet6_rth.c                             |   1 +
 inet/netinet/in.h                            |  35 ++--
 inet/netinet/tcp.h                           | 180 +++++++++----------
 inet/protocols/routed.h                      |   4 +-
 inet/setsourcefilter.c                       |   2 +-
 inet/test-ifaddrs.c                          |   1 +
 inet/test-inet6_opt.c                        |   1 +
 inet/tst-inet6_rth.c                         |   1 +
 inet/tst-inet6_scopeid_pton.c                |   1 +
 nis/nss_nis/nis-hosts.c                      |   1 +
 nis/nss_nisplus/nisplus-hosts.c              |   1 +
 nscd/aicache.c                               |   1 +
 nscd/cache.c                                 |   1 +
 nscd/hstcache.c                              |   1 +
 nscd/initgrcache.c                           |   1 +
 nscd/netgroupcache.c                         |   1 +
 nscd/nscd_gethst_r.c                         |   1 +
 nscd/servicescache.c                         |   1 +
 nss/digits_dots.c                            |   1 +
 nss/nss_files/files-hosts.c                  |   1 +
 nss/nss_files/files-network.c                |   1 +
 nss/tst-nss-files-hosts-erange.c             |   1 +
 nss/tst-nss-files-hosts-getent.c             |   1 +
 nss/tst-nss-files-hosts-multi.c              |   1 +
 posix/tst-getaddrinfo3.c                     |   1 +
 resolv/netdb.h                               |   1 +
 resolv/nss_dns/dns-network.c                 |   1 +
 resolv/resolv_conf.c                         |   1 +
 resolv/tst-bug18665-tcp.c                    |   1 +
 resolv/tst-bug18665.c                        |   1 +
 resolv/tst-inet_ntop.c                       |   1 +
 resolv/tst-inet_pton.c                       |   1 +
 resolv/tst-resolv-ai_idn-common.c            |   1 +
 resolv/tst-resolv-basic.c                    |   1 +
 resolv/tst-resolv-binary.c                   |   1 +
 resolv/tst-resolv-edns.c                     |   1 +
 resolv/tst-resolv-network.c                  |   1 +
 resolv/tst-resolv-nondecimal.c               |   1 +
 resolv/tst-resolv-search.c                   |   1 +
 resolv/tst-resolv-threads.c                  |   1 +
 resolv/tst-resolv-trailing.c                 |   1 +
 scripts/check-obsolete-constructs.py         |  12 +-
 socket/Makefile                              |   8 +-
 socket/bits/types/struct_linger.h            |  11 ++
 socket/bits/types/struct_sockaddr.h          |  15 ++
 socket/bits/types/struct_sockaddr_storage.h  |  21 +++
 socket/net/if.h                              |   2 +-
 socket/sys/socket.h                          |  13 +-
 {sysdeps/generic => socket}/sys/socketvar.h  |   0
 sunrpc/rpc_gethostbyname.c                   |   1 +
 support/support_format_address_family.c      |   1 +
 support/support_format_addrinfo.c            |   1 +
 support/support_format_dns_packet.c          |   1 +
 support/support_format_hostent.c             |   1 +
 support/support_format_netent.c              |   1 +
 sysdeps/mach/hurd/bits/socket.h              |  40 -----
 sysdeps/mach/hurd/if_index.c                 |   1 +
 sysdeps/mach/hurd/net/if_arp.h               |   3 +-
 sysdeps/mach/hurd/net/route.h                |   2 +-
 sysdeps/unix/bsd/bits/sockaddr.h             |   9 +
 sysdeps/unix/sysv/linux/bits/socket.h        |  35 ----
 sysdeps/unix/sysv/linux/check_native.c       |   1 +
 sysdeps/unix/sysv/linux/errqueue.h           |  19 +-
 sysdeps/unix/sysv/linux/net/if_arp.h         |   3 +-
 sysdeps/unix/sysv/linux/net/route.h          |  17 +-
 sysdeps/unix/sysv/linux/netatalk/at.h        |   3 +-
 81 files changed, 273 insertions(+), 267 deletions(-)
 create mode 100644 include/bits/types/struct_linger.h
 create mode 100644 include/bits/types/struct_sockaddr.h
 create mode 100644 include/bits/types/struct_sockaddr_storage.h
 create mode 100644 include/sys/socketvar.h
 create mode 100644 socket/bits/types/struct_linger.h
 create mode 100644 socket/bits/types/struct_sockaddr.h
 create mode 100644 socket/bits/types/struct_sockaddr_storage.h
 rename {sysdeps/generic => socket}/sys/socketvar.h (100%)

diff --git a/bits/socket.h b/bits/socket.h
index 8f5b85fa98..347b900e51 100644
--- a/bits/socket.h
+++ b/bits/socket.h
@@ -23,10 +23,6 @@
 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
 #endif
 
-#include <bits/wordsize.h>
-#include <bits/types.h>
-#include <bits/types/size_t.h>
-#include <bits/types/socklen_t.h>
 
 /* Types of sockets.  */
 enum __socket_type
@@ -137,34 +133,6 @@ enum __socket_type
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	128	/* 5 on the origional 4.4 BSD.  */
 
-/* Get the definition of the macro to define the common sockaddr members.  */
-#include <bits/sockaddr.h>
-
-/* Structure describing a generic socket address.  */
-struct sockaddr
-  {
-    __SOCKADDR_COMMON (sa_);	/* Common data: address family and length.  */
-    char sa_data[14];		/* Address data.  */
-  };
-
-
-/* Structure large enough to hold any socket address (with the historical
-   exception of AF_UNIX).  */
-#if __WORDSIZE == 64
-# define __ss_aligntype	__uint64_t
-#else
-# define __ss_aligntype	__uint32_t
-#endif
-#define _SS_PADSIZE \
-  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
-
-struct sockaddr_storage
-  {
-    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
-    char __ss_padding[_SS_PADSIZE];
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
-  };
-
 
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
@@ -347,11 +315,4 @@ enum
 #define SO_TYPE SO_TYPE
   };
 
-/* Structure used to manipulate the SO_LINGER option.  */
-struct linger
-  {
-    int l_onoff;		/* Nonzero to linger on close.  */
-    int l_linger;		/* Time to linger.  */
-  };
-
 #endif	/* bits/socket.h */
diff --git a/include/bits/types/struct_linger.h b/include/bits/types/struct_linger.h
new file mode 100644
index 0000000000..55b2f20dd7
--- /dev/null
+++ b/include/bits/types/struct_linger.h
@@ -0,0 +1 @@
+#include <socket/bits/types/struct_linger.h>
diff --git a/include/bits/types/struct_sockaddr.h b/include/bits/types/struct_sockaddr.h
new file mode 100644
index 0000000000..641fbcd56d
--- /dev/null
+++ b/include/bits/types/struct_sockaddr.h
@@ -0,0 +1 @@
+#include <socket/bits/types/struct_sockaddr.h>
diff --git a/include/bits/types/struct_sockaddr_storage.h b/include/bits/types/struct_sockaddr_storage.h
new file mode 100644
index 0000000000..68f3171f0c
--- /dev/null
+++ b/include/bits/types/struct_sockaddr_storage.h
@@ -0,0 +1 @@
+#include <socket/bits/types/struct_sockaddr_storage.h>
diff --git a/include/ifaddrs.h b/include/ifaddrs.h
index 416118f1b3..bea810b161 100644
--- a/include/ifaddrs.h
+++ b/include/ifaddrs.h
@@ -3,6 +3,7 @@
 
 # ifndef _ISOMAC
 
+#include <stddef.h>
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/include/netdb.h b/include/netdb.h
index e230b1f4fc..7853769ebe 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -39,21 +39,21 @@ extern int __old_gethostent_r (struct hostent *__restrict __result_buf,
 			       int *__restrict __h_errnop);
 
 extern int __gethostbyaddr_r (const void *__restrict __addr,
-			      socklen_t __len, int __type,
+			      __socklen_t __len, int __type,
 			      struct hostent *__restrict __result_buf,
 			      char *__restrict __buf, size_t __buflen,
 			      struct hostent **__restrict __result,
 			      int *__restrict __h_errnop)
      attribute_hidden;
 extern int __old_gethostbyaddr_r (const void *__restrict __addr,
-				  socklen_t __len, int __type,
+				  __socklen_t __len, int __type,
 				  struct hostent *__restrict __result_buf,
 				  char *__restrict __buf, size_t __buflen,
 				  struct hostent **__restrict __result,
 				  int *__restrict __h_errnop);
 
 extern int __gethostbyaddr2_r (const void *__restrict __addr,
-			       socklen_t __len, int __type,
+			       __socklen_t __len, int __type,
 			       struct hostent *__restrict __result_buf,
 			       char *__restrict __buf, size_t __buflen,
 			       struct hostent **__restrict __result,
@@ -246,7 +246,7 @@ extern enum nss_status _nss_ ## service ## _gethostbyname_r		      \
 		       (const char *name, struct hostent *host, char *buffer, \
 			size_t buflen, int *errnop, int *h_errnop);	      \
 extern enum nss_status _nss_ ## service ## _gethostbyaddr_r		      \
-		       (const void *addr, socklen_t addrlen, int af,	      \
+		       (const void *addr, __socklen_t addrlen, int af,	      \
 			struct hostent *host, char *buffer, size_t buflen,    \
 			int *errnop, int *h_errnop);			      \
 extern enum nss_status _nss_ ## service ## _setservent (int);		      \
diff --git a/include/sys/socketvar.h b/include/sys/socketvar.h
new file mode 100644
index 0000000000..658fd10b85
--- /dev/null
+++ b/include/sys/socketvar.h
@@ -0,0 +1 @@
+#include <socket/sys/socketvar.h>
diff --git a/inet/arpa/inet.h b/inet/arpa/inet.h
index facee279a8..616ac1d8fa 100644
--- a/inet/arpa/inet.h
+++ b/inet/arpa/inet.h
@@ -20,6 +20,7 @@
 
 #include <features.h>
 #include <netinet/in.h>		/* To define `struct in_addr'.  */
+#include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 
 __BEGIN_DECLS
diff --git a/inet/check_pf.c b/inet/check_pf.c
index 24183d45fc..ce2545a657 100644
--- a/inet/check_pf.c
+++ b/inet/check_pf.c
@@ -19,6 +19,7 @@
 #include <ifaddrs.h>
 #include <netdb.h>
 #include <stdint.h>
+#include <sys/socket.h>
 
 void
 attribute_hidden
diff --git a/inet/gethstbynm.c b/inet/gethstbynm.c
index d05799e4d0..ec0b26ab4c 100644
--- a/inet/gethstbynm.c
+++ b/inet/gethstbynm.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 
diff --git a/inet/gethstbynm_r.c b/inet/gethstbynm_r.c
index 5508a66c17..d1248db681 100644
--- a/inet/gethstbynm_r.c
+++ b/inet/gethstbynm_r.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <resolv/res_hconf.h>
diff --git a/inet/getsourcefilter.c b/inet/getsourcefilter.c
index e4b1647e0c..32dd94d18c 100644
--- a/inet/getsourcefilter.c
+++ b/inet/getsourcefilter.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <netinet/in.h>
 #include <stdint.h>
+#include <sys/socket.h>
 
 int
 getsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
diff --git a/inet/ifaddrs.h b/inet/ifaddrs.h
index dd48ff2fdf..57de5a1f68 100644
--- a/inet/ifaddrs.h
+++ b/inet/ifaddrs.h
@@ -20,7 +20,7 @@
 #define _IFADDRS_H	1
 
 #include <features.h>
-#include <sys/socket.h>
+#include <bits/types/struct_sockaddr.h>
 
 __BEGIN_DECLS
 
diff --git a/inet/inet6_opt.c b/inet/inet6_opt.c
index ed5114e2fb..ac29eb5a8d 100644
--- a/inet/inet6_opt.c
+++ b/inet/inet6_opt.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 
diff --git a/inet/inet6_option.c b/inet/inet6_option.c
index 762149a8b6..49d5a7fc18 100644
--- a/inet/inet6_option.c
+++ b/inet/inet6_option.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 #include <sys/param.h>
diff --git a/inet/inet6_rth.c b/inet/inet6_rth.c
index e79be7ad29..d1a11c33b1 100644
--- a/inet/inet6_rth.c
+++ b/inet/inet6_rth.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index b411ba939c..b7a1d6a2e8 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -19,10 +19,11 @@
 #define	_NETINET_IN_H	1
 
 #include <features.h>
-#include <bits/stdint-uintn.h>
-#include <sys/socket.h>
 #include <bits/types.h>
-
+#include <bits/stdint-uintn.h>
+#include <bits/sockaddr.h>
+#include <bits/types/struct_sockaddr.h>
+#include <bits/types/struct_sockaddr_storage.h>
 
 __BEGIN_DECLS
 
@@ -568,27 +569,27 @@ extern int inet6_option_find (const struct cmsghdr *__cmsg,
 
 
 /* Hop-by-Hop and Destination Options Processing (RFC 3542).  */
-extern int inet6_opt_init (void *__extbuf, socklen_t __extlen) __THROW;
-extern int inet6_opt_append (void *__extbuf, socklen_t __extlen, int __offset,
-			     uint8_t __type, socklen_t __len, uint8_t __align,
+extern int inet6_opt_init (void *__extbuf, __socklen_t __extlen) __THROW;
+extern int inet6_opt_append (void *__extbuf, __socklen_t __extlen, int __offset,
+			     uint8_t __type, __socklen_t __len, uint8_t __align,
 			     void **__databufp) __THROW;
-extern int inet6_opt_finish (void *__extbuf, socklen_t __extlen, int __offset)
+extern int inet6_opt_finish (void *__extbuf, __socklen_t __extlen, int __offset)
      __THROW;
 extern int inet6_opt_set_val (void *__databuf, int __offset, void *__val,
-			      socklen_t __vallen) __THROW;
-extern int inet6_opt_next (void *__extbuf, socklen_t __extlen, int __offset,
-			   uint8_t *__typep, socklen_t *__lenp,
+			      __socklen_t __vallen) __THROW;
+extern int inet6_opt_next (void *__extbuf, __socklen_t __extlen, int __offset,
+			   uint8_t *__typep, __socklen_t *__lenp,
 			   void **__databufp) __THROW;
-extern int inet6_opt_find (void *__extbuf, socklen_t __extlen, int __offset,
-			   uint8_t __type, socklen_t *__lenp,
+extern int inet6_opt_find (void *__extbuf, __socklen_t __extlen, int __offset,
+			   uint8_t __type, __socklen_t *__lenp,
 			   void **__databufp) __THROW;
 extern int inet6_opt_get_val (void *__databuf, int __offset, void *__val,
-			      socklen_t __vallen) __THROW;
+			      __socklen_t __vallen) __THROW;
 
 
 /* Routing Header Option (RFC 3542).  */
-extern socklen_t inet6_rth_space (int __type, int __segments) __THROW;
-extern void *inet6_rth_init (void *__bp, socklen_t __bp_len, int __type,
+extern __socklen_t inet6_rth_space (int __type, int __segments) __THROW;
+extern void *inet6_rth_init (void *__bp, __socklen_t __bp_len, int __type,
 			     int __segments) __THROW;
 extern int inet6_rth_add (void *__bp, const struct in6_addr *__addr) __THROW;
 extern int inet6_rth_reverse (const void *__in, void *__out) __THROW;
@@ -616,14 +617,14 @@ extern int setipv4sourcefilter (int __s, struct in_addr __interface_addr,
 /* Get source filter.  */
 extern int getsourcefilter (int __s, uint32_t __interface_addr,
 			    const struct sockaddr *__group,
-			    socklen_t __grouplen, uint32_t *__fmode,
+			    __socklen_t __grouplen, uint32_t *__fmode,
 			    uint32_t *__numsrc,
 			    struct sockaddr_storage *__slist) __THROW;
 
 /* Set source filter.  */
 extern int setsourcefilter (int __s, uint32_t __interface_addr,
 			    const struct sockaddr *__group,
-			    socklen_t __grouplen, uint32_t __fmode,
+			    __socklen_t __grouplen, uint32_t __fmode,
 			    uint32_t __numsrc,
 			    const struct sockaddr_storage *__slist) __THROW;
 #endif	/* use GNU */
diff --git a/inet/netinet/tcp.h b/inet/netinet/tcp.h
index 7b07accce7..8fc9c8f641 100644
--- a/inet/netinet/tcp.h
+++ b/inet/netinet/tcp.h
@@ -85,11 +85,11 @@
 #define TCP_REPAIR_OFF_NO_WP	 -1
 
 #ifdef __USE_MISC
-# include <bits/stdint-uintn.h>
 # include <bits/endian.h>
-# include <sys/socket.h>
+# include <bits/types.h>
+# include <bits/types/struct_sockaddr_storage.h>
 
-typedef	uint32_t tcp_seq;
+typedef	__uint32_t tcp_seq;
 /*
  * TCP header.
  * Per RFC 793, September, 1981.
@@ -100,61 +100,61 @@ struct tcphdr
     {
       struct
       {
-	uint16_t th_sport;	/* source port */
-	uint16_t th_dport;	/* destination port */
+	__uint16_t th_sport;	/* source port */
+	__uint16_t th_dport;	/* destination port */
 	tcp_seq th_seq;		/* sequence number */
 	tcp_seq th_ack;		/* acknowledgement number */
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-	uint8_t th_x2:4;	/* (unused) */
-	uint8_t th_off:4;	/* data offset */
+	__uint8_t th_x2:4;	/* (unused) */
+	__uint8_t th_off:4;	/* data offset */
 # endif
 # if __BYTE_ORDER == __BIG_ENDIAN
-	uint8_t th_off:4;	/* data offset */
-	uint8_t th_x2:4;	/* (unused) */
+	__uint8_t th_off:4;	/* data offset */
+	__uint8_t th_x2:4;	/* (unused) */
 # endif
-	uint8_t th_flags;
+	__uint8_t th_flags;
 # define TH_FIN	0x01
 # define TH_SYN	0x02
 # define TH_RST	0x04
 # define TH_PUSH	0x08
 # define TH_ACK	0x10
 # define TH_URG	0x20
-	uint16_t th_win;	/* window */
-	uint16_t th_sum;	/* checksum */
-	uint16_t th_urp;	/* urgent pointer */
+	__uint16_t th_win;	/* window */
+	__uint16_t th_sum;	/* checksum */
+	__uint16_t th_urp;	/* urgent pointer */
       };
       struct
       {
-	uint16_t source;
-	uint16_t dest;
-	uint32_t seq;
-	uint32_t ack_seq;
+	__uint16_t source;
+	__uint16_t dest;
+	__uint32_t seq;
+	__uint32_t ack_seq;
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-	uint16_t res1:4;
-	uint16_t doff:4;
-	uint16_t fin:1;
-	uint16_t syn:1;
-	uint16_t rst:1;
-	uint16_t psh:1;
-	uint16_t ack:1;
-	uint16_t urg:1;
-	uint16_t res2:2;
+	__uint16_t res1:4;
+	__uint16_t doff:4;
+	__uint16_t fin:1;
+	__uint16_t syn:1;
+	__uint16_t rst:1;
+	__uint16_t psh:1;
+	__uint16_t ack:1;
+	__uint16_t urg:1;
+	__uint16_t res2:2;
 # elif __BYTE_ORDER == __BIG_ENDIAN
-	uint16_t doff:4;
-	uint16_t res1:4;
-	uint16_t res2:2;
-	uint16_t urg:1;
-	uint16_t ack:1;
-	uint16_t psh:1;
-	uint16_t rst:1;
-	uint16_t syn:1;
-	uint16_t fin:1;
+	__uint16_t doff:4;
+	__uint16_t res1:4;
+	__uint16_t res2:2;
+	__uint16_t urg:1;
+	__uint16_t ack:1;
+	__uint16_t psh:1;
+	__uint16_t rst:1;
+	__uint16_t syn:1;
+	__uint16_t fin:1;
 # else
 #  error "Adjust your <bits/endian.h> defines"
 # endif
-	uint16_t window;
-	uint16_t check;
-	uint16_t urg_ptr;
+	__uint16_t window;
+	__uint16_t check;
+	__uint16_t urg_ptr;
       };
     };
 };
@@ -224,45 +224,45 @@ enum tcp_ca_state
 
 struct tcp_info
 {
-  uint8_t	tcpi_state;
-  uint8_t	tcpi_ca_state;
-  uint8_t	tcpi_retransmits;
-  uint8_t	tcpi_probes;
-  uint8_t	tcpi_backoff;
-  uint8_t	tcpi_options;
-  uint8_t	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
+  __uint8_t	tcpi_state;
+  __uint8_t	tcpi_ca_state;
+  __uint8_t	tcpi_retransmits;
+  __uint8_t	tcpi_probes;
+  __uint8_t	tcpi_backoff;
+  __uint8_t	tcpi_options;
+  __uint8_t	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
 
-  uint32_t	tcpi_rto;
-  uint32_t	tcpi_ato;
-  uint32_t	tcpi_snd_mss;
-  uint32_t	tcpi_rcv_mss;
+  __uint32_t	tcpi_rto;
+  __uint32_t	tcpi_ato;
+  __uint32_t	tcpi_snd_mss;
+  __uint32_t	tcpi_rcv_mss;
 
-  uint32_t	tcpi_unacked;
-  uint32_t	tcpi_sacked;
-  uint32_t	tcpi_lost;
-  uint32_t	tcpi_retrans;
-  uint32_t	tcpi_fackets;
+  __uint32_t	tcpi_unacked;
+  __uint32_t	tcpi_sacked;
+  __uint32_t	tcpi_lost;
+  __uint32_t	tcpi_retrans;
+  __uint32_t	tcpi_fackets;
 
   /* Times. */
-  uint32_t	tcpi_last_data_sent;
-  uint32_t	tcpi_last_ack_sent;	/* Not remembered, sorry.  */
-  uint32_t	tcpi_last_data_recv;
-  uint32_t	tcpi_last_ack_recv;
+  __uint32_t	tcpi_last_data_sent;
+  __uint32_t	tcpi_last_ack_sent;	/* Not remembered, sorry.  */
+  __uint32_t	tcpi_last_data_recv;
+  __uint32_t	tcpi_last_ack_recv;
 
   /* Metrics. */
-  uint32_t	tcpi_pmtu;
-  uint32_t	tcpi_rcv_ssthresh;
-  uint32_t	tcpi_rtt;
-  uint32_t	tcpi_rttvar;
-  uint32_t	tcpi_snd_ssthresh;
-  uint32_t	tcpi_snd_cwnd;
-  uint32_t	tcpi_advmss;
-  uint32_t	tcpi_reordering;
+  __uint32_t	tcpi_pmtu;
+  __uint32_t	tcpi_rcv_ssthresh;
+  __uint32_t	tcpi_rtt;
+  __uint32_t	tcpi_rttvar;
+  __uint32_t	tcpi_snd_ssthresh;
+  __uint32_t	tcpi_snd_cwnd;
+  __uint32_t	tcpi_advmss;
+  __uint32_t	tcpi_reordering;
 
-  uint32_t	tcpi_rcv_rtt;
-  uint32_t	tcpi_rcv_space;
+  __uint32_t	tcpi_rcv_rtt;
+  __uint32_t	tcpi_rcv_space;
 
-  uint32_t	tcpi_total_retrans;
+  __uint32_t	tcpi_total_retrans;
 };
 
 
@@ -275,18 +275,18 @@ struct tcp_info
 struct tcp_md5sig
 {
   struct sockaddr_storage tcpm_addr;		/* Address associated.  */
-  uint8_t	tcpm_flags;			/* Extension flags.  */
-  uint8_t	tcpm_prefixlen;			/* Address prefix.  */
-  uint16_t	tcpm_keylen;			/* Key length.  */
-  uint32_t	__tcpm_pad;			/* Zero.  */
-  uint8_t	tcpm_key[TCP_MD5SIG_MAXKEYLEN];	/* Key (binary).  */
+  __uint8_t	tcpm_flags;			/* Extension flags.  */
+  __uint8_t	tcpm_prefixlen;			/* Address prefix.  */
+  __uint16_t	tcpm_keylen;			/* Key length.  */
+  __uint32_t	__tcpm_pad;			/* Zero.  */
+  __uint8_t	tcpm_key[TCP_MD5SIG_MAXKEYLEN];	/* Key (binary).  */
 };
 
 /* For socket repair options.  */
 struct tcp_repair_opt
 {
-  uint32_t	opt_code;
-  uint32_t	opt_val;
+  __uint32_t	opt_code;
+  __uint32_t	opt_val;
 };
 
 /* Queue to repair, for TCP_REPAIR_QUEUE.  */
@@ -317,30 +317,30 @@ enum
 
 struct tcp_cookie_transactions
 {
-  uint16_t	tcpct_flags;
-  uint8_t	__tcpct_pad1;
-  uint8_t	tcpct_cookie_desired;
-  uint16_t	tcpct_s_data_desired;
-  uint16_t	tcpct_used;
-  uint8_t	tcpct_value[TCP_MSS_DEFAULT];
+  __uint16_t	tcpct_flags;
+  __uint8_t	__tcpct_pad1;
+  __uint8_t	tcpct_cookie_desired;
+  __uint16_t	tcpct_s_data_desired;
+  __uint16_t	tcpct_used;
+  __uint8_t	tcpct_value[TCP_MSS_DEFAULT];
 };
 
 /* For use with TCP_REPAIR_WINDOW.  */
 struct tcp_repair_window
 {
-  uint32_t snd_wl1;
-  uint32_t snd_wnd;
-  uint32_t max_window;
-  uint32_t rcv_wnd;
-  uint32_t rcv_wup;
+  __uint32_t snd_wl1;
+  __uint32_t snd_wnd;
+  __uint32_t max_window;
+  __uint32_t rcv_wnd;
+  __uint32_t rcv_wup;
 };
 
 /* For use with TCP_ZEROCOPY_RECEIVE.  */
 struct tcp_zerocopy_receive
 {
-  uint64_t address; /* In: address of mapping.  */
-  uint32_t length; /* In/out: number of bytes to map/mapped.  */
-  uint32_t recv_skip_hint; /* Out: amount of bytes to skip.  */
+  __uint64_t address; /* In: address of mapping.  */
+  __uint32_t length; /* In/out: number of bytes to map/mapped.  */
+  __uint32_t recv_skip_hint; /* Out: amount of bytes to skip.  */
 };
 
 #endif /* Misc.  */
diff --git a/inet/protocols/routed.h b/inet/protocols/routed.h
index adb1767dca..694c436445 100644
--- a/inet/protocols/routed.h
+++ b/inet/protocols/routed.h
@@ -32,7 +32,9 @@
 #ifndef _PROTOCOLS_ROUTED_H
 #define	_PROTOCOLS_ROUTED_H 1
 
-#include <sys/socket.h>
+#include <features.h>
+#include <bits/types/struct_sockaddr.h>
+
 /*
  * Routing Information Protocol
  *
diff --git a/inet/setsourcefilter.c b/inet/setsourcefilter.c
index 6aa18f48be..6d41e23e5b 100644
--- a/inet/setsourcefilter.c
+++ b/inet/setsourcefilter.c
@@ -20,7 +20,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <netinet/in.h>
-
+#include <sys/socket.h>
 
 int
 setsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
diff --git a/inet/test-ifaddrs.c b/inet/test-ifaddrs.c
index e96e7c854e..738c05981a 100644
--- a/inet/test-ifaddrs.c
+++ b/inet/test-ifaddrs.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ifaddrs.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
diff --git a/inet/test-inet6_opt.c b/inet/test-inet6_opt.c
index a7ebf006c6..e10680c498 100644
--- a/inet/test-inet6_opt.c
+++ b/inet/test-inet6_opt.c
@@ -1,3 +1,4 @@
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/inet/tst-inet6_rth.c b/inet/tst-inet6_rth.c
index 549d717c7d..abb85cdf26 100644
--- a/inet/tst-inet6_rth.c
+++ b/inet/tst-inet6_rth.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/ip6.h>
 
diff --git a/inet/tst-inet6_scopeid_pton.c b/inet/tst-inet6_scopeid_pton.c
index b09e7712f4..6a1b859a13 100644
--- a/inet/tst-inet6_scopeid_pton.c
+++ b/inet/tst-inet6_scopeid_pton.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
 #include <net-internal.h>
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
index d70973dcee..2851726376 100644
--- a/nis/nss_nis/nis-hosts.c
+++ b/nis/nss_nis/nis-hosts.c
@@ -25,6 +25,7 @@
 #include <netdb.h>
 #undef _nss_nis_endhostent
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <libc-lock.h>
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index 81ebd9f0d6..d7a9f3c5ea 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -23,6 +23,7 @@
 #include <netdb.h>
 #include <nss.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <rpcsvc/nis.h>
diff --git a/nscd/aicache.c b/nscd/aicache.c
index 5d8222e3b7..8b883b6c56 100644
--- a/nscd/aicache.c
+++ b/nscd/aicache.c
@@ -25,6 +25,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 #include <resolv/resolv-internal.h>
 #include <resolv/resolv_context.h>
 #include <scratch_buffer.h>
diff --git a/nscd/cache.c b/nscd/cache.c
index 85090a1641..c59b734210 100644
--- a/nscd/cache.c
+++ b/nscd/cache.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <libintl.h>
 #include <arpa/inet.h>
+#include <sys/socket.h>
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <sys/stat.h>
diff --git a/nscd/hstcache.c b/nscd/hstcache.c
index 94a2f6e9af..7dd74f2af3 100644
--- a/nscd/hstcache.c
+++ b/nscd/hstcache.c
@@ -33,6 +33,7 @@
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 #include <stackinfo.h>
 #include <scratch_buffer.h>
 
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index 678666563d..d25a478d07 100644
--- a/nscd/initgrcache.c
+++ b/nscd/initgrcache.c
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/param.h>
+#include <sys/socket.h>
 #include <scratch_buffer.h>
 #include <config.h>
 
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index 8fcb092657..b86010684b 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/param.h>
+#include <sys/socket.h>
 
 #include "../inet/netgroup.h"
 #include "nscd.h"
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c
index f4c5849862..909608c213 100644
--- a/nscd/nscd_gethst_r.c
+++ b/nscd/nscd_gethst_r.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <sys/socket.h>
 #include <arpa/nameser.h>
 #include <not-cancel.h>
 
diff --git a/nscd/servicescache.c b/nscd/servicescache.c
index 5ffc846e98..356e36ef68 100644
--- a/nscd/servicescache.c
+++ b/nscd/servicescache.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <stdint.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 #include <kernel-features.h>
 #include <scratch_buffer.h>
 
diff --git a/nss/digits_dots.c b/nss/digits_dots.c
index 440d9955d2..2b3624760b 100644
--- a/nss/digits_dots.c
+++ b/nss/digits_dots.c
@@ -25,6 +25,7 @@
 #include <resolv/resolv-internal.h>
 #include <resolv/resolv_context.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include "nsswitch.h"
 
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index da5967a87d..efcd6b4d4b 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <assert.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
index b63b5bfb79..61ace046b5 100644
--- a/nss/nss_files/files-network.c
+++ b/nss/nss_files/files-network.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
diff --git a/nss/tst-nss-files-hosts-erange.c b/nss/tst-nss-files-hosts-erange.c
index 9417957c78..bf77e23639 100644
--- a/nss/tst-nss-files-hosts-erange.c
+++ b/nss/tst-nss-files-hosts-erange.c
@@ -22,6 +22,7 @@
 #include <gnu/lib-names.h>
 #include <netdb.h>
 #include <nss.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/nss/tst-nss-files-hosts-getent.c b/nss/tst-nss-files-hosts-getent.c
index dfa6e8d57f..001f6f1ede 100644
--- a/nss/tst-nss-files-hosts-getent.c
+++ b/nss/tst-nss-files-hosts-getent.c
@@ -24,6 +24,7 @@
 #include <nss.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/nss/tst-nss-files-hosts-multi.c b/nss/tst-nss-files-hosts-multi.c
index 6d6ddc6f56..4862e84257 100644
--- a/nss/tst-nss-files-hosts-multi.c
+++ b/nss/tst-nss-files-hosts-multi.c
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/posix/tst-getaddrinfo3.c b/posix/tst-getaddrinfo3.c
index 5077f311fc..1d1919971a 100644
--- a/posix/tst-getaddrinfo3.c
+++ b/posix/tst-getaddrinfo3.c
@@ -2,6 +2,7 @@
 #include <netdb.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 
diff --git a/resolv/netdb.h b/resolv/netdb.h
index 6c1af6aee1..1158864312 100644
--- a/resolv/netdb.h
+++ b/resolv/netdb.h
@@ -25,6 +25,7 @@
 #include <features.h>
 
 #include <netinet/in.h>
+#include <bits/types/socklen_t.h>
 #include <bits/stdint-uintn.h>
 #ifdef __USE_MISC
 /* This is necessary to make this include file properly replace the
diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 21688c19b2..668cb502b2 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -65,6 +65,7 @@
 #include <stddef.h>
 
 #include "nsswitch.h"
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <resolv/resolv-internal.h>
diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
index c204625f4a..211a17dfd6 100644
--- a/resolv/resolv_conf.c
+++ b/resolv/resolv_conf.c
@@ -23,6 +23,7 @@
 #include <libc-lock.h>
 #include <resolv-internal.h>
 #include <sys/stat.h>
+#include <sys/socket.h>
 #include <libc-symbols.h>
 
 /* _res._u._ext.__glibc_extension_index is used as an index into a
diff --git a/resolv/tst-bug18665-tcp.c b/resolv/tst-bug18665-tcp.c
index 4595bc34ba..090ae0a86b 100644
--- a/resolv/tst-bug18665-tcp.c
+++ b/resolv/tst-bug18665-tcp.c
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-bug18665.c b/resolv/tst-bug18665.c
index e477777548..2417d67dda 100644
--- a/resolv/tst-bug18665.c
+++ b/resolv/tst-bug18665.c
@@ -21,6 +21,7 @@
 #include <resolv.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 #include <support/xthread.h>
diff --git a/resolv/tst-inet_ntop.c b/resolv/tst-inet_ntop.c
index f0de06306c..728fd25d7f 100644
--- a/resolv/tst-inet_ntop.c
+++ b/resolv/tst-inet_ntop.c
@@ -3,6 +3,7 @@
 #include <netinet/in.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 
 static int
 do_test (void)
diff --git a/resolv/tst-inet_pton.c b/resolv/tst-inet_pton.c
index 87f13d51f5..c137e50c13 100644
--- a/resolv/tst-inet_pton.c
+++ b/resolv/tst-inet_pton.c
@@ -21,6 +21,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/next_to_fault.h>
 #include <support/xunistd.h>
diff --git a/resolv/tst-resolv-ai_idn-common.c b/resolv/tst-resolv-ai_idn-common.c
index 61cc81b71f..f560ccf5cd 100644
--- a/resolv/tst-resolv-ai_idn-common.c
+++ b/resolv/tst-resolv-ai_idn-common.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-basic.c b/resolv/tst-resolv-basic.c
index 3046be24e1..fcc9fc8a84 100644
--- a/resolv/tst-resolv-basic.c
+++ b/resolv/tst-resolv-basic.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/format_nss.h>
diff --git a/resolv/tst-resolv-binary.c b/resolv/tst-resolv-binary.c
index eecdb7e0a3..153ce4d9cc 100644
--- a/resolv/tst-resolv-binary.c
+++ b/resolv/tst-resolv-binary.c
@@ -18,6 +18,7 @@
 
 #include <resolv.h>
 #include <string.h>
+#include <sys/types.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 
diff --git a/resolv/tst-resolv-edns.c b/resolv/tst-resolv-edns.c
index 0aaba73b05..e88463ddff 100644
--- a/resolv/tst-resolv-edns.c
+++ b/resolv/tst-resolv-edns.c
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 #include <support/support.h>
diff --git a/resolv/tst-resolv-network.c b/resolv/tst-resolv-network.c
index 4f68ce19e0..c4609a4db5 100644
--- a/resolv/tst-resolv-network.c
+++ b/resolv/tst-resolv-network.c
@@ -19,6 +19,7 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-nondecimal.c b/resolv/tst-resolv-nondecimal.c
index a0df6f332a..61888eadd9 100644
--- a/resolv/tst-resolv-nondecimal.c
+++ b/resolv/tst-resolv-nondecimal.c
@@ -18,6 +18,7 @@
 
 #include <netdb.h>
 #include <stdlib.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-search.c b/resolv/tst-resolv-search.c
index d49d2f8459..bca1e1312d 100644
--- a/resolv/tst-resolv-search.c
+++ b/resolv/tst-resolv-search.c
@@ -19,6 +19,7 @@
 #include <resolv.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-threads.c b/resolv/tst-resolv-threads.c
index 7e87e641cc..c06dd62642 100644
--- a/resolv/tst-resolv-threads.c
+++ b/resolv/tst-resolv-threads.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/namespace.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-trailing.c b/resolv/tst-resolv-trailing.c
index 7504bdae57..a513e56544 100644
--- a/resolv/tst-resolv-trailing.c
+++ b/resolv/tst-resolv-trailing.c
@@ -18,6 +18,7 @@
 
 #include <array_length.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index db367e61ae..2ca83b90c7 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -542,9 +542,6 @@ HEADER_ALLOWED_INCLUDES = {
     #          arpa/inet.h -> netinet/in.h
     "netdb.h":                     [ "netinet/in.h", "rpc/netdb.h" ],
     "arpa/inet.h":                 [ "netinet/in.h" ],
-    "net/if.h":                    [ "sys/socket.h" ],
-    "netinet/in.h":                [ "sys/socket.h" ],
-    "netinet/tcp.h":               [ "sys/socket.h" ],
 
     # Nonstandardized top-level headers
     "argp.h":                      [ "ctype.h", "errno.h", "getopt.h",
@@ -580,7 +577,6 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/procfs.h":                [ "sys/ucontext.h", "sys/user.h" ],
     "sys/ptrace.h":                [ "sys/ucontext.h" ],
     "sys/raw.h":                   [ "sys/ioctl.h" ],
-    "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/timerfd.h":               [ "time.h" ],
     "sys/ttychars.h":              [ "sys/ttydefaults.h" ],
     "sys/ucontext.h":              [ "sys/procfs.h" ],
@@ -598,6 +594,7 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/fcntl.h":                 [ "fcntl.h" ],
     "sys/poll.h":                  [ "poll.h" ],
     "sys/signal.h":                [ "signal.h" ],
+    "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/syslog.h":                [ "syslog.h" ],
     "sys/termios.h":               [ "termios.h" ],
     "sys/unistd.h":                [ "unistd.h" ],
@@ -606,18 +603,16 @@ HEADER_ALLOWED_INCLUDES = {
     "wait.h":                      [ "sys/wait.h" ],
 
     # Nonstandardized networking headers
-    "ifaddrs.h":                   [ "sys/socket.h" ],
 
     "resolv.h":                    [ "arpa/nameser.h", "netinet/in.h" ],
     "arpa/nameser.h":              [ "arpa/nameser_compat.h" ],
 
     "net/ethernet.h":              [ "net/if_ether.h" ],
-    "net/if_arp.h":                [ "sys/socket.h" ],
     "net/if_ppp.h":                [ "net/if.h", "net/ppp_defs.h",
                                      "sys/ioctl.h" ],
     "net/if_shaper.h":             [ "net/if.h", "sys/ioctl.h" ],
-    "net/route.h":                 [ "netinet/in.h", "sys/socket.h" ],
-    "netatalk/at.h":               [ "sys/socket.h", "sys/ioctl.h" ],
+    "net/route.h":                 [ "netinet/in.h" ],
+    "netatalk/at.h":               [ "sys/ioctl.h" ],
 
     "netinet/ether.h":             [ "netinet/if_ether.h" ],
     "netinet/icmp6.h":             [ "netinet/in.h" ],
@@ -629,7 +624,6 @@ HEADER_ALLOWED_INCLUDES = {
 
     "netrom/netrom.h":             [ "netax25/ax25.h" ],
     "netrose/rose.h":              [ "netax25/ax25.h" ],
-    "protocols/routed.h":          [ "sys/socket.h" ],
     "protocols/rwhod.h":           [ "paths.h" ],
 
     # Internal headers
diff --git a/socket/Makefile b/socket/Makefile
index cac527221c..cd31c3b875 100644
--- a/socket/Makefile
+++ b/socket/Makefile
@@ -22,9 +22,11 @@ subdir	:= socket
 
 include ../Makeconfig
 
-headers	:= sys/socket.h sys/un.h bits/sockaddr.h bits/socket.h \
-	   bits/socket2.h bits/types/struct_osockaddr.h \
-	   sys/socketvar.h net/if.h
+headers := net/if.h sys/socket.h sys/socketvar.h sys/un.h		\
+	   bits/sockaddr.h bits/socket.h bits/socket2.h			\
+	   bits/types/struct_linger.h bits/types/struct_osockaddr.h	\
+	   bits/types/struct_sockaddr.h					\
+	   bits/types/struct_sockaddr_storage.h
 
 routines := accept bind connect getpeername getsockname getsockopt	\
 	    listen recv recvfrom recvmsg send sendmsg sendto		\
diff --git a/socket/bits/types/struct_linger.h b/socket/bits/types/struct_linger.h
new file mode 100644
index 0000000000..58708e0204
--- /dev/null
+++ b/socket/bits/types/struct_linger.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_TYPES_STRUCT_LINGER_H
+#define _BITS_TYPES_STRUCT_LINGER_H 1
+
+/* Structure used to manipulate the SO_LINGER option.  */
+struct linger
+  {
+    int l_onoff;		/* Nonzero to linger on close.  */
+    int l_linger;		/* Time to linger.  */
+  };
+
+#endif
diff --git a/socket/bits/types/struct_sockaddr.h b/socket/bits/types/struct_sockaddr.h
new file mode 100644
index 0000000000..86100142ca
--- /dev/null
+++ b/socket/bits/types/struct_sockaddr.h
@@ -0,0 +1,15 @@
+#ifndef __struct_sockaddr_defined
+#define __struct_sockaddr_defined 1
+
+#include <bits/sockaddr.h>
+
+/* Structure describing a generic socket address.  For historical
+   reasons this type is smaller than many address families' concrete
+   socket addresses.  You may want struct sockaddr_storage instead.  */
+struct sockaddr
+  {
+    __SOCKADDR_COMMON (sa_);	/* Common data: family and perhaps length.  */
+    char sa_data[14];		/* Address data.  */
+  };
+
+#endif
diff --git a/socket/bits/types/struct_sockaddr_storage.h b/socket/bits/types/struct_sockaddr_storage.h
new file mode 100644
index 0000000000..47e0513939
--- /dev/null
+++ b/socket/bits/types/struct_sockaddr_storage.h
@@ -0,0 +1,21 @@
+#ifndef __struct_sockaddr_storage_defined
+#define __struct_sockaddr_storage_defined 1
+
+#include <bits/sockaddr.h>
+
+/* Structure large enough to hold any socket address (with the historical
+   exception of AF_UNIX).  */
+#ifndef __ss_aligntype
+# define __ss_aligntype	unsigned long int
+#endif
+#define _SS_PADSIZE \
+  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
+
+struct sockaddr_storage
+  {
+    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
+    char __ss_padding[_SS_PADSIZE];
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
+  };
+
+#endif /* bits/types/struct_sockaddr_storage.h */
diff --git a/socket/net/if.h b/socket/net/if.h
index b2fdbf7be0..f7fb0666cb 100644
--- a/socket/net/if.h
+++ b/socket/net/if.h
@@ -32,7 +32,7 @@ struct if_nameindex
 
 
 #ifdef __USE_MISC
-# include <sys/socket.h>  /* for struct sockaddr */
+# include <bits/types/struct_sockaddr.h>
 
 /* Standard interface flags. */
 enum
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index 9770d90d2a..c8042036e5 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -28,11 +28,11 @@ __BEGIN_DECLS
 #include <bits/types/ssize_t.h>
 #include <bits/types/socklen_t.h>
 #include <bits/types/struct_iovec.h>
+#include <bits/types/struct_linger.h>
 
-/* This operating system-specific header file defines the SOCK_*, PF_*,
-   AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
-   `struct msghdr', and `struct linger' types.  */
-#include <bits/socket.h>
+#include <bits/sockaddr.h>
+#include <bits/types/struct_sockaddr.h>
+#include <bits/types/struct_sockaddr_storage.h>
 
 #ifdef __USE_MISC
 # include <bits/types/struct_osockaddr.h>
@@ -42,6 +42,11 @@ __BEGIN_DECLS
 struct timespec;
 #endif
 
+/* This operating system-specific header file defines the SOCK_*, PF_*,
+   AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct msghdr' and
+   `struct cmsghdr' types.  */
+#include <bits/socket.h>
+
 /* The following constants should be used for the second parameter of
    `shutdown'.  */
 enum
diff --git a/sysdeps/generic/sys/socketvar.h b/socket/sys/socketvar.h
similarity index 100%
rename from sysdeps/generic/sys/socketvar.h
rename to socket/sys/socketvar.h
diff --git a/sunrpc/rpc_gethostbyname.c b/sunrpc/rpc_gethostbyname.c
index c44e2a38a0..eaf96a42df 100644
--- a/sunrpc/rpc_gethostbyname.c
+++ b/sunrpc/rpc_gethostbyname.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #include <rpc/rpc.h>
 #include <scratch_buffer.h>
 #include <string.h>
diff --git a/support/support_format_address_family.c b/support/support_format_address_family.c
index 8f439d5fc4..b629655ec1 100644
--- a/support/support_format_address_family.c
+++ b/support/support_format_address_family.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <support/support.h>
 
 char *
diff --git a/support/support_format_addrinfo.c b/support/support_format_addrinfo.c
index 6bccb36a48..e7316a6f24 100644
--- a/support/support_format_addrinfo.c
+++ b/support/support_format_addrinfo.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/socket.h>
 #include <support/support.h>
 #include <support/xmemstream.h>
 
diff --git a/support/support_format_dns_packet.c b/support/support_format_dns_packet.c
index 7ada6a8acc..02e705da25 100644
--- a/support/support_format_dns_packet.c
+++ b/support/support_format_dns_packet.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <resolv.h>
 #include <stdbool.h>
diff --git a/support/support_format_hostent.c b/support/support_format_hostent.c
index 604d1c2fed..e07d20d926 100644
--- a/support/support_format_hostent.c
+++ b/support/support_format_hostent.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <stdio.h>
diff --git a/support/support_format_netent.c b/support/support_format_netent.c
index d5ab83f2ac..3f524bd0d6 100644
--- a/support/support_format_netent.c
+++ b/support/support_format_netent.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
index 77498ca43e..43e3cdc8c5 100644
--- a/sysdeps/mach/hurd/bits/socket.h
+++ b/sysdeps/mach/hurd/bits/socket.h
@@ -25,11 +25,6 @@
 #endif
 
 
-#include <bits/types.h>
-#include <bits/types/size_t.h>
-#include <bits/types/socklen_t.h>
-#include <bits/wordsize.h>
-
 /* Types of sockets.  */
 enum __socket_type
 {
@@ -142,34 +137,6 @@ enum __socket_type
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	128	/* 5 on the origional 4.4 BSD.  */
 
-/* Get the definition of the macro to define the common sockaddr members.  */
-#include <bits/sockaddr.h>
-
-/* Structure describing a generic socket address.  */
-struct sockaddr
-  {
-    __SOCKADDR_COMMON (sa_);	/* Common data: address family and length.  */
-    char sa_data[14];		/* Address data.  */
-  };
-
-
-/* Structure large enough to hold any socket address (with the historical
-   exception of AF_UNIX).  */
-#if __WORDSIZE == 64
-# define __ss_aligntype	__uint64_t
-#else
-# define __ss_aligntype	__uint32_t
-#endif
-#define _SS_PADSIZE \
-  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
-
-struct sockaddr_storage
-  {
-    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
-    char __ss_padding[_SS_PADSIZE];
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
-  };
-
 
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
@@ -352,11 +319,4 @@ enum
 #define SO_TYPE SO_TYPE
   };
 
-/* Structure used to manipulate the SO_LINGER option.  */
-struct linger
-  {
-    int l_onoff;		/* Nonzero to linger on close.  */
-    int l_linger;		/* Time to linger.  */
-  };
-
 #endif	/* bits/socket.h */
diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c
index c8ddabb872..b5778f6270 100644
--- a/sysdeps/mach/hurd/if_index.c
+++ b/sysdeps/mach/hurd/if_index.c
@@ -19,6 +19,7 @@
 #include <error.h>
 #include <net/if.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 38665feab4..6f0d1bc94d 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -23,7 +23,8 @@
 #define _NET_IF_ARP_H 1
 
 #include <features.h>
-#include <sys/socket.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/mach/hurd/net/route.h b/sysdeps/mach/hurd/net/route.h
index fcb79bb33d..d288475426 100644
--- a/sysdeps/mach/hurd/net/route.h
+++ b/sysdeps/mach/hurd/net/route.h
@@ -22,7 +22,7 @@
 
 #include <features.h>
 
-#include <sys/socket.h>
+#include <bits/types/struct_sockaddr.h>
 #include <netinet/in.h>
 
 
diff --git a/sysdeps/unix/bsd/bits/sockaddr.h b/sysdeps/unix/bsd/bits/sockaddr.h
index d85f72b868..723aaf3e3d 100644
--- a/sysdeps/unix/bsd/bits/sockaddr.h
+++ b/sysdeps/unix/bsd/bits/sockaddr.h
@@ -42,4 +42,13 @@ typedef unsigned char sa_family_t;
 /* Size of struct sockaddr_storage.  */
 #define _SS_SIZE 128
 
+/* Desired alignment for struct sockaddr_storage.  */
+#include <bits/types.h>
+#include <bits/wordsize.h>
+#if __WORDSIZE == 64
+# define __ss_aligntype __uint64_t
+#else
+# define __ss_aligntype __uint32_t
+#endif
+
 #endif	/* bits/sockaddr.h */
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index ef3d6f9fc5..1fb3cbfb90 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -24,10 +24,6 @@
 #endif
 
 
-#include <bits/types.h>
-#include <bits/types/size_t.h>
-#include <bits/types/socklen_t.h>
-
 /* Get the architecture-dependent definition of enum __socket_type.  */
 #include <bits/socket_type.h>
 
@@ -165,30 +161,6 @@
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	128
 
-/* Get the definition of the macro to define the common sockaddr members.  */
-#include <bits/sockaddr.h>
-
-/* Structure describing a generic socket address.  */
-struct sockaddr
-  {
-    __SOCKADDR_COMMON (sa_);	/* Common data: address family and length.  */
-    char sa_data[14];		/* Address data.  */
-  };
-
-
-/* Structure large enough to hold any socket address (with the historical
-   exception of AF_UNIX).  */
-#define __ss_aligntype	unsigned long int
-#define _SS_PADSIZE \
-  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
-
-struct sockaddr_storage
-  {
-    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
-    char __ss_padding[_SS_PADSIZE];
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
-  };
-
 
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
@@ -437,11 +409,4 @@ struct ucred
 # undef IOC_OUT
 #endif
 
-/* Structure used to manipulate the SO_LINGER option.  */
-struct linger
-  {
-    int l_onoff;		/* Nonzero to linger on close.  */
-    int l_linger;		/* Time to linger.  */
-  };
-
 #endif	/* bits/socket.h */
diff --git a/sysdeps/unix/sysv/linux/check_native.c b/sysdeps/unix/sysv/linux/check_native.c
index 6521c9132c..4e346e9a6e 100644
--- a/sysdeps/unix/sysv/linux/check_native.c
+++ b/sysdeps/unix/sysv/linux/check_native.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <net/if.h>
 #include <net/if_arp.h>
+#include <sys/socket.h>
 #include <sys/ioctl.h>
 
 #include <asm/types.h>
diff --git a/sysdeps/unix/sysv/linux/errqueue.h b/sysdeps/unix/sysv/linux/errqueue.h
index 6698d94ead..58f24ae6cc 100644
--- a/sysdeps/unix/sysv/linux/errqueue.h
+++ b/sysdeps/unix/sysv/linux/errqueue.h
@@ -20,18 +20,19 @@
 #ifndef _BITS_ERRQUEUE_H
 #define _BITS_ERRQUEUE_H  1
 
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 
 struct sock_extended_err
   {
-    uint32_t ee_errno;
-    uint8_t ee_origin;
-    uint8_t ee_type;
-    uint8_t ee_code;
-    uint8_t ee_pad;
-    uint32_t ee_info;
-    uint32_t ee_data;
+    __uint32_t ee_errno;
+    __uint8_t ee_origin;
+    __uint8_t ee_type;
+    __uint8_t ee_code;
+    __uint8_t ee_pad;
+    __uint32_t ee_info;
+    __uint32_t ee_data;
+    /* A socket address immediately follows.  */
   };
 
 #define SO_EE_ORIGIN_NONE  0
diff --git a/sysdeps/unix/sysv/linux/net/if_arp.h b/sysdeps/unix/sysv/linux/net/if_arp.h
index 5013d085a2..767e5b4db3 100644
--- a/sysdeps/unix/sysv/linux/net/if_arp.h
+++ b/sysdeps/unix/sysv/linux/net/if_arp.h
@@ -23,7 +23,8 @@
 #define _NET_IF_ARP_H 1
 
 #include <features.h>
-#include <sys/socket.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/net/route.h b/sysdeps/unix/sysv/linux/net/route.h
index a0d9a74af4..edd4afd3b2 100644
--- a/sysdeps/unix/sysv/linux/net/route.h
+++ b/sysdeps/unix/sysv/linux/net/route.h
@@ -22,10 +22,11 @@
 
 #include <features.h>
 
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 #include <bits/wordsize.h>
 
+#include <netinet/in.h>
 
 /* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */
 struct rtentry
@@ -59,12 +60,12 @@ struct in6_rtmsg
     struct in6_addr rtmsg_dst;
     struct in6_addr rtmsg_src;
     struct in6_addr rtmsg_gateway;
-    uint32_t rtmsg_type;
-    uint16_t rtmsg_dst_len;
-    uint16_t rtmsg_src_len;
-    uint32_t rtmsg_metric;
+    __uint32_t rtmsg_type;
+    __uint16_t rtmsg_dst_len;
+    __uint16_t rtmsg_src_len;
+    __uint32_t rtmsg_metric;
     unsigned long int rtmsg_info;
-    uint32_t rtmsg_flags;
+    __uint32_t rtmsg_flags;
     int rtmsg_ifindex;
   };
 
@@ -113,7 +114,7 @@ struct in6_rtmsg
 #define RTF_NAT		0x08000000
 
 #define RTF_ADDRCLASSMASK	0xF8000000
-#define RT_ADDRCLASS(flags)	((uint32_t) flags >> 23)
+#define RT_ADDRCLASS(flags)	((__uint32_t) flags >> 23)
 
 #define RT_TOS(tos)		((tos) & IPTOS_TOS_MASK)
 
diff --git a/sysdeps/unix/sysv/linux/netatalk/at.h b/sysdeps/unix/sysv/linux/netatalk/at.h
index f78d6b8a07..1c6fe6391e 100644
--- a/sysdeps/unix/sysv/linux/netatalk/at.h
+++ b/sysdeps/unix/sysv/linux/netatalk/at.h
@@ -22,8 +22,7 @@
 #include <bits/types.h>
 #include <bits/sockaddr.h>
 
-#include <sys/socket.h>
-#include <sys/ioctl.h>
+#include <sys/ioctl.h> /* for SIOCPROTOPRIVATE */
 
 /* Constants from linux/atalk.h as of kernel version 5.0.  */
 
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 17/25] Don’t include sys/select.h from sys/types.h.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (12 preceding siblings ...)
  2019-06-26 18:26 ` [PATCH 23/25] Don’t include sys/socket.h from public headers Zack Weinberg
@ 2019-06-26 18:26 ` Zack Weinberg
  2019-06-26 19:06 ` [PATCH 24/25] Minimize inclusion of netinet/in.h from public headers Zack Weinberg
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:26 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

This is supposedly present for BSD compatibility, but the current
generation of BSDs is not consistent about it: FreeBSD does, OpenBSD
doesn’t, NetBSD exposes only fd_set and the FD_* macros.  Programs
that need to wait for any of multiple I/O events have several
alternatives to select nowadays, so I think it makes sense to expose
select only to programs that specifically want it.

Only a few places within our own code are affected.  A few test
programs need to include sys/select.h explicitly, as does rpc/svc.h.
sysdeps/nptl/thread_db.h needs to declare sigset_t, and
sysdeps/unix/sysv/linux/pselect.c was including sys/poll.h instead of
sys/select.h, which is probably a copy-and-paste error.  sys/socket.h
needs to forward-declare struct timespec under __USE_GNU, because
recvmmsg has a struct timespec * argument; I’m open to the possibility
of having it fully declare struct timespec.

I considered taking sys/select.h out of sys/time.h as well, but POSIX
not only explicitly allows this inclusion, it requires sys/time.h to
declare almost everything that sys/select.h declares.  It doesn’t seem
worth creating another bits header just to prevent sys/time.h from
declaring pselect, sigset_t, and struct timespec.

Not including sys/select.h from sys/types.h means that sys/types.h
also no longer defines anything from sys/time.h, and a couple of files
were relying on that.  (pthread_join_common.c should be using
clock_gettime instead of gettimeofday, but that's out of scope for
this patch series.)

	* posix/sys/types.h: Don’t include sys/select.h.
	* scripts/check-obsolete-constructs.py: Remove whitelist entry
	for sys/types.h -> sys/select.h.  Adjust commentary re
	sys/time.h -> sys/select.h.

	* socket/sys/socket.h: When __USE_GNU, forward-declare struct timespec.
	* misc/tst-fdset.c, nptl/tst-cancel4.c, scripts/check-c++-types.sh
	* sunrpc/rpc/svc.h: Include sys/select.h.
	* sysdeps/nptl/thread_db.h: Include bits/types/sigset_t.h.
	* sysdeps/unix/sysv/linux/pselect.c: Include sys/select.h,
	not sys/poll.h.
	* nptl/pthread_join_common.c, sysdeps/unix/sysv/linux/dl-vdso.h:
	Include sys/time.h.
---
 misc/tst-fdset.c                     | 2 +-
 nptl/pthread_join_common.c           | 2 ++
 nptl/tst-cancel4.c                   | 1 +
 posix/sys/types.h                    | 3 ---
 scripts/check-c++-types.sh           | 1 +
 scripts/check-obsolete-constructs.py | 6 +++---
 socket/sys/socket.h                  | 4 ++++
 sunrpc/rpc/svc.h                     | 1 +
 sysdeps/nptl/thread_db.h             | 2 +-
 sysdeps/unix/sysv/linux/dl-vdso.h    | 6 ++++++
 sysdeps/unix/sysv/linux/pselect.c    | 2 +-
 11 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/misc/tst-fdset.c b/misc/tst-fdset.c
index 70b7028dad..956e371746 100644
--- a/misc/tst-fdset.c
+++ b/misc/tst-fdset.c
@@ -18,7 +18,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
-#include <sys/types.h>
+#include <sys/select.h>
 
 static int
 do_test (void)
diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
index 5224ee2110..b8b016ccb7 100644
--- a/nptl/pthread_join_common.c
+++ b/nptl/pthread_join_common.c
@@ -20,6 +20,8 @@
 #include <atomic.h>
 #include <stap-probe.h>
 
+#include <sys/time.h>
+
 static void
 cleanup (void *arg)
 {
diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c
index 60a965d23a..dce93dc03a 100644
--- a/nptl/tst-cancel4.c
+++ b/nptl/tst-cancel4.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/ipc.h>
diff --git a/posix/sys/types.h b/posix/sys/types.h
index 08305cf812..9381695548 100644
--- a/posix/sys/types.h
+++ b/posix/sys/types.h
@@ -93,9 +93,6 @@ __BEGIN_DECLS
 
 /* In BSD <sys/types.h> is expected to define BYTE_ORDER.  */
 # include <endian.h>
-
-/* It also defines `fd_set' and the FD_* macros for `select'.  */
-# include <sys/select.h>
 #endif /* Use misc.  */
 
 __END_DECLS
diff --git a/scripts/check-c++-types.sh b/scripts/check-c++-types.sh
index a8f3cfff7b..141ddf7440 100755
--- a/scripts/check-c++-types.sh
+++ b/scripts/check-c++-types.sh
@@ -46,6 +46,7 @@ while read t; do
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/resource.h>
+#include <sys/select.h>
 #include <unistd.h>
 void foo ($t) { }
 EOF
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index bd5a97f76b..a051d4e845 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -530,13 +530,13 @@ HEADER_ALLOWED_INCLUDES = {
     # mandated: sys/msg.h -> sys/ipc.h
     #           sys/sem.h -> sys/ipc.h
     #           sys/shm.h -> sys/ipc.h
-    # allowed:  sys/time.h -> sys/select.h
-    #           sys/wait.h -> signal.h
+    #           sys/time.h -> sys/select.h (effectively)
+    # allowed:  sys/wait.h -> signal.h
     "sys/msg.h":                   [ "sys/ipc.h" ],
     "sys/sem.h":                   [ "sys/ipc.h" ],
     "sys/shm.h":                   [ "sys/ipc.h" ],
     "sys/time.h":                  [ "sys/select.h" ],
-    "sys/types.h":                 [ "endian.h", "sys/select.h" ],
+    "sys/types.h":                 [ "endian.h" ],
     "sys/uio.h":                   [ "sys/types.h" ],
     "sys/un.h":                    [ "string.h" ],
     "sys/wait.h":                  [ "signal.h" ],
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index 1bb90ed67c..ce793dc3e2 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -35,6 +35,10 @@ __BEGIN_DECLS
 # include <bits/types/struct_osockaddr.h>
 #endif
 
+#ifdef __USE_GNU
+struct timespec;
+#endif
+
 /* The following constants should be used for the second parameter of
    `shutdown'.  */
 enum
diff --git a/sunrpc/rpc/svc.h b/sunrpc/rpc/svc.h
index 85d0183d48..c77dcf0c4a 100644
--- a/sunrpc/rpc/svc.h
+++ b/sunrpc/rpc/svc.h
@@ -53,6 +53,7 @@
 
 #include <features.h>
 #include <rpc/rpc_msg.h>
+#include <sys/select.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/nptl/thread_db.h b/sysdeps/nptl/thread_db.h
index d134acaa24..4d949b0c37 100644
--- a/sysdeps/nptl/thread_db.h
+++ b/sysdeps/nptl/thread_db.h
@@ -26,7 +26,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/procfs.h>
-
+#include <bits/types/sigset_t.h>
 
 /* Error codes of the library.  */
 typedef enum
diff --git a/sysdeps/unix/sysv/linux/dl-vdso.h b/sysdeps/unix/sysv/linux/dl-vdso.h
index 9e61ca7423..edecf5faf4 100644
--- a/sysdeps/unix/sysv/linux/dl-vdso.h
+++ b/sysdeps/unix/sysv/linux/dl-vdso.h
@@ -23,6 +23,12 @@
 #include <ldsodefs.h>
 #include <dl-hash.h>
 
+/* This header must declare all functions that might be looked up
+   in the vDSO by code fragments generated by make-syscalls.sh.
+   At present the only such function that isn't covered by the above
+   headers is gettimeofday.  */
+#include <sys/time.h>
+
 /* Create version number record for lookup.  */
 #define PREPARE_VERSION(var, vname, vhash) \
   struct r_found_version var;						      \
diff --git a/sysdeps/unix/sysv/linux/pselect.c b/sysdeps/unix/sysv/linux/pselect.c
index c9406cac09..d1106e9b18 100644
--- a/sysdeps/unix/sysv/linux/pselect.c
+++ b/sysdeps/unix/sysv/linux/pselect.c
@@ -19,7 +19,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <time.h>
-#include <sys/poll.h>
+#include <sys/select.h>
 #include <kernel-features.h>
 #include <sysdep-cancel.h>
 
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 21/25] Don’t include sys/types.h or stdint.h from most public headers.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (9 preceding siblings ...)
  2019-06-26 18:06 ` [PATCH 19/25] Don’t include string.h from sys/un.h Zack Weinberg
@ 2019-06-26 18:26 ` Zack Weinberg
  2019-06-26 18:26 ` [PATCH 18/25] Don’t include signal.h from sys/wait.h or sys/param.h Zack Weinberg
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 18:26 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

Many public headers include sys/types.h and/or stdint.h when they only
need and/or are supposed to define a small number of types from that
header.  This patch changes as many of them as practical to include
only the single-type headers for the types they are actually specified
to define, and use the impl-namespace aliases for any types they need
but are not specified to define.  In most cases, where a header has
historically used uintN_t types, I changed it to use __uintN_t types;
in a few cases I chose to have it continue to define the complete set
of those types (using <bits/stdint-uintn.h>).

After this patch, the public headers that still include sys/types.h are:
stdlib.h and sys/param.h, where removal would risk breaking far too much;
the inclusion of sys/types.h; regex.h, which is taken verbatim from
gnulib and can't include features.h directly (I'm open to better ideas);
sys/bitypes.h, which is an alternative name for sys/types.h; and
the networking headers, which will be dealt with separately.  The headers
that still include stdint.h are: inttypes.h, as required by ISO C;
elf.h and thread_db.h, see discussion of debugger interface headers below;
and, again, the networking headers will be dealt with separately.

While I was at it, I moved headers out of sysdeps where possible: If
we have only a sysdeps/generic/something.h or sysdeps/gnu/something.h,
no other sysdeps variants, it is not really system-dependent and can
be moved to the directory that installs it.  If we have both
sysdeps/generic/ and gnu/something.h, the generic version is never
used (since we support only GNUish systems these days) and can be
deleted, and the gnu-version can be moved to the directory that
installs it.  If the only copy of a bits header is in the
top-level bits directory, it is not system-dependent.

For utmp.h and utmpx.h, I think we might be able to fold their
respective bits headers into the primary headers and make them not
system-dependent at all.  The remaining variation is between
s390*-*-linux* and everything else, and it appears to me that the s390
versions of the bits headers are actually the headers that everyone
should be using.  The only difference is that the s390 headers
unconditionally use 64-bit quantities for lastlog.ll_time,
utmp{,x}.ut_tv, and utmp{,x}.ut_session, whereas the generic headers
use either 64- or 32-bit quantities depending on
__WORDSIZE_TIME64_COMPAT32.  I could be wrong, but I don’t think it
makes sense for programs with 64-bit and 32-bit time_t to have
different ideas of the layout of a structures that are copied directly
to and from a shared file on disk.  But fixing that doesn’t belong in
this patch series.

The conform tests expect utmpx.h to define time_t and suseconds_t.
These are the public names for the types of the fields of struct
timeval, and utmpx.h is required to define struct timeval, so this is
a reasonable expectation even though POSIX doesn't _explicitly_ say
it's also required to define time_t and suseconds_t.  utmp.h is not a
standard header but it makes sense for it to be as consistent with
utmpx.h as possible, especially in our implementation where
/var/log/utmp and /var/log/utmpx have the same format.

I thought I was going to need to change all of the arch-specific
bits/epoll.h headers as well as sys/epoll.h, but it turned out not to
be necessary.  I still took the opportunity to give them all multiple
inclusion guards.

I suspect we do not need as many copies of bits/fcntl.h and bits/sem.h
as we have, but that’s complicated enough that it deserves its own patchset.

The debugger interface headers are a mess and I only have so much
patience for them.  This does the bare minimum required for
thread_db.h, sys/procfs.h, and sys/user.h, which are at least
nominally cross-platform interfaces, to avoid including sys/types.h,
sys/time.h, and/or signal.h.  Exposure of sys/ucontext.h is reduced
but not eliminated.  Cross-architecture consistency should be improved.
It would be desirable to stop including stdint.h from elf.h and
thread_db.h as well, but that would involve touching dozens more
bits headers and I ran out of patience.

Git does not understand “remove file X and then rename file Y over the
top of it” very well, so the diff looks bigger than it should.

This is another partial fix for Hurd-specific bug 23088.  The headers
that are still affected by that bug are aio.h, mqueue.h, regex.h,
signal.h, stdlib.h, and sys/types.h.

	* io/ftw.h: Don't include sys/types.h.
	* misc/sys/uio.h: Don't include sys/types.h.
	Include bits/types.h, bits/types/size_t.h, and bits/types/ssize_t.h.
	* posix/spawn.h: Don't include sys/types.h.
	Include bits/types.h, bits/types/mode_t.h, and bits/types/pid_t.h.
	* rt/aio.h: Don't include sys/types.h.
	Include bits/types.h, bits/pthreadtypes.h,
	bits/types/size_t.h, and bits/types/ssize_t.h.
	* sysdeps/pthread/semaphore.h: Don't include sys/types.h.
	* sysdeps/unix/sysv/linux/bits/uio-ext.h: Use __pid_t, not pid_t.

	* sysdeps/generic/netinet/in_systm.h: Rename to
	inet/netinet/in_systm.h.  Include bits/stdint-uintn.h,
	not sys/types.h or stdint.h.
	* sysdeps/generic/netinet/ip.h: Rename to
	inet/netinet/ip.h.  Include bits/stdint-uintn.h and
	bits/endian.h, not sys/types.h.
	* sysdeps/gnu/netinet/tcp.h: Rename to
	inet/netinet/tcp.h. Include bits/stdint-uintn.h and
	bits/endian.h, not sys/types.h or stdint.h.
	* sydeps/gnu/net/if.h: Rename to socket/net/if.h.
	Don’t include sys/types.h.

	* include/net/if.h: Include socket/net/if.h, rather than
	whatever the next net/if.h on the include path is.
	* include/netinet/in_systm.h, include/netinet/ip.h
	* include/netinet/tcp.h: New trivial wrappers.

	* sysdeps/generic/net/if.h: Delete, never used.
	* sysdeps/generic/netinet/tcp.h: Delete, never used.

	* bits/utmp.h: Delete file.
        * sysdeps/gnu/bits/utmp.h: Move to bits/utmp.h.
        Add multiple include guard.
        Don’t include paths.h, sys/time.h, or sys/types.h.
        Don’t use struct timeval.
        Use __intN_t for consistency with bits/utmpx.h.
        * sysdeps/unix/sysv/linux/s390/bits/utmp.h: Add multiple include guard.
        Don’t include paths.h, sys/time.h, sys/types.h, or bits/wordsize.h.
        Don’t use struct timeval.
        Use __intN_t for consistency with bits/utmpx.h.
        Use __time64_t unconditionally for lastlog.ll_time.
        Use __int64_t unconditionally for utmp.ut_session.
        Adjust indentation and blank lines to match bits/utmp.h.

        * sysdeps/gnu/bits/utmpx.h: Move to bits/utmpx.h.
        Add multiple include guard.
        Don’t include paths.h, sys/time.h, bits/types.h, or bits/wordsize.h.
        Don’t define _PATH_UTMPX or _PATH_WTMPX.
        Don’t use struct timeval.
        Use pid_t for consistency with bits/utmp.h.
        * sysdeps/unix/sysv/linux/s390/bits/utmpx.h: Add multiple include guard.
        Don’t define _PATH_UTMPX or _PATH_WTMPX.
        Don’t include paths.h, sys/time.h, bits/types.h, or bits/wordsize.h.
        Don’t define _PATH_UTMPX or _PATH_WTMPX.
        Don’t use struct timeval.
        Use pid_t for consistency with bits/utmp.h.
        Use __int64_t unconditionally for utmpx.ut_session.

        * login/utmp.h: Don’t include sys/types.h.
        Do include paths.h, bits/types.h, bits/types/pid_t.h,
        bits/types/suseconds_t, bits/types/time_t.h, and
        bits/types/struct_timeval.h.
        Move __BEGIN_DECLS to enclose only prototypes.

        * sysdeps/gnu/utmpx.h: Move to login/utmpx.h.
        Don’t include sys/time.h.  Do include bits/types.h,
        bits/types/suseconds_t, bits/types/time_t.h, and
        bits/types/struct_timeval.h.
        When __USE_GNU, include paths.h and define _PATH_UTMPX and _PATH_WTMPX.

        * login/Makefile (headers): Add utmpx.h and bits/utmpx.h.
        (routines): Add endutxent, getutmp, getutmpx, getutxent,
        getutxid, getutxline, pututxline, setutxent, updwtmpx, and
        utmpxname.  Reorganize.
        * sysdeps/gnu/Makefile: Do not add anything to sysdep_routines
        or sysdep_headers when subdir == login.

	* sysdeps/gnu/sys/mtio.h: Move to misc/sys/mtio.h.
	Don't include sys/types.h.
	* sysdeps/gnu/Makefile: Don't add anything to sysdep_headers
	for the misc directory.
	* misc/Makefile (headers): Add sys/mtio.h.
	* include/sys/mtio.h: New wrapper.

	* elf/link.h, inet/aliases.h, misc/sys/xattr.h:
	Don't include sys/types.h.  Include bits/types/size_t.h.

	* gmon/sys/gmon.h: Don't include sys/types.h.
	* gmon/sys/profil.h: Don't include sys/types.h.
	Include bits/types/size_t.h and bits/types/struct_timeval.h.
	* io/fts.h: Don't include sys/types.h.
	Include bits/types/dev_t.h, bits/types/ino_t.h, bits/types/ino64_t.h,
	and bits/types/nlink_t.h.
	* io/sys/sendfile.h: Don't include sys/types.h.
	Include bits/types.h, bits/types/off_t.h, bits/types/size_t.h,
	and bits/types/ssize_t.h.
	* stdlib/sys/random.h: Don't include sys/types.h.
	Include bits/types/size_t.h and bits/types/ssize_t.h.

	* gmon/tst-sprofil.h: Include sys/time.h.
	* sysdeps/mach/hurd/sendfile.c: Include sys/types.h.

	* sysdeps/unix/sysv/linux/sys/epoll.h: Don’t include stdint.h
	or sys/types.h.  Do include features.h and bits/types.h.
	(union epoll_data, struct epoll_event): Use __uint32_t and
	__uint64_t for field types.

	* sysdeps/unix/sysv/linux/alpha/bits/epoll.h
	* sysdeps/unix/sysv/linux/bits/epoll.h
	* sysdeps/unix/sysv/linux/hppa/bits/epoll.h
	* sysdeps/unix/sysv/linux/mips/bits/epoll.h
	* sysdeps/unix/sysv/linux/sparc/bits/epoll.h
	* sysdeps/unix/sysv/linux/x86/bits/epoll.h:
	Add multiple inclusion guard.

	* sysdeps/unix/sysv/linux/alpha/sys/acct.h: Style fix.
	* sysdeps/unix/sysv/linux/sys/acct.h: Include features.h
	and bits/stdint-uintn.h.  Don't include sys/types.h, stdint.h,
	or bits/types/time_t.h.

	* sysdeps/unix/sysv/linux/sys/fsuid.h
	* sysdeps/unix/sysv/linux/sys/quota.h
	Include bits/types.h, not sys/types.h.

	* sysdeps/nptl/sys/procfs.h: Include features.h and bits/types.h,
	not sys/types.h.
	* sysdeps/nptl/thread_db.h: Don’t include sys/types.h.
	* sysdeps/nptl/proc_service.h: Include bits/types/pid_t.h and
	bits/types/size_t.h.

	* sysdeps/unix/sysv/linux/sys/procfs.h: Include bits/types.h and
	bits/types/struct_timeval.h, not sys/time.h or sys/types.h.

	* sysdeps/unix/sysv/linux/aarch64/bits/procfs.h: Add multiple
	inclusion guard.  Include bits/types.h.  Correct a comment.

	* sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h:
	Add multiple inclusion guard.  Include sys/ucontext.h.

	* sysdeps/unix/sysv/linux/alpha/bits/procfs.h
	* sysdeps/unix/sysv/linux/sparc/bits/procfs.h
	Add multiple inclusion guard.  Don’t include signal.h or sys/ucontext.h.
	* sysdeps/unix/sysv/linux/ia64/bits/procfs.h:
        Add multiple inclusion guard.  Include sys/ucontext.h, not signal.h.
	* sysdeps/unix/sysv/linux/powerpc/bits/procfs.h:
        Add multiple inclusion guard.  Don’t include signal.h or
	sys/ucontext.h.  Include bits/wordsize.h and asm/elf.h.
	Adjust conditional for whether to provide various fallback
	definitions.

	* sysdeps/unix/sysv/linux/arm/bits/procfs.h
	* sysdeps/unix/sysv/linux/csky/bits/procfs.h
	* sysdeps/unix/sysv/linux/hppa/bits/procfs.h
	* sysdeps/unix/sysv/linux/m68k/bits/procfs.h
	* sysdeps/unix/sysv/linux/microblaze/bits/procfs.h
	* sysdeps/unix/sysv/linux/mips/bits/procfs.h
	* sysdeps/unix/sysv/linux/nios2/bits/procfs.h
	* sysdeps/unix/sysv/linux/riscv/bits/procfs.h
	* sysdeps/unix/sysv/linux/s390/bits/procfs.h
	* sysdeps/unix/sysv/linux/sh/bits/procfs.h
	* sysdeps/unix/sysv/linux/x86/bits/procfs.h:
        Add multiple inclusion guard.  Improve commentary.

	* sysdeps/posix/dl-fileid.h (r_file_id): Use __dev_t and __ino64_t
	for field types.

	* nss/nss.h
	* sysdeps/powerpc/sys/platform/ppc.h
	* sysdeps/unix/sysv/linux/sys/eventfd.h
	* sysdeps/unix/sysv/linux/sys/fanotify.h
	* sysdeps/unix/sysv/linux/sys/inotify.h
	* sysdeps/unix/sysv/linux/sys/raw.h
	* sysdeps/unix/sysv/linux/sys/signalfd.h:
	Include bits/types.h, not stdint.h.
	Include features.h where not already doing so.
	Use __(u)intN_t types instead of (u)intN_t types in all
	declarations.

	* sysdeps/unix/sysv/linux/powerpc/bits/powerpc.h:
	Use __uint64_t instead of uint64_t.
	* nss/tst-nss-test4.c: Include stdint.h.

	* bits/fcntl.h: Add multiple include guard.  Hoist inclusion of
	bits/types.h to top of file.
	* sysdeps/mach/hurd/bits/fcntl.h: Add multiple include guard.
	Include bits/types.h, not sys/types.h; remove redundant inclusion
	of bits/types.h in middle of file.

	* bits/sem.h: Add multiple include guard.  Include bits/types.h,
	not sys/types.h.
	* sysdeps/gnu/bits/sem.h: Likewise.
	* sysdeps/unix/sysv/linux/bits/sem.h: Likewise.
	* sysdeps/unix/sysv/linux/ia64/bits/ipc.h: Likewise.
	* sysvipc/sys/sem.h: Include bits/types/pid_t.h and
	bits/types/time_t.h.

	* resolv/bits/types/res_state.h: Include bits/types.h, not
	sys/types.h.  Use __uint32_t and __uint16_t, not uint32_t and
	uint16_t.

	* sysdeps/mach/hurd/bits/socket.h: Include bits/types.h, not
	sys/types.h.
	* sysdeps/unix/sysv/linux/bits/socket.h: Likewise.  Use __pid_t,
	__uid_t, and __gid_t, not pid_t, uid_t, and gid_t.
	* socket/sys/socket.h: Include bits/types.h, bits/types/ssize_t.h,
	and bits/types/socklen_t.h.
	* inet/htonl.c, include/htons.c: Include endian.h.
	* include/netinet/ether.h: Include bits/types/size_t.h.

	* scripts/check-obsolete-constructs.py
	(HEADER_ALLOWED_INCLUDES, SYSDEP_ALLOWED_INCLUDES): Update.

	* sysdeps/mach/hurd/i386/Makefile: Update list of xfails for
        bug 23088.
---
 bits/fcntl.h                                  |   9 +-
 bits/sem.h                                    |   7 +-
 {sysdeps/gnu/bits => bits}/utmp.h             |  32 ++++--
 {sysdeps/gnu/bits => bits}/utmpx.h            |  35 +++---
 elf/link.h                                    |   2 +-
 gmon/sys/gmon.h                               |   2 -
 gmon/sys/profil.h                             |   4 +-
 gmon/tst-sprofil.c                            |   1 +
 include/net/if.h                              |   2 +-
 include/netinet/ether.h                       |   1 +
 include/netinet/in_systm.h                    |   1 +
 include/netinet/ip.h                          |   1 +
 include/netinet/tcp.h                         |   1 +
 include/sys/mtio.h                            |   1 +
 include/utmpx.h                               |   1 +
 inet/aliases.h                                |   4 +-
 inet/htonl.c                                  |   3 +-
 inet/htons.c                                  |   2 +
 {sysdeps/generic => inet}/netinet/in_systm.h  |   3 +-
 {sysdeps/generic => inet}/netinet/ip.h        |   3 +-
 {sysdeps/gnu => inet}/netinet/tcp.h           |   4 +-
 io/fts.h                                      |   5 +-
 io/ftw.h                                      |   1 -
 io/sys/sendfile.h                             |   6 +-
 login/Makefile                                |  13 ++-
 login/utmp.h                                  |  15 ++-
 {sysdeps/gnu => login}/utmpx.h                |   9 +-
 misc/Makefile                                 |   6 +-
 {sysdeps/gnu => misc}/sys/mtio.h              |   3 -
 misc/sys/uio.h                                |   5 +-
 misc/sys/xattr.h                              |   3 +-
 nss/nss.h                                     |   6 +-
 nss/tst-nss-test4.c                           |   1 +
 posix/spawn.h                                 |   5 +-
 resolv/bits/types/res_state.h                 |  12 +-
 rt/aio.h                                      |   7 +-
 rt/mqueue.h                                   |   8 +-
 scripts/check-obsolete-constructs.py          |  62 +++-------
 {sysdeps/gnu => socket}/net/if.h              |   8 +-
 socket/sys/socket.h                           |   3 +
 stdlib/sys/random.h                           |   4 +-
 sysdeps/generic/net/if.h                      |  49 --------
 sysdeps/generic/netinet/tcp.h                 | 107 ------------------
 sysdeps/gnu/Makefile                          |  12 --
 sysdeps/gnu/bits/sem.h                        |   7 +-
 sysdeps/mach/hurd/bits/fcntl.h                |  11 +-
 sysdeps/mach/hurd/bits/socket.h               |   2 +-
 sysdeps/mach/hurd/i386/Makefile               |  35 ------
 sysdeps/mach/hurd/sendfile.c                  |   1 +
 sysdeps/nptl/proc_service.h                   |   3 +
 sysdeps/nptl/sys/procfs.h                     |   3 +-
 sysdeps/nptl/thread_db.h                      |   1 -
 sysdeps/posix/dl-fileid.h                     |   4 +-
 sysdeps/powerpc/sys/platform/ppc.h            |  10 +-
 sysdeps/pthread/semaphore.h                   |   2 +-
 sysdeps/unix/sysv/linux/aarch64/bits/procfs.h |  13 ++-
 sysdeps/unix/sysv/linux/alpha/bits/epoll.h    |   5 +
 .../sysv/linux/alpha/bits/procfs-prregset.h   |   9 ++
 sysdeps/unix/sysv/linux/alpha/bits/procfs.h   |   8 +-
 sysdeps/unix/sysv/linux/alpha/sys/acct.h      |   2 +-
 sysdeps/unix/sysv/linux/arm/bits/procfs.h     |   9 +-
 sysdeps/unix/sysv/linux/bits/epoll.h          |   5 +
 sysdeps/unix/sysv/linux/bits/sem.h            |   7 +-
 sysdeps/unix/sysv/linux/bits/socket.h         |   8 +-
 sysdeps/unix/sysv/linux/bits/uio-ext.h        |   4 +-
 sysdeps/unix/sysv/linux/csky/bits/procfs.h    |   5 +
 sysdeps/unix/sysv/linux/hppa/bits/epoll.h     |   5 +
 sysdeps/unix/sysv/linux/hppa/bits/procfs.h    |   5 +
 sysdeps/unix/sysv/linux/ia64/bits/ipc.h       |   2 +-
 sysdeps/unix/sysv/linux/ia64/bits/procfs.h    |   8 +-
 sysdeps/unix/sysv/linux/m68k/bits/procfs.h    |   9 +-
 .../unix/sysv/linux/microblaze/bits/procfs.h  |   9 +-
 sysdeps/unix/sysv/linux/microblaze/sys/user.h |   4 +-
 sysdeps/unix/sysv/linux/mips/bits/epoll.h     |   5 +
 sysdeps/unix/sysv/linux/mips/bits/procfs.h    |   5 +
 sysdeps/unix/sysv/linux/nios2/bits/procfs.h   |   5 +
 sysdeps/unix/sysv/linux/powerpc/bits/ppc.h    |   2 +-
 sysdeps/unix/sysv/linux/powerpc/bits/procfs.h |  20 ++--
 sysdeps/unix/sysv/linux/powerpc/sys/user.h    |   1 +
 sysdeps/unix/sysv/linux/riscv/bits/procfs.h   |   8 ++
 sysdeps/unix/sysv/linux/s390/bits/procfs.h    |   7 ++
 .../{gnu => unix/sysv/linux/s390}/bits/utmp.h |  37 +++---
 sysdeps/unix/sysv/linux/s390/bits/utmpx.h     |  34 ++----
 sysdeps/unix/sysv/linux/sh/bits/procfs.h      |   5 +
 sysdeps/unix/sysv/linux/sparc/bits/epoll.h    |   5 +
 sysdeps/unix/sysv/linux/sparc/bits/procfs.h   |   7 +-
 sysdeps/unix/sysv/linux/sys/acct.h            |   6 +-
 sysdeps/unix/sysv/linux/sys/epoll.h           |  10 +-
 sysdeps/unix/sysv/linux/sys/eventfd.h         |   5 +-
 sysdeps/unix/sysv/linux/sys/fanotify.h        |   6 +-
 sysdeps/unix/sysv/linux/sys/fsuid.h           |   2 +-
 sysdeps/unix/sysv/linux/sys/inotify.h         |  11 +-
 sysdeps/unix/sysv/linux/sys/procfs.h          |   6 +-
 sysdeps/unix/sysv/linux/sys/quota.h           |   2 +-
 sysdeps/unix/sysv/linux/sys/raw.h             |   7 +-
 sysdeps/unix/sysv/linux/sys/signalfd.h        |  47 ++++----
 sysdeps/unix/sysv/linux/x86/bits/epoll.h      |   5 +
 sysdeps/unix/sysv/linux/x86/bits/procfs.h     |   5 +
 sysvipc/sys/sem.h                             |   2 +
 99 files changed, 443 insertions(+), 477 deletions(-)
 copy {sysdeps/gnu/bits => bits}/utmp.h (83%)
 rename {sysdeps/gnu/bits => bits}/utmpx.h (82%)
 create mode 100644 include/netinet/in_systm.h
 create mode 100644 include/netinet/ip.h
 create mode 100644 include/netinet/tcp.h
 create mode 100644 include/sys/mtio.h
 create mode 100644 include/utmpx.h
 rename {sysdeps/generic => inet}/netinet/in_systm.h (97%)
 rename {sysdeps/generic => inet}/netinet/ip.h (99%)
 rename {sysdeps/gnu => inet}/netinet/tcp.h (99%)
 rename {sysdeps/gnu => login}/utmpx.h (94%)
 rename {sysdeps/gnu => misc}/sys/mtio.h (99%)
 rename {sysdeps/gnu => socket}/net/if.h (98%)
 delete mode 100644 sysdeps/generic/net/if.h
 delete mode 100644 sysdeps/generic/netinet/tcp.h
 rename sysdeps/{gnu => unix/sysv/linux/s390}/bits/utmp.h (83%)

diff --git a/bits/fcntl.h b/bits/fcntl.h
index 8bb1357684..c69869f1c4 100644
--- a/bits/fcntl.h
+++ b/bits/fcntl.h
@@ -16,10 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_FCNTL_H
+#define _BITS_FCNTL_H 1
+
 #ifndef	_FCNTL_H
 #error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#include <bits/types.h>
 
 /* File access modes for `open' and `fcntl'.  */
 #define	O_RDONLY	0	/* Open read-only.  */
@@ -104,9 +108,6 @@
 /* File descriptor flags used with F_GETFD and F_SETFD.  */
 #define	FD_CLOEXEC	1	/* Close on exec.  */
 
-
-#include <bits/types.h>
-
 /* The structure describing an advisory lock.  This is the type of the third
    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
 struct flock
@@ -144,3 +145,5 @@ struct flock64
 # define POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+
+#endif
diff --git a/bits/sem.h b/bits/sem.h
index 02754c7e58..6eed74c12e 100644
--- a/bits/sem.h
+++ b/bits/sem.h
@@ -15,11 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_SEM_H
+#define _BITS_SEM_H 1
+
 #ifndef _SYS_SEM_H
 # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Flags for `semop'.  */
 #define SEM_UNDO	0x1000		/* undo the operation on exit */
@@ -58,3 +61,5 @@ struct semid_ds
    incorrect.  One can test the macro _SEM_SEMUN_UNDEFINED to see whether
    one must define the union or not.  */
 #define _SEM_SEMUN_UNDEFINED	1
+
+#endif /* bits/sem.h */
diff --git a/sysdeps/gnu/bits/utmp.h b/bits/utmp.h
similarity index 83%
copy from sysdeps/gnu/bits/utmp.h
copy to bits/utmp.h
index 7357034cb6..3d593e0c0a 100644
--- a/sysdeps/gnu/bits/utmp.h
+++ b/bits/utmp.h
@@ -16,13 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_UTMP_H
+#define _BITS_UTMP_H 1
+
 #ifndef _UTMP_H
 # error "Never include <bits/utmp.h> directly; use <utmp.h> instead."
 #endif
 
-#include <paths.h>
-#include <sys/time.h>
-#include <sys/types.h>
 #include <bits/wordsize.h>
 
 
@@ -36,7 +36,7 @@
 struct lastlog
   {
 #if __WORDSIZE_TIME64_COMPAT32
-    int32_t ll_time;
+    __int32_t ll_time;
 #else
     __time_t ll_time;
 #endif
@@ -68,23 +68,29 @@ struct utmp
     __attribute_nonstring__;	/* Hostname for remote login.  */
   struct exit_status ut_exit;	/* Exit status of a process marked
 				   as DEAD_PROCESS.  */
+
 /* The ut_session and ut_tv fields must be the same size when compiled
    32- and 64-bit.  This allows data files and shared memory to be
-   shared between 32- and 64-bit applications.  */
+   shared between 32- and 64-bit applications.  Even on 64-bit systems,
+   struct timeval is not guaranteed to have both fields be 64 bits.  */
 #if __WORDSIZE_TIME64_COMPAT32
-  int32_t ut_session;		/* Session ID, used for windowing.  */
+  __int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
-    int32_t tv_sec;		/* Seconds.  */
-    int32_t tv_usec;		/* Microseconds.  */
+    __int32_t tv_sec;		/* Seconds.  */
+    __int32_t tv_usec;		/* Microseconds.  */
   } ut_tv;			/* Time entry was made.  */
 #else
-  long int ut_session;		/* Session ID, used for windowing.  */
-  struct timeval ut_tv;		/* Time entry was made.  */
+  __int64_t ut_session;		/* Session ID, used for windowing.  */
+  struct
+  {
+    __int64_t tv_sec;		/* Seconds.  */
+    __int64_t tv_usec;		/* Microseconds.  */
+  } ut_tv;			/* Time entry was made.  */
 #endif
 
-  int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
-  char __glibc_reserved[20];		/* Reserved for future use.  */
+  __int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
+  char __glibc_reserved[20];	/* Reserved for future use.  */
 };
 
 /* Backwards compatibility hacks.  */
@@ -124,3 +130,5 @@ struct utmp
 #define _HAVE_UT_ID	1
 #define _HAVE_UT_TV	1
 #define _HAVE_UT_HOST	1
+
+#endif /* bits/utmp.h */
diff --git a/sysdeps/gnu/bits/utmpx.h b/bits/utmpx.h
similarity index 82%
rename from sysdeps/gnu/bits/utmpx.h
rename to bits/utmpx.h
index 472a7d57d3..ac4a5323fd 100644
--- a/sysdeps/gnu/bits/utmpx.h
+++ b/bits/utmpx.h
@@ -16,22 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_UTMPX_H
+#define _BITS_UTMPX_H 1
+
 #ifndef _UTMPX_H
 # error "Never include <bits/utmpx.h> directly; use <utmpx.h> instead."
 #endif
 
-#include <bits/types.h>
-#include <sys/time.h>
-#include <bits/wordsize.h>
-
-
-#ifdef __USE_GNU
-# include <paths.h>
-# define _PATH_UTMPX	_PATH_UTMP
-# define _PATH_WTMPX	_PATH_WTMP
-#endif
-
-
 #define __UT_LINESIZE	32
 #define __UT_NAMESIZE	32
 #define __UT_HOSTSIZE	256
@@ -55,7 +46,7 @@ struct __exit_status
 struct utmpx
 {
   short int ut_type;		/* Type of login.  */
-  __pid_t ut_pid;		/* Process ID of login process.  */
+  pid_t ut_pid;			/* Process ID of login process.  */
   char ut_line[__UT_LINESIZE];	/* Devicename.  */
   char ut_id[4];		/* Inittab ID. */
   char ut_user[__UT_NAMESIZE];	/* Username.  */
@@ -63,9 +54,10 @@ struct utmpx
   struct __exit_status ut_exit;	/* Exit status of a process marked
 				   as DEAD_PROCESS.  */
 
-/* The fields ut_session and ut_tv must be the same size when compiled
-   32- and 64-bit.  This allows files and shared memory to be shared
-   between 32- and 64-bit applications.  */
+/* The ut_session and ut_tv fields must be the same size when compiled
+   32- and 64-bit.  This allows data files and shared memory to be
+   shared between 32- and 64-bit applications.  Even on 64-bit systems,
+   struct timeval is not guaranteed to have both fields be 64 bits.  */
 #if __WORDSIZE_TIME64_COMPAT32
   __int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
@@ -74,9 +66,14 @@ struct utmpx
     __int32_t tv_usec;		/* Microseconds.  */
   } ut_tv;			/* Time entry was made.  */
 #else
-  long int ut_session;		/* Session ID, used for windowing.  */
-  struct timeval ut_tv;		/* Time entry was made.  */
+  __int64_t ut_session;		/* Session ID, used for windowing.  */
+  struct
+  {
+    __int64_t tv_sec;		/* Seconds.  */
+    __int64_t tv_usec;		/* Microseconds.  */
+  } ut_tv;			/* Time entry was made.  */
 #endif
+
   __int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
   char __glibc_reserved[20];		/* Reserved for future use.  */
 };
@@ -100,3 +97,5 @@ struct utmpx
 #ifdef __USE_GNU
 # define ACCOUNTING	9	/* System accounting.  */
 #endif
+
+#endif /* bits/utmpx.h */
diff --git a/elf/link.h b/elf/link.h
index 7a463bc2bf..7871b9aef8 100644
--- a/elf/link.h
+++ b/elf/link.h
@@ -23,7 +23,6 @@
 #include <features.h>
 #include <elf.h>
 #include <dlfcn.h>
-#include <sys/types.h>
 
 /* We use this macro to refer to ELF types independent of the native wordsize.
    `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'.  */
@@ -31,6 +30,7 @@
 #define _ElfW(e,w,t)	_ElfW_1 (e, w, _##t)
 #define _ElfW_1(e,w,t)	e##w##t
 
+#include <bits/types/size_t.h>
 #include <bits/elfclass.h>		/* Defines __ELF_NATIVE_CLASS.  */
 #include <bits/link.h>
 
diff --git a/gmon/sys/gmon.h b/gmon/sys/gmon.h
index b4cc3b043a..5d7de0fe9b 100644
--- a/gmon/sys/gmon.h
+++ b/gmon/sys/gmon.h
@@ -34,8 +34,6 @@
 
 #include <features.h>
 
-#include <sys/types.h>
-
 /*
  * See gmon_out.h for gmon.out format.
  */
diff --git a/gmon/sys/profil.h b/gmon/sys/profil.h
index ba99ac8634..1122590213 100644
--- a/gmon/sys/profil.h
+++ b/gmon/sys/profil.h
@@ -20,8 +20,8 @@
 
 #include <features.h>
 
-#include <sys/time.h>
-#include <sys/types.h>
+#include <bits/types/size_t.h>
+#include <bits/types/struct_timeval.h>
 
 /* This interface is intended to follow the sprofil() system calls as
    described by the sprofil(2) man page of Irix v6.5, except that:
diff --git a/gmon/tst-sprofil.c b/gmon/tst-sprofil.c
index 3f7f909cba..53de7a624d 100644
--- a/gmon/tst-sprofil.c
+++ b/gmon/tst-sprofil.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/profil.h>
+#include <sys/time.h>
 
 #include <bits/wordsize.h>
 
diff --git a/include/net/if.h b/include/net/if.h
index 6c4cbc96c3..2e7af05ed2 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -1,6 +1,6 @@
 #ifndef _NET_IF_H
 
-# include_next <net/if.h>
+#include <socket/net/if.h>
 
 #ifndef _ISOMAC
 libc_hidden_proto (if_nametoindex)
diff --git a/include/netinet/ether.h b/include/netinet/ether.h
index 8bfe7e03ad..a60aa27240 100644
--- a/include/netinet/ether.h
+++ b/include/netinet/ether.h
@@ -2,6 +2,7 @@
 #include <inet/netinet/ether.h>
 
 # ifndef _ISOMAC
+#  include <bits/types/size_t.h>
 
 libc_hidden_proto (ether_aton_r)
 libc_hidden_proto (ether_ntoa_r)
diff --git a/include/netinet/in_systm.h b/include/netinet/in_systm.h
new file mode 100644
index 0000000000..7634c9b5a0
--- /dev/null
+++ b/include/netinet/in_systm.h
@@ -0,0 +1 @@
+#include <inet/netinet/in_systm.h>
diff --git a/include/netinet/ip.h b/include/netinet/ip.h
new file mode 100644
index 0000000000..da55733e90
--- /dev/null
+++ b/include/netinet/ip.h
@@ -0,0 +1 @@
+#include <inet/netinet/ip.h>
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
new file mode 100644
index 0000000000..edba529813
--- /dev/null
+++ b/include/netinet/tcp.h
@@ -0,0 +1 @@
+#include <inet/netinet/tcp.h>
diff --git a/include/sys/mtio.h b/include/sys/mtio.h
new file mode 100644
index 0000000000..f4861bda70
--- /dev/null
+++ b/include/sys/mtio.h
@@ -0,0 +1 @@
+#include <misc/sys/mtio.h>
diff --git a/include/utmpx.h b/include/utmpx.h
new file mode 100644
index 0000000000..cfe9b7c054
--- /dev/null
+++ b/include/utmpx.h
@@ -0,0 +1 @@
+#include <login/utmpx.h>
diff --git a/inet/aliases.h b/inet/aliases.h
index 67828ca7b6..eebbbc46f2 100644
--- a/inet/aliases.h
+++ b/inet/aliases.h
@@ -19,9 +19,7 @@
 #define _ALIASES_H	1
 
 #include <features.h>
-
-#include <sys/types.h>
-
+#include <bits/types/size_t.h>
 
 __BEGIN_DECLS
 
diff --git a/inet/htonl.c b/inet/htonl.c
index 39acfa6557..bb6b4f5899 100644
--- a/inet/htonl.c
+++ b/inet/htonl.c
@@ -15,8 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <stdint.h>
 #include <netinet/in.h>
+#include <endian.h>
+#include <stdint.h>
 
 #undef	htonl
 #undef	ntohl
diff --git a/inet/htons.c b/inet/htons.c
index 500ca50f49..2b22ca123c 100644
--- a/inet/htons.c
+++ b/inet/htons.c
@@ -16,6 +16,8 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <netinet/in.h>
+#include <endian.h>
+#include <stdint.h>
 
 #undef	htons
 #undef	ntohs
diff --git a/sysdeps/generic/netinet/in_systm.h b/inet/netinet/in_systm.h
similarity index 97%
rename from sysdeps/generic/netinet/in_systm.h
rename to inet/netinet/in_systm.h
index 2b3c74281b..6964aca21a 100644
--- a/sysdeps/generic/netinet/in_systm.h
+++ b/inet/netinet/in_systm.h
@@ -19,8 +19,7 @@
 #ifndef _NETINET_IN_SYSTM_H
 #define _NETINET_IN_SYSTM_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <bits/stdint-uintn.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/generic/netinet/ip.h b/inet/netinet/ip.h
similarity index 99%
rename from sysdeps/generic/netinet/ip.h
rename to inet/netinet/ip.h
index 13b03ff79f..35f61d1694 100644
--- a/sysdeps/generic/netinet/ip.h
+++ b/inet/netinet/ip.h
@@ -19,9 +19,10 @@
 #define __NETINET_IP_H 1
 
 #include <features.h>
-#include <sys/types.h>
 
 #include <netinet/in.h>
+#include <bits/endian.h>
+#include <bits/stdint-uintn.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/gnu/netinet/tcp.h b/inet/netinet/tcp.h
similarity index 99%
rename from sysdeps/gnu/netinet/tcp.h
rename to inet/netinet/tcp.h
index 1a164a9649..7b07accce7 100644
--- a/sysdeps/gnu/netinet/tcp.h
+++ b/inet/netinet/tcp.h
@@ -85,9 +85,9 @@
 #define TCP_REPAIR_OFF_NO_WP	 -1
 
 #ifdef __USE_MISC
-# include <sys/types.h>
+# include <bits/stdint-uintn.h>
+# include <bits/endian.h>
 # include <sys/socket.h>
-# include <stdint.h>
 
 typedef	uint32_t tcp_seq;
 /*
diff --git a/io/fts.h b/io/fts.h
index acfa260f07..0e43b35236 100644
--- a/io/fts.h
+++ b/io/fts.h
@@ -51,8 +51,11 @@
 #define	_FTS_H 1
 
 #include <features.h>
-#include <sys/types.h>
 
+#include <bits/types/dev_t.h>
+#include <bits/types/ino_t.h>
+#include <bits/types/ino64_t.h>
+#include <bits/types/nlink_t.h>
 
 typedef struct {
 	struct _ftsent *fts_cur;	/* current node */
diff --git a/io/ftw.h b/io/ftw.h
index 1ef67f7f3c..ea1d1ee48b 100644
--- a/io/ftw.h
+++ b/io/ftw.h
@@ -24,7 +24,6 @@
 
 #include <features.h>
 
-#include <sys/types.h>
 #include <sys/stat.h>
 
 
diff --git a/io/sys/sendfile.h b/io/sys/sendfile.h
index b21c0857be..d0e8a6777e 100644
--- a/io/sys/sendfile.h
+++ b/io/sys/sendfile.h
@@ -20,7 +20,11 @@
 #define _SYS_SENDFILE_H	1
 
 #include <features.h>
-#include <sys/types.h>
+
+#include <bits/types.h>
+#include <bits/types/off_t.h>
+#include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
 
 __BEGIN_DECLS
 
diff --git a/login/Makefile b/login/Makefile
index 92535f0aec..e9bdd1ad15 100644
--- a/login/Makefile
+++ b/login/Makefile
@@ -23,12 +23,15 @@ subdir	:= login
 
 include ../Makeconfig
 
-headers	:= utmp.h bits/utmp.h lastlog.h pty.h
+headers	:= utmp.h bits/utmp.h utmpx.h bits/utmpx.h lastlog.h pty.h
 
-routines := getlogin getlogin_r setlogin getlogin_r_chk \
-	    getutent getutent_r getutid getutline getutid_r getutline_r \
-	    utmp_file utmpname updwtmp getpt grantpt unlockpt ptsname \
-	    ptsname_r_chk
+routines :=								\
+	getlogin getlogin_r getlogin_r_chk setlogin			\
+	getpt grantpt ptsname ptsname_r_chk unlockpt			\
+	getutent getutent_r getutid getutid_r getutline getutline_r	\
+	getutmp updwtmp utmp_file utmpname				\
+	endutxent getutmpx getutxent getutxid getutxline pututxline	\
+	setutxent updwtmpx utmpxname
 
 CFLAGS-grantpt.c += -DLIBEXECDIR='"$(libexecdir)"'
 
diff --git a/login/utmp.h b/login/utmp.h
index 168c159b7b..9c12e3c915 100644
--- a/login/utmp.h
+++ b/login/utmp.h
@@ -20,21 +20,26 @@
 
 #include <features.h>
 
-#include <sys/types.h>
-
-
-__BEGIN_DECLS
+/* utmp.h is not standardized; utmpx.h is, and is required to define
+   pid_t and struct timeval.  It makes sense for utmp.h to be
+   consistent.  */
+#include <bits/types.h>
+#include <bits/types/pid_t.h>
+#include <bits/types/suseconds_t.h>
+#include <bits/types/time_t.h>
+#include <bits/types/struct_timeval.h>
 
 /* Get system dependent values and data structures.  */
 #include <bits/utmp.h>
 
 /* Compatibility names for the strings of the canonical file names.  */
+#include <paths.h>
 #define UTMP_FILE	_PATH_UTMP
 #define UTMP_FILENAME	_PATH_UTMP
 #define WTMP_FILE	_PATH_WTMP
 #define WTMP_FILENAME	_PATH_WTMP
 
-
+__BEGIN_DECLS
 
 /* Make FD be the controlling terminal, stdin, stdout, and stderr;
    then close FD.  Returns 0 on success, nonzero on error.  */
diff --git a/sysdeps/gnu/utmpx.h b/login/utmpx.h
similarity index 94%
rename from sysdeps/gnu/utmpx.h
rename to login/utmpx.h
index 41c122d970..de18f58e9e 100644
--- a/sysdeps/gnu/utmpx.h
+++ b/login/utmpx.h
@@ -19,15 +19,22 @@
 #define	_UTMPX_H	1
 
 #include <features.h>
-#include <sys/time.h>
 
 /* Required according to Unix98.  */
+#include <bits/types.h>
 #include <bits/types/pid_t.h>
+#include <bits/types/suseconds_t.h>
+#include <bits/types/time_t.h>
+#include <bits/types/struct_timeval.h>
 
 /* Get system dependent values and data structures.  */
 #include <bits/utmpx.h>
 
 #ifdef __USE_GNU
+# include <paths.h>
+# define _PATH_UTMPX	_PATH_UTMP
+# define _PATH_WTMPX	_PATH_WTMP
+
 /* Compatibility names for the strings of the canonical file names.  */
 # define UTMPX_FILE	_PATH_UTMPX
 # define UTMPX_FILENAME	_PATH_UTMPX
diff --git a/misc/Makefile b/misc/Makefile
index e6c73896cd..106ce57776 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -36,9 +36,9 @@ headers :=								\
 	bits/uio-ext.h bits/uio_lim.h bits/xopen_lim.h			\
 	gnu/libc-version.h						\
 	sys/auxv.h sys/cdefs.h sys/dir.h sys/file.h sys/ioctl.h		\
-	sys/mman.h sys/param.h sys/ptrace.h sys/queue.h sys/reboot.h	\
-	sys/select.h sys/swap.h sys/syscall.h sys/sysinfo.h		\
-	sys/syslog.h sys/sysmacros.h sys/uio.h sys/xattr.h
+	sys/mman.h sys/mtio.h sys/param.h sys/ptrace.h sys/queue.h	\
+	sys/reboot.h sys/select.h sys/swap.h sys/syscall.h		\
+	sys/sysinfo.h sys/syslog.h sys/sysmacros.h sys/uio.h sys/xattr.h
 
 routines := brk sbrk sstk ioctl \
 	    readv writev preadv preadv64 pwritev pwritev64 \
diff --git a/sysdeps/gnu/sys/mtio.h b/misc/sys/mtio.h
similarity index 99%
rename from sysdeps/gnu/sys/mtio.h
rename to misc/sys/mtio.h
index 0ce41c58df..1387b13fac 100644
--- a/sysdeps/gnu/sys/mtio.h
+++ b/misc/sys/mtio.h
@@ -21,11 +21,8 @@
 #ifndef _SYS_MTIO_H
 #define _SYS_MTIO_H	1
 
-/* Get necessary definitions from system and kernel headers.  */
-#include <sys/types.h>
 #include <sys/ioctl.h>
 
-
 /* Structure for MTIOCTOP - magnetic tape operation command.  */
 struct mtop
   {
diff --git a/misc/sys/uio.h b/misc/sys/uio.h
index ec1ca4af82..40bedd079a 100644
--- a/misc/sys/uio.h
+++ b/misc/sys/uio.h
@@ -19,7 +19,10 @@
 #define _SYS_UIO_H	1
 
 #include <features.h>
-#include <sys/types.h>
+
+#include <bits/types.h>
+#include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
 #include <bits/types/struct_iovec.h>
 #include <bits/uio_lim.h>
 #ifdef __IOV_MAX
diff --git a/misc/sys/xattr.h b/misc/sys/xattr.h
index f1143f892c..03c7dec9aa 100644
--- a/misc/sys/xattr.h
+++ b/misc/sys/xattr.h
@@ -19,8 +19,9 @@
 #define _SYS_XATTR_H	1
 
 #include <features.h>
-#include <sys/types.h>
 
+#include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
 
 __BEGIN_DECLS
 
diff --git a/nss/nss.h b/nss/nss.h
index 9d4f33e999..0be375259f 100644
--- a/nss/nss.h
+++ b/nss/nss.h
@@ -22,7 +22,7 @@
 #define _NSS_H	1
 
 #include <features.h>
-#include <stdint.h>
+#include <bits/types.h>
 
 
 __BEGIN_DECLS
@@ -44,8 +44,8 @@ struct gaih_addrtuple
     struct gaih_addrtuple *next;
     char *name;
     int family;
-    uint32_t addr[4];
-    uint32_t scopeid;
+    __uint32_t addr[4];
+    __uint32_t scopeid;
   };
 
 
diff --git a/nss/tst-nss-test4.c b/nss/tst-nss-test4.c
index cf6ef46b01..14bea82cb6 100644
--- a/nss/tst-nss-test4.c
+++ b/nss/tst-nss-test4.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #include <support/support.h>
 
diff --git a/posix/spawn.h b/posix/spawn.h
index 471dbea022..2dd75439cb 100644
--- a/posix/spawn.h
+++ b/posix/spawn.h
@@ -21,7 +21,10 @@
 
 #include <features.h>
 #include <sched.h>
-#include <sys/types.h>
+
+#include <bits/types.h>
+#include <bits/types/mode_t.h>
+#include <bits/types/pid_t.h>
 #include <bits/types/sigset_t.h>
 
 
diff --git a/resolv/bits/types/res_state.h b/resolv/bits/types/res_state.h
index 2544a627f6..81febe13b0 100644
--- a/resolv/bits/types/res_state.h
+++ b/resolv/bits/types/res_state.h
@@ -1,7 +1,7 @@
 #ifndef __res_state_defined
 #define __res_state_defined 1
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <netinet/in.h>
 
 /* res_state: the global state used by the resolver stub.  */
@@ -28,7 +28,7 @@ struct __res_state {
 	unsigned unused:23;
 	struct {
 		struct in_addr	addr;
-		uint32_t	mask;
+		__uint32_t	mask;
 	} sort_list[MAXRESOLVSORT];
 	/* 4 byte hole here on 64-bit architectures.  */
 	void * __glibc_unused_qhook;
@@ -40,11 +40,11 @@ struct __res_state {
 	union {
 		char	pad[52];	/* On an i386 this means 512b total. */
 		struct {
-			uint16_t		nscount;
-			uint16_t		nsmap[MAXNS];
+			__uint16_t		nscount;
+			__uint16_t		nsmap[MAXNS];
 			int			nssocks[MAXNS];
-			uint16_t		nscount6;
-			uint16_t		nsinit;
+			__uint16_t		nscount6;
+			__uint16_t		nsinit;
 			struct sockaddr_in6	*nsaddrs[MAXNS];
 #ifdef _LIBC
 			unsigned long long int __glibc_extension_index
diff --git a/rt/aio.h b/rt/aio.h
index d1b97bf0e4..a874e45ac9 100644
--- a/rt/aio.h
+++ b/rt/aio.h
@@ -23,7 +23,12 @@
 #define _AIO_H	1
 
 #include <features.h>
-#include <sys/types.h>
+
+#include <bits/types.h>
+#include <bits/pthreadtypes.h>
+#include <bits/types/off_t.h>
+#include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
 #include <bits/types/sigevent_t.h>
 #include <bits/sigevent-consts.h>
 #include <bits/types/struct_timespec.h>
diff --git a/rt/mqueue.h b/rt/mqueue.h
index 308a52c1bc..dcc786d12d 100644
--- a/rt/mqueue.h
+++ b/rt/mqueue.h
@@ -19,13 +19,19 @@
 #define _MQUEUE_H	1
 
 #include <features.h>
-#include <sys/types.h>
 #include <fcntl.h>
+
+#include <bits/types.h>
+#include <bits/pthreadtypes.h>
 #include <bits/types/sigevent_t.h>
+#include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
 #include <bits/types/struct_timespec.h>
+
 /* Get the definition of mqd_t and struct mq_attr.  */
 #include <bits/mqueue.h>
 
+
 __BEGIN_DECLS
 
 /* Establish connection between a process and a message queue NAME and
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index f456c98def..1ecb7c9823 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -515,16 +515,15 @@ HEADER_ALLOWED_INCLUDES = {
     #           mqueue.h -> fcntl.h
     #           sched.h -> time.h
     #           spawn.h -> sched.h
-    "aio.h":                       [ "sys/types.h" ],
-    "ftw.h":                       [ "sys/stat.h", "sys/types.h" ],
+    "ftw.h":                       [ "sys/stat.h" ],
     "langinfo.h":                  [ "nl_types.h" ],
-    "mqueue.h":                    [ "fcntl.h", "sys/types.h" ],
+    "mqueue.h":                    [ "fcntl.h" ],
     "pthread.h":                   [ "sched.h", "time.h" ],
     "regex.h":                     [ "limits.h", "sys/types.h" ],
     "sched.h":                     [ "time.h" ],
-    "semaphore.h":                 [ "sys/types.h" ],
-    "spawn.h":                     [ "sched.h", "sys/types.h" ],
+    "spawn.h":                     [ "sched.h" ],
     "termios.h":                   [ "sys/ttydefaults.h" ],
+    "utmpx.h":                     [ "paths.h" ],
 
     # POSIX sys/ headers
     # mandated: sys/msg.h -> sys/ipc.h
@@ -538,77 +537,54 @@ HEADER_ALLOWED_INCLUDES = {
     # necessary for backward compatibility with BSD
     "sys/types.h":                 [ "endian.h" ],
 
-    "sys/uio.h":                   [ "sys/types.h" ],
-
     # POSIX networking headers
     # allowed: netdb.h -> netinet/in.h
     #          arpa/inet.h -> netinet/in.h
     "netdb.h":                     [ "netinet/in.h", "rpc/netdb.h" ],
     "arpa/inet.h":                 [ "netinet/in.h" ],
-    "net/if.h":                    [ "sys/socket.h", "sys/types.h" ],
+    "net/if.h":                    [ "sys/socket.h" ],
     "netinet/in.h":                [ "sys/socket.h" ],
-    "netinet/tcp.h":               [ "stdint.h", "sys/socket.h",
-                                     "sys/types.h" ],
+    "netinet/tcp.h":               [ "sys/socket.h" ],
 
     # Nonstandardized top-level headers
-    "aliases.h":                   [ "sys/types.h" ],
     "argp.h":                      [ "ctype.h", "errno.h", "getopt.h",
                                      "limits.h", "stdio.h" ],
     "argz.h":                      [ "errno.h", "string.h" ],
     "elf.h":                       [ "stdint.h" ],
     "envz.h":                      [ "argz.h", "errno.h" ],
-    "fts.h":                       [ "sys/types.h" ],
     "gshadow.h":                   [ "paths.h" ],
     "ieee754.h":                   [ "float.h" ],
     "lastlog.h":                   [ "utmp.h" ],
     "libintl.h":                   [ "locale.h" ],
-    "link.h":                      [ "dlfcn.h", "elf.h", "sys/types.h" ],
+    "link.h":                      [ "dlfcn.h", "elf.h" ],
     "mntent.h":                    [ "paths.h" ],
-    "nss.h":                       [ "stdint.h" ],
     "obstack.h":                   [ "stddef.h", "string.h" ],
     "proc_service.h":              [ "sys/procfs.h" ],
     "pty.h":                       [ "sys/ioctl.h", "termios.h" ],
     "sgtty.h":                     [ "sys/ioctl.h" ],
     "shadow.h":                    [ "paths.h" ],
     "stdio_ext.h":                 [ "stdio.h" ],
-    "thread_db.h":                 [ "pthread.h", "stdint.h", "sys/procfs.h",
-                                     "sys/types.h" ],
+    "thread_db.h":                 [ "pthread.h", "stdint.h", "sys/procfs.h" ],
     "ucontext.h":                  [ "sys/ucontext.h" ],
-    "utmp.h":                      [ "sys/types.h" ],
-    "utmpx.h":                     [ "sys/time.h" ],
+    "utmp.h":                      [ "paths.h" ],
     "values.h":                    [ "float.h", "limits.h" ],
 
     # Nonstandardized sys/ headers
-    "sys/acct.h":                  [ "endian.h", "stdint.h", "sys/types.h" ],
     "sys/auxv.h":                  [ "elf.h" ],
     "sys/elf.h":                   [ "sys/procfs.h" ],
-    "sys/epoll.h":                 [ "stdint.h", "sys/types.h" ],
-    "sys/eventfd.h":               [ "stdint.h" ],
-    "sys/fanotify.h":              [ "stdint.h" ],
     "sys/file.h":                  [ "fcntl.h" ],
-    "sys/fsuid.h":                 [ "sys/types.h" ],
-    "sys/gmon.h":                  [ "sys/types.h" ],
-    "sys/inotify.h":               [ "stdint.h" ],
     "sys/ioctl.h":                 [ "sys/ttydefaults.h" ],
     "sys/mount.h":                 [ "sys/ioctl.h" ],
-    "sys/mtio.h":                  [ "sys/ioctl.h", "sys/types.h" ],
+    "sys/mtio.h":                  [ "sys/ioctl.h" ],
     "sys/param.h":                 [ "endian.h", "limits.h", "sys/types.h" ],
-    "sys/platform/ppc.h":          [ "stdint.h" ],
-    "sys/procfs.h":                [ "sys/time.h", "sys/types.h",
-                                     "sys/user.h" ],
-    "sys/profil.h":                [ "sys/time.h", "sys/types.h" ],
+    "sys/procfs.h":                [ "sys/ucontext.h", "sys/user.h" ],
     "sys/ptrace.h":                [ "sys/ucontext.h" ],
-    "sys/quota.h":                 [ "sys/types.h" ],
-    "sys/random.h":                [ "sys/types.h" ],
-    "sys/raw.h":                   [ "stdint.h", "sys/ioctl.h" ],
-    "sys/sendfile.h":              [ "sys/types.h" ],
-    "sys/signalfd.h":              [ "stdint.h" ],
+    "sys/raw.h":                   [ "sys/ioctl.h" ],
     "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/timerfd.h":               [ "time.h" ],
     "sys/ttychars.h":              [ "sys/ttydefaults.h" ],
     "sys/ucontext.h":              [ "sys/procfs.h" ],
     "sys/vfs.h":                   [ "sys/statfs.h" ],
-    "sys/xattr.h":                 [ "sys/types.h" ],
 
     # Nonstandardized headers that do nothing but include some other
     # header(s).  These exist for compatibility with old systems where
@@ -656,8 +632,7 @@ HEADER_ALLOWED_INCLUDES = {
     "netinet/if_fddi.h":           [ "stdint.h", "sys/types.h" ],
     "netinet/if_tr.h":             [ "stdint.h", "sys/types.h" ],
     "netinet/igmp.h":              [ "netinet/in.h", "sys/types.h" ],
-    "netinet/in_systm.h":          [ "stdint.h", "sys/types.h" ],
-    "netinet/ip.h":                [ "netinet/in.h", "sys/types.h" ],
+    "netinet/ip.h":                [ "netinet/in.h" ],
     "netinet/ip6.h":               [ "inttypes.h", "netinet/in.h" ],
     "netinet/ip_icmp.h":           [ "netinet/in.h", "netinet/ip.h",
                                      "stdint.h", "sys/types.h" ],
@@ -675,14 +650,8 @@ HEADER_ALLOWED_INCLUDES = {
     "features.h":                  [ "gnu/stubs.h", "stdc-predef.h",
                                      "sys/cdefs.h" ],
 
-    "bits/fcntl.h":                [ "sys/types.h" ],
-    "bits/ipc.h":                  [ "sys/types.h" ],
     "bits/procfs.h":               [ "signal.h", "sys/ucontext.h" ],
-    "bits/sem.h":                  [ "sys/types.h" ],
-    "bits/socket.h":               [ "sys/types.h" ],
-    "bits/types/res_state.h":      [ "netinet/in.h", "sys/types.h" ],
-    "bits/utmp.h":                 [ "paths.h", "sys/time.h", "sys/types.h" ],
-    "bits/utmpx.h":                [ "paths.h", "sys/time.h" ],
+    "bits/types/res_state.h":      [ "netinet/in.h" ],
 
     "bits/types/__va_list.h":      [ "stdarg.h" ],
     "bits/types/ptrdiff_t.h":      [ "stddef.h" ],
@@ -730,7 +699,8 @@ SYSDEP_ALLOWED_INCLUDES = {
         "bits/ioctls.h":           [ "asm/ioctls.h", "linux/sockios.h" ],
         "bits/local_lim.h":        [ "linux/limits.h" ],
         "bits/param.h":            [ "linux/limits.h", "linux/param.h" ],
-        "bits/procfs.h":           [ "asm/ptrace.h" ],
+        "bits/procfs.h":           [ "asm/elf.h", "asm/ptrace.h" ],
+        "bits/procfs-prregset.h":  [ "sys/ucontext.h" ],
         "bits/sigcontext.h":       [ "asm/sigcontext.h" ],
         "bits/socket.h":           [ "asm/socket.h" ],
     },
diff --git a/sysdeps/gnu/net/if.h b/socket/net/if.h
similarity index 98%
rename from sysdeps/gnu/net/if.h
rename to socket/net/if.h
index e94ed67c21..b2fdbf7be0 100644
--- a/sysdeps/gnu/net/if.h
+++ b/socket/net/if.h
@@ -21,12 +21,6 @@
 
 #include <features.h>
 
-#ifdef __USE_MISC
-# include <sys/types.h>
-# include <sys/socket.h>
-#endif
-
-
 /* Length of interface name.  */
 #define IF_NAMESIZE	16
 
@@ -38,6 +32,8 @@ struct if_nameindex
 
 
 #ifdef __USE_MISC
+# include <sys/socket.h>  /* for struct sockaddr */
+
 /* Standard interface flags. */
 enum
   {
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index ce793dc3e2..9770d90d2a 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -23,7 +23,10 @@
 
 __BEGIN_DECLS
 
+#include <bits/types.h>
 #include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
+#include <bits/types/socklen_t.h>
 #include <bits/types/struct_iovec.h>
 
 /* This operating system-specific header file defines the SOCK_*, PF_*,
diff --git a/stdlib/sys/random.h b/stdlib/sys/random.h
index 2297edf2f2..1da7f6bea0 100644
--- a/stdlib/sys/random.h
+++ b/stdlib/sys/random.h
@@ -20,7 +20,9 @@
 #define _SYS_RANDOM_H 1
 
 #include <features.h>
-#include <sys/types.h>
+
+#include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
 
 /* Flags for use with getrandom.  */
 #define GRND_NONBLOCK 0x01
diff --git a/sysdeps/generic/net/if.h b/sysdeps/generic/net/if.h
deleted file mode 100644
index 4af66511e7..0000000000
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
deleted file mode 100644
index 3b59e949d8..0000000000
diff --git a/sysdeps/gnu/Makefile b/sysdeps/gnu/Makefile
index a03d40e4ca..fdfbfc45d8 100644
--- a/sysdeps/gnu/Makefile
+++ b/sysdeps/gnu/Makefile
@@ -58,24 +58,12 @@ $(foreach o,$(object-suffixes) $(object-suffixes:=.d),\
 	  $(objpfx)errlist$o): $(objpfx)errlist-compat.h
 endif
 
-ifeq ($(subdir),login)
-sysdep_routines += setutxent getutxent endutxent getutxid getutxline \
-		   pututxline utmpxname updwtmpx getutmpx getutmp
-
-sysdep_headers += utmpx.h bits/utmpx.h
-endif
-
 
 ifeq ($(subdir),inet)
 sysdep_headers += netinet/udp.h netinet/ip_icmp.h
 endif
 
 
-ifeq ($(subdir),misc)
-sysdep_headers += sys/mtio.h
-endif
-
-
 ifeq ($(subdir),csu)
 routines += unwind-resume
 shared-only-routines += unwind-resume
diff --git a/sysdeps/gnu/bits/sem.h b/sysdeps/gnu/bits/sem.h
index 12ec4e61b1..2eeb12af0c 100644
--- a/sysdeps/gnu/bits/sem.h
+++ b/sysdeps/gnu/bits/sem.h
@@ -15,11 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_SEM_H
+#define _BITS_SEM_H 1
+
 #ifndef _SYS_SEM_H
 # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Flags for `semop'.  */
 #define SEM_UNDO	0x1000		/* undo the operation on exit */
@@ -85,3 +88,5 @@ struct  seminfo
 };
 
 #endif /* __USE_MISC */
+
+#endif /* bits/sem.h */
diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h
index 9da4f8a145..b666a71ac2 100644
--- a/sysdeps/mach/hurd/bits/fcntl.h
+++ b/sysdeps/mach/hurd/bits/fcntl.h
@@ -16,11 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_FCNTL_H
+#define _BITS_FCNTL_H 1
+
 #ifndef _FCNTL_H
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* File access modes.  These are understood by io servers; they can be
    passed in `dir_lookup', and are returned by `io_get_openmodes'.
@@ -180,13 +183,9 @@
 # define F_DUPFD_CLOEXEC 1030	/* Duplicate, set FD_CLOEXEC on new one.  */
 #endif
 
-
 /* File descriptor flags used with F_GETFD and F_SETFD.  */
 #define	FD_CLOEXEC	1	/* Close on exec.  */
 
-
-#include <bits/types.h>
-
 /* The structure describing an advisory lock.  This is the type of the third
    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
 struct flock
@@ -228,3 +227,5 @@ struct flock64
 # define POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+
+#endif /* bits/fcntl.h */
diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
index ad590af3f6..77498ca43e 100644
--- a/sysdeps/mach/hurd/bits/socket.h
+++ b/sysdeps/mach/hurd/bits/socket.h
@@ -25,7 +25,7 @@
 #endif
 
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 #include <bits/wordsize.h>
diff --git a/sysdeps/mach/hurd/i386/Makefile b/sysdeps/mach/hurd/i386/Makefile
index bf62a5fc67..88747c684a 100644
--- a/sysdeps/mach/hurd/i386/Makefile
+++ b/sysdeps/mach/hurd/i386/Makefile
@@ -20,69 +20,34 @@ ifeq ($(subdir),conform)
 conformtest-xfail-conds += i386-gnu
 
 # For bug 23088
-test-xfail-POSIX/fcntl.h/conform = yes
 test-xfail-POSIX/signal.h/conform = yes
-test-xfail-POSIX/semaphore.h/conform = yes
 test-xfail-POSIX/regex.h/conform = yes
 test-xfail-POSIX/aio.h/conform = yes
 test-xfail-POSIX/mqueue.h/conform = yes
 test-xfail-POSIX/sys/types.h/conform = yes
-test-xfail-UNIX98/fcntl.h/conform = yes
-test-xfail-UNIX98/netdb.h/conform = yes
 test-xfail-UNIX98/signal.h/conform = yes
-test-xfail-UNIX98/semaphore.h/conform = yes
 test-xfail-UNIX98/regex.h/conform = yes
 test-xfail-UNIX98/aio.h/conform = yes
-test-xfail-UNIX98/ftw.h/conform = yes
 test-xfail-UNIX98/mqueue.h/conform = yes
-test-xfail-UNIX98/netinet/in.h/conform = yes
-test-xfail-UNIX98/sys/sem.h/conform = yes
-test-xfail-UNIX98/sys/uio.h/conform = yes
-test-xfail-UNIX98/sys/socket.h/conform = yes
 test-xfail-UNIX98/sys/types.h/conform = yes
 test-xfail-UNIX98/stdlib.h/conform = yes
-test-xfail-UNIX98/arpa/inet.h/conform = yes
-test-xfail-POSIX2008/fcntl.h/conform = yes
-test-xfail-POSIX2008/netdb.h/conform = yes
 test-xfail-POSIX2008/signal.h/conform = yes
-test-xfail-POSIX2008/semaphore.h/conform = yes
 test-xfail-POSIX2008/regex.h/conform = yes
 test-xfail-POSIX2008/aio.h/conform = yes
 test-xfail-POSIX2008/mqueue.h/conform = yes
-test-xfail-POSIX2008/netinet/in.h/conform = yes
-test-xfail-POSIX2008/sys/socket.h/conform = yes
 test-xfail-POSIX2008/sys/types.h/conform = yes
-test-xfail-POSIX2008/arpa/inet.h/conform = yes
-test-xfail-XOPEN2K/fcntl.h/conform = yes
-test-xfail-XOPEN2K/netdb.h/conform = yes
 test-xfail-XOPEN2K/signal.h/conform = yes
-test-xfail-XOPEN2K/semaphore.h/conform = yes
 test-xfail-XOPEN2K/regex.h/conform = yes
 test-xfail-XOPEN2K/aio.h/conform = yes
-test-xfail-XOPEN2K/ftw.h/conform = yes
 test-xfail-XOPEN2K/mqueue.h/conform = yes
-test-xfail-XOPEN2K/netinet/in.h/conform = yes
-test-xfail-XOPEN2K/sys/sem.h/conform = yes
-test-xfail-XOPEN2K/sys/uio.h/conform = yes
-test-xfail-XOPEN2K/sys/socket.h/conform = yes
 test-xfail-XOPEN2K/sys/types.h/conform = yes
 test-xfail-XOPEN2K/stdlib.h/conform = yes
-test-xfail-XOPEN2K/arpa/inet.h/conform = yes
-test-xfail-XOPEN2K8/fcntl.h/conform = yes
-test-xfail-XOPEN2K8/netdb.h/conform = yes
 test-xfail-XOPEN2K8/signal.h/conform = yes
-test-xfail-XOPEN2K8/semaphore.h/conform = yes
 test-xfail-XOPEN2K8/regex.h/conform = yes
 test-xfail-XOPEN2K8/aio.h/conform = yes
-test-xfail-XOPEN2K8/ftw.h/conform = yes
 test-xfail-XOPEN2K8/mqueue.h/conform = yes
-test-xfail-XOPEN2K8/netinet/in.h/conform = yes
-test-xfail-XOPEN2K8/sys/sem.h/conform = yes
-test-xfail-XOPEN2K8/sys/uio.h/conform = yes
-test-xfail-XOPEN2K8/sys/socket.h/conform = yes
 test-xfail-XOPEN2K8/sys/types.h/conform = yes
 test-xfail-XOPEN2K8/stdlib.h/conform = yes
-test-xfail-XOPEN2K8/arpa/inet.h/conform = yes
 
 # For bug 23819
 test-xfail-ISO11/threads.h/linknamespace = yes
diff --git a/sysdeps/mach/hurd/sendfile.c b/sysdeps/mach/hurd/sendfile.c
index 4857396cf7..dbb1ab8730 100644
--- a/sysdeps/mach/hurd/sendfile.c
+++ b/sysdeps/mach/hurd/sendfile.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <sys/sendfile.h>
+#include <sys/types.h>
 #include <stddef.h>
 
 /* Send COUNT bytes from file associated with IN_FD starting at OFFSET to
diff --git a/sysdeps/nptl/proc_service.h b/sysdeps/nptl/proc_service.h
index 4aa52c6390..600cbd132e 100644
--- a/sysdeps/nptl/proc_service.h
+++ b/sysdeps/nptl/proc_service.h
@@ -22,6 +22,9 @@
 /* The definitions in this file must correspond to those in the debugger.  */
 #include <sys/procfs.h>
 
+#include <bits/types/size_t.h>
+#include <bits/types/pid_t.h>
+
 __BEGIN_DECLS
 
 /* Functions in this interface return one of these status codes.  */
diff --git a/sysdeps/nptl/sys/procfs.h b/sysdeps/nptl/sys/procfs.h
index 6ade66dfb6..0f886746e2 100644
--- a/sysdeps/nptl/sys/procfs.h
+++ b/sysdeps/nptl/sys/procfs.h
@@ -19,7 +19,8 @@
 #ifndef _SYS_PROCFS_H
 #define _SYS_PROCFS_H	1
 
-#include <sys/types.h>
+#include <features.h>
+#include <bits/types.h>
 
 /* The rest of this file provides the types for emulation of the
    Solaris <proc_service.h> interfaces that should be implemented by
diff --git a/sysdeps/nptl/thread_db.h b/sysdeps/nptl/thread_db.h
index 4d949b0c37..3d6cb3a891 100644
--- a/sysdeps/nptl/thread_db.h
+++ b/sysdeps/nptl/thread_db.h
@@ -24,7 +24,6 @@
    with the goal to share the same code in the debugger.  */
 #include <pthread.h>
 #include <stdint.h>
-#include <sys/types.h>
 #include <sys/procfs.h>
 #include <bits/types/sigset_t.h>
 
diff --git a/sysdeps/posix/dl-fileid.h b/sysdeps/posix/dl-fileid.h
index 1ed7c2c57b..6a5dfc7446 100644
--- a/sysdeps/posix/dl-fileid.h
+++ b/sysdeps/posix/dl-fileid.h
@@ -23,8 +23,8 @@
    a unique identifier for a file.  */
 struct r_file_id
   {
-    dev_t dev;
-    ino64_t ino;
+    __dev_t dev;
+    __ino64_t ino;
   };
 
 /* Sample FD to fill in *ID.  Returns true on success.
diff --git a/sysdeps/powerpc/sys/platform/ppc.h b/sysdeps/powerpc/sys/platform/ppc.h
index 40ac0a5245..fe4d445dd4 100644
--- a/sysdeps/powerpc/sys/platform/ppc.h
+++ b/sysdeps/powerpc/sys/platform/ppc.h
@@ -20,24 +20,24 @@
 #define _SYS_PLATFORM_PPC_H	1
 
 #include <features.h>
-#include <stdint.h>
+#include <bits/types.h>
 #include <bits/ppc.h>
 
 /* Read the Time Base Register.   */
-static __inline__ uint64_t
+static __inline__ __uint64_t
 __ppc_get_timebase (void)
 {
 #if __GNUC_PREREQ (4, 8)
   return __builtin_ppc_get_timebase ();
 #else
 # ifdef __powerpc64__
-  uint64_t __tb;
+  __uint64_t __tb;
   /* "volatile" is necessary here, because the user expects this assembly
      isn't moved after an optimization.  */
   __asm__ volatile ("mfspr %0, 268" : "=r" (__tb));
   return __tb;
 # else  /* not __powerpc64__ */
-  uint32_t __tbu, __tbl, __tmp; \
+  __uint32_t __tbu, __tbl, __tmp;
   __asm__ volatile ("0:\n\t"
 		    "mftbu %0\n\t"
 		    "mftbl %1\n\t"
@@ -45,7 +45,7 @@ __ppc_get_timebase (void)
 		    "cmpw %0, %2\n\t"
 		    "bne- 0b"
 		    : "=r" (__tbu), "=r" (__tbl), "=r" (__tmp));
-  return (((uint64_t) __tbu << 32) | __tbl);
+  return (((__uint64_t) __tbu << 32) | __tbl);
 # endif  /* not __powerpc64__ */
 #endif
 }
diff --git a/sysdeps/pthread/semaphore.h b/sysdeps/pthread/semaphore.h
index 87c054392c..075b0be175 100644
--- a/sysdeps/pthread/semaphore.h
+++ b/sysdeps/pthread/semaphore.h
@@ -19,7 +19,7 @@
 #define _SEMAPHORE_H	1
 
 #include <features.h>
-#include <sys/types.h>
+
 #ifdef __USE_XOPEN2K
 # include <bits/types/struct_timespec.h>
 #endif
diff --git a/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h b/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h
index ea91de06bd..fec2f6a266 100644
--- a/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/aarch64/bits/procfs.h
@@ -17,19 +17,28 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
+#include <bits/types.h>
+
 /* Type for a general-purpose register.  */
 typedef __uint64_t elf_greg_t;
 
 /* And the whole bunch of them.  We could have used `struct
-   pt_regs' directly in the typedef, but tradition says that
+   user_regs_struct' directly in the typedef, but tradition says that
    the register set is an array, which does have some peculiar
-   semantics, so leave it that way.  */
+   semantics, so leave it that way.
+
+   struct user_regs_struct is defined in sys/user.h.  */
 #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t))
 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 /* Register set for the floating-point registers.  */
 typedef struct user_fpsimd_struct elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/epoll.h b/sysdeps/unix/sysv/linux/alpha/bits/epoll.h
index 3bf1853cd8..41dd9c51c4 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/epoll.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/epoll.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_EPOLL_H
+#define _BITS_EPOLL_H 1
+
 #ifndef	_SYS_EPOLL_H
 # error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead."
 #endif
@@ -25,3 +28,5 @@ enum
     EPOLL_CLOEXEC  = 010000000
 #define EPOLL_CLOEXEC EPOLL_CLOEXEC
   };
+
+#endif /* bits/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h b/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
index a5fffc0005..58b015fbc6 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
@@ -17,9 +17,18 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_PRREGSET_H
+#define _BITS_PROCFS_PRREGSET_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs-prregset.h> directly; use <sys/procfs.h> instead."
 #endif
 
+/* For gregset_t and fpregset_t.  FIXME: sys/procfs.h should not
+   expose all of sys/ucontext.h.  */
+#include <sys/ucontext.h>
+
 typedef gregset_t __prgregset_t;
 typedef fpregset_t __prfpregset_t;
+
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/procfs.h b/sysdeps/unix/sysv/linux/alpha/bits/procfs.h
index d0fd280821..f04a453bd5 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/procfs.h
@@ -16,13 +16,13 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-#include <signal.h>
-#include <sys/ucontext.h>
-
 /*
  * The OSF/1 version of <sys/procfs.h> makes gregset_t 46 entries long.
  * I have no idea why that is so.  For now, we just leave it at 33
@@ -36,3 +36,5 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 typedef double elf_fpreg_t;
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/sys/acct.h b/sysdeps/unix/sysv/linux/alpha/sys/acct.h
index 95e5b86e2f..98c92edc0d 100644
--- a/sysdeps/unix/sysv/linux/alpha/sys/acct.h
+++ b/sysdeps/unix/sysv/linux/alpha/sys/acct.h
@@ -16,8 +16,8 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _SYS_ACCT_H
-
 #define _SYS_ACCT_H	1
+
 #include <features.h>
 
 #include <bits/types/time_t.h>
diff --git a/sysdeps/unix/sysv/linux/arm/bits/procfs.h b/sysdeps/unix/sysv/linux/arm/bits/procfs.h
index f168b3af20..333fff661b 100644
--- a/sysdeps/unix/sysv/linux/arm/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/arm/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -26,9 +29,13 @@ typedef unsigned long elf_greg_t;
 /* And the whole bunch of them.  We could have used `struct
    user_regs' directly in the typedef, but tradition says that
    the register set is an array, which does have some peculiar
-   semantics, so leave it that way.  */
+   semantics, so leave it that way.
+
+   struct user_regs is defined in sys/user.h.  */
 #define ELF_NGREG (sizeof (struct user_regs) / sizeof (elf_greg_t))
 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 /* Register set for the floating-point registers.  */
 typedef struct user_fpregs elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/bits/epoll.h b/sysdeps/unix/sysv/linux/bits/epoll.h
index eaba990c23..a00f3d9431 100644
--- a/sysdeps/unix/sysv/linux/bits/epoll.h
+++ b/sysdeps/unix/sysv/linux/bits/epoll.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_EPOLL_H
+#define _BITS_EPOLL_H 1
+
 #ifndef	_SYS_EPOLL_H
 # error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead."
 #endif
@@ -25,3 +28,5 @@ enum
     EPOLL_CLOEXEC = 02000000
 #define EPOLL_CLOEXEC EPOLL_CLOEXEC
   };
+
+#endif /* bits/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/bits/sem.h b/sysdeps/unix/sysv/linux/bits/sem.h
index a216459010..68600e3917 100644
--- a/sysdeps/unix/sysv/linux/bits/sem.h
+++ b/sysdeps/unix/sysv/linux/bits/sem.h
@@ -15,11 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_SEM_H
+#define _BITS_SEM_H 1
+
 #ifndef _SYS_SEM_H
 # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <bits/sem-pad.h>
 
 /* Flags for `semop'.  */
@@ -95,3 +98,5 @@ struct  seminfo
 };
 
 #endif /* __USE_MISC */
+
+#endif /* bits/sem.h */
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index 19e664842f..ef3d6f9fc5 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -24,7 +24,7 @@
 #endif
 
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 
@@ -337,9 +337,9 @@ enum
 /* User visible structure for SCM_CREDENTIALS message */
 struct ucred
 {
-  pid_t pid;			/* PID of sending process.  */
-  uid_t uid;			/* UID of sending process.  */
-  gid_t gid;			/* GID of sending process.  */
+  __pid_t pid;			/* PID of sending process.  */
+  __uid_t uid;			/* UID of sending process.  */
+  __gid_t gid;			/* GID of sending process.  */
 };
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/bits/uio-ext.h b/sysdeps/unix/sysv/linux/bits/uio-ext.h
index c4ea63df0b..a39080691b 100644
--- a/sysdeps/unix/sysv/linux/bits/uio-ext.h
+++ b/sysdeps/unix/sysv/linux/bits/uio-ext.h
@@ -26,7 +26,7 @@
 __BEGIN_DECLS
 
 /* Read from another process' address space.  */
-extern ssize_t process_vm_readv (pid_t __pid, const struct iovec *__lvec,
+extern ssize_t process_vm_readv (__pid_t __pid, const struct iovec *__lvec,
 				 unsigned long int __liovcnt,
 				 const struct iovec *__rvec,
 				 unsigned long int __riovcnt,
@@ -34,7 +34,7 @@ extern ssize_t process_vm_readv (pid_t __pid, const struct iovec *__lvec,
   __THROW;
 
 /* Write to another process' address space.  */
-extern ssize_t process_vm_writev (pid_t __pid, const struct iovec *__lvec,
+extern ssize_t process_vm_writev (__pid_t __pid, const struct iovec *__lvec,
 				  unsigned long int __liovcnt,
 				  const struct iovec *__rvec,
 				  unsigned long int __riovcnt,
diff --git a/sysdeps/unix/sysv/linux/csky/bits/procfs.h b/sysdeps/unix/sysv/linux/csky/bits/procfs.h
index 4ec0c5e759..97982b65bd 100644
--- a/sysdeps/unix/sysv/linux/csky/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/csky/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -35,3 +38,5 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 #define ELF_NFPREG (sizeof (struct user_fp) / sizeof (elf_fpreg_t))
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/epoll.h b/sysdeps/unix/sysv/linux/hppa/bits/epoll.h
index 156bda0f3c..77722144f0 100644
--- a/sysdeps/unix/sysv/linux/hppa/bits/epoll.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/epoll.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_EPOLL_H
+#define _BITS_EPOLL_H 1
+
 #ifndef	_SYS_EPOLL_H
 # error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead."
 #endif
@@ -25,3 +28,5 @@ enum
     EPOLL_CLOEXEC = 010000000
 #define EPOLL_CLOEXEC EPOLL_CLOEXEC
   };
+
+#endif /* bits/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/procfs.h b/sysdeps/unix/sysv/linux/hppa/bits/procfs.h
index 9d57472b5e..5bbdb2bc2e 100644
--- a/sysdeps/unix/sysv/linux/hppa/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -28,3 +31,5 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 #define ELF_NFPREG 32
 typedef double elf_fpreg_t;
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/ipc.h b/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
index 6f9705e28a..a6fbabec64 100644
--- a/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
@@ -20,7 +20,7 @@
 # error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Mode bits for `msgget', `semget', and `shmget'.  */
 #define IPC_CREAT	01000		/* Create key if key does not exist. */
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/procfs.h b/sysdeps/unix/sysv/linux/ia64/bits/procfs.h
index 8918975e1d..754e9690c9 100644
--- a/sysdeps/unix/sysv/linux/ia64/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/procfs.h
@@ -16,11 +16,15 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-#include <signal.h>
+/* For struct __ia64_fpreg.  FIXME: sys/procfs.h should not expose all
+   of sys/ucontext.h.  */
 #include <sys/ucontext.h>
 #include <bits/sigcontext.h>
 
@@ -39,3 +43,5 @@ typedef elf_greg_t greg_t;
 typedef elf_gregset_t gregset_t;
 typedef elf_fpregset_t fpregset_t;
 #define NGREG ELF_NGREG
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/m68k/bits/procfs.h b/sysdeps/unix/sysv/linux/m68k/bits/procfs.h
index 4a9d4aa3cc..401ac2354a 100644
--- a/sysdeps/unix/sysv/linux/m68k/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/m68k/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -26,9 +29,13 @@ typedef unsigned long elf_greg_t;
 /* And the whole bunch of them.  We could have used `struct
    user_regs_struct' directly in the typedef, but tradition says that
    the register set is an array, which does have some peculiar
-   semantics, so leave it that way.  */
+   semantics, so leave it that way.
+
+   struct user_regs_struct is defined by sys/user.h.  */
 #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t))
 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 /* Register set for the floating-point registers.  */
 typedef struct user_m68kfp_struct elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/microblaze/bits/procfs.h b/sysdeps/unix/sysv/linux/microblaze/bits/procfs.h
index 7da4b7385b..0f425272a3 100644
--- a/sysdeps/unix/sysv/linux/microblaze/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/microblaze/bits/procfs.h
@@ -17,6 +17,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -27,9 +30,13 @@ typedef unsigned long elf_greg_t;
 /* And the whole bunch of them.  We could have used `struct
    user_regs_struct' directly in the typedef, but tradition says that
    the register set is an array, which does have some peculiar
-   semantics, so leave it that way.  */
+   semantics, so leave it that way.
+
+   struct user_regs_struct is defined by sys/user.h.  */
 #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t))
 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 /* Register set for the floating-point registers.  */
 typedef struct user_fpregs_struct elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/microblaze/sys/user.h b/sysdeps/unix/sysv/linux/microblaze/sys/user.h
index baf6a28247..e6542ecd1b 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sys/user.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sys/user.h
@@ -17,7 +17,9 @@
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef _SYS_USER_H
-# define _SYS_USER_H	1
+#define _SYS_USER_H	1
+
+#include <features.h>
 
 #include <features.h>
 
diff --git a/sysdeps/unix/sysv/linux/mips/bits/epoll.h b/sysdeps/unix/sysv/linux/mips/bits/epoll.h
index eaba990c23..a00f3d9431 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/epoll.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/epoll.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_EPOLL_H
+#define _BITS_EPOLL_H 1
+
 #ifndef	_SYS_EPOLL_H
 # error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead."
 #endif
@@ -25,3 +28,5 @@ enum
     EPOLL_CLOEXEC = 02000000
 #define EPOLL_CLOEXEC EPOLL_CLOEXEC
   };
+
+#endif /* bits/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/mips/bits/procfs.h b/sysdeps/unix/sysv/linux/mips/bits/procfs.h
index 7df96af52d..6543713624 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -35,3 +38,5 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 typedef double elf_fpreg_t;
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/nios2/bits/procfs.h b/sysdeps/unix/sysv/linux/nios2/bits/procfs.h
index a8431229ff..0c401edadc 100644
--- a/sysdeps/unix/sysv/linux/nios2/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/nios2/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -32,3 +35,5 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 /* Register set for the floating-point registers.  */
 typedef struct user_fpregs elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/ppc.h b/sysdeps/unix/sysv/linux/powerpc/bits/ppc.h
index 4b5667a68e..77436a93f7 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/ppc.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/ppc.h
@@ -26,7 +26,7 @@
 __BEGIN_DECLS
 
 /* Read the time base frequency.   */
-extern uint64_t __ppc_get_timebase_freq (void);
+extern __uint64_t __ppc_get_timebase_freq (void);
 
 __END_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/procfs.h b/sysdeps/unix/sysv/linux/powerpc/bits/procfs.h
index cf67771a9d..18c6870977 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/procfs.h
@@ -16,17 +16,20 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-#include <signal.h>
-#include <sys/ucontext.h>
+#include <bits/wordsize.h>
+#include <asm/elf.h>
+
+/* These definitions may have been provided by asm/elf.h.  Otherwise
+   we define them here.  */
+#ifndef ELF_NGREG
 
-/* These definitions are normally provided by ucontext.h via
-   asm/sigcontext.h, asm/ptrace.h, and asm/elf.h.  Otherwise we define
-   them here.  */
-#if !defined __PPC64_ELF_H && !defined _ASM_POWERPC_ELF_H
 #define ELF_NGREG       48      /* includes nip, msr, lr, etc. */
 #define ELF_NFPREG      33      /* includes fpscr */
 #if __WORDSIZE == 32
@@ -46,4 +49,7 @@ typedef struct {
   unsigned int u[4];
 } __attribute__ ((__aligned__ (16))) elf_vrreg_t;
 typedef elf_vrreg_t elf_vrregset_t[ELF_NVRREG];
-#endif
+
+#endif /* ifndef ELF_NGREG */
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/user.h b/sysdeps/unix/sysv/linux/powerpc/sys/user.h
index 2d90235a14..3c928cef37 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/user.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/user.h
@@ -22,6 +22,7 @@
 #include <bits/types/size_t.h>
 
 #include <asm/ptrace.h>
+#include <bits/types/size_t.h>
 
 struct user {
 	struct pt_regs	regs;			/* entire machine state */
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/procfs.h b/sysdeps/unix/sysv/linux/riscv/bits/procfs.h
index f2e4503d5d..6ab26013a6 100644
--- a/sysdeps/unix/sysv/linux/riscv/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/riscv/bits/procfs.h
@@ -16,10 +16,16 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
+/* FIXME: sys/ucontext.h does not define NGREG or NFPREG unless
+   __USE_MISC is active, and sys/procfs.h should not expose all of
+   sys/ucontext.h.  */
 #include <sys/ucontext.h>
 
 /* ELF register definitions */
@@ -29,3 +35,5 @@
 typedef unsigned long int elf_greg_t;
 typedef unsigned long int elf_gregset_t[32];
 typedef union __riscv_mc_fp_state elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/s390/bits/procfs.h b/sysdeps/unix/sysv/linux/s390/bits/procfs.h
index 364051c1c7..597ccdb754 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/procfs.h
@@ -16,10 +16,15 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
+/* FIXME: sys/ucontext.h does not define NGREG unless __USE_MISC is
+   active, and sys/procfs.h should not expose all of sys/ucontext.h.  */
 #include <sys/ucontext.h>
 
 typedef greg_t elf_greg_t;
@@ -27,3 +32,5 @@ typedef greg_t elf_greg_t;
 typedef gregset_t elf_gregset_t;
 typedef fpreg_t   elf_fpreg_t;
 typedef fpregset_t elf_fpregset_t;
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/gnu/bits/utmp.h b/sysdeps/unix/sysv/linux/s390/bits/utmp.h
similarity index 83%
rename from sysdeps/gnu/bits/utmp.h
rename to sysdeps/unix/sysv/linux/s390/bits/utmp.h
index 7357034cb6..553fb30fb5 100644
--- a/sysdeps/gnu/bits/utmp.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/utmp.h
@@ -1,4 +1,4 @@
-/* The `struct utmp' type, describing entries in the utmp file.  GNU version.
+/* The `struct utmp' type, describing entries in the utmp file.  S/390 version.
    Copyright (C) 1993-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,15 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_UTMP_H
+#define _BITS_UTMP_H 1
+
 #ifndef _UTMP_H
 # error "Never include <bits/utmp.h> directly; use <utmp.h> instead."
 #endif
 
-#include <paths.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <bits/wordsize.h>
-
 
 #define UT_LINESIZE	32
 #define UT_NAMESIZE	32
@@ -35,11 +33,7 @@
    previous logins.  */
 struct lastlog
   {
-#if __WORDSIZE_TIME64_COMPAT32
-    int32_t ll_time;
-#else
-    __time_t ll_time;
-#endif
+    __time64_t ll_time;
     char ll_line[UT_LINESIZE];
     char ll_host[UT_HOSTSIZE];
   };
@@ -68,23 +62,20 @@ struct utmp
     __attribute_nonstring__;	/* Hostname for remote login.  */
   struct exit_status ut_exit;	/* Exit status of a process marked
 				   as DEAD_PROCESS.  */
+
 /* The ut_session and ut_tv fields must be the same size when compiled
    32- and 64-bit.  This allows data files and shared memory to be
-   shared between 32- and 64-bit applications.  */
-#if __WORDSIZE_TIME64_COMPAT32
-  int32_t ut_session;		/* Session ID, used for windowing.  */
+   shared between 32- and 64-bit applications.  Even on 64-bit systems,
+   struct timeval is not guaranteed to have both fields be 64 bits.  */
+  __int64_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
-    int32_t tv_sec;		/* Seconds.  */
-    int32_t tv_usec;		/* Microseconds.  */
+    __int64_t tv_sec;		/* Seconds.  */
+    __int64_t tv_usec;		/* Microseconds.  */
   } ut_tv;			/* Time entry was made.  */
-#else
-  long int ut_session;		/* Session ID, used for windowing.  */
-  struct timeval ut_tv;		/* Time entry was made.  */
-#endif
 
-  int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
-  char __glibc_reserved[20];		/* Reserved for future use.  */
+  __int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
+  char __glibc_reserved[20];	/* Reserved for future use.  */
 };
 
 /* Backwards compatibility hacks.  */
@@ -124,3 +115,5 @@ struct utmp
 #define _HAVE_UT_ID	1
 #define _HAVE_UT_TV	1
 #define _HAVE_UT_HOST	1
+
+#endif /* bits/utmp.h */
diff --git a/sysdeps/unix/sysv/linux/s390/bits/utmpx.h b/sysdeps/unix/sysv/linux/s390/bits/utmpx.h
index ea3e860a2d..e498e72cff 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/utmpx.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/utmpx.h
@@ -1,4 +1,4 @@
-/* Structures and definitions for the user accounting database.  GNU version.
+/* Structures and definitions for the user accounting database.  S/390 version.
    Copyright (C) 1997-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,22 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_UTMPX_H
+#define _BITS_UTMPX_H 1
+
 #ifndef _UTMPX_H
 # error "Never include <bits/utmpx.h> directly; use <utmpx.h> instead."
 #endif
 
-#include <bits/types.h>
-#include <sys/time.h>
-#include <bits/wordsize.h>
-
-
-#ifdef __USE_GNU
-# include <paths.h>
-# define _PATH_UTMPX	_PATH_UTMP
-# define _PATH_WTMPX	_PATH_WTMP
-#endif
-
-
 #define __UT_LINESIZE	32
 #define __UT_NAMESIZE	32
 #define __UT_HOSTSIZE	256
@@ -55,7 +46,7 @@ struct __exit_status
 struct utmpx
 {
   short int ut_type;		/* Type of login.  */
-  __pid_t ut_pid;		/* Process ID of login process.  */
+  pid_t ut_pid;			/* Process ID of login process.  */
   char ut_line[__UT_LINESIZE];	/* Devicename.  */
   char ut_id[4];		/* Inittab ID. */
   char ut_user[__UT_NAMESIZE];	/* Username.  */
@@ -63,20 +54,17 @@ struct utmpx
   struct __exit_status ut_exit;	/* Exit status of a process marked
 				   as DEAD_PROCESS.  */
 
-/* The fields ut_session and ut_tv must be the same size when compiled
-   32- and 64-bit.  This allows files and shared memory to be shared
-   between 32- and 64-bit applications.  */
-#if __WORDSIZE == 32
+/* The ut_session and ut_tv fields must be the same size when compiled
+   32- and 64-bit.  This allows data files and shared memory to be
+   shared between 32- and 64-bit applications.  Even on 64-bit systems,
+   struct timeval is not guaranteed to have both fields be 64 bits.  */
   __int64_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
     __int64_t tv_sec;		/* Seconds.  */
     __int64_t tv_usec;		/* Microseconds.  */
   } ut_tv;			/* Time entry was made.  */
-#else
-  long int ut_session;		/* Session ID, used for windowing.  */
-  struct timeval ut_tv;		/* Time entry was made.  */
-#endif
+
   __int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
   char __glibc_reserved[20];		/* Reserved for future use.  */
 };
@@ -100,3 +88,5 @@ struct utmpx
 #ifdef __USE_GNU
 # define ACCOUNTING	9	/* System accounting.  */
 #endif
+
+#endif /* bits/utmpx.h */
diff --git a/sysdeps/unix/sysv/linux/sh/bits/procfs.h b/sysdeps/unix/sysv/linux/sh/bits/procfs.h
index 5e33070aac..1825874736 100644
--- a/sysdeps/unix/sysv/linux/sh/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/sh/bits/procfs.h
@@ -16,9 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
 /* elf_gregset_t and elf_fpregset_t are defined by sys/user.h for
    SH.  */
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/epoll.h b/sysdeps/unix/sysv/linux/sparc/bits/epoll.h
index 29e00522b3..2ddfe7b5ee 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/epoll.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/epoll.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_EPOLL_H
+#define _BITS_EPOLL_H 1
+
 #ifndef	_SYS_EPOLL_H
 # error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead."
 #endif
@@ -25,3 +28,5 @@ enum
     EPOLL_CLOEXEC = 0x400000
 #define EPOLL_CLOEXEC EPOLL_CLOEXEC
   };
+
+#endif /* bits/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/procfs.h b/sysdeps/unix/sysv/linux/sparc/bits/procfs.h
index cc7ca46f4a..9aa9c6d72c 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/procfs.h
@@ -16,12 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
 
-#include <signal.h>
-#include <sys/ucontext.h>
 #include <bits/wordsize.h>
 
 #if __WORDSIZE == 64
@@ -59,3 +60,5 @@ typedef struct
 
 typedef unsigned long elf_greg_t;
 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+#endif /* bits/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/sys/acct.h b/sysdeps/unix/sysv/linux/sys/acct.h
index 4c119dafd2..515045b275 100644
--- a/sysdeps/unix/sysv/linux/sys/acct.h
+++ b/sysdeps/unix/sysv/linux/sys/acct.h
@@ -18,10 +18,10 @@
 #ifndef _SYS_ACCT_H
 #define _SYS_ACCT_H	1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <features.h>
+
 #include <bits/endian.h>
-#include <bits/types/time_t.h>
+#include <bits/stdint-uintn.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/sys/epoll.h b/sysdeps/unix/sysv/linux/sys/epoll.h
index 51ec53dbca..3a16323328 100644
--- a/sysdeps/unix/sysv/linux/sys/epoll.h
+++ b/sysdeps/unix/sysv/linux/sys/epoll.h
@@ -18,9 +18,9 @@
 #ifndef	_SYS_EPOLL_H
 #define	_SYS_EPOLL_H	1
 
-#include <stdint.h>
-#include <sys/types.h>
+#include <features.h>
 
+#include <bits/types.h>
 #include <bits/types/sigset_t.h>
 
 /* Get the platform-dependent flags.  */
@@ -76,13 +76,13 @@ typedef union epoll_data
 {
   void *ptr;
   int fd;
-  uint32_t u32;
-  uint64_t u64;
+  __uint32_t u32;
+  __uint64_t u64;
 } epoll_data_t;
 
 struct epoll_event
 {
-  uint32_t events;	/* Epoll events */
+  __uint32_t events;	/* Epoll events */
   epoll_data_t data;	/* User data variable */
 } __EPOLL_PACKED;
 
diff --git a/sysdeps/unix/sysv/linux/sys/eventfd.h b/sysdeps/unix/sysv/linux/sys/eventfd.h
index d0a9d4c4a8..b6a6c18157 100644
--- a/sysdeps/unix/sysv/linux/sys/eventfd.h
+++ b/sysdeps/unix/sysv/linux/sys/eventfd.h
@@ -18,13 +18,14 @@
 #ifndef	_SYS_EVENTFD_H
 #define	_SYS_EVENTFD_H	1
 
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 /* Get the platform-dependent flags.  */
 #include <bits/eventfd.h>
 
 /* Type for event counter.  */
-typedef uint64_t eventfd_t;
+typedef __uint64_t eventfd_t;
 
 
 __BEGIN_DECLS
diff --git a/sysdeps/unix/sysv/linux/sys/fanotify.h b/sysdeps/unix/sysv/linux/sys/fanotify.h
index a37b9b6eb3..c024f6a32a 100644
--- a/sysdeps/unix/sysv/linux/sys/fanotify.h
+++ b/sysdeps/unix/sysv/linux/sys/fanotify.h
@@ -18,10 +18,10 @@
 #ifndef	_SYS_FANOTIFY_H
 #define	_SYS_FANOTIFY_H	1
 
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 #include <linux/fanotify.h>
 
-
 __BEGIN_DECLS
 
 /* Create and initialize fanotify group.  */
@@ -30,7 +30,7 @@ extern int fanotify_init (unsigned int __flags, unsigned int __event_f_flags)
 
 /* Add, remove, or modify an fanotify mark on a filesystem object.  */
 extern int fanotify_mark (int __fanotify_fd, unsigned int __flags,
-			  uint64_t __mask, int __dfd, const char *__pathname)
+			  __uint64_t __mask, int __dfd, const char *__pathname)
      __THROW;
 
 __END_DECLS
diff --git a/sysdeps/unix/sysv/linux/sys/fsuid.h b/sysdeps/unix/sysv/linux/sys/fsuid.h
index 54bd2d9c60..054d20c9e6 100644
--- a/sysdeps/unix/sysv/linux/sys/fsuid.h
+++ b/sysdeps/unix/sysv/linux/sys/fsuid.h
@@ -19,7 +19,7 @@
 #define _SYS_FSUID_H	1
 
 #include <features.h>
-#include <sys/types.h>
+#include <bits/types.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/sys/inotify.h b/sysdeps/unix/sysv/linux/sys/inotify.h
index 4b59b8e376..4dc7fc208f 100644
--- a/sysdeps/unix/sysv/linux/sys/inotify.h
+++ b/sysdeps/unix/sysv/linux/sys/inotify.h
@@ -18,7 +18,8 @@
 #ifndef	_SYS_INOTIFY_H
 #define	_SYS_INOTIFY_H	1
 
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 
 /* Get the platform-dependent flags.  */
 #include <bits/inotify.h>
@@ -28,9 +29,9 @@
 struct inotify_event
 {
   int wd;		/* Watch descriptor.  */
-  uint32_t mask;	/* Watch mask.  */
-  uint32_t cookie;	/* Cookie to synchronize two events.  */
-  uint32_t len;		/* Length (including NULs) of name.  */
+  __uint32_t mask;	/* Watch mask.  */
+  __uint32_t cookie;	/* Cookie to synchronize two events.  */
+  __uint32_t len;	/* Length (including NULs) of name.  */
   char name __flexarr;	/* Name.  */
 };
 
@@ -89,7 +90,7 @@ extern int inotify_init1 (int __flags) __THROW;
 
 /* Add watch of object NAME to inotify instance FD.  Notify about
    events specified by MASK.  */
-extern int inotify_add_watch (int __fd, const char *__name, uint32_t __mask)
+extern int inotify_add_watch (int __fd, const char *__name, __uint32_t __mask)
   __THROW;
 
 /* Remove the watch specified by WD from the inotify instance FD.  */
diff --git a/sysdeps/unix/sysv/linux/sys/procfs.h b/sysdeps/unix/sysv/linux/sys/procfs.h
index d24c19138a..c9ef13ff6e 100644
--- a/sysdeps/unix/sysv/linux/sys/procfs.h
+++ b/sysdeps/unix/sysv/linux/sys/procfs.h
@@ -30,8 +30,10 @@
    GDB unless you know what you are doing.  */
 
 #include <features.h>
-#include <sys/time.h>
-#include <sys/types.h>
+
+#include <bits/types.h>
+#include <bits/types/struct_timeval.h>
+
 #include <sys/user.h>
 
 /* bits/procfs.h, provided by each architecture, must define
diff --git a/sysdeps/unix/sysv/linux/sys/quota.h b/sysdeps/unix/sysv/linux/sys/quota.h
index 8c3a5a1da6..cf55f48ae5 100644
--- a/sysdeps/unix/sysv/linux/sys/quota.h
+++ b/sysdeps/unix/sysv/linux/sys/quota.h
@@ -52,8 +52,8 @@
 #define _SYS_QUOTA_H 1
 
 #include <features.h>
-#include <sys/types.h>
 
+#include <bits/types.h>
 #include <linux/quota.h>
 
 /*
diff --git a/sysdeps/unix/sysv/linux/sys/raw.h b/sysdeps/unix/sysv/linux/sys/raw.h
index b4e5a82b6e..fbdefe0221 100644
--- a/sysdeps/unix/sysv/linux/sys/raw.h
+++ b/sysdeps/unix/sysv/linux/sys/raw.h
@@ -18,7 +18,8 @@
 #ifndef _SYS_RAW_H
 #define _SYS_RAW_H	1
 
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 #include <sys/ioctl.h>
 
 /* The major device number for raw devices.  */
@@ -31,8 +32,8 @@
 struct raw_config_request
 {
   int raw_minor;
-  uint64_t block_major;
-  uint64_t block_minor;
+  __uint64_t block_major;
+  __uint64_t block_minor;
 };
 
 #endif /* sys/raw.h */
diff --git a/sysdeps/unix/sysv/linux/sys/signalfd.h b/sysdeps/unix/sysv/linux/sys/signalfd.h
index 13fd8b43fc..5a8f035301 100644
--- a/sysdeps/unix/sysv/linux/sys/signalfd.h
+++ b/sysdeps/unix/sysv/linux/sys/signalfd.h
@@ -18,7 +18,8 @@
 #ifndef	_SYS_SIGNALFD_H
 #define	_SYS_SIGNALFD_H	1
 
-#include <stdint.h>
+#include <features.h>
+#include <bits/types.h>
 #include <bits/types/sigset_t.h>
 
 /* Get the platform-dependent flags.  */
@@ -26,28 +27,28 @@
 
 struct signalfd_siginfo
 {
-  uint32_t ssi_signo;
-  int32_t ssi_errno;
-  int32_t ssi_code;
-  uint32_t ssi_pid;
-  uint32_t ssi_uid;
-  int32_t ssi_fd;
-  uint32_t ssi_tid;
-  uint32_t ssi_band;
-  uint32_t ssi_overrun;
-  uint32_t ssi_trapno;
-  int32_t ssi_status;
-  int32_t ssi_int;
-  uint64_t ssi_ptr;
-  uint64_t ssi_utime;
-  uint64_t ssi_stime;
-  uint64_t ssi_addr;
-  uint16_t ssi_addr_lsb;
-  uint16_t __pad2;
-  int32_t ssi_syscall;
-  uint64_t ssi_call_addr;
-  uint32_t ssi_arch;
-  uint8_t __pad[28];
+  __uint32_t ssi_signo;
+  __int32_t ssi_errno;
+  __int32_t ssi_code;
+  __uint32_t ssi_pid;
+  __uint32_t ssi_uid;
+  __int32_t ssi_fd;
+  __uint32_t ssi_tid;
+  __uint32_t ssi_band;
+  __uint32_t ssi_overrun;
+  __uint32_t ssi_trapno;
+  __int32_t ssi_status;
+  __int32_t ssi_int;
+  __uint64_t ssi_ptr;
+  __uint64_t ssi_utime;
+  __uint64_t ssi_stime;
+  __uint64_t ssi_addr;
+  __uint16_t ssi_addr_lsb;
+  __uint16_t __pad2;
+  __int32_t ssi_syscall;
+  __uint64_t ssi_call_addr;
+  __uint32_t ssi_arch;
+  __uint8_t __pad[28];
 };
 
 __BEGIN_DECLS
diff --git a/sysdeps/unix/sysv/linux/x86/bits/epoll.h b/sysdeps/unix/sysv/linux/x86/bits/epoll.h
index 162874aba3..c8c8737f44 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/epoll.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/epoll.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_EPOLL_H
+#define _BITS_EPOLL_H 1
+
 #ifndef	_SYS_EPOLL_H
 # error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead."
 #endif
@@ -27,3 +30,5 @@ enum
   };
 
 #define __EPOLL_PACKED __attribute__ ((__packed__))
+
+#endif /* bits/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/x86/bits/procfs.h b/sysdeps/unix/sysv/linux/x86/bits/procfs.h
index 55ea4c9f48..6feb88c26c 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/procfs.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/procfs.h
@@ -16,6 +16,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_PROCFS_H
+#define _BITS_PROCFS_H 1
+
 #ifndef _SYS_PROCFS_H
 # error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead."
 #endif
@@ -48,3 +51,5 @@ typedef struct user_fpxregs_struct elf_fpxregset_t;
    floating-point stuff.  */
 typedef struct user_fpregs_struct elf_fpregset_t;
 #endif
+
+#endif /* bits/procfs.h */
diff --git a/sysvipc/sys/sem.h b/sysvipc/sys/sem.h
index 6b5d43d71c..09e633592d 100644
--- a/sysvipc/sys/sem.h
+++ b/sysvipc/sys/sem.h
@@ -25,6 +25,8 @@
 
 /* Define types required by the standard.  */
 #include <bits/types/size_t.h>
+#include <bits/types/pid_t.h>
+#include <bits/types/time_t.h>
 #ifdef __USE_GNU
 # include <bits/types/struct_timespec.h>
 #endif
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 24/25] Minimize inclusion of netinet/in.h from public headers.
  2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
                   ` (13 preceding siblings ...)
  2019-06-26 18:26 ` [PATCH 17/25] Don’t include sys/select.h from sys/types.h Zack Weinberg
@ 2019-06-26 19:06 ` Zack Weinberg
  14 siblings, 0 replies; 17+ messages in thread
From: Zack Weinberg @ 2019-06-26 19:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: joseph, carlos

As with sys/socket.h and struct sockaddr, most of the files including
netinet/in.h just want struct sockaddr_in or a related type, so
introduce bits/types headers for these.  POSIX specifically allows
arpa/inet.h to include netinet/in.h and I think it makes sense to
preserve that.  The definition of struct sockaddr_in had a dependence
on the definition of struct sockaddr; to avoid that, bits/sockaddr.h
grows a new macro, __SOCKADDR_DATA_SIZE, which is the declared size of
struct sockaddr.sa_data.

On Linux, some kernel headers (notably linux/in.h and linux/in6.h)
attempt to cooperate with a C library’s headers in defining types such
as struct sockaddr_in.  There is a set of macros whose names begin
with __UAPI_DEF_ that indicate that a type has already been defined.
This mechanism doesn’t actually work with the kernel headers as they
are in 5.0, as far as I can tell, but it could be made to work with
straightforward changes, so it makes sense for us to support it to the
extent we can.  To do this sensibly I need to introduce a new bits
header called bits/uapi-compat.h, with a trivial definition for
non-Linux.  This replaces the existing __USE_KERNEL_IPV6_DEFS macro.

	* bits/sockaddr.h (__SOCKADDR_DATA_SIZE): New macro.
	* sysdeps/unix/bsd/bits/sockaddr.h: Likewise.
	* sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h: Likewise.
	* socket/bits/types/struct_sockaddr.h: Use __SOCKADDR_DATA_SIZE as
	array length of sa_data.

	* bits/in.h: Add multiple inclusion guard.
	(__USE_KERNEL_IPV6_DEFS): Don’t define.
	* sysdeps/unix/sysv/linux/bits/in.h: Similarly.
	(IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP): Define when not
	already defined, not conditional on __USE_KERNEL_IPV6_DEFS.

	* bits/uapi-compat.h: New file, trivial generic version.
	* sysdeps/unix/sysv/linux/bits/uapi-compat.h: New file,
	Linux-specific version which recognizes kernel header guard macros
	and defines __UAPI_DEF_* macros as appropriate.
	* misc/Makefile: Install bits/uapi-compat.h.

	* include/bits/types/in_addr_t.h, include/bits/types/in_port_t.h
	* include/bits/types/struct_in_addr.h
	* include/bits/types/struct_in6_addr.h
	* include/bits/types/struct_sockaddr_in.h
	* include/bits/types/struct_sockaddr_in6.h:
	New wrapper headers.

	* inet/bits/types/in_addr_t.h, inet/bits/types/in_port_t.h
	* inet/bits/types/struct_in_addr.h
	* inet/bits/types/struct_in6_addr.h
	* inet/bits/types/struct_sockaddr_in.h
	* inet/bits/types/struct_sockaddr_in6.h
	New single-type headers, factored out of inet/netinet/in.h.
	Add __UAPI_DEF_* conditionals where appropriate, and verify that
	all conditionalized definitions agree with the relevant
	OS-supplied header.  Use __SOCKADDR_DATA_SIZE to set size of sin_zero.
	* inet/Makefile: Install the new single-type headers.

	* inet/netinet/in.h: Include bits/uapi-compat.h.
	Define in_addr_t, in_port_t, struct in_addr, struct in6_addr,
	struct sockaddr_in, and struct sockaddr_in6 by including the
	above single-type headers, not directly.  Replace all
	__USE_KERNEL_IPV6_DEFS conditionals with appropriate __UAPI_DEF_*
	conditionals.  Add appropriate __UAPI_DEF_* conditionals around
	the definitions of the IPPROTO_* constants, the IN_CLASS
	macros, and struct ip_mreq.  Import IN_LOOPBACK macro from
	Linux 5.0 linux/in.h and verify all other conditionalized
	definitions agree with the relevant linux/ header.
	Define IPPORT_RESERVED only if not already defined, and make it a
	macro so we can tell.

	* inet/netinet/igmp.h, inet/netinet/ip.h, inet/netinet/ip_icmp.h:
	Include bits/types/struct_in_addr.h, not netinet/in.h.

	* inet/netinet/ip_icmp.h: Hoist all #includes to the top of the file.

	* inet/netinet/icmp6.h, inet/netinet/ip6.h
	* sysdeps/unix/sysv/linux/net/route.h:
	Include bits/types/struct_in6_addr.h, not netinet/in.h.

	* sysdeps/mach/hurd/net/route.h: Include bits/types.h and
	bits/types/struct_in6_addr.h, not netinet/in.h.  Use __uint16_t
	and __uint32_t instead of uint16_t and uint32_t.

	* resolv/bits/types/res_state.h: Include bits/types/struct_in_addr.h
	and bits/types/struct_sockaddr_in.h.  Forward declare struct
	sockaddr_in6.  Don’t include netinet/in.h.

	* resolv/netdb.h: Don’t include netinet/in.h.  Use socklen_t
	instead of __socklen_t.  Define IPPORT_RESERVED only if not
	already defined, with definition matching netinet/in.h.
	When __USE_MISC, include bits/sockaddr.h.
	* resolv/resolv.h: Don’t include netinet/in.h.

	* inet/tst-getni1.c, inet/tst-getni2.c
	* nss/tst-nss-files-hosts-erange.c, nss/tst-nss-files-hosts-getent.c
	* nss/tst-nss-files-hosts-multi.c, posix/tst-getaddrinfo2.c
	* resolv/tst-bug18665-tcp.c, resolv/tst-resolv-ai_idn-common.c
	* resolv/tst-resolv-canonname.c, resolv/tst-resolv-edns.c
	* resolv/tst-resolv-network.c, resolv/tst-resolv-nondecimal.c
	* resolv/tst-resolv-search.c, support/tst-support-namespace.c:
	Include netinet/in.h.
	* support/resolv_test.h: Include stdint.h, not sys/cdefs.h.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
	Update.
---
 bits/in.h                                    |   8 +-
 bits/sockaddr.h                              |   3 +
 bits/uapi-compat.h                           |  34 +++++
 include/bits/types/in_addr_t.h               |   1 +
 include/bits/types/in_port_t.h               |   1 +
 include/bits/types/struct_in6_addr.h         |   1 +
 include/bits/types/struct_in_addr.h          |   1 +
 include/bits/types/struct_sockaddr_in.h      |   1 +
 include/bits/types/struct_sockaddr_in6.h     |   1 +
 inet/Makefile                                |   5 +-
 inet/bits/types/in_addr_t.h                  |   9 ++
 inet/bits/types/in_port_t.h                  |   9 ++
 inet/bits/types/struct_in6_addr.h            |  30 ++++
 inet/bits/types/struct_in_addr.h             |  18 +++
 inet/bits/types/struct_sockaddr_in.h         |  28 ++++
 inet/bits/types/struct_sockaddr_in6.h        |  25 +++
 inet/netinet/icmp6.h                         |   2 +-
 inet/netinet/igmp.h                          |   2 +-
 inet/netinet/in.h                            | 102 +++++--------
 inet/netinet/ip.h                            |   2 +-
 inet/netinet/ip6.h                           |   2 +-
 inet/netinet/ip_icmp.h                       |   7 +-
 inet/tst-getni1.c                            |   1 +
 inet/tst-getni2.c                            |   1 +
 misc/Makefile                                |   2 +-
 nss/tst-nss-files-hosts-erange.c             |   1 +
 nss/tst-nss-files-hosts-getent.c             |   1 +
 nss/tst-nss-files-hosts-multi.c              |   1 +
 posix/tst-getaddrinfo2.c                     |   1 +
 resolv/bits/types/res_state.h                |   5 +-
 resolv/netdb.h                               |  12 +-
 resolv/resolv.h                              |   1 -
 resolv/tst-bug18665-tcp.c                    |   1 +
 resolv/tst-resolv-ai_idn-common.c            |   1 +
 resolv/tst-resolv-canonname.c                |   1 +
 resolv/tst-resolv-edns.c                     |   1 +
 resolv/tst-resolv-network.c                  |   1 +
 resolv/tst-resolv-nondecimal.c               |   1 +
 resolv/tst-resolv-search.c                   |   1 +
 scripts/check-obsolete-constructs.py         |  20 +--
 socket/bits/types/struct_sockaddr.h          |   2 +-
 support/resolv_test.h                        |   4 +-
 support/tst-support-namespace.c              |   1 +
 sysdeps/mach/hurd/net/route.h                |  15 +-
 sysdeps/unix/bsd/bits/sockaddr.h             |   3 +
 sysdeps/unix/sysv/linux/bits/in.h            |  33 ++--
 sysdeps/unix/sysv/linux/bits/uapi-compat.h   | 153 +++++++++++++++++++
 sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h |   4 +-
 sysdeps/unix/sysv/linux/net/route.h          |   3 +-
 49 files changed, 429 insertions(+), 134 deletions(-)
 create mode 100644 bits/uapi-compat.h
 create mode 100644 include/bits/types/in_addr_t.h
 create mode 100644 include/bits/types/in_port_t.h
 create mode 100644 include/bits/types/struct_in6_addr.h
 create mode 100644 include/bits/types/struct_in_addr.h
 create mode 100644 include/bits/types/struct_sockaddr_in.h
 create mode 100644 include/bits/types/struct_sockaddr_in6.h
 create mode 100644 inet/bits/types/in_addr_t.h
 create mode 100644 inet/bits/types/in_port_t.h
 create mode 100644 inet/bits/types/struct_in6_addr.h
 create mode 100644 inet/bits/types/struct_in_addr.h
 create mode 100644 inet/bits/types/struct_sockaddr_in.h
 create mode 100644 inet/bits/types/struct_sockaddr_in6.h
 create mode 100644 sysdeps/unix/sysv/linux/bits/uapi-compat.h

diff --git a/bits/in.h b/bits/in.h
index 7652bc45d0..cc24174a45 100644
--- a/bits/in.h
+++ b/bits/in.h
@@ -15,15 +15,15 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_IN_H
+#define _BITS_IN_H 1
+
 /* Generic version.  */
 
 #ifndef _NETINET_IN_H
 # error "Never use <bits/in.h> directly; include <netinet/in.h> instead."
 #endif
 
-/* This is the generic version, do not assume a linux-based kernel.  */
-#define __USE_KERNEL_IPV6_DEFS 0
-
 /* To select the IP level.  */
 #define SOL_IP		0
 
@@ -115,3 +115,5 @@ struct ip_opts
 #define IPV6_RTHDR_STRICT	1	/* Hop must be a neighbour.  */
 
 #define IPV6_RTHDR_TYPE_0	0	/* IPv6 Routing header type 0.  */
+
+#endif /* bits/in.h.  */
diff --git a/bits/sockaddr.h b/bits/sockaddr.h
index 2505246ec5..b3434747b3 100644
--- a/bits/sockaddr.h
+++ b/bits/sockaddr.h
@@ -39,4 +39,7 @@ typedef unsigned short int sa_family_t;
 /* Size of struct sockaddr_storage.  */
 #define _SS_SIZE 128
 
+/* Size of struct sockaddr.sa_data.  */
+#define __SOCKADDR_DATA_SIZE 14
+
 #endif	/* bits/sockaddr.h */
diff --git a/bits/uapi-compat.h b/bits/uapi-compat.h
new file mode 100644
index 0000000000..afa9ddd5d3
--- /dev/null
+++ b/bits/uapi-compat.h
@@ -0,0 +1,34 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This header is internal to glibc and should not be included outside
+   of glibc headers.  It is included by each header that needs to make
+   global declarations that may or may not already have been made by a
+   header provided by the underlying operating system kernel.  All such
+   declarations are associated with macros named __UAPI_DEF_something,
+   which have three possible values:
+
+   If __UAPI_DEF_FOO is not defined, nobody has yet declared `foo'.
+   If __UAPI_DEF_FOO is defined to 0, glibc's headers have declared `foo'.
+   If __UAPI_DEF_FOO is defined to 1, the kernel's headers have declared `foo`.
+
+   This header cannot have a multiple-inclusion guard, because it needs
+   to recheck for additional declarations by kernel headers each time
+   a glibc header that uses it is included.
+
+   This generic version of uapi-compat.h is used on operating systems
+   where none of the above coordination is necessary.  */
diff --git a/include/bits/types/in_addr_t.h b/include/bits/types/in_addr_t.h
new file mode 100644
index 0000000000..a894f8bce2
--- /dev/null
+++ b/include/bits/types/in_addr_t.h
@@ -0,0 +1 @@
+#include <inet/bits/types/in_addr_t.h>
diff --git a/include/bits/types/in_port_t.h b/include/bits/types/in_port_t.h
new file mode 100644
index 0000000000..bea5710585
--- /dev/null
+++ b/include/bits/types/in_port_t.h
@@ -0,0 +1 @@
+#include <inet/bits/types/in_port_t.h>
diff --git a/include/bits/types/struct_in6_addr.h b/include/bits/types/struct_in6_addr.h
new file mode 100644
index 0000000000..61c35a118d
--- /dev/null
+++ b/include/bits/types/struct_in6_addr.h
@@ -0,0 +1 @@
+#include <inet/bits/types/struct_in6_addr.h>
diff --git a/include/bits/types/struct_in_addr.h b/include/bits/types/struct_in_addr.h
new file mode 100644
index 0000000000..c0835d01d0
--- /dev/null
+++ b/include/bits/types/struct_in_addr.h
@@ -0,0 +1 @@
+#include <inet/bits/types/struct_in_addr.h>
diff --git a/include/bits/types/struct_sockaddr_in.h b/include/bits/types/struct_sockaddr_in.h
new file mode 100644
index 0000000000..3bf048b832
--- /dev/null
+++ b/include/bits/types/struct_sockaddr_in.h
@@ -0,0 +1 @@
+#include <inet/bits/types/struct_sockaddr_in.h>
diff --git a/include/bits/types/struct_sockaddr_in6.h b/include/bits/types/struct_sockaddr_in6.h
new file mode 100644
index 0000000000..d0c30ec239
--- /dev/null
+++ b/include/bits/types/struct_sockaddr_in6.h
@@ -0,0 +1 @@
+#include <inet/bits/types/struct_sockaddr_in6.h>
diff --git a/inet/Makefile b/inet/Makefile
index a58278a1e1..a4392b6448 100644
--- a/inet/Makefile
+++ b/inet/Makefile
@@ -22,7 +22,10 @@ subdir	:= inet
 
 include ../Makeconfig
 
-headers	:= aliases.h ifaddrs.h bits/in.h				     \
+headers	:= aliases.h ifaddrs.h bits/in.h 				     \
+	   bits/types/in_addr_t.h bits/types/in_port_t.h		     \
+	   bits/types/struct_in_addr.h bits/types/struct_in6_addr.h	     \
+	   bits/types/struct_sockaddr_in.h bits/types/struct_sockaddr_in6.h  \
            netinet/ether.h netinet/icmp6.h netinet/if_ether.h netinet/igmp.h \
            netinet/in.h netinet/in_systm.h netinet/ip.h netinet/ip6.h	     \
 	   netinet/ip_icmp.h netinet/tcp.h netinet/udp.h		     \
diff --git a/inet/bits/types/in_addr_t.h b/inet/bits/types/in_addr_t.h
new file mode 100644
index 0000000000..63779bbd75
--- /dev/null
+++ b/inet/bits/types/in_addr_t.h
@@ -0,0 +1,9 @@
+#ifndef __in_addr_t_defined
+#define __in_addr_t_defined 1
+
+#include <bits/types.h>
+
+/* Type to represent an IPv4 address.  */
+typedef __uint32_t in_addr_t;
+
+#endif
diff --git a/inet/bits/types/in_port_t.h b/inet/bits/types/in_port_t.h
new file mode 100644
index 0000000000..8fa1a02fef
--- /dev/null
+++ b/inet/bits/types/in_port_t.h
@@ -0,0 +1,9 @@
+#ifndef __in_port_t_defined
+#define __in_port_t_defined 1
+
+#include <bits/types.h>
+
+/* Type to represent a TCP or UDP port.  */
+typedef __uint16_t in_port_t;
+
+#endif
diff --git a/inet/bits/types/struct_in6_addr.h b/inet/bits/types/struct_in6_addr.h
new file mode 100644
index 0000000000..5aaea39701
--- /dev/null
+++ b/inet/bits/types/struct_in6_addr.h
@@ -0,0 +1,30 @@
+#ifndef __struct_in6_addr_defined
+#define __struct_in6_addr_defined 1
+
+#include <features.h>
+#include <bits/types.h>
+#include <bits/uapi-compat.h>
+
+/* Kernel headers may already have defined this type.  */
+#if !defined __UAPI_DEF_IN6_ADDR || __UAPI_DEF_IN6_ADDR == 0
+#define __UAPI_DEF_IN6_ADDR 0
+#define __UAPI_DEF_IN6_ADDR_ALT 0
+
+/* Struct representing an IPv6 address.  */
+struct in6_addr
+{
+  union
+  {
+    __uint8_t  __u6_addr8[16];
+    __uint16_t __u6_addr16[8];
+    __uint32_t __u6_addr32[4];
+  } __in6_u;
+#define s6_addr			__in6_u.__u6_addr8
+#ifdef __USE_MISC
+# define s6_addr16		__in6_u.__u6_addr16
+# define s6_addr32		__in6_u.__u6_addr32
+#endif
+};
+
+#endif /* __UAPI_DEF_IN6_ADDR is zero or not defined.  */
+#endif /* struct_in6_addr.h.  */
diff --git a/inet/bits/types/struct_in_addr.h b/inet/bits/types/struct_in_addr.h
new file mode 100644
index 0000000000..0dbe57f0fd
--- /dev/null
+++ b/inet/bits/types/struct_in_addr.h
@@ -0,0 +1,18 @@
+#ifndef __struct_in_addr_defined
+#define __struct_in_addr_defined 1
+
+#include <bits/types/in_addr_t.h>
+#include <bits/uapi-compat.h>
+
+/* Kernel headers may already have defined this type.  */
+#if !defined __UAPI_DEF_IN_ADDR || __UAPI_DEF_IN_ADDR == 0
+#define __UAPI_DEF_IN_ADDR 0
+
+/* Struct representing an IPv4 address.  */
+struct in_addr
+{
+  in_addr_t s_addr;
+};
+
+#endif /* __UAPI_DEF_IN_ADDR is zero or not defined. */
+#endif /* struct_in_addr.h.  */
diff --git a/inet/bits/types/struct_sockaddr_in.h b/inet/bits/types/struct_sockaddr_in.h
new file mode 100644
index 0000000000..f2289eb0c6
--- /dev/null
+++ b/inet/bits/types/struct_sockaddr_in.h
@@ -0,0 +1,28 @@
+#ifndef __struct_sockaddr_in_defined
+#define __struct_sockaddr_in_defined 1
+
+#include <bits/types.h>
+#include <bits/types/struct_in_addr.h>
+#include <bits/types/in_port_t.h>
+#include <bits/sockaddr.h>
+#include <bits/uapi-compat.h>
+
+/* Kernel headers may already have defined this type.  */
+#if !defined __UAPI_DEF_SOCKADDR_IN || __UAPI_DEF_SOCKADDR_IN == 0
+#define __UAPI_DEF_SOCKADDR_IN 0
+
+/* Structure describing an IPv4 socket address.  */
+struct sockaddr_in
+{
+  __SOCKADDR_COMMON (sin_);
+  in_port_t sin_port;			/* Port number.  */
+  struct in_addr sin_addr;		/* IPv4 address.  */
+
+  /* Pad to size of `struct sockaddr'.  */
+  unsigned char sin_zero[__SOCKADDR_DATA_SIZE
+                         - sizeof (in_port_t)
+                         - sizeof (struct in_addr)];
+};
+
+#endif /* __UAPI_DEF_SOCKADDR_IN is zero or not defined.  */
+#endif /* struct_sockaddr_in.h.  */
diff --git a/inet/bits/types/struct_sockaddr_in6.h b/inet/bits/types/struct_sockaddr_in6.h
new file mode 100644
index 0000000000..7af109fc1e
--- /dev/null
+++ b/inet/bits/types/struct_sockaddr_in6.h
@@ -0,0 +1,25 @@
+#ifndef __struct_sockaddr_in6_defined
+#define __struct_sockaddr_in6_defined 1
+
+#include <bits/types.h>
+#include <bits/types/struct_in6_addr.h>
+#include <bits/types/in_port_t.h>
+#include <bits/sockaddr.h>
+#include <bits/uapi-compat.h>
+
+/* Kernel headers may already have defined this type.  */
+#if !defined __UAPI_DEF_SOCKADDR_IN6 || __UAPI_DEF_SOCKADDR_IN6 == 0
+#define __UAPI_DEF_SOCKADDR_IN6 0
+
+/* Structure describing an IPv6 socket address.  */
+struct sockaddr_in6
+{
+  __SOCKADDR_COMMON (sin6_);
+  in_port_t sin6_port;		/* Transport layer port # */
+  uint32_t sin6_flowinfo;	/* IPv6 flow information */
+  struct in6_addr sin6_addr;	/* IPv6 address */
+  uint32_t sin6_scope_id;	/* IPv6 scope-id */
+};
+
+#endif /* __UAPI_DEF_SOCKADDR_IN6 is zero or not defined.  */
+#endif /* struct_sockaddr_in6.h.  */
diff --git a/inet/netinet/icmp6.h b/inet/netinet/icmp6.h
index 5119085391..4e5da1d9ae 100644
--- a/inet/netinet/icmp6.h
+++ b/inet/netinet/icmp6.h
@@ -22,7 +22,7 @@
 #include <bits/endian.h>
 #include <bits/types.h>
 #include <bits/types/size_t.h>
-#include <netinet/in.h>
+#include <bits/types/struct_in6_addr.h>
 
 #define ICMP6_FILTER 1
 
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 6eafc19a73..6a599d347d 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -22,8 +22,8 @@
 
 #ifdef __USE_MISC
 
-#include <netinet/in.h>
 #include <bits/types.h>
+#include <bits/types/struct_in_addr.h>
 
 __BEGIN_DECLS
 
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index b7a1d6a2e8..d691bd31b1 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -19,24 +19,28 @@
 #define	_NETINET_IN_H	1
 
 #include <features.h>
+
 #include <bits/types.h>
 #include <bits/stdint-uintn.h>
 #include <bits/sockaddr.h>
+#include <bits/uapi-compat.h>
+
+#include <bits/types/in_addr_t.h>
+#include <bits/types/in_port_t.h>
+#include <bits/types/struct_in_addr.h>
+#include <bits/types/struct_in6_addr.h>
 #include <bits/types/struct_sockaddr.h>
+#include <bits/types/struct_sockaddr_in.h>
+#include <bits/types/struct_sockaddr_in6.h>
 #include <bits/types/struct_sockaddr_storage.h>
 
-__BEGIN_DECLS
-
-/* Internet address.  */
-typedef uint32_t in_addr_t;
-struct in_addr
-  {
-    in_addr_t s_addr;
-  };
-
 /* Get system-specific definitions.  */
 #include <bits/in.h>
 
+__BEGIN_DECLS
+
+#if !defined __UAPI_DEF_IN_IPPROTO || __UAPI_DEF_IN_IPPROTO == 0
+#define __UAPI_DEF_IN_IPPROTO 0
 /* Standard well-defined IP protocols.  */
 enum
   {
@@ -92,11 +96,10 @@ enum
 #define IPPROTO_RAW		IPPROTO_RAW
     IPPROTO_MAX
   };
+#endif
 
-/* If __USE_KERNEL_IPV6_DEFS is 1 then the user has included the kernel
-   network headers first and we should use those ABI-identical definitions
-   instead of our own, otherwise 0.  */
-#if !__USE_KERNEL_IPV6_DEFS
+#if !defined __UAPI_DEF_IPPROTO_V6 || __UAPI_DEF_IPPROTO_V6 == 0
+#define __UAPI_DEF_IPPROTO_V6 0
 enum
   {
     IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
@@ -114,10 +117,7 @@ enum
     IPPROTO_MH = 135       /* IPv6 mobility header.  */
 #define IPPROTO_MH		IPPROTO_MH
   };
-#endif /* !__USE_KERNEL_IPV6_DEFS */
-
-/* Type to represent a port.  */
-typedef uint16_t in_port_t;
+#endif
 
 /* Standard well-known ports.  */
 enum
@@ -153,7 +153,10 @@ enum
     IPPORT_ROUTESERVER = 520,
 
     /* Ports less than this value are reserved for privileged processes.  */
+#ifndef IPPORT_RESERVED /* also defined in netdb.h */
     IPPORT_RESERVED = 1024,
+#define IPPORT_RESERVED IPPORT_RESERVED
+#endif
 
     /* Ports greater this value are reserved for (non-privileged) servers.  */
     IPPORT_USERRESERVED = 5000
@@ -163,6 +166,8 @@ enum
 
    On subnets, host and network parts are found according to
    the subnet mask, not these masks.  */
+#if !defined __UAPI_DEF_IN_CLASS || __UAPI_DEF_IN_CLASS == 0
+#define __UAPI_DEF_IN_CLASS 0
 
 #define	IN_CLASSA(a)		((((in_addr_t)(a)) & 0x80000000) == 0)
 #define	IN_CLASSA_NET		0xff000000
@@ -200,6 +205,7 @@ enum
 #ifndef INADDR_LOOPBACK
 # define INADDR_LOOPBACK	((in_addr_t) 0x7f000001) /* Inet 127.0.0.1.  */
 #endif
+#define	IN_LOOPBACK(a)		((((in_addr_t) (a)) & 0xff000000) == 0x7f000000)
 
 /* Defines for Multicast INADDR.  */
 #define INADDR_UNSPEC_GROUP	((in_addr_t) 0xe0000000) /* 224.0.0.0 */
@@ -207,24 +213,7 @@ enum
 #define INADDR_ALLRTRS_GROUP    ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
 #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) /* 224.0.0.106 */
 #define INADDR_MAX_LOCAL_GROUP  ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
-
-#if !__USE_KERNEL_IPV6_DEFS
-/* IPv6 address */
-struct in6_addr
-  {
-    union
-      {
-	uint8_t	__u6_addr8[16];
-	uint16_t __u6_addr16[8];
-	uint32_t __u6_addr32[4];
-      } __in6_u;
-#define s6_addr			__in6_u.__u6_addr8
-#ifdef __USE_MISC
-# define s6_addr16		__in6_u.__u6_addr16
-# define s6_addr32		__in6_u.__u6_addr32
-#endif
-  };
-#endif /* !__USE_KERNEL_IPV6_DEFS */
+#endif /* __UAPI_DEF_IN_CLASS is zero or not defined */
 
 extern const struct in6_addr in6addr_any;        /* :: */
 extern const struct in6_addr in6addr_loopback;   /* ::1 */
@@ -234,34 +223,9 @@ extern const struct in6_addr in6addr_loopback;   /* ::1 */
 #define INET_ADDRSTRLEN 16
 #define INET6_ADDRSTRLEN 46
 
-
-/* Structure describing an Internet socket address.  */
-struct sockaddr_in
-  {
-    __SOCKADDR_COMMON (sin_);
-    in_port_t sin_port;			/* Port number.  */
-    struct in_addr sin_addr;		/* Internet address.  */
-
-    /* Pad to size of `struct sockaddr'.  */
-    unsigned char sin_zero[sizeof (struct sockaddr)
-			   - __SOCKADDR_COMMON_SIZE
-			   - sizeof (in_port_t)
-			   - sizeof (struct in_addr)];
-  };
-
-#if !__USE_KERNEL_IPV6_DEFS
-/* Ditto, for IPv6.  */
-struct sockaddr_in6
-  {
-    __SOCKADDR_COMMON (sin6_);
-    in_port_t sin6_port;	/* Transport layer port # */
-    uint32_t sin6_flowinfo;	/* IPv6 flow information */
-    struct in6_addr sin6_addr;	/* IPv6 address */
-    uint32_t sin6_scope_id;	/* IPv6 scope-id */
-  };
-#endif /* !__USE_KERNEL_IPV6_DEFS */
-
 #ifdef __USE_MISC
+#if !defined __UAPI_DEF_IP_MREQ || __UAPI_DEF_IP_MREQ == 0
+#define __UAPI_DEF_IP_MREQ 0
 /* IPv4 multicast request.  */
 struct ip_mreq
   {
@@ -284,8 +248,10 @@ struct ip_mreq_source
     struct in_addr imr_sourceaddr;
   };
 #endif
+#endif
 
-#if !__USE_KERNEL_IPV6_DEFS
+#if !defined __UAPI_DEF_IPV6_MREQ || __UAPI_DEF_IP_MREQ == 0
+#define __UAPI_DEF_IPV6_MREQ 0
 /* Likewise, for IPv6.  */
 struct ipv6_mreq
   {
@@ -295,7 +261,7 @@ struct ipv6_mreq
     /* local interface */
     unsigned int ipv6mr_interface;
   };
-#endif /* !__USE_KERNEL_IPV6_DEFS */
+#endif
 
 #ifdef __USE_MISC
 /* Multicast group request.  */
@@ -533,21 +499,25 @@ extern int bindresvport6 (int __sockfd, struct sockaddr_in6 *__sock_in)
 #ifdef __USE_GNU
 struct cmsghdr;			/* Forward declaration.  */
 
-#if !__USE_KERNEL_IPV6_DEFS
+#if !defined __UAPI_DEF_IN6_PKTINFO || __UAPI_DEF_IN6_PKTINFO == 0
+#define __UAPI_DEF_IN6_PKTINFO 0
 /* IPv6 packet information.  */
 struct in6_pktinfo
   {
     struct in6_addr ipi6_addr;	/* src/dst IPv6 address */
     unsigned int ipi6_ifindex;	/* send/recv interface index */
   };
+#endif
 
+#if !defined __UAPI_DEF_IN6_MTUINFO || __UAPI_DEF_IN6_MTUINFO == 0
+#define __UAPI_DEF_IN6_MTUINFO 0
 /* IPv6 MTU information.  */
 struct ip6_mtuinfo
   {
     struct sockaddr_in6 ip6m_addr; /* dst address including zone ID */
     uint32_t ip6m_mtu;		   /* path MTU in host byte order */
   };
-#endif /* !__USE_KERNEL_IPV6_DEFS */
+#endif
 
 /* Obsolete hop-by-hop and Destination Options Processing (RFC 2292).  */
 extern int inet6_option_space (int __nbytes)
diff --git a/inet/netinet/ip.h b/inet/netinet/ip.h
index fa6b588c42..a3beca86b9 100644
--- a/inet/netinet/ip.h
+++ b/inet/netinet/ip.h
@@ -20,9 +20,9 @@
 
 #include <features.h>
 
-#include <netinet/in.h>
 #include <bits/endian.h>
 #include <bits/types.h>
+#include <bits/types/struct_in_addr.h>
 
 __BEGIN_DECLS
 
diff --git a/inet/netinet/ip6.h b/inet/netinet/ip6.h
index e2a8d2b356..b16e093394 100644
--- a/inet/netinet/ip6.h
+++ b/inet/netinet/ip6.h
@@ -19,9 +19,9 @@
 #define _NETINET_IP6_H 1
 
 #include <features.h>
-#include <netinet/in.h>
 #include <bits/endian.h>
 #include <bits/types.h>
+#include <bits/types/struct_in6_addr.h>
 
 struct ip6_hdr
   {
diff --git a/inet/netinet/ip_icmp.h b/inet/netinet/ip_icmp.h
index da7ff3b81b..54660e792b 100644
--- a/inet/netinet/ip_icmp.h
+++ b/inet/netinet/ip_icmp.h
@@ -20,6 +20,10 @@
 
 #include <features.h>
 #include <bits/types.h>
+#ifdef __USE_MISC
+#include <bits/types/struct_in_addr.h>
+#include <netinet/ip.h>
+#endif
 
 __BEGIN_DECLS
 
@@ -122,9 +126,6 @@ struct icmphdr
  *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
  */
 
-#include <netinet/in.h>
-#include <netinet/ip.h>
-
 /*
  * Internal of an ICMP Router Advertisement
  */
diff --git a/inet/tst-getni1.c b/inet/tst-getni1.c
index 3960f7112e..154ee200e6 100644
--- a/inet/tst-getni1.c
+++ b/inet/tst-getni1.c
@@ -1,6 +1,7 @@
 #include <netdb.h>
 #include <stdio.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 
 static int
 do_test (void)
diff --git a/inet/tst-getni2.c b/inet/tst-getni2.c
index 66e78062ba..0811e40a24 100644
--- a/inet/tst-getni2.c
+++ b/inet/tst-getni2.c
@@ -1,6 +1,7 @@
 #include <netdb.h>
 #include <stdio.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 
 static int
 do_test (void)
diff --git a/misc/Makefile b/misc/Makefile
index 106ce57776..6c0e4b4ede 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -33,7 +33,7 @@ headers :=								\
 	bits/mman.h bits/param.h bits/select.h bits/select2.h		\
 	bits/stab.def bits/syslog-ldbl.h bits/syslog-path.h		\
 	bits/syslog.h bits/sysmacros.h bits/types/struct_iovec.h	\
-	bits/uio-ext.h bits/uio_lim.h bits/xopen_lim.h			\
+	bits/uapi-compat.h bits/uio-ext.h bits/uio_lim.h bits/xopen_lim.h \
 	gnu/libc-version.h						\
 	sys/auxv.h sys/cdefs.h sys/dir.h sys/file.h sys/ioctl.h		\
 	sys/mman.h sys/mtio.h sys/param.h sys/ptrace.h sys/queue.h	\
diff --git a/nss/tst-nss-files-hosts-erange.c b/nss/tst-nss-files-hosts-erange.c
index bf77e23639..6b500cf617 100644
--- a/nss/tst-nss-files-hosts-erange.c
+++ b/nss/tst-nss-files-hosts-erange.c
@@ -23,6 +23,7 @@
 #include <netdb.h>
 #include <nss.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/nss/tst-nss-files-hosts-getent.c b/nss/tst-nss-files-hosts-getent.c
index 001f6f1ede..3ba740c397 100644
--- a/nss/tst-nss-files-hosts-getent.c
+++ b/nss/tst-nss-files-hosts-getent.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/nss/tst-nss-files-hosts-multi.c b/nss/tst-nss-files-hosts-multi.c
index 4862e84257..2467bdd291 100644
--- a/nss/tst-nss-files-hosts-multi.c
+++ b/nss/tst-nss-files-hosts-multi.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/posix/tst-getaddrinfo2.c b/posix/tst-getaddrinfo2.c
index d8be4a8e8f..d0913790a9 100644
--- a/posix/tst-getaddrinfo2.c
+++ b/posix/tst-getaddrinfo2.c
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 
 static int
 do_test (void)
diff --git a/resolv/bits/types/res_state.h b/resolv/bits/types/res_state.h
index 81febe13b0..274e6a0a01 100644
--- a/resolv/bits/types/res_state.h
+++ b/resolv/bits/types/res_state.h
@@ -2,7 +2,10 @@
 #define __res_state_defined 1
 
 #include <bits/types.h>
-#include <netinet/in.h>
+#include <bits/types/struct_in_addr.h>
+#include <bits/types/struct_sockaddr_in.h>
+
+struct sockaddr_in6;
 
 /* res_state: the global state used by the resolver stub.  */
 #define MAXNS			3	/* max # name servers we'll track */
diff --git a/resolv/netdb.h b/resolv/netdb.h
index 1158864312..2be4ff9afa 100644
--- a/resolv/netdb.h
+++ b/resolv/netdb.h
@@ -24,7 +24,6 @@
 
 #include <features.h>
 
-#include <netinet/in.h>
 #include <bits/types/socklen_t.h>
 #include <bits/stdint-uintn.h>
 #ifdef __USE_MISC
@@ -77,7 +76,10 @@ extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
 
 #if defined __USE_XOPEN2K || defined __USE_XOPEN_EXTENDED
 /* Highest reserved Internet port number.  */
-# define IPPORT_RESERVED	1024
+# ifndef IPPORT_RESERVED /* also defined in netinet/in.h */
+enum { IPPORT_RESERVED = 1024 };
+#  define IPPORT_RESERVED IPPORT_RESERVED
+# endif
 #endif
 
 #ifdef __USE_GNU
@@ -133,7 +135,7 @@ extern struct hostent *gethostent (void);
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
-extern struct hostent *gethostbyaddr (const void *__addr, __socklen_t __len,
+extern struct hostent *gethostbyaddr (const void *__addr, socklen_t __len,
 				      int __type);
 
 /* Return entry from host data base for host with NAME.
@@ -168,7 +170,7 @@ extern int gethostent_r (struct hostent *__restrict __result_buf,
 			 struct hostent **__restrict __result,
 			 int *__restrict __h_errnop);
 
-extern int gethostbyaddr_r (const void *__restrict __addr, __socklen_t __len,
+extern int gethostbyaddr_r (const void *__restrict __addr, socklen_t __len,
 			    int __type,
 			    struct hostent *__restrict __result_buf,
 			    char *__restrict __buf, size_t __buflen,
@@ -436,6 +438,8 @@ extern int getnetgrent_r (char **__restrict __hostp,
 
 
 #ifdef __USE_MISC
+#include <bits/sockaddr.h> /* for sa_family_t */
+
 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
    The local user is LOCUSER, on the remote machine the command is
    executed as REMUSER.  In *FD2P the descriptor to the socket for the
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 5783de697d..c29a92ec8a 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -54,7 +54,6 @@
 
 #include <features.h>
 
-#include <netinet/in.h>
 #include <arpa/nameser.h>
 
 #include <bits/types.h>
diff --git a/resolv/tst-bug18665-tcp.c b/resolv/tst-bug18665-tcp.c
index 090ae0a86b..5760afa837 100644
--- a/resolv/tst-bug18665-tcp.c
+++ b/resolv/tst-bug18665-tcp.c
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-ai_idn-common.c b/resolv/tst-resolv-ai_idn-common.c
index f560ccf5cd..dcc01852c2 100644
--- a/resolv/tst-resolv-ai_idn-common.c
+++ b/resolv/tst-resolv-ai_idn-common.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-canonname.c b/resolv/tst-resolv-canonname.c
index 7379eee643..7da72a224b 100644
--- a/resolv/tst-resolv-canonname.c
+++ b/resolv/tst-resolv-canonname.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <gnu/lib-names.h>
 #include <netdb.h>
+#include <netinet/in.h>
 #include <nss.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/resolv/tst-resolv-edns.c b/resolv/tst-resolv-edns.c
index e88463ddff..fff61b063d 100644
--- a/resolv/tst-resolv-edns.c
+++ b/resolv/tst-resolv-edns.c
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 #include <support/support.h>
diff --git a/resolv/tst-resolv-network.c b/resolv/tst-resolv-network.c
index c4609a4db5..93fa4eeef4 100644
--- a/resolv/tst-resolv-network.c
+++ b/resolv/tst-resolv-network.c
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-nondecimal.c b/resolv/tst-resolv-nondecimal.c
index 61888eadd9..ffe9bfc00a 100644
--- a/resolv/tst-resolv-nondecimal.c
+++ b/resolv/tst-resolv-nondecimal.c
@@ -19,6 +19,7 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-search.c b/resolv/tst-resolv-search.c
index bca1e1312d..9672012186 100644
--- a/resolv/tst-resolv-search.c
+++ b/resolv/tst-resolv-search.c
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 2ca83b90c7..95360158b5 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -538,10 +538,10 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/types.h":                 [ "endian.h" ],
 
     # POSIX networking headers
-    # allowed: netdb.h -> netinet/in.h
-    #          arpa/inet.h -> netinet/in.h
-    "netdb.h":                     [ "netinet/in.h", "rpc/netdb.h" ],
+    # POSIX allows arpa/inet.h -> netinet/in.h
     "arpa/inet.h":                 [ "netinet/in.h" ],
+    # necessary for backward compatibility with Sun RPC
+    "netdb.h":                     [ "rpc/netdb.h" ],
 
     # Nonstandardized top-level headers
     "argp.h":                      [ "ctype.h", "errno.h", "getopt.h",
@@ -603,27 +603,20 @@ HEADER_ALLOWED_INCLUDES = {
     "wait.h":                      [ "sys/wait.h" ],
 
     # Nonstandardized networking headers
-
-    "resolv.h":                    [ "arpa/nameser.h", "netinet/in.h" ],
+    "resolv.h":                    [ "arpa/nameser.h" ],
     "arpa/nameser.h":              [ "arpa/nameser_compat.h" ],
 
     "net/ethernet.h":              [ "net/if_ether.h" ],
     "net/if_ppp.h":                [ "net/if.h", "net/ppp_defs.h",
                                      "sys/ioctl.h" ],
     "net/if_shaper.h":             [ "net/if.h", "sys/ioctl.h" ],
-    "net/route.h":                 [ "netinet/in.h" ],
     "netatalk/at.h":               [ "sys/ioctl.h" ],
-
     "netinet/ether.h":             [ "netinet/if_ether.h" ],
-    "netinet/icmp6.h":             [ "netinet/in.h" ],
     "netinet/if_ether.h":          [ "net/ethernet.h", "net/if_arp.h" ],
-    "netinet/igmp.h":              [ "netinet/in.h" ],
-    "netinet/ip.h":                [ "netinet/in.h" ],
-    "netinet/ip6.h":               [ "netinet/in.h" ],
-    "netinet/ip_icmp.h":           [ "netinet/in.h", "netinet/ip.h" ],
-
+    "netinet/ip_icmp.h":           [ "netinet/ip.h" ],
     "netrom/netrom.h":             [ "netax25/ax25.h" ],
     "netrose/rose.h":              [ "netax25/ax25.h" ],
+
     "protocols/rwhod.h":           [ "paths.h" ],
 
     # Internal headers
@@ -631,7 +624,6 @@ HEADER_ALLOWED_INCLUDES = {
                                      "sys/cdefs.h" ],
 
     "bits/procfs.h":               [ "signal.h", "sys/ucontext.h" ],
-    "bits/types/res_state.h":      [ "netinet/in.h" ],
 
     "bits/types/__va_list.h":      [ "stdarg.h" ],
     "bits/types/ptrdiff_t.h":      [ "stddef.h" ],
diff --git a/socket/bits/types/struct_sockaddr.h b/socket/bits/types/struct_sockaddr.h
index 86100142ca..34863beb05 100644
--- a/socket/bits/types/struct_sockaddr.h
+++ b/socket/bits/types/struct_sockaddr.h
@@ -9,7 +9,7 @@
 struct sockaddr
   {
     __SOCKADDR_COMMON (sa_);	/* Common data: family and perhaps length.  */
-    char sa_data[14];		/* Address data.  */
+    char sa_data[__SOCKADDR_DATA_SIZE];	/* Address data.  */
   };
 
 #endif
diff --git a/support/resolv_test.h b/support/resolv_test.h
index c9e48205ab..1557c51ee3 100644
--- a/support/resolv_test.h
+++ b/support/resolv_test.h
@@ -19,9 +19,9 @@
 #ifndef SUPPORT_RESOLV_TEST_H
 #define SUPPORT_RESOLV_TEST_H
 
-#include <arpa/nameser.h>
 #include <stdbool.h>
-#include <sys/cdefs.h>
+#include <stdint.h>
+#include <arpa/nameser.h>
 
 __BEGIN_DECLS
 
diff --git a/support/tst-support-namespace.c b/support/tst-support-namespace.c
index 02d9638e8c..d6338453f5 100644
--- a/support/tst-support-namespace.c
+++ b/support/tst-support-namespace.c
@@ -23,6 +23,7 @@
 #include <support/namespace.h>
 #include <support/xsocket.h>
 #include <support/xunistd.h>
+#include <netinet/in.h>
 
 /* Check that the loopback interface provides multiple addresses which
    can be used to run independent servers.  */
diff --git a/sysdeps/mach/hurd/net/route.h b/sysdeps/mach/hurd/net/route.h
index d288475426..666b7ab0f2 100644
--- a/sysdeps/mach/hurd/net/route.h
+++ b/sysdeps/mach/hurd/net/route.h
@@ -22,8 +22,9 @@
 
 #include <features.h>
 
+#include <bits/types.h>
 #include <bits/types/struct_sockaddr.h>
-#include <netinet/in.h>
+#include <bits/types/struct_in6_addr.h>
 
 
 /* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */
@@ -54,12 +55,12 @@ struct in6_rtmsg
     struct in6_addr rtmsg_dst;
     struct in6_addr rtmsg_src;
     struct in6_addr rtmsg_gateway;
-    uint32_t rtmsg_type;
-    uint16_t rtmsg_dst_len;
-    uint16_t rtmsg_src_len;
-    uint32_t rtmsg_metric;
+    __uint32_t rtmsg_type;
+    __uint16_t rtmsg_dst_len;
+    __uint16_t rtmsg_src_len;
+    __uint32_t rtmsg_metric;
     unsigned long int rtmsg_info;
-    uint32_t rtmsg_flags;
+    __uint32_t rtmsg_flags;
     int rtmsg_ifindex;
   };
 
@@ -108,7 +109,7 @@ struct in6_rtmsg
 #define RTF_NAT		0x08000000
 
 #define RTF_ADDRCLASSMASK	0xF8000000
-#define RT_ADDRCLASS(flags)	((uint32_t) flags >> 23)
+#define RT_ADDRCLASS(flags)	((__uint32_t) flags >> 23)
 
 #define RT_TOS(tos)		((tos) & IPTOS_TOS_MASK)
 
diff --git a/sysdeps/unix/bsd/bits/sockaddr.h b/sysdeps/unix/bsd/bits/sockaddr.h
index 723aaf3e3d..c4a3983ea3 100644
--- a/sysdeps/unix/bsd/bits/sockaddr.h
+++ b/sysdeps/unix/bsd/bits/sockaddr.h
@@ -51,4 +51,7 @@ typedef unsigned char sa_family_t;
 # define __ss_aligntype __uint32_t
 #endif
 
+/* Size of struct sockaddr.sa_data.  */
+#define __SOCKADDR_DATA_SIZE 14
+
 #endif	/* bits/sockaddr.h */
diff --git a/sysdeps/unix/sysv/linux/bits/in.h b/sysdeps/unix/sysv/linux/bits/in.h
index 71300fb81e..66a9f4d39c 100644
--- a/sysdeps/unix/sysv/linux/bits/in.h
+++ b/sysdeps/unix/sysv/linux/bits/in.h
@@ -15,32 +15,15 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_IN_H
+#define _BITS_IN_H 1
+
 /* Linux version.  */
 
 #ifndef _NETINET_IN_H
 # error "Never use <bits/in.h> directly; include <netinet/in.h> instead."
 #endif
 
-/* If the application has already included linux/in6.h from a linux-based
-   kernel then we will not define the IPv6 IPPROTO_* defines, in6_addr (nor the
-   defines), sockaddr_in6, or ipv6_mreq. Same for in6_ptkinfo or ip6_mtuinfo
-   in linux/ipv6.h. The ABI used by the linux-kernel and glibc match exactly.
-   Neither the linux kernel nor glibc should break this ABI without coordination.
-   In upstream kernel 56c176c9 the _UAPI prefix was stripped so we need to check
-   for _LINUX_IN6_H and _IPV6_H now, and keep checking the old versions for
-   maximum backwards compatibility.  */
-#if defined _UAPI_LINUX_IN6_H \
-    || defined _UAPI_IPV6_H \
-    || defined _LINUX_IN6_H \
-    || defined _IPV6_H
-/* This is not quite the same API since the kernel always defines s6_addr16 and
-   s6_addr32. This is not a violation of POSIX since POSIX says "at least the
-   following member" and that holds true.  */
-# define __USE_KERNEL_IPV6_DEFS 1
-#else
-# define __USE_KERNEL_IPV6_DEFS 0
-#endif
-
 /* Options for use with `getsockopt' and `setsockopt' at the IP level.
    The first word in the comment at the right is the data type used;
    "bool" means a boolean value stored in an `int'.  */
@@ -233,9 +216,11 @@ struct in_pktinfo
 #define IPV6_FREEBIND		78
 
 /* Obsolete synonyms for the above.  */
-#if !__USE_KERNEL_IPV6_DEFS
-# define IPV6_ADD_MEMBERSHIP	IPV6_JOIN_GROUP
-# define IPV6_DROP_MEMBERSHIP	IPV6_LEAVE_GROUP
+#ifndef IPV6_ADD_MEMBERSHIP
+#define IPV6_ADD_MEMBERSHIP	IPV6_JOIN_GROUP
+#endif
+#ifndef IPV6_DROP_MEMBERSHIP
+#define IPV6_DROP_MEMBERSHIP	IPV6_LEAVE_GROUP
 #endif
 #define IPV6_RXHOPOPTS		IPV6_HOPOPTS
 #define IPV6_RXDSTOPTS		IPV6_DSTOPTS
@@ -257,3 +242,5 @@ struct in_pktinfo
 #define IPV6_RTHDR_STRICT	1	/* Hop must be a neighbour.  */
 
 #define IPV6_RTHDR_TYPE_0	0	/* IPv6 Routing header type 0.  */
+
+#endif /* bits/in.h.  */
diff --git a/sysdeps/unix/sysv/linux/bits/uapi-compat.h b/sysdeps/unix/sysv/linux/bits/uapi-compat.h
new file mode 100644
index 0000000000..08f85a61e7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/bits/uapi-compat.h
@@ -0,0 +1,153 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This header is internal to glibc and should not be included outside
+   of glibc headers.  It is included by each header that needs to make
+   global declarations that may or may not already have been made by a
+   header provided by the underlying operating system kernel.  All such
+   declarations are associated with macros named __UAPI_DEF_something,
+   which have three possible values:
+
+   If __UAPI_DEF_FOO is not defined, nobody has yet declared `foo'.
+   If __UAPI_DEF_FOO is defined to 0, glibc's headers have declared `foo'.
+   If __UAPI_DEF_FOO is defined to 1, the kernel's headers have declared `foo`.
+
+   This header cannot have a multiple-inclusion guard, because it needs
+   to recheck for additional declarations by kernel headers each time
+   a glibc header that uses it is included.
+
+   This version of uapi-compat.h is used for Linux.  Sufficiently new
+   versions of the Linux kernel headers will define the __UAPI_DEF_*
+   macros themselves; this header's job is to preserve compatibility
+   with older versions of the headers that don't do this.
+
+   The guard macros on many of Linux's UAPI headers were changed in
+   kernel rev 56c176c9; we need to check them both with and without a
+   _UAPI_ prefix.  */
+
+#if defined _UAPI_LINUX_IF_H || defined _LINUX_IF_H
+
+#ifndef __UAPI_DEF_IF_IFCONF
+#define __UAPI_DEF_IF_IFCONF 1
+#endif
+#ifndef __UAPI_DEF_IF_IFMAP
+#define __UAPI_DEF_IF_IFMAP 1
+#endif
+#ifndef __UAPI_DEF_IF_IFNAMSIZ
+#define __UAPI_DEF_IF_IFNAMSIZ 1
+#endif
+#ifndef __UAPI_DEF_IF_IFREQ
+#define __UAPI_DEF_IF_IFREQ 1
+#endif
+#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
+#endif
+#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
+#endif
+
+#endif /* linux/if.h */
+
+#if defined _UAPI_LINUX_IN_H || defined _LINUX_IN_H
+
+#ifndef __UAPI_DEF_IN_ADDR
+#define __UAPI_DEF_IN_ADDR		1
+#endif
+#ifndef __UAPI_DEF_IN_IPPROTO
+#define __UAPI_DEF_IN_IPPROTO		1
+#endif
+#ifndef __UAPI_DEF_IN_PKTINFO
+#define __UAPI_DEF_IN_PKTINFO		1
+#endif
+#ifndef __UAPI_DEF_IP_MREQ
+#define __UAPI_DEF_IP_MREQ		1
+#endif
+#ifndef __UAPI_DEF_SOCKADDR_IN
+#define __UAPI_DEF_SOCKADDR_IN		1
+#endif
+#ifndef __UAPI_DEF_IN_CLASS
+#define __UAPI_DEF_IN_CLASS		1
+#endif
+
+#endif /* linux/in.h  */
+
+#if defined _UAPI_LINUX_IN6_H || defined _LINUX_IN6_H
+
+#ifndef __UAPI_DEF_IN6_ADDR
+#define __UAPI_DEF_IN6_ADDR 1
+#endif
+#ifndef __UAPI_DEF_IN6_ADDR_ALT
+# if defined __USE_MISC || defined __USE_GNU
+#  define __UAPI_DEF_IN6_ADDR_ALT 1
+# else
+#  define __UAPI_DEF_IN6_ADDR_ALT 0
+# endif
+#endif
+#ifndef __UAPI_DEF_SOCKADDR_IN6
+#define __UAPI_DEF_SOCKADDR_IN6 1
+#endif
+#ifndef __UAPI_DEF_IPV6_MREQ
+#define __UAPI_DEF_IPV6_MREQ 1
+#endif
+#ifndef __UAPI_DEF_IPPROTO_V6
+#define __UAPI_DEF_IPPROTO_V6 1
+#endif
+#ifndef __UAPI_DEF_IPV6_OPTIONS
+#define __UAPI_DEF_IPV6_OPTIONS 1
+#endif
+
+#endif /* linux/in6.h */
+
+#if defined _UAPI_IPV6_H || defined _IPV6_H
+
+#ifndef __UAPI_DEF_IN6_PKTINFO
+#define __UAPI_DEF_IN6_PKTINFO 1
+#endif
+#ifndef __UAPI_DEF_IP6_MTUINFO
+#define __UAPI_DEF_IP6_MTUINFO 1
+#endif
+
+#endif /* linux/ipv6.h */
+
+#if defined _UAPI_IPX_H_ || defined _IPX_H_
+
+#ifndef __UAPI_DEF_SOCKADDR_IPX
+#define __UAPI_DEF_SOCKADDR_IPX			1
+#endif
+#ifndef __UAPI_DEF_IPX_ROUTE_DEFINITION
+#define __UAPI_DEF_IPX_ROUTE_DEFINITION		1
+#endif
+#ifndef __UAPI_DEF_IPX_INTERFACE_DEFINITION
+#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	1
+#endif
+#ifndef __UAPI_DEF_IPX_CONFIG_DATA
+#define __UAPI_DEF_IPX_CONFIG_DATA		1
+#endif
+#ifndef __UAPI_DEF_IPX_ROUTE_DEF
+#define __UAPI_DEF_IPX_ROUTE_DEF		1
+#endif
+
+#endif /* linux/ipx.h */
+
+#if defined _UAPI_LINUX_XATTR_H || defined _LINUX_XATTR_H \
+ || defined __USE_KERNEL_XATTR_DEFS
+
+#ifndef __UAPI_DEF_XATTR
+#define __UAPI_DEF_XATTR		1
+#endif
+
+#endif /* linux/xattr.h */
diff --git a/sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h b/sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h
index 15f5504755..8956ea7a0f 100644
--- a/sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h
+++ b/sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h
@@ -23,7 +23,6 @@
 #ifndef _BITS_SOCKADDR_H
 #define _BITS_SOCKADDR_H	1
 
-
 /* POSIX.1g specifies this type name for the `sa_family' member.  */
 typedef unsigned short int sa_family_t;
 
@@ -39,4 +38,7 @@ typedef unsigned short int sa_family_t;
 /* Size of struct sockaddr_storage.  */
 #define _SS_SIZE 126
 
+/* Size of struct sockaddr.sa_data.  */
+#define __SOCKADDR_DATA_SIZE 14
+
 #endif	/* bits/sockaddr.h */
diff --git a/sysdeps/unix/sysv/linux/net/route.h b/sysdeps/unix/sysv/linux/net/route.h
index edd4afd3b2..380f5d3759 100644
--- a/sysdeps/unix/sysv/linux/net/route.h
+++ b/sysdeps/unix/sysv/linux/net/route.h
@@ -23,11 +23,10 @@
 #include <features.h>
 
 #include <bits/types.h>
+#include <bits/types/struct_in6_addr.h>
 #include <bits/types/struct_sockaddr.h>
 #include <bits/wordsize.h>
 
-#include <netinet/in.h>
-
 /* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */
 struct rtentry
   {
-- 
2.20.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 13/25] Split up endian.h to minimize exposure of BYTE_ORDER.
  2019-06-26 17:50 ` [PATCH 13/25] Split up endian.h to minimize exposure of BYTE_ORDER Zack Weinberg
@ 2019-07-24 21:14   ` Joseph Myers
  0 siblings, 0 replies; 17+ messages in thread
From: Joseph Myers @ 2019-07-24 21:14 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: libc-alpha, carlos

On Wed, 26 Jun 2019, Zack Weinberg wrote:

>  - The C-SKY port does not fully support big-endian mode, but I do
>    not think this is sufficient reason to make csky/bits/endian(ness).h
>    error out if __CSKYBE__ is defined, so it now defines __BYTE_ORDER
>    appropriately for whichever mode the compiler is in.

The general principle here is that we have a defined set of known ABIs 
supported by glibc - and if the compiler might support some other ABI 
variant that isn't properly supported by glibc (and doesn't have its own 
dynamic linker name allocated in glibc, for example), we should ensure 
that any attempt to build glibc for that ABI fails.

(The most friendly way to fail would probably be an error from the 
preconfigure fragment rather than later when building some file including 
some header using #error.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-07-24 21:14 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26 17:50 [PATCH 10/25] Swap sys/syslog.h with syslog.h Zack Weinberg
2019-06-26 17:50 ` [PATCH 20/25] Don’t include sys/time.h from sys/timex.h Zack Weinberg
2019-06-26 17:50 ` [PATCH 16/25] Limit the set of strings.h functions also exposed in string.h Zack Weinberg
2019-06-26 17:50 ` [PATCH 11/25] Swap sys/poll.h with poll.h Zack Weinberg
2019-06-26 17:50 ` [PATCH 14/25] Add bits/types/ wrappers for stddef.h and stdarg.h types Zack Weinberg
2019-06-26 17:50 ` [PATCH 13/25] Split up endian.h to minimize exposure of BYTE_ORDER Zack Weinberg
2019-07-24 21:14   ` Joseph Myers
2019-06-26 17:50 ` [PATCH 12/25] Don’t include sys/cdefs.h directly from public headers Zack Weinberg
2019-06-26 17:50 ` [PATCH 15/25] Don’t rely on stddef.h or stdarg.h for individual type definitions Zack Weinberg
2019-06-26 18:06 ` [PATCH 22/25] Minimize includes of unrelated public headers by networking headers Zack Weinberg
2019-06-26 18:06 ` [PATCH 25/25] Rename sys/ucontext.h to bits/ucontext.h Zack Weinberg
2019-06-26 18:06 ` [PATCH 19/25] Don’t include string.h from sys/un.h Zack Weinberg
2019-06-26 18:26 ` [PATCH 21/25] Don’t include sys/types.h or stdint.h from most public headers Zack Weinberg
2019-06-26 18:26 ` [PATCH 18/25] Don’t include signal.h from sys/wait.h or sys/param.h Zack Weinberg
2019-06-26 18:26 ` [PATCH 23/25] Don’t include sys/socket.h from public headers Zack Weinberg
2019-06-26 18:26 ` [PATCH 17/25] Don’t include sys/select.h from sys/types.h Zack Weinberg
2019-06-26 19:06 ` [PATCH 24/25] Minimize inclusion of netinet/in.h from public headers Zack Weinberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).