d8307d
commit 09e1b0e3f6facc1af2dbcfef204f0aaa8718772b
d8307d
Author: Florian Weimer <fweimer@redhat.com>
d8307d
Date:   Mon May 20 21:54:57 2019 +0200
d8307d
d8307d
    libio: Remove codecvt vtable [BZ #24588]
d8307d
    
d8307d
    The codecvt vtable is not a real vtable because it also contains the
d8307d
    conversion state data.  Furthermore, wide stream support was added to
d8307d
    GCC 3.0, after a C++ ABI bump, so there is no compatibility
d8307d
    requirement with libstdc++.
d8307d
    
d8307d
    This change removes several unmangled function pointers which could
d8307d
    be used with a corrupted FILE object to redirect execution.  (libio
d8307d
    vtable verification did not cover the codecvt vtable.)
d8307d
    
d8307d
    Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>
d8307d
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
d8307d
d8307d
diff --git a/libio/fileops.c b/libio/fileops.c
d8307d
index d2070a856e..daa5a05877 100644
d8307d
--- a/libio/fileops.c
d8307d
+++ b/libio/fileops.c
d8307d
@@ -331,9 +331,6 @@ _IO_new_file_fopen (FILE *fp, const char *filename, const char *mode,
d8307d
 
d8307d
 	  cc = fp->_codecvt = &fp->_wide_data->_codecvt;
d8307d
 
d8307d
-	  /* The functions are always the same.  */
d8307d
-	  *cc = __libio_codecvt;
d8307d
-
d8307d
 	  cc->__cd_in.__cd.__nsteps = fcts.towc_nsteps;
d8307d
 	  cc->__cd_in.__cd.__steps = fcts.towc;
d8307d
 
d8307d
diff --git a/libio/iofgetpos.c b/libio/iofgetpos.c
d8307d
index 8032192440..388c4a0708 100644
d8307d
--- a/libio/iofgetpos.c
d8307d
+++ b/libio/iofgetpos.c
d8307d
@@ -70,8 +70,7 @@ _IO_new_fgetpos (FILE *fp, __fpos_t *posp)
d8307d
   else
d8307d
     {
d8307d
       posp->__pos = pos;
d8307d
-      if (fp->_mode > 0
d8307d
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
d8307d
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
d8307d
 	/* This is a stateful encoding, safe the state.  */
d8307d
 	posp->__state = fp->_wide_data->_IO_state;
d8307d
     }
d8307d
diff --git a/libio/iofgetpos64.c b/libio/iofgetpos64.c
d8307d
index 54de6a8205..6a0ba50d29 100644
d8307d
--- a/libio/iofgetpos64.c
d8307d
+++ b/libio/iofgetpos64.c
d8307d
@@ -54,8 +54,7 @@ _IO_new_fgetpos64 (FILE *fp, __fpos64_t *posp)
d8307d
   else
d8307d
     {
d8307d
       posp->__pos = pos;
d8307d
-      if (fp->_mode > 0
d8307d
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
d8307d
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
d8307d
 	/* This is a stateful encoding, safe the state.  */
d8307d
 	posp->__state = fp->_wide_data->_IO_state;
d8307d
     }
d8307d
diff --git a/libio/iofsetpos.c b/libio/iofsetpos.c
d8307d
index d7b1abbc61..4df1aae082 100644
d8307d
--- a/libio/iofsetpos.c
d8307d
+++ b/libio/iofsetpos.c
d8307d
@@ -58,8 +58,7 @@ _IO_new_fsetpos (FILE *fp, const __fpos_t *posp)
d8307d
   else
d8307d
     {
d8307d
       result = 0;
d8307d
-      if (fp->_mode > 0
d8307d
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
d8307d
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
d8307d
 	/* This is a stateful encoding, restore the state.  */
d8307d
 	fp->_wide_data->_IO_state = posp->__state;
d8307d
     }
d8307d
diff --git a/libio/iofsetpos64.c b/libio/iofsetpos64.c
d8307d
index d1865b728e..f382ba0dc1 100644
d8307d
--- a/libio/iofsetpos64.c
d8307d
+++ b/libio/iofsetpos64.c
d8307d
@@ -48,8 +48,7 @@ _IO_new_fsetpos64 (FILE *fp, const fpos64_t *posp)
d8307d
   else
d8307d
     {
d8307d
       result = 0;
d8307d
-      if (fp->_mode > 0
d8307d
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
d8307d
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
d8307d
 	/* This is a stateful encoding, safe the state.  */
d8307d
 	fp->_wide_data->_IO_state = posp->__state;
d8307d
     }
d8307d
diff --git a/libio/iofwide.c b/libio/iofwide.c
d8307d
index 247cfde3d0..80cb2d5074 100644
d8307d
--- a/libio/iofwide.c
d8307d
+++ b/libio/iofwide.c
d8307d
@@ -39,44 +39,6 @@
d8307d
 #include <sysdep.h>
d8307d
 
d8307d
 
d8307d
-/* Prototypes of libio's codecvt functions.  */
d8307d
-static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
d8307d
-				     __mbstate_t *statep,
d8307d
-				     const wchar_t *from_start,
d8307d
-				     const wchar_t *from_end,
d8307d
-				     const wchar_t **from_stop, char *to_start,
d8307d
-				     char *to_end, char **to_stop);
d8307d
-static enum __codecvt_result do_unshift (struct _IO_codecvt *codecvt,
d8307d
-					 __mbstate_t *statep, char *to_start,
d8307d
-					 char *to_end, char **to_stop);
d8307d
-static enum __codecvt_result do_in (struct _IO_codecvt *codecvt,
d8307d
-				    __mbstate_t *statep,
d8307d
-				    const char *from_start,
d8307d
-				    const char *from_end,
d8307d
-				    const char **from_stop, wchar_t *to_start,
d8307d
-				    wchar_t *to_end, wchar_t **to_stop);
d8307d
-static int do_encoding (struct _IO_codecvt *codecvt);
d8307d
-static int do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
-		      const char *from_start,
d8307d
-		      const char *from_end, size_t max);
d8307d
-static int do_max_length (struct _IO_codecvt *codecvt);
d8307d
-static int do_always_noconv (struct _IO_codecvt *codecvt);
d8307d
-
d8307d
-
d8307d
-/* The functions used in `codecvt' for libio are always the same.  */
d8307d
-const struct _IO_codecvt __libio_codecvt =
d8307d
-{
d8307d
-  .__codecvt_destr = NULL,		/* Destructor, never used.  */
d8307d
-  .__codecvt_do_out = do_out,
d8307d
-  .__codecvt_do_unshift = do_unshift,
d8307d
-  .__codecvt_do_in = do_in,
d8307d
-  .__codecvt_do_encoding = do_encoding,
d8307d
-  .__codecvt_do_always_noconv = do_always_noconv,
d8307d
-  .__codecvt_do_length = do_length,
d8307d
-  .__codecvt_do_max_length = do_max_length
d8307d
-};
d8307d
-
d8307d
-
d8307d
 /* Return orientation of stream.  If mode is nonzero try to change
d8307d
    the orientation first.  */
d8307d
 #undef _IO_fwide
d8307d
@@ -118,9 +80,6 @@ _IO_fwide (FILE *fp, int mode)
d8307d
 	assert (fcts.towc_nsteps == 1);
d8307d
 	assert (fcts.tomb_nsteps == 1);
d8307d
 
d8307d
-	/* The functions are always the same.  */
d8307d
-	*cc = __libio_codecvt;
d8307d
-
d8307d
 	cc->__cd_in.__cd.__nsteps = fcts.towc_nsteps;
d8307d
 	cc->__cd_in.__cd.__steps = fcts.towc;
d8307d
 
d8307d
@@ -150,11 +109,11 @@ _IO_fwide (FILE *fp, int mode)
d8307d
 }
d8307d
 
d8307d
 
d8307d
-static enum __codecvt_result
d8307d
-do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
-	const wchar_t *from_start, const wchar_t *from_end,
d8307d
-	const wchar_t **from_stop, char *to_start, char *to_end,
d8307d
-	char **to_stop)
d8307d
+enum __codecvt_result
d8307d
+__libio_codecvt_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
+		     const wchar_t *from_start, const wchar_t *from_end,
d8307d
+		     const wchar_t **from_stop, char *to_start, char *to_end,
d8307d
+		     char **to_stop)
d8307d
 {
d8307d
   enum __codecvt_result result;
d8307d
 
d8307d
@@ -202,57 +161,11 @@ do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
 }
d8307d
 
d8307d
 
d8307d
-static enum __codecvt_result
d8307d
-do_unshift (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
-	    char *to_start, char *to_end, char **to_stop)
d8307d
-{
d8307d
-  enum __codecvt_result result;
d8307d
-
d8307d
-  struct __gconv_step *gs = codecvt->__cd_out.__cd.__steps;
d8307d
-  int status;
d8307d
-  size_t dummy;
d8307d
-
d8307d
-  codecvt->__cd_out.__cd.__data[0].__outbuf = (unsigned char *) to_start;
d8307d
-  codecvt->__cd_out.__cd.__data[0].__outbufend = (unsigned char *) to_end;
d8307d
-  codecvt->__cd_out.__cd.__data[0].__statep = statep;
d8307d
-
d8307d
-  __gconv_fct fct = gs->__fct;
d8307d
-#ifdef PTR_DEMANGLE
d8307d
-  if (gs->__shlib_handle != NULL)
d8307d
-    PTR_DEMANGLE (fct);
d8307d
-#endif
d8307d
-
d8307d
-  status = DL_CALL_FCT (fct,
d8307d
-			(gs, codecvt->__cd_out.__cd.__data, NULL, NULL,
d8307d
-			 NULL, &dummy, 1, 0));
d8307d
-
d8307d
-  *to_stop = (char *) codecvt->__cd_out.__cd.__data[0].__outbuf;
d8307d
-
d8307d
-  switch (status)
d8307d
-    {
d8307d
-    case __GCONV_OK:
d8307d
-    case __GCONV_EMPTY_INPUT:
d8307d
-      result = __codecvt_ok;
d8307d
-      break;
d8307d
-
d8307d
-    case __GCONV_FULL_OUTPUT:
d8307d
-    case __GCONV_INCOMPLETE_INPUT:
d8307d
-      result = __codecvt_partial;
d8307d
-      break;
d8307d
-
d8307d
-    default:
d8307d
-      result = __codecvt_error;
d8307d
-      break;
d8307d
-    }
d8307d
-
d8307d
-  return result;
d8307d
-}
d8307d
-
d8307d
-
d8307d
-static enum __codecvt_result
d8307d
-do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
-       const char *from_start, const char *from_end, const char **from_stop,
d8307d
-       wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
d8307d
+enum __codecvt_result
d8307d
+__libio_codecvt_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
+		    const char *from_start, const char *from_end,
d8307d
+		    const char **from_stop,
d8307d
+		    wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
d8307d
 {
d8307d
   enum __codecvt_result result;
d8307d
 
d8307d
@@ -300,8 +213,8 @@ do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
 }
d8307d
 
d8307d
 
d8307d
-static int
d8307d
-do_encoding (struct _IO_codecvt *codecvt)
d8307d
+int
d8307d
+__libio_codecvt_encoding (struct _IO_codecvt *codecvt)
d8307d
 {
d8307d
   /* See whether the encoding is stateful.  */
d8307d
   if (codecvt->__cd_in.__cd.__steps[0].__stateful)
d8307d
@@ -317,16 +230,10 @@ do_encoding (struct _IO_codecvt *codecvt)
d8307d
 }
d8307d
 
d8307d
 
d8307d
-static int
d8307d
-do_always_noconv (struct _IO_codecvt *codecvt)
d8307d
-{
d8307d
-  return 0;
d8307d
-}
d8307d
-
d8307d
-
d8307d
-static int
d8307d
-do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
-	   const char *from_start, const char *from_end, size_t max)
d8307d
+int
d8307d
+__libio_codecvt_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
+			const char *from_start, const char *from_end,
d8307d
+			size_t max)
d8307d
 {
d8307d
   int result;
d8307d
   const unsigned char *cp = (const unsigned char *) from_start;
d8307d
@@ -353,10 +260,3 @@ do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
d8307d
 
d8307d
   return result;
d8307d
 }
