From patchwork Fri Jul 7 18:48:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1805035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.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=KTe4D1n1; dkim-atps=neutral Received: from server2.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QyMvJ07sGz20WT for ; Sat, 8 Jul 2023 04:51:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03272388200F for ; Fri, 7 Jul 2023 18:51:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03272388200F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688755914; bh=mUop/9KIG0iOpOBi2Xh9q8FQ/kehSlGaKvyO17SvWg8=; 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=KTe4D1n1w8PhlzGfJSABlsTVjFnfpSetCA6/9YoTWyEz9DCc/WX9Qsk3p8CSB86zC NfkaQes/X08/4jFomene2LSc9uvbuzjruJWyMTYww+PpugIutShkgaINaFNZtX4j6m mkrB1oT3QfHsfwjmd8d2upf+DHrKfzPOCFYb4E08= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2B756387092A for ; Fri, 7 Jul 2023 18:49:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B756387092A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-IBsuZ1x9MVuw63y0unPwCw-1; Fri, 07 Jul 2023 14:48:59 -0400 X-MC-Unique: IBsuZ1x9MVuw63y0unPwCw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4DDE081DA5D for ; Fri, 7 Jul 2023 18:48:59 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6F24492B01 for ; Fri, 7 Jul 2023 18:48:58 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v2 19/32] elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object In-Reply-To: Message-ID: References: X-From-Line: d4dc2cae86d90bb47024b078d309a292d0ef201b Mon Sep 17 00:00:00 2001 Date: Fri, 07 Jul 2023 20:48:56 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" So that they can eventually be called separately from dlopen. --- elf/dl-load.c | 43 ++++++++++++++++++++++++++------------ sysdeps/generic/ldsodefs.h | 13 ++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 8867fab6bc..f78e23f34a 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1901,24 +1901,14 @@ open_path (const char *name, size_t namelen, int mode, return -1; } -/* Map in the shared object file NAME. */ - struct link_map_private * -_dl_map_object (struct link_map_private *loader, const char *name, - int type, int trace_mode, int mode, Lmid_t nsid) +_dl_lookup_map (Lmid_t nsid, const char *name) { - int fd; - const char *origname = NULL; - char *realname; - char *name_copy; - struct link_map_private *l; - struct filebuf fb; - assert (nsid >= 0); assert (nsid < GL(dl_nns)); - /* Look for this name among those already loaded. */ - for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l_next (l)) + for (struct link_map_private *l = GL(dl_ns)[nsid]._ns_loaded; + l != NULL; l = l_next (l)) { /* If the requested name matches the soname of a loaded object, use that object. Elide this check for names that have not @@ -1947,6 +1937,22 @@ _dl_map_object (struct link_map_private *loader, const char *name, return l; } + return NULL; +} + +/* Map in the shared object file NAME. */ + +struct link_map_private * +_dl_map_new_object (struct link_map_private *loader, const char *name, + int type, int trace_mode, int mode, Lmid_t nsid) +{ + int fd; + const char *origname = NULL; + char *realname; + char *name_copy; + struct link_map_private *l; + struct filebuf fb; + /* Display information if we are debugging. */ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES) && loader != NULL) @@ -2201,6 +2207,17 @@ _dl_map_object (struct link_map_private *loader, const char *name, type, mode, &stack_end, nsid); } +struct link_map_private * +_dl_map_object (struct link_map_private *loader, const char *name, + int type, int trace_mode, int mode, Lmid_t nsid) +{ + struct link_map_private *l = _dl_lookup_map (nsid, name); + if (l != NULL) + return l; + return _dl_map_new_object (loader, name, type, trace_mode, mode, nsid); +} + + struct add_path_state { bool counting; diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index cdba342f99..0af430a266 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -908,6 +908,11 @@ int _dl_catch_exception (struct dl_exception *exception, void (*operate) (void *), void *args); rtld_hidden_proto (_dl_catch_exception) +/* Search NSID for a map with NAME. If no such map is already loaded, + return NULL. */ +struct link_map_private *_dl_lookup_map (Lmid_t nsid, const char *name) + attribute_hidden; + /* Open the shared object NAME and map in its segments. LOADER's DT_RPATH is used in searching for NAME. If the object is already opened, returns its existing map. */ @@ -916,6 +921,14 @@ struct link_map_private *_dl_map_object (struct link_map_private * loader, int type, int trace_mode, int mode, Lmid_t nsid) attribute_hidden; +/* Like _dl_map_object, but assumes that NAME has not been loaded yet + (_dl_lookmap returned NULL). */ +struct link_map_private *_dl_map_new_object (struct link_map_private * loader, + const char *name, + int type, int trace_mode, int mode, + Lmid_t nsid) attribute_hidden; + + /* Call _dl_map_object on the dependencies of MAP, and set up MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously loaded objects that will be inserted into MAP->l_searchlist after MAP