From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 65623383D7B8 for ; Fri, 7 Jul 2023 18:49:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65623383D7B8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688755780; 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=4k8VO6iIl/iJSz1yKqHs+tcW4DehyWh4nLSnRBbvu8Q=; b=X68g4igiKjMwStpd96NBHGQGV/xsjw5RUyG3MzveKDx7FUCw5hU9GUyteszjuX0yeUebpK AUDzG/rCHgWJPA+NxUb6luRvCUJ+NjOFbrIsH+5hsTOc9wiuGGUyTgR7yoZ68vR1MOPWTE RJ6pTCRhzRpLT8a2ZJBRVDksH8yfX1w= 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-116-K43nDMKkOTutxFN5AYRw-Q-1; Fri, 07 Jul 2023 14:49:39 -0400 X-MC-Unique: K43nDMKkOTutxFN5AYRw-Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC737101A529 for ; Fri, 7 Jul 2023 18:49:38 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3203CC09A09 for ; Fri, 7 Jul 2023 18:49:37 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 27/32] elf: Determine the caller link map in _dl_open In-Reply-To: Message-ID: References: X-From-Line: b87a9a9779889ef127946b88efb37cbc973fdde7 Mon Sep 17 00:00:00 2001 Date: Fri, 07 Jul 2023 20:49:36 +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.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 List-Id: 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 c2560f7eae..78c43a630c 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; @@ -496,30 +495,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 @@ -541,7 +516,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 @@ -887,7 +862,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 @@ -896,6 +870,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); -- 2.41.0