From patchwork Thu Dec 7 10:32:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 81658 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 5EF90384F9AE for ; Thu, 7 Dec 2023 10:35:12 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3172C3861842 for ; Thu, 7 Dec 2023 10:32:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3172C3861842 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 3172C3861842 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945167; cv=none; b=TIDiXUj3XJ/ZvNfGfx0L45EW9LEt3k3GXFIXrSbb5FUVBY2+ukDaTBNjlk7kbEQ1PIyHxUEx8Z6MqEKtH4THT5tbLfHiHVlC6Aq0KwDbMSCxiJHgpYeyw9KlU7n3ST8wcc0+opPql8BL90pLYG1U81/sr+FvXtrUpKtsk5OqRrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945167; c=relaxed/simple; bh=Wb11JXv5UZKBUEhWgFtTtZaOw+y2oc9NhHNEj9l9wNg=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=VlPtl9EfbZieTB1iyGJ1PQo6pm60Vz3KYUoFfuOJjyhFtnjk9yylAt2WoZJEayfggmUpL7LnSJJNXLw23wYOe4K/FHajvjWZqL0u0eH0h1Ji+R5t7tuO/q+NaN+pcErp5bp9F/k102+iYG0+2j/GNOBzjTrJWp9GMQA+SR6bm+k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701945165; 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=EhOcnmNFCdA9gPUiYI3L/R5J8u4Ag2ZI6+hsqyp7Fjk=; b=P7VzC9nD+DIiwzpDaTsF/jQNjq5kFlmxHr6umZFwSJJe0nk+oj+KST8REQzWzXgeeKveq2 5d2x2MXVPovw6/+33+DlfGt/2Vr1S3Oufc7uoBeSOHpuzrMXS+WzcVFsZ9tMFtapAaoMOP +r2XLGtNQVi4EOXw2siBjcaroXOldns= 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-357-mE3y0vlJP4qGowfQe_eATw-1; Thu, 07 Dec 2023 05:32:44 -0500 X-MC-Unique: mE3y0vlJP4qGowfQe_eATw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 0BDBA38130C3 for ; Thu, 7 Dec 2023 10:32:44 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 997E9492BC6 for ; Thu, 7 Dec 2023 10:32:43 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v3 27/32] elf: Determine the caller link map in _dl_open In-Reply-To: Message-ID: References: X-From-Line: d6215299700a189d3202f86f8db5924180cc6371 Mon Sep 17 00:00:00 2001 Date: Thu, 07 Dec 2023 11:32:41 +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.9 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_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.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 No functional change expected. This is in preparation of adding a fast path to dlopen in case no link map changes are required. --- elf/dl-open.c | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/elf/dl-open.c b/elf/dl-open.c index afac8498be..52e44804cf 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -49,8 +49,7 @@ struct dl_open_args { const char *file; int mode; - /* This is the caller of the dlopen() function. */ - const void *caller_dlopen; + struct link_map_private *caller_map; /* Derived from the caller address. */ struct link_map_private *map; /* Namespace ID. */ Lmid_t nsid; @@ -540,30 +539,6 @@ dl_open_worker_begin (void *a) struct dl_open_args *args = a; const char *file = args->file; int mode = args->mode; - struct link_map_private *call_map = NULL; - - /* Determine the caller's map if necessary. This is needed in case - we have a DST, when we don't know the namespace ID we have to put - the new object in, or when the file name has no path in which - case we need to look along the RUNPATH/RPATH of the caller. */ - const char *dst = strchr (file, '$'); - if (dst != NULL || args->nsid == __LM_ID_CALLER - || strchr (file, '/') == NULL) - { - const void *caller_dlopen = args->caller_dlopen; - - /* We have to find out from which object the caller is calling. - By default we assume this is the main application. */ - call_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded; - - struct link_map_private *l = _dl_find_dso_for_object ((ElfW(Addr)) caller_dlopen); - - if (l) - call_map = l; - - if (args->nsid == __LM_ID_CALLER) - args->nsid = call_map->l_ns; - } /* Prepare for link map updates. If dl_open_worker below returns normally, a matching _dl_protmem_end call is performed there. On @@ -585,7 +560,7 @@ dl_open_worker_begin (void *a) /* Load the named object. */ struct link_map_private *new; - args->map = new = _dl_map_object (call_map, file, lt_loaded, 0, + args->map = new = _dl_map_object (args->caller_map, file, lt_loaded, 0, mode | __RTLD_CALLMAP, args->nsid); /* If the pointer returned is NULL this means the RTLD_NOLOAD flag is @@ -906,7 +881,6 @@ no more namespaces available for dlmopen()")); struct dl_open_args args; args.file = file; args.mode = mode; - args.caller_dlopen = caller_dlopen; args.map = NULL; args.nsid = nsid; /* args.libc_already_loaded is always assigned by dl_open_worker @@ -915,6 +889,23 @@ no more namespaces available for dlmopen()")); args.argv = argv; args.env = env; + /* Determine the caller's map if necessary. This is needed when we + don't know the namespace ID in which we have to put the new object, + in case we have a DST, or when the file name has no path in + which case we need to look along the RUNPATH/RPATH of the caller. */ + if (nsid == __LM_ID_CALLER || strchr (file, '$') != NULL + || strchr (file, '/') == NULL) + { + args.caller_map = _dl_find_dso_for_object ((ElfW(Addr)) caller_dlopen); + if (args.caller_map == NULL) + /* By default we assume this is the main application. */ + args.caller_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded; + if (args.nsid == __LM_ID_CALLER) + args.nsid = args.caller_map->l_ns; + } + else + args.caller_map = NULL; + struct dl_exception exception; int errcode = _dl_catch_exception (&exception, dl_open_worker, &args);