From patchwork Tue Apr 13 08:18:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465609 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Li3hhyx7; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJQp54KSz9sVw for ; Tue, 13 Apr 2021 18:18:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A082E393C867; Tue, 13 Apr 2021 08:18:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A082E393C867 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301920; bh=yyIM7j/3Zh3VF5KEnLq2eX6J9U7OSx0D/qsSFCiHiqI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Li3hhyx7hofB97licSB3pZDbUfxYdE3ODxzJPy+rZ8RXiCZeR5iBqBtD3Rk3ge75k lGOwpb6N/K7rUaOJUP3PnPgXrgeqFJ0zRbavivetPtlovRYHmSLF8WebLvBLQ/lbg0 /VzIid/qLa3Rx7aEODn0Ws71g9DM2WoRUMHoDehM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140040.outbound.protection.outlook.com [40.107.14.40]) by sourceware.org (Postfix) with ESMTPS id 88384393C855 for ; Tue, 13 Apr 2021 08:18:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 88384393C855 Received: from AM5PR0202CA0021.eurprd02.prod.outlook.com (2603:10a6:203:69::31) by DB9PR08MB6748.eurprd08.prod.outlook.com (2603:10a6:10:2a7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:18:35 +0000 Received: from AM5EUR03FT010.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:69:cafe::53) by AM5PR0202CA0021.outlook.office365.com (2603:10a6:203:69::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:18:35 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT010.mail.protection.outlook.com (10.152.16.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:18:35 +0000 Received: ("Tessian outbound 82c2d58b350b:v90"); Tue, 13 Apr 2021 08:18:35 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8aae81b631ee2eb6 X-CR-MTA-TID: 64aa7808 Received: from 9e609ae978dd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A8D37FD4-0817-4407-A185-FAC352E16A9F.1; Tue, 13 Apr 2021 08:18:13 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9e609ae978dd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:18:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LB7E1/tW7sRU2NNtcL9OvLLZ3+tNaL70zsWsSGAoAWiw7wbmNM7fyfqfGXSbB0CMRF5iVZtUfiCcG4o6s77N6EGcEolPSia6k60BUCjUSm9WlX2KVUjYBRI0mKigeIGh07T7BROrmn4t93FNBTcp97HIp2s/CUpUBX8luR9MJbN5wzPumh6H11zape1sykTpW/U9d/opgap20voV1NQdBSQ8QaaiGRUwZPuVjUtq7fvfPvwdbDfoY0PxaUU8GhRo539zG4I4f6xVOdBe9GflRLCMNpduAzYduNHeIYZ1ctaV8UUETu9I5xdzHSGOTQW0xNbjNIK3Du0BP4SmpsF8Kw== 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=yyIM7j/3Zh3VF5KEnLq2eX6J9U7OSx0D/qsSFCiHiqI=; b=P/wM80WeY4ohBcS2Uw9IUVXMPVJxErK7mmrMHv4EOK1KV+EWIdXoEamndvBFCid6IW14r+tXTF/EPCHPNAnZguXrGSXFKvmlwCgegH0PeXxNvHv/BQHo5S0l6q9RHjw0UPDhyUnORYBoaVyN/O48oJuB5dJYl8ytjlYnbwKRReroFzk9NcGpjD4jlWGpN0Tbqha0AEA767QL+t6FUxOzKhl1hO+FpJLXQ/rKBbi80WdXm989i1h5BJ/PB8V2d2vyJ9LN3G1dWBCfL2blmSG3tAdzXncf9BzDJhhTn9CHQjncFk+bHfibSqURF2scfiJF/4I//amLzObhM0+CATWuEA== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6541.eurprd08.prod.outlook.com (2603:10a6:102:15a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.19; Tue, 13 Apr 2021 08:18:11 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:18:11 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 01/14] elf: Fix a DTV setup issue [BZ #27136] Date: Tue, 13 Apr 2021 09:18:00 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: SN7PR04CA0165.namprd04.prod.outlook.com (2603:10b6:806:125::20) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by SN7PR04CA0165.namprd04.prod.outlook.com (2603:10b6:806:125::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:18:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 98b75176-8f6d-43a7-329a-08d8fe54bbad X-MS-TrafficTypeDiagnostic: PAXPR08MB6541:|DB9PR08MB6748: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7219;OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: q4B62CaUioE+S5hAqjjyCOx9tqG0hDmkBX2oxXeYIF6G8WFDn0xnvM7ID5nCDDRKN09aSLylojWK9vMDUMn+kXO6aib1jzMsr71qT3fDh+zYvMLIPI/Xkq/KTEvupjCyiScvdjIfZUIaACyRzMiAQzHm2KcGf/qb3DY0vuWf54nPhWiIrSTCj/Lyq+Yima57oFxSBqpMfqvhdju4sSHig8qrdIh1VqclnCvLVUr0aAoHALtRx8zL8JBSy9sFPJrcVOFWwLHHosEJaD45EghxqsT/AuvbW3L5jsaCO9zoOfI9FqoVZN/vZKImhJGhjrN6Ir9zR3BMosiIFYXqRqEnX5S/hdlep+Xutplp5Ok+/kKgbK7niVQArJ+Tr87KAwI8yT7JDI2htJDL7LfJHdgKKUbdGUrEzpMlh1h5gCWdTdopjDzyJm9V7WISfLEesKPwnuhfT1ThO/h54CwQcVp5Up++7qJcHwKbZGI+LGx22XTAmj3Pb6W/mk7iOJnO2XFO9xMVaPumYsMzsga+TqBIFGNCUaTWRFD7gerjPvWv0noDOtlf4KS3gwJmJpoDeZasXFjHe7OCTCYwD+zqpacYJXdE1uQoupRn2yg097aLyQJrrvIU36SNY2P3rJue/OhtHZH4M90NbAxLQPyWDwRU8Bnpl49hWoOkpc3noXqpJY+/ba+3NRYmaGRiieoMeWBA X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(346002)(366004)(39860400002)(136003)(16526019)(316002)(8936002)(478600001)(52116002)(83380400001)(26005)(186003)(6512007)(69590400012)(6916009)(66946007)(8676002)(2906002)(36756003)(86362001)(66476007)(6506007)(44832011)(5660300002)(38100700002)(6486002)(6666004)(66556008)(38350700002)(4744005)(956004)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ISqgv40STjRmad4PkoS2oEShpNa6FHfDpjQ0dYBRsjNr1N+KLUw7otLV+cV1bi9dqi2mrM6SBc7Q2cEWVpa1gIKE6kmf25hY0SJpWnAg/goIyrh00M8MFSDyKlP8a16raYU3473glT9LWwwg+zMLL/xrLUGfGJSLkRCJVwHvriRCe0pOtzaPTPvMVLWg+YB7nzmmOgD/pUu3dxprCLPzLslZngudZ2f1JGovhLx0nLuo1rPxJ2vIJTgSoG3PqlcJeyFfH5oSnJeWpco5/bs/DsLecMmUx4WEGTMun27xyc6bpjvMtAD64Xj/5Z6/Diy/j7Qwdiqj+OSSBVvT4jvKIuO78wTFBOf7kBHWC+5t21CFHacgpbhsRn67gorK1n659xvPA+5vnFD26c0HX5q6BhdTBixbTYZzQ23yzfPU55HHf8wKUw2GVTT3KBwK9sWEWq8Qcq+q2SlTYaCastlfzUAs/dGokJdBCPnNjT6Zt7CNvF9rGXE46e7lYiK9UvEhRDuYnjemLXeeAb4nwS1ZTnWSDJTWTIidWfiSp9yIQr40x4WheFDmWkS2rRu+rwRH4bNZskw2XPAgNNnpT27KqhIai/4OCHvz+CZduuiYQHaJzeIqzTSDcqwb30dWE/MjwmkR9LA1OBJ6yI5qbPJMuxYKwbHVzOkKtx09uGbTRAtO5UKangSJsRgcKmnUORWUEPxhkjlDXuIyKQJVIj0GABHEPArlFt53kth6jpZCgy+uYngKFulyLleUJMA4PZYYfRxujTLJOjsj5npheKOa76nJDZBysl0u8zbSKEGiIT1R8dVA8mScUaVNkDGj73u6XmgrA93R0HD19+3LXpTJdAwXQV6DhPc29fL2cfqTR1e9GzKFZFZJlztP7EEQiMj/e0lvrhn4yfyMeNuGNVl5yyhpttuggKrvc3NcigJZDq+vuXWgt+8ZhHWYO3zJ6NBkMd9GSvSfBsqvZWGnyAfdyJmM+UahgdaP/FFtux/k8YjGfygHU+hsVsDMbu3+AI38ezwPA/3kPPAOQszzJGy/mdLIKmTzw+AZvJID26fVCIZ3MDdlELgRjQVUof9hhAMOOdy9j4A4jOeqVKbTbn3UG5RZqH20Po+8hIqmQRh1NIY5FeeiP4PPAoL0hsBqg8H26yuEk6OR/droDOP7x0EeRegCBcUE8T0zTupw5Y3LA6K1wyoQl1ShhziSTP86XJNOYZVb6MJeZstCM0rowBOHuWdrVzVgIMEHJ1W7TqrfYZ19Z4VrUr0QMbqQE3And8fC2IcdLyxwBL0GCFamfNAEkBfObXerWiXHZR9d2LoKYHEwm7mswX14/O6xW0gjS1Be X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6541 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT010.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 6dd5fcf4-c8aa-498b-cac4-08d8fe54ad38 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CSKY7l01L/IKbWDKjMJ1+uSP6NrfWjiw9jbZ3YPqQpL2JYnIEYVRYHcs+ZdU2vNFaN+D1raKrC240kTJV2Gj8w5WKRs5F5Q6V2Ui8hT3ACnX3VLUvvRCwN2+LyQ1rBYosA32M3cpyyqzlD2oWthjkx9WC3xoUGPZgdZkBpqCpRbcSiH76yzX4tnhgdkt+YDMtLKL8oC0DnIVe7fTeL5tHC+xuzKXqjJEQi7skpIEJbowrc3Cg2F0z61fRNW+ahIA1Thyp2xid1IzfwvLjL2rVqtOADZmZWVW6coe+9RWN9CuwAMk7biqQLgKhi9JYvAXulWi88LxJ6zlWO6P1bEv7vyb0hET65uKqPRvtIFscBYbzCMu6KSLYU4upPLjiqds3LNXSrq9/ZNnf8oP1dw19AgpSUG2suUVOZvVhym3NtuvuEfocU5Fags+dnqsRRfX42N4khdDgxVMUPkagCfiDV8kKYXyP4+BRw/fDsK4JorLNt+qcfPtL2LbZB8Xi88/ejwFvvW5uPgiNKSPeoEEFCeapeDS47JNsXDGwl65nXdtxG0twZTQm8RcA5pVBrOifvInSTO+lujlAeLq/HF8JgVro8em9VosVQWz54Y6OiohfPI8n3sKFKMsyYeowqsbPp5meel1D49j718F2/F0l7Hv62o0Y2RJrm71j3TedF77bBeeOZ5EIuuPxI3yd9uR X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(39860400002)(396003)(136003)(376002)(346002)(46966006)(36840700001)(336012)(2906002)(316002)(478600001)(956004)(70586007)(5660300002)(82310400003)(356005)(2616005)(36860700001)(44832011)(81166007)(186003)(6916009)(83380400001)(6506007)(8936002)(82740400003)(26005)(4744005)(6512007)(36756003)(8676002)(69590400012)(86362001)(47076005)(6486002)(70206006)(16526019)(6666004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:18:35.1713 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 98b75176-8f6d-43a7-329a-08d8fe54bbad X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT010.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6748 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The max modid is a valid index in the dtv, it should not be skipped. The bug is observable if the last module has modid == 64 and its generation is same or less than the max generation of the previous modules. Then dtv[0].counter implies dtv[64] is initialized but it isn't. Fixes bug 27136. Reviewed-by: Adhemerval Zanella --- elf/dl-tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elf/dl-tls.c b/elf/dl-tls.c index dd76829e74..79b93ad91b 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -590,7 +590,7 @@ _dl_allocate_tls_init (void *result) } total += cnt; - if (total >= GL(dl_tls_max_dtv_idx)) + if (total > GL(dl_tls_max_dtv_idx)) break; listp = listp->next; From patchwork Tue Apr 13 08:18:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465610 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=qMMxLgvq; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJQv11FFz9sW1 for ; Tue, 13 Apr 2021 18:18:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3BE8A396903C; Tue, 13 Apr 2021 08:18:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BE8A396903C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301922; bh=9G9splqBIdKlO6aE8FFsD3PfTBxDSW63VoEvmT+GNkE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qMMxLgvqE6xQtQnD2bqCaFDv71BZ7+3Xq+I/7kPDFfHWdezMvlTH7AkzOT9sKfwfw cB9DiNwO3159MACVusXM9t8RhqhFDDnmuI+U+SuZbJbM7bpgggvYiuFUqRh013Luhh 7T3ExyJTouOKBBgToASk2vNk8isJd8CLZ5oWUaR4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2054.outbound.protection.outlook.com [40.107.20.54]) by sourceware.org (Postfix) with ESMTPS id C64ED393C85F for ; Tue, 13 Apr 2021 08:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C64ED393C85F Received: from AM6P195CA0028.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:81::41) by VE1PR08MB5726.eurprd08.prod.outlook.com (2603:10a6:800:1b2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Tue, 13 Apr 2021 08:18:37 +0000 Received: from VE1EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:81:cafe::49) by AM6P195CA0028.outlook.office365.com (2603:10a6:209:81::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:18:36 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT005.mail.protection.outlook.com (10.152.18.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:18:36 +0000 Received: ("Tessian outbound 82c2d58b350b:v90"); Tue, 13 Apr 2021 08:18:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: dcee58c87e68cae2 X-CR-MTA-TID: 64aa7808 Received: from d499ea259de4.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A93C39A5-3D01-4102-BEB1-39D2CBA0ECBB.1; Tue, 13 Apr 2021 08:18:30 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d499ea259de4.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:18:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9MJvrlIsNwKM6w2raJKVivJOVKy/TQiIdJHjO4UZnp9dIWTnXNjHydaTPoBCxrjejZ3pT4om0E2i68YEWCmYoEmp/T0GwpplNhJa/dmxMssruMxHYumm9Tcqo/Cwun3iB4Ya5QbB5/6sQnmLTzawNz3AayQi69Jvora1/ZkYbq/zAeqDBdllxQL1oSEi7ipatGoP6CLh0mXCQdrK96h6AzM5pbRLqVtl+QKsteGFazRe7Rn236Fis/gA/815VXw1RQSR66Ml1s2K3G56Ll4ykzNpo90lLSXNQRL7FOaymx8HipUv4RD6uyWNGE9kRM4mx00Jh/czD0StPhHL4eyzQ== 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=9G9splqBIdKlO6aE8FFsD3PfTBxDSW63VoEvmT+GNkE=; b=RP/JRs8N4Ia1EQLue0uC0tZJWZ1xiLt2SmEnrl5obO0APmS+Fu9iLCTCTh9mOVqr093utiNiCynUqzLas2zh8qEXQI19eWI3zY9Ii5dHexkRKScWy2VLDDb/RsDqeDXuA/jqtSH8xqgl+hgoi4H/0Puw1lv3IvnRgk8sH8CI8mS0tRBmtTMKaL3/PVNdnSnTLNUuPT4YmqGuFGD7CzRYwlZpULGsMTSIKK9Vp0t7l2u9AnhINzXhvVJBja0r+zj5Ckp70AS+rSdYTMqUnFilbHv5ZWn4hatCgUi9qIRUxdpgG04smMx67E1nHFuRtLrM6KO6hCgFOtAZ1x3n571+PA== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6541.eurprd08.prod.outlook.com (2603:10a6:102:15a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.19; Tue, 13 Apr 2021 08:18:29 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:18:29 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 02/14] elf: Add a DTV setup test [BZ #27136] Date: Tue, 13 Apr 2021 09:18:22 +0100 Message-Id: <0b160a0060cd209a33496da51f915258ec5dd9a5.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO4P123CA0022.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:151::9) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO4P123CA0022.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:151::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:18:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 47e463bf-09c8-4ba3-a517-08d8fe54bc88 X-MS-TrafficTypeDiagnostic: PAXPR08MB6541:|VE1PR08MB5726: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: a2s26ABpxFvgbvfC3bhV93pnpDZVUc3uX6FB5sdftF22Y22VXo88lVqNQn1anSDbhGHHaXAmCNioKbtAAhHRzGapX0v6EI1PyHytC+udddi8W441qWvqD+PvXY/qe0HAY0zvEkt/utAOVuHeFSRwseEb2T9sdT9Qjk08a6r1cWRu9+ndgjgFug7s2nDPq6aWOBzAoWZ8tXdGtOxC1e7i0PUuUNqvEYwr/QpTK+chFFDN+McMwIrYgBsBAQAmNjZCxGPH8uYyG9dz34MrqjTgy6prgKqhKwYfIxjWOkq1hWa4uT6Peh8vNcKTvQEaWrDVgqbWDVY2hCeftP7f0uUkMJEcByEpADwCoGV9tZUCq3GBJpkIUzU+RPvapRXdq3loGgppfYJ1FAg7xc9PlkPzPU7f9Oee9vSp+5uQXJkNpS8a4jDHOBzn7g4lRfGd06t+RqN+ZperYkFqWTI6Vy+GJxKspBsYb7KyglMfeNd972tZFcarGPYbQ5K4TcwPET6Ls+kAK19RuYgDsFBHaegvBjflZQCaQVzIV6+/+gN7CC3ZUw8KB4khWaTEkeAjITWGfllz01GzCIo2iHZevD+vCYHv3NYsLwc9YNtrbpGwdbJFEUiWupezkOf3YaqUnAAfB9ng4BUOhjb2dqzzWGTai1v/LvRday06Zmk0RKF3vNgC/jNYmXpbQJwdFBrHQ9PKShp+9i5u4AtWH48fxqcY0pcTw1MyeZ8sKnOGPggMrQ9eDMbWPUl/wvDmi+PTzcW4sSwNcYcSZJwrpQPRnBwAZBN88bvS2RtuxjfhULf3CVg= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(346002)(366004)(39860400002)(136003)(16526019)(316002)(8936002)(478600001)(52116002)(83380400001)(26005)(186003)(6512007)(69590400012)(6916009)(66946007)(8676002)(2906002)(36756003)(86362001)(66476007)(6506007)(44832011)(5660300002)(38100700002)(6486002)(6666004)(66556008)(38350700002)(956004)(2616005)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: /rot6w9TA419m1+GxVS7sUU4VtY/2g/gG4N7ca/CTSg+mNpQwE4ehamrZ36LIgytjws3K5hyu3/8McECa5O/S9aHCLDkdEF6lXs4/F3YPQLbjfYDKFLcNUOm69av24fsXqK8lJ4gm0A7Gg9A2pZQhYZ/zAmUQPfYSf42CxlagXihij9hvkoz+CjQmEzw3GcB1W7SsdTrIEWFYTpiRtn/OqHPaOepJzdFzIc9EsTHmBqHtZ6trkat5htu9nRNVe4GeL9usQQXM3W4d0MO/3+TTO4AfRwX+ww1qZtwBKN0G0ktWVfekSX/qIxaAJQpfjKsby1LL6H1sZw5hN/BBYw4UQ96yqE+Cu+n6zVVB4hYGo0dHE3rL4D/Ot9v0YXD7dp91N9ZKwojnCHSAxGDi6UjfUJevCD+D3THI/yLD6Y46zImepSau+sdCIVUxRZ/tk6haPSfqmMm+4fSu+g/MLg2qSS57TmTv4n/49PWt1RHr+iuUvB9ItA5Fbx3/f/cLZJ5WHcYT+FUnWSetVVvtnlrk5uCa6NqR4BMGOZ7Q88IvrJ/2ikyP1JqhBt0xSvstJsuhhjE29/4ahl5vawPyavpYW2UBzB2NwqwXPQFrY+tnCTZiBHylig860lw+wwBn+tFZb5SATG2W04JEXp7caOY70U9oZf0z3kHItmOp5nyIxPEd00P9siD9MAZMpK7PptpyiGKE11wFmiHER0dP2geGbd3CsQ5FwR3/DClyB5Air0JZ12P70FzZLbiSfvCt9FE8NVozjO9sMiyvKUCps+8wz+gfS+6+piKLF4Kvi4fR9GjQAioeyT02iOViAGJSrfEPXzoTOzelpB4yyIMtXDGcjUbK33GFOYu4+NduqTZ6letp1quJRbNAHHehMcbBrqyr3qjDnc6FXHjqoPFjdHKqDzUonW4d/zFhHjy4MGEc0bolv15dO/1VR0/qnMIBOCer2SHxv0YgtNP9wOCikeFuq0C1zT5Ezbh3bW4DAAEg/yteIxpGvN9yUKa7hgINhAERirrlgowgakK5n6ggkaDGTKiyYmkbRBFkeW13RK7kVvzuVKyspHs5qYaK9Ln3k3DCiQkKq5AXI2Fv4j5yayJ62zzDVpLuPCh3dyQVINWqxXrcdqYe62Vk1agSRP/UO/5gptZxnP3Bp33r4SAOOtXhI+oZRfzXK3kgX3vNNaf929vyZSgumS7/8s1CZf4qO3/dFZx3KA0qkz/3tb5+kjcEikX0EzjXd6Ay49zswIvHV5wh+DtLHSuzSeNACcC8f8ryreLFSLj2NNDtd+XlsLd3NIZEpmG34wpVK5s3/suTmHkDAV0Xf7hXre41k806h4I X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6541 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 41471571-bd97-4b6a-fdc7-08d8fe54b7c6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kQGlywbFG04DJy7D/yFh8FCI2+i3ein1znr15YZVS4RrUWXqaWqyDINHLsmnYhHy2L2K81xYQ3NmKozdTzx3VdKSI5FYyXEKDabrUF/bHmn9xSQXt8Yx8kpBctXQ6fjCAMpUBqMPt/vK0gHkRW/5FhHgWJBQdm5yQ6RcjM78Tilv4Ne/O1IV0PNf56/ojd9RfqsRPWwHKqnmvSedTzy8eMThNxQAd57UfQmRBB7ESdqUIRwr3uYkhxvUUHt3nuPG1AXTco38s9tzPUa1sahzDFAT5oH/KtzoBYl6nsVghhgmVE19J5du2zrIV+ax9iJikhcKWSlXzNv0O1iN1VAno4rkSr5ei7KmF3O/lG/on4MZujJYOM6dv2wKh6tZL+uArtvxJ4OXG3tQiAj4Rl/QPjcx+GaL1ix814KVoiFx5BuegSx6hXy84rQHbDbRE4Yk+xyWJuRekwWdnQEEKLYxKbey5i5kBojmeEzDyKjQRO6v0HJbFY9VLwTyL/aNR9BqNuoILMypi8Q3/filc2MLPYlLfZWJJZHETwnR1qdxL4KFfE0nfz2hFUeEifl+aYoH0epT2lYtoUmI3xOASFpHcWw+tQoOjkNuVei87/MxflvO+tXEP6uDA9fCaYIYaY6uB2WZAibYZq1r5zsxgjC1HhJqH4W2U3L8FlhsXDAXua+669HWdpIz9D6Drf7I05TFe9PN8THfyuH9t5q7CQr6M9SJveMEtuvle7yZGLDOgnlrVc7YP/eXTgV/XWgmoBt90kbvm2nJ5VQkzl7bW8Jaq3N8/IZUzB6gnaPeRKPsRL4= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(396003)(136003)(39860400002)(346002)(376002)(36840700001)(46966006)(5660300002)(336012)(83380400001)(478600001)(16526019)(36756003)(8676002)(86362001)(6666004)(70206006)(6506007)(316002)(6916009)(81166007)(8936002)(6512007)(6486002)(2616005)(956004)(47076005)(69590400012)(186003)(26005)(2906002)(356005)(82740400003)(70586007)(44832011)(82310400003)(36860700001)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:18:36.5435 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47e463bf-09c8-4ba3-a517-08d8fe54bc88 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5726 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The test dlopens a large number of modules with TLS, they are reused from an existing test. The test relies on the reuse of slotinfo entries after dlclose, without bug 27135 fixed this needs a failing dlopen. With a slotinfo list that has non-monotone increasing generation counters, bug 27136 can trigger. Reviewed-by: Adhemerval Zanella --- v2: - moved from nptl/ to elf/ - dlopen a different set of existing modules. - code style fixes (!= NULL etc). - moved after bug fix patch --- elf/Makefile | 10 ++++- elf/tst-tls20.c | 98 ++++++++++++++++++++++++++++++++++++++++++ elf/tst-tls20mod-bad.c | 2 + 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 elf/tst-tls20.c create mode 100644 elf/tst-tls20mod-bad.c diff --git a/elf/Makefile b/elf/Makefile index 0bef49e53d..b1344f1133 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -222,7 +222,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-audit14 tst-audit15 tst-audit16 \ tst-single_threaded tst-single_threaded-pthread \ tst-tls-ie tst-tls-ie-dlmopen argv0test \ - tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask + tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ + tst-tls20 # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -344,6 +345,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ libmarkermod2-1 libmarkermod2-2 \ libmarkermod3-1 libmarkermod3-2 libmarkermod3-3 \ libmarkermod4-1 libmarkermod4-2 libmarkermod4-3 libmarkermod4-4 \ + tst-tls20mod-bad # Most modules build with _ISOMAC defined, but those filtered out # depend on internal headers. @@ -1924,3 +1926,9 @@ $(objpfx)tst-rtld-help.out: $(objpfx)ld.so fi; \ (exit $$status); \ $(evaluate-test) + +# Reuses tst-tls-many-dynamic-modules +tst-tls20mod-bad.so-no-z-defs = yes +$(objpfx)tst-tls20: $(libdl) $(shared-thread-library) +$(objpfx)tst-tls20.out: $(objpfx)tst-tls20mod-bad.so \ + $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so) diff --git a/elf/tst-tls20.c b/elf/tst-tls20.c new file mode 100644 index 0000000000..a378c1fa08 --- /dev/null +++ b/elf/tst-tls20.c @@ -0,0 +1,98 @@ +/* Test dtv setup if entries don't have monotone increasing generation. + Copyright (C) 2021 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 +#include +#include +#include +#include +#include +#include + +#define NMOD 100 +static void *mod[NMOD]; + +static void +load_fail (void) +{ + /* Expected to fail because of a missing symbol. */ + void *m = dlopen ("tst-tls20mod-bad.so", RTLD_NOW); + if (m != NULL) + FAIL_EXIT1 ("dlopen of tst-tls20mod-bad.so succeeded\n"); +} + +static void +load_mod (int i) +{ + char buf[100]; + snprintf (buf, sizeof buf, "tst-tls-manydynamic%02dmod.so", i); + mod[i] = xdlopen (buf, RTLD_LAZY); +} + +static void +unload_mod (int i) +{ + if (mod[i] != NULL) + xdlclose (mod[i]); + mod[i] = NULL; +} + +static void +access (int i) +{ + char buf[100]; + snprintf (buf, sizeof buf, "tls_global_%02d", i); + dlerror (); + int *p = dlsym (mod[i], buf); + printf ("mod[%d]: &tls = %p\n", i, p); + if (p == NULL) + FAIL_EXIT1 ("dlsym failed: %s\n", dlerror ()); + ++*p; +} + +static void * +start (void *a) +{ + for (int i = 0; i < NMOD; i++) + if (mod[i] != NULL) + access (i); + return 0; +} + +static int +do_test (void) +{ + int i; + + for (i = 0; i < NMOD; i++) + { + load_mod (i); + /* Bump the generation of mod[0] without using new dtv slot. */ + unload_mod (0); + load_fail (); /* Ensure GL(dl_tls_dtv_gaps) is true: see bug 27135. */ + load_mod (0); + /* Access TLS in all loaded modules. */ + pthread_t t = xpthread_create (0, start, 0); + xpthread_join (t); + } + for (i = 0; i < NMOD; i++) + unload_mod (i); + return 0; +} + +#include diff --git a/elf/tst-tls20mod-bad.c b/elf/tst-tls20mod-bad.c new file mode 100644 index 0000000000..c1aed8ea7d --- /dev/null +++ b/elf/tst-tls20mod-bad.c @@ -0,0 +1,2 @@ +void missing_symbol (void); +void f (void) {missing_symbol ();} From patchwork Tue Apr 13 08:18:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465611 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=HJsC4Cst; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJRY5dB1z9sVw for ; Tue, 13 Apr 2021 18:19:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 569BE3982052; Tue, 13 Apr 2021 08:19:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 569BE3982052 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301958; bh=62ZpOw/uiu2AgHBbXamK8GyV18i8m8RsEFD1DrCK8F0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HJsC4Cst5YuHyBhCdE/K+SVPJfOgc/lwgHtIfaubtt/a59+SID+jkZgbHOMAIiqSB OkDpeSs+fEGFGdX30/OdIPGYMKhABGRIAUMpB9HUtgby12HoxAu6Dmwv2BfeewE030 p3I2CXUI26wVZlhv0Aab6MppUwwaSj2BLcUGft2I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60063.outbound.protection.outlook.com [40.107.6.63]) by sourceware.org (Postfix) with ESMTPS id 65E1E393C85F for ; Tue, 13 Apr 2021 08:19:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65E1E393C85F Received: from AM6PR01CA0061.eurprd01.prod.exchangelabs.com (2603:10a6:20b:e0::38) by HE1PR0802MB2377.eurprd08.prod.outlook.com (2603:10a6:3:c9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Tue, 13 Apr 2021 08:19:12 +0000 Received: from VE1EUR03FT042.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:e0:cafe::98) by AM6PR01CA0061.outlook.office365.com (2603:10a6:20b:e0::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:19:12 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT042.mail.protection.outlook.com (10.152.19.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:19:12 +0000 Received: ("Tessian outbound 82c2d58b350b:v90"); Tue, 13 Apr 2021 08:19:11 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b5d1699080f75efb X-CR-MTA-TID: 64aa7808 Received: from 6615f889b6a9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CCE22BEA-49C0-4A0F-9B70-8AA35C588512.1; Tue, 13 Apr 2021 08:18:47 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6615f889b6a9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:18:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BQZ3p2n99eJp0sUvDwk8XSE0mFI4VXqE5/eiYYWf2p6lIp3nAovanrjz1BQmjfHoVsna9EliapoD+tJXqlMKr8ATcGUhHS2egYiGjE3SQ2xGpP5Jm93ezNWsKWx7huq1eqbHEw2nW2aRhh15AoufikpRFy9AkFpKeccWfuFQabY/lSxSYtrU+1yqWH8ezTAUqpix86hYUm4z3jRx5C1/znZKCSaraZ/IqnntarkJKPV0lXrIwVYWWVfDg73YoXJ3h3cvT7QvLhvofjwwzsgO0/W8Z1B3Wp9GPh32cHp4Kh1bdcdztPMi072wkT5AJsLzdSqk5K97RWAd54R3MRMYUg== 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=62ZpOw/uiu2AgHBbXamK8GyV18i8m8RsEFD1DrCK8F0=; b=lTLrAgIbZVGbY0ITmsNpHvm7CJGZfYOOfe5u4rN21Zu6dmKSTPv9xQOiNdRF8+O8LDSvWr7bfErtSMxbfmaH9gMX1XkZ+sDdOQLP+zQUYIDTM2z0tOucy0vRnZTTYdCfiijcrXpcBizh0pBfjzUO6uq2mYLxUtlio4397MKt2sowu4byC1zM9buHKOr9Gi5y9ZHaqsELUkICDIkFR3iLVjVUI82UczCUKsZ5GYaSRw++hZJK0WbLi/17Fa70Cba4Ejx41VP3ggw7jfLkfH8wlkVGJvXQOXzDVVr2WmXwG17x7vhdqeNUGc0J2VybKm5TigniL80y1tsJh0TaMFnCMA== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6397.eurprd08.prod.outlook.com (2603:10a6:102:12f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:18:45 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:18:45 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 03/14] elf: Fix comments and logic in _dl_add_to_slotinfo Date: Tue, 13 Apr 2021 09:18:39 +0100 Message-Id: <6b63f027658b2bbe41f2da374da0aff63a77647f.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO4P123CA0469.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::6) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO4P123CA0469.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:18:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4dc63003-b8a2-44fc-cd8e-08d8fe54d1bc X-MS-TrafficTypeDiagnostic: PAXPR08MB6397:|HE1PR0802MB2377: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:3631;OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: kPhO8klRRh/IJSwjL6Sxqo+NEbRfy8JIjAdJgJPtpjtm5qkgZJGTcyf+1ynAxhvOLnlqxEKTr4ZCHCFzDhyUg6+SEr4h594knm1A37Vio+q0380UR0sxPnanGxHGZuO2BJBfQoIo1eMFz5wDOWebyTk6x7MGo6+XieafuXZD7/G+7c0yu7NPbYdNBdKm4z1LQLqLN+YE+cQFixzr9bSDf6W7yz1wqizfZ9//9k/S51yIZiVmKWopBt9VPogZXjk4wcYCax/AdQoT0vQ8+JYkfiszm5zVGZrTPwBgN8d4lnuRQTEaSWQzVSG/5xM9VJMCKE/S2mcSUMx0PKVoZ2tsAqGIwOkLN7KwX/k94ChQJ0MchhhA9FERiJjXm/PkU4o+pJLMupXZ1vPBg2HZDADotFGZO2Qtn5ZWIgnVs28H0cf0S4wih6+2PUgf1sh9k07Br9rmpXJChDcUZNTxi8f4G7za3PdmrZtw0tkvhMnPUzmns/GJVkMrR2TXekZT1HrWrBOhphVbbACw6LWISHnVRLeBud01ZE8qxbHfrla3lLq7BCMz5bxKwQOGwank7LLGBZyVHRP8u68EvuC+YULrybmT9CofS3JF6kgL6zjJ0TltLSrLqUZ1b4tZKjFjuGf2w6oylX6Xta76l/4WUl0HH3TMxD2lGoB67haa//0GrDQcxkwEbXDthxw1Iz3LrvAr X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(346002)(396003)(39860400002)(376002)(366004)(2906002)(6666004)(66556008)(6506007)(36756003)(26005)(66946007)(69590400012)(44832011)(38350700002)(83380400001)(956004)(86362001)(6486002)(16526019)(8676002)(316002)(8936002)(478600001)(6512007)(52116002)(38100700002)(5660300002)(2616005)(186003)(66476007)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kHQ9qD5XeIpDHdm926iUm7d0SHXD4blEEsRE4oXpcL5yQJ/W/JIJky7gUgxSsuWwZbTrvtck1syxXCoecL8uOrl53Xz5VyjXRoH3dTAdQ/WbUq3aksnzrgiTdWo64jSuItLDed/q8+M3hWSYVzcyaFN0QhlLU5uae1DB3thuON3dSpNi/KJB+Bz7mSY/A8INJP6VtxKQI8SoBNvJrW6REgn89RkTyWVCup1xWTIgM3kcoyl3YIXV3VmGQFxMWJOVBL1StrkiXhoRb5ExcIJH9JEcfwqQL0FhsFVUvrXjiUetnVIAbfeqXi70CpsT1tTqXxJ2l4FQXOvKwQIibjuvr9TFsjp4ORsihn/LKiIUo0ustqyIRJkg1XmgepR24Wluos8JAY89niNmXi2DHbNkBPAX90zVrnuEog+zMJVOqo1KKUqLCXCFTukyHLuNDowCBdY46uzh4V3az9aHEJyjJLgwPK2QIvD1rAJrQFs0BudZbgEIUKUiSh1efWpvedf+sIYu7MPV6HErnpuKvVX89m1vO1L+VWGSwx6B5KecCWYx/KKApU6asMAeV1Na8JWeYT+tJRqCVbcmGU/DpNQXWyRmWUam5E/nDVG3uvRRitTyz03JFd7j/hmHfe6AKr29N/+UCL1gcQ4pQ/i+aFXe8vCE0LHi4UO1mdwplYienXSUJja6iyQFwY1NRQ6rW1V4/GpSAMS0mNaZBwMN+FJmkktNwc2tOITqz0AmLU5/VppEIA1YqSgAmELu7XXjeqfVLhPw+PK94GuIeOpUKBrbBc61syFqBQ8ZYztWHSgZwwzQwV6KwTIC9+YwTqMuEMnoyfhRMuyiEYdqKiji7SYxsEbV9wSArodnOp6cQ+0bqCG9wJEqNxbBHhvR3VZWwgyqV5uEu1u/XfY4jy5ldtFtnMBrSLbY6d2bcFSDFVYo8huKFyr7mihvsPAu5EbbGBIaSVeBxa16iaEZ9lMJdKthJKefpRdqNA/d1sOqO6CdklPu99heBFfFuAuZ6fCqf+6ceH8us0Y+o7XBNLDwrwVqiVQaz++HehYOoL4LZc+GmKmUwdWdMPMnLjti1joSby8hg7u7ioc4StDDQZhEVIr4stxIuWsPuHzJPwHXh7nb/REiu5b85xs0Oh0w995ri9xuOKJfTg0uuH0zU6oPcDrWZLTZBiMkI/8EFa+LOPV8wZ8+eM3VfMcYDTav3wYOvYyB897BTVII3yvKZYi9UaRrvVlF3xFNCfPng7iqTMe62peJVLh/4RG8lk2ykZ8/y5zG47GobMyBo5gWaZe4tA36anAYL6JmWiiSRipc4W2CuSWpoQAq8PEl8s9c23mTkf3i X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6397 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT042.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 624b626a-fe26-4340-1e66-08d8fe54c1bd X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ua9We5zm92M/7+zt28Ae/MVV1Sz14zBxc894+C7D+SnftgliNx0eo72OYfA2HGCDIcVy2r08sG/L2mj+TBcI53FCQr3g3rq4g8QDw6c/dq9UO0b++2tNmQIbhc7d5s7ZaSl7zOQZerIV14nYxlPTR5rpOETD++qtOtV7Fvqo1pNpvulpk7Q7JNiFUYacSk645ky3paMZLtDkRJAO9tVY/ZAkKEjs7vezMJ2zBhCOFcKlL1TtS9pAMcyL04476NSJon9BphTWOwb9NzJr9tXtlh7ujQQu8p0N6aXclmp4Jqh/HHvf7Lu4cJdunFwReSnGdOJNZAiSSxBYUPTA8hYPI47k++9nz5HDdJ2dbmNqmImTJqhOEWLf2u1Ccg0k2fVtP9su/BoWW4yMMTwzoMeKV1fhN/b+Tz/+VbwMtzaJAxf1kac8EvCjP4MH4UdAZ4ii9Dingc5ubQi11dYFVFBI3tYNcfsm6fcGoe1YAF1oe0LIGzomKLT22CVk6QHcJibNwX9EAD0GR4epdoLs1qNizjo9qQqTA5M2LTjh31K/tw5zipfvFuoXD3X1toZTi4jw5I00x/pt9JsNn+N2H23SWet36CepUTmUr3iJV/3qJuFEhPO4yUzXF3pgun4jn3KdP+P5Y/4lq5q1MVSjpgZiqr69NQegOnLhja/USlEf7yzAOWB0iTlVorYAXe7Uu01N X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(39860400002)(376002)(346002)(396003)(36840700001)(46966006)(6666004)(36756003)(6506007)(81166007)(82740400003)(2616005)(336012)(956004)(16526019)(5660300002)(70586007)(186003)(356005)(316002)(6916009)(44832011)(70206006)(8936002)(8676002)(478600001)(36860700001)(26005)(2906002)(6486002)(86362001)(69590400012)(47076005)(82310400003)(6512007)(83380400001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:19:12.1135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4dc63003-b8a2-44fc-cd8e-08d8fe54d1bc X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT042.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2377 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Since commit a509eb117fac1d764b15eba64993f4bdb63d7f3c Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] the generation counter update is not needed in the failure path. That commit ensures allocation in _dl_add_to_slotinfo happens before the demarcation point in dlopen (it is called twice, first time is for allocation only where dlopen can still be reverted on failure, then second time actual dtv updates are done which then cannot fail). Reviewed-by: Adhemerval Zanella --- v2: - expanded the commit message a bit. --- elf/dl-tls.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/elf/dl-tls.c b/elf/dl-tls.c index 79b93ad91b..24d00c14ef 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -998,16 +998,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); if (listp == NULL) { - /* We ran out of memory. We will simply fail this - call but don't undo anything we did so far. The - application will crash or be terminated anyway very - soon. */ - - /* We have to do this since some entries in the dtv - slotinfo array might already point to this - generation. */ - ++GL(dl_tls_generation); - + /* We ran out of memory while resizing the dtv slotinfo list. */ _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\ cannot create TLS data structures")); } From patchwork Tue Apr 13 08:18:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465612 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=jwFmFj5F; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJRj1Cfkz9sW4 for ; Tue, 13 Apr 2021 18:19:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00F1D3982041; Tue, 13 Apr 2021 08:19:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00F1D3982041 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301967; bh=j3a7ntAWJcBsaPT/L2yOPBxwia8UcYNfp1/OADLIUHc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jwFmFj5F+R8/Kh3+rNffsR9Ac0UcVdx6xUlkJu4vWgmutGHhVdFQ6dQKKwm0Es9ct 6U3c3O+HcPHxVohhBz3n3n74yEYCPWgu+JP0s5+gD97IZcAumZxOm7vRaes4NwWtfq PqUxmzeFqV/yhFGxCiJ0os+Gz7LAqQta8B5ytDqE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2080.outbound.protection.outlook.com [40.107.20.80]) by sourceware.org (Postfix) with ESMTPS id D8E78393C87E for ; Tue, 13 Apr 2021 08:19:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D8E78393C87E Received: from AM6PR01CA0046.eurprd01.prod.exchangelabs.com (2603:10a6:20b:e0::23) by AM6PR08MB4801.eurprd08.prod.outlook.com (2603:10a6:20b:c1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Tue, 13 Apr 2021 08:19:22 +0000 Received: from AM5EUR03FT049.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:e0:cafe::66) by AM6PR01CA0046.outlook.office365.com (2603:10a6:20b:e0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:19:22 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT049.mail.protection.outlook.com (10.152.17.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:19:21 +0000 Received: ("Tessian outbound 34291f7cb530:v90"); Tue, 13 Apr 2021 08:19:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: feafc006e0a5bf2d X-CR-MTA-TID: 64aa7808 Received: from 4e0af2f3386c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D67BF6C9-5ECF-4518-A3A2-D859259D8118.1; Tue, 13 Apr 2021 08:19:03 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4e0af2f3386c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:19:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V1Z710vcSK1yfknkBTiAJyDytYCOFbdT9YFaOryDmDlI+++a5fd78JAny2eqcMlvfZrQDgzbffJ6dofOcFWBPAGvcHz8s/i6H9PeBvvyudSGFa89dUIcjsjEztA7vpSXtz1cqjxNxOH5Y2OGREzNOCwKD6ZEmfErc0BT4LhHIG49/lWwF5ZD31m5tccpIvQc+Zoz0NR4tCD/EnpBTEgEWTbZF9HHN1uql0G2lkZnvH8BCvtDiaGEm3b9y+sIgcuBsidq3AlWLqTHZbZ/d0MFjVyT0+da/tm/NAXNlB2PUIxY81NfBD77U3euaH02I23gu8su4cpnlBMJ1isq/iu7nQ== 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=j3a7ntAWJcBsaPT/L2yOPBxwia8UcYNfp1/OADLIUHc=; b=TmDUCTHC1ddQTl2opDpUBs4LwzHdsQ+0zYAqxgpqklFVsBKFDqEoiWhLVo971dmj18cKGHfnpxMFrexc3JRi6lfVYgQYoM+QBcdqsSHA/vWHawNt9XilTJoZzJz3Nm1BHo1b26XYH7hMIpuz5Tj5Pj+OaFq2QhmvC2O6Ovtc7oFP6Jql6eK3P2iUmvq++iGlvR4ix04E/KXYNJthDSls9LJHLqZd4VrXhUaioe3OIoQ42H3A32SHVzHm3nZmJMvGtlvtEcGq4lcLLuzdf1URhkUx44wZ0e0kcAPWY7jsaY3gry8tz4UxNtJrg06wqiTUV94gnpcw5/mdgwD3m9ak5Q== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6558.eurprd08.prod.outlook.com (2603:10a6:102:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:19:02 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:19:02 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 04/14] elf: Refactor _dl_update_slotinfo to avoid use after free Date: Tue, 13 Apr 2021 09:18:56 +0100 Message-Id: <3237824fb057632817a8de508d1fcb1f2e6f5c7e.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO2P265CA0116.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::32) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0116.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:19:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d1392fc-8721-483e-ffbf-08d8fe54d766 X-MS-TrafficTypeDiagnostic: PAXPR08MB6558:|AM6PR08MB4801: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: XEP625vaFWFr6XAHotsAmfGEGvOWvbP4I7t88KDrkWf63AvAZ4LhuDo6KLIT5ppiRFdb87oAogaLTrX/d48QmGtk1c1ECmfCvK3mygSwmQBh18MQ3i8Oka0od5FpHPhm+fXLOX4pQNEcEc5JBG+ZwSi2KjKSH7a3OJE/IlRu7Xk1PUmF/43+mAYoNEkMkxPk3zi/0WpjY/zv3RsPHCXfFJRWt2+TCYibzvQJbxdeb6kfSJZLhls74djiZaW2QK8yb+teJOFlZX0NmU46K/uTsx95RJ8MuEh3LCujlFbIYdoiNQRVaHwj+/1Tm9ypGlmYWgGL6expgOTxRRdT3lRmMyD9lT+ZdWdmCXaXwJrIhiiZcSY9feLDC0KMknTGX3WViFUP5nJKBn8lSE063yYW3iNA9eNfeXERh0SAFwaWFKV8NZ8lC1RZ3EtxS5kd0sQInIZf34UHLoqYIs8IyR7uvL78MXo43GULrZ+NJu1F9Iqf1HNv8HI61E5cCSCJ9cYPuFQc5humjzIAlQH2iE4NXzuQIMqz5j/r1Zxm8tSRow0vYsneT6I/YOq0k1u1ykNK6nV6OjeZ1wU8PL07OZC+W2p7Hd9lelzB4DSgRpxq+WBwQ23sLSEs1EdfiGABhO8ZLYfN+o8NSf7wP9jKThaJXamfJI3CzTWQ9UEzKX7dlbxYHZjnjvusrGoYpLC4XcO4 X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(26005)(69590400012)(66556008)(44832011)(316002)(66476007)(6512007)(16526019)(38100700002)(8676002)(66946007)(38350700002)(52116002)(186003)(478600001)(2616005)(86362001)(2906002)(6666004)(5660300002)(6486002)(956004)(6506007)(6916009)(83380400001)(36756003)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: smZ5/h1uuVMLNUlWZVqxW1CrFptTz9kiog6I9Ya+KS4BSOMROWlICt5/zFIJVxVatWnN80+LB/9hP5rcZCCD/AiwIB3litZXcUixPI4UHifVUuogzJWDkDwC9snA450yyvcxWIaoOzITAkZqSQ2ma+bDXWzVnLR3aBM7fpsPQPMdDVXGzzVrtb49KcqlHdda/BCtw7yunj+H6GvnkIYjS6jJZIqRpbQal4spkUiTr8zW1uiUp/pNmSArMQqRnq8+9o46Ysj6Z3wiqBU4M2fTGiZ6BxewpWp/wm1gq7g4L9lNCpHxfOWtPYYatbLv1HzL1Noviyz3sr86kmgAySCvV/1SalIP1cHupt3Iqjp2HeS1jJSBQtOZN201Eahlt2wAxujot5rhDoQmZxGcwf3jYmotCoj0WQ0nju/qeKrFEMaAqBGmRExb2lidF3CIRrm+/CdLCw8MysSvsFSq0NWjRNahK5GlKQ1HZ1jJtYWbZu3YEfz+ROwLMvStRqW7a6u5byL8FgW6lqwlejj7OtnwQxPca6PM5EQ2UpMESNpsLIJmS/hLw12T7ybkcgIfOb8QKi1n0J95a+ifJEqmwLySUHvz2UiHAJiW5y3h4f/rfscGdViafXepRRxbpsUba/Kp48tBlF//n2pZJaJssKpPxLvh7rZEpPDjCnLeAkpbJWZTfUlzdIeSOJ+fEQs80jxT3hEjM+MJgWyDNXto4aE1R6veLVFpgmV1odnLpZRXah6QQGN7hZNv2rFIvvZtMV8F4Eb3ElWvQTqU21g7h7p+pP37bAiZ0H2z+D4GHwazV9+XFSKB4wQAbDfkLYGB0e1BLPgavai6Rj9m5A6pMqOJF2aivXp8GZSLjCMlSOlxN05Yjjy1pWVDP3S58Xt2clE964JfYWqIh3VU8ELEK0F4+iOm8eW4eT8QgNkRTyZoFqx3iCLmM/exBlWn2Od4/7gW90mJIx4A5T/az9wmhC4SbUgTzEkyGr+/WPvxlmY6YYosuH9Udj7Ecv8rQHP7Is2DkGwX1h5CHYLGrgn7pmayLGARlLK7tnRmcaurixkTbnvMeQgLB+psoQzY0bYdoKpxbQk8rcamiAJuQv2MlGyHc8jBOBcT5LuymvzZHzObgttLkD1YWq3bkxfs5Sm4pn06S+6p8pKUyLwS3jCMT4thp9fyhlDmLv78+PMhYzAIlgTLs8OMrAPLGx/G55P3VBb0hpd/KqtSJPi/mrAiig1mMYPJr/AGPskCM5I3RD8GhnGPchSV/iZqK0z9iztaWJuEZddSAsdsLnj2MxoE9JmHCS3m9A9pTiLD1liftRLjelvvogz57C1rYYdtG9ttS8gN X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6558 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 85703e03-ccd3-4253-becb-08d8fe54cbda X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xLPatE71G6+a2i3N5opRD9Ci0YcIwearrji6QpA+K9RCTYdSL+4xFPPrAI6fjWeMxiY2AjMuGu3g/fH8NLB7V8aHkHw8rBonuoP/Y3JW7Ddqdj7C0znay4PEXekgb1jJJYkah3eKsywoW6wj/mok/xsOefAZQMs6KfPPwes+7+s9v7YpbZYprpfIdGgyRFtX8pG6LvPdnRvxmeLiTnIs9S3rvNoyD7PnrVRat4CsKAnr87pfw0rhK7gksKRExImNRtURzZzcaUmjGrOxPm+ITAs2ntLfcSy0ij/YOXvm6hYFIjmeR28v3RPzm9veOV9X0ecrMIh7euKbIMd/RibDc+q2QpCCNrY2R7Kbgwf4GYDvTY+fCKZZeSfi9XJJW/OxjOTY9VecbO3JlXC92Zjb/h5mCUSv//CMs8t/rjUeALwFM3KfF8caUdurUiajapjLwVDy+b1FTYPvUej21wdeP7oX/CJ8roF3yV+a1mqJb9IxPkOH9vYeVop7V471eyqZjCSVnI4jFubCKqe8DfW1zX0cLTbk1nqoTDtkpvAyrD+e4Tw1+7bVTfZtEY6zVvvQMV1gloQmNxDF85J/QVnzan6dC3/PtdIzKzSIapoG1tuu+aVT9poe8VrwrAvCHznzZVAFTTSBMrxPBBl86mNa5HxWYF6nIBi7lcQyxwezzgGHqBpr2zUbncuCjIYPs8XF X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(396003)(136003)(346002)(376002)(39860400002)(46966006)(36840700001)(86362001)(36756003)(70586007)(82740400003)(47076005)(36860700001)(478600001)(81166007)(83380400001)(6916009)(956004)(26005)(70206006)(82310400003)(316002)(6666004)(5660300002)(69590400012)(8936002)(44832011)(8676002)(6506007)(356005)(186003)(2906002)(336012)(2616005)(6512007)(16526019)(6486002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:19:21.6885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d1392fc-8721-483e-ffbf-08d8fe54d766 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4801 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" map is not valid to access here because it can be freed by a concurrent dlclose: during tls access (via __tls_get_addr) _dl_update_slotinfo is called without holding dlopen locks. So don't check the modid of map. The map == 0 and map != 0 code paths can be shared (avoiding the dtv resize in case of map == 0 is just an optimization: larger dtv than necessary would be fine too). Reviewed-by: Adhemerval Zanella --- v2: - commit message update --- elf/dl-tls.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/elf/dl-tls.c b/elf/dl-tls.c index 24d00c14ef..f8b32b3ecb 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -743,6 +743,8 @@ _dl_update_slotinfo (unsigned long int req_modid) { for (size_t cnt = total == 0 ? 1 : 0; cnt < listp->len; ++cnt) { + size_t modid = total + cnt; + size_t gen = listp->slotinfo[cnt].gen; if (gen > new_gen) @@ -758,25 +760,12 @@ _dl_update_slotinfo (unsigned long int req_modid) /* If there is no map this means the entry is empty. */ struct link_map *map = listp->slotinfo[cnt].map; - if (map == NULL) - { - if (dtv[-1].counter >= total + cnt) - { - /* If this modid was used at some point the memory - might still be allocated. */ - free (dtv[total + cnt].pointer.to_free); - dtv[total + cnt].pointer.val = TLS_DTV_UNALLOCATED; - dtv[total + cnt].pointer.to_free = NULL; - } - - continue; - } - /* Check whether the current dtv array is large enough. */ - size_t modid = map->l_tls_modid; - assert (total + cnt == modid); if (dtv[-1].counter < modid) { + if (map == NULL) + continue; + /* Resize the dtv. */ dtv = _dl_resize_dtv (dtv); From patchwork Tue Apr 13 08:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465614 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ImUQKw9W; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJS20dJYz9sVw for ; Tue, 13 Apr 2021 18:19:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEDD0393C85F; Tue, 13 Apr 2021 08:19:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEDD0393C85F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301983; bh=LaKYoWqKLO5NDHPyszwt0zNEKgRV794+tn5Hd1VfQTg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ImUQKw9WBCNT8AZE3+mp6PB0B0vzp3mfLaw57Hn6ZcLTn+NRJEBa50pIi2CCmfMcH pXCX+6/rXj81RvlzunF3LxSUR2QkdcQBIs1oX9p9vIyqmfVpNGJd9DoknWpVeZkmtI UGaoKi6Ub/MAppEuT4HJUCwJOkr9+HBB6JcSQ9Oo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80048.outbound.protection.outlook.com [40.107.8.48]) by sourceware.org (Postfix) with ESMTPS id A51C4393C85F for ; Tue, 13 Apr 2021 08:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A51C4393C85F Received: from AS8PR04CA0067.eurprd04.prod.outlook.com (2603:10a6:20b:313::12) by VI1PR0801MB2096.eurprd08.prod.outlook.com (2603:10a6:800:8b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Tue, 13 Apr 2021 08:19:37 +0000 Received: from AM5EUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:313:cafe::10) by AS8PR04CA0067.outlook.office365.com (2603:10a6:20b:313::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:19:37 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT032.mail.protection.outlook.com (10.152.16.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:19:36 +0000 Received: ("Tessian outbound 34291f7cb530:v90"); Tue, 13 Apr 2021 08:19:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: bd4747229966f4c5 X-CR-MTA-TID: 64aa7808 Received: from 29273e85ca4c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 36108BE1-4026-41BF-B9E2-23D4FAA79E5F.1; Tue, 13 Apr 2021 08:19:27 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 29273e85ca4c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:19:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gMwBuV2ulh4r2TnU1V1j4sUr/H2S8nNahkLYYagT4YWRvSdUYZ5iM3RlY1AChKtNZ4mg5m9tiwje22EyMroCkDrrckfuRzIkx2L5t9iPZVLIfc67nFPmRKkcoLGHl/8sE1EEUEfDQ7VeY+mJ1MKY7Edzwnxm/Z9FMeWZoCAxml4WtIVxPrFL/hqxjogoQQCIkMuHihMFZKVsX4logHeR6llo+p2NI/1BGz/XkoZWX+86nFZFgQ/bM6MxU10zbIKwmflrPz6ac0DnBIXnuZsBYabGvDI3KAmBwIFYAo/bKuN86Lr54JIj4aB3QcCONahD+pMHpuOdg7z+oULswQ0Lag== 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=LaKYoWqKLO5NDHPyszwt0zNEKgRV794+tn5Hd1VfQTg=; b=bS+oRs052A8ilmseNtGjYYSiPPRzu3y5OgpKkw9YnEJpbs1E7n0+5SYuvD2lKVQfi/zJxCqKTTsfurX0Z6ULPxKbzg8kucxyy8zXbWMy/T1IdXjS3rBF9ISTJsppLoNWixmi0QtNqmNxHGY/9VaQOJ8fB7Kvy4XZ/D07vKZ17D0WztEETWVcUXvyDjdMDPhJ4syZMC+VIGlO0m1ysxJUZFGj4SYxvDaIAQwx5IrefgJMetFDZUgSSKDvaEzRxlPSV0Pov/DKpSB6Bz5XzUDD5462amosCPKKS42mXHwRwc3ePKYr4uIwgwU/VsceqmKqXLWsQRJ6A+pLPrDkbKafng== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6397.eurprd08.prod.outlook.com (2603:10a6:102:12f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:19:25 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:19:25 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 05/14] elf: Fix data races in pthread_create and TLS access [BZ #19329] Date: Tue, 13 Apr 2021 09:19:13 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: SN7PR04CA0232.namprd04.prod.outlook.com (2603:10b6:806:127::27) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by SN7PR04CA0232.namprd04.prod.outlook.com (2603:10b6:806:127::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:19:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c753614-fe34-4c45-7c33-08d8fe54e07e X-MS-TrafficTypeDiagnostic: PAXPR08MB6397:|VI1PR0801MB2096: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 70Yfzl/Gsq+xK3fgV9eQgxEA3cg2sZ3WKxnXkl0XZAk6tJHYhqaun17Z8fAT6TCul8cFiLwtX+2EKZcvqLBKARgoCDIl1cyQVjT7qXTNtQlJa5XAWoOx4Uh45uYky/oguFFXscYxQuWHZfACJz2XoCN6DFs/D+dYDEmT4dbQfScDBmUylgcQCAynIvIoUtyjAsyC968nayOnx8IaTplgKgmfl461hIxzhT+sBfFTcNX4Wi7fsM5c3CLlrPjnVAlkeMi2BxD88aqOPBQxuKmDYf5bDCxaabLLMl2HpLEmFnMGmXvO1XDSvRERrnLOVNN1I4EfjMybhVzLzeGq3HrPcv+qB1ZdJha66YGOKTxDd05InsEugZ5l1yw/XM35jdVlxp7+iosQt+89kkI4485LPeaWufBV0he3XU6fjcZggq8zhzCDKptchL+r6Ej4Mut5VlPK/cBoXgTN+P5Y4hKK/8LYElGaYoEH52dzq8CWZSgJx6UUu3ruHzumELxWd4xi2L4vDN/k+x4MqeDn333l2UvUQVV+KXAB8dRWY+8QNQt8rHMaLwjvhiuckB/zd82Y0iYSIjvjkFRtchyRnWLDHxsM4IHrD1xE6ORCapsghzEBu1dFybdZLS0+IrKHr74sz2pYkh1ijmmNwqWan6qKdDi0GXXmg4bbZRd+aDxKD2W6V+xWocY3Tr+9GPXWMDlr X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(346002)(396003)(39860400002)(376002)(366004)(2906002)(6666004)(66556008)(6506007)(36756003)(26005)(66946007)(69590400012)(44832011)(38350700002)(83380400001)(956004)(86362001)(6486002)(16526019)(8676002)(316002)(8936002)(478600001)(6512007)(52116002)(38100700002)(5660300002)(2616005)(186003)(66476007)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: gZr2ZoAJRBY4lZGghKz53HNeQM+EBad8gD9MCIFoX6kTFK1UDo6scRY4c5n5hNliOLkP39q3s9DkkNx9qOus4JTm5d7MRWChuVA8OVT7xFR1UP/GJ4p0hgY5T2Uw294k8j5LLuGmOJp4KC88gjU9xE9ev0372SYYmtZyBkg+OnXKiLZYuv58K2oTC2Re+uvHOdIX9L194yqEN23XKs9GZmBVHC867+7/ztSvuNgMMyG2ahhf2VyX2hZ+Pbth+Y6zSklZ+LfMe998tw44PmQrks0dwfXpU5AKtV1rzhjesvUxkiPJMGmE9J1145C37IPrqBQYNEfGCYjh/gTy+ZQXdruDXe/931vh4ENY+C+tiGjkp34dlG9BHXDgo2e5tYqP50YqK8EMoEUAKmBA9Kr0GzAfCyPPkcDRXV9SLsoeoulmGv43xN38X+Phn2WuCeb+Us0eJ/uBvHoMzol/ViF7oFMy2tvabVvGl/q8wXGlkYzTDWF/kkmOzLsUXwR0lLvn7KDeKxxxUTNMUMGfr7e/yk7KVCILs2W4QOaNrUFFduBGwW61DuVfegEqM/9HTnRuCF59kVvCBZTG+EkjuSViYw/tgUVNG25IVslXdCfM5x7Vh4sGNoffowc6AMuDNXsoNEU7R5iOl4j7jpsTYdmq9XjzSpsyHSOYuR7bSO8/boi18cmAuwQ06wlF6rpshEYyY9TB+eeXY008Nnw+D/qnpND9vatrES+zXDACqUi24m19VooI4qp58cP0QpDA68cuwRwazauqFMY6emqO+108pgDRtxGY2fqy5YmX+uchWkudqAIqjVUe4I7gZp1cYCSiJ9pnNtUDB2xkDsENaW8GpDNpczYXmfUY3YaN/Ls+E49tbr+xiafIuLpMjfBlwN+n3fq5f4mk9oe4Z3w5FHWdyz1KsFuWeS9hFZBhOxKphvcKanBF870uUKGG+4BbXrdUIJrGWpRbcUNdRZ/KqP9ndqe7CQA4xdk0vqvp6wRaMC3cXFULl7hk+ydMi+yxmL7Z8AW3ySzaZVVnm7gXLbfn8qYxCDwG1snKIiKltwRsoue/6KMtQ46gWGjMHJ+Ipy3o8C12YnDaS19p51jhk09GMD1HcvhlJwZbwSDMKtEggQLGzdtIpSb8DKH5gJl6h5PGLdKHOXhuqYlFI+xZ19BdeUPJUrIT+EI39LXLQk6GoxBbRbsTJnvewErhASTjGPXSKYpLr/31GRny+2o7qAXV74g4GDO5qBKTuXdXLmgJ4YvgF2EvckzYq0xKJkdw9TxIvbbjRuY/L0Y4ppUbGGTeb2PwQYj7dK0nplA+LQ1VwOq9qR0PKlMgwzK/HMrzFDaA X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6397 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: feac154d-7ac5-4081-7a68-08d8fe54d93b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +jhlBRxk7ni1txnAq8Rq49oYEMopE39JZhWzsti6voZm4vk6UUezG/3gpiUk1t9Nf0PtqFvednMG5DdgUU1ezYXFhC6rDHJIL+YczgECLavct92tip91xBFX+F3BQ3AYBP3UOYguqCT7gX4zS+o921TeFRV+Jdjnn0kLeMTOrtc+qz5rCVjlS1FjUL276NpcaDCr9V1SCPXTpNbCzBdwq0T7sI0GOZ87xQ40OjUYBJIA/QNM6xE08jQ8n0JXmGjzqG0vWttnDfYn1rT2wYiQ78EBJiJQ61JKhjeYB0Se3xrHe8AxhivCKwnb69/tSN8StsX+8fN0S4HS2ybPv4j5pUlENhzfNurcBl9TkEA2L9KArtWHZVKS5ez1sqh+0wQboURTe0oT9qZGwZxnXzd+PJj/PCt1fZdHJmAfAfIKnCIgt5aYypsB0ZNvl+vUKNNGAVn9LgTgjK7BeAH3qXsD1Qh1EW0VoGV8JwMoHkIXpRPhgjo8vHHx6FQf5vtvVHxVCIHf8U40Im+L67rbcfdWntzFto8noBk81a+Hyf+w6AYgyxWbE/V3dJV9f7+C7FkoVLLpX9GrYTpHGC0rkaTb/NZ2+hUzCLfqZVtc7Axo5/BrQOhWHk1bsIyWR3yS/qYR8ULxiMoJ7ssAteZxTIttwvDE4+z9IJJ/SBP0LMDpEvLJxCPBSGb9dknNir7cNUeq X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(346002)(396003)(376002)(136003)(39860400002)(36840700001)(46966006)(6486002)(82740400003)(356005)(70206006)(26005)(44832011)(6666004)(70586007)(36860700001)(6512007)(8676002)(478600001)(81166007)(82310400003)(316002)(2616005)(2906002)(186003)(956004)(83380400001)(47076005)(86362001)(36756003)(8936002)(6916009)(6506007)(336012)(5660300002)(69590400012)(16526019); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:19:36.9159 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c753614-fe34-4c45-7c33-08d8fe54e07e X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2096 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" DTV setup at thread creation (_dl_allocate_tls_init) is changed to take the dlopen lock, GL(dl_load_lock). Avoiding data races here without locks would require design changes: the map that is accessed for static TLS initialization here may be concurrently freed by dlclose. That use after free may be solved by only locking around static TLS setup or by ensuring dlclose does not free modules with static TLS, however currently every link map with TLS has to be accessed at least to see if it needs static TLS. And even if that's solved, still a lot of atomics would be needed to synchronize DTV related globals without a lock. So fix both bug 19329 and bug 27111 with a lock that prevents DTV setup running concurrently with dlopen or dlclose. _dl_update_slotinfo at TLS access still does not use any locks so CONCURRENCY NOTES are added to explain the synchronization. The early exit from the slotinfo walk when max_modid is reached is not strictly necessary, but does not hurt either. An incorrect acquire load was removed from _dl_resize_dtv: it did not synchronize with any release store or fence and synchronization is now handled separately at thread creation and TLS access time. There are still a number of racy read accesses to globals that will be changed to relaxed MO atomics in a followup patch. This should not introduce regressions compared to existing behaviour and avoid cluttering the main part of the fix. Not all TLS access related data races got fixed here: there are additional races at lazy tlsdesc relocations see bug 27137. Reviewed-by: Adhemerval Zanella --- elf/dl-tls.c | 63 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/elf/dl-tls.c b/elf/dl-tls.c index f8b32b3ecb..33c06782b1 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -471,14 +471,11 @@ extern dtv_t _dl_static_dtv[]; #endif static dtv_t * -_dl_resize_dtv (dtv_t *dtv) +_dl_resize_dtv (dtv_t *dtv, size_t max_modid) { /* Resize the dtv. */ dtv_t *newp; - /* Load GL(dl_tls_max_dtv_idx) atomically since it may be written to by - other threads concurrently. */ - size_t newsize - = atomic_load_acquire (&GL(dl_tls_max_dtv_idx)) + DTV_SURPLUS; + size_t newsize = max_modid + DTV_SURPLUS; size_t oldsize = dtv[-1].counter; if (dtv == GL(dl_initial_dtv)) @@ -524,11 +521,14 @@ _dl_allocate_tls_init (void *result) size_t total = 0; size_t maxgen = 0; + /* Protects global dynamic TLS related state. */ + __rtld_lock_lock_recursive (GL(dl_load_lock)); + /* Check if the current dtv is big enough. */ if (dtv[-1].counter < GL(dl_tls_max_dtv_idx)) { /* Resize the dtv. */ - dtv = _dl_resize_dtv (dtv); + dtv = _dl_resize_dtv (dtv, GL(dl_tls_max_dtv_idx)); /* Install this new dtv in the thread data structures. */ INSTALL_DTV (result, &dtv[-1]); @@ -596,6 +596,7 @@ _dl_allocate_tls_init (void *result) listp = listp->next; assert (listp != NULL); } + __rtld_lock_unlock_recursive (GL(dl_load_lock)); /* The DTV version is up-to-date now. */ dtv[0].counter = maxgen; @@ -730,12 +731,29 @@ _dl_update_slotinfo (unsigned long int req_modid) if (dtv[0].counter < listp->slotinfo[idx].gen) { - /* The generation counter for the slot is higher than what the - current dtv implements. We have to update the whole dtv but - only those entries with a generation counter <= the one for - the entry we need. */ + /* CONCURRENCY NOTES: + + Here the dtv needs to be updated to new_gen generation count. + + This code may be called during TLS access when GL(dl_load_lock) + is not held. In that case the user code has to synchrnize with + dlopen and dlclose calls of relevant modules. A module m is + relevant if the generation of m <= new_gen and dlclose of m is + synchronized: a memory access here happens after the dlopen and + before the dlclose of relevant modules. The dtv entries for + relevant modules need to be updated, other entries can be + arbitrary. + + This e.g. means that the first part of the slotinfo list can be + accessed race free, but the tail may be concurrently extended. + Similarly relevant slotinfo entries can be read race free, but + other entries are racy. However updating a non-relevant dtv + entry does not affect correctness. For a relevant module m, + max_modid >= modid of m. */ size_t new_gen = listp->slotinfo[idx].gen; size_t total = 0; + size_t max_modid = atomic_load_relaxed (&GL(dl_tls_max_dtv_idx)); + assert (max_modid >= req_modid); /* We have to look through the entire dtv slotinfo list. */ listp = GL(dl_tls_dtv_slotinfo_list); @@ -745,12 +763,14 @@ _dl_update_slotinfo (unsigned long int req_modid) { size_t modid = total + cnt; + /* Later entries are not relevant. */ + if (modid > max_modid) + break; + size_t gen = listp->slotinfo[cnt].gen; if (gen > new_gen) - /* This is a slot for a generation younger than the - one we are handling now. It might be incompletely - set up so ignore it. */ + /* Not relevant. */ continue; /* If the entry is older than the current dtv layout we @@ -767,7 +787,7 @@ _dl_update_slotinfo (unsigned long int req_modid) continue; /* Resize the dtv. */ - dtv = _dl_resize_dtv (dtv); + dtv = _dl_resize_dtv (dtv, max_modid); assert (modid <= dtv[-1].counter); @@ -789,8 +809,17 @@ _dl_update_slotinfo (unsigned long int req_modid) } total += listp->len; + if (total > max_modid) + break; + + /* Synchronize with _dl_add_to_slotinfo. Ideally this would + be consume MO since we only need to order the accesses to + the next node after the read of the address and on most + hardware (other than alpha) a normal load would do that + because of the address dependency. */ + listp = atomic_load_acquire (&listp->next); } - while ((listp = listp->next) != NULL); + while (listp != NULL); /* This will be the new maximum generation counter. */ dtv[0].counter = new_gen; @@ -982,7 +1011,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) the first slot. */ assert (idx == 0); - listp = prevp->next = (struct dtv_slotinfo_list *) + listp = (struct dtv_slotinfo_list *) malloc (sizeof (struct dtv_slotinfo_list) + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); if (listp == NULL) @@ -996,6 +1025,8 @@ cannot create TLS data structures")); listp->next = NULL; memset (listp->slotinfo, '\0', TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); + /* Synchronize with _dl_update_slotinfo. */ + atomic_store_release (&prevp->next, listp); } /* Add the information into the slotinfo data structure. */ From patchwork Tue Apr 13 08:19:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465615 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=PMH+YfO0; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJSG0sjNz9sVw for ; Tue, 13 Apr 2021 18:19:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB0913982060; Tue, 13 Apr 2021 08:19:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB0913982060 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301995; bh=2TPN0KmXruJJ/WpJkQcnFnqZiHZIK9zDLTZRCkAbl8I=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PMH+YfO0qpSoXY2iRlsqwWjmWjKyTka2sgwqzMAP6uJZY+ciZAWI2TNHPFCk5ixTC Iuzlidfe4c8jxJQ9vrHDnoaMhVSOwnYzzN/9Q2EbVR/Ije1gsv2tvTxRnw+RgK1FZI VcOmbsxBtEXUL8NLn8oko8V8WY9NzjdBsjvJUG+s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60081.outbound.protection.outlook.com [40.107.6.81]) by sourceware.org (Postfix) with ESMTPS id 75405393C871 for ; Tue, 13 Apr 2021 08:19:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 75405393C871 Received: from AS8PR04CA0013.eurprd04.prod.outlook.com (2603:10a6:20b:310::18) by AM0PR08MB4419.eurprd08.prod.outlook.com (2603:10a6:208:139::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Tue, 13 Apr 2021 08:19:50 +0000 Received: from AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:310:cafe::6c) by AS8PR04CA0013.outlook.office365.com (2603:10a6:20b:310::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:19:50 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT038.mail.protection.outlook.com (10.152.17.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:19:50 +0000 Received: ("Tessian outbound 34291f7cb530:v90"); Tue, 13 Apr 2021 08:19:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b6c630544b3be085 X-CR-MTA-TID: 64aa7808 Received: from 046f3dc888f3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 06A5E244-2A0D-4F68-8257-31BA7C376AF5.1; Tue, 13 Apr 2021 08:19:43 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 046f3dc888f3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:19:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JarGtGggB/GSKypzU/CAkHuTJ0jodLLj2bkVEuvoHr1fgxrNqM8C0vX015EhL9J+ztQKjVeBF2HarK8NdtOfrPUDkdGc5Z7aF3InU8CrHkPck5iGZp8LshwvDXScQp+ok8NdA+A5cI4vGRi2EdfMC0Q6LVEYAdYYsIaTPyw2gS3daFS2n0CxoiJZizEzPizaPu/7XhmAGgBpChX4v/6nC++ip1rqOAjLKIWk3oqC2AcAtDyVd93y5jpdMcuU7LUFRoxhL9o3sRfBmyR88OGA7lyP7ZXE6Q//2Urx5pXOP4S13v3lWtEK6zXbwZ5LTpMOKGO7MDpaUgPLtpL0hno5HA== 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=2TPN0KmXruJJ/WpJkQcnFnqZiHZIK9zDLTZRCkAbl8I=; b=eopT2ascSJ+54NSXAPZIrE1Uw4NLam+zz72uGqP/hVkzFmrXIMxLXzJXcpLBVgJzogWM84k3VKelLdd+GY0Bjyw/Mo7aqh1ls1dYhGbJq82C4WMXcAWwiFEnmtmLkLVamBHx0WvXzALNDPsyCmpC/wJnV9FAVLZpmH+vX57BiIBbgtzOu90LHjQqH81t16hQXBNgTtfSfNQqepqsOkoff6mbqR+5ORtUIg/49rSucTa5VP99FT5Ts7LSb9aMcVliIAC2CXogGOfcuAgTnL1AdW8fx2ek+PYjVXiOH9Qc8Y4aiP7yfBAK5bIZJn4hAfgCSt29K6JpddhTgUcqKjulJQ== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6397.eurprd08.prod.outlook.com (2603:10a6:102:12f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:19:42 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:19:42 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 06/14] elf: Use relaxed atomics for racy accesses [BZ #19329] Date: Tue, 13 Apr 2021 09:19:36 +0100 Message-Id: <10fb15a36b3f6bc3e5ca62cda081c86512f47d32.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO2P265CA0429.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::33) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0429.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22 via Frontend Transport; Tue, 13 Apr 2021 08:19:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d74d91f-4241-4b26-b31e-08d8fe54e84f X-MS-TrafficTypeDiagnostic: PAXPR08MB6397:|AM0PR08MB4419: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: zAw18BgXvK6t5D4Dw07vVVyrIY1Rj/mBJmpbnzErKVJC+1dIT6175TP+kyFICMK4zsZV2Kmmk1TibltKk/uWT4Iof5w91LCvw1XoG4syyWye0fbpVQ2QDIVk6GfwA87pB2IJsmYITZIU2KBzQHYPLZqp3XKJ8e+4DgDhawFLCS10JBmX9x31i+PAV0oS3arhrRRowxb6QZi8Fw8tmb1lSI4/YJQuWV8xQUSGT9U1p8hjggTfVWKQWI3IJq6+nvi+xUEZJEwY+GafE8sheOta+R9G8Hx/gpHkzIZpdB26EzH9KLIwuK9E5xG62sd1xtReLbAZDYCrPvgb3/KjDYFBfA24QOuk+9SaZ71O66OJAOl7HWlgnoC6yfFY5W9y7zw8pppdB5JGxnIBpwfMdf86sxWQYvXqwQ0yx7xQk9FAw9anjrco/I3jukNBOiAV03wKgySJT8oLonoNB2l3qOY0ZRbsqehi2xzO0czuGSzTUM+t0gVRgUZ1wsaSfBXt1SR9bFsG5Cqn/Q9Be6ybppyUBoTt9wibl6T2Yxcr4xtxTweKFyszm31aGh5V4MrDsQ2HyfiZSd/yhPKvQwuU7/RdXFI/loP6FxrEBY8gQhzZFAgbXmxmpWRXXf4i1e74wSHyrKIrMNrxgiRRWk4+fRF8+Vin7O6sKmlg2tMvVTbQlZcM9bphcovuvvdAAbq4WhKS X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(346002)(396003)(39860400002)(376002)(366004)(2906002)(6666004)(66556008)(6506007)(36756003)(26005)(66946007)(69590400012)(44832011)(38350700002)(83380400001)(956004)(86362001)(6486002)(16526019)(8676002)(316002)(8936002)(478600001)(6512007)(52116002)(38100700002)(5660300002)(2616005)(186003)(66476007)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DiXtVoqBjgpEl2NBFGk3LE2t1yp2k9L/LFX4pzAvMXZZojnY+FU9JUheQH742YNUyAyHUHLSKfYNCog2xaH12UR04UBuAQ31a+SEWrYT5GW+PC7zkbnyArIOjKLSKTKWcU1ZvgSPce6iSsAza3MaY0KXQtBm90tynlRvIkDsDggXczQwvNk7PhBmD32ucjEXjOj+zr8giz+laCQpmAmuPDAISyfepbKFbkcvuBvg03hvh+JhSP7FC32prpJV8yjD7ujqoaZ8c+QhjVHkIGfV4ArRel+HL2+SpV3XbrzOrAMXV4/9MTUtPKXbjA2gvNUq75mtlr3GsmQ8kW1VMkDZ1zQRzYfJbj5yevHiOaFlTpy94GTJGlSgBi69aAMPTktyZZr/0PPostut/r28ul7UwVSpjJFoi5QTUUK6CkH5iZztoQZFKgflNBcOblfvM58Usu+6r0yCeDYHixjjXvaBhnmdTpbnbQz1HI/A+kGsH5y6R8lUG3mngViG1J91HjQQ9UJEeTKa30nnMfQ8EIAujMZBtttk+3XAoV+8kBUJT/nsDIcZY2uxQI7nQ4ic60hjx2+xHcuERawwqSbjrSXqczPpTPQlLTlAQVt6NsecNkYz+0LzGRKbtf/No5ru0FttEGTk0ClgAPQA42D0iKWUrU8vIvZJRe5ne/b79jqdtG8LRykL/HRmtukNs4Ys+NG7yOa0ajfyrdAx05SxhH2U/1aQpwPWx11vrU9rHB9vFuli6MaCkznDDDn7PHsWoRUVOGAWZbfbVtbiy/gwx14g7G+Ew80vDT5ahU4vCPc6QNdhobQ5SiJDOCf/RUg/LSPGBzUzrTihVc+LEqJcI6DDVELJ/a181iyXoCU3G1rOCIvCorh4+DCVc6XK1YJ0sSp2QqvmTw4j6VwWWxMmDw7ETFQfZtfGPQg9XxZnUO/+Qaes3Mu7LNXiQJp+EleNI2g0GPlXQuEalOs/t9eoU2h6Q+3S5LE6EG/enkI1yHIEQ8u+frlzIfEnfX3ygbbKGCDWy1hKJdS4F1lYNA4u4KPeq+ZG1koxQpUVarYIJkjSqxjpl0Frp3K5UZdMHQoJ3sRwCSjUPZtD+Hkq6yD1RxWmqkkBbQ9cPY/KxEKEsRUBzOKkanD/thmikzEx8njy0UrwzbEwsrokF7xnPRG8Kgj/pMmsG5xwGtfYTT6wWxD0rk2q/qOt/anHNKOIttUn+g14PaTAfUhOP7CAbJ3d6QV+Oj0mCmBLOsh2U8EIe4UxYse4odfMblr9Nt3v06Qebc1E9T/oeXUpcF95zKFk5k79stLtVSBF/CuXdWS0yI84EMZTPShtGFj5L6c1OtHJUmJI X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6397 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: c5619d48-3abc-481a-b883-08d8fe54e395 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WDQszjidp+cjwzpr45+xrc/xIsZBhc8R6Z8z8FO8xWOxFJ8cbKdTmPwPw12ME3GUICbMZXBC89Lnorw4ZmWjTGLDphHgt7lwQupkYCs3dsB7R2kmYmxAGN+TVfDwUBLHDNnpTYp6ybZVfpjR6d1Pbcg0x3UD2WYuZdB/6woOTCJrCg58gVWN1V5obAqPRqrMzDJfUKU8NFr3U7BviTV2wllDg+ddCW0JD3rFv0O8wSniR9kEdSbKOwKX8qytpr492Mq5uomvy9QrBdddhbcu0L1OtaS+NhuKBaJiuavVoBdOWtsS5iLu6njj7MnzZ3d8xHkZ7MNPaqf5OCUWoX7JxRXcLP+hhrVNYxERR3juOzGs4Hkc/dvA3KGHYviitd1jGSejHlW2ex+qEFAEkRzfgxDuKT1z4xvRUIFoS1O5ergfA7wMlzkpehZHYSQ7O4sKWNQTetK7R73kJAEQ7G+BjGuQN1d6HRBcDoXge90gvdH72IWYMGVHcY4cPu94J1eyS6TTX4C+VjHC4f2Yfg+ZpFXY9RqwknlCvReih+IsVtvGFx3mawOlcBUhMpvfnZ3SpePyQGQdd2DzftPzInBrMc4m2+1ORClcKHsIjPQehkw0QOjW+0FsufH6Emr+x9pMJ7gz42Hl6SW3sfghwrU/2/xcuI1kycuYvmLHhIlAW4sG3qEutjzl+pUI1tKcoDkQ X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39860400002)(46966006)(36840700001)(36756003)(70586007)(82740400003)(47076005)(70206006)(956004)(2616005)(69590400012)(44832011)(8936002)(6486002)(336012)(6916009)(36860700001)(26005)(6666004)(5660300002)(82310400003)(2906002)(356005)(86362001)(316002)(83380400001)(8676002)(186003)(16526019)(6512007)(6506007)(478600001)(81166007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:19:50.0336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d74d91f-4241-4b26-b31e-08d8fe54e84f X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4419 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This is a follow up patch to the fix for bug 19329. This adds relaxed MO atomics to accesses that are racy, but relaxed MO is enough. Reviewed-by: Adhemerval Zanella --- v2: - handle x86_64 dl-tls.c too --- elf/dl-close.c | 20 +++++++++++++------- elf/dl-open.c | 5 ++++- elf/dl-tls.c | 31 +++++++++++++++++++++++-------- sysdeps/x86_64/dl-tls.c | 3 ++- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/elf/dl-close.c b/elf/dl-close.c index c51becd06b..3720e47dd1 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -79,9 +79,10 @@ remove_slotinfo (size_t idx, struct dtv_slotinfo_list *listp, size_t disp, { assert (old_map->l_tls_modid == idx); - /* Mark the entry as unused. */ - listp->slotinfo[idx - disp].gen = GL(dl_tls_generation) + 1; - listp->slotinfo[idx - disp].map = NULL; + /* Mark the entry as unused. These can be read concurrently. */ + atomic_store_relaxed (&listp->slotinfo[idx - disp].gen, + GL(dl_tls_generation) + 1); + atomic_store_relaxed (&listp->slotinfo[idx - disp].map, NULL); } /* If this is not the last currently used entry no need to look @@ -96,8 +97,8 @@ remove_slotinfo (size_t idx, struct dtv_slotinfo_list *listp, size_t disp, if (listp->slotinfo[idx - disp].map != NULL) { - /* Found a new last used index. */ - GL(dl_tls_max_dtv_idx) = idx; + /* Found a new last used index. This can be read concurrently. */ + atomic_store_relaxed (&GL(dl_tls_max_dtv_idx), idx); return true; } } @@ -571,7 +572,9 @@ _dl_close_worker (struct link_map *map, bool force) GL(dl_tls_dtv_slotinfo_list), 0, imap->l_init_called)) /* All dynamically loaded modules with TLS are unloaded. */ - GL(dl_tls_max_dtv_idx) = GL(dl_tls_static_nelem); + /* Can be read concurrently. */ + atomic_store_relaxed (&GL(dl_tls_max_dtv_idx), + GL(dl_tls_static_nelem)); if (imap->l_tls_offset != NO_TLS_OFFSET && imap->l_tls_offset != FORCED_DYNAMIC_TLS_OFFSET) @@ -769,8 +772,11 @@ _dl_close_worker (struct link_map *map, bool force) /* If we removed any object which uses TLS bump the generation counter. */ if (any_tls) { - if (__glibc_unlikely (++GL(dl_tls_generation) == 0)) + size_t newgen = GL(dl_tls_generation) + 1; + if (__glibc_unlikely (newgen == 0)) _dl_fatal_printf ("TLS generation counter wrapped! Please report as described in "REPORT_BUGS_TO".\n"); + /* Can be read concurrently. */ + atomic_store_relaxed (&GL(dl_tls_generation), newgen); if (tls_free_end == GL(dl_tls_static_used)) GL(dl_tls_static_used) = tls_free_start; diff --git a/elf/dl-open.c b/elf/dl-open.c index ab7aaa345e..83b8e96a5c 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -395,9 +395,12 @@ update_tls_slotinfo (struct link_map *new) } } - if (__builtin_expect (++GL(dl_tls_generation) == 0, 0)) + size_t newgen = GL(dl_tls_generation) + 1; + if (__builtin_expect (newgen == 0, 0)) _dl_fatal_printf (N_("\ TLS generation counter wrapped! Please report this.")); + /* Can be read concurrently. */ + atomic_store_relaxed (&GL(dl_tls_generation), newgen); /* We need a second pass for static tls data, because _dl_update_slotinfo must not be run while calls to diff --git a/elf/dl-tls.c b/elf/dl-tls.c index 33c06782b1..c4466bd9fc 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -175,7 +175,9 @@ _dl_next_tls_modid (void) /* No gaps, allocate a new entry. */ nogaps: - result = ++GL(dl_tls_max_dtv_idx); + result = GL(dl_tls_max_dtv_idx) + 1; + /* Can be read concurrently. */ + atomic_store_relaxed (&GL(dl_tls_max_dtv_idx), result); } return result; @@ -359,10 +361,12 @@ allocate_dtv (void *result) dtv_t *dtv; size_t dtv_length; + /* Relaxed MO, because the dtv size is later rechecked, not relied on. */ + size_t max_modid = atomic_load_relaxed (&GL(dl_tls_max_dtv_idx)); /* We allocate a few more elements in the dtv than are needed for the initial set of modules. This should avoid in most cases expansions of the dtv. */ - dtv_length = GL(dl_tls_max_dtv_idx) + DTV_SURPLUS; + dtv_length = max_modid + DTV_SURPLUS; dtv = calloc (dtv_length + 2, sizeof (dtv_t)); if (dtv != NULL) { @@ -767,7 +771,7 @@ _dl_update_slotinfo (unsigned long int req_modid) if (modid > max_modid) break; - size_t gen = listp->slotinfo[cnt].gen; + size_t gen = atomic_load_relaxed (&listp->slotinfo[cnt].gen); if (gen > new_gen) /* Not relevant. */ @@ -779,7 +783,8 @@ _dl_update_slotinfo (unsigned long int req_modid) continue; /* If there is no map this means the entry is empty. */ - struct link_map *map = listp->slotinfo[cnt].map; + struct link_map *map + = atomic_load_relaxed (&listp->slotinfo[cnt].map); /* Check whether the current dtv array is large enough. */ if (dtv[-1].counter < modid) { @@ -923,7 +928,12 @@ __tls_get_addr (GET_ADDR_ARGS) { dtv_t *dtv = THREAD_DTV (); - if (__glibc_unlikely (dtv[0].counter != GL(dl_tls_generation))) + /* Update is needed if dtv[0].counter < the generation of the accessed + module. The global generation counter is used here as it is easier + to check. Synchronization for the relaxed MO access is guaranteed + by user code, see CONCURRENCY NOTES in _dl_update_slotinfo. */ + size_t gen = atomic_load_relaxed (&GL(dl_tls_generation)); + if (__glibc_unlikely (dtv[0].counter != gen)) return update_get_addr (GET_ADDR_PARAM); void *p = dtv[GET_ADDR_MODULE].pointer.val; @@ -946,7 +956,10 @@ _dl_tls_get_addr_soft (struct link_map *l) return NULL; dtv_t *dtv = THREAD_DTV (); - if (__glibc_unlikely (dtv[0].counter != GL(dl_tls_generation))) + /* This may be called without holding the GL(dl_load_lock). Reading + arbitrary gen value is fine since this is best effort code. */ + size_t gen = atomic_load_relaxed (&GL(dl_tls_generation)); + if (__glibc_unlikely (dtv[0].counter != gen)) { /* This thread's DTV is not completely current, but it might already cover this module. */ @@ -1032,7 +1045,9 @@ cannot create TLS data structures")); /* Add the information into the slotinfo data structure. */ if (do_add) { - listp->slotinfo[idx].map = l; - listp->slotinfo[idx].gen = GL(dl_tls_generation) + 1; + /* Can be read concurrently. See _dl_update_slotinfo. */ + atomic_store_relaxed (&listp->slotinfo[idx].map, l); + atomic_store_relaxed (&listp->slotinfo[idx].gen, + GL(dl_tls_generation) + 1); } } diff --git a/sysdeps/x86_64/dl-tls.c b/sysdeps/x86_64/dl-tls.c index 6595f6615b..24ef560b71 100644 --- a/sysdeps/x86_64/dl-tls.c +++ b/sysdeps/x86_64/dl-tls.c @@ -40,7 +40,8 @@ __tls_get_addr_slow (GET_ADDR_ARGS) { dtv_t *dtv = THREAD_DTV (); - if (__glibc_unlikely (dtv[0].counter != GL(dl_tls_generation))) + size_t gen = atomic_load_relaxed (&GL(dl_tls_generation)); + if (__glibc_unlikely (dtv[0].counter != gen)) return update_get_addr (GET_ADDR_PARAM); return tls_get_addr_tail (GET_ADDR_PARAM, dtv, NULL); From patchwork Tue Apr 13 08:19:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465616 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=FVXVaMsk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJSd5lc6z9sVw for ; Tue, 13 Apr 2021 18:20:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CC49396B43D; Tue, 13 Apr 2021 08:20:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CC49396B43D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302015; bh=+hAJIilJv7lJzGjNZ6P7Ot4R+4e6dQmo0ydTsjyMWy4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FVXVaMskbpJ5VIW91COJiNDWFmanp18743bhLC6kkWN3gCACaKm7unSMCUGMNdSUN +YCZxe7CxlF/rfYepEEe8wE9N9QMjmkyGuO36M3FEXrtI98i6QrNsLI20kXcvRF5wk CMr69fS0HmCHVI7q63sEZgJA8xBLJzfViC9kQVdw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70071.outbound.protection.outlook.com [40.107.7.71]) by sourceware.org (Postfix) with ESMTPS id DD0BE393D013 for ; Tue, 13 Apr 2021 08:20:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DD0BE393D013 Received: from DB6PR0301CA0022.eurprd03.prod.outlook.com (2603:10a6:4:3e::32) by AS8PR08MB7174.eurprd08.prod.outlook.com (2603:10a6:20b:405::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Tue, 13 Apr 2021 08:20:08 +0000 Received: from DB5EUR03FT042.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:3e:cafe::90) by DB6PR0301CA0022.outlook.office365.com (2603:10a6:4:3e::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:20:07 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT042.mail.protection.outlook.com (10.152.21.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:20:07 +0000 Received: ("Tessian outbound 81a4524e9a48:v90"); Tue, 13 Apr 2021 08:20:07 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: dc94578adc998d08 X-CR-MTA-TID: 64aa7808 Received: from 8a6d11150931.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 02F2EFF3-C5D3-4F03-844B-618AFCC1C24F.1; Tue, 13 Apr 2021 08:20:01 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8a6d11150931.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:20:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qi9NMMx0+728fD1x+0JtLv5W4/nLyCW306FKTs+9IB2jPo9mZIB4avyhTxJVv0z5BR02Lmh1eu2dXLOaI/opBef9/kHridHNpfoyVSBosI3RBAtpcktxTYwdFsDEHNfCnD6BdLY5K+4QOrQYACZR5gWewc66I51QgUI+cTsQ8Ex0MQPJ2sT6hxiDpzpk0IQHtKjHdKg9lFhTI1YyfIywGmJp1ddu/oHU2/pPSXJnwJVXMnO6XEs1L086KJe8a+tPUnADvMdAWyhVhb4PKMp20TtpW6VFIEDczHXw21bayezTL1RKr6vj/SMIgunNyyl66QS4PoQRp+PWJ4OE0wn8Ug== 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=+hAJIilJv7lJzGjNZ6P7Ot4R+4e6dQmo0ydTsjyMWy4=; b=S7gUEI7WPaRUHF61X150+tm7N4qgrO2t+PQ6/L1aHunccfSchmCtxK2ztpxdR1jLCP4gYfuD547JvcVQmBSHpf1u6A/38TsBoNg0HcD6BHv5rNbDY02x4co0hFiY/yHQuYg7AAWTtvzlMssLQYzF+x3Tx5ZJy/W1Tg7DGAergu1vltdxL5tlJunuvPTyK1q7g3PIP4RHWCsv48bTqTESKpejFmu32ePD3QB0lCvmPXEiP7M7QA1do7ZDohRQ9V6LffyU7N59GkNc53+HD2yERn5Oy/HQZvElykMzeZ0ptKLnYfwStC6tPL/zwdEvKMjw8YfS/zTLkqO5ECwhnNG6fA== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6558.eurprd08.prod.outlook.com (2603:10a6:102:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:20:00 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:20:00 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 07/14] elf: Add test case for [BZ #19329] Date: Tue, 13 Apr 2021 09:19:53 +0100 Message-Id: <8df69dbc6cc31456a99ef4165fd0eeffc4de4678.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO2P123CA0045.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::33) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P123CA0045.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:20:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: efa29634-70fc-4b56-5d08-08d8fe54f2d0 X-MS-TrafficTypeDiagnostic: PAXPR08MB6558:|AS8PR08MB7174: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: XRfIQU3OSMypPfXkPSELFUxtv4mqCHwVLy/sXQE6bnwMezf3wcWZEs71WR5woR+VRUf9DALFGgRfIvF10Fl1tvMU9rELaIDjawsOkLGLWfZ6rYXC6NH2BJi5rF2FRGTUh10ewh9DJwPbgOOnz7LuogC/A1vdLGIkV/TqZxW5uCihOAOFZalAL+ZMiNduEyt+Wi7urrFTLwXdiRauzN6zFV3sBpwY4l0nXXIrc7t4wZlgg8SK/1G9SxKd75Y5Kc51yO2MwvVRXeCfkuXWLEXWi1KUIrvOk9EhzqyoV85bXEpeNtTHnm5Od/6DW5DZj2UW0Z+euJK4tclfbiTNiEFCHPsfCF5RcXm8trxLizmEbYTyEkLPoU0JSaBp/9KGLVuDh0En2tZrQH6iX3yYU52NCaaHYJRYkI4KIcPsMXK1BhRy0PqsxTrORQwKvCFr5tyDG6HUUxX0zaiRulviY129xYC5NaGpLy7TO3+t6PohUsFP/xW0Zj6G7SMqbr9Rl1hC75mhMTwWFnKN02ml7lOLzmh9+s5w0vAJmR1RI9CS0QCWlvWDluK+8Tuhj3r6vZM+WPJQQdILU8DoxJ4wqTdk6Imw5amsPtfWsq+sxwhu29QAj1WllLqU1dPifUDD6SYZzlhJl8ajKnX0hmCzftr+z5PXHQjctT0+8fWgJUS862KodIr04rf1cIMOV0jjliIHGKMdL1X7uJ1002Pr9yqalDydsfc1t+b8I3HxVWsiNEZWGOzSDijnPeloNtAF5dLgOJl0o03MsXJgx+zyRNsL3vtrhcNqdI5rKQKrxBgMpzQ= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(26005)(69590400012)(66556008)(44832011)(316002)(66476007)(6512007)(16526019)(38100700002)(8676002)(66946007)(38350700002)(52116002)(186003)(478600001)(2616005)(86362001)(2906002)(6666004)(5660300002)(6486002)(956004)(6506007)(6916009)(83380400001)(36756003)(8936002)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: IG7nB3PzhCGmQujif5P4i3L3Dh8glnvCa7K8tqI6e3wVJYDvsnxkFQ6gBiItX1g0ZWfbbMVARQTTdXhBbBLIRc34/nhZOEiEEjiKQhgbmI+erACUv35D/0rYwB6Elbi+PXrL6Ma6c5WgI7roVxBXuC2N1CcEmM8oNml07FuzS2CvEk2JasXn7Io6BO/lwWno0OKsld5ooJ1QRp6y6nmNOGSi66p4O/f4LIJWVSmc4dfTJkpoAY6Y8ba/dj3pWJwk82DMf8vQ2RNabeg2QRlZD2UdV4sSpsOxufJQwvApAFvYjpN11UOn3Rtoyt6Uei0GhQOU8FD+SpD/8pRjEfs83fop0CoQp+KxtPnrSYIE9IHgZ2MvJYYjXrvhv1djhc0H2N1tweE1MURxzNtS/H5dGx7eJsLlLaUoQ0032yo6RUtodQnkhcFyObycnBq3BSsKYC0qlmGB42/nP7VlnlBBGF+Qlcysk9a6R1sNKSnahIOVSj6kp92Ex9i/mScA8RYahSUeEZ3j9uueNs2PqP66QN/W9DakRtxfDGRwdaqrmyARWHWWTwawH/NOqGeoDeFAqOgDQQdDV4r0duZv+/lSoaLHh/L0BEfEPZWGVaBtHkRXJ2c3L51xNZkRBtb4QDUAmBVwi00WL3muMR+pYL8vLMIaeUaXcmuEVW8/Uf2JMon/ffLs1AB3Qyjc1bRzUfWMg2fjQ4aB9wghft9Tx2OJSX0EptPv43tBFHHrKCgHLbQdAahvYkRdGAuhDVFaG+jjfgueuBwZjV0ILOBIJZNE74UmNHLzgkDznlekerUBzYtOxqZgS3PTM/rgPutx4Dy1p95tFNXrzOORS9bxTqUARnFiPT1VkfzX2mg/rmnfH1qZCWfBHZQStMX6zvVkxM/8PnBSJcsNcyK54VQGMOqhN4OTx1gbRs74kHkJpSlwumgnetbbOpBelS2ji9FxQrK32t2HB3HT255vFevGY0uHasqbjPfUUwMxxif9KI9UNtpdpCk5m4NHhfLHJhYkYx36cvyDvQeGkvurejua4H8/cyYdI0W0/3HwX+tfGw0jyVd8SvGaHYBh8ctiqBaEZGAkDfB5FQAu2dysItvo8IvaCS1BhcIZTXB2QuJBDtraZVlaUdapGanN2fPaFdrMOdM4Iz0usuBCEMpZ4lx95amSSWxz5PftQImkzQfUGoB9zqZT2yzVpTrpptrA1xxEmjgABw5eX1RudjHYCiPH6b2tLt/VLNKOW08PJUbPYH6tX/VCe8HgTFo5MqiMY+uFdmyyJJodd2HAYw/QeW8O9OeJ433OeKkotk7O/uZZ+nD1O0zYERGjVwLoztmD1AlZHocB X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6558 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT042.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ffb5ea80-3345-43b1-7b89-08d8fe54ee4c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N9ciFbXxQ7WOtVgZPA4rQlEsNFXPnGjLQdcFCOtHWtTyOqSX3EGn7w+Tch/HKUjVPPE6sCTQQ4yg47dP/M+4sAbW556st8FccHuxVNijzwc4LTbq631Wi+ge7UxiY+nTV3oyLUhivo1ju3o3GbLs3GmrmMcFLD0nnSsFe0WAOLLJ0InGg+ut5taYdh6wxV/og9ZG+m9viC9WFShmgzZgWm6oyxlnU2xFaz1PHf9T1t/Hc7AVbcTk50pmDBcu+OqCIVdQPgXxN9P1pd9W0xpP6MHQnRiW0mmXRd9tY8VTHRLGIxq38vBSXQbjV+NTwRaK/epidMLV3ynuPvorVBFvn7/WwvsZ5aUt6sEBbfPXi1v9PKzdwkkJ1VCzVG+MdkxXS00QXNE0sYNJIvxk3/v5Q644LAAW/6nX+pibgKB/UK6URrz0oYdpfpVx0Nh2gHkBhUgzUz/VRHvKL2JHhxAkAHdw5WRT1mtmfKTidEmE/qAwCwh77hQ1fatAPhONPCEy44lf77zXAMpaLH44wgjb4LqLOTRBq/lbmAPIuJzWuqej+6sUXWsszlEmTzK5pJlRYtNHXJnRPJRkK8ekN0tQ8jOgz6cSAFOf6Zk++BPikUB8hkh2Nqk00t5gf+Rw8sfJIle/OPKJTWTOHFruayrkgTvKAgzBWhgGl97Dl0ssZxovSdt0CJyuf3+wRBFtKPD31ffrBEOR0JwZVaqD7GlRapTJWSkb9x3+VsJMquFiHjYvk5QO+OXxBTeIS+iR85VHHzdcgxqehddpx3OH/0xuO5jVIeUAgKb6tFrFTDwRlMo= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39860400002)(46966006)(36840700001)(356005)(82310400003)(6666004)(16526019)(6512007)(44832011)(36860700001)(186003)(316002)(70586007)(69590400012)(5660300002)(2616005)(956004)(6486002)(336012)(8676002)(81166007)(36756003)(26005)(47076005)(478600001)(8936002)(6916009)(83380400001)(82740400003)(70206006)(2906002)(86362001)(6506007)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:20:07.7304 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: efa29634-70fc-4b56-5d08-08d8fe54f2d0 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT042.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7174 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Test concurrent dlopen and pthread_create when the loaded modules have TLS. This triggers dl-tls assertion failures more reliably than the nptl/tst-stack4 test. The dlopened module has 100 DT_NEEDED dependencies with TLS, they were reused from an existing TLS test. The number of created threads during dlopen depends on filesystem speed and hardware, but at most 3 threads are alive at a time to limit resource usage. Reviewed-by: Adhemerval Zanella --- v5: - moved from nptl/ to elf/ - use many tls modules from another test (affects the timing a bit as these need more relocation processing, but still detects the race) - use xdlopen - use stdatomic.h - moved from tests-internal back to tests - use acq/rel atomics instead of relaxed, this works too and cleaner. - moved after bug fix patch. v4: - rebased, updated copyright year. - moved to tests-internal because of v3: - use the new test support code. - better Makefile usage so modules are cleaned properly. v2: - undef NDEBUG. - join nop threads so at most 3 threads exist at a time. - remove stack size setting (resource usage is no longer a concern). - stop creating threads after dlopen observably finished. - print the number of threads created for debugging. --- elf/Makefile | 9 ++++-- elf/tst-tls21.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ elf/tst-tls21mod.c | 1 + 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 elf/tst-tls21.c create mode 100644 elf/tst-tls21mod.c diff --git a/elf/Makefile b/elf/Makefile index b1344f1133..e9377608eb 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -223,7 +223,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-single_threaded tst-single_threaded-pthread \ tst-tls-ie tst-tls-ie-dlmopen argv0test \ tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ - tst-tls20 + tst-tls20 tst-tls21 # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -345,7 +345,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ libmarkermod2-1 libmarkermod2-2 \ libmarkermod3-1 libmarkermod3-2 libmarkermod3-3 \ libmarkermod4-1 libmarkermod4-2 libmarkermod4-3 libmarkermod4-4 \ - tst-tls20mod-bad + tst-tls20mod-bad tst-tls21mod # Most modules build with _ISOMAC defined, but those filtered out # depend on internal headers. @@ -1932,3 +1932,8 @@ tst-tls20mod-bad.so-no-z-defs = yes $(objpfx)tst-tls20: $(libdl) $(shared-thread-library) $(objpfx)tst-tls20.out: $(objpfx)tst-tls20mod-bad.so \ $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so) + +# Reuses tst-tls-many-dynamic-modules +$(objpfx)tst-tls21: $(libdl) $(shared-thread-library) +$(objpfx)tst-tls21.out: $(objpfx)tst-tls21mod.so +$(objpfx)tst-tls21mod.so: $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so) diff --git a/elf/tst-tls21.c b/elf/tst-tls21.c new file mode 100644 index 0000000000..560bf5813a --- /dev/null +++ b/elf/tst-tls21.c @@ -0,0 +1,68 @@ +/* Test concurrent dlopen and pthread_create: BZ 19329. + Copyright (C) 2021 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 +#include +#include +#include +#include +#include + +#define THREADS 10000 + +static atomic_int done; + +static void * +start (void *a) +{ + /* Load a module with many dependencies that each have TLS. */ + xdlopen ("tst-tls21mod.so", RTLD_LAZY); + atomic_store_explicit (&done, 1, memory_order_release); + return 0; +} + +static void * +nop (void *a) +{ + return 0; +} + +static int +do_test (void) +{ + pthread_t t1, t2; + int i; + + /* Load a module with lots of dependencies and TLS. */ + t1 = xpthread_create (0, start, 0); + + /* Concurrently create lots of threads until dlopen is observably done. */ + for (i = 0; i < THREADS; i++) + { + if (atomic_load_explicit (&done, memory_order_acquire) != 0) + break; + t2 = xpthread_create (0, nop, 0); + xpthread_join (t2); + } + + xpthread_join (t1); + printf ("threads created during dlopen: %d\n", i); + return 0; +} + +#include diff --git a/elf/tst-tls21mod.c b/elf/tst-tls21mod.c new file mode 100644 index 0000000000..206ece4fb3 --- /dev/null +++ b/elf/tst-tls21mod.c @@ -0,0 +1 @@ +int __thread x; From patchwork Tue Apr 13 08:20:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465618 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ctglwbYm; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJT06V39z9sVw for ; Tue, 13 Apr 2021 18:20:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 205A43982077; Tue, 13 Apr 2021 08:20:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 205A43982077 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302034; bh=xI4HhTiZQSuBUv2nCDJliLR3jzjqJlrPMoxOoThSUCE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ctglwbYmhT8kbByKQWc17Nf3VpDL6suIAn1rdxY+gXYhMPE2HkjsfNuMH00oSjArQ DQPO48c/hEtWa4YTpV5ZyAKgkPcYDelawxDER/b/uFBT4HrqzkU/bmCAcCpV+iUVr0 QIzIohS7H8Nbnuxzac9qh8w9oieJauQuvWcMT8p8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2044.outbound.protection.outlook.com [40.107.20.44]) by sourceware.org (Postfix) with ESMTPS id 45D22393D013 for ; Tue, 13 Apr 2021 08:20:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 45D22393D013 Received: from DB6PR1001CA0024.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:b7::34) by AM4PR08MB2897.eurprd08.prod.outlook.com (2603:10a6:205:a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:20:25 +0000 Received: from DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:b7:cafe::7a) by DB6PR1001CA0024.outlook.office365.com (2603:10a6:4:b7::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:20:25 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT044.mail.protection.outlook.com (10.152.21.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:20:25 +0000 Received: ("Tessian outbound 82c2d58b350b:v90"); Tue, 13 Apr 2021 08:20:25 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 23ae5e034a2130af X-CR-MTA-TID: 64aa7808 Received: from cc48a6b18337.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 14FC7FCE-B1C7-48DF-A54E-13EEFB350900.1; Tue, 13 Apr 2021 08:20:18 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cc48a6b18337.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:20:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=StkWBkf3SOH66+zLXzadyMcfwLALbUTZZqkrTY4IOBW0s1noyf3RBpEWmvYVz6A/tOgjRnxM7hu5D9zrPsWwmkoCyXnWFTFXvRrjrqpMxzDV2MYYbhyHBb32tGbq8rrg90uFfx5ZXV0djfJoydUrE1u0F/jo8iL3jaloiagddBOsVzW7vziQk7XAyJdcdGditTZ81aRn7BVUum0LRa1wL6/ZfBgtBvdvw4knWEKv9a6dfiNwtjbnZGy0oVFhbShOJjuKL6bly8ZZ9EXsTuzA3PdGKDQzEG2j9w0kkKGgEGCOvz+TsMxPp6F7Yhy/Yll/v8KzKTTAw4gLaVzehXYpTQ== 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=xI4HhTiZQSuBUv2nCDJliLR3jzjqJlrPMoxOoThSUCE=; b=ApvvDNTQqabI3y68/pPggvpL666SrgcLCHm+FqZNd/xoKzTSjwqojfv1LMJYopBaaI2iv5XtEvB+S+E+LyrxXTr8cFA6NwsRXNBkX35osEif91eGXE+9E+i1vIvGfTUoJkTEZpKxB7RXMT2IXj117s6hBnjmn5XQj9Jlls0c12GDqL3wwYixb30j34aVvGbxqf+grUu+6lf2ZrsRyKITCNcthhr0uytf3YrHM/MbcgOiltkxW/lyiCL10heYdLETIpNyTQZC2P8iaI69UvJqhtAojle7039k9K6xxHiv/Ogkiy57mxuaUx3u3BkHorQKkhY8Lsezd/Ll6fKTrAWebA== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6558.eurprd08.prod.outlook.com (2603:10a6:102:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:20:17 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:20:17 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 08/14] elf: Fix DTV gap reuse logic [BZ #27135] Date: Tue, 13 Apr 2021 09:20:11 +0100 Message-Id: <299d28c6695cd2e76f222b0d36b17b7124c549e7.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO3P123CA0008.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::13) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO3P123CA0008.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22 via Frontend Transport; Tue, 13 Apr 2021 08:20:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cebfd47c-76fe-451a-3e70-08d8fe54fd66 X-MS-TrafficTypeDiagnostic: PAXPR08MB6558:|AM4PR08MB2897: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 4o1YxE5SoE4UQtMNDeQ1dmdEGL63Wgkik3yUxRH+SvjxUqZPqqHXMOkcSIhY5CtPt4RGOz9r1HRF2DH/ybVi4joLZ1a523jIoDc8Qj4WG9zfaVqLsSlCF94OVfUPju2ZUG0EZP/XYh+XrY/e9xQUJxjNvbDjpDOBChLq90GYa8W6dlUr/9APLa2pe4W7U5Dq/g1YwYjs3+Idlq274AvHhmCyzS91KTcezsEl6IPdbGQ2qcUDKQmN7ouxyDV2NtfkhtXE5ZKZdNdqTAOt+dhusCbn3uagyzn7hjoA7CRxE8ZB2J+/FHbPDkppx+tGgHia8TPo6TH2HomWJbjS7TdpR2SkN8PnrICUmK4TQw0Jot5f/i4dmzBpMMw+Gadpu1NzBhzGR0f7QzqOsd2P3bsik6AXs4RG2vSEPs5dyT53YXn4isQ8QZxffFt35lHrNsrmOvRdwietqS+IOd8QBhgQ6Do/D8uVKi/XfciafozuNvLaxJD9JtlDFP1MZZQHrX0dR3GxlIWTQ68VUgvAxUSKufyivZpASFNIIkvqd58+g4Jh2Pw6p67kBk+8zwUfy3bmPAQfp1wvPUMD2TzGdgJTetMu/mSQuna5pNHIyJUt83VDVvJQnYzgvi5ddTj/kn+KuafJzP+W2PJWtCE+qS2yVuoPgMHvkeymfNxHy+VH7KTlwzj4omw4CemrAWCm8ljr X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(26005)(69590400012)(66556008)(44832011)(316002)(66476007)(6512007)(16526019)(38100700002)(8676002)(66946007)(38350700002)(52116002)(186003)(478600001)(2616005)(86362001)(2906002)(6666004)(5660300002)(6486002)(956004)(6506007)(6916009)(83380400001)(36756003)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: aybMPtzdEkjMOg+DcMiEGvD10bauslOWxp+sLMwD+L70UGH4EAGNPzcyKqV9+ahiSMCggqbT8RHmBjn5g3UVYW9hAtfz+crlDu5dFgogbgVGJ7y5pOicZrlQJeUYQD3vG61AC99hL07PyCPXM9touExlpj/6d33ToSUTK4h/CRgWDUye5iR9fF/IWN6OLFUvwnnHHNvDuh4/22WNNlJlH1C536nlP5y56fC/ay3ixoFEHyly4qT02C0PApBhjH8AcOlMhNkE8qWJ5YjUhGi81FOOsj1UVAjbOde+NZOQJ+VBHqy5PlQO8nsSy8dKZp1VcC+WZ3ZBxBZkmvx57ETlClU3d6hokts810yHGK6QCyJd41h8ALque8xwTbWPcIWYNl6HUbJbEDCySvQUUd17nxlUsIIjudd2XFCnaUCChtAFnEFu76fVqvIprBEfYe5rPjxoakOvtYrgEovuXo0Rv+/NRF92YReekoVOn100I7Y1r8iOHlTVyVLzfeOFR517hBvTM1q783caYvL2HgVYSjRuMXDUYXClLe3NCXi67UmP/7V5HhjxgtlkOJa+oFmleT6JJQ79qRoSnz3YwueMyRgUD9cMBUWBGWmemfhoIlQ2wWVwm4Y0AZRHa6O0T4m1iPnuauFYNGu7exT5JPa3D6yGYfFjW+x5Y/wsAY+uW7lsGoB4SDXUm+FHDWzDkEcYERFLVtlljuGUN0hmsFsUuA9cIVjVGC2SCPFDPaCpgF88KS4/gVsOKtvfR2jJFEtyyMhrlUzgyogFL/LiOeRINUvMh553f+fq6akBtbu8bl3iImuM7/ma4NKUJ/MR1yjZzBmQEQKxGImByDdiZPj9s7CL2uf4+j0siYHc1u3FnvfZgCfbWHwi3FVudGQldktb0XCR2bIfSmAmsARCXboHXrhcPtI+u2nDWkdtecMjXAg74j739mhkKx5nZuO8X7iF69ZDsS0Z8V0vnRa7ccc3ayiMBnTfYPBOjmnAOZge/P9O3nrm/xVqAkwe0vsxxunLRJlgBTuDqDRCUot6V1LXYwe10YLFNlyiui0H9MgimtTk97tKKLtqtV0TkjQ5LTHDqkMOmFUN2zFTFV5g68TydXd1ONsQypcz0jtIhpgwNEHp/MBuJvDIPFhBfky+28jiJGEhq7rQJz5gP2K3eRWJcnQbEOyT5GYWq2LPIXLTctPc5MFjoW4CEM+AtjduHUYN6iDrQbXM0nTL4RK0kdFKRibuAhAnEGpvrjANaOTv39dJ9e7235yI7bg593Otzbxy8jggOYxJ99D4C+HmfTPRecUkLvoOuIs7jR7XMPWCIcmxYNY9TAdJnDTUAkLbweCk X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6558 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 2dcf3b79-8114-4beb-0e05-08d8fe54f84a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sD7/7f1a+TiN3mOHkEoIo4h5IDjMGIwrki+avKm06OhKE0Tf7CJEaZizrUtQCSbaoICx7MKv0HmXrkPMk3zbSlkSr8vnF6ZlplIHJe+Nr9/uej9d6VVOQdU8xOGDO0ybEBA6gLflfBXLySTQd8Rvwk5NBc/XhCWNA+d535xn3CX/3+He0jIxNn+LPPRTJx8QsL8JLBAR1wbp6XDJfwi3Dh6HIgklYind1gEclEn5XMGdiZneJp1cRHRD9LKDoexwx+I/DdZfXtRqWL4/Z0E7LCoaFNXNhFsULx3t/6nvfVAiobvihK/7J5OLAN7/d1AT0H1RWafpc/mUdF46XImNBFv1xMDZ/zqBg1zwfhp7Y2vQHbu6yQRLrE2r6AQi2f+m1hNJdRrMvSm3aXsSAz2g9lVeOa4sNI/xgWSRlumi+ACuwe3ZK0I71vA6bQa75+C5dp16c4yFCK6bdxV4i5Yv8iRZc1wyXbzw9Z/EynSA61aehK+/KtptRmsm5YDWLv8J9IO4NiLh/GVZjn5ted04vmXfnt5shHd3UCAceIhmdaN6MrCH209MdMDCdKXlHmAnJtmRwzeK+pJOShzjWcDrGqzm9acJP462ecMrnTTc1gsbP4y0wmh6lB8Bkdo3sktks9drTKCAXNAx8yVyUvGBXkJ4RipuqELyPx17NUFp8/x5gOKcYBhR/HbCPcc15Tnd X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(376002)(346002)(39860400002)(396003)(46966006)(36840700001)(82740400003)(6512007)(86362001)(69590400012)(6506007)(70206006)(478600001)(316002)(2906002)(83380400001)(6486002)(956004)(26005)(36860700001)(5660300002)(2616005)(36756003)(47076005)(186003)(336012)(70586007)(356005)(81166007)(82310400003)(44832011)(16526019)(8676002)(8936002)(6666004)(6916009); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:20:25.4899 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cebfd47c-76fe-451a-3e70-08d8fe54fd66 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2897 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" For some reason only dlopen failure caused dtv gaps to be reused. It is possible that the intent was to never reuse modids for a different module, but after dlopen failure all gaps are reused not just the ones caused by the unfinished dlopened. So the code has to handle reused modids already which seems to work, however the data races at thread creation and tls access (see bug 19329 and bug 27111) may be more severe if slots are reused so this is scheduled after those fixes. I think fixing the races are not simpler if reuse is disallowed and reuse has other benefits, so set GL(dl_tls_dtv_gaps) whenever entries are removed from the middle of the slotinfo list. The value does not have to be correct: incorrect true value causes the next modid query to do a slotinfo walk, incorrect false will leave gaps and new entries are added at the end. Fixes bug 27135. Reviewed-by: Adhemerval Zanella --- elf/dl-close.c | 6 +++++- elf/dl-open.c | 10 ---------- elf/dl-tls.c | 5 +---- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/elf/dl-close.c b/elf/dl-close.c index 3720e47dd1..9f31532f41 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -88,7 +88,11 @@ remove_slotinfo (size_t idx, struct dtv_slotinfo_list *listp, size_t disp, /* If this is not the last currently used entry no need to look further. */ if (idx != GL(dl_tls_max_dtv_idx)) - return true; + { + /* There is an unused dtv entry in the middle. */ + GL(dl_tls_dtv_gaps) = true; + return true; + } } while (idx - disp > (disp == 0 ? 1 + GL(dl_tls_static_nelem) : 0)) diff --git a/elf/dl-open.c b/elf/dl-open.c index 83b8e96a5c..661f26977e 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -890,16 +890,6 @@ no more namespaces available for dlmopen()")); state if relocation failed, for example. */ if (args.map) { - /* Maybe some of the modules which were loaded use TLS. - Since it will be removed in the following _dl_close call - we have to mark the dtv array as having gaps to fill the - holes. This is a pessimistic assumption which won't hurt - if not true. There is no need to do this when we are - loading the auditing DSOs since TLS has not yet been set - up. */ - if ((mode & __RTLD_AUDIT) == 0) - GL(dl_tls_dtv_gaps) = true; - _dl_close_worker (args.map, true); /* All l_nodelete_pending objects should have been deleted diff --git a/elf/dl-tls.c b/elf/dl-tls.c index c4466bd9fc..b0257185e9 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -187,10 +187,7 @@ _dl_next_tls_modid (void) size_t _dl_count_modids (void) { - /* It is rare that we have gaps; see elf/dl-open.c (_dl_open) where - we fail to load a module and unload it leaving a gap. If we don't - have gaps then the number of modids is the current maximum so - return that. */ + /* The count is the max unless dlclose or failed dlopen created gaps. */ if (__glibc_likely (!GL(dl_tls_dtv_gaps))) return GL(dl_tls_max_dtv_idx); From patchwork Tue Apr 13 08:20:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465619 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=xA69FDoe; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJTF26nqz9sW8 for ; Tue, 13 Apr 2021 18:20:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF4D4398207C; Tue, 13 Apr 2021 08:20:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF4D4398207C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302046; bh=1vbxFpX+Wlte94xTBQS85D9po3/Z7KtywUaqWDrUi4M=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xA69FDoejh3VOJ/VckEKA2LTE6uAtDzjFJMtHn/TU1b7zuqwbc1RaQAMdQ9oRDfJf /8plnAyFtPCoMY1dCNggh1+PXUEfhBlLQY9QcmSRnuAFH5izhjC3LbJ65vFU3zvMQu iDSSPR5HfviA6E4/2he00z6yN77sQ11b9s5EzuCY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70040.outbound.protection.outlook.com [40.107.7.40]) by sourceware.org (Postfix) with ESMTPS id 0448D393D013 for ; Tue, 13 Apr 2021 08:20:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0448D393D013 Received: from DB8PR06CA0040.eurprd06.prod.outlook.com (2603:10a6:10:120::14) by AM5PR0801MB2099.eurprd08.prod.outlook.com (2603:10a6:203:4d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:20:41 +0000 Received: from DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:120:cafe::b4) by DB8PR06CA0040.outlook.office365.com (2603:10a6:10:120::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18 via Frontend Transport; Tue, 13 Apr 2021 08:20:41 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT043.mail.protection.outlook.com (10.152.20.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:20:41 +0000 Received: ("Tessian outbound 700fd1fc53d5:v90"); Tue, 13 Apr 2021 08:20:41 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 58c19a6176de4691 X-CR-MTA-TID: 64aa7808 Received: from d0058d87fbef.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2A75D98E-D7D4-4D5C-A6AD-CF67E0DBECED.1; Tue, 13 Apr 2021 08:20:35 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d0058d87fbef.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:20:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e3c45lGQTaka2EJ+Tlv+uJGcknz+rLopCN7xUYpC1/Oy9aQyjMVFA3VU5beQCJd400E68CL4pCAUJ9Fr0He628REpwRZD/jJsI6TdIx1rmR/kc99jTPdjSbIpteqrqS0LJwBG0059E+HhGrCvnLpXdhYmSrwwMzSP5/n0l/dUFdvximsXmj1ZDQsbnfhCpScrvVdVYR6c9exNLXkFBUNsQwk3uRqz+QXXyvHXk4oFqs+EP/+LoqlveLKX3DdmGsGzj+SHywE6Pip9SGw0Cqw6PPlAtMnR4BiVPgJ4LOfI1/vyGnY/hXcQkvoFdb5WhppHE/tnNjzldeHI0JI/hw2JQ== 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=1vbxFpX+Wlte94xTBQS85D9po3/Z7KtywUaqWDrUi4M=; b=Qn9NP7PGSRQqHsMzTXuSI3w5xmnzsZnJXJ+1SA3IPbdpRibBwfFPoQhj6wEROaeojun5ZaReP6QqihGzJE1+0Pq9FKITNkmqJ8lTFILr3pUfmLW+qYWMhmPZzFikj4b7EKgrhQZlAnZASQrCVGNctJGOrws6RGgYj4wK8/wwQijP360HE94izCAX05py//EIvxOwrZX60chISlZL4UWC2h/0/snwLGgTclBni/yn9TS0MgXsuN1Q2osKO+3F1rg30MyO6XPYAvuEHJ/htep3v9o5IM5g27VEn4d+PmEiRNT8yZ4bACSg66H8j6qjXSC6/JTouCmyRtxYjAYTWGdDcg== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6558.eurprd08.prod.outlook.com (2603:10a6:102:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:20:34 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:20:33 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 09/14] x86_64: Avoid lazy relocation of tlsdesc [BZ #27137] Date: Tue, 13 Apr 2021 09:20:27 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO2P265CA0274.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::22) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0274.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:20:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ee49487-c961-4613-2aae-08d8fe550705 X-MS-TrafficTypeDiagnostic: PAXPR08MB6558:|AM5PR0801MB2099: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2043;OLM:2043; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: atUAvKd47UeKfrnr5RHdG/a6uCBEzdKoqJaR7XHcvRG/c132cQMz07X+E6Jq5NFlKvryDCGMnhYyLMBE2u8Q8zoxtR52TmMRxzqXpk4qA+9JWN2KmgpKG8uj+FjdKsLNZF16eJT7YvXNzuHks7sEqhoeCTJx9lYjbo70PR/70ttV1Ywt6048RATnGz0y0tTOEd0ZgHxbE/8/6feDEsd9cPlVq6Y0JgqgiNSfH9Ax50LZW+RZj4cydviuzL56HPIqlyv1fYEFX1OECPLZdUU70q7kbxd+wZD2ktmEaWuapjfkSX2Z55/8L7prWd+iGSJ/+RU9k6WQFjzPDBsDpsqrkMKKBjDGDW+Il4m8DmaW0vO1YyDBGiP8yCYkuPXZVag3LvUBJG3d5RcS9vGCBTMW8+eX5E1n+AYg8bc+Z9dBlcfshtpFU0BFrMAvJ/kdJ0QxoS8JiQQ50kGC07AAASDjOKqelEdniWW11hLUjqY9Q+zbASdJ2ZDDq0Y5V/0WbkzISRIrkNv6Cdb+e1vk00syOrd4Q5FT8TLVWmIcr0VzivZovKxywTw+ehWRDiCswpLrX6BTW+lDyLrGMHpv8IrEx+rB4ojXJftX9j9jGq2Wv4RtkJ9l4wcYzxf3v3GZ8iJ1R9q3+uRWwtXHgrQfv9M8OAVWJNfvwhzqAG/HsmxXAm8TjX660PMnkOMonBF2RT4X X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(26005)(69590400012)(66556008)(44832011)(316002)(66476007)(6512007)(16526019)(38100700002)(8676002)(66946007)(38350700002)(52116002)(186003)(478600001)(2616005)(86362001)(2906002)(6666004)(5660300002)(6486002)(956004)(6506007)(6916009)(83380400001)(36756003)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: n7hWwLXVRyxMkSuh/q85NfH6hL08h+nouxbiodEPmacClcXx7dxw9A9jsOhaLbwQLurHNcZdW1PwTSVEjI30WnY5KUVfz1tK4709VQDbbhuGnOOwmmRPmKh8aLq4FhyXz5uCmXjuii5Tsx+e2fd+A/cRahtEFSpXijo2oSdruOef17P/rBGUx9DqJMRzpGi4O55HHeKqN+49sMeYcIgGuOOOz8EGNrQebqGQciCcRzOtyaef4RPkM0/E3sfnvg10l1YNNvLWnH7AdRYnfph2Op4XqQdkqGnX1XK70TvkgH85IB2kYbwx+ORwXpGR8B6GCaDMBCbKNra8v2K+EeHZBi0i/SyQFw7Mr5U/B9hFoEPA7xg+szX4A5vZcbfWhAwRpHjJfETe7AlLP41got3XUFS5cr4Y7EvDm1rj5EwxzqcIxMlUn9SN9gvW7lTDox33JXe9JJE2uFSo0qm0rITmv5pi0iNUd1x1JtoDcVioNOyIZvPR7RCQhtmxHV44jGHMml7fzh8FnlNHr+ZJfwZjVfzHP38uuMe4LseDsaBInV3s1aDdG+atP8+zc7I8df0RXFFmcXYev4oYEKZTzWf0RWMHsvDAtvIChNRbKm+aXKQvg9fFD5nmx63HkWnTFpABD+sudlMBZUvs8ozJn6sfdlPjebiM+ttcy95Q/V2Wjn08hfWT5PnLuZVMH4/EcDd/niGgk0JLnSFb/sDFn50MJFasG7suLpJtqoRCzGsV0llJi/NBqGhzEI6tUdKzG4c2uxRJ9PdLCJLbhgdrYWkge2P4hciIHXALYUSQ0+k0rpiWZsy70htuUpUYg1Zores0yb3qiAe/U0kKytyeVbJ0LVtYDpVWtcWPb1JaBLS0WbxMc9Vxod8nug9RrygOUEMGfYrvhI/Pe/9V6HLHTEUM/FMQ0aLMMmSNUJPKVW1eRWVbuLNINcQo2EcQU6eyl6ozltqirWRzMwXtEtWHeilzOvyOwB/TpuprTrZKbusrTMpYmdD3l3h9EPy3Kv8+7ZbuUYLIewigeXoG8lz/IBh9CNdy4TuNKics2/MkaUqqOJdpm2ohxP/2YEttk/vttBShav2gkXviBpruLrr9ULsgi+dfwQxqrzcSe8/bIPh4aAGY9axBZVmkxNGza+ocNAFzISvXf/o+8JEBVSWsHD5kcphfhlG52UToURJJsv1WN6Z3SLKxaSkbvuOssLGD5vxCiRWM5pHWEuK4SZ0F4SuF9k5KCb48WZhG0SHspnyAF9RA6v6Sv43tXC4ADknUwSEKBJ3Q/1egNY7qj3vImeYhv5CMr6Fp7yP+OMiH0ZDkm20Jf/8q2oaSoRG9apJp00LZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6558 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 4e313895-56db-4aef-c0f8-08d8fe55023d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +t6fSA63GOft6bsIhDW//d+ZCujgBEZ8zLssOs18+htfXPXmxZJS2a4B5oKn0krlwvKdOLenxIp2J2RwlkR9Bi37qlgLDE50H7Jl50vD1V67xgFAmSsn21S6IpCXGZLFVrlk3laSd4IntYH4NU+WhsOy07wV9qRhG3daKiuYfOsT9fOJJWUclTb4UVE0wNgzHbbY4G6/f664hqzCio3JpkJtI+cz4qLKZjHE4gmngaYSDgFEeH6z4beFOkypNUai3gZUHd6fhSoelURvIG5uxmgGXyxqOLJdWMal4xnKe3Ems6ZAl5YXNCzMdTBczH6uqxSuRvbzMqMT2qYoGjpMm8F+P9l4nhzHbl1w4DUNSqTUs3IOfJwiN2ZY6RkporT6AGPEaiELy0Z1k0Ow7zZviUB7h4KB3CDJYoKTZcLPc8lGFdIR9z9IJwjlfW2HP0xHJbjSSdL+Br5sPOT7znhhwXZcam7/Omr5h0k5jSBdNwcNx1VMdb04Fq5MvluFWVFkUfJoO26eoUJGgN+4ilNDHM9cNWcLK0TXKqdE/RNd4A8UfNhTRAhF0HXGpHrU/Qqgb9CAbKeORZIuYJF7mLKwkoKWo5lXqgkTFnYzpTEZhkWtTEEBNMjy4vTOJ+eFbmw0PlASBdCotK63/va0cLnMAUIZubzcHdGTPXEVMkwa6m1mDG7rEEl5EHIj4YPF9l9H X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(376002)(39860400002)(346002)(396003)(46966006)(36840700001)(36756003)(70206006)(83380400001)(6916009)(316002)(5660300002)(186003)(336012)(2616005)(956004)(82740400003)(6486002)(81166007)(8676002)(16526019)(8936002)(6506007)(26005)(356005)(36860700001)(6666004)(70586007)(82310400003)(2906002)(478600001)(69590400012)(86362001)(6512007)(44832011)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:20:41.6299 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ee49487-c961-4613-2aae-08d8fe550705 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB2099 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Lazy tlsdesc relocation is racy because the static tls optimization and tlsdesc management operations are done without holding the dlopen lock. This similar to the commit b7cf203b5c17dd6d9878537d41e0c7cc3d270a67 for aarch64, but it fixes a different race: bug 27137. Another issue is that ld auditing ignores DT_BIND_NOW and thus tries to relocate tlsdesc lazily, but that does not work in a BIND_NOW module due to missing DT_TLSDESC_PLT. Unconditionally relocating tlsdesc at load time fixes this bug 27721 too. --- v2: - mention the ldaudit issue with bindnow and tlsdesc. --- sysdeps/x86_64/dl-machine.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 103eee6c3f..9a876a371e 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -570,12 +570,21 @@ elf_machine_lazy_rel (struct link_map *map, } else if (__glibc_likely (r_type == R_X86_64_TLSDESC)) { - struct tlsdesc volatile * __attribute__((__unused__)) td = - (struct tlsdesc volatile *)reloc_addr; + const Elf_Symndx symndx = ELFW (R_SYM) (reloc->r_info); + const ElfW (Sym) *symtab = (const void *)D_PTR (map, l_info[DT_SYMTAB]); + const ElfW (Sym) *sym = &symtab[symndx]; + const struct r_found_version *version = NULL; - td->arg = (void*)reloc; - td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)]) - + map->l_addr); + if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL) + { + const ElfW (Half) *vernum = + (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); + version = &map->l_versions[vernum[symndx] & 0x7fff]; + } + + /* Always initialize TLS descriptors completely at load time, in + case static TLS is allocated for it that requires locking. */ + elf_machine_rela (map, reloc, sym, version, reloc_addr, skip_ifunc); } else if (__glibc_unlikely (r_type == R_X86_64_IRELATIVE)) { From patchwork Tue Apr 13 08:20:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465621 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=YYD+nsoZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJTn6G32z9sW1 for ; Tue, 13 Apr 2021 18:21:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43D2F3A07000; Tue, 13 Apr 2021 08:21:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43D2F3A07000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302075; bh=eI1o7CQWu6VbCUXjEL9eC6+LIz+Gs9bGdp06wUTT0qU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YYD+nsoZMzPvkiLwqlkO1ZRVnJKf5o/QNlR3jmUUS9Gjphqojo6ahKDDKepiJxIYE GDkyHKUY1k560G86MjP88sixXdkqKhGM3xNz8l3ryWpPQoXCT+P8vMqkGhBVRqM7Yt Gqgi0H88wGDC/+fU8TlRu9LdsALS4DTkO57CsCoE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2052.outbound.protection.outlook.com [40.107.21.52]) by sourceware.org (Postfix) with ESMTPS id 10E253A07000 for ; Tue, 13 Apr 2021 08:21:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 10E253A07000 Received: from AM5PR04CA0018.eurprd04.prod.outlook.com (2603:10a6:206:1::31) by PR3PR08MB5785.eurprd08.prod.outlook.com (2603:10a6:102:89::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Tue, 13 Apr 2021 08:21:10 +0000 Received: from AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::96) by AM5PR04CA0018.outlook.office365.com (2603:10a6:206:1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:21:10 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT039.mail.protection.outlook.com (10.152.17.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:21:09 +0000 Received: ("Tessian outbound 47ca92dabae7:v90"); Tue, 13 Apr 2021 08:21:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 7ad863d819d6974b X-CR-MTA-TID: 64aa7808 Received: from 4115594208e4.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A72E30A7-6751-4961-B65B-1647C8817984.1; Tue, 13 Apr 2021 08:20:56 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4115594208e4.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:20:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cKQQYROvlIvSlHeDNmZUva2W6Kg2L/YqPD957gB98QgCS7vratvUbtCkqLgM3R3lE1N/TKVr/W1JWNVjgE1SYTVsDG3M5JBIpb+8QocDIpa5D9wvox+7c/mVPc480fX7zZ+i8kmaZPTRK4TpeIxtegwEwgugLN6RQZiUx/uViPGVDjVLRvoLARZxVtmYYgcQm4XLqczk6HOXHNY608ltpDTA9nhO0djLFuXHrgPks4iG9TV8WUe8BHwZPGKg3826Y55QgUdwTulKq41FrKiujgraJZhP/izWHF7Mr5DjroLVTR95wR+iRhBvrzglLvo5Z6N6NSxYcipzdeEMSv98KA== 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=eI1o7CQWu6VbCUXjEL9eC6+LIz+Gs9bGdp06wUTT0qU=; b=YwVh+F7exUUeBUglXcLq7GErTIjlv0y+/AjCkobhaVmwnkcj7OrRgu++uttl7n6SrIgum8ZiQMFSDAKxpiHvmmNcDjfAujKcoKwpl4ujbTqbx3HFrtHmhStVZvsnIdSrSw126fW/7I6w1BeS/6jK5fY48FpB5D6BxINUTnSyQ8/Jdo8QJEmhE/dyBxUHM2NA4HCk4XSBCg5T24QEdAD9MQJBuqmQ9OWGGIYF6Hsim9CT2q4+XCKcbhIYxJ79/fLz699sJ8F11rEDXc9m2DQ69pOiQMDEllOi8Kk5x73Wuq/mRtM5MKqsMvu87G2QhL0Yu+AP00nqa+SSFJdDFT4YAg== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6558.eurprd08.prod.outlook.com (2603:10a6:102:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:20:55 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:20:55 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 10/14] i386: Avoid lazy relocation of tlsdesc [BZ #27137] Date: Tue, 13 Apr 2021 09:20:44 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: SN4PR0801CA0018.namprd08.prod.outlook.com (2603:10b6:803:29::28) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by SN4PR0801CA0018.namprd08.prod.outlook.com (2603:10b6:803:29::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:20:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72659760-f56a-4a6a-f718-08d8fe5517ad X-MS-TrafficTypeDiagnostic: PAXPR08MB6558:|PR3PR08MB5785: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:4714;OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: C2cZn97IR3Rj1ueCLaSLV6dXnPl3x1S3o8m/p7idxXFY/w/NN7tbPDyYivjMwSiw3+NnKTWreHV7npDDK1RhHMnUjcFyN6VNeE8cfUcHz/P2sw6XnLQHgppbl4BjWN0f63MJ6uE6TFd3Ql1ig3CPh8NDjoFDLGuGo6gbbqJJPtMoB7ko4mNTnssqm7hyxNon5x4iGJtjWBqfg6ar2Gvgigpn6yoP4wr/6E5/GreUEiiVvTKE6r3ecwmU8VjwQh0x/TKoOoxvD8wRuRVWo2GNllndhVNMW8HvTxEuPI/dimleHkAaK9UMjRa8+GYqDYICZ0s65z7xPrf2Gn9ma1YqeIrbTqJg+aFAX4toMB0qvNYo6dIPXnrpKWBoMyOOYGBfgGybgQYh+tHmdZ/+YtcXiUieFFwwa/Wlxh6OzBqAVyRcFIlfLysCAuhEwO6GIym6B6tmhmwqS9ksSPrdjI5OrMON+wiGVwj9/aHngve0PFvc633JR/PBVNalVl7/R4pqB5TV8yfbxB9L0GBPjRjAa7Rnx7x7GE+Monj/ijQk+/1E7QWTQWRYmXPzXC8qfwjIx8w9YqFBGhZ4W2179tu+cDGTxfotauh1HQuBNMctQfsOgntfVyLn4FQtOk51meB5d5i2Zad/LgTtX9KZHOxNFgYo6QkmgRw6ecxSCrmXMxPAaiRW3e+272/3LyKQf3Mw X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(26005)(69590400012)(66556008)(44832011)(316002)(66476007)(6512007)(16526019)(38100700002)(8676002)(66946007)(38350700002)(52116002)(186003)(478600001)(2616005)(86362001)(2906002)(6666004)(5660300002)(6486002)(956004)(6506007)(6916009)(83380400001)(36756003)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ZSWYsTh+a2Bd6L7KNnrB89ln1VErpEcKtyZIlGh5BIyeVFKxpR2ZfVAOEPFWnpLrgdKDN5gVx4ONft6PUgF5Q6wpuNqzfr7iQNJSfyDQoCnUy12kisJ2Jsr3n6qdSjbC97k+0lzxyO2hU3JzeqyyuoGxoxkSXYsEuDwq0Z4/2aN01sRYCPv3XC48DG3oa9QQEAsZSMjdK1DQeqZ4pibPPj/z5LWnAf4CdGcQ/dA9gYy8tMXv3hbGx2/piCKn02YrONBCHQfKU5MDMI9AXRT139nFeogXA0K1Q7bszeZHrbwPf5Kx9oJEcZyesjqX6rejOCtqcfhaE0rWKA9GcvcGj0Dkuk+l83+X9Sx9qHOPbTirNt444ArnIHSKiXWwfr6EScE6Ic39Nc7pLAekjhq7eWkc3hsV1g4jKE9vuXrMWKKdAYuDlbTfdHbPsF8WR5SMwgBVGw+N+2QSUcd7cgh7ggE0CvDUd3o2TpVOEro0pkyyX5HYpKtQ+m/UjTaeJ6I94X4VMdydlegjraQLLICGEA9L6gB+9mYZHE8iskhPTx2e1UF3ABlF8oDdkolp5EcAIEy4ZHj3RsmX11xUXXYsRw+QtdJYMAmoOzIdyaxHIO+8PODYLP5IDoEoSxhmyzW+I0cKRdGAW5QipN6iQT9OHmHQ9RumifExT/GTVS7Vd7+WnlOQ5XY3MFeCcsQIDL4sHYPplCJbu4BOBGAg4aHjmx9qntoqtFuDMsh4sysd2aTqXZJ9+MgHt6A2WI4c/06gVyOBW/b3X55FjYklGD3msT9pUK5C706s94D8TWDzHeyfULx/aJ96pXmHcEjQHkKH5LUkufLoMHVr2nB2UZ88WM1rgNN5I8T43+hc2+Bs/ytydKPSC1Ujw35on6qkJAvENTY9z407rrlVh9UsI3fka319cuCAep+IAdEAXCVSIjrb2SpEvEqyZE58m/BNlZgFEsVLQBz6izQkR+WflcxFcNiIpa/p4vzhayeK/1atrUFSMIs2zEaylz2ldMnm6Kad5ZrNhIfp1QjE4EuIwVOcPSFm0+I/kEnHcxlN66jQg/un5CCL4t5t8kx6yunnc59mwvcC9HZJxcdaohyUIi8sBXj/KgI4RxjmOnpSo+MAJnzxDAHhCCU12zewL6IAO3PEIvGM8evAcpKqezLTZ9x/GLPOyvp3P79vOufGQ8qbNY/WYTCuxgOToL0olaz+iRiObpiKDEUCMens2WuU3I0bUPFyxLTqgX7VqJaXjhDVTOiAppdor4G0o1UHK+Bij7UuFCgEZkpKrioVheyTs94rjpr+IJUkOaSQ5/Ip3Tra/Sho4k0sybpNINGQkZNHxVI+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6558 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 834bacea-a65e-4f0e-f1cd-08d8fe550f4f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZpHJbBHkghFmut1d0VJYV8MUOtrwksFsWkQsEk3gQmx8R2yit7C4aT9iSV1fNkTF3Iy2fAQoJdUkJC0BlJwbRIVsIacLE5C6hLTF7Zi9R1176IuAWEQao3lJxeWO16xpWzTFJ8sNFwccijBW/VvhBzePWZ4K4I0nqIffUr528nHdPY88cVDCNbqIiSMC6+AndoK5D88KamkR0dJrmd8Dh4TcW1iKMcOgBqTcPxKPSSxNQKMjSnevoDJGydPwLM0TkMG1k8SheAsMlR5/Chrhl2u7kmXA2ZkZvX+E7xhLk6nSLPCpyroJAuKXvY6GKpulkpCTavBsnsDmfJRT76uFbSUtWYPQrqLFbPbc9fok36AQ/GHHhdFHashBTH6GMHiX503o38fxpTAcZTs3+lSwXxv+2hjVVGKBjV5UJDjYwvZ7S8w6T0Dk3nmgq0MVdLXhoGixruvFpmEmGVmeLg1YLbOX3GNuaiirEXZn/lahIAsHMZMs6l107GyYAdO0sVpcC2KhP5SlSHqAtvZLYhcturM3p8hcgqZWTs1teSYNajS8FCpxZfFg1P6UB7Al8CtuctVG7XXy4KvkI8ey/0GmQIRQBhp6S2SMIeDzy7h7eG9yMsUGVZtURAmZq87JYvqz3G6FkgwgNYKZbhzIbVLJnVMawKiliwezByK7R38yDYQI7TVKW4x4nEzNBcjub4JX X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(396003)(39860400002)(346002)(376002)(136003)(46966006)(36840700001)(36860700001)(26005)(70206006)(8676002)(478600001)(86362001)(6512007)(2906002)(44832011)(82740400003)(6486002)(356005)(336012)(47076005)(6506007)(36756003)(956004)(81166007)(70586007)(16526019)(2616005)(316002)(8936002)(83380400001)(5660300002)(6666004)(6916009)(82310400003)(186003)(69590400012); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:21:09.5343 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72659760-f56a-4a6a-f718-08d8fe5517ad X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5785 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Lazy tlsdesc relocation is racy because the static tls optimization and tlsdesc management operations are done without holding the dlopen lock. This similar to the commit b7cf203b5c17dd6d9878537d41e0c7cc3d270a67 for aarch64, but it fixes a different race: bug 27137. On i386 the code is a bit more complicated than on x86_64 because both rel and rela relocs are supported. --- sysdeps/i386/dl-machine.h | 76 ++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 23e9cc3bfb..590b41d8d7 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -688,50 +688,32 @@ elf_machine_lazy_rel (struct link_map *map, } else if (__glibc_likely (r_type == R_386_TLS_DESC)) { - struct tlsdesc volatile * __attribute__((__unused__)) td = - (struct tlsdesc volatile *)reloc_addr; - - /* Handle relocations that reference the local *ABS* in a simple - way, so as to preserve a potential addend. */ - if (ELF32_R_SYM (reloc->r_info) == 0) - td->entry = _dl_tlsdesc_resolve_abs_plus_addend; - /* Given a known-zero addend, we can store a pointer to the - reloc in the arg position. */ - else if (td->arg == 0) - { - td->arg = (void*)reloc; - td->entry = _dl_tlsdesc_resolve_rel; - } - else - { - /* We could handle non-*ABS* relocations with non-zero addends - by allocating dynamically an arg to hold a pointer to the - reloc, but that sounds pointless. */ - const Elf32_Rel *const r = reloc; - /* The code below was borrowed from elf_dynamic_do_rel(). */ - const ElfW(Sym) *const symtab = - (const void *) D_PTR (map, l_info[DT_SYMTAB]); + const Elf32_Rel *const r = reloc; + /* The code below was borrowed from elf_dynamic_do_rel(). */ + const ElfW(Sym) *const symtab = + (const void *) D_PTR (map, l_info[DT_SYMTAB]); + /* Always initialize TLS descriptors completely at load time, in + case static TLS is allocated for it that requires locking. */ # ifdef RTLD_BOOTSTRAP - /* The dynamic linker always uses versioning. */ - assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL); + /* The dynamic linker always uses versioning. */ + assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL); # else - if (map->l_info[VERSYMIDX (DT_VERSYM)]) + if (map->l_info[VERSYMIDX (DT_VERSYM)]) # endif - { - const ElfW(Half) *const version = - (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); - ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff; - elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], - &map->l_versions[ndx], - (void *) (l_addr + r->r_offset), skip_ifunc); - } + { + const ElfW(Half) *const version = + (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); + ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff; + elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], + &map->l_versions[ndx], + (void *) (l_addr + r->r_offset), skip_ifunc); + } # ifndef RTLD_BOOTSTRAP - else - elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL, - (void *) (l_addr + r->r_offset), skip_ifunc); + else + elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL, + (void *) (l_addr + r->r_offset), skip_ifunc); # endif - } } else if (__glibc_unlikely (r_type == R_386_IRELATIVE)) { @@ -758,11 +740,21 @@ elf_machine_lazy_rela (struct link_map *map, ; else if (__glibc_likely (r_type == R_386_TLS_DESC)) { - struct tlsdesc volatile * __attribute__((__unused__)) td = - (struct tlsdesc volatile *)reloc_addr; + const Elf_Symndx symndx = ELFW (R_SYM) (reloc->r_info); + const ElfW (Sym) *symtab = (const void *)D_PTR (map, l_info[DT_SYMTAB]); + const ElfW (Sym) *sym = &symtab[symndx]; + const struct r_found_version *version = NULL; + + if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL) + { + const ElfW (Half) *vernum = + (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); + version = &map->l_versions[vernum[symndx] & 0x7fff]; + } - td->arg = (void*)reloc; - td->entry = _dl_tlsdesc_resolve_rela; + /* Always initialize TLS descriptors completely at load time, in + case static TLS is allocated for it that requires locking. */ + elf_machine_rela (map, reloc, sym, version, reloc_addr, skip_ifunc); } else if (__glibc_unlikely (r_type == R_386_IRELATIVE)) { From patchwork Tue Apr 13 08:21:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465622 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=K+AQq/vx; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJVL3CFNz9sVw for ; Tue, 13 Apr 2021 18:21:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3111C3968C03; Tue, 13 Apr 2021 08:21:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3111C3968C03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302104; bh=duycyx5W5vBu6cnCIjxOfv6X0T9L8z2U3SGZgNjP5dw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=K+AQq/vxUPkwkaRvzlW2xwC9VIWBW9M8I19dzggfm6vPNem7SL2qIL23/5cO+iRWb onASSnuwlwQT+UI5bN+FsOcvk5GZFf5+NR0hYuT0bgLXYzIknhG8Iu2L/88n2uWCMa fbSurINnknYaZH0n0xDjXLgYb+QVvDTtJLcKBFb4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60078.outbound.protection.outlook.com [40.107.6.78]) by sourceware.org (Postfix) with ESMTPS id 9D895393C868 for ; Tue, 13 Apr 2021 08:21:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D895393C868 Received: from AM6P194CA0096.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:8f::37) by AM0PR08MB4931.eurprd08.prod.outlook.com (2603:10a6:208:15e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Tue, 13 Apr 2021 08:21:37 +0000 Received: from VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8f:cafe::c4) by AM6P194CA0096.outlook.office365.com (2603:10a6:209:8f::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:21:36 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT026.mail.protection.outlook.com (10.152.18.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:21:36 +0000 Received: ("Tessian outbound 82c2d58b350b:v90"); Tue, 13 Apr 2021 08:21:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ed31d2ec2c469e56 X-CR-MTA-TID: 64aa7808 Received: from 36d8ebbcaa49.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F5BC4A1E-1B24-44EF-A2E9-14F18556A1E3.1; Tue, 13 Apr 2021 08:21:20 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 36d8ebbcaa49.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:21:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gcau+AkP374/XAP/3hLCzWg/7foNTWZGiwf9KyHyLIdxVyYbTD4lJwqL+qTuE3nFd6eF5LLdj79doeXOboSOvgE2lXc+yagDwOLPtfGZTTKz/PapLoFjDkVeb/sjz0qQEhMamtLar/BXqYPUShT+azZYREWBGIhYxkIH537rik+Mf1I8fnILdHofpsYwcilKK7+H/uZ2xYLbkar4z1EI3EbQgxIm+3M4MJ2GJyEPmCSDXgyah0G1Dh027gALD+u0lCGR2VbVu1kZL7RmuXBrf8ngJhi18ttj4vZi0K4UFj6jWcgLj7bpPVroPtlfvqiWFUp9g0kt8lSwBoBRp74tTQ== 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=duycyx5W5vBu6cnCIjxOfv6X0T9L8z2U3SGZgNjP5dw=; b=QSIfxadGYNHX/7qmddVEPL7jpWctGVq2qGlTiZ5DJVnsFugHgxX117za8oRK2hAM+eHfUQJTp0JcaKGb+Uh7+DSkbaON4R+uHRMW8BV27pWt5tgNnhASZ0tEZzK9NY8GR2fTgvXIcAnZ8wS5TkiEcewuKFCBz6zbvAD9ZmL/Uaw4YVFPzkVt6mOMHfP2b0B+Oc2qvNxRR7HpGc3yk6EFZVewq2cbjQkfCYJkevmc4OACaZ2IU6Imcc2iGWoEJWjnETljPr2UhxtZjbOqcgrtH5DTnD0X1xW8SWQNPOEJSX58CWlgBvGQBEgxDdMxj2pGdD26n5RoirUxGwtqt8cWoA== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6986.eurprd08.prod.outlook.com (2603:10a6:102:1de::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Tue, 13 Apr 2021 08:21:13 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:21:13 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 11/14] x86_64: Remove lazy tlsdesc relocation related code Date: Tue, 13 Apr 2021 09:21:07 +0100 Message-Id: <5419c82f25996f3887c541352e26a09446e66a3d.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LNXP265CA0024.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::36) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LNXP265CA0024.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:21:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 422e7013-6aa0-4a06-5f6c-08d8fe5527c2 X-MS-TrafficTypeDiagnostic: PAXPR08MB6986:|AM0PR08MB4931: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: r/7gtyUKaZmK0dPfcUk8CjSqhBh6OkYu3rA2R7iVVPOMoZp3g9N4l5REzo5ZWKtXON3/ezI6RKze0DRXWILTf/8vXce5SZKLlGoQ5GqMegXPH1NCLxK0+qLz/fmx50O5V4UMOUcMICFMc++OTsM/kouAOwLnBQPlGJFZSxBBReRvMwcRdz/4w2lBnSFRGVeYw4SV9YhZtqym8iGIzJ5pm9vEM+x/M4E3QnzjVF81BEbT7e03YDLYPARA/E1LVBb9+LAmgu5rVasabJ91Bo5jrQjiiugD+qL/gPTBH4l2foi6e68K2v5vn+XaoAdw5kpE3V+oMMAW4n9Kw7MVXJ6oTl4vkPp2A73ekS+b9+HoN0UAbaSysWpXLCrID5NIFfDUuUEKlHV72zEXdBoEeR7NDYp1hRcvt75yG9C4O7709RGiDeksCcn78q8Tv7kmXbfL6upKGgTaaEJt+IJJYAFWc8b3eN3t365MG9G+25ymGtR2Zw159QFixFaWzw5gZ84ms9ppd+ORd5F35SRPXHg8p+LxfgPiSeQ/K1PSm1OTAhTPXfjj0sAmJFrj1ORNGGADWKWDGK7Exo4t81RKBtDuuqd4i6/lyq+l8ctuBdjNv78mMpjr1AUCCkVmDOa2xAwt6xvW1/yYny6lS/mn0b6zLHX0Xqlb9HFu/K0WxptgcEB/CWHqXyC7W5n2/fkuSNERl4tHsnVypb4q88h1e+EEXmVjK+XH8R2AVGuS383rUMlAKswEXSbuC5hThuWI6vq9P1+u2pcFsahADOTtBZ4Wmg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(396003)(366004)(136003)(39860400002)(346002)(26005)(16526019)(478600001)(186003)(5660300002)(8676002)(6666004)(6512007)(52116002)(6486002)(6916009)(38100700002)(2906002)(6506007)(316002)(66946007)(66556008)(44832011)(66476007)(86362001)(956004)(2616005)(69590400012)(8936002)(83380400001)(36756003)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6ZITJwubQDo5Vg1cEC+1Lki9DUllSNSArsAdpdHsWtytJbDAi7TBiKVbWSoDdYndpzcC9VbMqdltGcyR0LB8eRlmu18TbV9bGJv9mtsjT5gHzXApUq/UfNN6U/mqmhIln4KaB0yPDqhmjlPPhnNEd1n7C33mOIzUpY4Ev9tXfY7TKeHLCYqyYsFJK+TUZNAyH3U1C3bJHVAEXVosVwJjeY8nroDb3WOib9ifXhpmITZCPvDiHt6arkiQ7UWAPViwYa3Mv7zZHnJdBw8ajEZIo8N+sZwU9zevf5/d0KspQOy0kK8Atdn5V1fJ9G3G46u/BHDHkZgPJkv05DSZxxe9AD70+u6X4p9cjesuGqMuJqzsZmjvSkBxWSC3A/3m0mekuKl0Ar9VrXbhEYt0wqXchoRQqQVUJ0RUXTogWgXIXkil0yGqvhMyt1/jSoJW8TTsHmoCmVlvQWN7U9niJLsFK7LWA+wsJwdRpPz1pNIGhC3dLCbGoCTvbyKpYNTZmzZkrdatDrYbOAEZ4Y3cZHGOJHbZU3FIVA3fasc0hbuLSdRCrhVLhup8QohSs3i0uyRJQ9jr1dcAhzSMNY3lo09lZqott3xhu75QDaelVO6YMQk+US6v97OopdqQLGJg8B9VZ6/e0Lrl8G1kDC8F8WnUnPR3cITn6IcNfomQv2wq0jKTYtqIKg34KkK0cgf0DJFHv2m/IGNSpnGR2o3VWd71Oc6aHaTqvQJI+9VgyxObTL1u99M0Hu2Zxz7wH8NPTXh7cF/shLQNxQGUS5U2p2FEnWSYwy9/kgcE44lJ3r5xVbT6XfevKpvAdHNcA4HYBNa30YhTQivn/l3WzbIvv0t1t77NE+S6yzMIUBK02PiF+BodXQUCVoV8vNpsLodfCvI/XTrWxS5OSae9pR0mg49o4SPMKT7hrSjzLdf/LJitVqxjluNruEUIBk3++KdIDBJVHxkghfZdwqOTzf5czCujamSbk4W5lUBNFi/deT5Jwl1l5bWHG65HRMM6FCAQ+5BTD99o1ejRRzweMNszU8QWnLvyUFE23Y9I1Kmv3yATOu6iDaYLUbf6olE28OR+7WrH3SczsXOVHep4+Psv1cv0lioiKFmc7GPnoh6grW3OwE/UxFAvx8iOE1LkFrMNWItUzi4PTMH42DK3/FpjJx+Ca4m1U7IRtw81QMZjQM5F/EaCBxks945pB7dBeE63VzgSPE+qh5MOBIUsZlexVyBgSwy8ILiwSzcTqh2wuwVdIemQNKKd9T05I1YFfcZlYhOUzv+bwdstq/SDviSnORa2/KQaRBEZuIL29XEt5Jr3T2AKwGafwzPAxGTCSVzh185k X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6986 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 64167020-4357-4b98-a21f-08d8fe5519b1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s9NYQagsgltMefYxSUPQVYcIPYSNzxMNo8Ge1035d7Cf5XV1FgYJ+8QbiZofss09ZNKAkSX0UVBk+OZP+4zQp4NNCfegktwYElTcL+nR9gm9EusyPHGhygJRfBeE/K/3CwTMNihIB4wEtRaQDNi8jYlGAURh6KmUKvzMEseAQsMjJUlPaMHagGhbSzAV0enRhWjtXpfSvWdzGFBXRIGJP9lpe5EtrX7HxyRf7e9x0zK7lMpyCTx/1ctfp16ducr7rh9FddO2LtIqFXW5LEH2nlGsmW3E9wL14Y/eTDvy6wZxinZaPjKSUDkOqoDAOjoEoPByZViiywBFULS3hreOxy5jkDTx8vtsWwHCTgmetC1m8FOJG9OzavagMXmh/1TyJ115+83gUvMu6JqTM2g4WboOBURPXyxdi3yNr9ACIvLRbai0HQHRLgBAxK9vMYJTF9xoQ/l0vz4cHvvtcuwp0jZ8GjSdcbKAWhael60FegT6zI01Ot5zF7zW5ofhLZF0AZ6b0rn21nEZwx8mpy4/zTsuyMjWvDXyH7Ve3WBfqaHpKGwLBIDQX/NBsEgjJmBHgM3J/wE3PoP1C58HQZbl6fD0J9KEIZXu9EwUbgJiXW9Goqkbnw5FnehJtPTK+lEjrBDj6Ie/jb9LLceQEc/DT0hV//M7wS8TY44OcThganxOGbnYytgD0b85hrZAx/waI9UfItOQqRduEw5+lYmmjEGxNvy32BtQ8uhsqX1vAEhZF0fyJ0KDLBIJN7fylmCiIp+nPEaUDky/gc3kVCrU2Q== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(346002)(396003)(136003)(376002)(39860400002)(36840700001)(46966006)(6512007)(478600001)(82740400003)(36756003)(8676002)(69590400012)(8936002)(44832011)(70586007)(16526019)(186003)(5660300002)(6666004)(83380400001)(86362001)(336012)(82310400003)(6486002)(2906002)(956004)(6916009)(2616005)(36860700001)(356005)(81166007)(316002)(70206006)(26005)(47076005)(6506007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:21:36.4370 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 422e7013-6aa0-4a06-5f6c-08d8fe5527c2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4931 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" _dl_tlsdesc_resolve_rela and _dl_tlsdesc_resolve_hold are only used for lazy tlsdesc relocation processing which is no longer supported. --- v2: - fix elf_machine_runtime_setup: remove tlsdesc got setup. --- sysdeps/x86_64/dl-machine.h | 4 -- sysdeps/x86_64/dl-tlsdesc.S | 104 ---------------------------------- sysdeps/x86_64/dl-tlsdesc.h | 4 +- sysdeps/x86_64/tlsdesc.c | 109 +----------------------------------- 4 files changed, 2 insertions(+), 219 deletions(-) diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 9a876a371e..a8596aa3fa 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -127,10 +127,6 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) } } - if (l->l_info[ADDRIDX (DT_TLSDESC_GOT)] && lazy) - *(ElfW(Addr)*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_GOT)]) + l->l_addr) - = (ElfW(Addr)) &_dl_tlsdesc_resolve_rela; - return lazy; } diff --git a/sysdeps/x86_64/dl-tlsdesc.S b/sysdeps/x86_64/dl-tlsdesc.S index 1d055adadd..ca9236bed8 100644 --- a/sysdeps/x86_64/dl-tlsdesc.S +++ b/sysdeps/x86_64/dl-tlsdesc.S @@ -144,107 +144,3 @@ _dl_tlsdesc_dynamic: cfi_endproc .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic #endif /* SHARED */ - - /* This function is a wrapper for a lazy resolver for TLS_DESC - RELA relocations. The incoming 0(%rsp) points to the caller's - link map, pushed by the dynamic object's internal lazy TLS - resolver front-end before tail-calling us. We need to pop it - ourselves. %rax points to a TLS descriptor, such that 0(%rax) - holds the address of the internal resolver front-end (unless - some other thread beat us to resolving it) and 8(%rax) holds a - pointer to the relocation. - - When the actual resolver returns, it will have adjusted the - TLS descriptor such that we can tail-call it for it to return - the TP offset of the symbol. */ - - .hidden _dl_tlsdesc_resolve_rela - .global _dl_tlsdesc_resolve_rela - .type _dl_tlsdesc_resolve_rela,@function - cfi_startproc - .align 16 - /* The PLT entry will have pushed the link_map pointer. */ -_dl_tlsdesc_resolve_rela: - _CET_ENDBR - cfi_adjust_cfa_offset (8) - /* Save all call-clobbered registers. Add 8 bytes for push in - the PLT entry to align the stack. */ - subq $80, %rsp - cfi_adjust_cfa_offset (80) - movq %rax, (%rsp) - movq %rdi, 8(%rsp) - movq %rax, %rdi /* Pass tlsdesc* in %rdi. */ - movq %rsi, 16(%rsp) - movq 80(%rsp), %rsi /* Pass link_map* in %rsi. */ - movq %r8, 24(%rsp) - movq %r9, 32(%rsp) - movq %r10, 40(%rsp) - movq %r11, 48(%rsp) - movq %rdx, 56(%rsp) - movq %rcx, 64(%rsp) - call _dl_tlsdesc_resolve_rela_fixup - movq (%rsp), %rax - movq 8(%rsp), %rdi - movq 16(%rsp), %rsi - movq 24(%rsp), %r8 - movq 32(%rsp), %r9 - movq 40(%rsp), %r10 - movq 48(%rsp), %r11 - movq 56(%rsp), %rdx - movq 64(%rsp), %rcx - addq $88, %rsp - cfi_adjust_cfa_offset (-88) - jmp *(%rax) - cfi_endproc - .size _dl_tlsdesc_resolve_rela, .-_dl_tlsdesc_resolve_rela - - /* This function is a placeholder for lazy resolving of TLS - relocations. Once some thread starts resolving a TLS - relocation, it sets up the TLS descriptor to use this - resolver, such that other threads that would attempt to - resolve it concurrently may skip the call to the original lazy - resolver and go straight to a condition wait. - - When the actual resolver returns, it will have adjusted the - TLS descriptor such that we can tail-call it for it to return - the TP offset of the symbol. */ - - .hidden _dl_tlsdesc_resolve_hold - .global _dl_tlsdesc_resolve_hold - .type _dl_tlsdesc_resolve_hold,@function - cfi_startproc - .align 16 -_dl_tlsdesc_resolve_hold: -0: - _CET_ENDBR - /* Save all call-clobbered registers. */ - subq $72, %rsp - cfi_adjust_cfa_offset (72) - movq %rax, (%rsp) - movq %rdi, 8(%rsp) - movq %rax, %rdi /* Pass tlsdesc* in %rdi. */ - movq %rsi, 16(%rsp) - /* Pass _dl_tlsdesc_resolve_hold's address in %rsi. */ - leaq . - _dl_tlsdesc_resolve_hold(%rip), %rsi - movq %r8, 24(%rsp) - movq %r9, 32(%rsp) - movq %r10, 40(%rsp) - movq %r11, 48(%rsp) - movq %rdx, 56(%rsp) - movq %rcx, 64(%rsp) - call _dl_tlsdesc_resolve_hold_fixup -1: - movq (%rsp), %rax - movq 8(%rsp), %rdi - movq 16(%rsp), %rsi - movq 24(%rsp), %r8 - movq 32(%rsp), %r9 - movq 40(%rsp), %r10 - movq 48(%rsp), %r11 - movq 56(%rsp), %rdx - movq 64(%rsp), %rcx - addq $72, %rsp - cfi_adjust_cfa_offset (-72) - jmp *(%rax) - cfi_endproc - .size _dl_tlsdesc_resolve_hold, .-_dl_tlsdesc_resolve_hold diff --git a/sysdeps/x86_64/dl-tlsdesc.h b/sysdeps/x86_64/dl-tlsdesc.h index d134b3f4db..03d5ac7a54 100644 --- a/sysdeps/x86_64/dl-tlsdesc.h +++ b/sysdeps/x86_64/dl-tlsdesc.h @@ -55,9 +55,7 @@ struct tlsdesc_dynamic_arg extern ptrdiff_t attribute_hidden _dl_tlsdesc_return(struct tlsdesc *on_rax), - _dl_tlsdesc_undefweak(struct tlsdesc *on_rax), - _dl_tlsdesc_resolve_rela(struct tlsdesc *on_rax), - _dl_tlsdesc_resolve_hold(struct tlsdesc *on_rax); + _dl_tlsdesc_undefweak(struct tlsdesc *on_rax); # ifdef SHARED extern void *_dl_make_tlsdesc_dynamic (struct link_map *map, diff --git a/sysdeps/x86_64/tlsdesc.c b/sysdeps/x86_64/tlsdesc.c index 4083849f22..ecf864d6ee 100644 --- a/sysdeps/x86_64/tlsdesc.c +++ b/sysdeps/x86_64/tlsdesc.c @@ -16,120 +16,13 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include #include #include #include +#define _dl_tlsdesc_resolve_hold 0 #include -/* The following 2 functions take a caller argument, that contains the - address expected to be in the TLS descriptor. If it's changed, we - want to return immediately. */ - -/* This function is used to lazily resolve TLS_DESC RELA relocations. - The argument location is used to hold a pointer to the relocation. */ - -void -attribute_hidden -_dl_tlsdesc_resolve_rela_fixup (struct tlsdesc volatile *td, - struct link_map *l) -{ - const ElfW(Rela) *reloc = td->arg; - - if (_dl_tlsdesc_resolve_early_return_p - (td, (void*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_PLT)]) + l->l_addr))) - return; - - /* The code below was borrowed from _dl_fixup(). */ - const ElfW(Sym) *const symtab - = (const void *) D_PTR (l, l_info[DT_SYMTAB]); - const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]); - const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)]; - lookup_t result; - - /* Look up the target symbol. If the normal lookup rules are not - used don't look in the global scope. */ - if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL - && __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0) - { - const struct r_found_version *version = NULL; - - if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL) - { - const ElfW(Half) *vernum = - (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]); - ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff; - version = &l->l_versions[ndx]; - if (version->hash == 0) - version = NULL; - } - - result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym, - l->l_scope, version, ELF_RTYPE_CLASS_PLT, - DL_LOOKUP_ADD_DEPENDENCY, NULL); - } - else - { - /* We already found the symbol. The module (and therefore its load - address) is also known. */ - result = l; - } - - if (! sym) - { - td->arg = (void*)reloc->r_addend; - td->entry = _dl_tlsdesc_undefweak; - } - else - { -# ifndef SHARED - CHECK_STATIC_TLS (l, result); -# else - if (!TRY_STATIC_TLS (l, result)) - { - td->arg = _dl_make_tlsdesc_dynamic (result, sym->st_value - + reloc->r_addend); - td->entry = _dl_tlsdesc_dynamic; - } - else -# endif - { - td->arg = (void*)(sym->st_value - result->l_tls_offset - + reloc->r_addend); - td->entry = _dl_tlsdesc_return; - } - } - - _dl_tlsdesc_wake_up_held_fixups (); -} - -/* This function is used to avoid busy waiting for other threads to - complete the lazy relocation. Once another thread wins the race to - relocate a TLS descriptor, it sets the descriptor up such that this - function is called to wait until the resolver releases the - lock. */ - -void -attribute_hidden -_dl_tlsdesc_resolve_hold_fixup (struct tlsdesc volatile *td, - void *caller) -{ - /* Maybe we're lucky and can return early. */ - if (caller != td->entry) - return; - - /* Locking here will stop execution until the running resolver runs - _dl_tlsdesc_wake_up_held_fixups(), releasing the lock. - - FIXME: We'd be better off waiting on a condition variable, such - that we didn't have to hold the lock throughout the relocation - processing. */ - __rtld_lock_lock_recursive (GL(dl_load_lock)); - __rtld_lock_unlock_recursive (GL(dl_load_lock)); -} - /* Unmap the dynamic object, but also release its TLS descriptor table if there is one. */ From patchwork Tue Apr 13 08:21:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465623 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=scVZUJiX; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJVS5Wjtz9sVw for ; Tue, 13 Apr 2021 18:21:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FEBF3968C06; Tue, 13 Apr 2021 08:21:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FEBF3968C06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302110; bh=YuJrvpT5gwhaz+358P/wSQY9SEOO/KLMwa7K0Er3SxE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=scVZUJiXmkBwWwMDYUTES8PW+7NP/vZi7jMLTxkVRft+1eQ0K5FN6ogGS+qrtSkJk OHF6jfpsgj5nfRTRtYcftbfqkU+p5fUCGNrX8YVjf5+SOl8aQttrtwzArHMiGfMX60 36mXDVIgzNvYmvsNUiUEww0NAAAJBY2B2girpATI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2067.outbound.protection.outlook.com [40.107.20.67]) by sourceware.org (Postfix) with ESMTPS id B87B73968C01 for ; Tue, 13 Apr 2021 08:21:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B87B73968C01 Received: from AM6PR0502CA0058.eurprd05.prod.outlook.com (2603:10a6:20b:56::35) by PA4PR08MB5904.eurprd08.prod.outlook.com (2603:10a6:102:e5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Tue, 13 Apr 2021 08:21:43 +0000 Received: from AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:56:cafe::b) by AM6PR0502CA0058.outlook.office365.com (2603:10a6:20b:56::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:21:42 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT033.mail.protection.outlook.com (10.152.16.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:21:42 +0000 Received: ("Tessian outbound 700fd1fc53d5:v90"); Tue, 13 Apr 2021 08:21:42 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1e612d38cf96e2c8 X-CR-MTA-TID: 64aa7808 Received: from 29cdbadc1ac2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F7BAD7F4-0EFF-4B20-8FAD-43804AC1B7DE.1; Tue, 13 Apr 2021 08:21:33 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 29cdbadc1ac2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:21:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dL+EHbs6sVckTbNxZyXooYviod2oEeWCEhF70HlO1m974LrRLK2Vn1NohiH5PaN4xechzIvO4m/sdjPogjJRuHmArNWJAwIIUZVDmt1NFLBvKuQkKJzFIiDDbCs1529XwLoNeULu8JCK3TEoqsF0lTMP78sbUUOIUJVd4Qq1sHkbQYoIWdoYzYmvrulpqMG72XmZQ5i6/FiLgxE6tKkD/KrwurybdqqIhSu40rXNmD53PTP+gpdkzVDV89m/wpdQJzOjaiMzAKFmFIeuM9+kXHD836VJynnpu4vCcDpmw2aLFWiONoqmGvqWs5MZk5yhxuKs7CHlzMcer8Q8uLpAlQ== 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=YuJrvpT5gwhaz+358P/wSQY9SEOO/KLMwa7K0Er3SxE=; b=Q0KSTo/H+qlzuDkpfUnxTagFZPLyrtYmNGsLdrLdvAMBvnwTSm8/lwW47KcDc99ygaucdw9bhpwAXu2ftPsNen2fGMrb/IJX9pVEIuHypA3fzmIRNFQwHZNPqXBKsh1WeOdfP644EvcQLQBPxAHqibLt9yeEb5TZ4SOyfJiK1eA7JugWBWPb8mvFgY6uJGuRvvWm5xlCcrNbTP8yg9cGk+czewLKvRG7lVB2S/u7PWgUe9B0FUYjgUAN7aPzgcE6SvN2Ubh+Mtm+Y0uxCmBZBFhUta2WGqSbkO1zDdxapZxIsLoDaCM0GREUWQMuEGY/9qfdu4YzNqsGW5S5rC/CRg== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6986.eurprd08.prod.outlook.com (2603:10a6:102:1de::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Tue, 13 Apr 2021 08:21:30 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:21:30 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 12/14] i386: Remove lazy tlsdesc relocation related code Date: Tue, 13 Apr 2021 09:21:24 +0100 Message-Id: <13859e5a8b0dab26c922c4d1df63d854957c33b3.1618301209.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO2P265CA0240.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::36) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0240.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:21:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e565f0f-85f5-4886-f5af-08d8fe552b8a X-MS-TrafficTypeDiagnostic: PAXPR08MB6986:|PA4PR08MB5904: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 4hEVuzfJXgtUoq9j54zVzCm0nCzuQ6X6/kIY1xewXopL1GPloIOjy9C9grBQgxFyEOlWfUDKjWXkK1ZVA3SpV20AEWxZ5oLMY9ohCrpFKS3SXQSrpR8oFwHQzoOaT5Kv75mYZ+Kg8/6aVmlSCAaz++eBJ5Q24KUyuLa6efwXUxxoBC9t1POQip+KZ2yLjLiPgZ9NltCzw2dxFgjx++8BTvThXsWcrNxkzhYbipISWT/5jNDC3HCBwYWEe9+WYuJ2BFj/Uyx4knUZVhXLvxX80DUQ22uFLZJA8XIkDstpU87O+SHV6RgJX7oR1hi5MBupK7YjDQWx0HoDGgC+z3KKtsQaV11LCjCNIkv/2i3jIsfDqk1yMnGus6t3WEGTJFSxgZOoSJHMqydrQ18sLK1iF8wmy4CU2h8Vo4P4HrN0WuLC46lCeLOdCMX8ZxPvEmcV3Oi2mnTUHcdtwUPP7t+H5VKXLlHpWbEp+Mn39cWIUXbH5euoRAurfsMgk5NA2KHyLK/X0VHg26tAJgz2ClqLPUGvgsDN6qlqUTO6Z1E4s5aYu8rlqtAXVJ7x+TlaeLzTfPWvdsaKmXVYN+2zTIvj9s2ORzTAzIA2FxgiKf2byMzio0DLfsA/ugx83+5EI8gVgEq+RxD8B82R5kSgy2zxAHsDo4iUfmYPjxNvK6wN6tWAZR3/5wpUlhIWZso2rT0fEE57MK6DKTWc18H/lo8kWyzZ9qSWU/ft/hM72X9d7bBXfdK9IakYjXv+AtEEqXSr X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(396003)(366004)(136003)(39860400002)(346002)(26005)(16526019)(478600001)(186003)(5660300002)(8676002)(6666004)(6512007)(52116002)(6486002)(6916009)(38100700002)(2906002)(6506007)(316002)(30864003)(66946007)(66556008)(44832011)(66476007)(86362001)(956004)(2616005)(69590400012)(8936002)(83380400001)(36756003)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nqIPPt+wYPkeCmNtqEQgyEPm8VVJJYODkAQtKf1JExHlL87t7YmKA8L9JrCOE7ocotVe5wZ46jFQoluO91hqW98sEW200zX5bewwn1diAEHV07r6IB2mfrYTKhzcv1xps/L7z0FhCJdgazAjtkaEMmcX8A577SBjoWdGCGWxkPuH0Z4gj/r3K4bFwzwI1ZaDwSovZZWERnxcVTwwzTqeU88mZN7ttnV3OYPWKqxokxPhtgaOdrXHeajeGSfxJEt27tNr6xr80PbkKcIoNxRoAOMKTPlvkq8kwnzwu/Qh/D03zqrkDBp6wbLjv6eYSYMt7r60f7w1ymyzALJWUK1qTUh4Tu9VA7RQ6TkdETPLwbVYkDNfs2H0R6nCSrVITKN+KRg1uOeb1wWa7j7a2lT1E0HnxzlWAFYJ1+uA/xkNHbwjG9j+0YOwAyBOh4SXo8Yt7LltBAz+AdZiYOwavL0jTe4YSoTlNfBHlV7MAsOsTZQ2Z+VSjACoZDbv9xLeGYDUgS5yj5YLlq+fgZiPeMdSc9XqKjWieZjmY96xhzL+/J7N9gnX6GLjN/7grIWwXvi2dVZKBJM1fMst32H9n3qqyYgWBBe+3vZPSJJ55PweGHWTHoDGFwvZ+IWvTsM9AJsFEuEsvEJzaqC3jHNWcFfhuSDjiTcQ57yF4Jm1BZmK1/pRgn1t/yR9cJC99z/7faD+bW5jLaVOfnEEgVCNHWNoUhhbveyIvLP1JXLkRyl+bRIfeo+eNWrinPIGvxALFHsTTmIYkt0AyHDEevI7fEDzTt7D3lHm5Z0lVez71OeoSuzcJb9ANsjcHYSTcJWtHv19tyiVbPaijA+1M7xzv7mHWY5YqpY+Him1GBk7M5Ug5sQI1KrMLgvpMep8b2nZhP9Z9P3GA7LM7/M4FCULcoRy1mCgNqgZ5pb7lERhOt0+Z9V0Te6ZFFfa2+FW6B7F3rRp/UZDuul2bQ9Uqip/hewlqsw6yWexxeMbv+tGKbCb6PPttWwhnM1xGc05ucbq5TNG504cDQhcC3RhMbqORdp/s9StwlRIPX3PWOvQ2Sv6CO9K5fAIMtH0CPhsrK1n88bM3h70RH8PzIAbmID1Ja/ncNOQW3N0mvrUotd1AMWSzEU3nMFmbpA9AF+fw6swJaRlXKFJn5d/lA9p0aY9tJeTzVPVod1MH1d6mwnjOBG5tYDRDM9VjBFbb/VAjotnVrgUaNd4JQmxbvEyM2gyCeDx0Ik15EIvU++nQ0h5QaccOH5YfXG5HYSfpj+iUYYYzgsnUjnlR7xcJXIRT9bMzr4nlFqloHrX5591B7Xn2JVEDvekEPfzYG57CqwupSnrQJLn X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6986 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: c9ef84ec-4a67-486a-e208-08d8fe5523d4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ib5FsK1AnZFGd0lLFcyjSeJkNTlLbzskjTMXQ/0dp90EvqbwglCZTQmvPP/w5x1o6YUzMrfpqmCqcegIBVoBGur05GXbHGy6bADSbmrnN2TrnhNIUnrLN20EbUeGl29oFkPFi8yEWZE1GrBvKSEHgWZyzAUY6TvzVHvsWeUTMEZHHrPyyPLurOk6ydUFAQZh5dZo8dlH6lPO1lZ7Zd84SdjQP2tvOaFJsZUyRwo14TzOCIeS0OzYHfOP7D+x+syyvT3h80M2t3O6xBYUUho0raTCm9g8am0qtD+8Wvxom5ESEw3lxvop4rVzJ3PTYMg3CXbq1D5cDiuWN9vh2gWLqLg++fXp1R7eVM782FsuMb9sHS8OEK/dSpn0TuATotFRKkKsKWtbtJcXRihhWro0QV5wyQTwd2rk19+bhhuOGbKar6azmE1OoTh2pi1DJRE8RjNlDsm3gHamKCPh0xfOPF5jsFip1qAUJuZxhwfn/Qx4T7D2mdRXemt73zQypi48G1D3BSSWlaXbb1evSJzUAHeQTsVhd7l/Stu28fGGFgTQNvdmOqJ7lMlCbcAgvfVhOWYTrbQNujw/h3HPQe//Nry+FZPhNPtPCysBm45anVFEH/cfB4ALF1Cd0zCsqcXo5Ic9kRlNA1bGdohEOsE5LczPXhN61KYIYCGoNfXdsffwTw50BktWtsiwY8NJL3+6jM6CjFuS93sJ+GEh/BYdEZ1h/kZyfMKNx9fzZHhFELg+HTuDplqsXAyQq7G8DqVXHGHN9JBDWUxca7oO9jqqqA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(376002)(396003)(346002)(39860400002)(46966006)(36840700001)(83380400001)(69590400012)(6666004)(36860700001)(86362001)(8936002)(956004)(6916009)(6506007)(186003)(16526019)(26005)(81166007)(2906002)(2616005)(336012)(8676002)(478600001)(5660300002)(36756003)(356005)(44832011)(70206006)(316002)(70586007)(82740400003)(6512007)(47076005)(6486002)(82310400003)(30864003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:21:42.8317 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e565f0f-85f5-4886-f5af-08d8fe552b8a X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB5904 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Like in commit e75711ebfa976d5468ec292282566a18b07e4d67 for x86_64, remove unused lazy tlsdesc relocation processing code: _dl_tlsdesc_resolve_abs_plus_addend _dl_tlsdesc_resolve_rel _dl_tlsdesc_resolve_rela _dl_tlsdesc_resolve_hold --- sysdeps/i386/dl-tlsdesc.S | 156 ------------------------- sysdeps/i386/dl-tlsdesc.h | 6 +- sysdeps/i386/tlsdesc.c | 231 +------------------------------------- 3 files changed, 2 insertions(+), 391 deletions(-) diff --git a/sysdeps/i386/dl-tlsdesc.S b/sysdeps/i386/dl-tlsdesc.S index e781d973b7..255fe88651 100644 --- a/sysdeps/i386/dl-tlsdesc.S +++ b/sysdeps/i386/dl-tlsdesc.S @@ -134,159 +134,3 @@ _dl_tlsdesc_dynamic: cfi_endproc .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic #endif /* SHARED */ - - /* This function is a wrapper for a lazy resolver for TLS_DESC - REL relocations that reference the *ABS* segment in their own - link maps. %ebx points to the caller's GOT. %eax points to a - TLS descriptor, such that 0(%eax) holds the address of the - resolver wrapper itself (unless some other thread beat us to - it) and 4(%eax) holds the addend in the relocation. - - When the actual resolver returns, it will have adjusted the - TLS descriptor such that we can tail-call it for it to return - the TP offset of the symbol. */ - - .hidden _dl_tlsdesc_resolve_abs_plus_addend - .global _dl_tlsdesc_resolve_abs_plus_addend - .type _dl_tlsdesc_resolve_abs_plus_addend,@function - cfi_startproc - .align 16 -_dl_tlsdesc_resolve_abs_plus_addend: -0: - _CET_ENDBR - pushl %eax - cfi_adjust_cfa_offset (4) - pushl %ecx - cfi_adjust_cfa_offset (4) - pushl %edx - cfi_adjust_cfa_offset (4) - movl $1f - 0b, %ecx - movl 4(%ebx), %edx - call _dl_tlsdesc_resolve_abs_plus_addend_fixup -1: - popl %edx - cfi_adjust_cfa_offset (-4) - popl %ecx - cfi_adjust_cfa_offset (-4) - popl %eax - cfi_adjust_cfa_offset (-4) - jmp *(%eax) - cfi_endproc - .size _dl_tlsdesc_resolve_abs_plus_addend, .-_dl_tlsdesc_resolve_abs_plus_addend - - /* This function is a wrapper for a lazy resolver for TLS_DESC - REL relocations that had zero addends. %ebx points to the - caller's GOT. %eax points to a TLS descriptor, such that - 0(%eax) holds the address of the resolver wrapper itself - (unless some other thread beat us to it) and 4(%eax) holds a - pointer to the relocation. - - When the actual resolver returns, it will have adjusted the - TLS descriptor such that we can tail-call it for it to return - the TP offset of the symbol. */ - - .hidden _dl_tlsdesc_resolve_rel - .global _dl_tlsdesc_resolve_rel - .type _dl_tlsdesc_resolve_rel,@function - cfi_startproc - .align 16 -_dl_tlsdesc_resolve_rel: -0: - _CET_ENDBR - pushl %eax - cfi_adjust_cfa_offset (4) - pushl %ecx - cfi_adjust_cfa_offset (4) - pushl %edx - cfi_adjust_cfa_offset (4) - movl $1f - 0b, %ecx - movl 4(%ebx), %edx - call _dl_tlsdesc_resolve_rel_fixup -1: - popl %edx - cfi_adjust_cfa_offset (-4) - popl %ecx - cfi_adjust_cfa_offset (-4) - popl %eax - cfi_adjust_cfa_offset (-4) - jmp *(%eax) - cfi_endproc - .size _dl_tlsdesc_resolve_rel, .-_dl_tlsdesc_resolve_rel - - /* This function is a wrapper for a lazy resolver for TLS_DESC - RELA relocations. %ebx points to the caller's GOT. %eax - points to a TLS descriptor, such that 0(%eax) holds the - address of the resolver wrapper itself (unless some other - thread beat us to it) and 4(%eax) holds a pointer to the - relocation. - - When the actual resolver returns, it will have adjusted the - TLS descriptor such that we can tail-call it for it to return - the TP offset of the symbol. */ - - .hidden _dl_tlsdesc_resolve_rela - .global _dl_tlsdesc_resolve_rela - .type _dl_tlsdesc_resolve_rela,@function - cfi_startproc - .align 16 -_dl_tlsdesc_resolve_rela: -0: - _CET_ENDBR - pushl %eax - cfi_adjust_cfa_offset (4) - pushl %ecx - cfi_adjust_cfa_offset (4) - pushl %edx - cfi_adjust_cfa_offset (4) - movl $1f - 0b, %ecx - movl 4(%ebx), %edx - call _dl_tlsdesc_resolve_rela_fixup -1: - popl %edx - cfi_adjust_cfa_offset (-4) - popl %ecx - cfi_adjust_cfa_offset (-4) - popl %eax - cfi_adjust_cfa_offset (-4) - jmp *(%eax) - cfi_endproc - .size _dl_tlsdesc_resolve_rela, .-_dl_tlsdesc_resolve_rela - - /* This function is a placeholder for lazy resolving of TLS - relocations. Once some thread starts resolving a TLS - relocation, it sets up the TLS descriptor to use this - resolver, such that other threads that would attempt to - resolve it concurrently may skip the call to the original lazy - resolver and go straight to a condition wait. - - When the actual resolver returns, it will have adjusted the - TLS descriptor such that we can tail-call it for it to return - the TP offset of the symbol. */ - - .hidden _dl_tlsdesc_resolve_hold - .global _dl_tlsdesc_resolve_hold - .type _dl_tlsdesc_resolve_hold,@function - cfi_startproc - .align 16 -_dl_tlsdesc_resolve_hold: -0: - _CET_ENDBR - pushl %eax - cfi_adjust_cfa_offset (4) - pushl %ecx - cfi_adjust_cfa_offset (4) - pushl %edx - cfi_adjust_cfa_offset (4) - movl $1f - 0b, %ecx - movl 4(%ebx), %edx - call _dl_tlsdesc_resolve_hold_fixup -1: - popl %edx - cfi_adjust_cfa_offset (-4) - popl %ecx - cfi_adjust_cfa_offset (-4) - popl %eax - cfi_adjust_cfa_offset (-4) - jmp *(%eax) - cfi_endproc - .size _dl_tlsdesc_resolve_hold, .-_dl_tlsdesc_resolve_hold diff --git a/sysdeps/i386/dl-tlsdesc.h b/sysdeps/i386/dl-tlsdesc.h index 753c03e79c..12e90da3a8 100644 --- a/sysdeps/i386/dl-tlsdesc.h +++ b/sysdeps/i386/dl-tlsdesc.h @@ -43,11 +43,7 @@ struct tlsdesc_dynamic_arg extern ptrdiff_t attribute_hidden __attribute__ ((regparm (1))) _dl_tlsdesc_return (struct tlsdesc *), - _dl_tlsdesc_undefweak (struct tlsdesc *), - _dl_tlsdesc_resolve_abs_plus_addend (struct tlsdesc *), - _dl_tlsdesc_resolve_rel (struct tlsdesc *), - _dl_tlsdesc_resolve_rela (struct tlsdesc *), - _dl_tlsdesc_resolve_hold (struct tlsdesc *); + _dl_tlsdesc_undefweak (struct tlsdesc *); # ifdef SHARED extern void *_dl_make_tlsdesc_dynamic (struct link_map *map, diff --git a/sysdeps/i386/tlsdesc.c b/sysdeps/i386/tlsdesc.c index 0bc646541f..436a21f66b 100644 --- a/sysdeps/i386/tlsdesc.c +++ b/sysdeps/i386/tlsdesc.c @@ -16,242 +16,13 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include #include #include #include +#define _dl_tlsdesc_resolve_hold 0 #include -/* The following 4 functions take an entry_check_offset argument. - It's computed by the caller as an offset between its entry point - and the call site, such that by adding the built-in return address - that is implicitly passed to the function with this offset, we can - easily obtain the caller's entry point to compare with the entry - point given in the TLS descriptor. If it's changed, we want to - return immediately. */ - -/* This function is used to lazily resolve TLS_DESC REL relocations - that reference the *ABS* segment in their own link maps. The - argument is the addend originally stored there. */ - -void -__attribute__ ((regparm (3))) attribute_hidden -_dl_tlsdesc_resolve_abs_plus_addend_fixup (struct tlsdesc volatile *td, - struct link_map *l, - ptrdiff_t entry_check_offset) -{ - ptrdiff_t addend = (ptrdiff_t) td->arg; - - if (_dl_tlsdesc_resolve_early_return_p (td, __builtin_return_address (0) - - entry_check_offset)) - return; - -#ifndef SHARED - CHECK_STATIC_TLS (l, l); -#else - if (!TRY_STATIC_TLS (l, l)) - { - td->arg = _dl_make_tlsdesc_dynamic (l, addend); - td->entry = _dl_tlsdesc_dynamic; - } - else -#endif - { - td->arg = (void*) (addend - l->l_tls_offset); - td->entry = _dl_tlsdesc_return; - } - - _dl_tlsdesc_wake_up_held_fixups (); -} - -/* This function is used to lazily resolve TLS_DESC REL relocations - that originally had zero addends. The argument location, that - originally held the addend, is used to hold a pointer to the - relocation, but it has to be restored before we call the function - that applies relocations. */ - -void -__attribute__ ((regparm (3))) attribute_hidden -_dl_tlsdesc_resolve_rel_fixup (struct tlsdesc volatile *td, - struct link_map *l, - ptrdiff_t entry_check_offset) -{ - const ElfW(Rel) *reloc = td->arg; - - if (_dl_tlsdesc_resolve_early_return_p (td, __builtin_return_address (0) - - entry_check_offset)) - return; - - /* The code below was borrowed from _dl_fixup(), - except for checking for STB_LOCAL. */ - const ElfW(Sym) *const symtab - = (const void *) D_PTR (l, l_info[DT_SYMTAB]); - const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]); - const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)]; - lookup_t result; - - /* Look up the target symbol. If the normal lookup rules are not - used don't look in the global scope. */ - if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL - && __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0) - { - const struct r_found_version *version = NULL; - - if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL) - { - const ElfW(Half) *vernum = - (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]); - ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff; - version = &l->l_versions[ndx]; - if (version->hash == 0) - version = NULL; - } - - result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym, - l->l_scope, version, ELF_RTYPE_CLASS_PLT, - DL_LOOKUP_ADD_DEPENDENCY, NULL); - } - else - { - /* We already found the symbol. The module (and therefore its load - address) is also known. */ - result = l; - } - - if (!sym) - { - td->arg = 0; - td->entry = _dl_tlsdesc_undefweak; - } - else - { -# ifndef SHARED - CHECK_STATIC_TLS (l, result); -# else - if (!TRY_STATIC_TLS (l, result)) - { - td->arg = _dl_make_tlsdesc_dynamic (result, sym->st_value); - td->entry = _dl_tlsdesc_dynamic; - } - else -# endif - { - td->arg = (void*)(sym->st_value - result->l_tls_offset); - td->entry = _dl_tlsdesc_return; - } - } - - _dl_tlsdesc_wake_up_held_fixups (); -} - -/* This function is used to lazily resolve TLS_DESC RELA relocations. - The argument location is used to hold a pointer to the relocation. */ - -void -__attribute__ ((regparm (3))) attribute_hidden -_dl_tlsdesc_resolve_rela_fixup (struct tlsdesc volatile *td, - struct link_map *l, - ptrdiff_t entry_check_offset) -{ - const ElfW(Rela) *reloc = td->arg; - - if (_dl_tlsdesc_resolve_early_return_p (td, __builtin_return_address (0) - - entry_check_offset)) - return; - - /* The code below was borrowed from _dl_fixup(), - except for checking for STB_LOCAL. */ - const ElfW(Sym) *const symtab - = (const void *) D_PTR (l, l_info[DT_SYMTAB]); - const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]); - const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)]; - lookup_t result; - - /* Look up the target symbol. If the normal lookup rules are not - used don't look in the global scope. */ - if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL - && __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0) - { - const struct r_found_version *version = NULL; - - if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL) - { - const ElfW(Half) *vernum = - (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]); - ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff; - version = &l->l_versions[ndx]; - if (version->hash == 0) - version = NULL; - } - - result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym, - l->l_scope, version, ELF_RTYPE_CLASS_PLT, - DL_LOOKUP_ADD_DEPENDENCY, NULL); - } - else - { - /* We already found the symbol. The module (and therefore its load - address) is also known. */ - result = l; - } - - if (!sym) - { - td->arg = (void*) reloc->r_addend; - td->entry = _dl_tlsdesc_undefweak; - } - else - { -# ifndef SHARED - CHECK_STATIC_TLS (l, result); -# else - if (!TRY_STATIC_TLS (l, result)) - { - td->arg = _dl_make_tlsdesc_dynamic (result, sym->st_value - + reloc->r_addend); - td->entry = _dl_tlsdesc_dynamic; - } - else -# endif - { - td->arg = (void*) (sym->st_value - result->l_tls_offset - + reloc->r_addend); - td->entry = _dl_tlsdesc_return; - } - } - - _dl_tlsdesc_wake_up_held_fixups (); -} - -/* This function is used to avoid busy waiting for other threads to - complete the lazy relocation. Once another thread wins the race to - relocate a TLS descriptor, it sets the descriptor up such that this - function is called to wait until the resolver releases the - lock. */ - -void -__attribute__ ((regparm (3))) attribute_hidden -_dl_tlsdesc_resolve_hold_fixup (struct tlsdesc volatile *td, - struct link_map *l __attribute__((__unused__)), - ptrdiff_t entry_check_offset) -{ - /* Maybe we're lucky and can return early. */ - if (__builtin_return_address (0) - entry_check_offset != td->entry) - return; - - /* Locking here will stop execution until the running resolver runs - _dl_tlsdesc_wake_up_held_fixups(), releasing the lock. - - FIXME: We'd be better off waiting on a condition variable, such - that we didn't have to hold the lock throughout the relocation - processing. */ - __rtld_lock_lock_recursive (GL(dl_load_lock)); - __rtld_lock_unlock_recursive (GL(dl_load_lock)); -} - - /* Unmap the dynamic object, but also release its TLS descriptor table if there is one. */ From patchwork Tue Apr 13 08:21:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465624 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=xXPzMGQj; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJVq3mv5z9sW1 for ; Tue, 13 Apr 2021 18:22:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3842D3968C05; Tue, 13 Apr 2021 08:22:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3842D3968C05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302129; bh=GlFM7+eu7q7Mas5jSCHnPd865/l2fjscVEpXXLt/aRA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xXPzMGQjWLruLZlEwNnn/oWT283RpgB+RgaQJkA2GacWQ+1Q0uLKvsPLUrK33yZYk d6PNWk6dV2kPJqIWj8Ogex9n1BahVxlQNB3jUrw7nbn73tE9K9UuLW6FULzG69RJ/C M6OOwVT15691L5imrlUTr6tekoCzdigNEtj/qCSU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30044.outbound.protection.outlook.com [40.107.3.44]) by sourceware.org (Postfix) with ESMTPS id 703803968C01 for ; Tue, 13 Apr 2021 08:22:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 703803968C01 Received: from AM6PR08CA0028.eurprd08.prod.outlook.com (2603:10a6:20b:c0::16) by PA4PR08MB5903.eurprd08.prod.outlook.com (2603:10a6:102:e9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Tue, 13 Apr 2021 08:22:03 +0000 Received: from AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:c0:cafe::30) by AM6PR08CA0028.outlook.office365.com (2603:10a6:20b:c0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:22:03 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT007.mail.protection.outlook.com (10.152.16.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:22:03 +0000 Received: ("Tessian outbound b610e7b4d771:v90"); Tue, 13 Apr 2021 08:22:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e190c997b9ad551c X-CR-MTA-TID: 64aa7808 Received: from 1df9d9039700.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 834660C6-989C-4E33-82ED-40B0647F3EF3.1; Tue, 13 Apr 2021 08:21:55 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 1df9d9039700.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:21:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j4gl3jwEG26kk84xcWp8vLO6ZSCo1TIIbZYgI+RE6WjMxS3WzM0FafHP77RiLtwVRHLG36MteLOAbZBbWmonNTrG/WgFlK3w9dDrfpDkaf20fptGCQcchLid1BDyGEp+uQePQsTBylfC0jCOZ+A7p0suTrI3Yca9nHgRaA8Ec/sVrLVI0tVuw8SIXe+ju6oO867CGp5Ldb2WfTuyW6ObgA9XbXncQtBEdBpEHUwGAJdz5btgpz4sjb/0KOsiNGE7/Q8R/O/4ftvRZko6AbM4YrpdgjLP6kq1c8jtBSaan4T+Vc8Sm3Xtl9r0/oiftNC2cBZrKjV12iL7+XLAwys7gg== 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=GlFM7+eu7q7Mas5jSCHnPd865/l2fjscVEpXXLt/aRA=; b=di3otYMW+2IMl4Uozc8CpMaMe5+d8DDQFf6+8rtqo5iT/GM7ubRlg/bITO7fiTRNAHudY5eHCGqXPtVu7N35dRibiVkMA4ViaaB8tQsxvz9JJufRtHAOf2/Aof24G+16/aC5bBQzfX10D1+GlPVABVUDaQaSN0RYA4kHnwYSsIl1oC/NTWvCSsG9Zl2UvbN3SbIVO3ssF7gE/RHbY0rrCpZIelJK0yvt3ZXPvsp56lzBdlerch6IDZuvqrQFQc63i+gcN8PQ6tmN0vaqni+iC3QRabTzZ5B+5Nr7Qlna/x8xJIFtoV8a7PAEIOwQVvS+dBLZN0KiGQhaps7/ROkM1g== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PA4PR08MB6237.eurprd08.prod.outlook.com (2603:10a6:102:f3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:21:47 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:21:47 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 13/14] elf: Remove lazy tlsdesc relocation related code Date: Tue, 13 Apr 2021 09:21:41 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LNXP123CA0016.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::28) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LNXP123CA0016.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:21:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f7897c79-bdd5-46dc-1b00-08d8fe5537c4 X-MS-TrafficTypeDiagnostic: PA4PR08MB6237:|PA4PR08MB5903: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: tzlIvXC9c9IJ5zl2GazIu/wWTeK8gKW4zNEMQwPD672fw6XMJVkCp1EE1WbWyxc4y7Rck33a5/lS4Vlfe9bF1KJGOZVw6Kjqjv0oWpXyxEI0ra1ycCO9yDuyUUTL0oJYxcHsIuGnLCBmSZc3/fn0jdUDN9lYhJ5mhko+5R4l8d1zjscA6Bzso2s58zYH1hyCqYkd4KKM4gRi+SrxlnKm4uu5ju8IV8PvbF8pDtyKIGfI96MSjFNJ19GWOApq4vgvjUeCWQRNzmn+Ol5M/w+MIBwI5OEb5BJGZ+KPPNkSLzvjL24sgbQO885Ld05as+LD9igr3JI6GpU/UAtyYkHOWwPbdwYvHSDr7ZrTbUrUBjiN1bkMu/ueVbPlx4DQPBv1NcUwIFCn3fJRHWIQpt0+q2ACa6W3Apk/g6Pi0JW4V8UuU6dBOj16dwWtebIHfKa4DUypUnFqsBdDdyKZuh06L5XiDiDTtxx/1emvkyNldK4uROXOGo3uHofdyT4hhNI6aB60OvOQlSB65p0+3uFzlp/w3IzP/eUZ3WyZg/komujmgI45+Jx9dgrJtJjRLhf0/BDiBRX89YG3rObFYA7O2qXJ+wuk/9YJK81IspTRc6dwRx5v696IwHu8g7lnsqfxcEJ1IF0cNDWqWx0GsNcWpKfIFZAcj3sjjVsVQZbXuFYQOTC78XZa9VzrcePcW8GU X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(8936002)(86362001)(2906002)(6486002)(66946007)(16526019)(8676002)(38100700002)(38350700002)(316002)(478600001)(44832011)(6506007)(186003)(6666004)(66476007)(6916009)(2616005)(36756003)(5660300002)(66556008)(6512007)(83380400001)(956004)(69590400012)(52116002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6FVKaoYBdy5DiGVsCx9jn0E3R1lU5uAhYWG4Z8tMKcPVCbDx1WfyqIGq3iWTYA5H4WuSPfXPMIfvEA3mvbyEc5r1WIHg7liW0McTVqZ4RF6N51MpLAt92HRohZH08Q13A54bXzvishEo9qDI/uRJhuNIVmviAJCpoS8Xj7YBqGUsBGdZNu5hojNB2YXCB4AZTpr6eEYIofpdDyRcY1+GYjDvCRvYu6j+kQLKuYC9EYoR7H1IRcfdFUsEmFkeT0XHiaufk6RTOu6mXU+aqj+1lHiCKKjZ6SLVORKU0oixj4hza4eCEpS6f9By0CRGEz/VQrFeAoCiM7LaPrc6L49FM5IkA1p8sXDFIAsbyoZlAynlVYYYxnfmf7X4HYWUaJykg0DjJr8VJvRjV7jPWaBnF0icm6ajG9TyGshZb+nheaq+otQHL27NIkkcGheRC2ptPofgM9WNp/CI/CtsecCQmZVL9M51WyCytpXoiYoRgQpr83mpurohWQseVEkSSHvaVjktYLAgo8DG7QAChu2q4qNY711Ah5u05eke4ac3vMHatqRGJPk9aV+YGlIRQWQY0OVMFKHfQE6FeU3kWKPONdGYtxRXal/ip96KUMzcsG1KhdLQaGkr7I4aSB6tMToW0p34+UnaHcubQTyRhaIz2C6tKEZilnUz5l9ex2Q2eSVlqoKyMdel0MpGznjYMvvFyzqtg+ZNP/shkDl1QDuksQeJgJ62pUXjtJ0DENz/tGcfutg13BmGKxcJKYR+VteZhqt/T5MkNkVvDN0taYV4s5s7lKWsjN9BKSY1AzjSNXLxtQJeqWp9YKmo+kc3/zlswf/GqkYQZFIdgM7LOQHlA2rh9CKFP8pNR0GCf0gN8W5DlWrbhgWHvUMTLpoYqTU7pviaB6iOKZYWgpc2xmNoQ2aMkLqbvHD9Ak2moel5dcmXCrrSz7zhwBicaYaeFZ5BhLHiRHm5xRvaJasjgDYAsKnCM7EMlEHrP3dCY5zuCZt/RrHLydhUzTYq5NG29G0ya1m+zGhW67davUKDObgQ0oIlqzJFzeP9G/KbF4pqakaWh/j/52yAJCtCeItA5mNDJuN9e4lrpQ2Pj0fdBlsxJEjtwGyb/4dgeLgGxIu+jnyzrDGgAfCdgoCfk6ECZzpVhegoo0zMh5N+4x2Upl2vDqBwwsPZyIw8DthKTrPcB80P4Vwxtk/HjLxo0CpOtLEdF7Ris23y2igNqfU4Aw9L91e3xVjcQnGDeVZS+XrUlz7IJGBmvXG/4KCf3BjK9twGmcFAP1vvxTm65SvYgQLKL+dC5rMBPRX00YcfURCPgS0ReJM3u6tjAYo2f+06tJaU X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6237 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 8a6dca6e-8f12-458d-cbfe-08d8fe552e24 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v2A4ZA1Jf/lK2gcszSoL5zzMN6B7POkzrRbu3n8FFPyXYF8l44t1zDyjvCjYF99G3LPPCVz5WOyR+YRIWN8KqnXmRxzO1lncj/Bz30iCvvSheq5HdMroCM7LhhZTNbk2QoNvbMohkFx7HD4mxBGhUEsDyUsLzw5EnUYpoK6bkq8N+2W/Kv+4VhhYfFukFV11v7qUIk2cBHcO/49fMuAZ3WzQgrwzLWQmn33KmgF+g9asOrBBVGVEN4BCLSTSj4/Y4KU8hL+Xhs0eFAtOvvOe59ZJ0VpGO6UyDV4brBax6HVnbL9qaRU9qDdNBnoeyptyJ5i1uR+d/3zMeScrED1JvGtQYL+r1j1jCAlOplbsd+aOR06XNinTdHfHFuLl9a1S7mo3XQVcAPPhLaN0vjf77Rf/upoyK08NWHYwpC3SbzDUJuMPuAKR8A8g8REkH8E3cOm4uB02vVItXKK7XWMnNev8Wh5AMM5oY2sZTcAM1qT5vyHYHjYETPMFfr6mXEJt4Lvg6L5mFjYduTtG3e9LOjTaCixAaetP95oEbRvvFsky6naKDmNi71z7mbQH8luJX3r3vS1EaVpkk6FR1DhkYWReTYU7k9PrwaY40dTj2K61yvCQIztq66jCBHEP3rFSG3dLVn4/sk2dd0VzE2AKp9KlfiHJTCGAm1gZ2xUuLYLmnAOBtQua830EjhJzCpPH X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(346002)(396003)(39860400002)(136003)(376002)(46966006)(36840700001)(478600001)(44832011)(316002)(82740400003)(336012)(6506007)(6666004)(8936002)(36756003)(81166007)(83380400001)(186003)(8676002)(16526019)(356005)(36860700001)(6916009)(956004)(70206006)(6512007)(82310400003)(2616005)(6486002)(69590400012)(70586007)(5660300002)(86362001)(26005)(47076005)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:22:03.3619 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7897c79-bdd5-46dc-1b00-08d8fe5537c4 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB5903 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Remove generic tlsdesc code related to lazy tlsdesc processing since lazy tlsdesc relocation is no longer supported. This includes removing GL(dl_load_lock) from _dl_make_tlsdesc_dynamic which is only called at load time when that lock is already held. Added a documentation comment too. Reviewed-by: Adhemerval Zanella --- elf/tlsdeschtab.h | 53 +++++---------------------------------- sysdeps/aarch64/tlsdesc.c | 1 - sysdeps/arm/tlsdesc.c | 1 - sysdeps/i386/tlsdesc.c | 1 - sysdeps/x86_64/tlsdesc.c | 1 - 5 files changed, 6 insertions(+), 51 deletions(-) diff --git a/elf/tlsdeschtab.h b/elf/tlsdeschtab.h index 21695fd1e9..85bd0415e1 100644 --- a/elf/tlsdeschtab.h +++ b/elf/tlsdeschtab.h @@ -78,6 +78,10 @@ map_generation (struct link_map *map) return GL(dl_tls_generation) + 1; } +/* Returns the data pointer for a given map and tls offset that is used + to fill in one of the GOT entries referenced by a TLSDESC relocation + when using dynamic TLS. This requires allocation, returns NULL on + allocation failure. */ void * _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset) { @@ -85,18 +89,12 @@ _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset) void **entry; struct tlsdesc_dynamic_arg *td, test; - /* FIXME: We could use a per-map lock here, but is it worth it? */ - __rtld_lock_lock_recursive (GL(dl_load_lock)); - ht = map->l_mach.tlsdesc_table; if (! ht) { ht = htab_create (); if (! ht) - { - __rtld_lock_unlock_recursive (GL(dl_load_lock)); - return 0; - } + return 0; map->l_mach.tlsdesc_table = ht; } @@ -104,15 +102,11 @@ _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset) test.tlsinfo.ti_offset = ti_offset; entry = htab_find_slot (ht, &test, 1, hash_tlsdesc, eq_tlsdesc); if (! entry) - { - __rtld_lock_unlock_recursive (GL(dl_load_lock)); - return 0; - } + return 0; if (*entry) { td = *entry; - __rtld_lock_unlock_recursive (GL(dl_load_lock)); return td; } @@ -122,44 +116,9 @@ _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset) thread. */ td->gen_count = map_generation (map); td->tlsinfo = test.tlsinfo; - - __rtld_lock_unlock_recursive (GL(dl_load_lock)); return td; } # endif /* SHARED */ -/* The idea of the following two functions is to stop multiple threads - from attempting to resolve the same TLS descriptor without busy - waiting. Ideally, we should be able to release the lock right - after changing td->entry, and then using say a condition variable - or a futex wake to wake up any waiting threads, but let's try to - avoid introducing such dependencies. */ - -static int -__attribute__ ((unused)) -_dl_tlsdesc_resolve_early_return_p (struct tlsdesc volatile *td, void *caller) -{ - if (caller != atomic_load_relaxed (&td->entry)) - return 1; - - __rtld_lock_lock_recursive (GL(dl_load_lock)); - if (caller != atomic_load_relaxed (&td->entry)) - { - __rtld_lock_unlock_recursive (GL(dl_load_lock)); - return 1; - } - - atomic_store_relaxed (&td->entry, _dl_tlsdesc_resolve_hold); - - return 0; -} - -static void -__attribute__ ((unused)) -_dl_tlsdesc_wake_up_held_fixups (void) -{ - __rtld_lock_unlock_recursive (GL(dl_load_lock)); -} - #endif diff --git a/sysdeps/aarch64/tlsdesc.c b/sysdeps/aarch64/tlsdesc.c index 9b6a8b0ec4..3c1bcd8fe6 100644 --- a/sysdeps/aarch64/tlsdesc.c +++ b/sysdeps/aarch64/tlsdesc.c @@ -22,7 +22,6 @@ #include #include #include -#define _dl_tlsdesc_resolve_hold 0 #include /* Unmap the dynamic object, but also release its TLS descriptor table diff --git a/sysdeps/arm/tlsdesc.c b/sysdeps/arm/tlsdesc.c index 2f70adef5c..b3d1735af4 100644 --- a/sysdeps/arm/tlsdesc.c +++ b/sysdeps/arm/tlsdesc.c @@ -20,7 +20,6 @@ #include #include #include -#define _dl_tlsdesc_resolve_hold 0 #include /* Unmap the dynamic object, but also release its TLS descriptor table diff --git a/sysdeps/i386/tlsdesc.c b/sysdeps/i386/tlsdesc.c index 436a21f66b..364c7769ce 100644 --- a/sysdeps/i386/tlsdesc.c +++ b/sysdeps/i386/tlsdesc.c @@ -20,7 +20,6 @@ #include #include #include -#define _dl_tlsdesc_resolve_hold 0 #include /* Unmap the dynamic object, but also release its TLS descriptor table diff --git a/sysdeps/x86_64/tlsdesc.c b/sysdeps/x86_64/tlsdesc.c index ecf864d6ee..3bb80517a3 100644 --- a/sysdeps/x86_64/tlsdesc.c +++ b/sysdeps/x86_64/tlsdesc.c @@ -20,7 +20,6 @@ #include #include #include -#define _dl_tlsdesc_resolve_hold 0 #include /* Unmap the dynamic object, but also release its TLS descriptor table From patchwork Tue Apr 13 08:21:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1465625 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=KpltnXzC; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKJW35VG9z9sVw for ; Tue, 13 Apr 2021 18:22:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C50523968C0B; Tue, 13 Apr 2021 08:22:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C50523968C0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618302141; bh=sddYzLpHANSzgprb5caHzWCdxa83Q2vJxLwexOolJfM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KpltnXzCUs+4hpb5FJm12FK2q1tstDBf5jTn0gr+pFtviGj5w4cGqbpKD4QAUmcBU R5moU5EWJIqbtMvWobkYLb9QN0VwVXuGmqUj3Niat+Ad7JhJkg84+0n11hecPuDpdi LRjfMwKX4H+65d6XAxIN+7iXMQUWaRV7ODaVVDcE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140082.outbound.protection.outlook.com [40.107.14.82]) by sourceware.org (Postfix) with ESMTPS id 181CB3968C0B for ; Tue, 13 Apr 2021 08:22:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 181CB3968C0B Received: from DB6PR0801CA0049.eurprd08.prod.outlook.com (2603:10a6:4:2b::17) by AM6PR08MB4470.eurprd08.prod.outlook.com (2603:10a6:20b:b5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.18; Tue, 13 Apr 2021 08:22:13 +0000 Received: from DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:2b:cafe::8) by DB6PR0801CA0049.outlook.office365.com (2603:10a6:4:2b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 13 Apr 2021 08:22:13 +0000 X-MS-Exchange-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=pass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT051.mail.protection.outlook.com (10.152.21.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:22:13 +0000 Received: ("Tessian outbound 82c2d58b350b:v90"); Tue, 13 Apr 2021 08:22:13 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 230df4b0c435bb40 X-CR-MTA-TID: 64aa7808 Received: from 39efff76f572.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DCC7E601-A10E-4E70-BEF8-C832CF13FA2A.1; Tue, 13 Apr 2021 08:22:06 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 39efff76f572.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:22:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NgcGCpy9Qc4luuwZEBuMKSyitglk8uCH4eddp/6VVVdTvXhiS+NaeHJde9Ht2EcUbKcHHQN4s5E0WOfZx5i4O7UioNcaNw3Be0kmsA5LCGfl/DLuFM7pxQcI5wCIJJKa3LntXgULxKDacFxs0qVSb2hmoGYQeL+B5W9tQ/zj0M1s2JTltgXFlMTyscGj3DDRqVF7sn5mhHd/9wFJPmAD2xbSASPVgJgx8trlgDPnHsGXsmWbu7e4PNECKLM5B2CwyF0O2VPynTkhDSDrPxu3Ur9vxOS+eDomCBMsxygRHdvrvpqv+DRHSkwwhQCQAD9foxtuOTbamvuNdsR6eUZknw== 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=sddYzLpHANSzgprb5caHzWCdxa83Q2vJxLwexOolJfM=; b=UtXPrV6R3pFe8qMiz5wZOTBplVQCPWYbPVT5SUR3c2yo86FlbBruuh+6sMlzdUpmtxhypdm1hwW1ibUEXCdE+SGg0+0jw9YOpkWSGYsP2MmNVnHi76eb1Cmbn5b/deYxLKn/f3tUpVKyJeUGkw+JaX9GJHDGxClMOdK8GwmEvkm/gBoqTgvm6ncZDLmwygifX1KkeEbA3leBim9vP5hyupXM+AEsW9o+/SosvQ1c5teODTnGRL7uxMe8/T2ISHZCAbRnGNAyhy84sNHn0Jfj/PI2FhufvR9HsUj0z+N6DsEBKtSP6cNNClu4o7owy89iDMCzdtR/KONKDUygVY2Ocg== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PA4PR08MB6237.eurprd08.prod.outlook.com (2603:10a6:102:f3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:22:04 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:22:04 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 14/14] RFC elf: Fix slow tls access after dlopen [BZ #19924] Date: Tue, 13 Apr 2021 09:21:58 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO4P123CA0401.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::10) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO4P123CA0401.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21 via Frontend Transport; Tue, 13 Apr 2021 08:22:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 577d4e60-6922-46f3-f1be-08d8fe553d83 X-MS-TrafficTypeDiagnostic: PA4PR08MB6237:|AM6PR08MB4470: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: tfw2lvZgR0EHQA9eBBkELzTHLhvwoQhzUn38LXXx7bZGSki7rXMh1fnHbhxtDubQOvKV7hCNl1NRDvP5HR9GyNijCXRGzuxpDVeQYMPUG6bVt0QaOjaAEu1/uaGmmxWw6Ur3dULrlkuhts8cXhGyX3RE/KVGb0YDFGYHzaY28T6cjnl6LVY1Ls3ucOs2UAddLhfSkIIpC3AJrVmTxtSlxDhMIrPQs+vxolVuUedHwkRfcc/2mZ6II4O3S1JVHmlIE99yMiZht9N9HZt5MsmZSU9AtcDvDw0OPnx24B/5e5muIanwYpFyhwhLUPtLqhJqtwYtf05879WvdOqOqFwJdCuQ1fOiqL0CBoTGxZGHn1+j8YNSk0PmVHIQ72jBxG/QTkm7UvfR8pXvlqxBi2KAcMfBguCqiRVsuOnRu3XxfT1sn4zPiodP4OEQwJm2nFSRGQJPRzHzeMDUNfZeAWy2+2s/gJbWZN9q72j2tjJz8LZQMtlhbL6kw+8w7Ib4JFf0413ISIsEBB++iwQ1+myj/3KrTAzWN6+0l/yeS5W82bCfab2oDIIdRK5oyR9rPv1QHT6eec+UidK1dtnvxYOGkk5GRNPwf8QN13s7JHFzdTF6SY5dsxgpdNdKn9WAKRz7Q9gk7lsJNl0suR2j3ZxEeaeh0pSQfXl+E9/e1GJTWTsxqudx/HCXgFs8/H9WuuJK X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(8936002)(86362001)(2906002)(6486002)(66946007)(16526019)(8676002)(38100700002)(38350700002)(316002)(478600001)(44832011)(6506007)(186003)(6666004)(66476007)(6916009)(2616005)(36756003)(5660300002)(66556008)(6512007)(83380400001)(956004)(69590400012)(52116002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5naDOs9/91wVNqlj2mQaX9APgHwxHQuPOCI23XQd3ZjKTIKLlIqFRDsWsB/w1EwbJVMkblz9IifZjgAgUtMsnUvp3dmqDDvzJQJ2+gu/qg4eZOOtT8qng6j5w+WC7hzeQRpRU9eL7rZWEr/NGULBfcDZ8C/dNJvE6pTZZ86a2QDl/3Seq6XcLeDeI3VB6JCRX+g/45iWPsWWbOj9M48dN+omHiSJzh5p0s542QAKJ1BzDgJ7Q1TUowvyGjzS6iHXpTx3G/CYHrkvbDmTJoFgcSJxE0VNjzz1MPP8lmttBEnf5+YvN5G9isaMUAnfxRhzcYNHQdeM5typ5j/u4aINKP5teZdodBVhoPhgcDTOIUgUGcHOPawAAc8jOftEBKXWm7fCDjGiR9hlKUXaTwourIuPn1v3MvtKS+SBj8fa7J957C1ArlnhiWeSIttIS4vzAuRFlBd22Pt8fj3sHiKpAL1p9dmOMwqiwx9PTwJraiWq40t2MvRfhmTqEfcbPesgLkEePzLVZRk1o3ixP7nxRwfq3DnhBRzvW2ghwie+0/W39iKcfONqLK2W8uf8gnUslWAyR4y63wDrANhPrPoZ+ZlLhTqpspOQcNqo3A9aau36b0mDIoIvk06ITvHlof9AOVRjzw/8OVE7blQOYBWb9J5ZJNsJnBMglEU0crnbnWWbo6543YKxgpR8s3xH1qpvq+gMrjav5ZNlGSTn3DpD78g+XYTo8RAwANTVO3pYsMZZjazO0ntL27ieONg+w1Fk7A6j28FX+ejYtgVR6nlp5fvdWZeLRf8th8Ej7kCFOcZTUw2qVx0nCJDcF+xT4wXQyDN8atGzJ37/IVQ9S9GpD+einhGL+evMqUoSc3sWsZoUm1fJPf67JDvlKgZMRTrAzLmppZqb2VtuGEq0FEsLZAsZZBvsBR6g1aQZ9oBvlidR/GeKrlp2mkFC/CruIaQq/ccq8oxMTvIClNmBc05VDPfw9yKda6OZdJMcq4KYZUnEPcLTfXKp51XfoQ6z8zisAD9dC/TYlqUzaaxK6MLjRTRpnZ546PPaklEyPgJ8v9QsY1Wy1DuxS4i4cY/7+8imK+KTa1ir9cDefXxyBiYiez7YyNaVnI9aAt8eVjMRJtz+xKQ5247ul4jJE8aOwN9RPezydDMOtQc/q12E14tQybmZpTwTucQ5YbS3B8KAGhIGjNGW9tYK5HQNKht1JLRF21OV/eUgFkMwzyHqXjT/vugdimXCB4ZTFXhO0pJescJJ8gDxdP7Rw09jkJWxFmBmv9yUI6N3gdzP2c/Zay+a8+N0xMjw+UooEpf5eFd7geU1DjHrqvvYNf9iH2NmYK8U X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6237 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 11b6dc1e-bd25-45f2-d739-08d8fe553833 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sgmQI1nKEgJzs3s8YguEMoqm2gy3QoyD2Pe+adUMdQcuSX18q6neYXr69euhmItGFv19fPPq4ki4LnuJ28xVrjdOHmgGcxJoWSSp8xbAygO8p2boo/GZBCAV7A3PvHZx3fYP65gfgXRE09IMU7Qoa//tranxJfxZTFNhHfJWbzQDfevYZHdcsZO8WKHRANiivZFdF8P8uGl9OZC84KN4bpZOhgCbImn8N2bIdgBxUunVh49es3MJV4Ka5STNoj8/JRYklH1CUr/inc/3b5biCzS6p8GaTVLDPVyxznRWDxwCgMl36GZG8tKeP/8KbBB7MXMkeC9D8UQZEK5VUuhpC/sJQUtw/okVQeCfwFNqAjsFTXSrQGL7ZiPf9O41nEmu2vdHQG82HhrlDhoo77YYF0mTMJN8BHdH0qnNvjuQHja6Sf2WZyq0AGrDMtnPxWF39Sm/+y7ln6YJ7zpMBjiTpzCvtO1ZPB6IBiNOXlGc7/iB8SQnyfyrEQIYLpvZapJRHtze1hl+0QWnn1dISh9wy33O0MbceZqUDZe8t9ePY9/uxZu0kok3CLFTJT0966S6n9A0PDhpfX3I48I5I2dpkNgOq55sx95NPMrmz5JO2cYdQb3UkbydC77Vqo02Fna8INCtIj3OwQnifguzz9KtyEMRb2xgEe1sihZPiQ1Y0GZKl9kko+qSe5iYdgH2K/n+ X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(396003)(346002)(136003)(39860400002)(376002)(36840700001)(46966006)(2906002)(6506007)(8936002)(8676002)(86362001)(36756003)(956004)(6512007)(16526019)(478600001)(5660300002)(70586007)(336012)(6486002)(69590400012)(2616005)(26005)(6916009)(6666004)(70206006)(82310400003)(44832011)(83380400001)(316002)(36860700001)(82740400003)(186003)(47076005)(81166007)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:22:13.0577 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 577d4e60-6922-46f3-f1be-08d8fe553d83 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4470 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" In short: __tls_get_addr checks the global generation counter, _dl_update_slotinfo updates up to the generation of the accessed module. If the global generation is newer than geneneration of the module then __tls_get_addr keeps hitting the slow path that updates the dtv. Possible approaches i can see: 1. update to global generation instead of module, 2. check the module generation in the fast path. This patch is 1.: it needs additional sync (load acquire) so the slotinfo list is up to date with the observed global generation. Approach 2. would require walking the slotinfo list at all times. I don't know how to make that fast with many modules. Note: in the x86_64 version of dl-tls.c the generation is only loaded once, since relaxed mo is not faster than acquire mo load. I have not benchmarked this yet. --- elf/dl-close.c | 2 +- elf/dl-open.c | 8 ++++---- elf/dl-reloc.c | 5 ++--- elf/dl-tls.c | 28 ++++++++++++---------------- sysdeps/generic/ldsodefs.h | 3 ++- sysdeps/x86_64/dl-tls.c | 4 ++-- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/elf/dl-close.c b/elf/dl-close.c index 9f31532f41..45f8a7fe31 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -780,7 +780,7 @@ _dl_close_worker (struct link_map *map, bool force) if (__glibc_unlikely (newgen == 0)) _dl_fatal_printf ("TLS generation counter wrapped! Please report as described in "REPORT_BUGS_TO".\n"); /* Can be read concurrently. */ - atomic_store_relaxed (&GL(dl_tls_generation), newgen); + atomic_store_release (&GL(dl_tls_generation), newgen); if (tls_free_end == GL(dl_tls_static_used)) GL(dl_tls_static_used) = tls_free_start; diff --git a/elf/dl-open.c b/elf/dl-open.c index 661f26977e..5b9816e4e8 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -400,7 +400,7 @@ update_tls_slotinfo (struct link_map *new) _dl_fatal_printf (N_("\ TLS generation counter wrapped! Please report this.")); /* Can be read concurrently. */ - atomic_store_relaxed (&GL(dl_tls_generation), newgen); + atomic_store_release (&GL(dl_tls_generation), newgen); /* We need a second pass for static tls data, because _dl_update_slotinfo must not be run while calls to @@ -417,8 +417,8 @@ TLS generation counter wrapped! Please report this.")); now, but we can delay updating the DTV. */ imap->l_need_tls_init = 0; #ifdef SHARED - /* Update the slot information data for at least the - generation of the DSO we are allocating data for. */ + /* Update the slot information data for the current + generation. */ /* FIXME: This can terminate the process on memory allocation failure. It is not possible to raise @@ -426,7 +426,7 @@ TLS generation counter wrapped! Please report this.")); _dl_update_slotinfo would have to be split into two operations, similar to resize_scopes and update_scopes above. This is related to bug 16134. */ - _dl_update_slotinfo (imap->l_tls_modid); + _dl_update_slotinfo (imap->l_tls_modid, newgen); #endif GL(dl_init_static_tls) (imap); diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index c2df26deea..427669d769 100644 --- a/elf/dl-reloc.c +++ b/elf/dl-reloc.c @@ -111,11 +111,10 @@ _dl_try_allocate_static_tls (struct link_map *map, bool optional) if (map->l_real->l_relocated) { #ifdef SHARED +// TODO: it is not clear why we need to update the DTV here, add comment if (__builtin_expect (THREAD_DTV()[0].counter != GL(dl_tls_generation), 0)) - /* Update the slot information data for at least the generation of - the DSO we are allocating data for. */ - (void) _dl_update_slotinfo (map->l_tls_modid); + (void) _dl_update_slotinfo (map->l_tls_modid, GL(dl_tls_generation)); #endif GL(dl_init_static_tls) (map); diff --git a/elf/dl-tls.c b/elf/dl-tls.c index b0257185e9..b51a4f3a19 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -701,7 +701,7 @@ allocate_and_init (struct link_map *map) struct link_map * -_dl_update_slotinfo (unsigned long int req_modid) +_dl_update_slotinfo (unsigned long int req_modid, size_t new_gen) { struct link_map *the_map = NULL; dtv_t *dtv = THREAD_DTV (); @@ -718,19 +718,12 @@ _dl_update_slotinfo (unsigned long int req_modid) code and therefore add to the slotinfo list. This is a problem since we must not pick up any information about incomplete work. The solution to this is to ignore all dtv slots which were - created after the one we are currently interested. We know that - dynamic loading for this module is completed and this is the last - load operation we know finished. */ - unsigned long int idx = req_modid; + created after the generation we are interested in. We know that + dynamic loading for this generation is completed and this is the + last load operation we know finished. */ struct dtv_slotinfo_list *listp = GL(dl_tls_dtv_slotinfo_list); - while (idx >= listp->len) - { - idx -= listp->len; - listp = listp->next; - } - - if (dtv[0].counter < listp->slotinfo[idx].gen) + if (dtv[0].counter < new_gen) { /* CONCURRENCY NOTES: @@ -751,7 +744,6 @@ _dl_update_slotinfo (unsigned long int req_modid) other entries are racy. However updating a non-relevant dtv entry does not affect correctness. For a relevant module m, max_modid >= modid of m. */ - size_t new_gen = listp->slotinfo[idx].gen; size_t total = 0; size_t max_modid = atomic_load_relaxed (&GL(dl_tls_max_dtv_idx)); assert (max_modid >= req_modid); @@ -894,9 +886,9 @@ tls_get_addr_tail (GET_ADDR_ARGS, dtv_t *dtv, struct link_map *the_map) static struct link_map * __attribute_noinline__ -update_get_addr (GET_ADDR_ARGS) +update_get_addr (GET_ADDR_ARGS, size_t gen) { - struct link_map *the_map = _dl_update_slotinfo (GET_ADDR_MODULE); + struct link_map *the_map = _dl_update_slotinfo (GET_ADDR_MODULE, gen); dtv_t *dtv = THREAD_DTV (); void *p = dtv[GET_ADDR_MODULE].pointer.val; @@ -931,7 +923,11 @@ __tls_get_addr (GET_ADDR_ARGS) by user code, see CONCURRENCY NOTES in _dl_update_slotinfo. */ size_t gen = atomic_load_relaxed (&GL(dl_tls_generation)); if (__glibc_unlikely (dtv[0].counter != gen)) - return update_get_addr (GET_ADDR_PARAM); + { +// TODO: needs comment update if we rely on consistent generation with slotinfo + gen = atomic_load_acquire (&GL(dl_tls_generation)); + return update_get_addr (GET_ADDR_PARAM, gen); + } void *p = dtv[GET_ADDR_MODULE].pointer.val; diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index ea3f7a69d0..614463f016 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1224,7 +1224,8 @@ extern void _dl_add_to_slotinfo (struct link_map *l, bool do_add) /* Update slot information data for at least the generation of the module with the given index. */ -extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid) +extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid, + size_t gen) attribute_hidden; /* Look up the module's TLS block as for __tls_get_addr, diff --git a/sysdeps/x86_64/dl-tls.c b/sysdeps/x86_64/dl-tls.c index 24ef560b71..4ded8dd6b9 100644 --- a/sysdeps/x86_64/dl-tls.c +++ b/sysdeps/x86_64/dl-tls.c @@ -40,9 +40,9 @@ __tls_get_addr_slow (GET_ADDR_ARGS) { dtv_t *dtv = THREAD_DTV (); - size_t gen = atomic_load_relaxed (&GL(dl_tls_generation)); + size_t gen = atomic_load_acquire (&GL(dl_tls_generation)); if (__glibc_unlikely (dtv[0].counter != gen)) - return update_get_addr (GET_ADDR_PARAM); + return update_get_addr (GET_ADDR_PARAM, gen); return tls_get_addr_tail (GET_ADDR_PARAM, dtv, NULL); }