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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id EAC77398B837 for ; Thu, 1 Oct 2020 16:33:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EAC77398B837 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-133-u-rQAtRvMEqV54An9MDITQ-1; Thu, 01 Oct 2020 12:33:01 -0400 X-MC-Unique: u-rQAtRvMEqV54An9MDITQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A62080364B for ; Thu, 1 Oct 2020 16:33:00 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-114-84.ams2.redhat.com [10.36.114.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DA6655793 for ; Thu, 1 Oct 2020 16:32:59 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 13/28] elf: Add library search path information to ld.so --help In-Reply-To: References: Message-Id: Date: Thu, 01 Oct 2020 18:32:57 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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, 01 Oct 2020 16:33:10 -0000 --- elf/dl-usage.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/elf/dl-usage.c b/elf/dl-usage.c index 0a62e8f7cf..20aa715cb1 100644 --- a/elf/dl-usage.c +++ b/elf/dl-usage.c @@ -46,6 +46,61 @@ PARTICULAR PURPOSE.\n\ _exit (0); } +/* Print part of the library search path (from a single source). */ +static void +print_search_path_for_help_1 (struct r_search_path_elem **list) +{ + if (list == NULL || list == (void *) -1) + /* Path is missing or marked as inactive. */ + return; + + for (; *list != NULL; ++list) + { + (void) _dl_write (STDOUT_FILENO, " ", 2); + const char *name = (*list)->dirname; + size_t namelen = (*list)->dirnamelen; + if (namelen == 0) + { + /* The empty string denotes the current directory. */ + name = "."; + namelen = 1; + } + else if (namelen > 1) + /* Remove the trailing slash. */ + --namelen; + (void) _dl_write (STDOUT_FILENO, name, namelen); + _dl_printf (" (%s)\n", (*list)->what); + } +} + +/* Prints the library search path. See _dl_init_paths in dl-load.c + how this information is populated. */ +static void +print_search_path_for_help (struct dl_main_state *state) +{ + if (__rtld_search_dirs.dirs == NULL) + /* The run-time search paths have not yet been initialized. */ + _dl_init_paths (state->library_path, state->library_path_source); + + _dl_printf ("\nShared library search path:\n"); + + /* The print order should reflect the processing in + _dl_map_object. */ + + struct link_map *map = GL(dl_ns)[LM_ID_BASE]._ns_loaded; + if (map != NULL) + print_search_path_for_help_1 (map->l_rpath_dirs.dirs); + + print_search_path_for_help_1 (__rtld_env_path_list.dirs); + + if (map != NULL) + print_search_path_for_help_1 (map->l_runpath_dirs.dirs); + + _dl_printf (" (libraries located via %s)\n", LD_SO_CACHE); + + print_search_path_for_help_1 (__rtld_search_dirs.dirs); +} + void _dl_help (const char *argv0, struct dl_main_state *state) { @@ -80,5 +135,6 @@ setting environment variables (which would be inherted by subprocesses).\n\ This program interpreter self-identifies as: " RTLD "\n\ ", argv0); + print_search_path_for_help (state); _exit (0); } -- 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