diff --git a/argp/argp-fmtstream.c b/argp/argp-fmtstream.c
index e43a0c7cf1..7931c39af5 100644
--- a/argp/argp-fmtstream.c
+++ b/argp/argp-fmtstream.c
@@ -41,8 +41,6 @@
 
 #ifdef _LIBC
 # include <wchar.h>
-# include <libio/libioP.h>
-# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
 #endif
 
 #define INIT_BUF_SIZE 200
@@ -149,7 +147,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
 	      size_t i;
 	      for (i = 0; i < pad; i++)
 		{
-		  if (_IO_fwide (fs->stream, 0) > 0)
+		  if (fwide (fs->stream, 0) > 0)
 		    putwc_unlocked (L' ', fs->stream);
 		  else
 		    putc_unlocked (' ', fs->stream);
@@ -312,7 +310,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
 	      *nl++ = ' ';
 	  else
 	    for (i = 0; i < fs->wmargin; ++i)
-	      if (_IO_fwide (fs->stream, 0) > 0)
+	      if (fwide (fs->stream, 0) > 0)
 		putwc_unlocked (L' ', fs->stream);
 	      else
 		putc_unlocked (' ', fs->stream);
diff --git a/argp/argp-help.c b/argp/argp-help.c
index 2b6b0775d6..38c150afe9 100644
--- a/argp/argp-help.c
+++ b/argp/argp-help.c
@@ -48,10 +48,7 @@ char *alloca ();
 #include <stdarg.h>
 #include <ctype.h>
 #include <limits.h>
-#ifdef _LIBC
-# include <../libio/libioP.h>
-# include <wchar.h>
-#endif
+#include <wchar.h>
 
 #ifndef _
 /* This is for other GNU distributions with internationalized messages.  */
@@ -1769,7 +1766,7 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 #ifdef _LIBC
 	  char *buf;
 
-	  if (_IO_vasprintf (&buf, fmt, ap) < 0)
+	  if (__vasprintf (&buf, fmt, ap) < 0)
 	    buf = NULL;
 
 	  __fxprintf (stream, "%s: %s\n",
@@ -1839,7 +1836,7 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 #ifdef _LIBC
 	      char *buf;
 
-	      if (_IO_vasprintf (&buf, fmt, ap) < 0)
+	      if (__vasprintf (&buf, fmt, ap) < 0)
 		buf = NULL;
 
 	      __fxprintf (stream, ": %s", buf);
@@ -1873,7 +1870,7 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 #endif
 	    }
 
-	  if (_IO_fwide (stream, 0) > 0)
+	  if (fwide (stream, 0) > 0)
 	    putwc_unlocked (L'\n', stream);
 	  else
 	    putc_unlocked ('\n', stream);
diff --git a/assert/assert.c b/assert/assert.c
index 8ed691bd32..a46d8deb66 100644
--- a/assert/assert.c
+++ b/assert/assert.c
@@ -24,14 +24,10 @@
 #include <sysdep.h>
 #include <unistd.h>
 #include <sys/mman.h>
-
+#include <wchar.h>
 
 extern const char *__progname;
 
-#include <wchar.h>
-#include <libio/iolibio.h>
-#define fflush(s) _IO_fflush (s)
-
 /* This function, when passed a string containing an asserted
    expression, a filename, and a line number, prints a message
    on the standard error stream of the form:
diff --git a/benchtests/strcoll-inputs/filelist#en_US.UTF-8 b/benchtests/strcoll-inputs/filelist#en_US.UTF-8
index aa44107ad6..d3e46ed8aa 100644
--- a/benchtests/strcoll-inputs/filelist#en_US.UTF-8
+++ b/benchtests/strcoll-inputs/filelist#en_US.UTF-8
@@ -10604,7 +10604,6 @@ sin-inputs
 pthread_once-source.c
 libio
 rewind.c
-iolibio.h
 wfileops.c
 libio.h
 tst-wmemstream1.c
diff --git a/bits/_G_config.h b/bits/_G_config.h
index 2b60d29f5f..6da3c5f0f6 100644
--- a/bits/_G_config.h
+++ b/bits/_G_config.h
@@ -19,20 +19,17 @@
 #include <stddef.h>
 
 #include <bits/types/__mbstate_t.h>
+#include <bits/types/__fpos_t.h>
+#include <bits/types/__fpos64_t.h>
+
+#define _G_fpos_t __fpos_t
+#define _G_fpos64_t __fpos64_t
+
 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 # include <bits/types/wint_t.h>
 #endif
 
-typedef struct
-{
-  __off_t __pos;
-  __mbstate_t __state;
-} _G_fpos_t;
-typedef struct
-{
-  __off64_t __pos;
-  __mbstate_t __state;
-} _G_fpos64_t;
+
 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 # include <gconv.h>
 typedef union
diff --git a/conform/data/stdio.h-data b/conform/data/stdio.h-data
index f69802cc70..3ef2460661 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 _G_va_list
+#define va_list __gnuc_va_list
 #endif
 type size_t
 #if defined XOPEN2K8 || defined POSIX2008
diff --git a/csu/init.c b/csu/init.c
index 178063b44b..09f1318326 100644
--- a/csu/init.c
+++ b/csu/init.c
@@ -18,7 +18,7 @@
 
 #if defined __GNUC__ && __GNUC__ >= 2
 
-#include <stdio.h>
+#include <libio/libioP.h>
 
 /* This records which stdio is linked against in the application. */
 const int _IO_stdin_used = _G_IO_IO_FILE_VERSION;
diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c
index 9cd4143f2e..6958b2f936 100644
--- a/debug/asprintf_chk.c
+++ b/debug/asprintf_chk.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 
 /* Write formatted output from FORMAT to a string which is
diff --git a/debug/dprintf_chk.c b/debug/dprintf_chk.c
index df3867c61c..e86aa6a2a3 100644
--- a/debug/dprintf_chk.c
+++ b/debug/dprintf_chk.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 
 /* Write formatted output to D, according to the format string FORMAT.  */
diff --git a/debug/fgets_chk.c b/debug/fgets_chk.c
index 024c5cc0ee..e7f6085559 100644
--- a/debug/fgets_chk.c
+++ b/debug/fgets_chk.c
@@ -24,9 +24,9 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include <stdio.h>
 #include <sys/param.h>
+#include <libio/libioP.h>
 
 char *
 __fgets_chk (char *buf, size_t size, int n, _IO_FILE *fp)
diff --git a/debug/fgets_u_chk.c b/debug/fgets_u_chk.c
index 668fdc81d4..d3005942ff 100644
--- a/debug/fgets_u_chk.c
+++ b/debug/fgets_u_chk.c
@@ -24,9 +24,9 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include <stdio.h>
 #include <sys/param.h>
+#include <libio/libioP.h>
 
 char *
 __fgets_unlocked_chk (char *buf, size_t size, int n, _IO_FILE *fp)
diff --git a/debug/fgetws_chk.c b/debug/fgetws_chk.c
index 4693a0ba1b..ff2361806e 100644
--- a/debug/fgetws_chk.c
+++ b/debug/fgetws_chk.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include "libioP.h"
 #include <wchar.h>
 #include <sys/param.h>
+#include <libio/libioP.h>
 
 wchar_t *
 __fgetws_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp)
diff --git a/debug/fgetws_u_chk.c b/debug/fgetws_u_chk.c
index 36627d79be..ae7b977a5e 100644
--- a/debug/fgetws_u_chk.c
+++ b/debug/fgetws_u_chk.c
@@ -24,9 +24,9 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include <wchar.h>
 #include <sys/param.h>
+#include <libio/libioP.h>
 
 wchar_t *
 __fgetws_unlocked_chk (wchar_t *buf, size_t size, int n, _IO_FILE *fp)