d8307d
-
d8307d
-
d8307d
-static int
d8307d
-do_max_length (struct _IO_codecvt *codecvt)
d8307d
-{
d8307d
-  return codecvt->__cd_in.__cd.__steps[0].__max_needed_from;
d8307d
-}
d8307d
diff --git a/libio/libio.h b/libio/libio.h
d8307d
index c38095ff77..b985c386a2 100644
d8307d
--- a/libio/libio.h
d8307d
+++ b/libio/libio.h
d8307d
@@ -116,40 +116,8 @@ struct _IO_marker {
d8307d
   int _pos;
d8307d
 };
d8307d
 
d8307d
-/* This is the structure from the libstdc++ codecvt class.  */
d8307d
-enum __codecvt_result
d8307d
-{
d8307d
-  __codecvt_ok,
d8307d
-  __codecvt_partial,
d8307d
-  __codecvt_error,
d8307d
-  __codecvt_noconv
d8307d
-};
d8307d
-
d8307d
-/* The order of the elements in the following struct must match the order
d8307d
-   of the virtual functions in the libstdc++ codecvt class.  */
d8307d
 struct _IO_codecvt
d8307d
 {
d8307d
-  void (*__codecvt_destr) (struct _IO_codecvt *);
d8307d
-  enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
d8307d
-					     __mbstate_t *,
d8307d
-					     const wchar_t *,
d8307d
-					     const wchar_t *,
d8307d
-					     const wchar_t **, char *,
d8307d
-					     char *, char **);
d8307d
-  enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
d8307d
-						 __mbstate_t *, char *,
d8307d
-						 char *, char **);
d8307d
-  enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
d8307d
-					    __mbstate_t *,
d8307d
-					    const char *, const char *,
d8307d
-					    const char **, wchar_t *,
d8307d
-					    wchar_t *, wchar_t **);
d8307d
-  int (*__codecvt_do_encoding) (struct _IO_codecvt *);
d8307d
-  int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
d8307d
-  int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *,
d8307d
-			      const char *, const char *, size_t);
d8307d
-  int (*__codecvt_do_max_length) (struct _IO_codecvt *);
d8307d
-
d8307d
   _IO_iconv_t __cd_in;
