From patchwork Tue Jan 19 16:06:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1428718 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=caoBMFs1; dkim-atps=neutral Received: from sourceware.org (unknown [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 4DKtnx6rvTz9sSs for ; Wed, 20 Jan 2021 03:07:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 46088393C868; Tue, 19 Jan 2021 16:06:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46088393C868 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611072419; bh=XbP3MXiy/eqKbb8v9s1PQSPkOaN187KZRNK17PWtrlE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=caoBMFs1Xe+KXwWIkjx3ZNLicp8IRlfixFJBno5Yhq4OGAj2f9ygsjESoxtuJ2T/T JOpYm5sZfXRFUHhAuJlQgOm9NTDNwfYoNY2wPXZ0fs9pQqPSnWpEviSpYVZ8iRLgtw e/l+fG9tzxgxZRZ8DmeCKRPfjXwNj8bGUsui75T0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40062.outbound.protection.outlook.com [40.107.4.62]) by sourceware.org (Postfix) with ESMTPS id 7386C393C868 for ; Tue, 19 Jan 2021 16:06:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7386C393C868 Received: from AS8PR04CA0194.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::19) by AM9PR08MB6065.eurprd08.prod.outlook.com (2603:10a6:20b:2dd::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 16:06:53 +0000 Received: from AM5EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2f3:cafe::fd) by AS8PR04CA0194.outlook.office365.com (2603:10a6:20b:2f3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 16:06:53 +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 AM5EUR03FT005.mail.protection.outlook.com (10.152.16.146) 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 16:06:52 +0000 Received: ("Tessian outbound 4d8113405d55:v71"); Tue, 19 Jan 2021 16:06:52 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3de3d8dc8994371e X-CR-MTA-TID: 64aa7808 Received: from 7d68a9767d21.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BBA68217-B31A-48D3-A6A1-12D6AEDDB74B.1; Tue, 19 Jan 2021 16:06:44 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7d68a9767d21.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 19 Jan 2021 16:06:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X+7azdUmtfJYlALv5pDUi+Y9dm62TV3KY98ehXcjz37W+th5cjtN/z6kFtkzVYBgvTzP9GNnYMm/QK4VzqOH6VjGg10/gyEwwH3CuI6xSlaxMMnX38oOzLiZKtEiwH8yPE8QGVVCdQoK9iukxc/2laqQ3nKhrE2zDFAG3G4B5HoGP7c/WAng8GirP1PgLyKqCf4RMNpR+4FLVUTNBWo9ghx7VpqYGue8LvObkg+77wtbfyjUimeNg5SJXu20vQ6t4nVXnaiA/xTj3VnScg73cRZq5rha5zaMY9kfXLEG+tZLe3f37GiTF+Re+g6M6gzpU0UvCy3DQLg4Sw73ve5Bnw== 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=XbP3MXiy/eqKbb8v9s1PQSPkOaN187KZRNK17PWtrlE=; b=Kc6Amx+gMSxeUmwDDKGLAi0uU/OLiqkneayw/gHjIVWiMcQxMHZrNxvm9yhFu/H2XWKmJlncu3ZPJUfeYygwk+7ntmXHPKwYdqXLsoVJNdhQasANpRFlF2IqgPSHmWqaT2tZI2HLIjJgtsg338FYaxxt5+8ZjqADp+Mk+DwM3S2OLRkTQV9R8QuNJqEFXXa+gBn5pW32KvMDyYHDH2z+nzQwm+A0Qj/nukE8wS+ZGgikQkZ+wUxqAHBAZphxIUhSVHjjY/XK0wpxXzjBmSsOrZggbQjFSXrgFBAGapNhk/3Lb9x8KxJF3F8MSCnC2TM2QOJG6FFvBK6Ps748hoOZOQ== 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 PAXPR08MB6400.eurprd08.prod.outlook.com (2603:10a6:102:150::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10; Tue, 19 Jan 2021 16:06:43 +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 16:06:37 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v4 fixed] csu: Move static pie self relocation later [BZ #27072] Date: Tue, 19 Jan 2021 16:06:26 +0000 Message-Id: <20210119160626.14151-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-ClientProxiedBy: SN7PR04CA0169.namprd04.prod.outlook.com (2603:10b6:806:125::24) 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.53) by SN7PR04CA0169.namprd04.prod.outlook.com (2603:10b6:806:125::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 16:06:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ec50b1e1-4af9-42d3-00d6-08d8bc943c91 X-MS-TrafficTypeDiagnostic: PAXPR08MB6400:|AM9PR08MB6065: 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: /tEJheDuP2VItmjQN1lkrQKfPzwVKorZZrDR+CBv+71BNf8aXOJugUPt/tkBrG3Vxu9xRHmjUySgSn7uvlM71kw+4xJYtelW/M8+qN5N/gNelgHz4gQr2nBgN5B5cK1rcR3gSuglm6uMgVavj0wOnU6uHqxLHJSk2HZ30TkRWeMB1dyHK7iYIDnfv9D2CrNFAV0Q5HWAhz3dukxCiqXY+dciBS+9e/uAJHRSER862IG7spRdtDfkB8/bBSWvWmq9pLf4F6SqcYpm25WI1ZPCT4Oxe9ZTGe77QunLZ1XFMYusR2YYco4ANVZz+seX0m9tCnPAhP4jDelapsJ+TRYtmsgKFSVQyrxN7VJlszLVHr2FCk12N/ZoH38+ABsjQmXOnRr1B4lmBRqXG39AHD5Te8BcSRnAcVM8NTkHZz3g4jHXXhWFw8K1q6aL7f5bLImyIDQ4T5xZr4r+HBgER6ZV7A== 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)(39860400002)(376002)(366004)(136003)(396003)(186003)(5660300002)(6512007)(2616005)(956004)(66476007)(83380400001)(66946007)(66556008)(2906002)(478600001)(16526019)(6916009)(1076003)(8936002)(69590400011)(36756003)(6506007)(86362001)(26005)(6666004)(52116002)(44832011)(8676002)(6486002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2PmU0JYV3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: 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: AM5EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: eaffe63f-e164-45ed-38ea-08d8bc943329 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BkZTMtK/R2XBfdI65ngxqpmeuHUFpGOQrruIW9bIQEenBAZlILBUVuH+cQhWzzxPdMm9o8cd0N4yaSPNHsTEIuyx3R7amQNaKk/WvVBGL/zLIf5GkOGfpdXp2pb5sVc8x1ee+2esVdzlhr+q3G3u/ZdfwCxyQowUYJ6oZoUkvGxYdCEUUf6JwirwpJGUkLc8IwOhKEvpB6Y4bme9h1t5lCP2ZdSGTFJKc5WgMv7W6b2CS6y8DaEM0r5xRw+1BZ8bvXDt5P2ns5F98BWXrjGoCHUUo3Zf6vsNlzwcecUH+2efenoNdCu0AcTIUF4evD+oVXs3+j2kweD3S1pq+lPJL8CLWzhIiwHL2lQNFOYCDPJmLm+Swjas2+jR+VP2v/Kxvr4+nlQ8oQ+zn2IyQf6KozpvPLCX1sLnyxpq1CIZfUimzjqbGV48wGDLHUSrnhlDWoye5UN4plN/RcNNWUNnvEneQr099HCcrSBCJyDY3wtjUNjNs6eCP/s/fqVLO9Y/ 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)(8936002)(47076005)(26005)(2906002)(6512007)(16526019)(6486002)(70586007)(70206006)(82310400003)(6916009)(69590400011)(956004)(316002)(86362001)(6506007)(336012)(1076003)(186003)(36756003)(83380400001)(356005)(82740400003)(81166007)(8676002)(5660300002)(2616005)(478600001)(6666004)(44832011); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 16:06:52.9603 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec50b1e1-4af9-42d3-00d6-08d8bc943c91 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: AM5EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6065 X-Spam-Status: No, score=-14.1 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" 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 up to relocation processing includes _dl_aux_init (auxvec); __libc_init_secure (); __tunables_init (__environ); ARCH_INIT_CPU_FEATURES (); _dl_relocate_static_pie (); These are simple enough that RELATIVE relocs can be avoided. The following steps include ARCH_SETUP_IREL (); ARCH_SETUP_TLS (); ARCH_APPLY_IREL (); __ehdr_start may require RELATIVE relocation so it was moved after relocation processing but before tls setup which needs the program headers. This also means that targets that need ifunc resolution to be after tls setup cannot support static pie without splitting RELATIVE and IRELATIVE processing (or removing some of the dependencies between these steps). Fixes bug 27072. --- pushed a new patchset with this fixed to nsz/bug27072 and dropped the x86 test that is under discussion. Note: it's not clear that this is the right approach, the options considered: (1) avoid relative relocs by making symbols hidden in some files, (2) avoid relative relocs by marking some objects hidden, (3) do relative relocs early and irelative later for now (1) seemed simplest, but as noted in the commit message if relative and irelative are processed together that is a bit awkward (requires various workarounds for i386 that cannot mark all symbols hidden and means inflexible dependencies between operations that may be circular if ifuncs rely on tls). csu/libc-start.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/csu/libc-start.c b/csu/libc-start.c index 1e90dcb0a7..3239125202 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; @@ -169,6 +167,24 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), } # endif _dl_aux_init (auxvec); +# endif + + /* Initialize very early so that tunables can use it. */ + __libc_init_secure (); + + __tunables_init (__environ); + + 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 (); + +# ifdef HAVE_AUX_VECTOR if (GL(dl_phdr) == NULL) # endif { @@ -188,16 +204,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), } } - /* Initialize very early so that tunables can use it. */ - __libc_init_secure (); - - __tunables_init (__environ); - - ARCH_INIT_CPU_FEATURES (); - - /* Perform IREL{,A} relocations. */ - ARCH_SETUP_IREL (); - /* The stack guard goes into the TCB, so initialize it early. */ ARCH_SETUP_TLS ();