446cf2
commit de42613540de8d3d70b5f14a14923cab7bd694d0
446cf2
Author: Florian Weimer <fweimer@redhat.com>
446cf2
Date:   Mon May 25 18:17:27 2020 +0200
446cf2
446cf2
    elf: Turn _dl_printf, _dl_error_printf, _dl_fatal_printf into functions
446cf2
    
446cf2
    This change makes it easier to set a breakpoint on these calls.
446cf2
    
446cf2
    This also addresses the issue that including <ldsodefs.h> without
446cf2
    <unistd.h> does not result usable _dl_*printf macros because of the
446cf2
    use of the STD*_FILENO macros there.
446cf2
    
446cf2
    (The private symbol for _dl_fatal_printf will go away again
446cf2
    once the exception handling implementation is unified between
446cf2
    libc and ld.so.)
446cf2
    
446cf2
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
446cf2
446cf2
diff --git a/elf/Versions b/elf/Versions
446cf2
index 3be879c4adfa74c7..be88c48e6d45a937 100644
446cf2
--- a/elf/Versions
446cf2
+++ b/elf/Versions
446cf2
@@ -58,7 +58,7 @@ ld {
446cf2
     _dl_allocate_tls; _dl_allocate_tls_init;
446cf2
     _dl_argv; _dl_find_dso_for_object; _dl_get_tls_static_info;
446cf2
     _dl_deallocate_tls; _dl_make_stack_executable;
446cf2
-    _dl_rtld_di_serinfo; _dl_starting_up;
446cf2
+    _dl_rtld_di_serinfo; _dl_starting_up; _dl_fatal_printf;
446cf2
     _rtld_global; _rtld_global_ro;
446cf2
 
446cf2
     # Only here for gdb while a better method is developed.
446cf2
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
446cf2
index 3f28de3ee9d68368..508630e444d2a00c 100644
446cf2
--- a/elf/dl-misc.c
446cf2
+++ b/elf/dl-misc.c
446cf2
@@ -302,6 +302,37 @@ _dl_dprintf (int fd, const char *fmt, ...)
446cf2
   va_end (arg);
446cf2
 }
446cf2
 
446cf2
+void
446cf2
+_dl_printf (const char *fmt, ...)
446cf2
+{
446cf2
+  va_list arg;
446cf2
+
446cf2
+  va_start (arg, fmt);
446cf2
+  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
446cf2
+  va_end (arg);
446cf2
+}
446cf2
+
446cf2
+void
446cf2
+_dl_error_printf (const char *fmt, ...)
446cf2
+{
446cf2
+  va_list arg;
446cf2
+
446cf2
+  va_start (arg, fmt);
446cf2
+  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
446cf2
+  va_end (arg);
446cf2
+}
446cf2
+
446cf2
+void
446cf2
+_dl_fatal_printf (const char *fmt, ...)
446cf2
+{
446cf2
+  va_list arg;
446cf2
+
446cf2
+  va_start (arg, fmt);
446cf2
+  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
446cf2
+  va_end (arg);
446cf2
+  _exit (127);
446cf2
+}
446cf2
+rtld_hidden_def (_dl_fatal_printf)
446cf2
 
446cf2
 /* Test whether given NAME matches any of the names of the given object.  */
446cf2
 int
446cf2
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
446cf2
index 77923499d3de4366..6cbbaa808a596f77 100644
446cf2
--- a/sysdeps/generic/ldsodefs.h
446cf2
+++ b/sysdeps/generic/ldsodefs.h
446cf2
@@ -762,24 +762,19 @@ ssize_t _dl_write (int fd, const void *buffer, size_t length)
446cf2
 
446cf2
 /* Write a message on the specified descriptor standard output.  The
446cf2
    parameters are interpreted as for a `printf' call.  */
446cf2
-#define _dl_printf(fmt, args...) \
446cf2
-  _dl_dprintf (STDOUT_FILENO, fmt, ##args)
446cf2
+void _dl_printf (const char *fmt, ...)
446cf2
+  attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2)));
446cf2
 
446cf2
 /* Write a message on the specified descriptor standard error.  The
446cf2
    parameters are interpreted as for a `printf' call.  */
446cf2
-#define _dl_error_printf(fmt, args...) \
446cf2
-  _dl_dprintf (STDERR_FILENO, fmt, ##args)
446cf2
+void _dl_error_printf (const char *fmt, ...)
446cf2
+  attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2)));
446cf2
 
446cf2
 /* Write a message on the specified descriptor standard error and exit
446cf2
    the program.  The parameters are interpreted as for a `printf' call.  */
446cf2
-#define _dl_fatal_printf(fmt, args...) \
446cf2
-  do									      \
446cf2
-    {									      \
446cf2
-      _dl_dprintf (STDERR_FILENO, fmt, ##args);				      \
446cf2
-      _exit (127);							      \
446cf2
-    }									      \
446cf2
-  while (1)
446cf2
-
446cf2
+void _dl_fatal_printf (const char *fmt, ...)
446cf2
+  __attribute__ ((__format__ (__printf__, 1, 2), __noreturn__));
446cf2
+rtld_hidden_proto (_dl_fatal_printf)
446cf2
 
446cf2
 /* An exception raised by the _dl_signal_error function family and
446cf2
    caught by _dl_catch_error function family.  Exceptions themselves
446cf2
diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
446cf2
index 4b9dbf5acc088cff..eb79216e3b494486 100644
446cf2
--- a/sysdeps/mach/hurd/i386/localplt.data
446cf2
+++ b/sysdeps/mach/hurd/i386/localplt.data
446cf2
@@ -43,6 +43,7 @@ ld.so: _dl_allocate_tls_init
446cf2
 ld.so: _dl_exception_create
446cf2
 ld.so: _dl_exception_create_format
446cf2
 ld.so: _dl_exception_free
446cf2
+ld.so: _dl_fatal_printf
446cf2
 ld.so: _dl_find_dso_for_object
446cf2
 ld.so: _dl_init_first
446cf2
 ld.so: _dl_mcount