[08/28] elf: Implement ld.so --version
Commit Message
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(+)
Comments
On 01/10/2020 13:32, Florian Weimer via Libc-alpha wrote:
> 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).
Some comments below.
> ---
> elf/dl-main.h | 3 +++
> elf/dl-usage.c | 15 +++++++++++++++
> elf/rtld.c | 2 ++
> 3 files changed, 20 insertions(+)
>
> diff --git a/elf/dl-main.h b/elf/dl-main.h
> index 71ca5114de..0df849d3cd 100644
> --- a/elf/dl-main.h
> +++ b/elf/dl-main.h
> @@ -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__));
> +
Maybe _Noreturn here?
> /* Print ld.so --help output and exit. */
> void _dl_help (const char *argv0, struct dl_main_state *state)
> attribute_hidden __attribute__ ((__noreturn__));
> diff --git a/elf/dl-usage.c b/elf/dl-usage.c
> index 72ff99e70f..7355b094a5 100644
> --- a/elf/dl-usage.c
> +++ b/elf/dl-usage.c
> @@ -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);
> +}
> +
I think we will need a way to embedded the Copyright year using a macro
to avoid need to manually update it on each year.
> 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 (0);
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 5cdab3c99c..e0e8e98c2f 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -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')
>
Ok.
On 07/10/2020 15:36, Adhemerval Zanella wrote:
>
>
> On 01/10/2020 13:32, Florian Weimer via Libc-alpha wrote:
>> 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).
>
> Some comments below.
>
>> ---
>> elf/dl-main.h | 3 +++
>> elf/dl-usage.c | 15 +++++++++++++++
>> elf/rtld.c | 2 ++
>> 3 files changed, 20 insertions(+)
>>
>> diff --git a/elf/dl-main.h b/elf/dl-main.h
>> index 71ca5114de..0df849d3cd 100644
>> --- a/elf/dl-main.h
>> +++ b/elf/dl-main.h
>> @@ -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__));
>> +
>
> Maybe _Noreturn here?
>
>> /* Print ld.so --help output and exit. */
>> void _dl_help (const char *argv0, struct dl_main_state *state)
>> attribute_hidden __attribute__ ((__noreturn__));
>> diff --git a/elf/dl-usage.c b/elf/dl-usage.c
>> index 72ff99e70f..7355b094a5 100644
>> --- a/elf/dl-usage.c
>> +++ b/elf/dl-usage.c
>> @@ -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);
>> +}
>> +
>
> I think we will need a way to embedded the Copyright year using a macro
> to avoid need to manually update it on each year.
And I just noted you are handling on the scripts/update-copyrights,
so this should be ok.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
>> 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 (0);
>> diff --git a/elf/rtld.c b/elf/rtld.c
>> index 5cdab3c99c..e0e8e98c2f 100644
>> --- a/elf/rtld.c
>> +++ b/elf/rtld.c
>> @@ -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')
>>
>
> Ok.
>
* Adhemerval Zanella via Libc-alpha:
> Maybe _Noreturn here?
Fixed.
>> +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);
>> +}
Also switched to EXIT_SUCCESS here.
Pushed with these changes based on your later comment:
> And I just noted you are handling on the scripts/update-copyrights,
> so this should be ok.
>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Thanks,
Florian
@@ -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)
{
@@ -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 (0);
@@ -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')