diff --git a/debug/fprintf_chk.c b/debug/fprintf_chk.c
index cff4438afb..3bf90e6302 100644
--- a/debug/fprintf_chk.c
+++ b/debug/fprintf_chk.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to FP from the format string FORMAT.  */
diff --git a/debug/fread_chk.c b/debug/fread_chk.c
index b0cb061d0d..3e9b4836e9 100644
--- a/debug/fread_chk.c
+++ b/debug/fread_chk.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include <stdio.h>
+#include <libio/libioP.h>
 
 size_t
 __fread_chk (void *__restrict ptr, size_t ptrlen,
diff --git a/debug/fread_u_chk.c b/debug/fread_u_chk.c
index b3061f9745..a2e7ddbedd 100644
--- a/debug/fread_u_chk.c
+++ b/debug/fread_u_chk.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include <stdio.h>
+#include <libio/libioP.h>
 
 size_t
 __fread_unlocked_chk (void *__restrict ptr, size_t ptrlen,
diff --git a/debug/fwprintf_chk.c b/debug/fwprintf_chk.c
index aeb83077da..5e93bb4616 100644
--- a/debug/fwprintf_chk.c
+++ b/debug/fwprintf_chk.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <wchar.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to FP from the format string FORMAT.  */
diff --git a/debug/gets_chk.c b/debug/gets_chk.c
index 6c10d68f34..7b2d6c35cc 100644
--- a/debug/gets_chk.c
+++ b/debug/gets_chk.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "../libio/libioP.h"
 #include <limits.h>
+#include <libio/libioP.h>
 
 char *
 __gets_chk (char *buf, size_t size)
diff --git a/debug/obprintf_chk.c b/debug/obprintf_chk.c
index 3ac5a3cd4f..8565f43204 100644
--- a/debug/obprintf_chk.c
+++ b/debug/obprintf_chk.c
@@ -19,14 +19,13 @@
 
 
 #include <stdlib.h>
-#include <libioP.h>
-#include "../libio/strfile.h"
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
 #include <obstack.h>
 #include <stdarg.h>
 #include <stdio_ext.h>
+#include <libio/strfile.h>
 
 
 struct _IO_obstack_file
diff --git a/debug/printf_chk.c b/debug/printf_chk.c
index 426dc78386..bf9b363851 100644
--- a/debug/printf_chk.c
+++ b/debug/printf_chk.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to stdout from the format string FORMAT.  */
diff --git a/debug/snprintf_chk.c b/debug/snprintf_chk.c
index cddba37109..deeb8b59c9 100644
--- a/debug/snprintf_chk.c
+++ b/debug/snprintf_chk.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 
 /* Write formatted output into S, according to the format
diff --git a/debug/sprintf_chk.c b/debug/sprintf_chk.c
index 78214563dd..860adf7151 100644
--- a/debug/sprintf_chk.c
+++ b/debug/sprintf_chk.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 /* Write formatted output into S, according to the format string FORMAT.  */
 /* VARARGS4 */
diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c
index a00ef771e6..fa52a20c46 100644
--- a/debug/vasprintf_chk.c
+++ b/debug/vasprintf_chk.c
@@ -28,8 +28,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdio_ext.h>
-#include "../libio/libioP.h"
-#include "../libio/strfile.h"
+#include <libio/strfile.h>
 
 int
 __vasprintf_chk (char **result_ptr, int flags, const char *format,
diff --git a/debug/vdprintf_chk.c b/debug/vdprintf_chk.c
index c195a7951e..04cf45ae94 100644
--- a/debug/vdprintf_chk.c
+++ b/debug/vdprintf_chk.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <stdio_ext.h>
+#include <libio/libioP.h>
 
 int
 __vdprintf_chk (int d, int flags, const char *format, va_list arg)
diff --git a/debug/vfprintf_chk.c b/debug/vfprintf_chk.c
index 5babbf611e..f1a0d9cfb0 100644
--- a/debug/vfprintf_chk.c
+++ b/debug/vfprintf_chk.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to FP from the format string FORMAT.  */
diff --git a/debug/vfwprintf_chk.c b/debug/vfwprintf_chk.c
index 1ffd18cbd2..34f927e5a5 100644
--- a/debug/vfwprintf_chk.c
+++ b/debug/vfwprintf_chk.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <wchar.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to FP from the format string FORMAT.  */
diff --git a/debug/vprintf_chk.c b/debug/vprintf_chk.c
index b3b2c53df2..117e5ee514 100644
--- a/debug/vprintf_chk.c
+++ b/debug/vprintf_chk.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to stdout from the format string FORMAT.  */
diff --git a/debug/vsnprintf_chk.c b/debug/vsnprintf_chk.c
index d20d0fbd93..61825aca87 100644
--- a/debug/vsnprintf_chk.c
+++ b/debug/vsnprintf_chk.c
@@ -17,8 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "../libio/libioP.h"
-#include "../libio/strfile.h"
+#include <libio/strfile.h>
 
 extern const struct _IO_jump_t _IO_strn_jumps libio_vtable attribute_hidden;
 
diff --git a/debug/vsprintf_chk.c b/debug/vsprintf_chk.c
index aa9571d475..87568da2a9 100644
--- a/debug/vsprintf_chk.c
+++ b/debug/vsprintf_chk.c
@@ -17,8 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "../libio/libioP.h"
-#include "../libio/strfile.h"
+#include <libio/strfile.h>
 
 
 static int _IO_str_chk_overflow (_IO_FILE *fp, int c) __THROW;
diff --git a/debug/vswprintf_chk.c b/debug/vswprintf_chk.c
index 816955707f..049b3cb2cf 100644
--- a/debug/vswprintf_chk.c
+++ b/debug/vswprintf_chk.c
@@ -17,8 +17,7 @@
 
 #include <stdarg.h>
 #include <wchar.h>
-#include "../libio/libioP.h"
-#include "../libio/strfile.h"
+#include <libio/strfile.h>
 
 
 /* Write formatted output into S, according to the format
diff --git a/debug/vwprintf_chk.c b/debug/vwprintf_chk.c
index 51b67c159d..fefd4304b4 100644
--- a/debug/vwprintf_chk.c
+++ b/debug/vwprintf_chk.c
@@ -18,7 +18,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to stdout from the format string FORMAT.  */
diff --git a/debug/wprintf_chk.c b/debug/wprintf_chk.c
index 17023b6bb4..2d7e00f380 100644
--- a/debug/wprintf_chk.c
+++ b/debug/wprintf_chk.c
@@ -18,7 +18,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 
 /* Write formatted output to stdout from the format string FORMAT.  */
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
index 6793fa1ca6..8fcabe62ac 100644
--- a/grp/fgetgrent_r.c
+++ b/grp/fgetgrent_r.c
@@ -20,10 +20,6 @@
 #include <grp.h>
 #include <stdio.h>
 
-#include <libio/iolibio.h>
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 /* Define a line parsing function using the common code
    used in the nss_files module.  */
 
diff --git a/grp/putgrent.c b/grp/putgrent.c
index 810dc8d24c..41e6a66c98 100644
--- a/grp/putgrent.c
+++ b/grp/putgrent.c
@@ -21,9 +21,6 @@
 #include <string.h>
 #include <grp.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 #define _S(x)	x ? x : ""
 
 /* Write an entry to the given stream.
diff --git a/gshadow/fgetsgent_r.c b/gshadow/fgetsgent_r.c
index 13a5b181cb..e5d71c96c8 100644
--- a/gshadow/fgetsgent_r.c
+++ b/gshadow/fgetsgent_r.c
@@ -38,21 +38,21 @@ __fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen,
 {
   char *p;
 
-  _IO_flockfile (stream);
+  flockfile (stream);
   do
     {
       buffer[buflen - 1] = '\xff';
       p = fgets_unlocked (buffer, buflen, stream);
       if (p == NULL && feof_unlocked (stream))
 	{
-	  _IO_funlockfile (stream);
+	  funlockfile (stream);
 	  *result = NULL;
 	  __set_errno (ENOENT);
 	  return errno;
 	}
       if (p == NULL || buffer[buflen - 1] != '\xff')
 	{
-	  _IO_funlockfile (stream);
+	  funlockfile (stream);
 	  *result = NULL;
 	  __set_errno (ERANGE);
 	  return errno;
@@ -67,7 +67,7 @@ __fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen,
 	     ! parse_line (buffer, (void *) resbuf, (void *) buffer, buflen,
 			   &errno));
 
-  _IO_funlockfile (stream);
+  funlockfile (stream);
 
   *result = resbuf;
   return 0;
diff --git a/gshadow/putsgent.c b/gshadow/putsgent.c
index 262aea2891..638f9b2790 100644
--- a/gshadow/putsgent.c
+++ b/gshadow/putsgent.c
@@ -40,7 +40,7 @@ putsgent (const struct sgrp *g, FILE *stream)
       return -1;
     }
 
-  _IO_flockfile (stream);
+  flockfile (stream);
 
   if (fprintf (stream, "%s:%s:", g->sg_namp, _S (g->sg_passwd)) < 0)
     ++errors;
@@ -75,7 +75,7 @@ putsgent (const struct sgrp *g, FILE *stream)
   if (putc_unlocked ('\n', stream) == EOF)
     ++errors;
 
-  _IO_funlockfile (stream);
+  funlockfile (stream);
 
   return errors ? -1 : 0;
 }
diff --git a/hurd/fopenport.c b/hurd/fopenport.c
index f20c1ecdb8..3f9be4885f 100644
--- a/hurd/fopenport.c
+++ b/hurd/fopenport.c
@@ -81,7 +81,7 @@ closeio (void *cookie)
   return 0;
 }
 
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 #define fopencookie _IO_fopencookie
 static const cookie_io_functions_t funcsio =
 { readio, writeio, seekio, closeio };
diff --git a/hurd/vpprintf.c b/hurd/vpprintf.c
index 76cd31f922..d6fd8208fc 100644
--- a/hurd/vpprintf.c
+++ b/hurd/vpprintf.c
@@ -20,7 +20,7 @@
 #include <string.h>
 #include <hurd.h>
 
-#include <libioP.h>
+#include <libio/libioP.h>
 
 static ssize_t
 do_write (void *cookie,	const char *buf, size_t n)
diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
index d6cf9d2a3e..88b58cafa9 100644
--- a/iconv/gconv_conf.c
+++ b/iconv/gconv_conf.c
@@ -89,9 +89,6 @@ static const char builtin_aliases[] =
 #undef BUILTIN_ALIAS
 };
 
-#include <libio/libioP.h>
-#define __getdelim(line, len, c, fp) _IO_getdelim (line, len, c, fp)
-
 
 /* Value of the GCONV_PATH environment variable.  */
 const char *__gconv_path_envvar;
diff --git a/include/bits/libio.h b/include/bits/libio.h
index 572395d5ff..40b6851fe9 100644
--- a/include/bits/libio.h
+++ b/include/bits/libio.h
@@ -1,45 +1 @@
-#if !defined _ISOMAC && defined _IO_MTSAFE_IO
-# include <stdio-lock.h>
-#endif
 #include <libio/bits/libio.h>
-
-#ifndef _ISOMAC
-#ifndef _LIBC_LIBIO_H
-#define _LIBC_LIBIO_H
-
-libc_hidden_proto (__overflow)
-libc_hidden_proto (__underflow)
-libc_hidden_proto (__uflow)
-libc_hidden_proto (__woverflow)
-libc_hidden_proto (__wunderflow)
-libc_hidden_proto (__wuflow)
-libc_hidden_proto (_IO_free_backup_area)
-libc_hidden_proto (_IO_free_wbackup_area)
-libc_hidden_proto (_IO_padn)
-libc_hidden_proto (_IO_putc)
-libc_hidden_proto (_IO_sgetn)
-libc_hidden_proto (_IO_vfprintf)
-libc_hidden_proto (_IO_vfscanf)
-
-#ifdef _IO_MTSAFE_IO
-# undef _IO_peekc
-# undef _IO_flockfile
-# undef _IO_funlockfile
-# undef _IO_ftrylockfile
-
-# define _IO_peekc(_fp) _IO_peekc_locked (_fp)
-# if _IO_lock_inexpensive
-#  define _IO_flockfile(_fp) \
-  if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock)
-#  define _IO_funlockfile(_fp) \
-  if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock)
-# else
-#  define _IO_flockfile(_fp) \
-  if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp)
-#  define _IO_funlockfile(_fp) \
-  if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp)
-# endif
-#endif /* _IO_MTSAFE_IO */
-
-#endif
-#endif
diff --git a/include/bits/types/__fpos64_t.h b/include/bits/types/__fpos64_t.h
new file mode 100644
index 0000000000..68cc4e8b66
--- /dev/null
+++ b/include/bits/types/__fpos64_t.h
@@ -0,0 +1 @@
+#include <libio/bits/types/__fpos64_t.h>
diff --git a/include/bits/types/__fpos_t.h b/include/bits/types/__fpos_t.h
new file mode 100644
index 0000000000..2dcdc98d75
--- /dev/null
+++ b/include/bits/types/__fpos_t.h
@@ -0,0 +1 @@
+#include <libio/bits/types/__fpos_t.h>
diff --git a/include/bits/types/cookie_io_functions_t.h b/include/bits/types/cookie_io_functions_t.h
new file mode 100644
index 0000000000..87f7930c6e
--- /dev/null
+++ b/include/bits/types/cookie_io_functions_t.h
@@ -0,0 +1 @@
+#include <libio/bits/types/cookie_io_functions_t.h>
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 6137304b0b..e2dbc4f8c8 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -471,6 +471,8 @@ for linking")
   extern __typeof (name) __EI_##name \
 	__attribute__((alias (__hidden_asmname (#local))))
 #  define hidden_ver(local, name)	__hidden_ver1(local, __GI_##name, name);
+#  define hidden_weak_ver(local, name) \
+	__hidden_ver1(local, __GI_##name, name) __attribute__((weak));
 #  define hidden_data_ver(local, name)	hidden_ver(local, name)
 #  define hidden_def(name)		__hidden_ver1(__GI_##name, name, name);
 #  define hidden_data_def(name)		hidden_def(name)
@@ -499,6 +501,7 @@ for linking")
 #  define hidden_def(name)	strong_alias (name, __GI_##name)
 #  define hidden_weak(name)	hidden_def (name)
 #  define hidden_ver(local, name) strong_alias (local, __GI_##name)
+#  define hidden_weak_ver(local, name) hidden_ver (local, name)
 #  define hidden_data_def(name)	strong_data_alias (name, __GI_##name)
 #  define hidden_data_weak(name)	hidden_data_def (name)
 #  define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
@@ -527,6 +530,7 @@ for linking")
 # define hidden_weak(name)
 # define hidden_def(name)
 # define hidden_ver(local, name)
+# define hidden_weak_ver(local, name)
 # define hidden_data_weak(name)
 # define hidden_data_def(name)
 # define hidden_data_ver(local, name)
@@ -545,6 +549,7 @@ for linking")
 #  define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version)
 # endif
 # define libc_hidden_ver(local, name) hidden_ver (local, name)
+# define libc_hidden_weak_ver(local, name) hidden_weak_ver (local, name)
 # define libc_hidden_data_def(name) hidden_data_def (name)
 # define libc_hidden_data_weak(name) hidden_data_weak (name)
 # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
@@ -554,6 +559,7 @@ for linking")
 # define libc_hidden_def(name)
 # define libc_hidden_weak(name)
 # define libc_hidden_ver(local, name)
+# define libc_hidden_weak_ver(local, name)
 # define libc_hidden_data_def(name)
 # define libc_hidden_data_weak(name)
 # define libc_hidden_data_ver(local, name)
diff --git a/include/stdio.h b/include/stdio.h
index f1e987ae5e..13cd932009 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,7 +1,12 @@
 #ifndef _STDIO_H
+# if !defined _ISOMAC && defined _IO_MTSAFE_IO
+#  include <stdio-lock.h>
+# endif
 # include <libio/stdio.h>
 # ifndef _ISOMAC
 
+#  include <math_ldbl_opt.h>
+
 /* Now define the internal interfaces.  */
 
 extern int __fcloseall (void) attribute_hidden;
@@ -10,44 +15,50 @@ extern int __snprintf (char *__restrict __s, size_t __maxlen,
      __attribute__ ((__format__ (__printf__, 3, 4)));
 libc_hidden_proto (__snprintf)
 extern int __vsnprintf (char *__restrict __s, size_t __maxlen,
-			const char *__restrict __format, _G_va_list __arg)
+			const char *__restrict __format, __gnuc_va_list __arg)
      __attribute__ ((__format__ (__printf__, 3, 0)));
+libc_hidden_proto (__vsnprintf)
 extern int __vfscanf (FILE *__restrict __s,
 		      const char *__restrict __format,
-		      _G_va_list __arg)
+		      __gnuc_va_list __arg)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 libc_hidden_proto (__vfscanf)
 extern int __vscanf (const char *__restrict __format,
-		     _G_va_list __arg)
+		     __gnuc_va_list __arg)
      __attribute__ ((__format__ (__scanf__, 1, 0)));
-extern _IO_ssize_t __getline (char **__lineptr, size_t *__n,
-			      FILE *__stream) attribute_hidden;
+extern __ssize_t __getline (char **__lineptr, size_t *__n,
+                            FILE *__stream) attribute_hidden;
+extern __ssize_t __getdelim (char **__lineptr, size_t *__n,
+                             int __delim, FILE *__stream);
+libc_hidden_proto (__getdelim)
+
 extern int __vsscanf (const char *__restrict __s,
 		      const char *__restrict __format,
-		      _G_va_list __arg)
+		      __gnuc_va_list __arg)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
+libc_hidden_proto (__vsscanf)
 
 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 *,
-			   _G_va_list) __THROW;
+			   __gnuc_va_list) __THROW;
 extern int __vsnprintf_chk (char *, size_t, int, size_t, const char *,
-			    _G_va_list) __THROW;
+			    __gnuc_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 *, _G_va_list);
-extern int __vfprintf_chk (FILE *, int, const char *, _G_va_list);
+extern int __vprintf_chk (int, const char *, __gnuc_va_list);
+extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_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 *, _G_va_list) __THROW;
+extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW;
 extern int __dprintf_chk (int, int, const char *, ...);
-extern int __vdprintf_chk (int, int, const char *, _G_va_list);
+extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list);
 extern int __obstack_printf_chk (struct obstack *, int, const char *, ...)
      __THROW;
 extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
-				  _G_va_list) __THROW;
+				  __gnuc_va_list) __THROW;
 
 extern int __isoc99_fscanf (FILE *__restrict __stream,
 			    const char *__restrict __format, ...) __wur;
@@ -56,12 +67,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,
-			     _G_va_list __arg) __wur;
+			     __gnuc_va_list __arg) __wur;
 extern int __isoc99_vscanf (const char *__restrict __format,
-			    _G_va_list __arg) __wur;
+			    __gnuc_va_list __arg) __wur;
 extern int __isoc99_vsscanf (const char *__restrict __s,
 			     const char *__restrict __format,
-			     _G_va_list __arg) __THROW;
+			     __gnuc_va_list __arg) __THROW;
 libc_hidden_proto (__isoc99_vsscanf)
 libc_hidden_proto (__isoc99_vfscanf)
 
@@ -105,14 +116,17 @@ libc_hidden_proto (__fortify_fail)
 libc_hidden_proto (__fortify_fail_abort)
 
 /* Acquire ownership of STREAM.  */
-extern void __flockfile (FILE *__stream) attribute_hidden;
+extern void __flockfile (FILE *__stream);
+libc_hidden_proto (__flockfile)
 
 /* Relinquish the ownership granted for STREAM.  */
-extern void __funlockfile (FILE *__stream) attribute_hidden;
+extern void __funlockfile (FILE *__stream);
+libc_hidden_proto (__funlockfile)
 
 /* Try to acquire ownership of STREAM but do not block if it is not
    possible.  */
 extern int __ftrylockfile (FILE *__stream);
+libc_hidden_proto (__ftrylockfile)
 
 extern int __getc_unlocked (FILE *__fp);
 extern wint_t __getwc_unlocked (FILE *__fp);
@@ -125,23 +139,26 @@ extern int __fxprintf_nocancel (FILE *__fp, const char *__fmt, ...)
 extern const char *const _sys_errlist_internal[] attribute_hidden;
 extern int _sys_nerr_internal attribute_hidden;
 
-libc_hidden_proto (__asprintf)
 #  if IS_IN (libc)
-extern _IO_FILE *_IO_new_fopen (const char*, const char*);
+extern FILE *_IO_new_fopen (const char*, const char*);
 #   define fopen(fname, mode) _IO_new_fopen (fname, mode)
-extern _IO_FILE *_IO_new_fdopen (int, const char*);
+extern FILE *_IO_new_fdopen (int, const char*);
 #   define fdopen(fd, mode) _IO_new_fdopen (fd, mode)
-extern int _IO_new_fclose (_IO_FILE*);
+extern int _IO_new_fclose (FILE *);
 #   define fclose(fp) _IO_new_fclose (fp)
-extern int _IO_fputs (const char*, _IO_FILE*);
+extern int _IO_fputs (const char*, FILE *);
 libc_hidden_proto (_IO_fputs)
 #   define fputs(str, fp) _IO_fputs (str, fp)
-extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
+extern int _IO_new_fsetpos (FILE *, const fpos_t *);
 #   define fsetpos(fp, posp) _IO_new_fsetpos (fp, posp)
-extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
+extern int _IO_new_fgetpos (FILE *, fpos_t *);
 #   define fgetpos(fp, posp) _IO_new_fgetpos (fp, posp)
 #  endif
 
+libc_hidden_proto (__asprintf)
+extern __typeof (vasprintf) __vasprintf
+     __attribute__ ((__format__ (__printf__, 2, 0)));
+libc_hidden_proto (__vasprintf)
 libc_hidden_proto (dprintf)
 extern __typeof (dprintf) __dprintf
      __attribute__ ((__format__ (__printf__, 2, 3)));
@@ -149,6 +166,7 @@ libc_hidden_proto (__dprintf)
 libc_hidden_proto (fprintf)
 libc_hidden_proto (vfprintf)
 libc_hidden_proto (sprintf)
+libc_hidden_proto (vsprintf)
 libc_hidden_proto (sscanf)
 libc_hidden_proto (fwrite)
 libc_hidden_proto (perror)
@@ -157,11 +175,14 @@ libc_hidden_proto (rewind)
 libc_hidden_proto (fileno)
 extern __typeof (fileno) __fileno;
 libc_hidden_proto (__fileno)
+libc_hidden_proto (fread)
 libc_hidden_proto (fwrite)
 libc_hidden_proto (fseek)
+libc_hidden_proto (ftell)
 extern __typeof (ftello) __ftello;
 libc_hidden_proto (__ftello)
 libc_hidden_proto (fflush)
+libc_hidden_proto (setvbuf)
 libc_hidden_proto (fflush_unlocked)
 extern __typeof (fflush_unlocked) __fflush_unlocked;
 libc_hidden_proto (__fflush_unlocked)
@@ -194,5 +215,41 @@ libc_hidden_proto (__fmemopen)
 extern int __gen_tempfd (int flags);
 libc_hidden_proto (__gen_tempfd)
 
+libc_hidden_proto (__overflow)
+libc_hidden_proto (__underflow)
+libc_hidden_proto (__uflow)
+
+#if IS_IN (libc)
+# undef flockfile
+# define flockfile(s) __flockfile (s)
+# undef funlockfile
+# define funlockfile(s) __funlockfile (s)
+#endif
+
+#ifdef _IO_MTSAFE_IO
+# undef _IO_flockfile
+# undef _IO_funlockfile
+# undef _IO_ftrylockfile
+
+# if _IO_lock_inexpensive
+#  define _IO_USER_LOCK 0x8000
+#  define _IO_flockfile(_fp) \
+  if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock)
+#  define _IO_funlockfile(_fp) \
+  if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock)
+# else
+#  define _IO_flockfile(_fp) \
+  do { if (((_fp)->_flags & _IO_USER_LOCK) == 0) __flockfile (_fp) } while (0)
+#  define _IO_funlockfile(_fp) \
+  do { if (((_fp)->_flags & _IO_USER_LOCK) == 0) __funlockfile (_fp) } while (0)
+# endif
+
+# undef __flockfile
+# define __flockfile(s) _IO_flockfile (s)
+# undef __funlockfile
+# define __funlockfile(s) _IO_funlockfile (s)
+
+#endif /* _IO_MTSAFE_IO */
+
 # endif /* not _ISOMAC */
 #endif /* stdio.h */