d8307d
   _IO_iconv_t __cd_out;
d8307d
 };
d8307d
diff --git a/libio/libioP.h b/libio/libioP.h
d8307d
index 7bdec86a62..66afaa8968 100644
d8307d
--- a/libio/libioP.h
d8307d
+++ b/libio/libioP.h
d8307d
@@ -476,7 +476,6 @@ extern const struct _IO_jump_t _IO_streambuf_jumps;
d8307d
 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
d8307d
 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
d8307d
 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
d8307d
-extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
d8307d
 extern int _IO_do_write (FILE *, const char *, size_t);
d8307d
 libc_hidden_proto (_IO_do_write)
d8307d
 extern int _IO_new_do_write (FILE *, const char *, size_t);
d8307d
@@ -932,4 +931,32 @@ IO_validate_vtable (const struct _IO_jump_t *vtable)
d8307d
   return vtable;
d8307d
 }
d8307d
 
d8307d
+/* Character set conversion.  */
d8307d
+
d8307d
+enum __codecvt_result
d8307d
+{
d8307d
+  __codecvt_ok,
d8307d
+  __codecvt_partial,
d8307d
+  __codecvt_error,
d8307d
+  __codecvt_noconv
d8307d
+};
d8307d
+
d8307d
+enum __codecvt_result __libio_codecvt_out (struct _IO_codecvt *,
d8307d
+					   __mbstate_t *,
d8307d
+					   const wchar_t *,
d8307d
+					   const wchar_t *,
d8307d
+					   const wchar_t **, char *,
d8307d
+					   char *, char **)
d8307d
+  attribute_hidden;
d8307d
+enum __codecvt_result __libio_codecvt_in (struct _IO_codecvt *,
d8307d
+					  __mbstate_t *,
d8307d
+					  const char *, const char *,
d8307d
+					  const char **, wchar_t *,
d8307d
+					  wchar_t *, wchar_t **)
d8307d
+  attribute_hidden;
d8307d
+int __libio_codecvt_encoding (struct _IO_codecvt *) attribute_hidden;
d8307d
+int __libio_codecvt_length (struct _IO_codecvt *, __mbstate_t *,
d8307d
+			    const char *, const char *, size_t)
d8307d
+  attribute_hidden;
d8307d
+
d8307d
 #endif /* libioP.h.  */
