From patchwork Wed Jun 9 17:16:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 1490008 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) 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=dcCtT6wp; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4G0YhB6gHnz9sRf for ; Thu, 10 Jun 2021 03:17:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9C2139A142D for ; Wed, 9 Jun 2021 17:17:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9C2139A142D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623259048; bh=pDJn1XSMeYEHz+JjxKqSIAkPAIDr4oHoQQR2lFHhmyY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dcCtT6wpUVz9MXyhZCA5Olxd7CHAQWdiel0ns42gpJk8lP5aTfkH/P78r+T7EzIoW gTn6oG57yVjWT0yxCEirHvUXLIFAdGy/hEtKJzD+8L07h47GD7ckdwuRxnjV8eFvdf 7L66x1jtcLAi1xMZORDiP6NI44CdVnmDRt4gc1Qc= 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 79C30399C014 for ; Wed, 9 Jun 2021 17:16:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 79C30399C014 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (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 749E11F4356B for ; Wed, 9 Jun 2021 18:16:29 +0100 (BST) To: libc-alpha@sourceware.org Subject: [RFC][PATCH v11 2/7] Abstract loaded-DSO search code into a helper function Date: Wed, 9 Jun 2021 18:16:13 +0100 Message-Id: <20210609171618.20674-3-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210609171618.20674-1-vivek@collabora.com> References: <20210609171618.20674-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- 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 918ec7546c..579ec92b9b 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2027,6 +2027,44 @@ open_path (const char *name, size_t namelen, int mode, return -1; } +/* 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 != NULL; 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 176394de4d..44e7097712 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1287,6 +1287,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;