diff --git a/include/wchar.h b/include/wchar.h
index 1db0ac8278..64157f46ed 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -260,5 +260,11 @@ extern size_t __mbsrtowcs_l (wchar_t *dst, const char **src, size_t len,
 #  define mbsinit(state) ((state)->__count == 0)
 #  define __mbsinit(state) ((state)->__count == 0)
 
+#  if IS_IN (libc)
+extern __typeof (fwide) _IO_fwide;
+#   undef fwide
+#   define fwide(s, m) _IO_fwide (s, m)
+#  endif
+
 # endif
 #endif
diff --git a/libio/Makefile b/libio/Makefile
index 918a86bb74..0e51833f62 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -25,7 +25,8 @@ include ../Makeconfig
 headers	:= stdio.h libio.h _G_config.h \
 	   bits/stdio.h bits/libio.h bits/_G_config.h \
 	   bits/sys_errlist.h bits/stdio2.h bits/stdio-ldbl.h bits/libio-ldbl.h \
-	   bits/types/FILE.h bits/types/__FILE.h
+	   bits/types/FILE.h bits/types/__FILE.h bits/types/__fpos_t.h \
+	   bits/types/__fpos64_t.h bits/types/cookie_io_functions_t.h
 
 routines	:=							      \
 	filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen      \
diff --git a/libio/__fbufsize.c b/libio/__fbufsize.c
index e4e53f6abc..3a3fa2a0e4 100644
--- a/libio/__fbufsize.c
+++ b/libio/__fbufsize.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 size_t
 __fbufsize (FILE *fp)
diff --git a/libio/__flbf.c b/libio/__flbf.c
index e2f386bee6..abf19e5ddf 100644
--- a/libio/__flbf.c
+++ b/libio/__flbf.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 int
 __flbf (FILE *fp)
diff --git a/libio/__fpending.c b/libio/__fpending.c
index 17039c10bf..4048228425 100644
--- a/libio/__fpending.c
+++ b/libio/__fpending.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 size_t
 __fpending (FILE *fp)
diff --git a/libio/__freadable.c b/libio/__freadable.c
index 93022c3626..99eb437d1e 100644
--- a/libio/__freadable.c
+++ b/libio/__freadable.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 int
 __freadable (FILE *fp)
diff --git a/libio/__freading.c b/libio/__freading.c
index c4b9a4dac1..d0aaaa5f27 100644
--- a/libio/__freading.c
+++ b/libio/__freading.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 int
 __freading (FILE *fp)
diff --git a/libio/__fwritable.c b/libio/__fwritable.c
index dc34ae9801..a28dd62d47 100644
--- a/libio/__fwritable.c
+++ b/libio/__fwritable.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 int
 __fwritable (FILE *fp)
diff --git a/libio/__fwriting.c b/libio/__fwriting.c
index e84881515f..66417f12bb 100644
--- a/libio/__fwriting.c
+++ b/libio/__fwriting.c
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio_ext.h>
+#include "libioP.h"
 
 int
 __fwriting (FILE *fp)
diff --git a/libio/bits/libio.h b/libio/bits/libio.h
index fae5b932a1..08fa672b2a 100644
--- a/libio/bits/libio.h
+++ b/libio/bits/libio.h
@@ -28,14 +28,16 @@
 #ifndef _BITS_LIBIO_H
 #define _BITS_LIBIO_H 1
 
-#if !defined _STDIO_H && !defined _LIBIO_H
+#if !defined _STDIO_H && !defined _LIBIO_H && !defined _LIBIOP_H
 # error "Never include <bits/libio.h> directly; use <stdio.h> instead."
 #endif
 
+#include <stdio.h>
+
 #include <bits/_G_config.h>
 /* ALL of these should be defined in _G_config.h */
-#define _IO_fpos_t _G_fpos_t
-#define _IO_fpos64_t _G_fpos64_t
+#define _IO_fpos_t __fpos_t
+#define _IO_fpos64_t __fpos64_t
 #define _IO_size_t size_t
 #define _IO_ssize_t __ssize_t
 #define _IO_off_t __off_t
@@ -44,40 +46,13 @@
 #define _IO_uid_t __uid_t
 #define _IO_iconv_t _G_iconv_t
 #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
-#define _IO_BUFSIZ _G_BUFSIZ
-#define _IO_va_list _G_va_list
+#define _IO_BUFSIZ BUFSIZ
 #define _IO_wint_t wint_t
+#define _IO_va_list __gnuc_va_list
 
-/* This define avoids name pollution if we're using GNU stdarg.h */
-#define __need___va_list
-#include <stdarg.h>
-#ifdef __GNUC_VA_LIST
-# undef _IO_va_list
-# define _IO_va_list __gnuc_va_list
-#endif /* __GNUC_VA_LIST */
-
-#ifndef __P
-# include <sys/cdefs.h>
-#endif /*!__P*/
-
+#define _STDIO_USES_IOSTREAM
 #define _IO_UNIFIED_JUMPTABLES 1
 
-#ifndef EOF
-# define EOF (-1)
-#endif
-#ifndef NULL
-# if defined __GNUG__ && \
-    (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
-#  define NULL (__null)
-# else
-#  if !defined(__cplusplus)
-#   define NULL ((void*)0)
-#  else
-#   define NULL (0)
-#  endif
-# endif
-#endif
-
 #define _IOS_INPUT	1
 #define _IOS_OUTPUT	2
 #define _IOS_ATEND	4
@@ -330,49 +305,13 @@ extern _IO_FILE *_IO_stderr attribute_hidden;
 #endif
 
 
-/* Functions to do I/O and file management for a stream.  */
-
-/* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
-   Return number of bytes read.  */
-typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
-
-/* Write N bytes pointed to by BUF to COOKIE.  Write all N bytes
-   unless there is an error.  Return number of bytes written.  If
-   there is an error, return 0 and do not write anything.  If the file
-   has been opened for append (__mode.__append set), then set the file
-   pointer to the end of the file and then do the write; if not, just
-   write at the current file pointer.  */
-typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf,
-				 size_t __n);
-
-/* Move COOKIE's file position to *POS bytes from the
-   beginning of the file (if W is SEEK_SET),
-   the current position (if W is SEEK_CUR),
-   or the end of the file (if W is SEEK_END).
-   Set *POS to the new file position.
-   Returns zero if successful, nonzero if not.  */
-typedef int __io_seek_fn (void *__cookie, _IO_off64_t *__pos, int __w);
-
-/* Close COOKIE.  */
-typedef int __io_close_fn (void *__cookie);
-
-
+/* Compatibility names for cookie I/O functions.  */
 #ifdef __USE_GNU
-/* User-visible names for the above.  */
-typedef __io_read_fn cookie_read_function_t;
-typedef __io_write_fn cookie_write_function_t;
-typedef __io_seek_fn cookie_seek_function_t;
-typedef __io_close_fn cookie_close_function_t;
-
-/* The structure with the cookie function pointers.  */
-typedef struct
-{
-  __io_read_fn *read;		/* Read bytes.  */
-  __io_write_fn *write;		/* Write bytes.  */
-  __io_seek_fn *seek;		/* Seek/tell file position.  */
-  __io_close_fn *close;		/* Close file.  */
-} _IO_cookie_io_functions_t;
-typedef _IO_cookie_io_functions_t cookie_io_functions_t;
+typedef cookie_read_function_t __io_read_fn;
+typedef cookie_write_function_t __io_write_fn;
+typedef cookie_seek_function_t __io_seek_fn;
+typedef cookie_close_function_t __io_close_fn;
+typedef cookie_io_functions_t _IO_cookie_io_functions_t;
 
 struct _IO_cookie_file;
 
@@ -441,9 +380,10 @@ extern int _IO_peekc_locked (_IO_FILE *__fp);
 #define _IO_PENDING_OUTPUT_COUNT(_fp)	\
 	((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
 
-extern void _IO_flockfile (_IO_FILE *) __THROW;
-extern void _IO_funlockfile (_IO_FILE *) __THROW;
-extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
+/* These might have macro definitions while building libc itself.  */
+extern void (_IO_flockfile) (_IO_FILE *) __THROW;
+extern void (_IO_funlockfile) (_IO_FILE *) __THROW;
+extern int (_IO_ftrylockfile) (_IO_FILE *) __THROW;
 
 #define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
 #define _IO_flockfile(_fp) /**/
diff --git a/libio/bits/stdio.h b/libio/bits/stdio.h
index d287083de1..1415709eb0 100644
--- a/libio/bits/stdio.h
+++ b/libio/bits/stdio.h
@@ -33,7 +33,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, _G_va_list __arg)
+vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
 {
   return vfprintf (stdout, __fmt, __arg);
 }
@@ -111,7 +111,7 @@ putchar_unlocked (int __c)
 
 # ifdef	__USE_GNU
 /* Like `getdelim', but reads up to a newline.  */
-__STDIO_INLINE _IO_ssize_t
+__STDIO_INLINE __ssize_t
 getline (char **__lineptr, size_t *__n, FILE *__stream)
 {
   return __getdelim (__lineptr, __n, '\n', __stream);
diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h
index 55302e91d0..0ab62ef913 100644
--- a/libio/bits/stdio2.h
+++ b/libio/bits/stdio2.h
@@ -24,7 +24,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,
-			   _G_va_list __ap) __THROW;
+			   __gnuc_va_list __ap) __THROW;
 
 #ifdef __va_arg_pack
 __fortify_function int
@@ -41,7 +41,7 @@ __NTH (sprintf (char *__restrict __s, const char *__restrict __fmt, ...))
 
 __fortify_function int
 __NTH (vsprintf (char *__restrict __s, const char *__restrict __fmt,
-		 _G_va_list __ap))
+		 __gnuc_va_list __ap))
 {
   return __builtin___vsprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
 				   __bos (__s), __fmt, __ap);
@@ -54,7 +54,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,
-			    _G_va_list __ap) __THROW;
+			    __gnuc_va_list __ap) __THROW;
 
 # ifdef __va_arg_pack
 __fortify_function int
@@ -72,7 +72,7 @@ __NTH (snprintf (char *__restrict __s, size_t __n,
 
 __fortify_function int
 __NTH (vsnprintf (char *__restrict __s, size_t __n,
-		  const char *__restrict __fmt, _G_va_list __ap))
+		  const char *__restrict __fmt, __gnuc_va_list __ap))
 {
   return __builtin___vsnprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
 				    __bos (__s), __fmt, __ap);
@@ -86,9 +86,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, _G_va_list __ap);
+			   const char *__restrict __format, __gnuc_va_list __ap);
 extern int __vprintf_chk (int __flag, const char *__restrict __format,
-			  _G_va_list __ap);
+			  __gnuc_va_list __ap);
 
 # ifdef __va_arg_pack
 __fortify_function int
@@ -111,7 +111,7 @@ printf (const char *__restrict __fmt, ...)
 # endif
 
 __fortify_function int
-vprintf (const char *__restrict __fmt, _G_va_list __ap)
+vprintf (const char *__restrict __fmt, __gnuc_va_list __ap)
 {
 #ifdef __USE_EXTERN_INLINES
   return __vfprintf_chk (stdout, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
@@ -122,7 +122,7 @@ vprintf (const char *__restrict __fmt, _G_va_list __ap)
 
 __fortify_function int
 vfprintf (FILE *__restrict __stream,
-	  const char *__restrict __fmt, _G_va_list __ap)
+	  const char *__restrict __fmt, __gnuc_va_list __ap)
 {
   return __vfprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
@@ -131,7 +131,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, _G_va_list __arg)
+			   const char *__restrict __fmt, __gnuc_va_list __arg)
      __attribute__ ((__format__ (__printf__, 3, 0)));
 
 #  ifdef __va_arg_pack
@@ -147,7 +147,7 @@ dprintf (int __fd, const char *__restrict __fmt, ...)
 #  endif
 
 __fortify_function int
-vdprintf (int __fd, const char *__restrict __fmt, _G_va_list __ap)
+vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __ap)
 {
   return __vdprintf_chk (__fd, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
@@ -159,7 +159,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, _G_va_list __arg)
+			    const char *__restrict __fmt, __gnuc_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,
@@ -168,7 +168,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,
-				  _G_va_list __args)
+				  __gnuc_va_list __args)
      __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
 
 #  ifdef __va_arg_pack
@@ -205,14 +205,14 @@ __NTH (obstack_printf (struct obstack *__restrict __obstack,
 
 __fortify_function int
 __NTH (vasprintf (char **__restrict __ptr, const char *__restrict __fmt,
-		  _G_va_list __ap))
+		  __gnuc_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, _G_va_list __ap))
+			const char *__restrict __fmt, __gnuc_va_list __ap))
 {
   return __obstack_vprintf_chk (__obstack, __USE_FORTIFY_LEVEL - 1, __fmt,
 				__ap);
diff --git a/libio/bits/types/__fpos64_t.h b/libio/bits/types/__fpos64_t.h
new file mode 100644
index 0000000000..000091abbb
--- /dev/null
+++ b/libio/bits/types/__fpos64_t.h
@@ -0,0 +1,16 @@
+#ifndef _____fpos64_t_defined
+#define _____fpos64_t_defined 1
+
+#include <bits/types.h>
+#include <bits/types/__mbstate_t.h>
+
+/* Note: the tag name of this struct is _G_fpos64_t to preserve
+   historic C++ mangled names for functions taking fpos_t and/or
+   fpos64_t arguments.  That name should not be used in new code.  */
+typedef struct _G_fpos64_t
+{
+  __off64_t __pos;
+  __mbstate_t __state;
+} __fpos64_t;
+
+#endif
diff --git a/libio/bits/types/__fpos_t.h b/libio/bits/types/__fpos_t.h
new file mode 100644
index 0000000000..9df18701d7
--- /dev/null
+++ b/libio/bits/types/__fpos_t.h
@@ -0,0 +1,16 @@
+#ifndef _____fpos_t_defined
+#define _____fpos_t_defined 1
+
+#include <bits/types.h>
+#include <bits/types/__mbstate_t.h>
+
+/* Note: the tag name of this struct is _G_fpos_t to preserve historic
+   C++ mangled names for functions taking fpos_t arguments.  That name
+   should not be used in new code.  */
+typedef struct _G_fpos_t
+{
+  __off_t __pos;
+  __mbstate_t __state;
+} __fpos_t;
+
+#endif
diff --git a/libio/bits/types/cookie_io_functions_t.h b/libio/bits/types/cookie_io_functions_t.h
new file mode 100644
index 0000000000..4d31c1ff7e
--- /dev/null
+++ b/libio/bits/types/cookie_io_functions_t.h
@@ -0,0 +1,46 @@
+#ifndef __cookie_io_functions_t_defined
+#define __cookie_io_functions_t_defined 1
+
+#include <bits/types.h>
+
+/* Functions to do I/O and file management for a stream.  */
+
+/* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
+   Return number of bytes read.  */
+typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf,
+                                          size_t __nbytes);
+
+/* Write NBYTES bytes pointed to by BUF to COOKIE.  Write all NBYTES bytes
+   unless there is an error.  Return number of bytes written.  If
+   there is an error, return 0 and do not write anything.  If the file
+   has been opened for append (__mode.__append set), then set the file
+   pointer to the end of the file and then do the write; if not, just
+   write at the current file pointer.  */
+typedef __ssize_t cookie_write_function_t (void *__cookie, const char *__buf,
+                                           size_t __nbytes);
+
+/* Move COOKIE's file position to *POS bytes from the
+   beginning of the file (if W is SEEK_SET),
+   the current position (if W is SEEK_CUR),
+   or the end of the file (if W is SEEK_END).
+   Set *POS to the new file position.
+   Returns zero if successful, nonzero if not.  */
+typedef int cookie_seek_function_t (void *__cookie, __off64_t *__pos, int __w);
+
+/* Close COOKIE.  */
+typedef int cookie_close_function_t (void *__cookie);
+
+/* The structure with the cookie function pointers.
+   Note: the tag name of this struct is _IO_cookie_io_functions_t to
+   preserve historic C++ mangled names for functions taking
+   cookie_io_functions_t arguments.  That name should not be used in
+   new code.  */
+typedef struct _IO_cookie_io_functions_t
+{
+  cookie_read_function_t *read;		/* Read bytes.  */
+  cookie_write_function_t *write;	/* Write bytes.  */
+  cookie_seek_function_t *seek;		/* Seek/tell file position.  */
+  cookie_close_function_t *close;	/* Close file.  */
+} cookie_io_functions_t;
+
+#endif
diff --git a/libio/ftello.c b/libio/ftello.c
index c9df0569f0..00c13a2079 100644
--- a/libio/ftello.c
+++ b/libio/ftello.c
@@ -26,8 +26,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <libioP.h>
 #include <errno.h>