d8307d
diff --git a/libio/wfileops.c b/libio/wfileops.c
d8307d
index 69fbb62a02..f1863db638 100644
d8307d
--- a/libio/wfileops.c
d8307d
+++ b/libio/wfileops.c
d8307d
@@ -72,11 +72,11 @@ _IO_wdo_write (FILE *fp, const wchar_t *data, size_t to_do)
d8307d
 	    }
d8307d
 
d8307d
 	  /* Now convert from the internal format into the external buffer.  */
d8307d
-	  result = (*cc->__codecvt_do_out) (cc, &fp->_wide_data->_IO_state,
d8307d
-					    data, data + to_do, &new_data,
d8307d
-					    write_ptr,
d8307d
-					    buf_end,
d8307d
-					    &write_ptr);
d8307d
+	  result = __libio_codecvt_out (cc, &fp->_wide_data->_IO_state,
d8307d
+					data, data + to_do, &new_data,
d8307d
+					write_ptr,
d8307d
+					buf_end,
d8307d
+					&write_ptr);
d8307d
 
d8307d
 	  /* Write out what we produced so far.  */
d8307d
 	  if (_IO_new_do_write (fp, write_base, write_ptr - write_base) == EOF)
d8307d
@@ -140,12 +140,12 @@ _IO_wfile_underflow (FILE *fp)
d8307d
       fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
