From patchwork Wed Jan 20 15:31: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: 41777 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC7083840C2A; Wed, 20 Jan 2021 15:32:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC7083840C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611156738; bh=8zS5JXCD/PxxnmlCRDC4rWoLPJMFgEnFYKZ/loZc304=; 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=BjMaoHddWgfhCx0HzZMRL1vhyzXwYyHq+roK8KfH0849mtxNwUZUU7JtJsY3KQzrk TKz9mTfVLAhpbsQZP+3G/A34mrlvGo47L2aPkActgDrb6Il39c2IrJjO/VV6ecB95g e1L77BAuGlqfu3jtjnuLz63w4HSHh25pTpAfS+MQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2061.outbound.protection.outlook.com [40.107.20.61]) by sourceware.org (Postfix) with ESMTPS id 4F5653840C2A for ; Wed, 20 Jan 2021 15:32:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F5653840C2A Received: from AM5PR0601CA0084.eurprd06.prod.outlook.com (2603:10a6:206::49) by DBBPR08MB5546.eurprd08.prod.outlook.com (2603:10a6:10:c3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Wed, 20 Jan 2021 15:32:12 +0000 Received: from AM5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:0:cafe::c1) by AM5PR0601CA0084.outlook.office365.com (2603:10a6:206::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Wed, 20 Jan 2021 15:32:11 +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 AM5EUR03FT060.mail.protection.outlook.com (10.152.16.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Wed, 20 Jan 2021 15:32:11 +0000 Received: ("Tessian outbound 8418c949a3fa:v71"); Wed, 20 Jan 2021 15:32:10 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 23a6477e8ff397a0 X-CR-MTA-TID: 64aa7808 Received: from 4d72bb613e6f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 436C8F27-AABA-403C-9A9A-4FC610A229DC.1; Wed, 20 Jan 2021 15:32:03 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4d72bb613e6f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 20 Jan 2021 15:32:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aI97fE7/4G4DlmAONGG8OTSNpU5h29yMr+bZyD9oROg3B8RrV8Rcxpt+jzGC/6u5QV8XVSsBsd2qGgLTEmGpOKTYVAFFgbbOzGIVlvao9Z7i83ihClKxzwEhwkFlTBAo4Lcu9AOb4EyYFPENLG4I4eI2NLRAHAdQZYg3Lr3SSf95ZF/wWbHr5jLmmQsoPDqhYObcgKe68eA2UoeON1oROa6pMrza8GnIGgATARXyDWJT8bIMkzHX9LDnTPA2rbwh0t3Zp2fCzSFFcnvn4wEhT2gTG4tq/i4qVDwpDbVjmGP/KCLwQvP9cMHyidzDc0+gbZTSJFLo5fIUVI4q/cQnPQ== 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=8zS5JXCD/PxxnmlCRDC4rWoLPJMFgEnFYKZ/loZc304=; b=m9tBBVt036R7yZYQAx3Ati+AVqcX5awrIdmmFz3uyoFA59BTKBFXaCb8d7rcjKXRcPM9jicd8YYCT5sOuogQRHAzjurcfhf99VjGVSUMhnXss5jnRxSGPm1Hn0g80brOl6nPrfCPdAGWHdOwrdmf0B4j/Bp6SDo4+tgwYiJFRHUBFSZDLWsY4IxnDpBZ4pHqClwoiu1v6k7ReDncgCw3ycieIpVHMIw5bRicvLKGohDl7iEfAgbvdW3nwN07ddfnvY3G/zGxI3E8kVYePaTUv9phxVKIuhd/tdJAoQIhgjHoU8KEbN2P2U2EXbXkQ7X1b66cEwpKZ6c7T1SdWU56TQ== 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 PR3PR08MB5577.eurprd08.prod.outlook.com (2603:10a6:102:81::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.11; Wed, 20 Jan 2021 15:32: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; Wed, 20 Jan 2021 15:32:03 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v5 7/7] Make libc symbols hidden in static PIE Date: Wed, 20 Jan 2021 15:31:56 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.51] X-ClientProxiedBy: LO2P265CA0184.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::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.51) by LO2P265CA0184.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10 via Frontend Transport; Wed, 20 Jan 2021 15:32:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5e6f0c8a-6a76-40cc-4141-08d8bd588e44 X-MS-TrafficTypeDiagnostic: PR3PR08MB5577:|DBBPR08MB5546: 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: vkFfxolFtoftIR6xOrOelJ1ZRsGEAbF3xMYtoOb/RwP9W6fTNOTDKON1hDGLLpOknoBKJryFuhOr/0l5Vt3+S6CHjmPF1UQiRamiHw9PjZmpRcX/qgbA9r9tzFIM8s2i0YwbDX88zLOTjaWlT9U8cUiehc3uucbW8nr1YTKmjHLIlOGEvXJzs6ZZ8A58TRqG6COwDY8PmjqCiPl+Isv89ByVa02F1VpN2uRzNTOz9D6Y/mMi5udOQbptjcdm/g6QC/JaYNsOq9WDN0/d/K920l25bTKtWs79o0VbDI2WYNHNdxRrZRag2UkLj/vaS9KeDRFTFECQPc2YIbjgHjcz0WzExWrJrhDK4f2NhhnE99X8e5PEhRlgpZiK0FKSpOPB32BbOTtI2eZlTJvXGKRra13jpnoBFrpkycs9/cMLHIRyy5UlzU0lfb0InX7ZCMAilA1x94kkHJ5Z4BgxDKJjiQ== 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)(376002)(396003)(39860400002)(366004)(66476007)(2906002)(316002)(52116002)(6666004)(186003)(16526019)(66556008)(83380400001)(36756003)(86362001)(6486002)(2616005)(478600001)(26005)(44832011)(8936002)(6512007)(6916009)(66946007)(69590400011)(956004)(8676002)(5660300002)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: t6PRODRaflFk1vwY5+TNfh61m7/PfPtG4OgyGgjAfdlULIPg2wpKXnFqoMX/eo/0Cue2GQCCzxQbkdq35Jd9q6nKLHeReXOsVcL10LO+jFXvQSNc1OPPKGxa1zu5CCYYLapv4ud50tiwr3z7867zoFAmTlWn+wdrlqixSDhha59kZ0jN58TlvU8yDuqzmxs8364eADCRbZK9rXgR4MBRSj4RNQKbFzlxo6X58rQb3ZWdEajTT2SpJnklPDHPrUFdTgI9gxiGObO24adppJJiVC8D5avq6hnLnPGZVeKTfYbDrRcP7cAZWyIB5/KpJo6WPr6m4xXuPBjY+TtLOHfjRMyT0oyLBiOEHsNpdIvceo9+vmOESN5OSP1mJaYNCsY4/1TVEWWayEH0tmqHZB5iI6iF/QB6j20i/ImFd8gSc1m5CX3WNifMkofhws13TcWkbc+aowBA9FXMiJBt8k0gAyTEXGKFfCNAW0hcMwc+eY+bfYB9lTOhctJTnYaXAyJrkVFupe8W3VzBegJcMtJp6Gt0GDB4a6XdkMXa/vMXqDvkxtEhphmySv3ufd/G8ApGc4T2/eJ0z6dwQKs5BW/vWzywrk6HPzytRT4dYGqXvg2YXb+iomU55Is2K9e+A7O6rT3gXQnH/7W/Zzr8Yu0WvIZirwwXoeadwZCisWYbN8w4+XAUYJob2zVAO/C1pgqgvYL/Julsxwq2SgwYpVrQ/OBJTesmVfDkBBSMyrVLvF1yrlEB9zd8UF+WKbFiqnsiTJi2FO9xnd4K5052+mW5qy8aePBb/TrESDFWGHXgsZJ3di8l/pmf/wsiMLdsmcrqI2EXH8CJ805DVyqG/ulQNN9q4DM39emwKJZROl0r9PewtzFcFMZOsR8b9Cs/Zx8FIUt0eRLjrML/6E78qzrfpz1BDUpTMI2HX7njO8YibuZwDlWkTDGI+ZqUg9GWVWqGJOq7JpZCN9P+bHq9RBAQ7DV7lfmROUB5LuKO+zYrkt+NxGzjn+66S+/anUEfNJXl X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5577 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: AM5EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 2dd09933-35a4-49b8-92c9-08d8bd5888ea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D2V6vFRfSD2+qBLBmEY3F3PGNLqNur8PBShXLdKIPs5QknliO2EA1cHVp4EmPOpG4Z0u0xyC9YVezH220OKzej6lg5NRhWwmuCsP5tElUyQMGs1vAWDbBMG3bIEqk+oGmcEsSXxzg88QHXQ74LG7b+o68yW9MMhtwV2TVr0pthZjJf8bgJgpMVxyOyjkX+Mu/1z2MWvF++mOtWHigov8MCBo/BYo5D3VR4qcuW9GXfAIdwUtIE+6fWQNoafiHxC/mUvNYknV66jfeg+K1olS4NsXCpYjOJ0tUtNuPiMpFjGsqDdiI+OH7F2+HREuvKBKofdvH9Z2erawlrelX9xyZYPR0EtJYntl7sdS9N7Xc8LH07K+GesfMGe4rirIrpXelBH/KIM2PqFEr/LVsgdDRaVkM0WxoMp9G+t++WMDG6+DA5By6bSRvmKB+7VvNW42ILSdPAmocXqO2Suqijm1jQriw/PUEitCh0AA4KMoyCaEKcy5G5nz/n3U5pe/P1lf 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)(396003)(39860400002)(346002)(376002)(46966006)(69590400011)(316002)(186003)(70586007)(478600001)(6506007)(356005)(2906002)(82310400003)(44832011)(83380400001)(5660300002)(26005)(2616005)(81166007)(6916009)(70206006)(8676002)(336012)(6666004)(47076005)(82740400003)(36756003)(6486002)(16526019)(86362001)(956004)(8936002)(6512007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2021 15:32:11.3974 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e6f0c8a-6a76-40cc-4141-08d8bd588e44 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: AM5EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5546 X-Spam-Status: No, score=-14.0 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" Hidden visibility can avoid indirections and RELATIVE relocs in static PIE libc. The check should use IS_IN_LIB instead of IS_IN(libc) since all symbols are defined locally in static PIE and the optimization is useful in all libraries not just libc. However the test system links objects from libcrypt.a into dynamic linked test binaries where hidden visibility does not work. I think mixing static and shared libc components in the same binary should not be supported usage, but to be safe only use hidden in libc.a. On some targets (i386) this optimization cannot be applied because hidden visibility PIE ifunc functions don't work, so it is gated by NO_HIDDEN_EXTERN_FUNC_IN_PIE. From -static-pie linked 'int main(){}' this shaves off 71 relative relocs on aarch64 and reduces code size by about 2k. Reviewed-by: Adhemerval Zanella --- include/libc-symbols.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/libc-symbols.h b/include/libc-symbols.h index ea126ae70c..f4dd735555 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -434,13 +434,18 @@ for linking") strong_alias(real, name) #endif -#if defined SHARED || defined LIBC_NONSHARED \ - || (BUILD_PIE_DEFAULT && IS_IN (libc)) +#if defined SHARED || defined LIBC_NONSHARED # define attribute_hidden __attribute__ ((visibility ("hidden"))) #else # define attribute_hidden #endif +/* Mark all symbols hidden in static PIE libc to avoid GOT indirections. */ +#if BUILD_PIE_DEFAULT && !defined NO_HIDDEN_EXTERN_FUNC_IN_PIE \ + && IS_IN (libc) && !defined LIBC_NONSHARED +# pragma GCC visibility push(hidden) +#endif + #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec"))) #define attribute_relro __attribute__ ((section (".data.rel.ro")))