From patchwork Mon Jun 22 15:14:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1314527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=mG1VGQZn; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49rCd85Vjsz9sRW for ; Tue, 23 Jun 2020 01:14:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A8793947413; Mon, 22 Jun 2020 15:14:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A8793947413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592838868; bh=KsVR4Nm2eRyUhkB9A2Rs1u9oB/hKM7p1tI+1vDfjvf0=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mG1VGQZnD+PZaJAT/VSpOJNgIKRAw0xgmNmiKYJC6O9y7hHibgbX7dZ7/00tAqaEx BlX2Qv1jpgjq72WObjrRORmbBoiNpzwdFO+0VY9lo46vICxOc+1QMjyitbZHdxeIfM saBSZcJBB2ZJ7i75ObrOT/+m1RWCJGUoJc/ARYNc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id E0B173939C2C for ; Mon, 22 Jun 2020 15:14:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E0B173939C2C 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-432-xwjgKTQONpmq-5DZRiuk_g-1; Mon, 22 Jun 2020 11:14:23 -0400 X-MC-Unique: xwjgKTQONpmq-5DZRiuk_g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFCC48018AD for ; Mon, 22 Jun 2020 15:14:20 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-112-185.ams2.redhat.com [10.36.112.185]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CCD35C1BD for ; Mon, 22 Jun 2020 15:14:20 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 15/30] elf: Add library search path information to ld.so --help In-Reply-To: References: Message-Id: <9ea76cd783d71995a2380f4026f19dc6ecea0af7.1592836143.git.fweimer@redhat.com> Date: Mon, 22 Jun 2020 17:14:18 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 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_H3, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- elf/dl-usage.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/elf/dl-usage.c b/elf/dl-usage.c index 5caf9794c6..4712ab1c72 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) { @@ -79,5 +134,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); }