d8307d
       fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
d8307d
 	fp->_wide_data->_IO_buf_base;
d8307d
-      status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
d8307d
-				       fp->_IO_read_ptr, fp->_IO_read_end,
d8307d
-				       &read_stop,
d8307d
-				       fp->_wide_data->_IO_read_ptr,
d8307d
-				       fp->_wide_data->_IO_buf_end,
d8307d
-				       &fp->_wide_data->_IO_read_end);
d8307d
+      status = __libio_codecvt_in (cd, &fp->_wide_data->_IO_state,
d8307d
+				   fp->_IO_read_ptr, fp->_IO_read_end,
d8307d
+				   &read_stop,
d8307d
+				   fp->_wide_data->_IO_read_ptr,
d8307d
+				   fp->_wide_data->_IO_buf_end,
d8307d
+				   &fp->_wide_data->_IO_read_end);
d8307d
 
d8307d
       fp->_IO_read_base = fp->_IO_read_ptr;
d8307d
       fp->_IO_read_ptr = (char *) read_stop;
d8307d
@@ -266,11 +266,11 @@ _IO_wfile_underflow (FILE *fp)
d8307d
       naccbuf += to_copy;
d8307d
       from = accbuf;
d8307d
     }
d8307d
-  status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
d8307d
-				   from, to, &read_ptr_copy,
d8307d
-				   fp->_wide_data->_IO_read_end,
d8307d
-				   fp->_wide_data->_IO_buf_end,
d8307d
-				   &fp->_wide_data->_IO_read_end);
d8307d
+  status = __libio_codecvt_in (cd, &fp->_wide_data->_IO_state,
d8307d
+			       from, to, &read_ptr_copy,
d8307d
+			       fp->_wide_data->_IO_read_end,
d8307d
+			       fp->_wide_data->_IO_buf_end,
d8307d
+			       &fp->_wide_data->_IO_read_end);
d8307d
 
