From patchwork Fri Jan 8 16:20:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 41681 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 E8C323982431; Fri, 8 Jan 2021 16:20:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8C323982431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610122826; bh=AJjRKVVaPVbqR+IT22N7OI0Zk+9N+Gh1NCsQ184p9CE=; 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=OlglIB2mZ80YjgSyF5DuiCArficrZf5CMu/CIIaejDI/04ygHY7zEc7f/YVucmUEm FlmdEYk+usQHgjjkA0BWV6it5a7Ou6v8X/ZAIBcvF2MmSHFzqrew2MMqA9lpGtq5/Y hin4GoY/ZxIAHJPjXD0S/UULDRFSgH7IZReIIsLQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30084.outbound.protection.outlook.com [40.107.3.84]) by sourceware.org (Postfix) with ESMTPS id 483E03982423 for ; Fri, 8 Jan 2021 16:20:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 483E03982423 Received: from AM6P192CA0061.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:82::38) by AM0PR08MB4275.eurprd08.prod.outlook.com (2603:10a6:208:140::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Fri, 8 Jan 2021 16:20:21 +0000 Received: from AM5EUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:82:cafe::d4) by AM6P192CA0061.outlook.office365.com (2603:10a6:209:82::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Fri, 8 Jan 2021 16:20:21 +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 AM5EUR03FT062.mail.protection.outlook.com (10.152.17.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Fri, 8 Jan 2021 16:20:21 +0000 Received: ("Tessian outbound f362b81824dc:v71"); Fri, 08 Jan 2021 16:20:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e739c6d036d51b71 X-CR-MTA-TID: 64aa7808 Received: from 3d12edb79078.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C3A9A3E0-11DE-40CC-A254-3CF61BCF87B6.1; Fri, 08 Jan 2021 16:20:15 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3d12edb79078.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 08 Jan 2021 16:20:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QOVsnLyNlUcfCPbvd5Q3UkHGwt3OMPNyBxeC3JRoWdHNr2Nq0ejKOVW8DSkmusu/y7j14SBeZQ9u+BNv/U/70EFqNMNu9DGd0txNbvzExZxlF5P4QLKAczMoHNbkl4+p5qPapABWzf+X/6As0xuOiQyUiJS+sW3flzo9jCc3X9I5mCdnvkABlkovqg/ATj/UiY/ErhNIJ819E9C4hUQcR3rwV/yZZkiIjb9VnFHj+VeoJQXcErxcwkWw6jFfENH/rwNxXTRI7qf51WlLFJlDBPdzSsNfQ/+zf8W7YbYtTuwMsP8rApM+ZpTfMtEM5OBmMkcquGct0oEvTF/UDmwqAw== 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=AJjRKVVaPVbqR+IT22N7OI0Zk+9N+Gh1NCsQ184p9CE=; b=arPZCPe4MgV6RpLK+JwEnHduIzu3xKtWIgcAMXguNVbnXQmaL4apGTfJe9R6FbM6wtMhpKHnwmn6cBqYdVbn34iygANf26L8WFvJF2bI3aXedV1TnKGwCfot95UQ/xIUl+k4eS5ZrelQA3tHnRrhBul61MNk1rHrqHW+dvswq4M8dPPGVBKzBzeI4chvbsd+2tpWgPtyYoWWS3UXUpvQY+1RXoaOw3d89gpIrX2P8ycPQC2rQEWsLq2Z3mT1ad/QEF5UG+wnOwJxbbYVdnj/g+9BB2DFkxawFrLsTJ+UAm+zthrM9ekdUou3kheuX5mdoa9h9It4OUfqa7F6mIMghQ== 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 PR3PR08MB5578.eurprd08.prod.outlook.com (2603:10a6:102:83::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Fri, 8 Jan 2021 16:20:14 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f%6]) with mapi id 15.20.3742.006; Fri, 8 Jan 2021 16:20:14 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 2/4] Make libc symbols hidden in static PIE Date: Fri, 8 Jan 2021 16:20:08 +0000 Message-Id: <56297d0f9c00bd27901dc41ef20d749cf564def7.1610121077.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.51] X-ClientProxiedBy: LO2P265CA0062.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::26) 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 LO2P265CA0062.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Fri, 8 Jan 2021 16:20:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7bdcfb20-ffa3-4764-8339-08d8b3f14bd0 X-MS-TrafficTypeDiagnostic: PR3PR08MB5578:|AM0PR08MB4275: 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: RW0b24DTu6f2e0ZrPYfRuVIHb31ZSoMqsxZW0rcsCXGo60XqC4+A/vXYI/DUODUWSRNtzIJ2oiPyPIWiRSstAfRiQUjBHAwyocQJr6zp2gW8qrzl/VkBbgGcrp4TYxksdj1SVOZTZip9RO4rzxkwM6eQADwglHTPCupDHpZOGT8OiG1RIHxFzzeq4ouM+vPfOYVJwhD3Bju0QyDqcy+gGnpnIZ5WvWZH6xYSQinTf9MXyVf2BGlYzhsmIy9JdzaLwigiwdTulVUjq/qsmigjOLa3eYzZXOT+/OpK1a0DiMHx53iDtWP0u6qVTrp6+DQeORlmydSm9YrOq4GhaNzl6IckFHLn7oaLQHHtVeCmn+AKSUPZtxVe/TzeBISAvGo/UvdU7OXbF4cBdMwHKjvx7TNIMdlh+FjQcOAw4pG14pPHEoT/9M7gg7Iu2a2ZnqHIX0nQJc6bU6VQ64s+TcO/BQ== 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)(136003)(396003)(39850400004)(366004)(36756003)(8936002)(52116002)(86362001)(69590400011)(16526019)(6506007)(26005)(6916009)(83380400001)(186003)(5660300002)(6512007)(6666004)(66946007)(66476007)(8676002)(316002)(66556008)(6486002)(44832011)(956004)(2616005)(2906002)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Z7MHBq6vEwYDtuYzw9xHF3vN+dNXmJ7ERuwTKBGdNkpRWb+F0wiRjDRXC31Ac5tETD+QJgjG5PvrWEDZAOyYRJ5L7hVo9kubCNlZkrbQQbFio0sU0Rd6a3cAsdvrTZWzNZ0Jwi2kk5i05r4HmcFFKXdWPzdEMWEtrRORBL14CuHuegm4DG3akMvcVjugfPFksygMW/OuoYG6vms7TaNDuNKPLI6nR6tpG9eJNk/bCYOdYWD0C/DBmfa5I4PemMjHSwB7vgfoq8K0O9BeF70x+S0YSeBB4NXh3q+FZaSE7W4ImEHTRPxeTIeCi9+hfUdhbL6csm9i+pj8j9d7LeNE7NFrVBs4MlssKVEqz/JkPywIafXOY7LxGxP5P2yLBMg21XRgAzsqbP3wn3UVR9RXgITFEcVGoUgWmsvDYE6O34E0xhdpXmq4+dlLrlQ5uUIQnAV2eQzu6HxYW7sulvyOTcTQrGZEO7qF3H2BupnwTPzxz97Y5myS6iDzwdqRotr/G9jHF7+bDRra1ETt1CoILpfy/u7kWFZEmDadH97TtwMaFGF9i596CuYCP8yVhWqhzUcvC27SmhuCLVxdgpbJmtoTgoSFMZKHNlx9neSwjPTNw7eXjW3+fbCgA3EG5HevgDxExAdvirAVi68IMzNEDSIzs/UHFBz/czzrWRAgGL3op68EBt4a4yg6MBt+gPF/YPrragL0662kQsxQ0IHGwkvx7V1Jh9vFgxCT3GF6ZY45jkR+umFrZsleCi1/fZvfKQ3mePbCdCab82X4sMIePtg+vaH0g9wPOerL44OAf3ZEnF9WMdLuCYsuoBStNgSp3t2po0lN1IQmcX8rgGPi1HGptTVbi8g5D1pqYTIFrVDFi19zXyRQies6y56CcllEtTaUg+iB4N1MQ+yseLoSKpJlrqKlv+p4Qd3dtG7iIg1dJjdhynggVv9qV2bLOZw+DsWXYe/MJ3Nkgt+yUdFgFRqqcsDi9BzMiMWqxQRjQNuWVVVxiIuAakHIyY7UlWpZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5578 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: AM5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: a3a311fa-5456-48e8-f0c8-08d8b3f147e8 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YkHtyKXtcmxVuAsf5HD5Dhv0wf/T/pb2dNZkwaZStFRcdO/A/YaqYdO9BLCBw2j8QcwqQFLvQfGmkvAwtiQvtYUi3sljxNQ/7grWSe+qDrqNu1gEyOOufv83QxpWE5tDKf1PwTAin0Lh9AvoCEXTplReku8wHY8Ch+2nKhxH0bH0MW92zRtkqrq3NQV8GKD0F7YW87wU1+r3HmwBjh3KTGYlXaoT28JkC7hyKfWLShIhkGRd+BgZI5ewOX9U13qzaAjd37kPYmuEYQAixW6PvuA/AeMvwC1q5AQr88llX/zKg4aMSkMcWfAMTfnAONeDV4vJyTEy5PGQimJXGx3PzgOKnYuf1lZkkfTDsaTD2dmoBMCHkfbCP2NX3hw1AIE8a1etY2zBo4G6PE8Ha8TGv5wZEkDtJZVuwkENZT/GnDNgqF7KC139R/sH5zQNl3sREOCEujZzXL7g8mxUI9s7G9lh7gEucD15G8qvLJDF+Ri5fdfIC6M0NduWGQICoCCYQIciPRuiEi1N63niXcP8Kw== 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)(39850400004)(396003)(346002)(136003)(376002)(46966006)(34020700004)(6666004)(70586007)(6916009)(8936002)(47076005)(356005)(70206006)(6512007)(82310400003)(6506007)(336012)(6486002)(69590400011)(2906002)(478600001)(956004)(36756003)(8676002)(82740400003)(2616005)(86362001)(5660300002)(81166007)(26005)(16526019)(44832011)(316002)(83380400001)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2021 16:20:21.2811 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bdcfb20-ffa3-4764-8339-08d8b3f14bd0 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: AM5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4275 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" Hidden matters with static PIE: extern symbol access in position independent code usually involves GOT indirections which needs RELATIVE relocs in a static linked PIE. Using So hidden avoids indirections and RELATIVE relocs on targets that can access symbols pc-relative. The check should use IS_IN_LIB instead of IS_IN(libc) since all static libraries can use hidden visibility to avoid indirections, however the test system links objects from libcrypt.a into dynamic linked test binaries so hidden does not work there. 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. From -static-pie linked 'int main(){}' this shaves off 73 relative relocs on aarch64 and reduces code size too. --- include/libc-symbols.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/libc-symbols.h b/include/libc-symbols.h index ea126ae70c..93e63ee889 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -434,13 +434,17 @@ 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 && 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")))