From patchwork Fri Nov 11 14:48:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 18862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp782966wru; Fri, 11 Nov 2022 06:49:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf71M8P/W9M29cwrEje0WAEC7aqto4KndCK77/k8sTQsPvL7Wvk/uvVOp4LHhl+GhlKKa5FO X-Received: by 2002:a17:906:a386:b0:78d:3f96:b7aa with SMTP id k6-20020a170906a38600b0078d3f96b7aamr2078518ejz.74.1668178177185; Fri, 11 Nov 2022 06:49:37 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qw32-20020a1709066a2000b007a20c586f4esi2265367ejc.876.2022.11.11.06.49.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 06:49:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="hdfkEs8/"; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F0D023858425 for ; Fri, 11 Nov 2022 14:49:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0D023858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668178176; bh=wRH19IW60Kf4P6FtHUsDT3PLPr/MWHRsEFMYeYwBkgQ=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hdfkEs8/1fhQ+/s2gPc/k7BoE+0Q+kj88+kqG1kc6NH+kVQ4YJFsEkk8j3fbbjCxP r7L2k/WL7hwA4QKR4TIHrndDs3ziy60c4d/mSpFGDqO9OxLadmjbnH2KgpzMViGx6N Kw3y6yzpeCpXburarAVjW8zJNuMFH5BDnJa/u6BQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80059.outbound.protection.outlook.com [40.107.8.59]) by sourceware.org (Postfix) with ESMTPS id 1E51F3858D1E for ; Fri, 11 Nov 2022 14:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E51F3858D1E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Ira1e0cuvXi6aqt988FgFRoovbUlinhIhDhicAPg+huira1IWKTXejnWDVvXW0IiOON4iQsu3Qtu5vWghgbOFdFaxt7DN8GG3qB1wzdsBj25UV0/3rE/S10A4QAwe0dnDKEoSrEEk/XWe4Y5jXniGXVItHk3KQWIV4apqvQsMluWV8Nlrr9LEacOUZmlBAlplxZAwvjuPHcmjXRnY7pivC4Z7UONQqotLz0TP5DeCchdQ/1VGuCkd753hQIT34OYdROFzQddDKHERVxKRSVLDxxad6vgHHbXLi+ZAY+4Oo2ukI0jzz/U0kY8FNG0TcmsY5W2Rbl1lQEda1ujtOSH8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wRH19IW60Kf4P6FtHUsDT3PLPr/MWHRsEFMYeYwBkgQ=; b=TbzAktlfiVkMzlMvjhtjOzXqG3IY535sD2TmnOtiVgY8BY3pj6RkKlD45G9oghdfAAP8XvaDw3gRjZPuV5DT83NYHeFhuOuxkhCug1o212b1cpYDx0kXXzVJqUPebj8lrkIQuOtgEXS3UBH3+LnVKbVkBKLditMSWademz6gwEMVp/4JR/ez59VhlW1dO92/w7I7rVc2jXaweIqUNOAzq2p3+Yo8dk91v0gQg86Rbd0My24KiNqhFOOPz/9c38JyFYs69FjOKz2Uy2rta2mnu7wNS5limZ2X6Wj3iGCKhtAO9IgVA91wmp7dKOZrOxwXMP9kiDZfPCjjEgekqTea1A== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB9PR01CA0026.eurprd01.prod.exchangelabs.com (2603:10a6:10:1d8::31) by AS8PR08MB5943.eurprd08.prod.outlook.com (2603:10a6:20b:23e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 14:48:38 +0000 Received: from DBAEUR03FT028.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1d8:cafe::55) by DB9PR01CA0026.outlook.office365.com (2603:10a6:10:1d8::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.14 via Frontend Transport; Fri, 11 Nov 2022 14:48:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT028.mail.protection.outlook.com (100.127.142.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 14:48:37 +0000 Received: ("Tessian outbound f394866f3f2b:v130"); Fri, 11 Nov 2022 14:48:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2207e6965296104b X-CR-MTA-TID: 64aa7808 Received: from eb753722223e.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E47AB532-2CDE-4FE5-832D-A31C3DF6BFBE.1; Fri, 11 Nov 2022 14:48:26 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id eb753722223e.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 14:48:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V4xLERiWdSuejZvK1gXSitVtOHwtWW2dbaCtWKnzfwCWEL/CU9y2+kLkW9CPviVNcxLATDfxHUcEXo9oxDkEjIxsA3go9Mf+IOBgctL9BBi5u36SwueaEaKRZtHtFLUniXXNadX6lcdwmAxDPGtGbV/tLYTSPJaAdqHdpLUytug9w2pJKAVa+Wd6eDL7IIML3mDRkFih7thkoxLuF4av+BotvV8TaYw6BXlB7uBMjEEy8mKVE+7/linQbzLuj2T65tPQbZ/sQ1YIPXCxy02GKmOS+D5ceGRw3lP1dmdILtKlD1kb2VBo7C+yZyfLMHblyFXYxqTt511j0+/R9Pb0vg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wRH19IW60Kf4P6FtHUsDT3PLPr/MWHRsEFMYeYwBkgQ=; b=KoplCPlGWb0zq4Pn6imOqOKHQzjL0feX6s87kZqGI1RL0wBcGwbhu1wJgrlVqn+Rg/8B544XuPHIjmFqjYf/JVOiLhLG60q2EgpL44J8L0wQ44+33i+6v9HtmIzsWRpe6lmvOxykYStSK/PuTHVSO8Qx046ih28JJ20pwCCjIAPTTQ/MTod53KfsDpm4jes/HowPlPdP3HnbLw0spVRvbHAqTjph1ftOtt26PDKQHoAXK79ViLBks07vDprYxcZQsZSCW4DXZeePBP4PX0b0fOwnQa87YVwtgGwbnahxQCCnWGjBxnxkXZIy9kGWBn97/+XHWUy260Oue2gmRTbAqQ== 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 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by DB3PR08MB9036.eurprd08.prod.outlook.com (2603:10a6:10:430::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 14:48:24 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::4c73:7d14:fc39:a3cb]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::4c73:7d14:fc39:a3cb%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 14:48:24 +0000 To: GCC Patches CC: Richard Sandiford , Kyrylo Tkachov , "maskray@google.com" Subject: [PATCH] AArch64: Add support for -mdirect-extern-access Thread-Topic: [PATCH] AArch64: Add support for -mdirect-extern-access Thread-Index: AQHY9dtXMtH7hxnFdEmxr5DzGF96Fg== Date: Fri, 11 Nov 2022 14:48:24 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: PAWPR08MB8982:EE_|DB3PR08MB9036:EE_|DBAEUR03FT028:EE_|AS8PR08MB5943:EE_ X-MS-Office365-Filtering-Correlation-Id: adc4f2b7-6e70-4831-6ec0-08dac3f3d115 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: QkWnw+OHg2ZeTld/xnZy0LWadKGZVlaaaF3xeTG2ajtMFffJ6uX5Yxi/JVpP4akjAOe8yMX1Qhibpo8cF5coQYUZlPW8vQ+Fg177IXskuwGe5soNxvUDtQbkOpjJNAtmuIAvmnB+kdRqGyXhlsVGXr5v/vXzJLBW5nNioRe4nkOyTef5sgJP3o8/h4hrzeyiEizVgD/w1BErVg6jb0STdZk4j0r+ZLDgi0tUXV9aUBSh378zzuOLFBAZ3P/q3nKQc0Wmu2UEvvFeIDtI43M/vvw9uxWsrqmT1QSy85a/LNfJyawl0FUH3M3P8B8futcULb5Aayj6eSC01l65OC7pJwFU9N64tl6HiTlQvKyHrtqFu2yl8DnxiLUsf+yOCGGGTk4oyR9Ikuj3dFKJs9mJbg3AR1qghDGeu01ncf5Ief91KU9F9DqEQ1dMg4pa9rjFSfvTHD0UfrSc27L3mXmFzL/2/Gm2Of02QjpNGM6tZB/BM48zuid/FxvHp8lllMW+03EypG6S0efmkp3WViw+Nqre+UTe+k5gUSN1CnZ7PBPC5GNFHqfoQ5AxgppxFChFXIifE36tm4HPN5Kshbzfjz82+GCKYVPkUcISAbjgC1rVct0pXyKzGqNGJuAg03LO32tuGPLPcQmHb2hj7/odIqLgxVmhr8U3dZzh2qZBXihXQzEPgj+snSMhM2OB1Txo57o5V6DkrIJxVQN0bVqKQsIx63pVw6lCoW0uvf/tkaWaGNDqWr/6tDDtnp3RxA322rMczOHxSD008gMI22L1790oZRbEAR+6z4JIC3EJSR0= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAWPR08MB8982.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(396003)(366004)(346002)(136003)(376002)(451199015)(6916009)(52536014)(6506007)(66446008)(316002)(7696005)(8936002)(54906003)(33656002)(83380400001)(186003)(55016003)(5660300002)(2906002)(91956017)(8676002)(4326008)(66476007)(64756008)(66556008)(76116006)(41300700001)(9686003)(26005)(66946007)(86362001)(38100700002)(38070700005)(71200400001)(478600001)(122000001)(84970400001); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR08MB9036 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 631d8f15-965e-477c-7930-08dac3f3c923 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m/6QRlJbzg3r4m/gdLRDWAIzcGsupPeqImqq1Ns0gxZ7zE73uXJoA90IuPyhjTnY6fTnmjlX5KvPsczKT86HSBDVpZ1ho6rV90WELOEY/VjlRPkBk9fKrFx7UrVM3xUVHaXyKUCRUaEL+LDWLPJnba71TEQ2tAGwvx9kZ5NvqfJeeopfE4pWd/bMapuvTQB+81d3Y332YGd7395jA6fL2KRcrzelW3M0GXvQ3jRPqZ1hIy1FikGQe5RJTRnndpq/sh/3Pl2Sc3qQgb1xQ9RojVI/0lb4ZuYpofZDb4NXeJl4lOF/FB11Zehip0+UbOQziWAwg8pDap/i41gBJGML9jgLvlbnQG/b8YsmzbOxj7Pqucol/i5eIVprefN6VW2/bI2waFCE6C9tH1ReEOuTxo+bbWq+di8pkmfWibetrWhzVC15ijxi8sEAhCFJWFFjvOQsHr31RLs6KBg/0Wki2Jx+tRc/weqcht5YUXk0zMElyUwWHaqlwNhx728KtT28B87dMK5yrlPvhgmiskd+eUvo/ZjT85hIyBla7ngpxhkSdNQlpHWiin/iKBhrAwgQrdjLm+aYHRqS0zhw8Y0aLuveChF4dVEyJDD+E9MGuIwqUtzfGtuOybLnkSx1WvQxTpD/86C1ThftPenWLLyYOT1TEKr/5hUTnuNQonXMj9jsbc05DXbu1r+Jy6AErDJ302tfjjVDoxHADIq2EK75VvCBeweiitG9/y5f+gQW5u/WFogM7k/lLJ5AtOd++AXAxNqq7npiQeTWOeshTb4DYfCSshnJZhQXE6i5Rmi+uII= 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:(13230022)(4636009)(396003)(39860400002)(136003)(346002)(376002)(451199015)(40470700004)(46966006)(36840700001)(82740400003)(81166007)(107886003)(82310400005)(478600001)(356005)(84970400001)(316002)(8936002)(52536014)(36860700001)(7696005)(6506007)(6916009)(54906003)(4326008)(86362001)(70586007)(26005)(9686003)(8676002)(70206006)(33656002)(83380400001)(41300700001)(47076005)(40480700001)(186003)(336012)(2906002)(5660300002)(40460700003)(55016003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 14:48:37.8658 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adc4f2b7-6e70-4831-6ec0-08dac3f3d115 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: DBAEUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5943 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Wilco Dijkstra via Gcc-patches From: Wilco Dijkstra Reply-To: Wilco Dijkstra Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749211600267819157?= X-GMAIL-MSGID: =?utf-8?q?1749211600267819157?= Add a new option -mdirect-extern-access similar to other targets. This removes GOT indirections on external symbols with -fPIE, resulting in significantly better code quality. With -fPIC it only affects protected symbols, allowing for more efficient shared libraries which can be linked with standard PIE binaries (this is what LLVM does by default, so this improves interoperability with LLVM). This patch doesn't affect ABI, but in the future GCC and LLVM should converge to using the same ABI. Regress and bootstrap pass, OK for commit? gcc/ * config/aarch64/aarch64.cc (aarch64_binds_local_p): New function. (aarch64_symbol_binds_local_p): Refactor, support direct extern access. * config/aarch64/aarch64-linux.h (TARGET_BINDS_LOCAL_P): Use aarch64_binds_local_p. * config/aarch64/aarch64-freebsd.h (TARGET_BINDS_LOCAL_P): Likewise. * config/aarch64/aarch64-protos.h: Add aarch64_binds_local_p. * doc/gcc/gcc-command-options/option-summary.rst: Add -mdirect-extern-access. * doc/gcc/gcc-command-options/machine-dependent-options/aarch64-options.rst: Add description of -mdirect-extern-access. gcc/testsuite/ * gcc.target/aarch64/pr66912-2.c: New test. diff --git a/gcc/config/aarch64/aarch64-freebsd.h b/gcc/config/aarch64/aarch64-freebsd.h index 13beb3781b61afd82d767884f3c16ff8eead09cc..20bc0f48e484686cd3754613bf20bb3521079d48 100644 --- a/gcc/config/aarch64/aarch64-freebsd.h +++ b/gcc/config/aarch64/aarch64-freebsd.h @@ -71,7 +71,7 @@ strong definitions in dependent shared libraries, will resolve to COPY relocated symbol in the executable. See PR65780. */ #undef TARGET_BINDS_LOCAL_P -#define TARGET_BINDS_LOCAL_P default_binds_local_p_2 +#define TARGET_BINDS_LOCAL_P aarch64_binds_local_p /* Use the AAPCS type for wchar_t, override the one from config/freebsd.h. */ diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h index 5e4553d79f5053f2da0eb381e0805f47aec964ae..6c962402155d60b82610d4f65af5182d6faa47ad 100644 --- a/gcc/config/aarch64/aarch64-linux.h +++ b/gcc/config/aarch64/aarch64-linux.h @@ -70,7 +70,7 @@ strong definitions in dependent shared libraries, will resolve to COPY relocated symbol in the executable. See PR65780. */ #undef TARGET_BINDS_LOCAL_P -#define TARGET_BINDS_LOCAL_P default_binds_local_p_2 +#define TARGET_BINDS_LOCAL_P aarch64_binds_local_p /* Define this to be nonzero if static stack checking is supported. */ #define STACK_CHECK_STATIC_BUILTIN 1 diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index 238820581c5ee7617f8eed1df2cf5418b1127e19..fac754f78c1d7606ba90e1034820a62466b96b63 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -1072,5 +1072,6 @@ const char *aarch64_sls_barrier (int); const char *aarch64_indirect_call_asm (rtx); extern bool aarch64_harden_sls_retbr_p (void); extern bool aarch64_harden_sls_blr_p (void); +extern bool aarch64_binds_local_p (const_tree); #endif /* GCC_AARCH64_PROTOS_H */ diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index d1f979ebcf80333d957f8ad8631deef47dc693a5..ab4c42c34da5b15f6739c9b0a7ebaafda9488f2d 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -19185,9 +19185,29 @@ aarch64_tlsdesc_abi_id () static bool aarch64_symbol_binds_local_p (const_rtx x) { - return (SYMBOL_REF_DECL (x) - ? targetm.binds_local_p (SYMBOL_REF_DECL (x)) - : SYMBOL_REF_LOCAL_P (x)); + if (!SYMBOL_REF_DECL (x)) + return SYMBOL_REF_LOCAL_P (x); + + if (targetm.binds_local_p (SYMBOL_REF_DECL (x))) + return true; + + /* In PIE binaries avoid a GOT indirection on non-weak data symbols if + aarch64_direct_extern_access is true. */ + if (flag_pie && aarch64_direct_extern_access && !SYMBOL_REF_WEAK (x) + && !SYMBOL_REF_FUNCTION_P (x)) + return true; + + return false; +} + +/* Implement TARGET_BINDS_LOCAL_P hook. */ + +bool +aarch64_binds_local_p (const_tree exp) +{ + /* Protected symbols are local if aarch64_direct_extern_access is true. */ + return default_binds_local_p_3 (exp, flag_shlib != 0, true, + !aarch64_direct_extern_access, !flag_pic); } /* Return true if SYMBOL_REF X is thread local */ diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt index b89b20450710592101b93f4f3b5dc33d152d1eb6..6251a36b544a03955361b445c9f5dfad3740eea8 100644 --- a/gcc/config/aarch64/aarch64.opt +++ b/gcc/config/aarch64/aarch64.opt @@ -299,3 +299,7 @@ Constant memset size in bytes from which to start using MOPS sequence. -param=aarch64-vect-unroll-limit= Target Joined UInteger Var(aarch64_vect_unroll_limit) Init(4) Param Limit how much the autovectorizer may unroll a loop. + +mdirect-extern-access +Target Var(aarch64_direct_extern_access) Init(0) +Do not indirect accesses to external symbols via the GOT. diff --git a/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarch64-options.rst b/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarch64-options.rst index c2b23a6ee97ef2b7c74119f22c1d3e3d85385f4d..599c37fe299dc142d25d2133a4cd0b861e34fd01 100644 --- a/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarch64-options.rst +++ b/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarch64-options.rst @@ -389,6 +389,20 @@ These options are defined for AArch64 implementations: The default is :samp:`-msve-vector-bits=scalable`, which produces vector-length agnostic code. +.. option:: -mdirect-extern-access, -mno-direct-extern-access + + Use direct accesses for external data symbols. It avoids a GOT indirection + on all external data symbols with :option:`-fpie` or :option:`-fPIE`. This is + useful for executables linked with :option:`-static` or :option:`-static-pie`. + With :option:`-fpic` or :option:`-fPIC`, it only affects accesses to protected + data symbols. It has no effect on non-position independent code. The default + is :option:`-mno-direct-extern-access`. + + .. warning:: + + Use :option:`-mdirect-extern-access` either in shared libraries or in + executables, but not in both. Protected symbols used both in a shared + library and executable may cause linker errors or fail to work correctly. .. _aarch64-feature-modifiers: diff --git a/gcc/doc/gcc/gcc-command-options/option-summary.rst b/gcc/doc/gcc/gcc-command-options/option-summary.rst index d068f98feac27d95f1402a530a78b553d623d2e9..dbc9b45ae1db12737aca3a6fd246b88a0e9467c2 100644 --- a/gcc/doc/gcc/gcc-command-options/option-summary.rst +++ b/gcc/doc/gcc/gcc-command-options/option-summary.rst @@ -634,7 +634,8 @@ in the following sections. :option:`-moverride=string` :option:`-mverbose-cost-dump` |gol| :option:`-mstack-protector-guard=guard` :option:`-mstack-protector-guard-reg=sysreg` |gol| :option:`-mstack-protector-guard-offset=offset` :option:`-mtrack-speculation` |gol| - :option:`-moutline-atomics` + :option:`-moutline-atomics` |gol| + :option:`-mdirect-extern-access` *Adapteva Epiphany Options* diff --git a/gcc/testsuite/gcc.target/aarch64/pr66912-2.c b/gcc/testsuite/gcc.target/aarch64/pr66912-2.c new file mode 100644 index 0000000000000000000000000000000000000000..58e6e1f37116bff77015a7321890ece30c9e6a5c --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr66912-2.c @@ -0,0 +1,41 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpic" } */ +/* { dg-require-effective-target fpic } */ + +__attribute__((visibility("protected"))) +int n_common; + +__attribute__((weak, visibility("protected"))) +int n_weak_common; + +__attribute__((visibility("protected"))) +int n_init = -1; + +__attribute__((weak, visibility("protected"))) +int n_weak_init = -1; + +int +f1 () +{ + return n_common; +} + +int +f2 () +{ + return n_weak_common; +} + +int +f3 () +{ + return n_init; +} + +int +f4 () +{ + return n_weak_init; +} + +/* { dg-final { scan-assembler-times ":got" 0 } } */