From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id EE17B3861817 for ; Thu, 8 Oct 2020 13:13:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EE17B3861817 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-_J6K8XUhOfygZwKYw1n2dQ-1; Thu, 08 Oct 2020 09:13:48 -0400 X-MC-Unique: _J6K8XUhOfygZwKYw1n2dQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38CADED557; Thu, 8 Oct 2020 13:13:47 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-154.ams2.redhat.com [10.36.113.154]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 608A419D7C; Thu, 8 Oct 2020 13:13:46 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH 07/28] elf: Implement ld.so --help References: <05bb7e01b9a1cb063ec4619285a08bcb25fd6d97.1601569371.git.fweimer@redhat.com> <9e2b33e4-92a9-a238-cedd-e0ee87927bbe@linaro.org> Date: Thu, 08 Oct 2020 15:13:44 +0200 In-Reply-To: <9e2b33e4-92a9-a238-cedd-e0ee87927bbe@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Wed, 7 Oct 2020 14:16:51 -0300") Message-ID: <877ds0g8s7.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Oct 2020 13:13:53 -0000 * Adhemerval Zanella via Libc-alpha: >> @@ -98,6 +98,11 @@ call_init_paths (const struct dl_main_state *state) >> } >> >> /* Print ld.so usage information and exit. */ >> -void _dl_usage (void) attribute_hidden __attribute__ ((__noreturn__)); >> +void _dl_usage (const char *argv0, const char *wrong_option) >> + 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__)); >> >> #endif /* _DL_MAIN */ > > Maybe use _Noreturn here? Fixed. >> diff --git a/elf/dl-usage.c b/elf/dl-usage.c >> index f3d89d22b7..72ff99e70f 100644 >> --- a/elf/dl-usage.c >> +++ b/elf/dl-usage.c >> @@ -19,12 +19,24 @@ >> #include >> #include >> #include >> +#include >> >> void >> -_dl_usage (void) >> +_dl_usage (const char *argv0, const char *wrong_option) >> { >> - _dl_fatal_printf ("\ >> -Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\ >> + if (wrong_option != NULL) >> + _dl_error_printf ("%s: unrecognized option '%s'\n", argv0, wrong_option); >> + else >> + _dl_error_printf ("%s: missing program name\n", argv0); >> + _dl_error_printf ("Try '%s --help' for more information.\n", argv0); >> + _exit (1); >> +} >> + > > Maybe EXIT_FAILURE here? Fixed. >> +void >> +_dl_help (const char *argv0, struct dl_main_state *state) >> +{ >> + _dl_printf ("\ >> +Usage: %s [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\ >> You have invoked `ld.so', the helper program for shared library executables.\n\ >> This program usually lives in the file `/lib/ld.so', and special directives\n\ >> in executable files using ELF shared libraries tell the system's program\n\ >> @@ -47,5 +59,9 @@ of this helper program; chances are you did not intend to run this program.\n\ >> in LIST\n\ >> --audit LIST use objects named in LIST as auditors\n\ >> --preload LIST preload objects named in LIST\n\ >> - --argv0 STRING set argv[0] to STRING before running\n"); >> + --argv0 STRING set argv[0] to STRING before running\n\ >> + --help display this help and exit\n\ >> +", >> + argv0); >> + _exit (0); >> } > > Maybe EXIT_SUCCESS here? Fixed. >> /* If we have no further argument the program was called incorrectly. >> Grant the user some education. */ >> if (_dl_argc < 2) >> - _dl_usage (); >> + { >> + if (state.mode == rtld_help) >> + /* --help without an executable is not an error. */ >> + _dl_help (ld_so_name, &state); >> + else >> + _dl_usage (ld_so_name, NULL); >> + } >> > > Why open brackets here? There is no stack variable to possible escape. They are guarded by an if statement: /* If we have no further argument the program was called incorrectly. Grant the user some education. */ if (_dl_argc < 2) { if (state.mode == rtld_mode_help) /* --help without an executable is not an error. */ _dl_help (ld_so_name, &state); else _dl_usage (ld_so_name, NULL); } >> @@ -1647,6 +1681,11 @@ dl_main (const ElfW(Phdr) *phdr, >> audit_list_add_dynamic_tag (&state.audit_list, main_map, DT_AUDIT); >> audit_list_add_dynamic_tag (&state.audit_list, main_map, DT_DEPAUDIT); >> >> + /* At this point, all data has been obtained that is included in the >> + --help output. */ >> + if (__builtin_expect (state.mode, normal) == rtld_help) >> + _dl_help (ld_so_name, &state); >> + >> /* If we have auditing DSOs to load, do it now. */ >> bool need_security_init = true; >> if (state.audit_list.length > 0) >> > > Use __glibc_{un}likely or just remove the branch hint (I really don't think > this matter here anyway). Fixed. I've pushed this with the indicated changes (and the adjustments for renaming the enum constant to rtld_mode_help). Thanks, Florian -- Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill