From patchwork Wed Jan 20 15:31:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 41775 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 42ADF396E83F; Wed, 20 Jan 2021 15:31:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42ADF396E83F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611156718; bh=MD8os6ogBhc/djnpi791uMhtujkzAbvC3E0DJ/D5oo0=; 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=EA1XJmi1weCkS22FqUecL5KUbed5fvchxL8+Edac0POn8UzJOW+rcd/cXL9lmNK16 29EE5GmiZOCWaEQNz7fhd3pwyPBZKVdiXASAIHysyRiqc4umIqyxNrLdr7hArsHUGB a9QSGsvXx2Z6+XaCyFCA2PeDfDSvNamQRT9OUowE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0628.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::628]) by sourceware.org (Postfix) with ESMTPS id DB7C1385700F for ; Wed, 20 Jan 2021 15:31:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DB7C1385700F Received: from DB7PR05CA0024.eurprd05.prod.outlook.com (2603:10a6:10:36::37) by VE1PR08MB5727.eurprd08.prod.outlook.com (2603:10a6:800:1a5::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12; Wed, 20 Jan 2021 15:31:39 +0000 Received: from DB5EUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:36:cafe::c9) by DB7PR05CA0024.outlook.office365.com (2603:10a6:10:36::37) 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:31:38 +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 DB5EUR03FT019.mail.protection.outlook.com (10.152.20.163) 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:31:38 +0000 Received: ("Tessian outbound e989e14f9207:v71"); Wed, 20 Jan 2021 15:31:38 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3428ffd598accdc0 X-CR-MTA-TID: 64aa7808 Received: from cecc729764a7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 47C50E69-7060-41EE-9579-F0CE510CD4A0.1; Wed, 20 Jan 2021 15:31:31 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cecc729764a7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 20 Jan 2021 15:31:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VmtQrJE1ZAzbo5peU1h0W7zF6tdmkqSkD+QBiMBANshfiuWXnky7j8LWzwLjAxiO2zaN3dkVfNvnTFRp/kfuA0/KgQad7BKl+AAgPlIIt9b7V8iAVw9Gyox6Z/DZm4MEIq40JDSvtjDglJyQsNYMwWXGaOBs4kCjFsAaIjgX1IhTWkxNB5kY/TveVee8ij91Y0rpetTQBgL41jvV+oAtwi3TMkTLlXAxZTwrHHZiNUyNG0fPIN4mZLtwiVKYDvhPJZD2WgJwV69aVX2QMFSYHlWgMp27QEDLeLxrTJOER3JfDtl/2PMTwf2hjdbHpblNb4bKKzbyXAp+zSYVOHb9lg== 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=MD8os6ogBhc/djnpi791uMhtujkzAbvC3E0DJ/D5oo0=; b=hve7taWSVPpOvRa9baMxirgAJSCvCNOId7593yVpGGLhwET1L3y19QJ4FrWfaJsfE8//WHqZStDW5zNaDh8TGEMaQNlSCVAWQRxwktdUom3mkkfMi21rvJkFd1JIYWQYqBP4XW+xUvhn0hY+bmB0Zdaz2R+SlgNf2gH3tq1Y/saMZqFctSKf2SSVU2tAKzHijx+g6N7x4T0hboDugvPfMsD5qGSsQLmUBCJk6Kls4jhFTVgJw+CYuUBOUbC3UgIaXZL3b4Tv5nuDd/VHTAIougO+ugPoiQ0nrdAFfjSxhO6hQQ9q5ByFgUoYxxYxiNG4J35nrrX367xTH0VYMI1/3g== 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:31:30 +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:31:28 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v5 5/7] Use hidden visibility for early static PIE code Date: Wed, 20 Jan 2021 15:31:22 +0000 Message-Id: <54afd0132a909969862bb2ce96bd5e95beab324a.1611155254.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: LO4P123CA0487.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1ab::6) 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 LO4P123CA0487.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1ab::6) 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:31:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 744655f6-f482-480f-d3a2-08d8bd587ad7 X-MS-TrafficTypeDiagnostic: PR3PR08MB5577:|VE1PR08MB5727: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: K3FxYjNp7ykFjeGDFZg6sdn5ZF3FeR0OT0VL3Bft8tmGAHvW0nsQSZ2HcNEgOnGHkS3tmqeqwM9YJ7FIzv1ZjKp1BP30MT8s5mAEg7uXgUQkoMZVaXAxUSxhZQ48mgVilwk5JqWetX3J2cR6MBbiiZTytTtjzQbF+nltOXaHEkW7CHu/well2/PRZ0i+zgqMnK+pTnHA6Iyj7alrFZtYruR4mMfH7CQ6TLsudnnrjc3GH4nJDuCKuvxcp0hVzcf/nkqyjAreV0tRx0/N47ZcA5EGRFvqRG/1QhC6oYdxzwvbwF1h+1qMu/soCetR82EkTElyliP86mPiK2QFh4ghdK3sBSMJseaez9708dlCCzWPIXjaQlrnFm1/9TGzedVD1MS+fqqCJctufO8JumdhnbL+c+LybeAWA9DxuwaD1QLwY8c68peLFWk2z0d5m9lLE+B4K2sVXrV3knT7eYzdWR4DeCiakGmnwOnUieZ0/eXNG9VGbSKT+uNq3zHsadEoSPCfa8TGS4zhusYkn/RvNg== 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: lkT05E2ZAcFGMJD7BJw8FG0rBXoSCPzn6Zr1Tr83d7xRUoL7iDj9YHSryrsqZX31EGN2o7xCvKixJylwV9BQkgOajjfNn/fx8ICdVqv7jtC9CZmHDCjTQdqGq9AjGqfgyZDjaZda+CDtjBsKlqHYwUwFNE+t34b0cnBpwn5crEBoOrb0W+4f75cEK0nAh8fIz//zViKHSkrAyT6YpFR15dqE9c4u2VKwVLTN7HqrU7M38YrdTfqxOD68UquTyQJDfxFAmcZ1VD1KAROXg5moFKPLZOlv3NeApeWx3vXFoaOLQBPZbkk44O8KdZ4pXTvh/A/7cXfQf/g5MQb9rtrpCawOSATvqD2mvTUIcch6Qr/CH9YoFl9HW7csZUdJA/tVKJ+PkUeUVPIE1PaOo3TYrHOs0idtUAW2UuYN0TT6iQLheMPPKtijNgUmcy3cfIcjCHD3spbuaTlrDyD9you6qqMMyDoPh10g7iNL4hP9G8q9FUTIFV2/g44Vi7huX2oSQktjQRzHl+jkwc0BhZb6TFArIvPyLjybQ9jQqeKRRgkdLeKu9XqbIWGNxkmSjoAZ+rE3t7P4ByT8VoPeSELy0N8uXrrx8M1RLkBA5HKm3G6C2Q6NpzUJgzsm2/KDgVJAnSwMo/Ryb9UwSz5cnuaKW6g/w+k4LcHGKklnNcef+mT/O5OxTZv2Gervcv+/xJ28JNXNq0am+914eMrwpPMXiKKCU2+FmV3hiWP9aWmX3hPZJZUR/UyA08MhxS+FBWymPS+cVMPOtjiPJZm/xn/NYkxkiXk7s5tihcA5+57VNYFH8iF5p/fobt1I+tbopUkBfHifB8URiaoyHeqZIDwykzZeIL1Mth1ZnraxHC3ovJFVp6fF3jCprfak7qF9LAHVQCSnu1cTR3Xaqouh/VhEgtPzW94sHRzLY4vRedcRU5vddy4NF4yuuBOHNrxNCaZO4RPuf4xDhNauWvwNUEB3TrKWXGfK+zoLjfRU2JYQkbmSxxVYNHj2Lu4W6VoVtefT 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: DB5EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 4e1d93c0-003c-4b99-3d9a-08d8bd5874be X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cqCGM88J56u1gTTcbe63ENrM/1X0Swm2pBNGuZ84VNkcS4DCMtcNNTtagCSNVzEm2e0v0p5jMs/Ey71jA6aGSbKc6xqwnzPshga3jlwuVOenqTEpMOFZ9H+2mjeimvrKpFAKTVxPRiA59XJP9QKpQN0geSgrC0E01/n2SoIAHnarJlsVbL7FFq9dBBjldw+x7gji2EjhrYzASlJy5vzRS+3lrsDeg6FUebidOjEg3+8EMVKkPNHqShygRazj18EAsFnal0uZJAifaLhtybp3H+cProlgI20e1UvryHUCA4kDiZg/ZTAj2Cmxf8nitL7vZaV5Rx7p7CKDnv6tIfEEQM99gFdnCk8GB+hIUm6sUazY62573ARC0AjL+T156XKwRMGRxRcaDnQgwqoLEmxC72Muz2hA0AsOdopb+ufll50pQC5tDWxQ+STvRPiSTazo8xIta8AWKn3WHo9oDWsKdqMzU69z/xJ7q0dbD3g5vRd2p/2RDUuimJ5vexoYCxpjWPvmYdxfC2QpR7T5nCLJTaKyJXqXhqZJypjQo7zP4HoJi3br6fPD2qMW8Cue7IpalFT1U/Z46MkqJVfRaiHReQ== 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)(39860400002)(346002)(376002)(396003)(46966006)(2616005)(81166007)(6666004)(356005)(82310400003)(6486002)(82740400003)(956004)(6512007)(44832011)(36756003)(336012)(478600001)(5660300002)(70586007)(186003)(70206006)(6506007)(6916009)(316002)(8676002)(2906002)(47076005)(16526019)(26005)(86362001)(69590400011)(8936002)(83380400001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2021 15:31:38.8591 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 744655f6-f482-480f-d3a2-08d8bd587ad7 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: DB5EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5727 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, 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" Extern symbol access in position independent code usually involves GOT indirection which needs RELATIVE reloc in a static linked PIE. (On some targets this is avoided e.g. because the linker can relax a GOT access to a pc-relative access, but this is not generally true.) Code that runs before static PIE self relocation must avoid relying on dynamic relocations which can be ensured by using hidden visibility. However we cannot just make all symbols hidden: On i386, all calls to IFUNC functions must go through PLT and calls to hidden functions CANNOT go through PLT in PIE since EBX used in PIE PLT may not be set up for local calls to hidden IFUNC functions. This patch aims to make symbol references hidden in code that is used before and by _dl_relocate_static_pie when building a static PIE libc. Note: for an object that is used in the startup code, its references and definition may not have consistent visibility: it is only forced hidden in the startup code. This is needed for fixing bug 27072. Co-authored-by: H.J. Lu Reviewed-by: Adhemerval Zanella --- csu/libc-start.c | 4 ++++ elf/dl-reloc-static-pie.c | 2 ++ elf/dl-support.c | 6 ++++++ elf/dl-tunables.c | 4 ++++ elf/enbl-secure.c | 4 ++++ misc/sbrk.c | 4 ++++ sysdeps/unix/sysv/linux/aarch64/libc-start.c | 5 +++++ sysdeps/x86/libc-start.c | 5 +++++ 8 files changed, 34 insertions(+) diff --git a/csu/libc-start.c b/csu/libc-start.c index 5b9ce1d158..a2f6e12728 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -15,6 +15,10 @@ License along with the GNU C Library; if not, see . */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c index a8d964061e..d5bd2f31e9 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -17,6 +17,8 @@ . */ #if ENABLE_STATIC_PIE +/* Mark symbols hidden in static PIE for early self relocation to work. */ +# pragma GCC visibility push(hidden) #include #include #include "dynamic-link.h" diff --git a/elf/dl-support.c b/elf/dl-support.c index 2434c470c7..7abb65d8e3 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -19,6 +19,12 @@ /* This file defines some things that for the dynamic linker are defined in rtld.c and dl-sysdep.c in ways appropriate to bootstrap dynamic linking. */ +#include +/* Mark symbols hidden in static PIE for early self relocation to work. + Note: string.h may have ifuncs which cannot be hidden on i686. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index e44476f204..b1a50b8469 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -18,6 +18,10 @@ License along with the GNU C Library; if not, see . */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include diff --git a/elf/enbl-secure.c b/elf/enbl-secure.c index 5dcf649626..9e47526bd3 100644 --- a/elf/enbl-secure.c +++ b/elf/enbl-secure.c @@ -19,6 +19,10 @@ /* This file is used in the static libc. For the shared library, dl-sysdep.c defines and initializes __libc_enable_secure. */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include diff --git a/misc/sbrk.c b/misc/sbrk.c index 99b3fb517e..95800b32aa 100644 --- a/misc/sbrk.c +++ b/misc/sbrk.c @@ -15,6 +15,10 @@ License along with the GNU C Library; if not, see . */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-start.c b/sysdeps/unix/sysv/linux/aarch64/libc-start.c index f816f04ee1..e1604a6ed0 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc-start.c +++ b/sysdeps/unix/sysv/linux/aarch64/libc-start.c @@ -17,6 +17,11 @@ . */ #ifndef SHARED + +/* Mark symbols hidden in static PIE for early self relocation to work. */ +# if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +# endif # include # include diff --git a/sysdeps/x86/libc-start.c b/sysdeps/x86/libc-start.c index 4bbd7d555b..d30aec2aa1 100644 --- a/sysdeps/x86/libc-start.c +++ b/sysdeps/x86/libc-start.c @@ -16,6 +16,11 @@ . */ #ifndef SHARED + +/* Mark symbols hidden in static PIE for early self relocation to work. */ +# if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +# endif /* Define I386_USE_SYSENTER to support syscall during startup in static PIE. */ # include