+#include "libioP.h"
 
 
 off_t
diff --git a/libio/ftello64.c b/libio/ftello64.c
index fcc8495296..489ed25768 100644
--- a/libio/ftello64.c
+++ b/libio/ftello64.c
@@ -26,8 +26,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <libioP.h>
 #include <errno.h>
+#include "libioP.h"
 
 #ifndef __OFF_T_MATCHES_OFF64_T
 
diff --git a/libio/fwide.c b/libio/fwide.c
index 2357be556e..1c093d4af0 100644
--- a/libio/fwide.c
+++ b/libio/fwide.c
@@ -24,9 +24,11 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "libioP.h"
+
+#undef fwide
 
 int
 fwide (_IO_FILE *fp, int mode)
diff --git a/libio/fwprintf.c b/libio/fwprintf.c
index fab63a8716..74e31ead17 100644
--- a/libio/fwprintf.c
+++ b/libio/fwprintf.c
@@ -15,10 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "libioP.h"
 
 
 /* Write formatted output to STREAM from the format string FORMAT.  */
diff --git a/libio/fwscanf.c b/libio/fwscanf.c
index ce4b35d31d..41b7bc6dbe 100644
--- a/libio/fwscanf.c
+++ b/libio/fwscanf.c
@@ -15,10 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "libioP.h"
 
 /* Read formatted input from STREAM according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/libio/iofopncook.c b/libio/iofopncook.c
index b39b4c364f..caf244bb28 100644
--- a/libio/iofopncook.c
+++ b/libio/iofopncook.c
@@ -24,9 +24,10 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "libioP.h"
+
 #include <shlib-compat.h>
 
 /* Prototyped for local functions.  */
diff --git a/libio/iofread.c b/libio/iofread.c
index 0c00e321e0..399d896bfa 100644
--- a/libio/iofread.c
+++ b/libio/iofread.c
@@ -42,6 +42,7 @@ _IO_fread (void *buf, _IO_size_t size, _IO_size_t count, _IO_FILE *fp)
 libc_hidden_def (_IO_fread)
 
 weak_alias (_IO_fread, fread)
+libc_hidden_weak (fread)
 
 # ifndef _IO_MTSAFE_IO
 strong_alias (_IO_fread, __fread_unlocked)
diff --git a/libio/iofsetpos.c b/libio/iofsetpos.c
index b82cb22d10..b63bd6aca3 100644
--- a/libio/iofsetpos.c
+++ b/libio/iofsetpos.c
@@ -24,6 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
+#include <errno.h>
+
 /* We need to avoid the header declarations of these, because
    the types don't match _IO_fsetpos and then the compiler will
    complain about the mismatch when we do the alias below.  */
@@ -31,13 +33,12 @@
 #define _IO_fsetpos64 __renamed__IO_fsetpos64
 #define fsetpos64 __renamed_fsetpos64
 
-#include <libioP.h>
+#include "libioP.h"
 
 #undef _IO_new_fsetpos64
 #undef _IO_fsetpos64
 #undef fsetpos64
 
-#include <errno.h>
 #include <shlib-compat.h>
 
 int
diff --git a/libio/iofsetpos64.c b/libio/iofsetpos64.c
index 44e8c21d84..dbbceeb88f 100644
--- a/libio/iofsetpos64.c
+++ b/libio/iofsetpos64.c
@@ -24,8 +24,9 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <errno.h>
+#include "libioP.h"
+
 #include <shlib-compat.h>
 
 #ifndef __OFF_T_MATCHES_OFF64_T
diff --git a/libio/ioftell.c b/libio/ioftell.c
index 3f0501570f..fb5a6eec75 100644
--- a/libio/ioftell.c
+++ b/libio/ioftell.c
@@ -58,3 +58,4 @@ _IO_ftell (_IO_FILE *fp)
 libc_hidden_def (_IO_ftell)
 
 weak_alias (_IO_ftell, ftell)
+libc_hidden_weak (ftell)
diff --git a/libio/iofwide.c b/libio/iofwide.c
index 96f41930e1..2cf3ffe243 100644
--- a/libio/iofwide.c
+++ b/libio/iofwide.c
@@ -24,14 +24,14 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <dlfcn.h>
 #include <wchar.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
-
 #include <langinfo.h>
+
+#include "libioP.h"
 #include <locale/localeinfo.h>
 #include <wcsmbs/wcsmbsload.h>
 #include <iconv/gconv_int.h>
diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c
index 8d9cfa27c7..63fa9da713 100644
--- a/libio/iogetdelim.c
+++ b/libio/iogetdelim.c
@@ -125,3 +125,4 @@ unlock_return:
 
 weak_alias (_IO_getdelim, __getdelim)
 weak_alias (_IO_getdelim, getdelim)
+libc_hidden_weak (__getdelim)
diff --git a/libio/iolibio.h b/libio/iolibio.h
deleted file mode 100644
index 621b31cff1..0000000000
--- a/libio/iolibio.h
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <stdio.h>
-
-/* These emulate stdio functionality, but with a different name
-   (_IO_ungetc instead of ungetc), and using _IO_FILE instead of FILE. */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int _IO_fclose (_IO_FILE*);
-extern int _IO_new_fclose (_IO_FILE*);
-extern int _IO_old_fclose (_IO_FILE*);
-extern _IO_FILE *_IO_fdopen (int, const char*) __THROW;
-libc_hidden_proto (_IO_fdopen)
-extern _IO_FILE *_IO_old_fdopen (int, const char*) __THROW;
-extern _IO_FILE *_IO_new_fdopen (int, const char*) __THROW;
-extern int _IO_fflush (_IO_FILE*);
-libc_hidden_proto (_IO_fflush)
-extern int _IO_fgetpos (_IO_FILE*, _IO_fpos_t*);
-extern int _IO_fgetpos64 (_IO_FILE*, _IO_fpos64_t*);
-extern char* _IO_fgets (char*, int, _IO_FILE*);
-extern _IO_FILE *_IO_fopen (const char*, const char*);
-extern _IO_FILE *_IO_old_fopen (const char*, const char*);
-extern _IO_FILE *_IO_new_fopen (const char*, const char*);
-extern _IO_FILE *_IO_fopen64 (const char*, const char*);
-extern _IO_FILE *__fopen_internal (const char*, const char*, int)
-	attribute_hidden;
-extern _IO_FILE *__fopen_maybe_mmap (_IO_FILE *) __THROW attribute_hidden;
-extern int _IO_fprintf (_IO_FILE*, const char*, ...);
-extern int _IO_fputs (const char*, _IO_FILE*);
-libc_hidden_proto (_IO_fputs)
-extern int _IO_fsetpos (_IO_FILE*, const _IO_fpos_t *);
-extern int _IO_fsetpos64 (_IO_FILE*, const _IO_fpos64_t *);
-extern long int _IO_ftell (_IO_FILE*);
-libc_hidden_proto (_IO_ftell)
-extern _IO_size_t _IO_fread (void*, _IO_size_t, _IO_size_t, _IO_FILE*);
-libc_hidden_proto (_IO_fread)
-extern _IO_size_t _IO_fwrite (const void*, _IO_size_t, _IO_size_t, _IO_FILE*);
-libc_hidden_proto (_IO_fwrite)
-extern char* _IO_gets (char*);
-extern void _IO_perror (const char*) __THROW;
-extern int _IO_printf (const char*, ...);
-extern int _IO_puts (const char*);
-extern int _IO_scanf (const char*, ...);
-extern void _IO_setbuffer (_IO_FILE *, char*, _IO_size_t) __THROW;
-libc_hidden_proto (_IO_setbuffer)
-extern int _IO_setvbuf (_IO_FILE*, char*, int, _IO_size_t) __THROW;
-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, _IO_FILE*) __THROW;
-extern int _IO_vsscanf (const char *, const char *, _IO_va_list) __THROW;
-extern int _IO_vsprintf (char*, const char*, _IO_va_list) __THROW;
-libc_hidden_proto (_IO_vsprintf)
-extern int _IO_vswprintf (wchar_t*, _IO_size_t, const wchar_t*, _IO_va_list)
-       __THROW;
-
-struct obstack;
-extern int _IO_obstack_vprintf (struct obstack *, const char *, _IO_va_list)
-       __THROW;
-extern int _IO_obstack_printf (struct obstack *, const char *, ...) __THROW;
-#ifndef _IO_pos_BAD
-#define _IO_pos_BAD ((_IO_off64_t)(-1))
-#endif
-#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
-#define _IO_fseek(__fp, __offset, __whence) \
-  (_IO_seekoff_unlocked (__fp, __offset, __whence, _IOS_INPUT|_IOS_OUTPUT) \
-   == _IO_pos_BAD ? EOF : 0)
-#define _IO_rewind(FILE) \
-  (void) _IO_seekoff_unlocked (FILE, 0, 0, _IOS_INPUT|_IOS_OUTPUT)
-#define _IO_vprintf(FORMAT, ARGS) \
-  _IO_vfprintf (_IO_stdout, FORMAT, ARGS)
-#define _IO_freopen(FILENAME, MODE, FP) \
-  (_IO_file_close_it (FP), \
-   _IO_file_fopen (FP, FILENAME, MODE, 1))
-#define _IO_old_freopen(FILENAME, MODE, FP) \
-  (_IO_old_file_close_it (FP), _IO_old_file_fopen(FP, FILENAME, MODE))
-#define _IO_freopen64(FILENAME, MODE, FP) \
-  (_IO_file_close_it (FP), \
-   _IO_file_fopen (FP, FILENAME, MODE, 0))
-#define _IO_fileno(FP) ((FP)->_fileno)
-extern _IO_FILE* _IO_popen (const char*, const char*) __THROW;
-extern _IO_FILE* _IO_new_popen (const char*, const char*) __THROW;
-extern _IO_FILE* _IO_old_popen (const char*, const char*) __THROW;
-extern int __new_pclose (_IO_FILE *) __THROW;
-extern int __old_pclose (_IO_FILE *) __THROW;
-#define _IO_pclose _IO_fclose
-#define _IO_setbuf(_FP, _BUF) _IO_setbuffer (_FP, _BUF, _IO_BUFSIZ)
-#define _IO_setlinebuf(_FP) _IO_setvbuf (_FP, NULL, 1, 0)
-
-_IO_FILE *__new_freopen (const char *, const char *, _IO_FILE *) __THROW;
-_IO_FILE *__old_freopen (const char *, const char *, _IO_FILE *) __THROW;
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/libio/ioseekoff.c b/libio/ioseekoff.c
index 6179cd0c25..a60d8bea3e 100644
--- a/libio/ioseekoff.c
+++ b/libio/ioseekoff.c
@@ -25,8 +25,8 @@
    in files containing the exception.  */
 
 #include <stdlib.h>
-#include <libioP.h>
 #include <errno.h>
+#include "libioP.h"
 
 _IO_off64_t
 _IO_seekoff_unlocked (_IO_FILE *fp, _IO_off64_t offset, int dir, int mode)
diff --git a/libio/ioseekpos.c b/libio/ioseekpos.c
index 9863ece3af..5441c2f32a 100644
--- a/libio/ioseekpos.c
+++ b/libio/ioseekpos.c
@@ -24,7 +24,7 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
+#include "libioP.h"
 
 _IO_off64_t
 _IO_seekpos_unlocked (_IO_FILE *fp, _IO_off64_t pos, int mode)
diff --git a/libio/iosetvbuf.c b/libio/iosetvbuf.c
index 7d376476d3..62a2a0a283 100644
--- a/libio/iosetvbuf.c
+++ b/libio/iosetvbuf.c
@@ -96,3 +96,4 @@ unlock_return:
 libc_hidden_def (_IO_setvbuf)
 
 weak_alias (_IO_setvbuf, setvbuf)
+libc_hidden_weak (setvbuf)
diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c
index b5e87abb06..2638b43db6 100644
--- a/libio/iovdprintf.c
+++ b/libio/iovdprintf.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <stdio_ext.h>
+#include "libioP.h"
 
 int
 _IO_vdprintf (int d, const char *format, _IO_va_list arg)
diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c
index 02be5e7c7a..46337a0d5d 100644
--- a/libio/iovsprintf.c
+++ b/libio/iovsprintf.c
@@ -24,7 +24,6 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include "strfile.h"
 
 int
@@ -44,6 +43,6 @@ __IO_vsprintf (char *string, const char *format, _IO_va_list args)
   return ret;
 }
 ldbl_hidden_def (__IO_vsprintf, _IO_vsprintf)
-
 ldbl_strong_alias (__IO_vsprintf, _IO_vsprintf)
 ldbl_weak_alias (__IO_vsprintf, vsprintf)
+ldbl_hidden_weak (__IO_vsprintf, vsprintf)
diff --git a/libio/iovsscanf.c b/libio/iovsscanf.c
index b5514fc74e..43de9b6427 100644
--- a/libio/iovsscanf.c
+++ b/libio/iovsscanf.c
@@ -24,7 +24,6 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include "strfile.h"
 
 int
@@ -42,4 +41,5 @@ _IO_vsscanf (const char *string, const char *format, _IO_va_list args)
   return ret;
 }
 ldbl_weak_alias (_IO_vsscanf, __vsscanf)
+ldbl_hidden_weak (_IO_vsscanf, __vsscanf)
 ldbl_weak_alias (_IO_vsscanf, vsscanf)
diff --git a/libio/iovswscanf.c b/libio/iovswscanf.c
index bcc2702067..271aae0408 100644
--- a/libio/iovswscanf.c
+++ b/libio/iovswscanf.c
@@ -24,9 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
-#include "strfile.h"
 #include <wchar.h>
+#include "strfile.h"
 
 int
 __vswscanf (const wchar_t *string, const wchar_t *format, _IO_va_list args)
diff --git a/libio/libioP.h b/libio/libioP.h
index 068ceb2615..921622f947 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -24,6 +24,9 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
+#ifndef _LIBIOP_H
+#define _LIBIOP_H 1
+
 /* NOTE: libio is now exclusively used only by glibc since libstdc++ has its
    own implementation.  As a result, functions that were implemented for C++
    (like *sputn) may no longer have C++ semantics.  This is of course only
@@ -33,17 +36,111 @@
    FIXME: All of the C++ cruft eventually needs to go away.  */
 
 #include <stddef.h>
-
+#include <stdio.h>
 #include <errno.h>
 #include <libc-lock.h>
 
 #include <math_ldbl_opt.h>
 
