93dc2d
commit b693d75f0c611bce9b0ad984bad306121d42c535
93dc2d
Author: Florian Weimer <fweimer@redhat.com>
93dc2d
Date:   Fri Jan 14 20:16:05 2022 +0100
93dc2d
93dc2d
    elf: Split dl-printf.c from dl-misc.c
93dc2d
    
93dc2d
    This allows to use different compiler flags for the diagnostics
93dc2d
    code.
93dc2d
    
93dc2d
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
93dc2d
93dc2d
diff --git a/elf/Makefile b/elf/Makefile
93dc2d
index 124905f96c88ab53..52aafc89cec835ab 100644
93dc2d
--- a/elf/Makefile
93dc2d
+++ b/elf/Makefile
93dc2d
@@ -64,6 +64,7 @@ dl-routines = \
93dc2d
   dl-object \
93dc2d
   dl-open \
93dc2d
   dl-origin \
93dc2d
+  dl-printf \
93dc2d
   dl-profile \
93dc2d
   dl-reloc \
93dc2d
   dl-runtime \
93dc2d
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
93dc2d
index b256d792c6198683..f17140b129343f7b 100644
93dc2d
--- a/elf/dl-misc.c
93dc2d
+++ b/elf/dl-misc.c
93dc2d
@@ -16,24 +16,16 @@
93dc2d
    License along with the GNU C Library; if not, see
93dc2d
    <https://www.gnu.org/licenses/>.  */
93dc2d
 
93dc2d
-#include <assert.h>
93dc2d
+#include <_itoa.h>
93dc2d
 #include <fcntl.h>
93dc2d
 #include <ldsodefs.h>
93dc2d
-#include <limits.h>
93dc2d
 #include <link.h>
93dc2d
-#include <stdarg.h>
93dc2d
-#include <stdlib.h>
93dc2d
-#include <string.h>
93dc2d
-#include <unistd.h>
93dc2d
+#include <not-cancel.h>
93dc2d
 #include <stdint.h>
93dc2d
+#include <stdlib.h>
93dc2d
 #include <sys/mman.h>
93dc2d
-#include <sys/param.h>
93dc2d
 #include <sys/stat.h>
93dc2d
-#include <sys/uio.h>
93dc2d
-#include <sysdep.h>
93dc2d
-#include <_itoa.h>
93dc2d
-#include <dl-writev.h>
93dc2d
-#include <not-cancel.h>
93dc2d
+#include <unistd.h>
93dc2d
 
