From patchwork Wed Jan 29 11:17:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Kilroy X-Patchwork-Id: 37596 Received: (qmail 100410 invoked by alias); 29 Jan 2020 11:18:05 -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 98741 invoked by uid 89); 29 Jan 2020 11:17:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 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=HReceived-SPF:receiver, HReceived-SPF:client-ip, HReceived-SPF:helo, relocating X-HELO: EUR04-HE1-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=YlGsu/Dm6xBDP3IL2hK8M2qGQNrBbWqRcGTmzLPHlKc=; b=iByr0z38cVJCKfDmIRQesm4Tr41widMzBRYtlWoq5zB9CMJfjHarP12d1iDZ0dmPJi9LUlw9I7BTXbs1WhpL30142ar1d1q906Pyr5o8iQl+mKgL5VANfuQSDdbCUu2qknircBBBejqhwk04uVDnSMm0xFCJcXsWLdEmT+e0wco= 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: b7acbb529d6a1c1a X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PZMjGLclHxJOJEDcGDPpU4/dW8NDZost8vi7Agu6tlNjKjWllirK9xzBxijHoKDU1GJkJsDCmej6CyaOzj++sX3T/Pgj35hdfASmLEe/t2XLlmmcFCSjcUiC3bcUXAIEgiS+SIoIYkR8lRNTpEA6bMceExFYk001okHosiLAaj/TzpKVsH9dpxpOaUy5iXFs2B7y7MGWQ/umttNIJHiZ4rnQRyGxuqmcJew4k1KmV9DoN2AR0bnXIicEBHWvQ/OTuxNnX+dPxFVFSQNp9bwBmYvzfeVLiPj6fuug2cNcmnERKwd7z++L5Rks7rdB8himJkGmvzAZmkeKh3WDI/hamw== 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=YlGsu/Dm6xBDP3IL2hK8M2qGQNrBbWqRcGTmzLPHlKc=; b=afPr7vAeHwReFagnEqWxEMecKdwm3JypRGhRM5Q3MOdSLG+CcdDVmg2tOlO7OGM3wWqkyur/qAyAzfEwLvkp6vC/yow0Rvaw06MPiOetNAlWT7FAa3Dv8Psap/R3wslIqm9KHeEZgxnzW2ghbCMz9P+IogCZadTyL9wMU0wFNQpyugT/R6dLNX3VEmhUeQp+0WhX9KUAyA+ffXLh7hjqDOw1xMsDX3Hkfe/aljUvPJMyVVMG9S/WJJTC3uWTA9Oz71LzQYcPRVQkOXRUrkpf31w+shZuvTkaKTg50oseL+aFL4pxeEibVm0X06UcsrvL6xjOOiPi+g3QbAhDi96omw== 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=YlGsu/Dm6xBDP3IL2hK8M2qGQNrBbWqRcGTmzLPHlKc=; b=iByr0z38cVJCKfDmIRQesm4Tr41widMzBRYtlWoq5zB9CMJfjHarP12d1iDZ0dmPJi9LUlw9I7BTXbs1WhpL30142ar1d1q906Pyr5o8iQl+mKgL5VANfuQSDdbCUu2qknircBBBejqhwk04uVDnSMm0xFCJcXsWLdEmT+e0wco= From: David Kilroy To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH v4 3/3] elf: avoid stack allocation in dl_open_worker Date: Wed, 29 Jan 2020 11:17:33 +0000 Message-ID: <1580296643-36839-4-git-send-email-david.kilroy@arm.com> References: <1580296643-36839-1-git-send-email-david.kilroy@arm.com> In-Reply-To: <1580296643-36839-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)(346002)(39860400002)(396003)(376002)(366004)(136003)(189003)(199004)(6486002)(7696005)(52116002)(86362001)(4326008)(8936002)(81166006)(8676002)(81156014)(478600001)(6916009)(71200400001)(316002)(2906002)(16526019)(36756003)(2616005)(26005)(66946007)(186003)(44832011)(66476007)(66556008)(64756008)(956004)(66446008)(5660300002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB3903; H:VI1PR08MB2958.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: z/nYvC2Q3jPosDt6RnYFjfjKUBSKTUQRCC5LQm+lLwuSwnGVYMKUOe49mMeVD9fdrrkk1+efeOsJGFy9IeAOVkT6MX5kqUaJtUir0TiXbYZOH61ZAMiEfIb4PpZnhWvQf0u42sMONyglcDczPLCBJRNXz1YK+jmVsV3qd2pkVX0Wq7Sa3tw1vFNqt+3o2no75afThOE/w2QW+YaLpy6myWAdZxzQDxqtoq4vrxgQey7Dm+KZqtQlc90Xa6ISd1uUlMcQVfyKUzL99ahWY654f4Ylb+izDjOav+KKB4RzXFt2pVffDaLstnGv6hY0bj5abpjz5t1HYqjkStlnbpwkAjE9BODFkDENb/W6gnGPy3bxSESHKotsB0cRF+/XHlRVg4zmgYcPEnwjjp+77vLcR9Ek8/hNR1wHIPQiMQSrcc8Zc833vsTAK+Qm8AMu/Xqa x-ms-exchange-antispam-messagedata: KlttL9315vcZi6vuL+t79dOvr2w5dO6iPvvLTWIrqvbQ4I86yhT/tbJzFK9d7LcvIxuARq9+qweQJiVnS+KkpDtWhsK4iBTvZIrqj4ZIiJ4lVd6eTPe+dEzE3avpVEhC+S9m0gjNyphTqAwmE0wZYQ== 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: AM5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 42525f10-46c3-476d-9850-08d7a4acd689 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 314adc2..7b3b177 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -621,25 +621,18 @@ dl_open_worker (void *a) This allows IFUNC relocations to work and it also means copy relocation of dependencies are if necessary overwritten. __dl_map_object_deps has already sorted l_initfini for us. */ - 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); @@ -654,9 +647,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) {