-#include "iolibio.h"
+#include <bits/libio.h>
+
+__BEGIN_DECLS
+
+libc_hidden_proto (__woverflow)
+libc_hidden_proto (__wunderflow)
+libc_hidden_proto (__wuflow)
+libc_hidden_proto (_IO_flockfile)
+libc_hidden_proto (_IO_free_backup_area)
+libc_hidden_proto (_IO_free_wbackup_area)
+libc_hidden_proto (_IO_ftrylockfile)
+libc_hidden_proto (_IO_funlockfile)
+libc_hidden_proto (_IO_padn)
+libc_hidden_proto (_IO_putc)
+libc_hidden_proto (_IO_sgetn)
+libc_hidden_proto (_IO_vfprintf)
+libc_hidden_proto (_IO_vfscanf)
+
+extern int _IO_fclose (FILE*);
+extern int _IO_new_fclose (FILE*);
+extern int _IO_old_fclose (FILE*);
+extern FILE *_IO_fdopen (int, const char*) __THROW;
+libc_hidden_proto (_IO_fdopen)
+extern FILE *_IO_old_fdopen (int, const char*) __THROW;
+extern FILE *_IO_new_fdopen (int, const char*) __THROW;
+extern int _IO_fflush (FILE*);
+libc_hidden_proto (_IO_fflush)
+extern int _IO_fgetpos (FILE*, __fpos_t*);
+extern int _IO_fgetpos64 (FILE*, __fpos64_t*);
+extern char* _IO_fgets (char*, int, FILE*);
+extern FILE *_IO_fopen (const char*, const char*);
+extern FILE *_IO_old_fopen (const char*, const char*);
+extern FILE *_IO_new_fopen (const char*, const char*);
+extern FILE *_IO_fopen64 (const char*, const char*);
+extern FILE *__fopen_internal (const char*, const char*, int)
+	attribute_hidden;
+extern FILE *__fopen_maybe_mmap (FILE *) __THROW attribute_hidden;
+extern int _IO_fprintf (FILE*, const char*, ...);
+extern int _IO_fputs (const char*, FILE*);
+libc_hidden_proto (_IO_fputs)
+extern int _IO_fsetpos (FILE*, const __fpos_t *);
+extern int _IO_fsetpos64 (FILE*, const __fpos64_t *);
+extern long int _IO_ftell (FILE*);
+libc_hidden_proto (_IO_ftell)
+extern size_t _IO_fread (void*, size_t, size_t, FILE*);
+libc_hidden_proto (_IO_fread)
+extern size_t _IO_fwrite (const void*, size_t, size_t, FILE*);
+libc_hidden_proto (_IO_fwrite)
+extern char* _IO_gets (char*);
+extern void _IO_perror (const char*) __THROW;
+extern int _IO_printf (const char*, ...);
+extern int _IO_puts (const char*);
+extern int _IO_scanf (const char*, ...);
+extern void _IO_setbuffer (FILE *, char*, size_t) __THROW;
+libc_hidden_proto (_IO_setbuffer)
+extern int _IO_setvbuf (FILE*, char*, int, size_t) __THROW;
+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_vsprintf (char*, const char*, __gnuc_va_list) __THROW;
+libc_hidden_proto (_IO_vsprintf)
+extern int _IO_vswprintf (wchar_t*, size_t, const wchar_t*, __gnuc_va_list)
+       __THROW;
+
+struct obstack;
+extern int _IO_obstack_vprintf (struct obstack *, const char *, __gnuc_va_list)
+       __THROW;
+extern int _IO_obstack_printf (struct obstack *, const char *, ...) __THROW;
+#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
+#define _IO_fseek(__fp, __offset, __whence) \
+  (_IO_seekoff_unlocked (__fp, __offset, __whence, _IOS_INPUT|_IOS_OUTPUT) \
+   == _IO_pos_BAD ? EOF : 0)
+#define _IO_rewind(FILE) \
+  (void) _IO_seekoff_unlocked (FILE, 0, 0, _IOS_INPUT|_IOS_OUTPUT)
+#define _IO_vprintf(FORMAT, ARGS)               \
+  _IO_vfprintf (_IO_stdout, FORMAT, ARGS)
+#define _IO_freopen(FILENAME, MODE, FP) \
+  (_IO_file_close_it (FP), \
+   _IO_file_fopen (FP, FILENAME, MODE, 1))
+#define _IO_old_freopen(FILENAME, MODE, FP) \
+  (_IO_old_file_close_it (FP), _IO_old_file_fopen(FP, FILENAME, MODE))
+#define _IO_freopen64(FILENAME, MODE, FP) \
+  (_IO_file_close_it (FP), \
+   _IO_file_fopen (FP, FILENAME, MODE, 0))
+#define _IO_fileno(FP) ((FP)->_fileno)
+extern FILE* _IO_popen (const char*, const char*) __THROW;
+extern FILE* _IO_new_popen (const char*, const char*) __THROW;
+extern FILE* _IO_old_popen (const char*, const char*) __THROW;
+extern int __new_pclose (FILE *) __THROW;
+extern int __old_pclose (FILE *) __THROW;
+#define _IO_pclose _IO_fclose
+#define _IO_setbuf(_FP, _BUF) _IO_setbuffer (_FP, _BUF, BUFSIZ)
+#define _IO_setlinebuf(_FP) _IO_setvbuf (_FP, NULL, 1, 0)
+
+FILE *__new_freopen (const char *, const char *, FILE *) __THROW;
+FILE *__old_freopen (const char *, const char *, FILE *) __THROW;
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 #define _IO_seek_set 0
 #define _IO_seek_cur 1
@@ -714,21 +811,13 @@ extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
 
 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
-#ifndef _IO_pos_BAD
-# define _IO_pos_BAD ((_IO_off64_t) -1)
-#endif
+#define _IO_pos_BAD ((_IO_off64_t) -1)
+
 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
-#ifndef _IO_pos_adjust
-# define _IO_pos_adjust(pos, delta) ((pos) += (delta))
-#endif
-/* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
-#ifndef _IO_pos_0
-# define _IO_pos_0 ((_IO_off64_t) 0)
-#endif
+#define _IO_pos_adjust(pos, delta) ((pos) += (delta))
 
-#ifdef __cplusplus
-}
-#endif
+/* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
+#define _IO_pos_0 ((_IO_off64_t) 0)
 
 #ifdef _IO_MTSAFE_IO
 /* check following! */
@@ -876,3 +965,7 @@ IO_validate_vtable (const struct _IO_jump_t *vtable)
     _IO_vtable_check ();
   return vtable;
 }
+
+__END_DECLS
+
+#endif /* libioP.h.  */
diff --git a/libio/memstream.c b/libio/memstream.c
index d86befcc02..a86e5cc90a 100644
--- a/libio/memstream.c
+++ b/libio/memstream.c
@@ -15,10 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include "libioP.h"
-#include "strfile.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include "strfile.h"
 
 
 struct _IO_FILE_memstream
diff --git a/libio/obprintf.c b/libio/obprintf.c
index 4adafc9f2c..d081ced485 100644
--- a/libio/obprintf.c
+++ b/libio/obprintf.c
@@ -19,14 +19,13 @@
 
 
 #include <stdlib.h>
-#include "libioP.h"
-#include "strfile.h"
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
 #include <obstack.h>
 #include <stdarg.h>
 #include <stdio_ext.h>
+#include "strfile.h"
 
 
 struct _IO_obstack_file
diff --git a/libio/oldiofsetpos.c b/libio/oldiofsetpos.c
index ee634bcac4..2238d2ed7f 100644
--- a/libio/oldiofsetpos.c
+++ b/libio/oldiofsetpos.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <errno.h>
+#include "libioP.h"
 
 #include <shlib-compat.h>
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
diff --git a/libio/oldiofsetpos64.c b/libio/oldiofsetpos64.c
index e1e41101ba..e4b65f97bb 100644
--- a/libio/oldiofsetpos64.c
+++ b/libio/oldiofsetpos64.c
@@ -24,8 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <errno.h>
+#include "libioP.h"
 
 #include <shlib-compat.h>
 #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
diff --git a/libio/oldtmpfile.c b/libio/oldtmpfile.c
index f3a266bced..6e63af53e8 100644
--- a/libio/oldtmpfile.c
+++ b/libio/oldtmpfile.c
@@ -21,7 +21,7 @@
 #define _IO_USE_OLD_IO_FILE
 #include <stdio.h>
 #include <unistd.h>
-#include <iolibio.h>
+#include "libioP.h"
 
 /* This returns a new stream opened on a temporary file (generated
    by tmpnam).  The file is opened with mode "w+b" (binary read/write).
diff --git a/libio/stdio.h b/libio/stdio.h
index 95bc902a82..1b4c58aff5 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -32,18 +32,23 @@ __BEGIN_DECLS
 #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/FILE.h>
 
-#define _STDIO_USES_IOSTREAM
-
-#include <bits/libio.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 _G_va_list va_list;
+typedef __gnuc_va_list va_list;
 #   define _VA_LIST_DEFINED
 #  endif
 # else
@@ -75,12 +80,12 @@ typedef __ssize_t ssize_t;
 
 /* The type of the second argument to `fgetpos' and `fsetpos'.  */
 #ifndef __USE_FILE_OFFSET64
-typedef _G_fpos_t fpos_t;
+typedef __fpos_t fpos_t;
 #else
-typedef _G_fpos64_t fpos_t;
+typedef __fpos64_t fpos_t;
 #endif
 #ifdef __USE_LARGEFILE64
-typedef _G_fpos64_t fpos64_t;
+typedef __fpos64_t fpos64_t;
 #endif
 
 /* The possibilities for the third argument to `setvbuf'.  */
@@ -90,16 +95,11 @@ typedef _G_fpos64_t fpos64_t;
 
 
 /* Default buffer size.  */
-#ifndef BUFSIZ
-# define BUFSIZ _IO_BUFSIZ
-#endif
+#define BUFSIZ 8192
 
 
-/* End of file character.
-   Some things throughout the library rely on this being -1.  */
-#ifndef EOF
-# define EOF (-1)
-#endif
+/* End of file character.  */
+#define EOF (-1)
 
 
 /* The possibilities for the third argument to `fseek'.
@@ -132,9 +132,9 @@ typedef _G_fpos64_t fpos64_t;
 
 
 /* Standard streams.  */
-extern struct _IO_FILE *stdin;		/* Standard input stream.  */
-extern struct _IO_FILE *stdout;		/* Standard output stream.  */
-extern struct _IO_FILE *stderr;		/* Standard error output stream.  */
+extern FILE *stdin;		/* Standard input stream.  */
+extern FILE *stdout;		/* Standard output stream.  */
+extern FILE *stderr;		/* Standard error output stream.  */
 /* C89/C99 say they're macros.  Make them happy.  */
 #define stdin stdin
 #define stdout stdout
@@ -270,7 +270,7 @@ extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
    and uses the given functions for input and output.  */
 extern FILE *fopencookie (void *__restrict __magic_cookie,
 			  const char *__restrict __modes,
-			  _IO_cookie_io_functions_t __io_funcs) __THROW __wur;
+			  cookie_io_functions_t __io_funcs) __THROW __wur;
 #endif
 
 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
@@ -325,15 +325,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,
-		     _G_va_list __arg);
+		     __gnuc_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, _G_va_list __arg);
+extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
 /* Write formatted output to S from argument list ARG.  */
 extern int vsprintf (char *__restrict __s, const char *__restrict __format,
-		     _G_va_list __arg) __THROWNL;
+		     __gnuc_va_list __arg) __THROWNL;
 
 #if defined __USE_ISOC99 || defined __USE_UNIX98
 /* Maximum chars of output to write in MAXLEN.  */
@@ -342,7 +342,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, _G_va_list __arg)
+		      const char *__restrict __format, __gnuc_va_list __arg)
      __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
 #endif
 
@@ -350,7 +350,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,
-		      _G_va_list __arg)
+		      __gnuc_va_list __arg)
      __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
 extern int __asprintf (char **__restrict __ptr,
 		       const char *__restrict __fmt, ...)
@@ -363,7 +363,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,
-		     _G_va_list __arg)
+		     __gnuc_va_list __arg)
      __attribute__ ((__format__ (__printf__, 2, 0)));
 extern int dprintf (int __fd, const char *__restrict __fmt, ...)
      __attribute__ ((__format__ (__printf__, 2, 3)));
@@ -418,19 +418,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,
-		    _G_va_list __arg)
+		    __gnuc_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, _G_va_list __arg)
+extern int vscanf (const char *__restrict __format, __gnuc_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, _G_va_list __arg)
+		    const char *__restrict __format, __gnuc_va_list __arg)
      __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
 
 # if !defined __USE_GNU \
@@ -442,26 +442,26 @@ extern int vsscanf (const char *__restrict __s,
    s, S or [.  */
 extern int __REDIRECT (vfscanf,
 		       (FILE *__restrict __s,
-			const char *__restrict __format, _G_va_list __arg),
+			const char *__restrict __format, __gnuc_va_list __arg),
 		       __isoc99_vfscanf)
      __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
 extern int __REDIRECT (vscanf, (const char *__restrict __format,
-				_G_va_list __arg), __isoc99_vscanf)
+				__gnuc_va_list __arg), __isoc99_vscanf)
      __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
 extern int __REDIRECT_NTH (vsscanf,
 			   (const char *__restrict __s,
 			    const char *__restrict __format,
-			    _G_va_list __arg), __isoc99_vsscanf)
+			    __gnuc_va_list __arg), __isoc99_vsscanf)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 #  else
 extern int __isoc99_vfscanf (FILE *__restrict __s,
 			     const char *__restrict __format,
-			     _G_va_list __arg) __wur;
+			     __gnuc_va_list __arg) __wur;
 extern int __isoc99_vscanf (const char *__restrict __format,
-			    _G_va_list __arg) __wur;
+			    __gnuc_va_list __arg) __wur;
 extern int __isoc99_vsscanf (const char *__restrict __s,
 			     const char *__restrict __format,
-			     _G_va_list __arg) __THROW;
+			     __gnuc_va_list __arg) __THROW;
 #   define vfscanf __isoc99_vfscanf
 #   define vscanf __isoc99_vscanf
 #   define vsscanf __isoc99_vsscanf
@@ -483,10 +483,6 @@ extern int getc (FILE *__stream);
    marked with __THROW.  */
 extern int getchar (void);
 
-/* The C standard explicitly says this is a macro, so we always do the
-   optimization for it.  */
-#define getc(_fp) _IO_getc (_fp)
-
 #ifdef __USE_POSIX199506
 /* These are defined in POSIX.1:1996.
 
@@ -523,10 +519,6 @@ extern int putc (int __c, FILE *__stream);
    marked with __THROW.  */
 extern int putchar (int __c);
 
-/* The C standard explicitly says this can be a macro,
-   so we always do the optimization for it.  */
-#define putc(_ch, _fp) _IO_putc (_ch, _fp)
-
 #ifdef __USE_MISC
 /* Faster version when locking is not necessary.
 
@@ -600,12 +592,12 @@ extern char *fgets_unlocked (char *__restrict __s, int __n,
    cancellation point.  But due to similarity with an POSIX interface
    or due to the implementation they are cancellation points and
    therefore not marked with __THROW.  */
-extern _IO_ssize_t __getdelim (char **__restrict __lineptr,
-			       size_t *__restrict __n, int __delimiter,
-			       FILE *__restrict __stream) __wur;
-extern _IO_ssize_t getdelim (char **__restrict __lineptr,
-			     size_t *__restrict __n, int __delimiter,
-			     FILE *__restrict __stream) __wur;
+extern __ssize_t __getdelim (char **__restrict __lineptr,
+                             size_t *__restrict __n, int __delimiter,
+                             FILE *__restrict __stream) __wur;
+extern __ssize_t getdelim (char **__restrict __lineptr,
+                           size_t *__restrict __n, int __delimiter,
+                           FILE *__restrict __stream) __wur;
 
 /* Like `getdelim', but reads up to a newline.
 
@@ -613,9 +605,9 @@ extern _IO_ssize_t getdelim (char **__restrict __lineptr,
    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 _IO_ssize_t getline (char **__restrict __lineptr,
-			    size_t *__restrict __n,
-			    FILE *__restrict __stream) __wur;
+extern __ssize_t getline (char **__restrict __lineptr,
+                          size_t *__restrict __n,
+                          FILE *__restrict __stream) __wur;
 #endif
 
 
@@ -828,7 +820,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,
-			    _G_va_list __args)
+			    __gnuc_va_list __args)
      __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
 #endif /* Use GNU.  */
 
@@ -853,6 +845,9 @@ extern void funlockfile (FILE *__stream) __THROW;
 # include <bits/getopt_posix.h>
 #endif
 
+/* Internal definitions used by optimizing inlines.  */
+#include <bits/libio.h>
+
 /* If we are compiling with optimizing read this file.  It contains
    several optimizing inline functions and macros.  */
 #ifdef __USE_EXTERN_INLINES
diff --git a/libio/strfile.h b/libio/strfile.h
index 68dfcbfe83..8b5d30708a 100644
--- a/libio/strfile.h
+++ b/libio/strfile.h
@@ -25,6 +25,7 @@
    in files containing the exception.  */
 
 #include <stdio.h>
+#include "libioP.h"
 
 typedef void *(*_IO_alloc_type) (_IO_size_t);
 typedef void (*_IO_free_type) (void*);
diff --git a/libio/strops.c b/libio/strops.c
index ac995c830e..6ce160941e 100644
--- a/libio/strops.c
+++ b/libio/strops.c
@@ -25,10 +25,9 @@
    in files containing the exception.  */
 
 #include <assert.h>
-#include "strfile.h"
-#include "libioP.h"
 #include <string.h>
 #include <stdio_ext.h>