93dc2d
 /* Read the whole contents of FILE into new mmap'd space with given
93dc2d
    protections.  *SIZEP gets the size of the file.  On error MAP_FAILED
93dc2d
@@ -70,270 +62,6 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
93dc2d
   return result;
93dc2d
 }
93dc2d
 
93dc2d
-
93dc2d
-/* Bare-bones printf implementation.  This function only knows about
93dc2d
-   the formats and flags needed and can handle only up to 64 stripes in
93dc2d
-   the output.  */
93dc2d
-static void
93dc2d
-_dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
93dc2d
-{
93dc2d
-# define NIOVMAX 64
93dc2d
-  struct iovec iov[NIOVMAX];
93dc2d
-  int niov = 0;
93dc2d
-  pid_t pid = 0;
93dc2d
-  char pidbuf[12];
93dc2d
-
93dc2d
-  while (*fmt != '\0')
93dc2d
-    {
93dc2d
-      const char *startp = fmt;
93dc2d
-
93dc2d
-      if (tag_p > 0)
93dc2d
-	{
93dc2d
-	  /* Generate the tag line once.  It consists of the PID and a
93dc2d
-	     colon followed by a tab.  */
93dc2d
-	  if (pid == 0)
93dc2d
-	    {
93dc2d
-	      char *p;
93dc2d
-	      pid = __getpid ();
93dc2d
-	      assert (pid >= 0 && sizeof (pid_t) <= 4);
93dc2d
-	      p = _itoa (pid, &pidbuf[10], 10, 0);
93dc2d
-	      while (p > pidbuf)
93dc2d
-		*--p = ' ';
93dc2d
-	      pidbuf[10] = ':';
93dc2d
-	      pidbuf[11] = '\t';
93dc2d
-	    }
93dc2d
-
93dc2d
-	  /* Append to the output.  */
93dc2d
-	  assert (niov < NIOVMAX);
93dc2d
-	  iov[niov].iov_len = 12;
93dc2d
-	  iov[niov++].iov_base = pidbuf;
93dc2d
-
93dc2d
-	  /* No more tags until we see the next newline.  */
93dc2d
-	  tag_p = -1;
93dc2d
-	}
93dc2d
-
93dc2d
-      /* Skip everything except % and \n (if tags are needed).  */
93dc2d
-      while (*fmt != '\0' && *fmt != '%' && (! tag_p || *fmt != '\n'))
93dc2d
-	++fmt;
93dc2d
-
93dc2d
-      /* Append constant string.  */
93dc2d
-      assert (niov < NIOVMAX);
93dc2d
-      if ((iov[niov].iov_len = fmt - startp) != 0)
93dc2d
-	iov[niov++].iov_base = (char *) startp;
93dc2d
-
93dc2d
-      if (*fmt == '%')
93dc2d
-	{
93dc2d
-	  /* It is a format specifier.  */
93dc2d
-	  char fill = ' ';
93dc2d
-	  int width = -1;
93dc2d
-	  int prec = -1;
93dc2d
-#if LONG_MAX != INT_MAX
93dc2d
-	  int long_mod = 0;
93dc2d
-#endif
93dc2d
-
93dc2d
-	  /* Recognize zero-digit fill flag.  */
93dc2d
-	  if (*++fmt == '0')
93dc2d
-	    {
93dc2d
-	      fill = '0';
93dc2d
-	      ++fmt;
93dc2d
-	    }
93dc2d
-
93dc2d
-	  /* See whether with comes from a parameter.  Note that no other
93dc2d
-	     way to specify the width is implemented.  */
93dc2d
-	  if (*fmt == '*')
93dc2d
-	    {
93dc2d
-	      width = va_arg (arg, int);
93dc2d
-	      ++fmt;
93dc2d
-	    }
93dc2d
-
93dc2d
-	  /* Handle precision.  */
93dc2d
-	  if (*fmt == '.' && fmt[1] == '*')
93dc2d
-	    {
93dc2d
-	      prec = va_arg (arg, int);
93dc2d
-	      fmt += 2;
93dc2d
-	    }
93dc2d
-
93dc2d
-	  /* Recognize the l modifier.  It is only important on some
93dc2d
-	     platforms where long and int have a different size.  We
93dc2d
-	     can use the same code for size_t.  */
93dc2d
-	  if (*fmt == 'l' || *fmt == 'Z')
93dc2d
-	    {
93dc2d
-#if LONG_MAX != INT_MAX
93dc2d
-	      long_mod = 1;
93dc2d
-#endif
93dc2d
-	      ++fmt;
93dc2d
-	    }
93dc2d
-
93dc2d
-	  switch (*fmt)
93dc2d
-	    {
93dc2d
-	      /* Integer formatting.  */
93dc2d
-	    case 'd':
93dc2d
-	    case 'u':
93dc2d
-	    case 'x':
93dc2d
-	      {
93dc2d
-		/* We have to make a difference if long and int have a
93dc2d
-		   different size.  */
93dc2d
-#if LONG_MAX != INT_MAX
93dc2d
-		unsigned long int num = (long_mod
93dc2d
-					 ? va_arg (arg, unsigned long int)
93dc2d
-					 : va_arg (arg, unsigned int));
93dc2d
-#else
93dc2d
-		unsigned long int num = va_arg (arg, unsigned int);
93dc2d
-#endif
93dc2d
-		bool negative = false;
93dc2d
-		if (*fmt == 'd')
93dc2d
-		  {
93dc2d
-#if LONG_MAX != INT_MAX
93dc2d
-		    if (long_mod)
93dc2d
-		      {
93dc2d
-			if ((long int) num < 0)
93dc2d
-			  negative = true;
93dc2d
-		      }
93dc2d
-		    else
93dc2d
-		      {
93dc2d
-			if ((int) num < 0)
93dc2d
-			  {
93dc2d
-			    num = (unsigned int) num;
93dc2d
-			    negative = true;
93dc2d
-			  }
93dc2d
-		      }
93dc2d
-#else
93dc2d
-		    if ((int) num < 0)
93dc2d
-		      negative = true;
93dc2d
-#endif
93dc2d
-		  }
93dc2d
-
93dc2d
-		/* We use alloca() to allocate the buffer with the most
93dc2d
-		   pessimistic guess for the size.  Using alloca() allows
93dc2d
-		   having more than one integer formatting in a call.  */
93dc2d
-		char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
93dc2d
-		char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
93dc2d
-		char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
93dc2d
-
93dc2d
-		/* Pad to the width the user specified.  */
93dc2d
-		if (width != -1)
93dc2d
-		  while (endp - cp < width)
93dc2d
-		    *--cp = fill;
93dc2d
-
93dc2d
-		if (negative)
93dc2d
-		  *--cp = '-';
93dc2d
-
93dc2d
-		iov[niov].iov_base = cp;
93dc2d
-		iov[niov].iov_len = endp - cp;
93dc2d
-		++niov;
93dc2d
-	      }
93dc2d
-	      break;
93dc2d
-
93dc2d
-	    case 's':
93dc2d
-	      /* Get the string argument.  */
93dc2d
-	      iov[niov].iov_base = va_arg (arg, char *);
93dc2d
-	      iov[niov].iov_len = strlen (iov[niov].iov_base);
93dc2d
-	      if (prec != -1)
93dc2d
-		iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
93dc2d
-	      ++niov;
93dc2d
-	      break;
93dc2d
-
93dc2d
-	    case '%':
93dc2d
-	      iov[niov].iov_base = (void *) fmt;
93dc2d
-	      iov[niov].iov_len = 1;
93dc2d
-	      ++niov;
93dc2d
-	      break;
93dc2d
-
93dc2d
-	    default:
93dc2d
-	      assert (! "invalid format specifier");
93dc2d
-	    }
93dc2d
-	  ++fmt;
93dc2d
-	}
93dc2d
-      else if (*fmt == '\n')
93dc2d
-	{
93dc2d
-	  /* See whether we have to print a single newline character.  */
93dc2d
-	  if (fmt == startp)
93dc2d
-	    {
93dc2d
-	      iov[niov].iov_base = (char *) startp;
93dc2d
-	      iov[niov++].iov_len = 1;
93dc2d
-	    }
93dc2d
-	  else
93dc2d
-	    /* No, just add it to the rest of the string.  */
93dc2d
-	    ++iov[niov - 1].iov_len;
93dc2d
-
93dc2d
-	  /* Next line, print a tag again.  */
93dc2d
-	  tag_p = 1;
93dc2d
-	  ++fmt;
93dc2d
-	}
93dc2d
-    }
93dc2d
-
93dc2d
-  /* Finally write the result.  */
93dc2d
-  _dl_writev (fd, iov, niov);
93dc2d
-}
93dc2d
-
93dc2d
-
93dc2d
-/* Write to debug file.  */
93dc2d
-void
93dc2d
-_dl_debug_printf (const char *fmt, ...)
93dc2d
-{
93dc2d
-  va_list arg;
93dc2d
-
93dc2d
-  va_start (arg, fmt);
93dc2d
-  _dl_debug_vdprintf (GLRO(dl_debug_fd), 1, fmt, arg);
93dc2d
-  va_end (arg);
93dc2d
-}
93dc2d
-
93dc2d
-
93dc2d
-/* Write to debug file but don't start with a tag.  */
93dc2d
-void
93dc2d
-_dl_debug_printf_c (const char *fmt, ...)
93dc2d
-{
93dc2d
-  va_list arg;
93dc2d
-
93dc2d
-  va_start (arg, fmt);
93dc2d
-  _dl_debug_vdprintf (GLRO(dl_debug_fd), -1, fmt, arg);
93dc2d
-  va_end (arg);
93dc2d
-}
93dc2d
-
93dc2d
-
93dc2d
-/* Write the given file descriptor.  */
93dc2d
-void
93dc2d
-_dl_dprintf (int fd, const char *fmt, ...)
93dc2d
-{
93dc2d
-  va_list arg;
93dc2d
-
93dc2d
-  va_start (arg, fmt);
93dc2d
-  _dl_debug_vdprintf (fd, 0, fmt, arg);
93dc2d
-  va_end (arg);
93dc2d
-}
93dc2d
-
93dc2d
-void
93dc2d
-_dl_printf (const char *fmt, ...)
93dc2d
-{
93dc2d
-  va_list arg;
93dc2d
-
93dc2d
-  va_start (arg, fmt);
93dc2d
-  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
93dc2d
-  va_end (arg);
93dc2d
-}
93dc2d
-
93dc2d
-void
93dc2d
-_dl_error_printf (const char *fmt, ...)
93dc2d
-{
93dc2d
-  va_list arg;
93dc2d
-
93dc2d
-  va_start (arg, fmt);
93dc2d
-  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
93dc2d
-  va_end (arg);
93dc2d
-}
93dc2d
-
93dc2d
-void
93dc2d
-_dl_fatal_printf (const char *fmt, ...)
93dc2d
-{
93dc2d
-  va_list arg;
93dc2d
-
93dc2d
-  va_start (arg, fmt);
93dc2d
-  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
93dc2d
-  va_end (arg);
93dc2d
-  _exit (127);
93dc2d
-}
93dc2d
-rtld_hidden_def (_dl_fatal_printf)
93dc2d
-
93dc2d
 /* Test whether given NAME matches any of the names of the given object.  */
