From patchwork Thu Oct 17 10:33:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Kilroy X-Patchwork-Id: 35089 Received: (qmail 57126 invoked by alias); 17 Oct 2019 10:33:30 -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 57109 invoked by uid 89); 17 Oct 2019 10:33:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= 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=03g3Eo+7UTtbwzPTbP1GJ1Kqvt6lXYmJurQApX5TCmc=; b=v5tWoyzK6Jk1e6QpJEc2ikHefbilcZBb6hFIFEpMy/rz81y/UJhC1FqeNqIUSaD2yIOtw/AA+6g6+yoZBhMGD/OUfaYlPbujgDA6wMw/Jrtg/rVZOaDkCBvIjscl7JvMbbaPfSbCyc21+e80cubsDzHul2BxRGQx83/3Ok6TEOc= Authentication-Results: spf=fail (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=none action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 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: d0c2eb45bd27eaca X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JdPyHhOk5bHnRxGCniArTKbgFlbZD6Rkn83NV7uZEbq6XC4Ujy3YpeiUPM5NVGctIvUGg1tems355qeUpBc3VuG59+Tq6MbtgcwIpkBj4qZ0iQ6MPnovEroR/RzKhPYcmzVjRybutz8EOX/di9EQRCkDLWUWG4jsVb4PwlWcD2D1nUYzv6sORNvvfM8xyaCc3j3SCj1qC/W3JbmBpj5vdSOyzaIl57g/w/Iuroswo4Z2cgETITxPGXyUyU0xUAi4HZbHsxQU2MnmajVfPWVWfm7yMEOvi8avfbWjCwpdhbeskBrwega7L2ubxhe4XEe1m1hQ/FnrL92EHXDCn6accA== 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=03g3Eo+7UTtbwzPTbP1GJ1Kqvt6lXYmJurQApX5TCmc=; b=b3TkBym3UBjyOUwsel/+1kbZcHlfu1gM0MNXYcJcOqTk5RjdvaCpwcTMYsS4M2OWn5F48iZqxr15PGE60V07bbgbwEC4IkMedQlyj2Qp0J2OI+5YbwAQP+mcWe8BeIYLTJkrWJ4yPsXYKIef6cTadIrII/r/t15bsiY9xSFSiTzKpBzlt17biSM7R3MLzr1SHqS5XNNCakTij+enO+6CvnXkesfDld3Rf3E76rTEM5MRv2f2fOja/1AchKKvGqW6KxHeA4KgJ9JjHbHGxGjzDP7NN7bHmI9xSx1GH4Lek2J0GbUEBedgY/qcad5WZqQa/70hOnzLzgd3Hr7X4G9vfQ== 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=03g3Eo+7UTtbwzPTbP1GJ1Kqvt6lXYmJurQApX5TCmc=; b=v5tWoyzK6Jk1e6QpJEc2ikHefbilcZBb6hFIFEpMy/rz81y/UJhC1FqeNqIUSaD2yIOtw/AA+6g6+yoZBhMGD/OUfaYlPbujgDA6wMw/Jrtg/rVZOaDkCBvIjscl7JvMbbaPfSbCyc21+e80cubsDzHul2BxRGQx83/3Ok6TEOc= From: David Kilroy To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH 3/3] elf: avoid stack allocation in dl_open_worker Date: Thu, 17 Oct 2019 10:33:19 +0000 Message-ID: <42c95e0805f33efa9c7bd6c8d14997df312a787c.1571301957.git.david.kilroy@arm.com> References: In-Reply-To: Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=David.Kilroy@arm.com; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:6790;OLM:6790; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(136003)(39860400002)(396003)(346002)(189003)(199004)(7736002)(305945005)(64756008)(99286004)(478600001)(66946007)(36756003)(102836004)(66446008)(66556008)(6512007)(26005)(186003)(386003)(66476007)(11346002)(5640700003)(446003)(71200400001)(2501003)(44832011)(486006)(2616005)(5660300002)(476003)(52116002)(8676002)(71190400001)(66066001)(76176011)(4326008)(6506007)(6436002)(86362001)(8936002)(3846002)(25786009)(6116002)(118296001)(14454004)(81166006)(6916009)(6486002)(316002)(256004)(81156014)(2906002)(50226002)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB5492; H:AM0PR08MB4068.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A: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: 12f6DR9VCojUufO9vFLtOMoyRDLDc+ei6NDJblYc5DPzYmrH4tKVbLu4VIzeJXAP6CfkBZ/5Rt/i5Y1oGlzJO/w19/ggIEL3Qkmj5aGAhSOcEdj3IgSQcNZyw5FqfcWN3+GoQBjYAg8B7in4ig1DKdeQawUbJUTDkQBPka5bfegdbpkOo+NGJamZThc8t9NJnGplk0501J0uNKH1ws8dEvbRI85A9KWl2ifOouNJHl9aMecUoiA6Uh7F2mWaqE4LV8fJJx3IEFvmJjpV5FdMCX9WxTqv1TL8Q7Fp0A3jeT7mPNIBuYhDFl7TF31QIUdSTaMXggomZ4RAU32ATV/H25gP+moI/OlpC1mK35b0pBOAUccvSbxyuPeqUf72m6e2ttLDPF2qr1Lba7/AtiETKtL/NRJAg8wl3OrJcWNBpc4= x-ms-exchange-transport-forked: True MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Kilroy@arm.com; Return-Path: David.Kilroy@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3be147f4-468b-43ba-9c15-08d752ed6da9 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 25e8fb0..d96921a 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -304,34 +304,30 @@ 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); int relocation_in_progress = 0; - 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) {