d8307d
   if (__glibc_unlikely (naccbuf != 0))
d8307d
     fp->_IO_read_ptr += MAX (0, read_ptr_copy - &accbuf[naccbuf - to_copy]);
d8307d
@@ -372,12 +372,12 @@ _IO_wfile_underflow_mmap (FILE *fp)
d8307d
   fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
d8307d
   fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
d8307d
     fp->_wide_data->_IO_buf_base;
d8307d
-  (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
d8307d
-			  fp->_IO_read_ptr, fp->_IO_read_end,
d8307d
-			  &read_stop,
d8307d
-			  fp->_wide_data->_IO_read_ptr,
d8307d
-			  fp->_wide_data->_IO_buf_end,
d8307d
-			  &fp->_wide_data->_IO_read_end);
d8307d
+  __libio_codecvt_in (cd, &fp->_wide_data->_IO_state,
d8307d
+		      fp->_IO_read_ptr, fp->_IO_read_end,
d8307d
+		      &read_stop,
d8307d
+		      fp->_wide_data->_IO_read_ptr,
d8307d
+		      fp->_wide_data->_IO_buf_end,
d8307d
+		      &fp->_wide_data->_IO_read_end);
d8307d
 
d8307d
   fp->_IO_read_ptr = (char *) read_stop;
d8307d
 
d8307d
@@ -495,7 +495,7 @@ _IO_wfile_sync (FILE *fp)
d8307d
       struct _IO_codecvt *cv = fp->_codecvt;
d8307d
       off64_t new_pos;
d8307d
 
d8307d
-      int clen = (*cv->__codecvt_do_encoding) (cv);
d8307d
+      int clen = __libio_codecvt_encoding (cv);
d8307d
 
d8307d
       if (clen > 0)
d8307d
 	/* It is easy, a fixed number of input bytes are used for each
d8307d
@@ -511,9 +511,9 @@ _IO_wfile_sync (FILE *fp)
d8307d
 	  size_t wnread = (fp->_wide_data->_IO_read_ptr
d8307d
 			   - fp->_wide_data->_IO_read_base);
d8307d
 	  fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
d8307d
-	  nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
d8307d
-					      fp->_IO_read_base,
d8307d
-					      fp->_IO_read_end, wnread);
d8307d
+	  nread = __libio_codecvt_length (cv, &fp->_wide_data->_IO_state,
d8307d
+					  fp->_IO_read_base,
d8307d
+					  fp->_IO_read_end, wnread);
d8307d
 	  fp->_IO_read_ptr = fp->_IO_read_base + nread;
d8307d
 	  delta = -(fp->_IO_read_end - fp->_IO_read_base - nread);
d8307d
 	}
d8307d
@@ -548,7 +548,7 @@ adjust_wide_data (FILE *fp, bool do_convert)
d8307d
 {
d8307d
   struct _IO_codecvt *cv = fp->_codecvt;
d8307d
 
d8307d
-  int clen = (*cv->__codecvt_do_encoding) (cv);
d8307d
+  int clen = __libio_codecvt_encoding (cv);
d8307d
 
d8307d
   /* Take the easy way out for constant length encodings if we don't need to
d8307d
      convert.  */