93dc2d
 int
93dc2d
 _dl_name_match_p (const char *name, const struct link_map *map)
93dc2d
@@ -354,7 +82,6 @@ _dl_name_match_p (const char *name, const struct link_map *map)
93dc2d
   return 0;
93dc2d
 }
93dc2d
 
93dc2d
-
93dc2d
 unsigned long int
93dc2d
 _dl_higher_prime_number (unsigned long int n)
93dc2d
 {
93dc2d
diff --git a/elf/dl-printf.c b/elf/dl-printf.c
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..d3264ba96cd959bf
93dc2d
--- /dev/null
93dc2d
+++ b/elf/dl-printf.c
93dc2d
@@ -0,0 +1,292 @@
93dc2d
+/* printf implementation for the dynamic loader.
93dc2d
+   Copyright (C) 1997-2022 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library; if not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+#include <_itoa.h>
93dc2d
+#include <assert.h>
93dc2d
+#include <dl-writev.h>
93dc2d
+#include <ldsodefs.h>
93dc2d
+#include <limits.h>
93dc2d
+#include <stdarg.h>
93dc2d
+#include <stdint.h>
93dc2d
+#include <stdlib.h>
93dc2d
+#include <string.h>
93dc2d
+#include <sys/uio.h>
93dc2d
+#include <unistd.h>
93dc2d
+
93dc2d
+/* Bare-bones printf implementation.  This function only knows about
93dc2d
+   the formats and flags needed and can handle only up to 64 stripes in
93dc2d
+   the output.  */
93dc2d
+static void
93dc2d
+_dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
93dc2d
+{
93dc2d
+# define NIOVMAX 64
93dc2d
+  struct iovec iov[NIOVMAX];
93dc2d
+  int niov = 0;
93dc2d
+  pid_t pid = 0;
93dc2d
+  char pidbuf[12];
93dc2d
+
93dc2d
+  while (*fmt != '\0')
93dc2d
+    {
93dc2d
+      const char *startp = fmt;
93dc2d
+
93dc2d
+      if (tag_p > 0)
93dc2d
+	{
93dc2d
+	  /* Generate the tag line once.  It consists of the PID and a
93dc2d
+	     colon followed by a tab.  */
93dc2d
+	  if (pid == 0)
93dc2d
+	    {
93dc2d
+	      char *p;
93dc2d
+	      pid = __getpid ();
93dc2d
+	      assert (pid >= 0 && sizeof (pid_t) <= 4);
93dc2d
+	      p = _itoa (pid, &pidbuf[10], 10, 0);
93dc2d
+	      while (p > pidbuf)
93dc2d
+		*--p = ' ';
93dc2d
+	      pidbuf[10] = ':';
93dc2d
+	      pidbuf[11] = '\t';
93dc2d
+	    }
93dc2d
+
93dc2d
+	  /* Append to the output.  */
93dc2d
+	  assert (niov < NIOVMAX);
93dc2d
+	  iov[niov].iov_len = 12;
93dc2d
+	  iov[niov++].iov_base = pidbuf;
93dc2d
+
93dc2d
+	  /* No more tags until we see the next newline.  */
93dc2d
+	  tag_p = -1;
93dc2d
+	}
93dc2d
+
93dc2d
+      /* Skip everything except % and \n (if tags are needed).  */
93dc2d
+      while (*fmt != '\0' && *fmt != '%' && (! tag_p || *fmt != '\n'))
93dc2d
+	++fmt;
93dc2d
+
93dc2d
+      /* Append constant string.  */
93dc2d
+      assert (niov < NIOVMAX);
93dc2d
+      if ((iov[niov].iov_len = fmt - startp) != 0)
93dc2d
+	iov[niov++].iov_base = (char *) startp;
93dc2d
+
93dc2d
+      if (*fmt == '%')
93dc2d
+	{
93dc2d
+	  /* It is a format specifier.  */
93dc2d
+	  char fill = ' ';
93dc2d
+	  int width = -1;
93dc2d
+	  int prec = -1;
93dc2d
+#if LONG_MAX != INT_MAX
93dc2d
+	  int long_mod = 0;
93dc2d
+#endif
93dc2d
+
93dc2d
+	  /* Recognize zero-digit fill flag.  */
93dc2d
+	  if (*++fmt == '0')
93dc2d
+	    {
93dc2d
+	      fill = '0';
93dc2d
+	      ++fmt;
93dc2d
+	    }
93dc2d
+
93dc2d
+	  /* See whether with comes from a parameter.  Note that no other
93dc2d
+	     way to specify the width is implemented.  */
93dc2d
+	  if (*fmt == '*')
93dc2d
+	    {
93dc2d
+	      width = va_arg (arg, int);
93dc2d
+	      ++fmt;
93dc2d
+	    }
93dc2d
+
93dc2d
+	  /* Handle precision.  */
93dc2d
+	  if (*fmt == '.' && fmt[1] == '*')
93dc2d
+	    {
93dc2d
+	      prec = va_arg (arg, int);
93dc2d
+	      fmt += 2;
93dc2d
+	    }
93dc2d
+
93dc2d
+	  /* Recognize the l modifier.  It is only important on some
93dc2d
+	     platforms where long and int have a different size.  We
93dc2d
+	     can use the same code for size_t.  */
93dc2d
+	  if (*fmt == 'l' || *fmt == 'Z')
93dc2d
+	    {
93dc2d
+#if LONG_MAX != INT_MAX
93dc2d
+	      long_mod = 1;
93dc2d
+#endif
93dc2d
+	      ++fmt;
93dc2d
+	    }
93dc2d
+
93dc2d
+	  switch (*fmt)
93dc2d
+	    {
93dc2d
+	      /* Integer formatting.  */
93dc2d
+	    case 'd':
93dc2d
+	    case 'u':
93dc2d
+	    case 'x':
93dc2d
+	      {
93dc2d
+		/* We have to make a difference if long and int have a
93dc2d
+		   different size.  */
93dc2d
+#if LONG_MAX != INT_MAX
93dc2d
+		unsigned long int num = (long_mod
93dc2d
+					 ? va_arg (arg, unsigned long int)
93dc2d
+					 : va_arg (arg, unsigned int));
93dc2d
+#else
93dc2d
+		unsigned long int num = va_arg (arg, unsigned int);
93dc2d
+#endif
93dc2d
+		bool negative = false;
93dc2d
+		if (*fmt == 'd')
93dc2d
+		  {
93dc2d
+#if LONG_MAX != INT_MAX
93dc2d
+		    if (long_mod)
93dc2d
+		      {
93dc2d
+			if ((long int) num < 0)
93dc2d
+			  negative = true;
93dc2d
+		      }
93dc2d
+		    else
93dc2d
+		      {
93dc2d
+			if ((int) num < 0)
93dc2d
+			  {
93dc2d
+			    num = (unsigned int) num;
93dc2d
+			    negative = true;
93dc2d
+			  }
93dc2d
+		      }
93dc2d
+#else
93dc2d
+		    if ((int) num < 0)
93dc2d
+		      negative = true;
93dc2d
+#endif
93dc2d
+		  }
93dc2d
+
93dc2d
+		/* We use alloca() to allocate the buffer with the most
93dc2d
+		   pessimistic guess for the size.  Using alloca() allows
93dc2d
+		   having more than one integer formatting in a call.  */
93dc2d
+		char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
93dc2d
+		char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
93dc2d
+		char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
93dc2d
+
93dc2d
+		/* Pad to the width the user specified.  */
93dc2d
+		if (width != -1)
93dc2d
+		  while (endp - cp < width)
93dc2d
+		    *--cp = fill;
93dc2d
+
93dc2d
+		if (negative)
93dc2d
+		  *--cp = '-';
93dc2d
+
93dc2d
+		iov[niov].iov_base = cp;
93dc2d
+		iov[niov].iov_len = endp - cp;
93dc2d
+		++niov;
93dc2d
+	      }
93dc2d
+	      break;
93dc2d
+
93dc2d
+	    case 's':
93dc2d
+	      /* Get the string argument.  */
93dc2d
+	      iov[niov].iov_base = va_arg (arg, char *);
93dc2d
+	      iov[niov].iov_len = strlen (iov[niov].iov_base);
93dc2d
+	      if (prec != -1)
93dc2d
+		iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
93dc2d
+	      ++niov;
93dc2d
+	      break;
93dc2d
+
93dc2d
+	    case '%':
93dc2d
+	      iov[niov].iov_base = (void *) fmt;
93dc2d
+	      iov[niov].iov_len = 1;
93dc2d
+	      ++niov;
93dc2d
+	      break;
93dc2d
+
93dc2d
+	    default:
93dc2d
+	      assert (! "invalid format specifier");
93dc2d
+	    }
93dc2d
+	  ++fmt;
93dc2d
+	}
93dc2d
+      else if (*fmt == '\n')
93dc2d
+	{
93dc2d
+	  /* See whether we have to print a single newline character.  */
93dc2d
+	  if (fmt == startp)
93dc2d
+	    {
93dc2d
+	      iov[niov].iov_base = (char *) startp;
93dc2d
+	      iov[niov++].iov_len = 1;
93dc2d
+	    }
93dc2d
+	  else
93dc2d
+	    /* No, just add it to the rest of the string.  */
93dc2d
+	    ++iov[niov - 1].iov_len;
93dc2d
+
93dc2d
+	  /* Next line, print a tag again.  */
93dc2d
+	  tag_p = 1;
93dc2d
+	  ++fmt;
93dc2d
+	}
93dc2d
+    }
93dc2d
+
93dc2d
+  /* Finally write the result.  */
93dc2d
+  _dl_writev (fd, iov, niov);
93dc2d
+}
93dc2d
+
93dc2d
+
93dc2d
+/* Write to debug file.  */
93dc2d
+void
93dc2d
+_dl_debug_printf (const char *fmt, ...)
93dc2d
+{
93dc2d
+  va_list arg;
93dc2d
+
93dc2d
+  va_start (arg, fmt);
93dc2d
+  _dl_debug_vdprintf (GLRO(dl_debug_fd), 1, fmt, arg);
93dc2d
+  va_end (arg);
93dc2d
+}
93dc2d
+
93dc2d
+
93dc2d
+/* Write to debug file but don't start with a tag.  */
93dc2d
+void
93dc2d
+_dl_debug_printf_c (const char *fmt, ...)
93dc2d
+{
93dc2d
+  va_list arg;
93dc2d
+
93dc2d
+  va_start (arg, fmt);
93dc2d
+  _dl_debug_vdprintf (GLRO(dl_debug_fd), -1, fmt, arg);
93dc2d
+  va_end (arg);
93dc2d
+}
93dc2d
+
93dc2d
+
93dc2d
+/* Write the given file descriptor.  */
93dc2d
+void
93dc2d
+_dl_dprintf (int fd, const char *fmt, ...)
93dc2d
+{
93dc2d
+  va_list arg;
93dc2d
+
93dc2d
+  va_start (arg, fmt);
93dc2d
+  _dl_debug_vdprintf (fd, 0, fmt, arg);
93dc2d
+  va_end (arg);
93dc2d
+}
93dc2d
+
93dc2d
+void
93dc2d
+_dl_printf (const char *fmt, ...)
93dc2d
+{
93dc2d
+  va_list arg;
93dc2d
+
93dc2d
+  va_start (arg, fmt);
93dc2d
+  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
93dc2d
+  va_end (arg);
93dc2d
+}
93dc2d
+
93dc2d
+void
93dc2d
+_dl_error_printf (const char *fmt, ...)
93dc2d
+{
93dc2d
+  va_list arg;
93dc2d
+
93dc2d
+  va_start (arg, fmt);
93dc2d
+  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
93dc2d
+  va_end (arg);
93dc2d
+}
93dc2d
+
93dc2d
+void
93dc2d
+_dl_fatal_printf (const char *fmt, ...)
93dc2d
+{
93dc2d
+  va_list arg;
93dc2d
+
93dc2d
+  va_start (arg, fmt);
93dc2d
+  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
93dc2d
+  va_end (arg);
93dc2d
+  _exit (127);
93dc2d
+}
93dc2d
+rtld_hidden_def (_dl_fatal_printf)