From patchwork Mon Jan 18 16:26:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 41753 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 4DABC388C01B; Mon, 18 Jan 2021 16:26:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DABC388C01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610987190; bh=lE19Zs5MyMreTy3y49zKv0Dscxf6balahUu15zSgLLM=; 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=siWM0fHW7iNA8aOgU0i8Sp9CXNW8zgjnP1gqucxWRigYsMyqXk0ItCkWVHU3LcA6m xgQGWRPC42EbrLK/oddAgGq/k360O4zM8COtH1eR2oLXL+EL5+ov3+KD1YnUzKHJLk wfjlvjoJzEgU8kveNHicuGFcjBcLv2HPA+OVQNxc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05hn2223.outbound.protection.outlook.com [52.100.174.223]) by sourceware.org (Postfix) with ESMTPS id E2C6F388C01B for ; Mon, 18 Jan 2021 16:26:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E2C6F388C01B Received: from DB8PR06CA0014.eurprd06.prod.outlook.com (2603:10a6:10:100::27) by DB7PR08MB3788.eurprd08.prod.outlook.com (2603:10a6:10:31::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10; Mon, 18 Jan 2021 16:26:23 +0000 Received: from DB5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:100:cafe::b5) by DB8PR06CA0014.outlook.office365.com (2603:10a6:10:100::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Mon, 18 Jan 2021 16:26:23 +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 DB5EUR03FT007.mail.protection.outlook.com (10.152.20.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12 via Frontend Transport; Mon, 18 Jan 2021 16:26:23 +0000 Received: ("Tessian outbound af289585f0f4:v71"); Mon, 18 Jan 2021 16:26:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b094ec6810dbdbe3 X-CR-MTA-TID: 64aa7808 Received: from 85c6bb6f2cd6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A0BCFF5A-21C8-4C03-AF6E-D76D60641BB0.1; Mon, 18 Jan 2021 16:26:14 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 85c6bb6f2cd6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Jan 2021 16:26:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kTkprN6ZN3x/ADuIiRm1b1b9/0AZ0QFrk90oAkxiXVa093dBqHVR6sZfvvETsx4Jaiqfy86ASTH85oEch/E8bEup8LNBDTwpCrhh/Po92UcmyUqeWx+pU9xUfZpe0j3eli3VG21E1UGyueg0Zol+KSzOWpnzU8eNFhKarPrDRSPOEomnFZupZqnp3/mN9Aw7ZbfBxu4WHpEjn7dTWp/Egp04FqBbnVp2p2vGKSFpa8A+Vj7HyomD42BT0KnLaV6GfVXaOCPDHfgF3ouCg1k4Lxo092jHiT1arYerRO5clRL6lrkrwo1/bRL+4WLxTPdV4P42TBv+ZvHHbvfm1deaFA== 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=lE19Zs5MyMreTy3y49zKv0Dscxf6balahUu15zSgLLM=; b=Dc2yr1IPEc6f89KJgXTgjIf8pHnEItam7enq1WpDq8/JnXVvv7B+z+FC0S1g3+VUORdVz8n92wkPReZeStWYTRtl8+bjNA0zO5FKfkKStjGm5GIxJk82l0J1hsbKyFYj2Zx1K1omF3zUW4EjadDqoL38CLWNYbMy5f22nYDOfFEhcAPdmDnkE03uXzDQ+D0DGPUshmY97PL0bvV2xXDZP/4gp6kpe+u8wGXIOUieE0k/8VO26dryZzzymGPjh7W2r5kB+2aiDUFGfSL0KAUE/iOQ7NhbvUVMXxw/B7OCygFd9MnZwqH+qQ+L+dRAfWO8Pyb9ZO6hlSbF/49j6i5Qdg== 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 PA4PR08MB6238.eurprd08.prod.outlook.com (2603:10a6:102:e8::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.11; Mon, 18 Jan 2021 16:26:13 +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; Mon, 18 Jan 2021 16:26:13 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v4 10/10] Make libc symbols hidden in static PIE Date: Mon, 18 Jan 2021 16:26:07 +0000 Message-Id: <4b939181155fc70ccb708530c1244eb0c2fafbef.1610986541.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0146.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::14) 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.54) by LO2P265CA0146.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Mon, 18 Jan 2021 16:26:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4d32eda8-3e74-4e95-2a41-08d8bbcdcb95 X-MS-TrafficTypeDiagnostic: PA4PR08MB6238:|DB7PR08MB3788: 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: AbsG+uU3s9UNpexrKBlY1UCCKn7GGjx7SAirxGuI8Ez30LsW+M7VAb7RKRvKjKFM0FK4M5XiJnY5cAiqWkXF8Zs4SZza+qYh79RN/HNDlM9bj0XsdpZl84ompe652hwDt4IxqHBM6aBmUqPocEjv+qro1EMkE+hqh8fEriUK0f+wKqUWAWOvwJAU/hv4pBkfxQe99aDw437TXmTNzS0z+d5ijkXkV3cClUSwq2MID8jbwOeaVQ+f0Krr7GXpxFcDpEG2WjA3Kbxm22gXLAZcMyEfN77Ra2KaMF7zLZ/4+emXUb3q7ccpa4HGFolrobVO8l9+8QbZBu/EQDhSkpZ9lPnUCstOUNkgMtd64tgL9FDlmNbwlvb6lR7VrmY323khb05ZHVqjRKa0XV9+IBs7wutOq6C90QC9iFHtEiH3Gqe/W4A5Ug62TzLAutq4CfGGenPmUeAJHKFbc7PQH8GQDKzP8gt2PMFHJ7Eo3RnbarkJt3AIDSfBsKcpiNbB4glHU8Gxu5PiqCAKuxCH/8LzBRTewor/+Lkmx9Z5z+YAC7X3zQDVWDbB4nX5bDAFtOUy4CRf3gjpI5cF8jMBnG2jmg== 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)(366004)(39850400004)(376002)(396003)(136003)(346002)(83380400001)(6486002)(8676002)(69590400011)(478600001)(6666004)(52116002)(6916009)(316002)(8936002)(66476007)(66556008)(66946007)(5660300002)(86362001)(16526019)(26005)(6512007)(2906002)(186003)(6506007)(956004)(2616005)(36756003)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nJiaYovlZIUJOwV/jPz5LX499RdZodX5Z3GNglxCN9fWfGprJ0ofX5Dwi6Nwq5B0i24v0ReTvXx3PBi+l2kdcHtjQEldvPgFqDrjATW4DMcDg/scaxs1UV1y5IcUfMPNsH0uBkbg+mVOnX3JRI8WVlb97GBGbPi8VSJLz3agGkpJ9PwWVEKhEvHb0NMDyzrIvJgPu5cqTevsRq4sxI6py3aJtmluW/lWAgY5KYFx1tE8VxIIHu25PNAO1FJdFbqqffRX/PcROGByQacdgtVSwkFScRA7ukX1Vsmry8YhlvA2Ok5+R0l+S21oAvAKsOqOw8LaT6sfOhmWErLfFWDIadmuRmsJUUyh+m1zvh5drJXTERmhj1f62cPHcKMnq55mOGepUNopgU/t5mAj1V22F0YgsLiylKmPB+GO5r0sN+yiX2LzjHp+ouVnmdSJTGr20F9eUqJN3KGJutAf+Gc5czuIqYXPiu5EmoIshMCdwZtJbVgw2Q59+ARRD1OYzR4nkUi4jbUW/Pzj53ObLpC30GRtnv34PISjMRHHsvtm6pcPf0Bo0i8pcE2TvWxf/70/JVCtOg6hQky3D+gdFJwkdr1cYegrk+/YUiOpbDptMysTXojiEs9T97SBaIEVFIjDh5hLFvSz5JSeEZbHUuVn5+A5p0F9+Gon0pSqB/SS+L35woq/nwOuv5lb6lOIijGeu5cV2OehJKpe3XfgcwYvYFYdpxTgjzwFJmea5jFmbas1zq1sAOCtdfulKuHrgow9DVR76vnzavRbrrQ/MrKiiNK4tLv8wMnzjaXc/5Ngk77QMjoqAJAH2LIHgKgPwm+A00XGWWRzhoy1FRGFgSmND6/P1JfSBw6NBlr9qG1GxDUkiTFnWWSOL6Km5BY1y+399JjLaE60rLy0KLvOT11ehGkYOKOQv1URo0Lxb6IFlsrDl7xFjaTYIFKkUXbjrI4m7VQWTdHpva3Bo0jf8VyWwwcSRgqjNCTsbHVYQcxud0CXoo5x5xexrkcsrPpR2WfN X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6238 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: DB5EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 4860572d-c029-4cc2-6b60-08d8bbcdc5d0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QJFO7ryPb9pB6tLU9YAmgKnez3hiLRnT+h5tuYaX4kVewxy+UQw//D6V8r3YGmao+GBWA1Ve+lQEez81xWlkK3uqZExwji1MxkPain4DoOuCWBuk4yxc2pgMSUeCg79SaNZNGwTXFqMVO1iD/tvGSGJvDMOYt5VhboNULGXKta2+DAotVIV/bVFbVq5brNbznRDbfjehS8JOVlr6vBHhoYq0WiMOU347sN5JRi0imP3TbyzTdeFsn1R5Gj21FD4xbDCStTmTTA1+M3amhH6itwanAl/7h1vCPNGZkyY7Dr65P4y+hbvBE4JrJsdTVM7Hsu76I4FZtPfBPS6WyrU1CQrDJU+opow/HsIiUuBcl5Cf6oskc3Y2nf33EUvMHJ8u7gUJK43FhjspxQyDZoccFetoUoch88ae3MC9939SZn8mnq1YzyRREkHriDfXdScvy4wJ6ipCasH9lKOWD5wGNb8BW9KiCFSnEaLZypqYGk+NzXQCW5Eo+cqp2uGkYju2 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)(136003)(376002)(396003)(346002)(46966006)(8936002)(81166007)(356005)(6916009)(82740400003)(478600001)(70586007)(70206006)(316002)(6512007)(5660300002)(82310400003)(8676002)(83380400001)(44832011)(26005)(2616005)(36756003)(186003)(69590400011)(956004)(34010700045)(336012)(6486002)(2906002)(16526019)(6666004)(47076005)(86362001)(6506007); DIR:OUT; SFP:1501; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2021 16:26:23.1095 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d32eda8-3e74-4e95-2a41-08d8bbcdcb95 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: DB5EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3788 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" 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. Hidden visibility 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. This is an optimization. But on some targets (i386) it 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. --- 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")))