e354a5
commit 542923d949e8b2480e48bd85fea13cf5d00d30b7
e354a5
Author: Florian Weimer <fweimer@redhat.com>
e354a5
Date:   Thu Oct 8 15:33:00 2020 +0200
e354a5
e354a5
    elf: Implement ld.so --version
e354a5
    
e354a5
    This prints out version information for the dynamic loader and
e354a5
    exits immediately, without further command line processing
e354a5
    (which seems to match what some GNU tools do).
e354a5
    
e354a5
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
e354a5
e354a5
diff --git a/elf/dl-main.h b/elf/dl-main.h
e354a5
index ac7249a580214860..b51256d3b48230b0 100644
e354a5
--- a/elf/dl-main.h
e354a5
+++ b/elf/dl-main.h
e354a5
@@ -105,6 +105,9 @@ call_init_paths (const struct dl_main_state *state)
e354a5
 _Noreturn void _dl_usage (const char *argv0, const char *wrong_option)
e354a5
   attribute_hidden;
e354a5
 
e354a5
+/* Print ld.so version information and exit.  */
e354a5
+_Noreturn void _dl_version (void) attribute_hidden;
e354a5
+
e354a5
 /* Print ld.so --help output and exit.  */
e354a5
 _Noreturn void _dl_help (const char *argv0, struct dl_main_state *state)
e354a5
   attribute_hidden;
e354a5
diff --git a/elf/dl-usage.c b/elf/dl-usage.c
e354a5
index c1820dca2fa117ee..f3c5ac76d37f9c03 100644
e354a5
--- a/elf/dl-usage.c
e354a5
+++ b/elf/dl-usage.c
e354a5
@@ -20,6 +20,7 @@
e354a5
 #include <dl-main.h>
e354a5
 #include <ldsodefs.h>
e354a5
 #include <unistd.h>
e354a5
+#include "version.h"
e354a5
 
e354a5
 void
e354a5
 _dl_usage (const char *argv0, const char *wrong_option)
e354a5
@@ -32,6 +33,19 @@ _dl_usage (const char *argv0, const char *wrong_option)
e354a5
   _exit (EXIT_FAILURE);
e354a5
 }
e354a5
 
e354a5
+void
e354a5
+_dl_version (void)
e354a5
+{
e354a5
+  _dl_printf ("\
e354a5
+ld.so " PKGVERSION RELEASE " release version " VERSION ".\n\
e354a5
+Copyright (C) 2020 Free Software Foundation, Inc.\n\
e354a5
+This is free software; see the source for copying conditions.\n\
e354a5
+There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
e354a5
+PARTICULAR PURPOSE.\n\
e354a5
+");
e354a5
+  _exit (EXIT_SUCCESS);
e354a5
+}
e354a5
+
e354a5
 void
e354a5
 _dl_help (const char *argv0, struct dl_main_state *state)
e354a5
 {
e354a5
@@ -61,6 +75,7 @@ of this helper program; chances are you did not intend to run this program.\n\
e354a5
   --preload LIST        preload objects named in LIST\n\
e354a5
   --argv0 STRING        set argv[0] to STRING before running\n\
e354a5
   --help                display this help and exit\n\
e354a5
+  --version             output version information and exit\n\
e354a5
 ",
e354a5
               argv0);
e354a5
   _exit (EXIT_SUCCESS);
e354a5
diff --git a/elf/rtld.c b/elf/rtld.c
e354a5
index b92641cb1c2d99a6..da1eef108508b95f 100644
e354a5
--- a/elf/rtld.c
e354a5
+++ b/elf/rtld.c
e354a5
@@ -1248,6 +1248,8 @@ dl_main (const ElfW(Phdr) *phdr,
e354a5
 	    --_dl_argc;
e354a5
 	    ++_dl_argv;
e354a5
 	  }
e354a5
+	else if (strcmp (_dl_argv[1], "--version") == 0)
e354a5
+	  _dl_version ();
e354a5
 	else if (_dl_argv[1][0] == '-' && _dl_argv[1][1] == '-')
e354a5
 	  {
e354a5
 	   if (_dl_argv[1][1] == '\0')