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).
---
elf/dl-main.h | 3 +++
elf/dl-usage.c | 15 +++++++++++++++
elf/rtld.c | 2 ++
3 files changed, 20 insertions(+)
@@ -101,6 +101,9 @@ call_init_paths (const struct dl_main_state *state)
void _dl_usage (const char *argv0, const char *wrong_option)
attribute_hidden __attribute__ ((__noreturn__));
+/* Print ld.so version information and exit. */
+void _dl_version (void) attribute_hidden __attribute__ ((__noreturn__));
+
/* Print ld.so --help output and exit. */
void _dl_help (const char *argv0, struct dl_main_state *state)
attribute_hidden __attribute__ ((__noreturn__));
@@ -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 (1);
}
+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 (0);
+}
+
void
_dl_help (const char *argv0, struct dl_main_state *state)
{
@@ -60,6 +74,7 @@ of this helper program; chances are you did not intend to run this program.\n\
--audit LIST use objects named in LIST as auditors\n\
--preload LIST preload objects named in LIST\n\
--help display this help and exit\n\
+ --version output version information and exit\n\
",
argv0);
_exit (0);
@@ -1224,6 +1224,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')