]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Implement ld.so --version
authorFlorian Weimer <fweimer@redhat.com>
Thu, 8 Oct 2020 13:33:00 +0000 (15:33 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 8 Oct 2020 13:33:00 +0000 (15:33 +0200)
This prints out version information for the dynamic loader and
exits immediately, without further command line processing
(which seems to match what some GNU tools do).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
elf/dl-main.h
elf/dl-usage.c
elf/rtld.c

index ac7249a580214860fcaea97cc3e5ba9d621dc244..b51256d3b48230b08e2ad5ae71a4e2ad1d35f310 100644 (file)
@@ -105,6 +105,9 @@ call_init_paths (const struct dl_main_state *state)
 _Noreturn void _dl_usage (const char *argv0, const char *wrong_option)
   attribute_hidden;
 
+/* Print ld.so version information and exit.  */
+_Noreturn void _dl_version (void) attribute_hidden;
+
 /* Print ld.so --help output and exit.  */
 _Noreturn void _dl_help (const char *argv0, struct dl_main_state *state)
   attribute_hidden;
index c1820dca2fa117eea5f1270e91cb3043c1f6280f..f3c5ac76d37f9c03616b4362862ceec1cf0e4a83 100644 (file)
@@ -20,6 +20,7 @@
 #include <dl-main.h>
 #include <ldsodefs.h>
 #include <unistd.h>
+#include "version.h"
 
 void
 _dl_usage (const char *argv0, const char *wrong_option)
@@ -32,6 +33,19 @@ _dl_usage (const char *argv0, const char *wrong_option)
   _exit (EXIT_FAILURE);
 }
 
+void
+_dl_version (void)
+{
+  _dl_printf ("\
+ld.so " PKGVERSION RELEASE " release version " VERSION ".\n\
+Copyright (C) 2020 Free Software Foundation, Inc.\n\
+This is free software; see the source for copying conditions.\n\
+There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
+PARTICULAR PURPOSE.\n\
+");
+  _exit (EXIT_SUCCESS);
+}
+
 void
 _dl_help (const char *argv0, struct dl_main_state *state)
 {
@@ -61,6 +75,7 @@ of this helper program; chances are you did not intend to run this program.\n\
   --preload LIST        preload objects named in LIST\n\
   --argv0 STRING        set argv[0] to STRING before running\n\
   --help                display this help and exit\n\
+  --version             output version information and exit\n\
 ",
               argv0);
   _exit (EXIT_SUCCESS);
index 2eeec981a58ad22ee0e0f31771a8a879ccc32c69..fcf4bb70b18ed75ac060945374ea5133cf5a73ff 100644 (file)
@@ -1254,6 +1254,8 @@ dl_main (const ElfW(Phdr) *phdr,
            --_dl_argc;
            ++_dl_argv;
          }
+       else if (strcmp (_dl_argv[1], "--version") == 0)
+         _dl_version ();
        else if (_dl_argv[1][0] == '-' && _dl_argv[1][1] == '-')
          {
           if (_dl_argv[1][1] == '\0')