From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 091491F463 for ; Tue, 3 Dec 2019 17:31:48 +0000 (UTC) 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=Hh+xZvOxMRue7FH3v01J/fwNIN+Je Gd/4nQPSa2GI0R1T3Y5yYz9UNmauCX1tcxRx1vcVVIlzRowDwZeraHm9iScJugAl uikpBunYVcmCMg4TpMtqYeXSk5j4gsRPYMwKqlpyv3OsNOoZ/dfy4L6XoXA2dxYn Loln6r+Hvf8jzU= 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=OK1 do8U1wHSJmvk8vLij6zY9vB9hZZhKMedkAdgNDJiH+zPvsb6MWk90+IcE0behYLI INjTXi6Xn5/9t6dCon7ncjdW0FUelGRdMqjp0xY3rSpaqYSsijajOXf47cV0Fhq/ gIb1DHg93peF2u7tryJjMXC09XtRgxXu3/2xCskI= 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 Received: (qmail 15677 invoked by uid 89); 3 Dec 2019 17:30:28 -0000 Authentication-Results: sourceware.org; auth=none 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 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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. --- 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 =3D 0; + unsigned int first =3D UINT_MAX; + unsigned int last =3D 0; unsigned int j =3D 0; struct link_map *l =3D new->l_initfini[0]; do { if (! l->l_real->l_relocated) - ++nmaps; - l =3D new->l_initfini[++j]; - } - while (l !=3D NULL); - /* Stack allocation is limited by the number of loaded objects. */ - struct link_map *maps[nmaps]; - nmaps =3D 0; - j =3D 0; - l =3D new->l_initfini[0]; - do - { - if (! l->l_real->l_relocated) - maps[nmaps++] =3D l; + { + if (first =3D=3D UINT_MAX) + first =3D j; + last =3D j + 1; + } l =3D new->l_initfini[++j]; } while (l !=3D 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. */ =20 - for (unsigned int i =3D nmaps; i-- > 0; ) + for (unsigned int i =3D last; i-- > first; ) { - l =3D maps[i]; + l =3D new->l_initfini[i]; + + if (l->l_real->l_relocated) + continue; =20 if (! relocation_in_progress) { --=20 2.7.4