From patchwork Tue Jan 12 17:22:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 41698 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 CE60E3894C36; Tue, 12 Jan 2021 17:22:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE60E3894C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610472139; 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=IbnW8WOkKGpv6IYejXkz5lmjLCtFMK+U5+aWYfhiQHJn3MO3TEUcjh1PohXq9JB67 bptpsMrujRDu9ujLphWBhVdj111ugAn+D5cGPml0e9HW969+YiI1ZPb1hP3v6ZXfAM rtdUUBGnio9SR5wW3w8lAJM9yS1+/OMBXkqBd6kY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140052.outbound.protection.outlook.com [40.107.14.52]) by sourceware.org (Postfix) with ESMTPS id 316993894C33 for ; Tue, 12 Jan 2021 17:22:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 316993894C33 Received: from AM5PR0402CA0019.eurprd04.prod.outlook.com (2603:10a6:203:90::29) by VI1PR08MB2928.eurprd08.prod.outlook.com (2603:10a6:802:1e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.11; Tue, 12 Jan 2021 17:22:14 +0000 Received: from AM5EUR03FT061.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:90:cafe::fe) by AM5PR0402CA0019.outlook.office365.com (2603:10a6:203:90::29) 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, 12 Jan 2021 17:22: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 AM5EUR03FT061.mail.protection.outlook.com (10.152.16.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Tue, 12 Jan 2021 17:22:13 +0000 Received: ("Tessian outbound 8418c949a3fa:v71"); Tue, 12 Jan 2021 17:22:13 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cb72f6af9963b3e3 X-CR-MTA-TID: 64aa7808 Received: from d54ed4daa39c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DFF1EFC0-6B67-44B0-A42D-0F95A1E8A811.1; Tue, 12 Jan 2021 17:22:07 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d54ed4daa39c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 12 Jan 2021 17:22:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TsJjSTqr0KyfMa4r5CB9ZAa5N/hk62Nx9PsGYFgfL9BaiyWxyyOlYrjpxO+9pwDaA+5lqGTbBpODz/v90xy+VjCBOIeRy22iU4kyfmQZfByuDRBG89Nsecua7tPF1XHUHymeJfQ2n8FsHE3bweN6AS8V5nTzl/cCAL59BVovbIgGcd9VSmzpz/3SVsKbNSG1i6AiAxVzFfW97NuDCwmAlGJLfmYcB9h8Nv81biepNzPjxSBCiO5tZd6S12M0QXwDDm2MsMe4yo/PBa1t4KhxbIBS/kDQh3/kOJloQORVxNQJcsaCSGgRa5zeXUanGMS4HP+OBP408LEH4pcD4tx6CQ== 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=BA8v7ZACWK7BNhd77zpi3g5sRXHGMZlS6O7M6h9Q3Az9GP0/RXqpco01eVG55auoQ0m2iC5S7UsE/xToHVrPzwY8HECbXt4Z9A8FaCrh7Dqkr28udhYHJlnNwI1U88pyeKRcdUCiLA1b56aA6fQKJOb/bPkDXQ3cUfXj5Ff1xWPZKO4gcMmuf2WdXZ0QU+HQcuFDxn49LTpyB7RYf/h6p1W0vPtoBVVvQjWlYl5ZRFC+5pSIE2jwsoLgOyMN56XAnGE2FPPAqemD3kMA4elfFoa2P0ugK/QH0dHGTPSp7CFx+XpDU5atiBd8UzRy9ICH9X7UMBxLAOLwVpxawoQf1w== 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 PR3PR08MB5753.eurprd08.prod.outlook.com (2603:10a6:102:87::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Tue, 12 Jan 2021 17:22:07 +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.012; Tue, 12 Jan 2021 17:22:06 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v3 2/5] Make libc symbols hidden in static PIE Date: Tue, 12 Jan 2021 17:22:00 +0000 Message-Id: <27498bbc768372541e4379794656ac2778d33035.1610471272.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.50] X-ClientProxiedBy: LO2P265CA0416.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::20) 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.50) by LO2P265CA0416.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::20) 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, 12 Jan 2021 17:22:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f588d0e7-bd76-43f6-76dc-08d8b71e9a1a X-MS-TrafficTypeDiagnostic: PR3PR08MB5753:|VI1PR08MB2928: 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: Ey9e5Eyd58gFFGj50iNTmO0hnsF0DGiJPf/5cUF2rSZyhiHgAjmSAx9CiqsHnKuey4D6SoiPU+W8hTW8oo5MJJ11lMxfEEqbIaa+YKQKu2koYIOGXAkEqFh0RqCrZG4/qAKoBMfV34HebGC79j9WsWytiFrSH+5SnD8GDE+xE2v++Nb9HD2wcB1wDXLbMqRcKBiRslr0QfDhLHstOBy5PHyW6XT0hWdLCMoB+8U6zY+GL07IFc/kVKH0gdZApo498EKEE449cTthTOdPHY9A/HjDi6+tgQlAIMl6hV4ATsgU4lVqjecSurjA0sf2kW3ewnUuB7jiaDXLjdskhOtgS04ySiuxw6UqxUQBXujkzqgCfrJ8XyQnzaOhK/HPt5Sn436R7mbUn7cVtHw9PQqjjyMt92OFHjjj+Q0n29XWOobWHLJV7puJhdbek5sRoWKH/yMFqGn4MfVHz4vLP2R/5g== 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)(376002)(136003)(39850400004)(346002)(366004)(396003)(16526019)(26005)(6916009)(86362001)(6506007)(956004)(36756003)(83380400001)(69590400011)(478600001)(2906002)(8936002)(186003)(66476007)(6512007)(2616005)(6486002)(316002)(5660300002)(66946007)(44832011)(6666004)(66556008)(52116002)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GZYrDpppZnrn9FIcJIHYL9h5NVL4AXFZgy1viu+1S7/FSbT7y1B/FhdVK7nbSh3BD2Y7FMIxhG/apjIPyrCPM+aRcXjSmEUkBkB+sVt1d+G/4lEuCgAHG4gYAZSJ3gvIsJbwWGkmadmJEXcZg3/+rsEOxu1rGeRBN7UHE8E6hXKzf6eYex7YZdyUdOElhtlliKae4JUMqEQo6a6IDv/W+s3YPUFtVZFy357C7JIWSzImqbvfZkqoDMFgY2BjHKhaKUAIL2YRUN8mDedA67oAawgaDh3PJi21SFuxbRLtwGUNcnsWq/kfq3L4XXyOfPJa7L+9l4FjF9OT7rbCeB+M2GSmOLHTp0a9RAuajKYSDH+9H5d23Rc3rT6kLj/b1tz/fJsHZofX0mI09f0jj8PH+Jzj1RtygW/zkwXMIXhX5Noev+lgBEYz13EyoMiM5PqeZO0JwhIQi8Nd8qlkqOb1zFrI1jmu2rwOqSnSzkujjxGwbTy+KK5AjYM3I29RbvPnDn+ZXQgjdlBdzczYfIfdeS+FXI4U26aC6n8cdLwWzJcKWzOW+ehE1EBkdoh4ceVMHwBlDBYPFe/hDWeQe8YAFhvKuvogWhlA0NRYoEnwn6z3Ae8OKNRStYKslYRQwFM3GdTZq0JlqutMkK2B4UiSJsgNYMdFTpnAkelEYUUFmwRCbD0UgiBtDqrANQjc2XkgWLHSzai/pEE+uKTqMA7A16SDrmFrkZA0pC4d5bAG4WzlArDqwjfTnVHdAqIEYDYlPo7ZLTtx5FPf5JVb5atRrWa/uAUB5aDEZ1+NKXv1aVMtyjbtF1oNrsdiPlWqb+3jCaAqU7AKufDa+5JT4SbPc49FRjs15iYsGBZ0o3l+uHAbvCHBXr9unNtcp1AOA9TSh1Hf1aheQ+QX/nLvvaHJT+sx2D/b6ILYOvllzs81w5320o4Kj2SJyZ/ykaKGJVX7KcwA7adcj0o+sMncTuWw63fOQtiTf91rn8Zuo9aJf63N+SKUbNqw4ybaNyEJTLeb X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5753 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: AM5EUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 013d2d61-dd20-4997-4250-08d8b71e9632 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PtikCXp0lKZW9yF8em+8FGOFpHsL/2n27oKWLt8GPyT4Ws3YlmJMxuBRauxPk0YKMX5+coTe1hVGWdQKS0fqLczYUp6ZVPn2eP9vy+wdMcGIRX0WQfny+x4cpICAb2xBz5KHv1Z/cjv7L1NbEdbKNQKbSVSzWXUUq6mkWUtpzWn7iRFp5t3wQFKDrZeH5VR8mF7fqOGswTr7p3R8G1vBmoP1IVFXImWjytJhiBdsVZ9LQ1UjCQ1YIAAVkQFb/4Dlr5Pj4y/kBXTe2Aasr37U92c81pXto8CQtNQZ20SItKHVdBab6HJz0LU92mdmKBAHZBNBIGive5vI8u7m0MvcJOAqYug7nThfev2g+AJoPmD2fhcGSqfkaNxwPVyRFipIWBW0wFWxYX+vbj5yG42xow8v8GTqrUC2BWqybO+O/MsfJxOhetj11AWovyxFhmVQFx2gQf6pWqOMZNU3LIwRbCLt/c3OzieNnO/Tn2LR6gFZQScLEhYDIZCruIFGuOksOeDiA44IzJxUlOD2KTeUIg== 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)(376002)(136003)(39850400004)(346002)(46966006)(83380400001)(81166007)(356005)(6666004)(70586007)(82310400003)(69590400011)(86362001)(34020700004)(82740400003)(70206006)(316002)(6486002)(6512007)(478600001)(2616005)(6506007)(8936002)(336012)(956004)(5660300002)(186003)(2906002)(8676002)(44832011)(26005)(6916009)(16526019)(47076005)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2021 17:22:13.4553 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f588d0e7-bd76-43f6-76dc-08d8b71e9a1a 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: AM5EUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB2928 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_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")))