From patchwork Mon Mar 30 17:43:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 38673 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 95F913887540 for ; Mon, 30 Mar 2020 17:43:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 95F913887540 Received: from noise.collabora.co.uk (unknown [IPv6:2a00:5f00:102:0:c0a7:51ff:feaf:e642]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id D40ED2966EA; Mon, 30 Mar 2020 18:43:57 +0100 (BST) From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= To: vivek@etla.org, libc-alpha@sourceware.org Subject: [RFC][PATCH v4 08/15] Abstract the loaded-DSO search code into a private helper function Date: Mon, 30 Mar 2020 18:43:42 +0100 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-Spam-Status: No, score=-27.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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: Mon, 30 Mar 2020 17:44:00 -0000 --- elf/dl-load.c | 38 ++++++++++++++++++++++++++++++++++++++ sysdeps/generic/ldsodefs.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/elf/dl-load.c b/elf/dl-load.c index 221589e292..d4d6a6318b 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1936,6 +1936,44 @@ _dl_find_proxy (Lmid_t nsid, const char *name) return NULL; } +/* search for a shared object in a given namespace. */ +struct link_map * +_dl_find_dso (const char *name, Lmid_t nsid) +{ + struct link_map *l; + + for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next) + { + /* If the requested name matches the soname of a loaded object, + use that object. Elide this check for names that have not + yet been opened. */ + if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0)) + continue; + if (!_dl_name_match_p (name, l)) + { + const char *soname; + + if (__glibc_likely (l->l_soname_added) + || l->l_info[DT_SONAME] == NULL) + continue; + + soname = ((const char *) D_PTR (l, l_info[DT_STRTAB]) + + l->l_info[DT_SONAME]->d_un.d_val); + if (strcmp (name, soname) != 0) + continue; + + /* We have a match on a new name -- cache it. */ + add_name_to_object (l, soname); + l->l_soname_added = 1; + } + + /* We have a match. */ + return l; + } + + return NULL; +} + /* Map in the shared object file NAME. */ struct link_map * diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index d3113ff4d8..3b5c5e9147 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1184,6 +1184,10 @@ extern void _dl_show_scope (struct link_map *new, int from) extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr); rtld_hidden_proto (_dl_find_dso_for_object) +extern struct link_map *_dl_find_dso (const char *name, Lmid_t nsid); +rtld_hidden_proto (_dl_find_dso) + + /* Initialization which is normally done by the dynamic linker. */ extern void _dl_non_dynamic_init (void) attribute_hidden;