From patchwork Fri Nov 24 12:56:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 80719 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 12DE2385AE54 for ; Fri, 24 Nov 2023 12:56:39 +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 509E5385773F for ; Fri, 24 Nov 2023 12:56:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 509E5385773F 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 509E5385773F 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=1700830586; cv=none; b=joehI/AjqTe5h5C0C6fvNmdYfXuLXhTMdWDiSxa98K3hOKrEGOr+3o31GdS0V9eg5kzv0WEfalHXYp6sV6/stxpxJqJT1Jw2QGXhBS9ErC1qeU8EKAgUrt09Y92b99t62roY3FBHtGPVoxNW2zLBBwKSh0MsGB8GBemibBMf8zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700830586; c=relaxed/simple; bh=JZEjeCOoIdNQG24LnUEDiP7pDyJbRPXAv8NVdQUsbQ0=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=nGe9JRg7kr918ooePDRmf5lfLXaZ5NGeK9lI5/mQ7kWtCjd+uLpp98xMHN6Cpw7kV8DqHgNxwPvsF8aHOAYq0YDcEjIrZ22N+4G8PX8aijbWI264hObP44c+lw6VJNmCkN90YfAH/fuyZstVry7y7ZBWxILOQJK0n3gj/yz32Wk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700830585; 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=z9rLlykGSGtrSvG1OWiWZtU7LT502cgYHGiSYI42e0s=; b=LHZJOCtrZ5I6H6lasFAl11lanbUNRCJAwnC0qqFptxiXj48+sEot5J+QBCaFmOTHn65fXg kCGgPp4GudhgE3ymsKtZSu++j9qJdUKbSSEnxuxv9LuhVokynim7dm7wyALZKVtL1xeusU RNQPY6Roy5OyG+TZ8r/nI+606Wng3LI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-iWPhpQxIN6C31sXHfAkRgQ-1; Fri, 24 Nov 2023 07:56:23 -0500 X-MC-Unique: iWPhpQxIN6C31sXHfAkRgQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 7D3A9185A780 for ; Fri, 24 Nov 2023 12:56:23 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 21D455028 for ; Fri, 24 Nov 2023 12:56:23 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 2/3] elf: Introduce the _dl_open_relocate_one_object function In-Reply-To: Message-ID: <8a70ef2c01ffde6327764087300e14dbc2dcea68.1700829130.git.fweimer@redhat.com> References: X-From-Line: 8a70ef2c01ffde6327764087300e14dbc2dcea68 Mon Sep 17 00:00:00 2001 Date: Fri, 24 Nov 2023 13:56:21 +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.5 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_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 It is extracted from dl_open_worker_begin. Reviewed-by: Carlos O'Donell --- elf/dl-open.c | 86 ++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/elf/dl-open.c b/elf/dl-open.c index 351931af04..417d2fb948 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -468,6 +468,50 @@ activate_nodelete (struct link_map *new) } } +/* Relocate the object L. *RELOCATION_IN_PROGRESS controls whether + the debugger is notified of the start of relocation processing. */ +static void +_dl_open_relocate_one_object (struct dl_open_args *args, struct r_debug *r, + struct link_map *l, int reloc_mode, + bool *relocation_in_progress) +{ + if (l->l_real->l_relocated) + return; + + if (!*relocation_in_progress) + { + /* Notify the debugger that relocations are about to happen. */ + LIBC_PROBE (reloc_start, 2, args->nsid, r); + *relocation_in_progress = true; + } + +#ifdef SHARED + if (__glibc_unlikely (GLRO(dl_profile) != NULL)) + { + /* If this here is the shared object which we want to profile + make sure the profile is started. We can find out whether + this is necessary or not by observing the `_dl_profile_map' + variable. If it was NULL but is not NULL afterwards we must + start the profiling. */ + struct link_map *old_profile_map = GL(dl_profile_map); + + _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1); + + if (old_profile_map == NULL && GL(dl_profile_map) != NULL) + { + /* We must prepare the profiling. */ + _dl_start_profile (); + + /* Prevent unloading the object. */ + GL(dl_profile_map)->l_nodelete_active = true; + } + } + else +#endif + _dl_relocate_object (l, l->l_scope, reloc_mode, 0); +} + + /* struct dl_init_args and call_dl_init are used to call _dl_init with exception handling disabled. */ struct dl_init_args @@ -654,7 +698,7 @@ dl_open_worker_begin (void *a) } while (l != NULL); - int relocation_in_progress = 0; + bool relocation_in_progress = false; /* Perform relocation. This can trigger lazy binding in IFUNC resolvers. For NODELETE mappings, these dependencies are not @@ -665,44 +709,8 @@ dl_open_worker_begin (void *a) are undefined anyway, so this is not a problem. */ for (unsigned int i = last; i-- > first; ) - { - l = new->l_initfini[i]; - - if (l->l_real->l_relocated) - continue; - - if (! relocation_in_progress) - { - /* Notify the debugger that relocations are about to happen. */ - LIBC_PROBE (reloc_start, 2, args->nsid, r); - relocation_in_progress = 1; - } - -#ifdef SHARED - if (__glibc_unlikely (GLRO(dl_profile) != NULL)) - { - /* If this here is the shared object which we want to profile - make sure the profile is started. We can find out whether - this is necessary or not by observing the `_dl_profile_map' - variable. If it was NULL but is not NULL afterwards we must - start the profiling. */ - struct link_map *old_profile_map = GL(dl_profile_map); - - _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1); - - if (old_profile_map == NULL && GL(dl_profile_map) != NULL) - { - /* We must prepare the profiling. */ - _dl_start_profile (); - - /* Prevent unloading the object. */ - GL(dl_profile_map)->l_nodelete_active = true; - } - } - else -#endif - _dl_relocate_object (l, l->l_scope, reloc_mode, 0); - } + _dl_open_relocate_one_object (args, r, new->l_initfini[i], reloc_mode, + &relocation_in_progress); /* This only performs the memory allocations. The actual update of the scopes happens below, after failure is impossible. */