+#include "strfile.h"
 
 void
 _IO_str_init_static_internal (_IO_strfile *sf, char *ptr, _IO_size_t size,
diff --git a/libio/swprintf.c b/libio/swprintf.c
index 10f722d035..8fb3aa0b06 100644
--- a/libio/swprintf.c
+++ b/libio/swprintf.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <wchar.h>
+#include "libioP.h"
 
 /* Write formatted output into S, according to the format string FORMAT.  */
 /* VARARGS3 */
diff --git a/libio/swscanf.c b/libio/swscanf.c
index c8686bcbaf..320523e2e4 100644
--- a/libio/swscanf.c
+++ b/libio/swscanf.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <wchar.h>
+#include "libioP.h"
 
 /* Read formatted input from S, according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/libio/vasprintf.c b/libio/vasprintf.c
index 390a63d124..dc6fe33b2c 100644
--- a/libio/vasprintf.c
+++ b/libio/vasprintf.c
@@ -24,10 +24,9 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <string.h>
-#include "libioP.h"
-#include "stdio.h"
+#include <stdio.h>
 #include <stdio_ext.h>
 #include "strfile.h"
 
@@ -85,4 +84,6 @@ _IO_vasprintf (char **result_ptr, const char *format, _IO_va_list args)
   (*result_ptr)[needed - 1] = '\0';
   return ret;
 }
+strong_alias (_IO_vasprintf, __vasprintf)
+ldbl_hidden_def (_IO_vasprintf, __vasprintf)
 ldbl_weak_alias (_IO_vasprintf, vasprintf)
diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c
index 7e67a0a2c8..001d39cab7 100644
--- a/libio/vsnprintf.c
+++ b/libio/vsnprintf.c
@@ -24,7 +24,6 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include "strfile.h"
 
 static int _IO_strn_overflow (_IO_FILE *fp, int c) __THROW;
@@ -119,3 +118,4 @@ _IO_vsnprintf (char *string, _IO_size_t maxlen, const char *format,
 }
 ldbl_weak_alias (_IO_vsnprintf, __vsnprintf)
 ldbl_weak_alias (_IO_vsnprintf, vsnprintf)
+ldbl_hidden_weak (_IO_vsnprintf, __vsnprintf)
diff --git a/libio/vswprintf.c b/libio/vswprintf.c
index bf23a0d665..3d389e15c6 100644
--- a/libio/vswprintf.c
+++ b/libio/vswprintf.c
@@ -24,10 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include "libioP.h"
 #include "strfile.h"
 
-
 static wint_t _IO_wstrn_overflow (_IO_FILE *fp, wint_t c) __THROW;
 
 static wint_t
diff --git a/libio/vtables.c b/libio/vtables.c
index 9fd4ccf642..afc8de90dd 100644
--- a/libio/vtables.c
+++ b/libio/vtables.c
@@ -17,8 +17,9 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <dlfcn.h>
-#include <libioP.h>
 #include <stdio.h>
+#include "libioP.h"
+
 #include <ldsodefs.h>
 
 #ifdef SHARED
diff --git a/libio/vwprintf.c b/libio/vwprintf.c
index 72ebfec92d..c2af326d06 100644
--- a/libio/vwprintf.c
+++ b/libio/vwprintf.c
@@ -15,10 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "libioP.h"
 
 /* Write formatted output to stdout according to the
    format string FORMAT, using the argument list in ARG.  */
diff --git a/libio/wfileops.c b/libio/wfileops.c
index 2488821d54..2dbbea9be9 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -27,11 +27,12 @@
    in files containing the exception.  */
 
 #include <assert.h>
-#include <libioP.h>
 #include <wchar.h>
-#include <gconv.h>
 #include <stdlib.h>
 #include <string.h>
+#include "libioP.h"
+
+#include <gconv.h>
 
 /* Convert TO_DO wide character from DATA to FP.
    Then mark FP as having empty buffers. */
diff --git a/libio/wmemstream.c b/libio/wmemstream.c
index c962071d26..5fecb38fdf 100644
--- a/libio/wmemstream.c
+++ b/libio/wmemstream.c
@@ -15,11 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include "libioP.h"
-#include "strfile.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <wchar.h>
+#include "strfile.h"
 
 
 struct _IO_FILE_wmemstream
diff --git a/libio/wprintf.c b/libio/wprintf.c
index 5945f651fc..bc3164b87e 100644
--- a/libio/wprintf.c
+++ b/libio/wprintf.c
@@ -15,10 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "libioP.h"
 
 /* Write formatted output to stdout from the format string FORMAT.  */
 /* VARARGS1 */
diff --git a/libio/wscanf.c b/libio/wscanf.c
index c8cdad0acd..af7d814521 100644
--- a/libio/wscanf.c
+++ b/libio/wscanf.c
@@ -15,10 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include "libioP.h"
 
 
 /* Read formatted input from stdin according to the format string FORMAT.  */
diff --git a/libio/wstrops.c b/libio/wstrops.c
index a3374a7b15..d02ebdcc9a 100644
--- a/libio/wstrops.c
+++ b/libio/wstrops.c
@@ -25,11 +25,10 @@
    in files containing the exception.  */
 
 #include <assert.h>
-#include "strfile.h"
-#include "libioP.h"
 #include <string.h>
 #include <wchar.h>
 #include <stdio_ext.h>
+#include "strfile.h"
 
 void
 _IO_wstr_init_static (_IO_FILE *fp, wchar_t *ptr, _IO_size_t size,
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 48106f9bd4..da8d36149e 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -222,6 +222,7 @@
 
 #include <unistd.h>
 #include <stdio.h>    /* needed for malloc_stats */
+#include <libio/libioP.h> /* needed for cancellation handling in malloc_stats */
 #include <errno.h>
 
 #include <shlib-compat.h>
@@ -4962,7 +4963,7 @@ __malloc_stats (void)
 
   if (__malloc_initialized < 0)
     ptmalloc_init ();
-  _IO_flockfile (stderr);
+  flockfile (stderr);
   int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
   ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
   for (i = 0, ar_ptr = &main_arena;; i++)
@@ -4993,7 +4994,7 @@ __malloc_stats (void)
   fprintf (stderr, "max mmap bytes   = %10lu\n",
            (unsigned long) mp_.max_mmapped_mem);
   ((_IO_FILE *) stderr)->_flags2 |= old_flags2;
-  _IO_funlockfile (stderr);
+  funlockfile (stderr);
 }
 
 
diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 9064f209ec..60fc4c5a07 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -35,11 +35,6 @@
 
 #include <libc-internal.h>
 #include <dso_handle.h>
-
-#include <libio/iolibio.h>
-#define setvbuf(s, b, f, l) _IO_setvbuf (s, b, f, l)
-#define fwrite(buf, size, count, fp) _IO_fwrite (buf, size, count, fp)
-
 #include <kernel-features.h>
 
 #define TRACE_BUFFER_SIZE 512
diff --git a/malloc/obstack.c b/malloc/obstack.c
index 05ad7e962c..968361b14e 100644
--- a/malloc/obstack.c
+++ b/malloc/obstack.c
@@ -400,10 +400,6 @@ _obstack_memory_used (struct obstack *h)
 #  define _(msgid) gettext (msgid)
 # endif
 
-# ifdef _LIBC
-#  include <libio/iolibio.h>
-# endif
-
 static _Noreturn void
 print_and_abort (void)
 {
diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c
index f4a0e7bda4..c11232269a 100644
--- a/malloc/set-freeres.c
+++ b/malloc/set-freeres.c
@@ -19,8 +19,7 @@
 #include <stdlib.h>
 #include <set-hooks.h>
 #include <libc-internal.h>
-
-#include "../libio/libioP.h"
+#include <libio/libioP.h>
 
 DEFINE_HOOK (__libc_subfreeres, (void));
 
diff --git a/misc/err.c b/misc/err.c
index 2b836e8358..79bee6dbac 100644
--- a/misc/err.c
+++ b/misc/err.c
@@ -22,10 +22,9 @@
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
-
 #include <wchar.h>
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
+#include <libio/libioP.h>
+
 
 extern char *__progname;
 
@@ -86,7 +85,7 @@ void
 vwarnx (const char *format, __gnuc_va_list ap)
 {
   flockfile (stderr);
-  if (_IO_fwide (stderr, 0) > 0)
+  if (fwide (stderr, 0) > 0)
     {
       __fwprintf (stderr, L"%s: ", __progname);
       convert_and_print (format, ap);
@@ -109,7 +108,7 @@ vwarn (const char *format, __gnuc_va_list ap)
   int error = errno;
 
   flockfile (stderr);
-  if (_IO_fwide (stderr, 0) > 0)
+  if (fwide (stderr, 0) > 0)
     {
       __fwprintf (stderr, L"%s: ", __progname);
       if (format)
diff --git a/misc/error.c b/misc/error.c
index b4e8b6c938..f7f8c9d8bc 100644
--- a/misc/error.c
+++ b/misc/error.c
@@ -39,6 +39,7 @@
 # include <stdbool.h>
 # include <stdint.h>
 # include <wchar.h>
+# include <libio/libioP.h>
 # define mbsrtowcs __mbsrtowcs
 # define USE_UNLOCKED_IO 0
 # define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b)
@@ -67,7 +68,6 @@ unsigned int error_message_count;
 # define program_name program_invocation_name
 # include <errno.h>
 # include <limits.h>
-# include <libio/libioP.h>
 
 /* In GNU libc we want do not want to use the common name 'error' directly.
    Instead make it a weak alias.  */
@@ -80,11 +80,6 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
 # define error __error
 # define error_at_line __error_at_line
 
-# include <libio/iolibio.h>
-# define fflush(s) _IO_fflush (s)
-# undef putc
-# define putc(c, fp) _IO_putc (c, fp)
-
 # include <libc-lock.h>
 
 #else /* not _LIBC */
@@ -203,7 +198,7 @@ static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3))
 error_tail (int status, int errnum, const char *message, va_list args)
 {
 #if _LIBC
-  if (_IO_fwide (stderr, 0) > 0)
+  if (fwide (stderr, 0) > 0)
     {
       size_t len = strlen (message) + 1;
       wchar_t *wmessage = NULL;
@@ -304,7 +299,7 @@ error (int status, int errnum, const char *message, ...)
 
   flush_stdout ();
 #ifdef _LIBC
-  _IO_flockfile (stderr);
+  flockfile (stderr);
 #endif
   if (error_print_progname)
     (*error_print_progname) ();
@@ -321,7 +316,7 @@ error (int status, int errnum, const char *message, ...)
   error_tail (status, errnum, message, args);
 
 #ifdef _LIBC
-  _IO_funlockfile (stderr);
+  funlockfile (stderr);
 # ifdef __libc_ptf_call
   __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
 # endif
@@ -367,7 +362,7 @@ error_at_line (int status, int errnum, const char *file_name,
 
   flush_stdout ();
 #ifdef _LIBC
-  _IO_flockfile (stderr);
+  flockfile (stderr);
 #endif
   if (error_print_progname)
     (*error_print_progname) ();
@@ -392,7 +387,7 @@ error_at_line (int status, int errnum, const char *file_name,
   error_tail (status, errnum, message, args);
 
 #ifdef _LIBC
-  _IO_funlockfile (stderr);
+  funlockfile (stderr);
 # ifdef __libc_ptf_call
   __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
 # endif
diff --git a/misc/getpass.c b/misc/getpass.c
index a7023e37a8..29e28f3d08 100644
--- a/misc/getpass.c
+++ b/misc/getpass.c
@@ -20,10 +20,7 @@
 #include <string.h>		/* For string function builtin redirect.  */
 #include <termios.h>
 #include <unistd.h>
-
 #include <wchar.h>
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
 #include <libc-lock.h>
 
 /* It is desirable to use this bit on systems that have it.
diff --git a/misc/getttyent.c b/misc/getttyent.c
index 0fa4ddbdde..57bae5b423 100644
--- a/misc/getttyent.c
+++ b/misc/getttyent.c
@@ -37,9 +37,6 @@ static char sccsid[] = "@(#)getttyent.c	8.1 (Berkeley) 6/4/93";
 #include <ctype.h>
 #include <string.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 static char zapchar;
 static FILE *tf;
 
diff --git a/misc/mntent_r.c b/misc/mntent_r.c
index 7a82658654..9613373207 100644
--- a/misc/mntent_r.c
+++ b/misc/mntent_r.c
@@ -23,9 +23,6 @@
 #include <string.h>
 #include <sys/types.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 #undef __setmntent
 #undef __endmntent
 #undef __getmntent_r
diff --git a/misc/syslog.c b/misc/syslog.c
index 2b6bd373bc..bd86f3507a 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -53,13 +53,10 @@ static char sccsid[] = "@(#)syslog.c	8.4 (Berkeley) 3/18/94";
 
 #include <stdarg.h>
 
-#include <libio/iolibio.h>
 #include <math_ldbl_opt.h>
 
 #include <kernel-features.h>
 
-#define ftell(s) _IO_ftell (s)
-
 static int	LogType = SOCK_DGRAM;	/* type of socket connection */
 static int	LogFile = -1;		/* fd for log */
 static int	connected;		/* have done connect */
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index caaf07c134..7a1c452d14 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -32,7 +32,7 @@
 #include <exit-thread.h>
 #include <default-sched.h>
 #include <futex-internal.h>
-#include "libioP.h"
+#include <libio/libioP.h>
 
 #include <shlib-compat.h>
 
diff --git a/posix/getopt.c b/posix/getopt.c
index 4b832208f8..2916724207 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -31,15 +31,11 @@
 #ifdef _LIBC
 /* When used as part of glibc, error printing must be done differently
    for standards compliance.  getopt is not a cancellation point, so
-   it must not call functions that are, and it is specified by an
-   older standard than stdio locking, so it must not refer to
-   functions in the "user namespace" related to stdio locking.
-   Finally, it must use glibc's internal message translation so that
-   the messages are looked up in the proper text domain.  */
+   it must not call functions that are, and it must use glibc's
+   internal message translation so that the messages are looked up in
+   the proper text domain.  */
 # include <libintl.h>
 # define fprintf __fxprintf_nocancel
-# define flockfile(fp) _IO_flockfile (fp)
-# define funlockfile(fp) _IO_funlockfile (fp)
 #else
 # include "gettext.h"
 # define _(msgid) gettext (msgid)
diff --git a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c
index ec21739b76..49432df51a 100644
--- a/pwd/fgetpwent_r.c
+++ b/pwd/fgetpwent_r.c
@@ -20,9 +20,6 @@
 #include <stdio.h>
 #include <pwd.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 /* Define a line parsing function using the common code
    used in the nss_files module.  */
 
diff --git a/resolv/res_init.c b/resolv/res_init.c
index f5e52cbbb9..3351c50a6f 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -313,7 +313,7 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser)
             ssize_t ret = __getline (&parser->buffer, &buffer_size, fp);
             if (ret <= 0)
               {
-                if (_IO_ferror_unlocked (fp))
+                if (ferror_unlocked (fp))
                   return false;
                 else
                   break;
diff --git a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
index 5a547b436d..b75a7ad25e 100644
--- a/shadow/fgetspent_r.c
+++ b/shadow/fgetspent_r.c
@@ -20,9 +20,6 @@
 #include <shadow.h>
 #include <stdio.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 /* Define a line parsing function using the common code
    used in the nss_files module.  */
 
diff --git a/shadow/putspent.c b/shadow/putspent.c
index edd79d238d..b278e8f1e1 100644
--- a/shadow/putspent.c
+++ b/shadow/putspent.c
@@ -20,9 +20,6 @@
 #include <stdio.h>
 #include <shadow.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 #define _S(x)	x ? x : ""
 
 
diff --git a/stdio-common/asprintf.c b/stdio-common/asprintf.c
index bff858e657..ea983a06e4 100644
--- a/stdio-common/asprintf.c
+++ b/stdio-common/asprintf.c
@@ -18,8 +18,6 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include <libioP.h>
-#define vasprintf(s, f, a) _IO_vasprintf (s, f, a)
 #undef __asprintf
 
 /* Write formatted output from FORMAT to a string which is
@@ -32,7 +30,7 @@ ___asprintf (char **string_ptr, const char *format, ...)
   int done;
 
   va_start (arg, format);
-  done = vasprintf (string_ptr, format, arg);
+  done = __vasprintf (string_ptr, format, arg);
   va_end (arg);
 
   return done;
diff --git a/stdio-common/dprintf.c b/stdio-common/dprintf.c
index 11bd12b838..e9f74a4efd 100644
--- a/stdio-common/dprintf.c
+++ b/stdio-common/dprintf.c
@@ -18,7 +18,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include <libioP.h>
+#include <libio/libioP.h>
 #define vdprintf(d, f, a) _IO_vdprintf (d, f, a)
 
 /* Write formatted output to D, according to the format string FORMAT.  */
diff --git a/stdio-common/flockfile.c b/stdio-common/flockfile.c
index 60ddd34087..f7fc4b8c3d 100644
--- a/stdio-common/flockfile.c
+++ b/stdio-common/flockfile.c
@@ -17,7 +17,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <libio/libioP.h>
 
+#undef flockfile
+#undef __flockfile
 #undef _IO_flockfile
 
 void
@@ -25,5 +28,7 @@ __flockfile (FILE *stream)
 {
   /* Do nothing.  Using this version does not do any locking.  */
 }
-weak_alias (__flockfile, flockfile);
-weak_alias (__flockfile, _IO_flockfile)
+strong_alias (__flockfile, _IO_flockfile)
+weak_alias (__flockfile, flockfile)
+libc_hidden_def (__flockfile)
+libc_hidden_def (_IO_flockfile)
diff --git a/stdio-common/fprintf.c b/stdio-common/fprintf.c
index 2bbf14bf5d..e59517567e 100644
--- a/stdio-common/fprintf.c
+++ b/stdio-common/fprintf.c
@@ -17,7 +17,6 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
 
 
 /* Write formatted output to STREAM from the format string FORMAT.  */
diff --git a/stdio-common/fscanf.c b/stdio-common/fscanf.c
index b60a2a3b81..029183aed0 100644
--- a/stdio-common/fscanf.c
+++ b/stdio-common/fscanf.c
@@ -15,7 +15,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 
diff --git a/stdio-common/ftrylockfile.c b/stdio-common/ftrylockfile.c
index 02e426b6f1..c9218d0616 100644
--- a/stdio-common/ftrylockfile.c
+++ b/stdio-common/ftrylockfile.c
@@ -17,7 +17,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <libio/libioP.h>
 
+#undef ftrylockfile
+#undef __ftrylockfile
 #undef _IO_ftrylockfile
 
 int
@@ -26,5 +29,7 @@ __ftrylockfile (FILE *stream)
   /* Do nothing.  Using this version does not do any locking.  */
   return 1;
 }
-weak_alias (__ftrylockfile, ftrylockfile);
-weak_alias (__ftrylockfile, _IO_ftrylockfile)
+strong_alias (__ftrylockfile, _IO_ftrylockfile)
+weak_alias (__ftrylockfile, ftrylockfile)
+libc_hidden_def (__ftrylockfile)
+libc_hidden_def (_IO_ftrylockfile)
diff --git a/stdio-common/funlockfile.c b/stdio-common/funlockfile.c
index a59a18c9a4..d0a9294061 100644
--- a/stdio-common/funlockfile.c
+++ b/stdio-common/funlockfile.c
@@ -17,7 +17,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <libio/libioP.h>
 
+#undef funlockfile
+#undef __funlockfile
 #undef _IO_funlockfile
 
 void
@@ -25,5 +28,7 @@ __funlockfile (FILE *stream)
 {
   /* Do nothing.  Using this version does not do any locking.  */
 }
-weak_alias (__funlockfile, _IO_funlockfile)
-weak_alias (__funlockfile, funlockfile);
+strong_alias (__funlockfile, _IO_funlockfile)
+weak_alias (__funlockfile, funlockfile)
+libc_hidden_def (__funlockfile)
+libc_hidden_def (_IO_funlockfile)
diff --git a/stdio-common/fxprintf.c b/stdio-common/fxprintf.c
index c1f02925fb..b4d5b5a2a2 100644
--- a/stdio-common/fxprintf.c
+++ b/stdio-common/fxprintf.c
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <wchar.h>
-#include <libioP.h>
+#include <libio/libioP.h>
 
 static int
 locked_vfxprintf (FILE *fp, const char *fmt, va_list ap)
diff --git a/stdio-common/getline.c b/stdio-common/getline.c
index a8b91ec62a..c10ad59371 100644
--- a/stdio-common/getline.c
+++ b/stdio-common/getline.c
@@ -20,11 +20,6 @@
 
 #undef __getline
 
-#include "../libio/libioP.h"
-#undef ssize_t
-#define ssize_t _IO_ssize_t
-#define __getdelim _IO_getdelim
-
 /* Like getdelim, but always looks for a newline.  */
 ssize_t
 __getline (char **lineptr, size_t *n, FILE *stream)
diff --git a/stdio-common/getw.c b/stdio-common/getw.c
index 781a0dc97b..18dc7b7cd6 100644
--- a/stdio-common/getw.c
+++ b/stdio-common/getw.c
@@ -17,9 +17,6 @@
 
 #include <stdio.h>
 
-#include <libio/iolibio.h>
-#define fread(p, m, n, s) _IO_fread (p, m, n, s)
-
 /* Read a word (int) from STREAM.  */
 int
 getw (FILE *stream)
diff --git a/stdio-common/isoc99_fscanf.c b/stdio-common/isoc99_fscanf.c
index 9cdf85e679..13124d597e 100644
--- a/stdio-common/isoc99_fscanf.c
+++ b/stdio-common/isoc99_fscanf.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from STREAM according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/stdio-common/isoc99_scanf.c b/stdio-common/isoc99_scanf.c
index bf7dbe86bb..a8ad1a5bf0 100644
--- a/stdio-common/isoc99_scanf.c
+++ b/stdio-common/isoc99_scanf.c
@@ -17,7 +17,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
+#include <libio/libioP.h>
 
 
 /* Read formatted input from stdin according to the format string FORMAT.  */
diff --git a/stdio-common/isoc99_sscanf.c b/stdio-common/isoc99_sscanf.c
index 56a60a2c05..acef8d19fd 100644
--- a/stdio-common/isoc99_sscanf.c
+++ b/stdio-common/isoc99_sscanf.c
@@ -17,7 +17,6 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
 
 /* Read formatted input from S, according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/stdio-common/isoc99_vfscanf.c b/stdio-common/isoc99_vfscanf.c
index 5d4389abdb..925ddf7111 100644
--- a/stdio-common/isoc99_vfscanf.c
+++ b/stdio-common/isoc99_vfscanf.c
@@ -15,8 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from STREAM according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/stdio-common/isoc99_vscanf.c b/stdio-common/isoc99_vscanf.c
index 8b2b8af0b5..78da49352d 100644
--- a/stdio-common/isoc99_vscanf.c
+++ b/stdio-common/isoc99_vscanf.c
@@ -15,8 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdio.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from STDIN according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/stdio-common/isoc99_vsscanf.c b/stdio-common/isoc99_vsscanf.c
index ead4e551be..5544be61d2 100644
--- a/stdio-common/isoc99_vsscanf.c
+++ b/stdio-common/isoc99_vsscanf.c
@@ -24,9 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <stdio.h>
-#include "../libio/strfile.h"
+#include <libio/strfile.h>
 
 int
 __isoc99_vsscanf (const char *string, const char *format, _IO_va_list args)
diff --git a/stdio-common/perror.c b/stdio-common/perror.c
index b6836c93f6..7fc113a680 100644
--- a/stdio-common/perror.c
+++ b/stdio-common/perror.c
@@ -20,7 +20,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <wchar.h>
-#include "libioP.h"
+
+#include <libio/libioP.h>
 
 static void
 perror_internal (FILE *fp, const char *s, int errnum)
diff --git a/stdio-common/printf.c b/stdio-common/printf.c
index 205b5e42df..c346198663 100644
--- a/stdio-common/printf.c
+++ b/stdio-common/printf.c
@@ -15,7 +15,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 
diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c
index 97f643af24..dd647f1d01 100644
--- a/stdio-common/printf_fp.c
+++ b/stdio-common/printf_fp.c
@@ -22,7 +22,7 @@
 #define HAVE_ALLOCA 1
 
 #include <array_length.h>
-#include <libioP.h>
+#include <libio/libioP.h>
 #include <alloca.h>
 #include <ctype.h>
 #include <float.h>
diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c
index 002a7e1fec..7b1e6a2648 100644
--- a/stdio-common/printf_fphex.c
+++ b/stdio-common/printf_fphex.c
@@ -45,7 +45,7 @@
 
 /* This defines make it possible to use the same code for GNU C library and
    the GNU I/O library.	 */
-#include <libioP.h>
+#include <libio/libioP.h>
 #define PUT(f, s, n) _IO_sputn (f, s, n)
 #define PAD(f, c, n) (wide ? _IO_wpadn (f, c, n) : _IO_padn (f, c, n))
 /* We use this file GNU C library and GNU I/O library.	So make
diff --git a/stdio-common/printf_size.c b/stdio-common/printf_size.c
index 520b6b1e9a..ddc8789490 100644
--- a/stdio-common/printf_size.c
+++ b/stdio-common/printf_size.c
@@ -22,7 +22,7 @@
 #include <ieee754.h>
 #include <math.h>
 #include <printf.h>
-#include <libioP.h>
+#include <libio/libioP.h>
 
 
 /* This defines make it possible to use the same code for GNU C library and
diff --git a/stdio-common/putw.c b/stdio-common/putw.c
index 789cf0de3e..b18c6e6273 100644
--- a/stdio-common/putw.c
+++ b/stdio-common/putw.c
@@ -16,8 +16,6 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
-#include <libio/iolibio.h>
-#define fwrite(p, n, m, s) _IO_fwrite (p, n, m, s)
 
 /* Write the word (int) W to STREAM.  */
 int
diff --git a/stdio-common/scanf.c b/stdio-common/scanf.c
index e61b5f1ad3..41b8d3bd7e 100644
--- a/stdio-common/scanf.c
+++ b/stdio-common/scanf.c
@@ -18,8 +18,6 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include <libioP.h>
-
 
 /* Read formatted input from stdin according to the format string FORMAT.  */
 /* VARARGS1 */
@@ -30,7 +28,7 @@ __scanf (const char *format, ...)
   int done;
 
   va_start (arg, format);
-  done = _IO_vfscanf (stdin, format, arg, NULL);
+  done = __vfscanf (stdin, format, arg);
   va_end (arg);
 
   return done;
diff --git a/stdio-common/snprintf.c b/stdio-common/snprintf.c
index 29a169b08b..d513da2ae3 100644
--- a/stdio-common/snprintf.c
+++ b/stdio-common/snprintf.c
@@ -17,8 +17,6 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
-#define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
 
 /* Write formatted output into S, according to the format
    string FORMAT, writing no more than MAXLEN characters.  */
diff --git a/stdio-common/sprintf.c b/stdio-common/sprintf.c
index bf5671dde9..61fe3abcf5 100644
--- a/stdio-common/sprintf.c
+++ b/stdio-common/sprintf.c
@@ -17,8 +17,6 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
-#define vsprintf(s, f, a) _IO_vsprintf (s, f, a)
 
 /* Write formatted output into S, according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/stdio-common/sscanf.c b/stdio-common/sscanf.c
index 88cd641798..f3aefb87be 100644
--- a/stdio-common/sscanf.c
+++ b/stdio-common/sscanf.c
@@ -17,8 +17,6 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
-#define __vsscanf(s, f, a) _IO_vsscanf (s, f, a)
 
 /* Read formatted input from S, according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/stdio-common/tmpfile.c b/stdio-common/tmpfile.c
index 5ffecae60c..7075f456c8 100644
--- a/stdio-common/tmpfile.c
+++ b/stdio-common/tmpfile.c
@@ -20,8 +20,6 @@
 #include <stdio.h>
 #include <unistd.h>
 
-#include <iolibio.h>
-#define __fdopen _IO_fdopen
 #ifndef tmpfile
 # define tmpfile __new_tmpfile
 #endif
@@ -60,7 +58,7 @@ tmpfile (void)
       (void) __unlink (buf);
     }
 
-  if ((f = __fdopen (fd, "w+b")) == NULL)
+  if ((f = fdopen (fd, "w+b")) == NULL)
     __close (fd);
 
   return f;
diff --git a/stdio-common/tstgetln.c b/stdio-common/tstgetln.c
index a18f754e35..7e068d2a0b 100644
--- a/stdio-common/tstgetln.c
+++ b/stdio-common/tstgetln.c
@@ -16,8 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
-#undef ssize_t
-#define ssize_t _IO_ssize_t
+#include <sys/types.h>
 
 int
 main (int argc, char *argv[])
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index 3b87740dd9..ef3445a146 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -39,13 +39,8 @@
    Beside this it is also shared between the normal and wide character
    implementation as defined in ISO/IEC 9899:1990/Amendment 1:1995.  */
 
+#include <libio/libioP.h>
 
-#include <libioP.h>
-#define FILE		_IO_FILE
-#undef va_list
-#define va_list	_IO_va_list
-#undef BUFSIZ
-#define BUFSIZ		_IO_BUFSIZ
 /* In some cases we need extra space for all the output which is not
    counted in the width of the string. We assume 32 characters is
    enough.  */
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index 099dfeac9e..7ebd3e6c72 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -71,7 +71,7 @@
 #define MALLOC		(GNU_MALLOC | POSIX_MALLOC)
 
 #include <locale/localeinfo.h>
-#include <libioP.h>
+#include <libio/libioP.h>
 
 #undef va_list
 #define va_list	_IO_va_list
diff --git a/stdio-common/vprintf.c b/stdio-common/vprintf.c
index d459642dc8..f3585006a7 100644
--- a/stdio-common/vprintf.c
+++ b/stdio-common/vprintf.c
@@ -18,7 +18,6 @@
 #include <stdarg.h>
 #undef	__OPTIMIZE__	/* Avoid inline `vprintf' function.  */
 #include <stdio.h>
-#include <libioP.h>
 
 #undef	vprintf
 
diff --git a/stdlib/strfmon_l.c b/stdlib/strfmon_l.c
index cd3796ced9..2be44cb9b5 100644
--- a/stdlib/strfmon_l.c
+++ b/stdlib/strfmon_l.c
@@ -22,13 +22,12 @@
 #include <langinfo.h>
 #include <locale.h>
 #include <monetary.h>
-#include "../libio/libioP.h"
-#include "../libio/strfile.h"
 #include <printf.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
-#include "../locale/localeinfo.h"
+#include <libio/strfile.h>
+#include <locale/localeinfo.h>
 
 
 #define out_char(Ch)							      \
diff --git a/stdlib/strfrom-skeleton.c b/stdlib/strfrom-skeleton.c
index 2840512cae..2df6b79cab 100644
--- a/stdlib/strfrom-skeleton.c
+++ b/stdlib/strfrom-skeleton.c
@@ -22,10 +22,9 @@
    code duplication.  */
 
 #include <ctype.h>
-#include "../libio/libioP.h"
-#include "../libio/strfile.h"
-#include <printf.h>
 #include <string.h>
+#include <printf.h>
+#include <libio/strfile.h>
 #include <locale/localeinfo.h>
 
 #define UCHAR_T char
diff --git a/sunrpc/clnt_perr.c b/sunrpc/clnt_perr.c
index cac1dd9913..a1d6176f82 100644
--- a/sunrpc/clnt_perr.c
+++ b/sunrpc/clnt_perr.c
@@ -35,7 +35,6 @@
 #include <libintl.h>
 #include <rpc/rpc.h>
 #include <wchar.h>
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
 static char *auth_errmsg (enum auth_stat stat);
diff --git a/sunrpc/openchild.c b/sunrpc/openchild.c
index 29f274a8ad..ae92707986 100644
--- a/sunrpc/openchild.c
+++ b/sunrpc/openchild.c
@@ -41,10 +41,6 @@
 #include <rpc/rpc.h>
 #include <rpc/clnt.h>
 
-#include <libio/iolibio.h>
-#define fflush(s) _IO_fflush (s)
-#define __fdopen(fd,m) _IO_fdopen (fd,m)
-
 /*
  * returns pid, or -1 for failure
  */
@@ -85,9 +81,9 @@ _openchild (const char *command, FILE ** fto, FILE ** ffrom)
       /*
        * parent: write into pdto[1], read from pdfrom[0]
        */
-      *fto = __fdopen (pdto[1], "w");
+      *fto = fdopen (pdto[1], "w");
       __close (pdto[0]);
-      *ffrom = __fdopen (pdfrom[0], "r");
+      *ffrom = fdopen (pdfrom[0], "r");
       __close (pdfrom[1]);
       break;
     }
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index f12ed31441..cf07ec61c5 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -40,9 +40,7 @@
 #include <rpc/pmap_clnt.h>
 #include <sys/socket.h>
 #include <netdb.h>
-
 #include <wchar.h>
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
 struct proglst_
diff --git a/sunrpc/svc_tcp.c b/sunrpc/svc_tcp.c
index 5ffa7ba6cf..0c1e54ef7b 100644
--- a/sunrpc/svc_tcp.c
+++ b/sunrpc/svc_tcp.c
@@ -61,9 +61,7 @@
 #include <sys/poll.h>
 #include <errno.h>
 #include <stdlib.h>
-
 #include <wchar.h>
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
 /*
diff --git a/sunrpc/svc_udp.c b/sunrpc/svc_udp.c
index 50589871b0..c6519a740c 100644
--- a/sunrpc/svc_udp.c
+++ b/sunrpc/svc_udp.c
@@ -63,7 +63,6 @@
 #endif
 
 #include <wchar.h>
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
 #define rpc_buffer(xprt) ((xprt)->xp_p1)
diff --git a/sunrpc/xdr_rec.c b/sunrpc/xdr_rec.c
index c9a1eaad63..5bfe0f14bf 100644
--- a/sunrpc/xdr_rec.c
+++ b/sunrpc/xdr_rec.c
@@ -49,7 +49,6 @@
 #include <rpc/rpc.h>
 #include <libintl.h>
 #include <wchar.h>
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
 static bool_t xdrrec_getlong (XDR *, long *);
diff --git a/sunrpc/xdr_ref.c b/sunrpc/xdr_ref.c
index eab3b74227..968aab4797 100644
--- a/sunrpc/xdr_ref.c
+++ b/sunrpc/xdr_ref.c
@@ -40,7 +40,6 @@
 #include <rpc/xdr.h>
 #include <libintl.h>
 #include <wchar.h>
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
 #define LASTUNSIGNED	((u_int)0-1)
diff --git a/sunrpc/xdr_stdio.c b/sunrpc/xdr_stdio.c
index 0c2cbb78de..83a55a2311 100644
--- a/sunrpc/xdr_stdio.c
+++ b/sunrpc/xdr_stdio.c
@@ -39,14 +39,8 @@
 #include <stdio.h>
 #include <rpc/xdr.h>
 
-#include <libio/iolibio.h>
 #include <shlib-compat.h>
 
-#define fflush(s) _IO_fflush (s)
-#define fread(p, m, n, s) _IO_fread (p, m, n, s)
-#define ftell(s) _IO_ftell (s)
-#define fwrite(p, m, n, s) _IO_fwrite (p, m, n, s)
-
 static bool_t xdrstdio_getlong (XDR *, long *);
 static bool_t xdrstdio_putlong (XDR *, const long *);
 static bool_t xdrstdio_getbytes (XDR *, caddr_t, u_int);
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 0ea27865c0..00cb6fcbf9 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -27,6 +27,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <stdint.h>
+#include <unistd.h>
 
 #include <elf.h>
 #include <dlfcn.h>
diff --git a/sysdeps/generic/math_ldbl_opt.h b/sysdeps/generic/math_ldbl_opt.h
index 8a5d8ba107..a4b3806a10 100644
--- a/sysdeps/generic/math_ldbl_opt.h
+++ b/sysdeps/generic/math_ldbl_opt.h
@@ -9,6 +9,7 @@
 #define LONG_DOUBLE_COMPAT(lib, introduced) 0
 #define long_double_symbol(lib, local, symbol)
 #define ldbl_hidden_def(local, name) libc_hidden_def (name)
+#define ldbl_hidden_weak(local, name) libc_hidden_weak (name)
 #define ldbl_strong_alias(name, aliasname) strong_alias (name, aliasname)
 #define ldbl_weak_alias(name, aliasname) weak_alias (name, aliasname)
 #define __ldbl_is_dbl 0
diff --git a/sysdeps/ieee754/ldbl-opt/math_ldbl_opt.h b/sysdeps/ieee754/ldbl-opt/math_ldbl_opt.h
index af861c11ea..5994240aab 100644
--- a/sysdeps/ieee754/ldbl-opt/math_ldbl_opt.h
+++ b/sysdeps/ieee754/ldbl-opt/math_ldbl_opt.h
@@ -12,6 +12,7 @@
   long_double_symbol_1 (lib, local, symbol, LONG_DOUBLE_COMPAT_VERSION)
 #ifdef SHARED
 # define ldbl_hidden_def(local, name) libc_hidden_ver (local, name)
+# define ldbl_hidden_weak(local, name) libc_hidden_weak_ver (local, name)
 # define ldbl_strong_alias(name, aliasname) \
   strong_alias (name, __GL_##name##_##aliasname) \
   long_double_symbol (libc, __GL_##name##_##aliasname, aliasname);
@@ -22,6 +23,7 @@
   versioned_symbol (lib, local, symbol, version)
 #else
 # define ldbl_hidden_def(local, name) libc_hidden_def (name)
+# define ldbl_hidden_weak(local, name) libc_hidden_weak (name)
 # define ldbl_strong_alias(name, aliasname) strong_alias (name, aliasname)
 # define ldbl_weak_alias(name, aliasname) weak_alias (name, aliasname)
 # ifndef __ASSEMBLER__
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
index 7280d48ac5..e3c7d5f496 100644
--- a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
+++ b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
@@ -19,13 +19,13 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
 #include <wchar.h>
 #include <printf.h>
 #include <monetary.h>
 #include <locale/localeinfo.h>
 #include <sys/syslog.h>
 #include <libc-lock.h>
+#include <libio/libioP.h>
 
 #include "nldbl-compat.h"
 
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-compat.h b/sysdeps/ieee754/ldbl-opt/nldbl-compat.h
index 3b3ef731a6..4e7d517f37 100644
--- a/sysdeps/ieee754/ldbl-opt/nldbl-compat.h
+++ b/sysdeps/ieee754/ldbl-opt/nldbl-compat.h
@@ -36,7 +36,6 @@
 /* Declare the __nldbl_NAME function the wrappers call that's in libc.so.  */
 #define NLDBL_DECL(name) extern __typeof (name) __nldbl_##name
 
-NLDBL_DECL (_IO_vfscanf);
 NLDBL_DECL (vfscanf);
 NLDBL_DECL (vfwscanf);
 NLDBL_DECL (obstack_vprintf);
@@ -82,23 +81,25 @@ extern ssize_t __nldbl___vstrfmon (char *, size_t, const char *, va_list)
 /* 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, _G_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, _G_va_list) __THROW;
+				   const char *__restrict, va_list) __THROW;
 extern int __nldbl___vsnprintf_chk (char *__restrict, size_t, int, size_t,
-				    const char *__restrict, _G_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 *, _G_va_list)
+extern int __nldbl___vasprintf_chk (char **, int, const char *, va_list)
   __THROW;
-extern int __nldbl___vdprintf_chk (int, int, const char *, _G_va_list);
+extern int __nldbl___vdprintf_chk (int, int, const char *, va_list);
 extern int __nldbl___obstack_vprintf_chk (struct obstack *, int, const char *,
-					  _G_va_list) __THROW;
+					  va_list) __THROW;
 extern void __nldbl___vsyslog_chk (int, int, const char *, va_list);
 
+/* This function is not declared by stdio.h anymore.  */
+extern int __nldbl__IO_vfscanf (FILE *, const char *, va_list, int *);
 
 #endif /* __NLDBL_COMPAT_H */
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c b/sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c
index 05581c0354..ffb7d788fe 100644
--- a/sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c
+++ b/sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c
@@ -2,7 +2,7 @@
 
 int
 attribute_hidden
-_IO_vfscanf (FILE *s, const char *fmt, _IO_va_list ap, int *errp)
+_IO_vfscanf (FILE *s, const char *fmt, __gnuc_va_list ap, int *errp)
 {
   return __nldbl__IO_vfscanf (s, fmt, ap, errp);
 }
diff --git a/sysdeps/mach/hurd/tmpfile.c b/sysdeps/mach/hurd/tmpfile.c
index 488bb6ae2b..2e913c1e2e 100644
--- a/sysdeps/mach/hurd/tmpfile.c
+++ b/sysdeps/mach/hurd/tmpfile.c
@@ -22,7 +22,6 @@
 #include <hurd/fd.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <iolibio.h>
 
 /* This returns a new stream opened on a temporary file (generated
    by tmpnam).  The file is opened with mode "w+b" (binary read/write).
diff --git a/sysdeps/pthread/flockfile.c b/sysdeps/pthread/flockfile.c
index 4dc3f75035..275e11c548 100644
--- a/sysdeps/pthread/flockfile.c
+++ b/sysdeps/pthread/flockfile.c
@@ -18,8 +18,11 @@
 
 #include <pthread.h>
 #include <stdio.h>
-#include <stdio-lock.h>
+#include <libio/libioP.h>
 
+#undef flockfile
+#undef __flockfile
+#undef _IO_flockfile
 
 void
 __flockfile (FILE *stream)
@@ -29,3 +32,5 @@ __flockfile (FILE *stream)
 }
 strong_alias (__flockfile, _IO_flockfile)
 weak_alias (__flockfile, flockfile)
+libc_hidden_def (__flockfile)
+libc_hidden_def (_IO_flockfile)
diff --git a/sysdeps/pthread/ftrylockfile.c b/sysdeps/pthread/ftrylockfile.c
index 3fff61f3c6..8a72e29b13 100644
--- a/sysdeps/pthread/ftrylockfile.c
+++ b/sysdeps/pthread/ftrylockfile.c
@@ -16,11 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <pthread.h>
 #include <stdio.h>
-#include <stdio-lock.h>
+#include <libio/libioP.h>
 
+#undef ftrylockfile
+#undef __ftrylockfile
+#undef _IO_ftrylockfile
 
 int
 __ftrylockfile (FILE *stream)
@@ -29,3 +31,5 @@ __ftrylockfile (FILE *stream)
 }
 strong_alias (__ftrylockfile, _IO_ftrylockfile)
 weak_alias (__ftrylockfile, ftrylockfile)
+libc_hidden_def (__ftrylockfile)
+libc_hidden_def (_IO_ftrylockfile)
diff --git a/sysdeps/pthread/funlockfile.c b/sysdeps/pthread/funlockfile.c
index 27afe8c131..d2b9f6c8e6 100644
--- a/sysdeps/pthread/funlockfile.c
+++ b/sysdeps/pthread/funlockfile.c
@@ -18,8 +18,11 @@
 
 #include <pthread.h>
 #include <stdio.h>
-#include <stdio-lock.h>
+#include <libio/libioP.h>
 
+#undef funlockfile
+#undef __funlockfile
+#undef _IO_funlockfile
 
 void
 __funlockfile (FILE *stream)
@@ -28,3 +31,5 @@ __funlockfile (FILE *stream)
 }
 strong_alias (__funlockfile, _IO_funlockfile)
 weak_alias (__funlockfile, funlockfile)
+libc_hidden_def (__funlockfile)
+libc_hidden_def (_IO_funlockfile)
diff --git a/sysdeps/unix/sysv/linux/bits/_G_config.h b/sysdeps/unix/sysv/linux/bits/_G_config.h
index 9994869098..338150291f 100644
--- a/sysdeps/unix/sysv/linux/bits/_G_config.h
+++ b/sysdeps/unix/sysv/linux/bits/_G_config.h
@@ -19,20 +19,16 @@
 #include <stddef.h>
 
 #include <bits/types/__mbstate_t.h>
+#include <bits/types/__fpos_t.h>
+#include <bits/types/__fpos64_t.h>
+
+#define _G_fpos_t __fpos_t
+#define _G_fpos64_t __fpos64_t
+
 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 # include <bits/types/wint_t.h>
 #endif
 
-typedef struct
-{
-  __off_t __pos;
-  __mbstate_t __state;
-} _G_fpos_t;
-typedef struct
-{
-  __off64_t __pos;
-  __mbstate_t __state;
-} _G_fpos64_t;
 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 # include <gconv.h>
 typedef union
diff --git a/sysdeps/unix/sysv/linux/hppa/localplt.data b/sysdeps/unix/sysv/linux/hppa/localplt.data
index 3279c0af05..9fece8ef71 100644
--- a/sysdeps/unix/sysv/linux/hppa/localplt.data
+++ b/sysdeps/unix/sysv/linux/hppa/localplt.data
@@ -7,7 +7,6 @@ libc.so: malloc
 libc.so: memalign
 libc.so: realloc
 libc.so: __sigsetjmp
-libc.so: _IO_funlockfile
 libc.so: sigprocmask
 libc.so: __errno_location
 libm.so: matherr
diff --git a/sysdeps/unix/sysv/linux/readonly-area.c b/sysdeps/unix/sysv/linux/readonly-area.c
index 9cbb6e9d4d..09e3db8d9f 100644
--- a/sysdeps/unix/sysv/linux/readonly-area.c
+++ b/sysdeps/unix/sysv/linux/readonly-area.c
@@ -21,7 +21,6 @@
 #include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
-#include "libio/libioP.h"
 
 /* Return 1 if the whole area PTR .. PTR+SIZE is not writable.
    Return -1 if it is writable.  */
@@ -55,7 +54,7 @@ __readonly_area (const char *ptr, size_t size)
 
   while (! feof_unlocked (fp))
     {
-      if (_IO_getdelim (&line, &linelen, '\n', fp) <= 0)
+      if (__getdelim (&line, &linelen, '\n', fp) <= 0)
 	break;
 
       char *p;
diff --git a/wcsmbs/isoc99_fwscanf.c b/wcsmbs/isoc99_fwscanf.c
index 0c6a2c47ac..e8a06c0c45 100644
--- a/wcsmbs/isoc99_fwscanf.c
+++ b/wcsmbs/isoc99_fwscanf.c
@@ -15,10 +15,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from STREAM according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/wcsmbs/isoc99_swscanf.c b/wcsmbs/isoc99_swscanf.c
index ff523db706..ea90a6912a 100644
--- a/wcsmbs/isoc99_swscanf.c
+++ b/wcsmbs/isoc99_swscanf.c
@@ -17,8 +17,8 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
 #include <wchar.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from S, according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/wcsmbs/isoc99_vfwscanf.c b/wcsmbs/isoc99_vfwscanf.c
index 5e6d91fb21..47e40cbd71 100644
--- a/wcsmbs/isoc99_vfwscanf.c
+++ b/wcsmbs/isoc99_vfwscanf.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdio.h>
 #include <wchar.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from STREAM according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/wcsmbs/isoc99_vswscanf.c b/wcsmbs/isoc99_vswscanf.c
index 3cea62e741..d0f34d4976 100644
--- a/wcsmbs/isoc99_vswscanf.c
+++ b/wcsmbs/isoc99_vswscanf.c
@@ -24,9 +24,8 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <libioP.h>
 #include <wchar.h>
-#include "../libio/strfile.h"
+#include <libio/strfile.h>
 
 int
 __isoc99_vswscanf (const wchar_t *string, const wchar_t *format,
diff --git a/wcsmbs/isoc99_vwscanf.c b/wcsmbs/isoc99_vwscanf.c
index d8e229247c..00e890c765 100644
--- a/wcsmbs/isoc99_vwscanf.c
+++ b/wcsmbs/isoc99_vwscanf.c
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <libioP.h>
 #include <stdio.h>
 #include <wchar.h>
+#include <libio/libioP.h>
 
 /* Read formatted input from STDIN according to the format string FORMAT.  */
 /* VARARGS2 */
diff --git a/wcsmbs/isoc99_wscanf.c b/wcsmbs/isoc99_wscanf.c
index abfbd50c11..0c949f6767 100644
--- a/wcsmbs/isoc99_wscanf.c
+++ b/wcsmbs/isoc99_wscanf.c
@@ -17,8 +17,8 @@
 
 #include <stdarg.h>
 #include <stdio.h>
-#include <libioP.h>
 #include <wchar.h>
+#include <libio/libioP.h>
 
 
 /* Read formatted input from stdin according to the format string FORMAT.  */
