From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60054.outbound.protection.outlook.com [40.107.6.54]) by sourceware.org (Postfix) with ESMTPS id A21FC3814FE1 for ; Tue, 7 Jun 2022 13:25:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A21FC3814FE1 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=OEmzRUvnLMo1wZoNEAKwhThe9zsMNGjzhhsFNnQR9c34hGTzFOnGdqcMR6+Pj3YtjhAqPyVBW3dhG3CAHtmc7UFhxAiYXr5Le33MCeRg3dgSw5ir/SVg0Isv0dMP6nlzn6B73ttADTAaG+Ra9OR9qETjBdBA/EzJ3l1UZgobmweAwOR2tIU9PZhKd/dvjrTzROu8SJ98Oe3sn3WhOuKX98eSb4RqCFOJKDB0j+0MWIUaf5/UCSV57ooDePoiKXCufX+mT6l91kIajeTIvrvWL2RWTIIVt7ip9pfu4LS0LdQq7uoAhBsetQAumDubrWsGClUh6e10wUgB2/vE3x9QSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qPK7/8hUyCa1PBCFj+pPpILNoofNJyW4iffkkysfQv4=; b=VIo3GcNdnZvtEk81TVhy8A/2PVwC1fKi3rJ2Wnoa500y/PHIzuO8RJCyxMZVaIbr3w932HYMT98p9SL750qZiG38CefWE32sLx5tsXfMjBRGdu3ARHg4BoePMRpg/kE1E8vkLtToQVxk0HKjO1JnrpgxzMB5I7NqBKn3ohfJvZ3vCH/QQRe4XcbaMthqJ+x+CPHvZMids7KkP55tZsxNbIcJ8b/PbE52UR4ziPjTsUdd6KrAD6Jh/YjPWfjPIKynNcSh/swc3DxZ+ZkShg/GZ4JsAT7ZeB6pY12bivvw2vjJUsf8f+gVGVaAdYj+wQ0GR7kumaqCQ3SKPgyzRXsnlQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AM6P193CA0088.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::29) by DBBPR08MB6057.eurprd08.prod.outlook.com (2603:10a6:10:1f5::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Tue, 7 Jun 2022 13:25:00 +0000 Received: from VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:88:cafe::16) by AM6P193CA0088.outlook.office365.com (2603:10a6:209:88::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Tue, 7 Jun 2022 13:24:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT060.mail.protection.outlook.com (10.152.19.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Tue, 7 Jun 2022 13:24:59 +0000 Received: ("Tessian outbound ff2e13d26e0f:v120"); Tue, 07 Jun 2022 13:24:59 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b5b4459ae71c686c X-CR-MTA-TID: 64aa7808 Received: from 281e2943bbfd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9045740D-7F92-401E-8840-3C9C5803665B.1; Tue, 07 Jun 2022 13:24:52 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 281e2943bbfd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 07 Jun 2022 13:24:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ORfSVp8+aINwVlsjfA5uWGhrHkWxqNOOyfXTdfFemw2ShODngMr0t04AL7UndfrIozN3FspnnSV991+yzzVsMyT82/cimB18KiShlPObRwZEoDFOLhWeOT1qKLbky0CDGBD51ywo+4OW39o9/64fZphaXlb6X1WOIxpCLmKQ4/1Wd3vyaNTlDyGcEQKGhwTwlgS5OTl4O6wpeD0J7rum7V5HLSkWywIIhveuSIK0NrTf7Z/iPluCCLLRENEGUK2Hlijw5gQTT/7FWTrx5JOSaDaTWaHMMRZ+Uvs4Kzxdqx2OKf204MkXLkmb+RLOZ8H516Da9jx9peTNSkBWMjy8ow== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qPK7/8hUyCa1PBCFj+pPpILNoofNJyW4iffkkysfQv4=; b=dp/QFE/EMOoJH+bYfpLeYyo+1Rrp4oPoAIWqzu9XfGI7FHWAMScYh9IOrFsA7VtGV1VpwPfbIC79qR4PxGfK13khEgH4TihNl3YMgtT7v/jIcxVMySM5//D+coPZXTDCC6BQ9FvlO35T0JJS5LMzEj9dhAj+N92q2e935+gTkiC66ZJTovMdnaPYJFCZjqIaF5huiwc0HyvrWW57/9YY8t6ZrKKVZdF56C3hZf0JlHyLQvydoGhOsO/mNbISutJw9HTlHprvaTd/ZXc4URRK/cL01ihjjUhoO5EBW9UCSkTPklxDauzhJH7yR/MOL3r9cFTNWudMeLC4ghDmPNQxqA== 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) by AS8PR08MB6757.eurprd08.prod.outlook.com (2603:10a6:20b:39e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Tue, 7 Jun 2022 13:24:51 +0000 Received: from DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::9ccc:fe7c:19e5:bfa6]) by DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::9ccc:fe7c:19e5:bfa6%4]) with mapi id 15.20.5314.019; Tue, 7 Jun 2022 13:24:51 +0000 Date: Tue, 7 Jun 2022 14:24:36 +0100 From: Szabolcs Nagy To: Fangrui Song Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v3] elf: Remove ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA Message-ID: References: <20220601175633.2407189-1-maskray@google.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220601175633.2407189-1-maskray@google.com> X-ClientProxiedBy: LO4P123CA0450.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::23) To DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b8009678-0f60-4c5e-2f7d-08da48891f2f X-MS-TrafficTypeDiagnostic: AS8PR08MB6757:EE_|VE1EUR03FT060:EE_|DBBPR08MB6057:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: KLYEsE71KOz31PE3Cyd6+bhnLNwFgLuPCjXkfRvHF58nkfDCPIy3yWNrEK9gvdILuSJAFg3uNehUDR5VeiAxDvJ3Am1zUawAIjLk4iV/Fks4Z2ujAoYTOXwQZa4Qai4nldiJTq7flkFvk9g9s8TU89x0teCtM05cTxvBPAVZhUNMUCPvnsbxz2ibJnsT1QxQJOJTTqHI5yxkW5A4unnrlpfDUgFGoGXDWSJTSlqpCRcFeTQrgoLLHXw3fQ1XNnkgTIHYTvDUOBX7r3LBXW9ZrizyNXbAVukGONjmEd42kxLRmsa6X/dMt8wxGR6q4VdaIHLPR+olB+R9IjuO0sBqwSO/GkMt4K3EBHRKZTMijzRMbE2jaell6nHBtOWpRqi0qBdi/JFmcLOlh2olKJoKBXCR7nYyaGlOau4g5lWECXF87SPWQLpnXc62v/G+sjdTTYsWzC8f6Jyk//jcN3URKL0FC32ZU0rdA1a+9w/339mBxHI7hd2YFeOwuz1Uba06an/mNyxWvqegLQgGEG6ThOnCb0TBSYIJQHeLPloqPt7Yau+oA5a/OcBpc3TPcJ7auEFR9CzuLOT9buoWv2Zso5zR2FIWAbyC8q84IjX8PMFOGTBEYrQlCMShYWmd7uaYyDJLDA8/QrDsEJEriTvOZA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7179.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(8936002)(6512007)(316002)(44832011)(186003)(6486002)(2906002)(508600001)(83380400001)(38100700002)(66556008)(2616005)(66946007)(36756003)(66476007)(6916009)(6666004)(4326008)(8676002)(26005)(86362001)(5660300002)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6757 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c7acb757-33c3-4f8a-b3cc-08da488919ea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fij5qtBRdgSCLqzZi/kWp71LLXBQF72BV12da0N9rbOPvW2tXWSkaNVRzkszMTxA7N9mzmD/Y3QIQEl/GbwIvmAJLkJKpikJ6RJ9SwljWK18nCABAzhetVUB2l/zjgeY4HtOrnWRtOGdxV5gLJzJLIx687yGvmsD3HKNtzSuyaan009f/lOT0iYdQBr3QGfW66PQ7sC6G5fKfjUAa9P+65u2iX+3zdxxbgPXq6kLcm4HMaT2WurqG5P2+DBrlKkR0Duv8LUgYEeWiLVXymuLoF7koKyo4g82/J4Hy9XLT99BRUj88Cfj6oNFQdGEd9L6VFyW9zrx/DHJ/gyA5Kg0Nr6wnYWSXeQV3dSQLe/AiC9icGPWzYfr29cOI4ik0iFiP2idcnkfwDnyt/X1UW4n2c3ggUpCMmW9RSqqYG1YIlUeCAJPULIX5VNJLv8LQaKCojVnACybyWhMp1ESQrE0waLaN87Y5mU6yHjA2MJc49vSeUgczU0GGwXHI/Ia8YTsJvJCChM6I977Y52fwKsrIgILHv7IFMPZlsGzgYsKW2Omn+omuItIC9OgmwN+l9zbJ5vZoW094cH33HYfk8pPOQ9iXSxW7OkwIxCWc345izeCO4TNagJpL+ggTG81DhonPIyQCRUzVyb69rZ4ZnlsPf9JwzMtRt84MS3ElwZ07AxffivxE1hyuLuGRaG+acVL 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:(13230001)(4636009)(46966006)(36840700001)(40470700004)(86362001)(82310400005)(70206006)(2906002)(8676002)(336012)(47076005)(83380400001)(8936002)(81166007)(6666004)(2616005)(40460700003)(26005)(6512007)(316002)(6506007)(186003)(5660300002)(70586007)(36860700001)(508600001)(4326008)(36756003)(356005)(44832011)(6486002)(6862004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2022 13:24:59.6158 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8009678-0f60-4c5e-2f7d-08da48891f2f 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: VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB6057 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-List-Received-Date: Tue, 07 Jun 2022 13:25:04 -0000 The 06/01/2022 10:56, Fangrui Song wrote: > If an executable has copy relocations for extern protected data, that > can only work if the library containing the definition is built with > assumptions (a) the compiler emits GOT-generating relocations (b) the > linker produces R_*_GLOB_DAT instead of R_*_RELATIVE. Otherwise the > library uses its own definition directly and the executable accesses a > stale copy. Note: the GOT relocations defeat the purpose of protected > visibility as an optimization, but allow rtld to make the executable and > library use the same copy when copy relocations are present, but it > turns out this never worked perfectly. > > ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA has strange semantics when both > a.so and b.so define protected var and the executable copy relocates > var: b.so accesses its own copy even with GLOB_DAT. The behavior change > is from commit 62da1e3b00b51383ffa7efc89d8addda0502e107 (x86) and then > copied to nios2 (ae5eae7cfc9c4a8297ff82ec6b794faca1976ecc) and arc > (0e7d930c4c11de896fe807f67fa1eb756c9c1e05). > > Without ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, b.so accesses the copy > relocated data like a.so. > > ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA has another effect in the absence > of copy relocations: when a protected data symbol is defined in multiple > objects, the code tries to bind the relocation locally. Without > ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, STV_PROTECTED is handled in the > same way as STV_DEFAULT: if ld produces GLOB_DAT (some ports of GNU ld), > the relocation will bind to the first definition; otherwise (e.g. > ld.lld) ld does the binding locally and ld.so doesn't help. > i think we should not change the interposition semantics. we should go back to the old behaviour where only copy relocs were broken (and there was an expensive workaround to deal with protected symbol interposition). i think you want to revert the elf/dl-lookup.c changes of commit 62da1e3b00b51383ffa7efc89d8addda0502e107 Author: H.J. Lu CommitDate: 2015-03-31 05:16:57 -0700 Add ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA to x86 > It's extremely unlikely anyone relies on the > ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA behavior, so let's remove it: this > removes a check in the symbol lookup code. > > -- > Changes from v1: > * Reword commit message as suggested by Szabolcs Nagy > > Changes from v2: > * Explain interposition behavior > --- > elf/dl-lookup.c | 90 ------------------------------------- > sysdeps/arc/dl-sysdep.h | 21 --------- > sysdeps/generic/ldsodefs.h | 12 +---- > sysdeps/i386/dl-machine.h | 3 +- > sysdeps/nios2/dl-sysdep.h | 21 --------- > sysdeps/x86/dl-lookupcfg.h | 4 -- > sysdeps/x86_64/dl-machine.h | 8 +--- > 7 files changed, 4 insertions(+), 155 deletions(-) > delete mode 100644 sysdeps/arc/dl-sysdep.h > delete mode 100644 sysdeps/nios2/dl-sysdep.h > > diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c > index a42f6d5390..41d108e0b8 100644 > --- a/elf/dl-lookup.c > +++ b/elf/dl-lookup.c ... > @@ -854,43 +801,6 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, > return 0; > } > > - int protected = (*ref > - && ELFW(ST_VISIBILITY) ((*ref)->st_other) == STV_PROTECTED); > - if (__glibc_unlikely (protected != 0)) > - { > - /* It is very tricky. We need to figure out what value to > - return for the protected symbol. */ > - if (type_class == ELF_RTYPE_CLASS_PLT) > - { > - if (current_value.s != NULL && current_value.m != undef_map) > - { > - current_value.s = *ref; > - current_value.m = undef_map; > - } > - } > - else > - { > - struct sym_val protected_value = { NULL, NULL }; > - > - for (scope = symbol_scope; *scope != NULL; i = 0, ++scope) > - if (do_lookup_x (undef_name, new_hash, &old_hash, *ref, > - &protected_value, *scope, i, version, flags, > - skip_map, > - (ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA > - && ELFW(ST_TYPE) ((*ref)->st_info) == STT_OBJECT > - && type_class == ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA) > - ? ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA > - : ELF_RTYPE_CLASS_PLT, NULL) != 0) > - break; > - > - if (protected_value.s != NULL && protected_value.m != undef_map) > - { > - current_value.s = *ref; > - current_value.m = undef_map; > - } > - } > - } > - i think we should keep this part without the ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA bit.