From patchwork Thu Oct 1 16:32:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 40599 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A7FA398546F; Thu, 1 Oct 2020 16:32:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A7FA398546F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601569945; bh=P6AhDwRjMUmfgD3E5soMvgasagNg60A+hpvINl3l9hs=; 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=ydbn4FDqwAu1DZla05J7xNIQqV2+QGbCoOlR5q7VOLciCBkAzebYaptnbX+jt5OvD uv0JgmqKBIjElk49K9ESJiXvKkRt4kwjvfHzbJF0a11243h9fk5QSC7zBxneTR1kZJ igGV27yYCWjAANmQqMxTO4fZUkHD+vuON2cSn2gE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 9295A398B81A for ; Thu, 1 Oct 2020 16:32:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9295A398B81A 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-536-gkrkQBobMV68d31og7ZCkw-1; Thu, 01 Oct 2020 12:32:18 -0400 X-MC-Unique: gkrkQBobMV68d31og7ZCkw-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 D6D17180F174 for ; Thu, 1 Oct 2020 16:32:17 +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 53B905576E for ; Thu, 1 Oct 2020 16:32:17 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 06/28] elf: Record whether paths come from LD_LIBRARY_PATH or --library-path In-Reply-To: References: Message-Id: Date: Thu, 01 Oct 2020 18:32:15 +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 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-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" This allows more precise diagnostics. Reviewed-by: Adhemerval Zanella --- elf/dl-load.c | 4 ++-- elf/dl-main.h | 5 ++++- elf/dl-support.c | 2 +- elf/rtld.c | 3 +++ sysdeps/generic/ldsodefs.h | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 5ba117d597..5fbb8c9ad4 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -682,7 +682,7 @@ cache_rpath (struct link_map *l, void -_dl_init_paths (const char *llp) +_dl_init_paths (const char *llp, const char *source) { size_t idx; const char *strp; @@ -820,7 +820,7 @@ _dl_init_paths (const char *llp) } (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;", - "LD_LIBRARY_PATH", NULL, l); + source, NULL, l); if (env_path_list.dirs[0] == NULL) { diff --git a/elf/dl-main.h b/elf/dl-main.h index 681f366871..68dd27d0d7 100644 --- a/elf/dl-main.h +++ b/elf/dl-main.h @@ -71,6 +71,9 @@ struct dl_main_state /* The library search path. */ const char *library_path; + /* Where library_path comes from. LD_LIBRARY_PATH or --library. */ + const char *library_path_source; + /* The list preloaded objects from LD_PRELOAD. */ const char *preloadlist; @@ -91,7 +94,7 @@ struct dl_main_state static inline void call_init_paths (const struct dl_main_state *state) { - _dl_init_paths (state->library_path); + _dl_init_paths (state->library_path, state->library_path_source); } /* Print ld.so usage information and exit. */ diff --git a/elf/dl-support.c b/elf/dl-support.c index 7704c101c5..afbc94df54 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -323,7 +323,7 @@ _dl_non_dynamic_init (void) /* Initialize the data structures for the search paths for shared objects. */ - _dl_init_paths (getenv ("LD_LIBRARY_PATH")); + _dl_init_paths (getenv ("LD_LIBRARY_PATH"), "LD_LIBRARY_PATH"); /* Remember the last search directory added at startup. */ _dl_init_all_dirs = GL(dl_all_dirs); diff --git a/elf/rtld.c b/elf/rtld.c index f3e1791e2f..d11fe22b83 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -286,6 +286,7 @@ dl_main_state_init (struct dl_main_state *state) { audit_list_init (&state->audit_list); state->library_path = NULL; + state->library_path_source = NULL; state->preloadlist = NULL; state->preloadarg = NULL; state->mode = normal; @@ -1203,6 +1204,7 @@ dl_main (const ElfW(Phdr) *phdr, && _dl_argc > 2) { state.library_path = _dl_argv[2]; + state.library_path_source = "--library_path"; _dl_skip_args += 2; _dl_argc -= 2; @@ -2655,6 +2657,7 @@ process_envvars (struct dl_main_state *state) && memcmp (envline, "LIBRARY_PATH", 12) == 0) { state->library_path = &envline[13]; + state->library_path_source = "LD_LIBRARY_PATH"; break; } diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 7cb1fccc80..510a2f6841 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1046,8 +1046,10 @@ rtld_hidden_proto (_dl_debug_state) extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns) attribute_hidden; -/* Initialize the basic data structure for the search paths. */ -extern void _dl_init_paths (const char *library_path) attribute_hidden; +/* Initialize the basic data structure for the search paths. SOURCE + is either "LD_LIBRARY_PATH" or "--library-path". */ +extern void _dl_init_paths (const char *library_path, const char *source) + attribute_hidden; /* Gather the information needed to install the profiling tables and start the timers. */