From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2084.outbound.protection.outlook.com [40.107.20.84]) by sourceware.org (Postfix) with ESMTPS id 6F53E38708BB for ; Tue, 19 Jan 2021 14:35:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6F53E38708BB Received: from DB8PR03CA0023.eurprd03.prod.outlook.com (2603:10a6:10:be::36) by PA4PR08MB5951.eurprd08.prod.outlook.com (2603:10a6:102:ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.11; Tue, 19 Jan 2021 14:35:13 +0000 Received: from DB5EUR03FT063.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:be:cafe::da) by DB8PR03CA0023.outlook.office365.com (2603:10a6:10:be::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10 via Frontend Transport; Tue, 19 Jan 2021 14:35: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 DB5EUR03FT063.mail.protection.outlook.com (10.152.20.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12 via Frontend Transport; Tue, 19 Jan 2021 14:35:13 +0000 Received: ("Tessian outbound 4d8113405d55:v71"); Tue, 19 Jan 2021 14:35:13 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ad00736d790f94b1 X-CR-MTA-TID: 64aa7808 Received: from 0e13f0607212.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DBC0BD37-2B75-4E37-BA5B-3FDA4DB595D6.1; Tue, 19 Jan 2021 14:35:05 +0000 Received: from FRA01-PR2-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0e13f0607212.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 19 Jan 2021 14:35:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=coGWf6z28/W0Rn5qPnsFt2kNIuhRAfV3FBeQ7zt7fVdhX9nh3HNaTXbh6q8zSF0RzhWR2ijs27P753nSjnM8A60rAdpt34AwNtB8GfhLzrtiTIiQESLbqrswhsEgTHFYAPJTcGFz8FaatPWJH5QjaPqxeAgz4F2JxVnRQf9kwC0E//+FkkIHn1vxj/5dfjevasRdXjbJWaKdUr5jaCMzELTfI2hizkUJmUPt1V+E2DvNal7L5zF94KmwPkGyYJUVoKkcrY5ch8K69SKG9h+UKM2E1MkRWhsl53I+NrZDaQQINIYzsa8hw5i6iYDlwdGP2izIUlTd8PoBa4ZMEv0y/g== 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=wM8pn5G/epIx5v3qlj6K68l6NEVVRyTO7chikBQEZIA=; b=PJ6uEhqrkkhi+fmkQoDocs1e0IG0U8s+g9MspjZy6yRtiv1Bf6sZ4rJaIQajebBrfctujowd8KwxOVSesr9PMZfoAd22IF0iBU7BY9YpixSzPZDQTHYqj3mesS6/YXsw9KsAKWLqeZMd4TJ+gnv1m0gDCaCsBChqLIemQAUCKZemrhdn+sZPBHDyzYw8L0thIDunBhQXe76blxqqNn7Qjny718WKIAv3goJ9Wye86Ne18G/96pSfGXyLLCtNtQ82I9DcO8T2EqFaDpg6weuKKyQPLYssM12KSbTKrbTQ9iiB8KOE4gKuOh7l9jD9/pqnV0wkGUMz931L3IBrEpRxtw== 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: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PR2PR08MB4633.eurprd08.prod.outlook.com (2603:10a6:101:1c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Tue, 19 Jan 2021 14:35:03 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 14:35:03 +0000 Date: Tue, 19 Jan 2021 14:35:01 +0000 From: Szabolcs Nagy To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v4 08/10] csu: Move static pie self relocation later [BZ #27072] Message-ID: <20210119143500.GA3445@arm.com> References: <4224b7c0428492696fe6d6c01739adcf69fc677d.1610986541.git.szabolcs.nagy@arm.com> <1ba70d1b-08f8-6a5d-ecf4-45200744c9d8@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1ba70d1b-08f8-6a5d-ecf4-45200744c9d8@linaro.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [217.140.106.53] X-ClientProxiedBy: LO4P123CA0355.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::18) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.53) by LO4P123CA0355.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Tue, 19 Jan 2021 14:35:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c8327f2f-5a7c-403c-4934-08d8bc876e88 X-MS-TrafficTypeDiagnostic: PR2PR08MB4633:|PA4PR08MB5951: 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: o39cRABVGno0L6fqJqJV4HlZyXZpHJHKRSucBYI6dORFL1tDijK0WNsNtfnWIvjqDbyKjZ7xESXNn3kE3fzPujdPJqZvndr/DZybh9i9ikmTOt1x+1TEFopSYIF6q1pi/erzXXOUa9iYPneE8HLpsUTHKiJCicyEdwv9n8CvaWAS7l3/MYbhsCm+bo7bFt9yRSuXFpGs/QGBr41iwki0s7RhneXO77B0T3ojl/LLVFYh9ZUwWDKU+veP7rjc7S/Mi6dDd2hZTSPAleKM9g034fw9qyScxhM4JBHMrpXUtrQA1Agb/iNiKfDlxb+aMs2XKPrbP/cvR9Qy+EOlwbAPFAlaWAVv8bL901NqLcQWiluaoipXdAwDDcKOzIsFCZOcsVFqE5PB80zWHzMGtPwrIw== 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)(376002)(396003)(136003)(39860400002)(366004)(66556008)(66946007)(86362001)(55016002)(4326008)(8676002)(33656002)(36756003)(66476007)(2616005)(6916009)(316002)(44832011)(2906002)(83380400001)(956004)(53546011)(26005)(8936002)(1076003)(8886007)(5660300002)(7696005)(478600001)(52116002)(186003)(16526019); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?SWR6TElvK3M1czBDaWcrUTlHQWFLOS9kMUdqd0ZtM1h1WEFUV1EwZkN2ZXA5?= =?utf-8?B?UHJRYnlEekEwSWNlL0lRcHZDUUJvc3czT2lWWGMwczlEakJOV1czOHRtbGZU?= =?utf-8?B?NUlzeTFKYXYybTkvd2EzZXU5K2VIRW0wVFovTnltMEpXWEpRUUxFUzNmSkhJ?= =?utf-8?B?Y1YrV2xpL21VU3NWVENGdVhYb280cVpKeTFDU0Z5eHc4RHI3WUt2aFlvTk5X?= =?utf-8?B?blc5azdDWm12UkJoa0NaaWRIdE4vTTFvbjZJZnFHclc3U2VTR0Urc3J0ekdZ?= =?utf-8?B?d1cva0VaQzJraXdaOEZ6cDZhN254REJLOUZzSnpTSStiQ1VnbmE2eDN1djNu?= =?utf-8?B?TUQ2THdWb040aWZ1SXpVaHZ0VWppZDlpN0ZQQ1NSL3MxbEIxdGNTQUV6QmF2?= =?utf-8?B?WVh6RVZ4dlozUWlZaTN4V3VGUEowWlgzSHE0WW9ORVVsN0FQazd2V3QyMGM0?= =?utf-8?B?OW5aRmpESVZnbENtbWJRdHVRWlpOYzFlNCtsMzNRYnI2aGZleFpUS1JCb1p4?= =?utf-8?B?M05ZUlM0QU9Vc3FqakhJZHNMQzVwd1JnanZkcjN1RmtCdVJvQjUvbW1FQlVN?= =?utf-8?B?VFRPQmgzV0ZXU0laOGtwQ3p0Q0NvMVRGbENqNUx6NjdTbDMwekR3c1lzT3lh?= =?utf-8?B?YU1NSG55M3hyYk1DMU9GVnlXZ01hOUVTL3lJWXN3d3hPQi9wQ0phcXBXTm0x?= =?utf-8?B?b05nVWR1YjlBc0VFbDNVZ3U1WVBrekRFVGRuTjFJVXB2QUN3VmdCQUo3MXVK?= =?utf-8?B?bkRHU1FWVWZ4OTRPNHV5Qko4QkNPaWRqd21ZRFVXemhnRkkyNy81dytSVVFh?= =?utf-8?B?UkJWS2Fuc3JlbTBmUjlkTjNQYnowb0tlbkJPYkx1cmpFSFFqekRxWTh1bkZG?= =?utf-8?B?RG90dkRzTmlLVk1QaHJKYTBpcEhPMll2anJ0a0xMbzZNNWl1ZlI5VDBSU2g0?= =?utf-8?B?ekFBbjdRbUE3NmlpUGtJeVFVNkRheWt4Q2J0VkU2SUMzQ2VlZ0lVTnE1bWQz?= =?utf-8?B?YktVeThCZTFETTE4M0Rmd2wvN2N5OGUySENlQm9FdE1zVE56WkNHYktwVmFH?= =?utf-8?B?Rll2RWNhOEVzbHc0UHJUYWNqaGQ0YkQvMEdYRWdldXhCZGVYeElMQVBHZ2Jj?= =?utf-8?B?UTdtemp1ZjY3WHJHQTlXV1c5T09MS05TWUxwVHYyN3FmZWs1a3gvaFdBL1ph?= =?utf-8?B?b0xQU1dLbVZRTWFrMGNQYmdycW9EN1c2L2tQdFJwM0hKaW9PS0NkSktnRnNs?= =?utf-8?B?Sk9UQ2NobGJ2SGttMWFlVU9uYjZWcTF3d1VkQUdiZ2h3cHc5NE9kV2hoWUhp?= =?utf-8?Q?X+SQt4zou0wiFQ9fwM2gcQqigMiK2QRZ1x?= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4633 Original-Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 7802b115-d368-4f05-bb72-08d8bc876863 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AOkL9PRzTuwa2E4SvCW3WdGCN4WXc/9jMImoMT4wtO9kQpHkGOr2rX5xdOe9lJZAO2T7O6+cWKxS+5hk7z/rbwUqTxBuf3f02TyfE8+ycMXs6c9pfmYD7EAhli8n52TEiZNzvmt/6kvbpG0ZiclFTidfyTK3VeO9wVL+HM16KI5zf6D4vFoOZqUryJ0ro3EgRG1rahXAQ5CMnLJ6I4AE3bPZz1SNOFXdjQKvQ4Ni5HO8+/90O4dKdzcPSV4jWnJ1ixRMC2EwLzwIe0v+3nrgaIchmooc6N+yOfSJidrp9lcbTJCFw+36tM7ZTgmvxwTw4NuLCDPshepA5UjJZfExPRhNGvVR7Uib6X931eGfFgbXJZgTh6I/xaspt5E3OoMJyCwwmLEep6Th0S43wL1QC6u/nPW1q85OHREvbwM7sGt/zCaxjkjWNqlK7wFP+osfBDz5UkJ3qprxZnDfIdA6gg== 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)(39860400002)(376002)(136003)(46966006)(956004)(53546011)(86362001)(316002)(2616005)(82310400003)(2906002)(7696005)(83380400001)(8676002)(44832011)(336012)(33656002)(55016002)(478600001)(1076003)(5660300002)(36756003)(81166007)(4326008)(8886007)(356005)(8936002)(70206006)(70586007)(186003)(6862004)(16526019)(82740400003)(47076005)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 14:35:13.3897 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8327f2f-5a7c-403c-4934-08d8bc876e88 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: DB5EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB5951 X-Spam-Status: No, score=-14.4 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-List-Received-Date: Tue, 19 Jan 2021 14:35:21 -0000 The 01/19/2021 11:07, Adhemerval Zanella wrote: > On 18/01/2021 13:25, Szabolcs Nagy via Libc-alpha wrote: > > IFUNC resolvers may depend on tunables and cpu feature setup so > > move static pie self relocation after those. > > > > It is hard to guarantee that the ealy startup code does not rely > > on relocations so this is a bit fragile. It would be more robust > > to handle RELATIVE relocs early and only IRELATIVE relocs later, > > but the current relocation processing code cannot do that. > > > > The early startup code before relocation processing includes > > > > _dl_aux_init (auxvec); > > __libc_init_secure (); > > __tunables_init (__environ); > > ARCH_INIT_CPU_FEATURES (); > > > > These are simple enough that RELATIVE relocs can be avoided. > > > > __ehdr_start may require RELATIVE relocation so it was moved > > later, fortunately ehdr and phdr are not used in the early code. > > > > Fixes bug 27072. > > LGTM, thanks. > > Reviewed-by: Adhemerval Zanella sigh, this is an old version of this patch, i made a mistake putting the series together. the problem is that _dl_phdr is used in ARCH_SETUP_TLS (to get the tls program headers) so the __ehdr_start magic should be before that (this only matters if auxv lacks AT_PHDR for some reason, which should not happen normally on linux, so testing won't show the problem) i'm trying to figure out where i lost the new version.. thanks for the reviews. > > > --- > > csu/libc-start.c | 44 +++++++++++++++++++++++++------------------- > > 1 file changed, 25 insertions(+), 19 deletions(-) > > > > diff --git a/csu/libc-start.c b/csu/libc-start.c > > index 1e90dcb0a7..c2b59431a3 100644 > > --- a/csu/libc-start.c > > +++ b/csu/libc-start.c > > @@ -146,8 +146,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), > > int result; > > > > #ifndef SHARED > > - _dl_relocate_static_pie (); > > - > > char **ev = &argv[argc + 1]; > > > > __environ = ev; > Ok. > > > > @@ -169,24 +167,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), > > } > > # endif > > _dl_aux_init (auxvec); > > - if (GL(dl_phdr) == NULL) > > # endif > > - { > > - /* Starting from binutils-2.23, the linker will define the > > - magic symbol __ehdr_start to point to our own ELF header > > - if it is visible in a segment that also includes the phdrs. > > - So we can set up _dl_phdr and _dl_phnum even without any > > - information from auxv. */ > > - > > - extern const ElfW(Ehdr) __ehdr_start > > - __attribute__ ((weak, visibility ("hidden"))); > > - if (&__ehdr_start != NULL) > > - { > > - assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr)); > > - GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff; > > - GL(dl_phnum) = __ehdr_start.e_phnum; > > - } > > - } > > > > /* Initialize very early so that tunables can use it. */ > > __libc_init_secure (); > > Ok. > > > @@ -195,6 +176,11 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), > > > > ARCH_INIT_CPU_FEATURES (); > > > > + /* Do static pie self relocation after tunables and cpu features > > + are setup for ifunc resolvers. Before this point relocations > > + must be avoided. */ > > + _dl_relocate_static_pie (); > > + > > /* Perform IREL{,A} relocations. */ > > ARCH_SETUP_IREL (); > > > > Ok. > > > @@ -206,6 +192,26 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), > > hwcap and platform fields available in the TCB. */ > > ARCH_APPLY_IREL (); > > > > +# ifdef HAVE_AUX_VECTOR > > + if (GL(dl_phdr) == NULL) > > +# endif > > + { > > + /* Starting from binutils-2.23, the linker will define the > > + magic symbol __ehdr_start to point to our own ELF header > > + if it is visible in a segment that also includes the phdrs. > > + So we can set up _dl_phdr and _dl_phnum even without any > > + information from auxv. */ > > + > > + extern const ElfW(Ehdr) __ehdr_start > > + __attribute__ ((weak, visibility ("hidden"))); > > + if (&__ehdr_start != NULL) > > + { > > + assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr)); > > + GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff; > > + GL(dl_phnum) = __ehdr_start.e_phnum; > > + } > > + } > > + > > /* Set up the stack checker's canary. */ > > uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random); > > # ifdef THREAD_SET_STACK_GUARD > > > > Ok.