From patchwork Tue Dec 3 17:30:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Kilroy X-Patchwork-Id: 1203812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-107669-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="cfGmm1YB"; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="aX6PNbD8"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="aX6PNbD8"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47S8DR6tKnz9sP6 for ; Wed, 4 Dec 2019 04:31:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:content-type:content-transfer-encoding :mime-version; q=dns; s=default; b=gCCzMVjAHNq0LsbWiEOKSp6x3KW1c Xh18Ie9BXm7wZrLnk37kegbDLJZCSk8SkvzPqPk9xlcMcMorTL64oJU1foSZgEAf ZnJLJFlb8N56M1vR9jVnlMsJlxOrOK6/bl9gUVwfdoGjno6pMWG/PEWSEUm7GiC5 jS+RRzY/wQVPyI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:content-type:content-transfer-encoding :mime-version; s=default; bh=zFYzBGPAFAo12u5B+/SWmhEQVus=; b=cfG mm1YB8DSKsTOrLEX+/4QVcZTZe4Vs3+6QuOcKut3yKGpDNgthM3v6HVIW/WuK0zn LhQdVjF1SffRXtZzY1qQVqC0JvKsd5K+A1Sq/IMPGcQWdVnQbkZAP7Aun3ltST/6 Nwh08V/iuKWVfDYSe5mrOXxs66xNxxYN/NUvbk9Y= Received: (qmail 16081 invoked by alias); 3 Dec 2019 17:30:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 15677 invoked by uid 89); 3 Dec 2019 17:30:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1792 X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F2xr7vPj26LCgS8MuKGYrADsk0rWP02s/9tbwORzgRU=; b=aX6PNbD8EZRI8gKxgUrgs1/jNWU5UVsxl3kFlYA73YKQriSMjZe5cILqF+syAUHP4QHDpZ2YEPRQ2YDNG0vcd9BJvDDK9oUvvwwyMWXW1FPwzLozpUMISrLyKR6pXZ0jrm2KeFEniygxvXTJTHwLsI3d5TPms0QV1Hhh4BCskUU= Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 70c1bc5f82f0bafe X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dby4fmdS7ohvyedsRXloGPI16SlQabrOnn0W7Kt/2oYeWuXEMFv5AVD153lZLtAFHcC/5w235rGo7DawgiER6vzSyxdHHfs1mBRKpebOptFdHxs4YkpUVEZ+qoA+h39bYz92hXDd59HUl0NF0l2+VlNIVVsOss/HrvgNf5TVpQLd80COXCCQuWgKYrpxVFko52XA2FwxUh95OOfT1D2Y8wxPHpu0C9udFd6MiHx0F3t6OxHuQ07kyb8s0JGm8sVNaGSyki7QlRsCX2PowvjPKomfjKJxLohSBmOANumbU5soj23lKV+bDOOMMdmDhP3jEjk7jJGgZy6TjIjm5zYKHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F2xr7vPj26LCgS8MuKGYrADsk0rWP02s/9tbwORzgRU=; b=TDqoTnXJaw+MvrtS8dd6zmuUGvMELLsLZhzhOCh+HGn0SScstKRkYSTJTqDYVPP/n+Bx6mMX/dVpmkox5es7tdSUZwmdfZMCXTCHE7ObtUzM9AVWhdeVXFdMB+zUSF9KTyw6/z7DJyPoKVdCbOGDaXxmPoavU8Gm2KBQSwJtqIzsi2Y3+1xP+aLrAY/MHgt96+nbuaQIZeGPG4AHUMA8S155vFzWi4SFnOUtwTODongc1aB8+XOK+iyAKlVSiYcvWtJPon9Sk9wrOOHSB7kIAVVg1JaNUIhFC+F9ZdE71c1SuqElhQFFuUR2Txy7VTvxUhefdU8sILGEI+q2iDvS8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F2xr7vPj26LCgS8MuKGYrADsk0rWP02s/9tbwORzgRU=; b=aX6PNbD8EZRI8gKxgUrgs1/jNWU5UVsxl3kFlYA73YKQriSMjZe5cILqF+syAUHP4QHDpZ2YEPRQ2YDNG0vcd9BJvDDK9oUvvwwyMWXW1FPwzLozpUMISrLyKR6pXZ0jrm2KeFEniygxvXTJTHwLsI3d5TPms0QV1Hhh4BCskUU= From: David Kilroy To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH v3 3/3] elf: avoid stack allocation in dl_open_worker Date: Tue, 3 Dec 2019 17:30:11 +0000 Message-ID: <1575394197-18006-4-git-send-email-david.kilroy@arm.com> References: <1575394197-18006-1-git-send-email-david.kilroy@arm.com> In-Reply-To: <1575394197-18006-1-git-send-email-david.kilroy@arm.com> Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=David.Kilroy@arm.com; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:7691;OLM:7691; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(136003)(39860400002)(396003)(376002)(346002)(366004)(199004)(189003)(52314003)(99286004)(102836004)(6436002)(4326008)(478600001)(14454004)(2906002)(386003)(50226002)(36756003)(186003)(6916009)(2616005)(6506007)(305945005)(76176011)(52116002)(86362001)(81156014)(25786009)(26005)(71190400001)(6486002)(71200400001)(256004)(81166006)(2501003)(7736002)(3846002)(8676002)(8936002)(446003)(11346002)(44832011)(316002)(66476007)(6512007)(66556008)(66446008)(64756008)(66946007)(2351001)(5660300002)(6116002)(5640700003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB4001; H:AM0PR08MB4068.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: KEikf8pfv7E7SOemiz+xDlcDQzVlCdg7oqY3uMnQwF6tCVnzsTMHEvZcdoJIxpLF2tijDnVu2ygURuNaDZo8Qx/Gc2OLZupMkPPakHttQU4QLwNsNu3AWFr1Yt7vCFO2KrPmuvHzwKAg/Oe6tbzanl6gvA7BsWIkIX99upEuGCXlQGmcyIrFeT9c2PFo51JYwVLlR5o/TC7TCBXXmyy2aTxX4bZFJsqm3dssSBDcBVggR7T4vPf07Xo8t5wSc3s0lQOF4zu3bv28z+42ACXya//mS29jT38TOgIKM/48GF8VRXDlObpYmTGQqOM1o6+xW2Az2HkS7UqBTlpxAMIxPQ8Xez6PTSWh+V80wsMnqhCe3HgYzckiyfkLOdxG0BbcvunfBbdvchRRMcq0albi/5K/y32V7lW4pxHcREKjCISrpcdo9kqgjHbBzG55vl2S x-ms-exchange-transport-forked: True MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Kilroy@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT051.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3b764e09-c08e-42e0-0392-08d77816735c As the sort was removed, there's no need to keep a separate map of links. Instead, when relocating objects iterate over l_initfini directly. This allows us to remove the loop copying l_initfini elements into map. We still need a loop to identify the first and last elements that need relocation. Tested by running the testsuite on x86_64. Reviewed-by: Adhemerval Zanella --- elf/dl-open.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/elf/dl-open.c b/elf/dl-open.c index c4d09c7c..eb36a91 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -636,25 +636,18 @@ dl_open_worker (void *a) /* Sort the objects by dependency for the relocation process. This allows IFUNC relocations to work and it also means copy relocation of dependencies are if necessary overwritten. */ - unsigned int nmaps = 0; + unsigned int first = UINT_MAX; + unsigned int last = 0; unsigned int j = 0; struct link_map *l = new->l_initfini[0]; do { if (! l->l_real->l_relocated) - ++nmaps; - l = new->l_initfini[++j]; - } - while (l != NULL); - /* Stack allocation is limited by the number of loaded objects. */ - struct link_map *maps[nmaps]; - nmaps = 0; - j = 0; - l = new->l_initfini[0]; - do - { - if (! l->l_real->l_relocated) - maps[nmaps++] = l; + { + if (first == UINT_MAX) + first = j; + last = j + 1; + } l = new->l_initfini[++j]; } while (l != NULL); @@ -669,9 +662,12 @@ dl_open_worker (void *a) them. However, such relocation dependencies in IFUNC resolvers are undefined anyway, so this is not a problem. */ - for (unsigned int i = nmaps; i-- > 0; ) + for (unsigned int i = last; i-- > first; ) { - l = maps[i]; + l = new->l_initfini[i]; + + if (l->l_real->l_relocated) + continue; if (! relocation_in_progress) {