From patchwork Thu Jan 7 11:01:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1423244 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org 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=nstIHngf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4DBNb338rHz9sWC for ; Thu, 7 Jan 2021 22:01:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3F664396EC67; Thu, 7 Jan 2021 11:01:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F664396EC67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610017293; 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=nstIHngfjZ8D7immAC4Ea/t+dbdTxLbDkeFB7RI4SLMaCS3aNaxFO56HoVzD4ZCul 8IU7Ov6zbs9cOu9xb/DFfeeqGKdS1aB9ZozPW06HeP29oNiUusGsfBDZPZFSL7FioS OoPVCfFFbhyF+03HXudtJw8qmiEFkcgqJyDBXe/M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70075.outbound.protection.outlook.com [40.107.7.75]) by sourceware.org (Postfix) with ESMTPS id 470D0396EC61 for ; Thu, 7 Jan 2021 11:01:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 470D0396EC61 Received: from MR2P264CA0024.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:1::36) by VI1PR08MB4224.eurprd08.prod.outlook.com (2603:10a6:803:bc::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Thu, 7 Jan 2021 11:01:27 +0000 Received: from VE1EUR03FT012.eop-EUR03.prod.protection.outlook.com (2603:10a6:500:1:cafe::c) by MR2P264CA0024.outlook.office365.com (2603:10a6:500:1::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.23 via Frontend Transport; Thu, 7 Jan 2021 11:01:26 +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 VE1EUR03FT012.mail.protection.outlook.com (10.152.18.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Thu, 7 Jan 2021 11:01:26 +0000 Received: ("Tessian outbound eeda57fffe7b:v71"); Thu, 07 Jan 2021 11:01:26 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e60edd44ddb1b21b X-CR-MTA-TID: 64aa7808 Received: from fd0c542fd905.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 94FA249D-09AC-4FEC-98F5-CC3C8FFC1C9A.1; Thu, 07 Jan 2021 11:01:20 +0000 Received: from FRA01-PR2-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fd0c542fd905.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 07 Jan 2021 11:01:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=awMLbFqKycm+oUme1YNMyl6fDoTtJoFC16QDYF0zwp18AlBS8zC4hJmxdEXhy3epit7lMbWuyxNFm77gC39UlScO74GQJi5vYItjRSvGLmNnTiy4/oUdDC+1HAHn/a/jMoFuXk9WAAkaqi/G4exsYEQ3mn2+ysJetHH6oO44GMA7lMC8tq+Mf1RDf5E2dj7dFKasnYNAuFlzh90RJfPhZijOMbBpQFbpIisigutXF77q1kGw6dqN/pllj5IMquZGh+iE+vqeS5csOvmSI2b/whqi/FPHbWXPHQh5yJa1fxPBvbz/jdM6XuxQLxxLehQFGphCx0a4TX6tDecY7XyNAg== 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=GlH0zdQnGO4Im7XZO6ybTb7wa4Bz3S6XgZORo3z4OFlZUoPMedR1QtjxTLRxzq7J2qApS/F+UZZ3m508BUk1H0FODFHmf+9IcGAg9XXXeP68H8wMBDQik1z3meG34veQzFBnboc1kD7V/bDbpXHWld9QGEoyj5uQDWXSregz9bb5pSO2Px5NDg6GC+mEO1FxuTM05CcITYK/mjQnRtG0Qz+ohhc93m5KyrAIQhrmlweDpNE8OnS1ycvTqWFxdKCzpEG1YwGQ0qyLuJ1YbgTI4W+/hzEeflMH/Hy3VQcQvR2ATaPmczOUpM0xLFdOE8hxOa3EIguJpgKShDJQMu2e3g== 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 PR2PR08MB4809.eurprd08.prod.outlook.com (2603:10a6:101:1a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.21; Thu, 7 Jan 2021 11:01:18 +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; Thu, 7 Jan 2021 11:01:18 +0000 To: libc-alpha@sourceware.org Subject: [PATCH 1/3] Make libc symbols hidden in static PIE Date: Thu, 7 Jan 2021 11:01:06 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.51] X-ClientProxiedBy: SN6PR16CA0054.namprd16.prod.outlook.com (2603:10b6:805:ca::31) 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 SN6PR16CA0054.namprd16.prod.outlook.com (2603:10b6:805:ca::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Thu, 7 Jan 2021 11:01:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6e64f9b8-b556-414c-9a1a-08d8b2fb942e X-MS-TrafficTypeDiagnostic: PR2PR08MB4809:|VI1PR08MB4224: 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: XVpvZ5ZrQ6Ll2KO5wsIi81S6jRFcM3rzwRP9P1R9rKd5U2GbQIJYurbCciDvd971kfOA/bRGn2ornwX1vdo1WtNPTgY60gjOBU8S3iJnQWwOJ54aBOmY7kZGnZZW6s42YpF2S81jxSz9+sKi3r6lfX1AUF9975hyk6XHdIY0DM2rBLiPzQcHL8dyp4S/hJtrepNfpN6JgcyJEVBVW8LrlxYSVYo/TwjJFZajlLsWn2NkjHhJFN8uwpz0MfGkLfC92Yu23JxxIRN8HKvhEYoTxCtvA4rDQI1KGlR49Puy6q5XO1aZSknvS0u3lfRlGx30niWLnQbX9j3rcUv2U5Ix1BCRxWpeXRE5zIPDp1mlSOeodDQZpbbYeIiYak+z3u/qPIlpnJTfOT6r0GqTNFehUoyZFH9P35YbRvRRf7ee7o4Weww1vy9dsm+ehz9ilKapNtV2XhTttPziBAo8ET3NMw== 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)(136003)(396003)(39860400002)(376002)(366004)(6666004)(2616005)(6916009)(86362001)(44832011)(69590400011)(52116002)(6486002)(956004)(8936002)(36756003)(26005)(2906002)(66946007)(66476007)(16526019)(5660300002)(6506007)(66556008)(83380400001)(8676002)(316002)(186003)(6512007)(478600001); DIR:OUT; SF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08MB4809 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: VE1EUR03FT012.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 8eb15e62-a5f9-4584-a4c2-08d8b2fb8f31 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /V2XIeIE7o70lKVuzvZZh3antXOvvC7WsZ0oEFz3rqmJD26VmqJvh9f5jGc4G0w9vL/SHIn12G3/NZulX2uSgsm3Ld3+4QJvc2NrjyH1O3yt8M6WG+g1QtETK6/LJarixlvNWnt3pEUw3lMEUovp8IrLpIIDt2TZ8lUX4/Iw5x6WvCNjnUK17z8Tj4rmRH4Ggp0q5/1CWpiFHkCa6M9IG/Ve0TAuhCV6yVCIhE129vpidEpPTrBnQREWVK7NuDBYdIrB1GE437NRx1EC+wcGdSVZoWE4/fDW3sJbmGCJ64KbzGcjppSqPeMqnaS+69QqtbgPBiqpphWuT+GEXuwO2oz16DRe6ih2VIHOLYbutYk/rxw6GR7cjKXNQO7jtmWor6z35wUU74RMVCV2Pu5rkSzPNd78uTWyofJZQrCLOH+888Osa2Q8vmwcCUoLGZ6JZLy3P0tp3pHy8a3Q0AoB7CvDwUWoFMZ1u3vg8cHAYUSEJGWWbwTHTdqEsfokrYStq7dZWPcjrzpiPEp+ieMxKQ== 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)(376002)(346002)(136003)(396003)(39860400002)(46966006)(86362001)(6486002)(6512007)(36756003)(6916009)(44832011)(956004)(478600001)(336012)(2616005)(83380400001)(8936002)(8676002)(6506007)(2906002)(16526019)(186003)(70586007)(5660300002)(70206006)(47076005)(316002)(356005)(81166007)(82740400003)(6666004)(34020700004)(82310400003)(26005)(69590400011); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2021 11:01:26.4253 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e64f9b8-b556-414c-9a1a-08d8b2fb942e 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: VE1EUR03FT012.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4224 X-Spam-Status: No, score=-13.9 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. 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")))