d8307d
@@ -565,12 +565,12 @@ adjust_wide_data (FILE *fp, bool do_convert)
d8307d
     {
d8307d
 
d8307d
       fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
d8307d
-      status = (*cv->__codecvt_do_in) (cv, &fp->_wide_data->_IO_state,
d8307d
-				       fp->_IO_read_base, fp->_IO_read_ptr,
d8307d
-				       &read_stop,
d8307d
-				       fp->_wide_data->_IO_read_base,
d8307d
-				       fp->_wide_data->_IO_buf_end,
d8307d
-				       &fp->_wide_data->_IO_read_end);
d8307d
+      status = __libio_codecvt_in (cv, &fp->_wide_data->_IO_state,
d8307d
+				   fp->_IO_read_base, fp->_IO_read_ptr,
d8307d
+				   &read_stop,
d8307d
+				   fp->_wide_data->_IO_read_base,
d8307d
+				   fp->_wide_data->_IO_buf_end,
d8307d
+				   &fp->_wide_data->_IO_read_end);
d8307d
 
d8307d
       /* Should we return EILSEQ?  */
d8307d
       if (__glibc_unlikely (status == __codecvt_error))
d8307d
@@ -648,7 +648,7 @@ do_ftell_wide (FILE *fp)
d8307d
 	}
d8307d
 
d8307d
       struct _IO_codecvt *cv = fp->_codecvt;
d8307d
-      int clen = (*cv->__codecvt_do_encoding) (cv);
d8307d
+      int clen = __libio_codecvt_encoding (cv);
d8307d
 
d8307d
       if (!unflushed_writes)
d8307d
 	{
d8307d
@@ -663,9 +663,9 @@ do_ftell_wide (FILE *fp)
d8307d
 
d8307d
 	      size_t delta = wide_read_ptr - wide_read_base;
d8307d
 	      __mbstate_t state = fp->_wide_data->_IO_last_state;
d8307d
-	      nread = (*cv->__codecvt_do_length) (cv, &state,
d8307d
-						  fp->_IO_read_base,
d8307d
-						  fp->_IO_read_end, delta);
d8307d
+	      nread = __libio_codecvt_length (cv, &state,
d8307d
+					      fp->_IO_read_base,
d8307d
+					      fp->_IO_read_end, delta);
d8307d
 	      offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
d8307d
 	    }
d8307d
 	}
d8307d
@@ -688,9 +688,8 @@ do_ftell_wide (FILE *fp)
d8307d
 	      enum __codecvt_result status;
d8307d
 
d8307d
 	      __mbstate_t state = fp->_wide_data->_IO_last_state;
d8307d
-	      status = (*cv->__codecvt_do_out) (cv, &state,
d8307d
-						in, in + delta, &in,
d8307d
-						out, out + outsize, &outstop);
d8307d
+	      status = __libio_codecvt_out (cv, &state, in, in + delta, &in,
d8307d
+					    out, out + outsize, &outstop);
d8307d
 
d8307d
 	      /* We don't check for __codecvt_partial because it can be
d8307d
 		 returned on one of two conditions: either the output
d8307d
@@ -801,7 +800,7 @@ _IO_wfile_seekoff (FILE *fp, off64_t offset, int dir, int mode)
d8307d
 	 find out which position in the external buffer corresponds to
d8307d
 	 the current position in the internal buffer.  */
d8307d
       cv = fp->_codecvt;
d8307d
-      clen = (*cv->__codecvt_do_encoding) (cv);
d8307d
+      clen = __libio_codecvt_encoding (cv);
d8307d
 
d8307d
       if (mode != 0 || !was_writing)
d8307d
 	{
d8307d
@@ -819,10 +818,10 @@ _IO_wfile_seekoff (FILE *fp, off64_t offset, int dir, int mode)
d8307d
 	      delta = (fp->_wide_data->_IO_read_ptr
d8307d
 		       - fp->_wide_data->_IO_read_base);
d8307d
 	      fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
d8307d
-	      nread = (*cv->__codecvt_do_length) (cv,
d8307d
-						  &fp->_wide_data->_IO_state,
d8307d
-						  fp->_IO_read_base,
d8307d
-						  fp->_IO_read_end, delta);
d8307d
+	      nread = __libio_codecvt_length (cv,
d8307d
+					      &fp->_wide_data->_IO_state,
d8307d
+					      fp->_IO_read_base,
d8307d
+					      fp->_IO_read_end, delta);
d8307d
 	      fp->_IO_read_ptr = fp->_IO_read_base + nread;
d8307d
 	      fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
d8307d
 	      offset -= fp->_IO_read_end - fp->_IO_read_base - nread;