From patchwork Fri Nov 24 12:56:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 80718 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 C7C91385B526 for ; Fri, 24 Nov 2023 12:56:29 +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 3D095385843A for ; Fri, 24 Nov 2023 12:56:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D095385843A 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 3D095385843A 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=1700830578; cv=none; b=xxu6dcmVTI/EYoY1//MS+xBguOqOX570SZ5CnZKQeK22BJ2ZKUEhLvytID9GDTJg6xQ5CJNKyaGNU+hF4YsSaf/xSlWPFXDylkWV22txXl2WWQo4lwXOH2/e/4dOljqe+s7qLijRYC/UQBJOz8kR0XDNhHF3nj27ivmCmz7XItM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700830578; c=relaxed/simple; bh=HZx07PpQVg64pcLm9a6Q+TgRKvgUfxAL9/3VxU9Ycm8=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=G5piLRIIuf25v+uzexq4M7xO9GTM/n0fCz8+2sGlcgjANbT3kf2gKDIyaSWmMMMl4Wd/El2TnDYxLiXLcKqhVMS8MCYa503e4AS8b23g87jZ8u0gAzJ23c4jtKHBo+tFUf8sM/OrKHRULUJl+/ooD07zSTjcsq4/+pNJ7MS1+6E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700830576; 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=FOQJHv84IIICqo3dFNhGX/vsgRXiMq0mZZuiCIr1cmM=; b=LuxmzLLavGZpEPdrjHNL9gjAF+ePeeYQfT/VKFblsxo90m7xV8dtQ3ojqlaTPIBeLbbWoB c0aLR7FaikkOYvFNkY4yiYInCVzvx4uBXOUCb+SCx6eBvzG4BceMsCGWlU3r+HuColqEf8 XAOB/WSPAYozbi9JmPdThcM+FaIQZAE= 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-280-86iI1tJUM0K5SZSg8CKRIQ-1; Fri, 24 Nov 2023 07:56:15 -0500 X-MC-Unique: 86iI1tJUM0K5SZSg8CKRIQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 6A9C83C0C131 for ; Fri, 24 Nov 2023 12:56:15 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 104962166B26 for ; Fri, 24 Nov 2023 12:56:14 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 1/3] elf: In _dl_relocate_object, skip processing if object is relocated In-Reply-To: Message-ID: <765fa8fd1d282964cf158d425b7e2cba28f79cb8.1700829130.git.fweimer@redhat.com> References: X-From-Line: 765fa8fd1d282964cf158d425b7e2cba28f79cb8 Mon Sep 17 00:00:00 2001 Date: Fri, 24 Nov 2023 13:56:13 +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.6 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 This is just a minor optimization. It also makes it more obvious that _dl_relocate_object can be called multiple times. Reviewed-by: Carlos O'Donell --- elf/dl-reloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index e5c555d82c..72c8586d29 100644 --- a/elf/dl-reloc.c +++ b/elf/dl-reloc.c @@ -205,6 +205,9 @@ void _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[], int reloc_mode, int consider_profiling) { + if (l->l_relocated) + return; + struct textrels { caddr_t start; @@ -242,9 +245,6 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[], # define consider_symbind 0 #endif - if (l->l_relocated) - return; - /* If DT_BIND_NOW is set relocate all references in this object. We do not do this if we are profiling, of course. */ // XXX Correct for auditing? 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. */ From patchwork Fri Nov 24 12:56:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 80720 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 5C745385C306 for ; Fri, 24 Nov 2023 12:56:51 +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 69033385BAC4 for ; Fri, 24 Nov 2023 12:56:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69033385BAC4 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 69033385BAC4 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=1700830598; cv=none; b=H9ErQqylG3D6WUCEOZaZWev4HyTOVWs+QpQgI68xhgT3aLJXg3N5g7EXXKt25Y+TXEPpxgNKQVpYXzjbvzUMzolcRS4GLucjvaBOdmin06Ts9+Qa9yn8yUy/WTyENFy3ZnCtLYLw+D08POeMGLlP2usZ4XTJNvBpbo6wepUgTAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700830598; c=relaxed/simple; bh=nJzL9Az+GFc2BLnAhuWrZphSUieO5Ho6JB7lPyZDbBA=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=OuomNZeyIgdqAmEtp/2VhjjQqhVU5PAqjzwtD6jk44o8QtclhyS928SiKJ/KyyoO1CKyqYepsu+NuhFGMiw5q6cR6oejfHklGGKq2YbpREKD8ALs007AyW9rKMotIMoCYRUY9Ymn1EVqPq5dWpVkVyAS7FmPk3mADtvNF5Cz96U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700830596; 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=39NTRgbTf71s1bGjshCgspmX3rOUt301JOgQpxMXgkY=; b=NjeAUQOp6rhT+pOpWarGZwUvZcYbnS8WC2ShgbMr23iNRYoZOCI9Blsb9AbOMTGOPgQvNO v0LffUR0xI/3SU3OsjFDE7+DqnOZV/mZyfpCUs6R8PStbxu8CHuBrKdzUC/IjKVJl9Owv8 HCAk+eSVUssEXujernpf+OcFfflKVfo= 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-562-Ayi0FMTvMQyCXXU2rWRVqw-1; Fri, 24 Nov 2023 07:56:34 -0500 X-MC-Unique: Ayi0FMTvMQyCXXU2rWRVqw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 0473E80D722 for ; Fri, 24 Nov 2023 12:56:34 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 729A81C060B0 for ; Fri, 24 Nov 2023 12:56:33 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 3/3] elf: Relocate libc.so early during startup and dlmopen (bug 31083) In-Reply-To: Message-ID: <7d8d7ed3614d4779f1b20e3acb8a7a5642d260e6.1700829130.git.fweimer@redhat.com> References: X-From-Line: 7d8d7ed3614d4779f1b20e3acb8a7a5642d260e6 Mon Sep 17 00:00:00 2001 Date: Fri, 24 Nov 2023 13:56:32 +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.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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 This makes it more likely that objects without dependencies can use IFUNC resolvers in libc.so. Reviewed-by: Carlos O'Donell --- elf/Makefile | 21 +++++++++++++++++++++ elf/dl-open.c | 11 +++++++++++ elf/rtld.c | 10 ++++++++-- elf/tst-nodeps1-mod.c | 25 +++++++++++++++++++++++++ elf/tst-nodeps1.c | 23 +++++++++++++++++++++++ elf/tst-nodeps2-mod.c | 1 + elf/tst-nodeps2.c | 29 +++++++++++++++++++++++++++++ 7 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 elf/tst-nodeps1-mod.c create mode 100644 elf/tst-nodeps1.c create mode 100644 elf/tst-nodeps2-mod.c create mode 100644 elf/tst-nodeps2.c diff --git a/elf/Makefile b/elf/Makefile index 3f7f89508e..afec7be084 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -433,6 +433,8 @@ tests += \ tst-nodelete-dlclose \ tst-nodelete-opened \ tst-nodelete2 \ + tst-nodeps1 \ + tst-nodeps2 \ tst-noload \ tst-non-directory-path \ tst-null-argv \ @@ -863,6 +865,8 @@ modules-names += \ tst-nodelete-dlclose-plugin \ tst-nodelete-opened-lib \ tst-nodelete2mod \ + tst-nodeps1-mod \ + tst-nodeps2-mod \ tst-non-directory-mod \ tst-null-argv-lib \ tst-p_alignmod-base \ @@ -1030,6 +1034,8 @@ modules-names-nobuild += \ tst-audit24bmod1 \ tst-audit24bmod2 \ tst-big-note-lib \ + tst-nodeps1-mod \ + tst-nodeps2-mod \ tst-ro-dynamic-mod \ # modules-names-nobuild @@ -3009,3 +3015,18 @@ tst-env-setuid-ARGS = -- $(host-test-program-cmd) # Reuse a module with a SONAME, to specific as the LD_PROFILE. $(objpfx)tst-env-setuid: $(objpfx)tst-sonamemove-runmod2.so + +# The object tst-nodeps1-mod.so has no explicit dependencies on libc.so. +$(objpfx)tst-nodeps1-mod.so: $(objpfx)tst-nodeps1-mod.os + $(LINK.o) -nostartfiles -nostdlib -shared -o $@ $^ +tst-nodeps1.so-no-z-defs = yes +# Link libc.so before the test module with the IFUNC resolver reference. +LDFLAGS-tst-nodeps1 = $(common-objpfx)libc.so $(objpfx)tst-nodeps1-mod.so +$(objpfx)tst-nodeps1: $(objpfx)tst-nodeps1-mod.so +# Reuse the tst-nodeps1 module. Link libc.so before the test module +# with the IFUNC resolver reference. +$(objpfx)tst-nodeps2-mod.so: $(common-objpfx)libc.so \ + $(objpfx)tst-nodeps1-mod.so $(objpfx)tst-nodeps2-mod.os + $(LINK.o) -Wl,--no-as-needed -nostartfiles -nostdlib -shared -o $@ $^ +$(objpfx)tst-nodeps2.out: \ + $(objpfx)tst-nodeps1-mod.so $(objpfx)tst-nodeps2-mod.so diff --git a/elf/dl-open.c b/elf/dl-open.c index 417d2fb948..b748c278ac 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -708,6 +708,17 @@ dl_open_worker_begin (void *a) them. However, such relocation dependencies in IFUNC resolvers are undefined anyway, so this is not a problem. */ + /* Ensure that libc is relocated first. This helps with the + execution of IFUNC resolvers in libc, and matters only to newly + created dlmopen namespaces. Do not do this for static dlopen + because libc has relocations against ld.so, which may not have + been relocated at this point. */ +#ifdef SHARED + if (GL(dl_ns)[args->nsid].libc_map != NULL) + _dl_open_relocate_one_object (args, r, GL(dl_ns)[args->nsid].libc_map, + reloc_mode, &relocation_in_progress); +#endif + for (unsigned int i = last; i-- > first; ) _dl_open_relocate_one_object (args, r, new->l_initfini[i], reloc_mode, &relocation_in_progress); diff --git a/elf/rtld.c b/elf/rtld.c index 0553c05edb..19bedcd4a6 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2272,11 +2272,17 @@ dl_main (const ElfW(Phdr) *phdr, objects. We do not re-relocate the dynamic linker itself in this loop because that could result in the GOT entries for functions we call being changed, and that would break us. It is safe to relocate - the dynamic linker out of order because it has no copy relocs (we - know that because it is self-contained). */ + the dynamic linker out of order because it has no copy relocations. + Likewise for libc, which is relocated early to ensure that IFUNC + resolvers in libc work. */ int consider_profiling = GLRO(dl_profile) != NULL; + if (GL(dl_ns)[LM_ID_BASE].libc_map != NULL) + _dl_relocate_object (GL(dl_ns)[LM_ID_BASE].libc_map, + GL(dl_ns)[LM_ID_BASE].libc_map->l_scope, + GLRO(dl_lazy) ? RTLD_LAZY : 0, consider_profiling); + /* If we are profiling we also must do lazy reloaction. */ GLRO(dl_lazy) |= consider_profiling; diff --git a/elf/tst-nodeps1-mod.c b/elf/tst-nodeps1-mod.c new file mode 100644 index 0000000000..45c8e3c631 --- /dev/null +++ b/elf/tst-nodeps1-mod.c @@ -0,0 +1,25 @@ +/* Test module with no libc.so dependency and string function references. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Some references to libc symbols which are likely to have IFUNC + resolvers. If they do not, this module does not exercise bug 31083. */ +void *memcpy_pointer = memcpy; +void *memmove_pointer = memmove; +void *memset_pointer = memset; diff --git a/elf/tst-nodeps1.c b/elf/tst-nodeps1.c new file mode 100644 index 0000000000..1a8bde36cd --- /dev/null +++ b/elf/tst-nodeps1.c @@ -0,0 +1,23 @@ +/* Test initially loaded module with implicit libc.so dependency (bug 31083). + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Testing happens before main. */ +int +main (void) +{ +} diff --git a/elf/tst-nodeps2-mod.c b/elf/tst-nodeps2-mod.c new file mode 100644 index 0000000000..4913feee9b --- /dev/null +++ b/elf/tst-nodeps2-mod.c @@ -0,0 +1 @@ +/* Empty test module which depends on tst-nodeps1-mod.so. */ diff --git a/elf/tst-nodeps2.c b/elf/tst-nodeps2.c new file mode 100644 index 0000000000..0bdc8eeb8c --- /dev/null +++ b/elf/tst-nodeps2.c @@ -0,0 +1,29 @@ +/* Test dlmopen with implicit libc.so dependency (bug 31083). + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +static int +do_test (void) +{ + void *handle = xdlmopen (LM_ID_NEWLM, "tst-nodeps2-mod.so", RTLD_NOW); + xdlclose (handle); + return 0; +} + +#include