From patchwork Thu Dec 7 10:32:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 81646 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 5B605384CB98 for ; Thu, 7 Dec 2023 10:33:42 +0000 (GMT) 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 3413E3858D20 for ; Thu, 7 Dec 2023 10:32:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3413E3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3413E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945139; cv=none; b=nbRfI+NGfTyxLDiH2Vf4BYnEj4qHVUYLeFAXyn8Z+S7FJqDqOPyF2/knDJOLPx/5QcNdLvRij2QSCxOj8Pw2+q6gvMOfTcxqzieO7rkJVqag7buGqMWYDmmChzmDltG8RRzPQE8b2SNRJ5xhQOehiMUrGFI7HvC02WdWbIaJw4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945139; c=relaxed/simple; bh=OEK6EdDL0E3z+OfZ0/+Q1dgoFJqREtLRzR/No6m/lts=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=HtiwnPkmxSc++/j1CKXbu0PjEUK/2JAhsAskSB0IlDSYO2ot+0Hk2X3pR9goHZlTdUiht6DxCgvs11ufyzCw5SQ+nRfHrMsJV4co6YRlcYNwSx0/lkMf2whgwPBHY66Xw1ab3vgsePDOOjRLwCQ6tehOOR2yP/gSZji4qpVkoyo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701945136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5qZdhRWMDos8091vKskYX9zyDfJqpft+o3BLXxbLLvA=; b=QbyZrDTnTySsiQqvlL3SikUNCAFZVxBR6YV7RZJL6SBPZVP6po7EL6W0aDBJOCyi7u1fL4 5zZq2CGLiAOfRJXICJcK0gdJeKMF0of4+kDJRMUHAaY7EhrnlYD/w9vvPWg7o+TqaHt5AS 6KjRhSOgijrVPHtDXIRu++tKvD90ORI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690--b0QtIkcOcmA7kTYn_JbaQ-1; Thu, 07 Dec 2023 05:32:15 -0500 X-MC-Unique: -b0QtIkcOcmA7kTYn_JbaQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 440D23C100B5 for ; Thu, 7 Dec 2023 10:32:15 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C8F2492BE6 for ; Thu, 7 Dec 2023 10:32:14 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v3 19/32] elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object In-Reply-To: Message-ID: <67022e56b3c09868b8579f3bfceb80a41d3db659.1701944612.git.fweimer@redhat.com> References: X-From-Line: 67022e56b3c09868b8579f3bfceb80a41d3db659 Mon Sep 17 00:00:00 2001 Date: Thu, 07 Dec 2023 11:32:12 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.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_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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org 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 5c9aaf2eec..d45ae48354 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1904,24 +1904,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 @@ -1950,6 +1940,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) @@ -2204,6 +2210,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 d6d45f8c69..01f99a57b7 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