From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com 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]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wRH19IW60Kf4P6FtHUsDT3PLPr/MWHRsEFMYeYwBkgQ=; b=pvJdZIuP8699mI9uqSMjUxz+L7CeYwq/b/5RlJoODHFm+NRoxnaecRuD0M6XZFBzUcTVRLsGbwfBojprFumBGxeqaDzNpOVTfl6bmmH5jCrOmr5aSXJKAvw8M7WJIC3T1jCPZoez/PpQ+Mf73PmxiPb6UuQQlnL5MdcniH/ciQc= 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wRH19IW60Kf4P6FtHUsDT3PLPr/MWHRsEFMYeYwBkgQ=; b=pvJdZIuP8699mI9uqSMjUxz+L7CeYwq/b/5RlJoODHFm+NRoxnaecRuD0M6XZFBzUcTVRLsGbwfBojprFumBGxeqaDzNpOVTfl6bmmH5jCrOmr5aSXJKAvw8M7WJIC3T1jCPZoez/PpQ+Mf73PmxiPb6UuQQlnL5MdcniH/ciQc= 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 From: Wilco Dijkstra 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; Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 List-Id: Add a new option -mdirect-extern-access similar to other targets. This rem= oves=0A= GOT indirections on external symbols with -fPIE, resulting in significantly= =0A= better code quality. With -fPIC it only affects protected symbols, allowin= g=0A= for more efficient shared libraries which can be linked with standard PIE= =0A= binaries (this is what LLVM does by default, so this improves interoperabil= ity=0A= with LLVM). This patch doesn't affect ABI, but in the future GCC and LLVM= =0A= should converge to using the same ABI.=0A= =0A= Regress and bootstrap pass, OK for commit?=0A= =0A= gcc/=0A= * config/aarch64/aarch64.cc (aarch64_binds_local_p): New function.=0A= (aarch64_symbol_binds_local_p): Refactor, support direct extern access.=0A= * config/aarch64/aarch64-linux.h (TARGET_BINDS_LOCAL_P):=0A= Use aarch64_binds_local_p.=0A= * config/aarch64/aarch64-freebsd.h (TARGET_BINDS_LOCAL_P): Likewise.=0A= * config/aarch64/aarch64-protos.h: Add aarch64_binds_local_p.=0A= * doc/gcc/gcc-command-options/option-summary.rst: Add=0A= -mdirect-extern-access.=0A= * doc/gcc/gcc-command-options/machine-dependent-options/aarch64-options.rs= t:=0A= Add description of -mdirect-extern-access.=0A= =0A= gcc/testsuite/=0A= * gcc.target/aarch64/pr66912-2.c: New test.=0A= =0A= ---=0A= =0A= diff --git a/gcc/config/aarch64/aarch64-freebsd.h b/gcc/config/aarch64/aarc= h64-freebsd.h=0A= index 13beb3781b61afd82d767884f3c16ff8eead09cc..20bc0f48e484686cd3754613bf2= 0bb3521079d48 100644=0A= --- a/gcc/config/aarch64/aarch64-freebsd.h=0A= +++ b/gcc/config/aarch64/aarch64-freebsd.h=0A= @@ -71,7 +71,7 @@=0A= strong definitions in dependent shared libraries, will resolve=0A= to COPY relocated symbol in the executable. See PR65780. */=0A= #undef TARGET_BINDS_LOCAL_P=0A= -#define TARGET_BINDS_LOCAL_P default_binds_local_p_2=0A= +#define TARGET_BINDS_LOCAL_P aarch64_binds_local_p=0A= =0A= /* Use the AAPCS type for wchar_t, override the one from=0A= config/freebsd.h. */=0A= diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch6= 4-linux.h=0A= index 5e4553d79f5053f2da0eb381e0805f47aec964ae..6c962402155d60b82610d4f65af= 5182d6faa47ad 100644=0A= --- a/gcc/config/aarch64/aarch64-linux.h=0A= +++ b/gcc/config/aarch64/aarch64-linux.h=0A= @@ -70,7 +70,7 @@=0A= strong definitions in dependent shared libraries, will resolve=0A= to COPY relocated symbol in the executable. See PR65780. */=0A= #undef TARGET_BINDS_LOCAL_P=0A= -#define TARGET_BINDS_LOCAL_P default_binds_local_p_2=0A= +#define TARGET_BINDS_LOCAL_P aarch64_binds_local_p=0A= =0A= /* Define this to be nonzero if static stack checking is supported. */=0A= #define STACK_CHECK_STATIC_BUILTIN 1=0A= diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch= 64-protos.h=0A= index 238820581c5ee7617f8eed1df2cf5418b1127e19..fac754f78c1d7606ba90e103482= 0a62466b96b63 100644=0A= --- a/gcc/config/aarch64/aarch64-protos.h=0A= +++ b/gcc/config/aarch64/aarch64-protos.h=0A= @@ -1072,5 +1072,6 @@ const char *aarch64_sls_barrier (int);=0A= const char *aarch64_indirect_call_asm (rtx);=0A= extern bool aarch64_harden_sls_retbr_p (void);=0A= extern bool aarch64_harden_sls_blr_p (void);=0A= +extern bool aarch64_binds_local_p (const_tree);=0A= =0A= #endif /* GCC_AARCH64_PROTOS_H */=0A= diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc= =0A= index d1f979ebcf80333d957f8ad8631deef47dc693a5..ab4c42c34da5b15f6739c9b0a7e= baafda9488f2d 100644=0A= --- a/gcc/config/aarch64/aarch64.cc=0A= +++ b/gcc/config/aarch64/aarch64.cc=0A= @@ -19185,9 +19185,29 @@ aarch64_tlsdesc_abi_id ()=0A= static bool=0A= aarch64_symbol_binds_local_p (const_rtx x)=0A= {=0A= - return (SYMBOL_REF_DECL (x)=0A= - ? targetm.binds_local_p (SYMBOL_REF_DECL (x))=0A= - : SYMBOL_REF_LOCAL_P (x));=0A= + if (!SYMBOL_REF_DECL (x))=0A= + return SYMBOL_REF_LOCAL_P (x);=0A= +=0A= + if (targetm.binds_local_p (SYMBOL_REF_DECL (x)))=0A= + return true;=0A= +=0A= + /* In PIE binaries avoid a GOT indirection on non-weak data symbols if= =0A= + aarch64_direct_extern_access is true. */=0A= + if (flag_pie && aarch64_direct_extern_access && !SYMBOL_REF_WEAK (x)=0A= + && !SYMBOL_REF_FUNCTION_P (x))=0A= + return true;=0A= +=0A= + return false;=0A= +}=0A= +=0A= +/* Implement TARGET_BINDS_LOCAL_P hook. */=0A= +=0A= +bool=0A= +aarch64_binds_local_p (const_tree exp)=0A= +{=0A= + /* Protected symbols are local if aarch64_direct_extern_access is true. = */=0A= + return default_binds_local_p_3 (exp, flag_shlib !=3D 0, true,=0A= + !aarch64_direct_extern_access, !flag_pic);=0A= }=0A= =0A= /* Return true if SYMBOL_REF X is thread local */=0A= diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.op= t=0A= index b89b20450710592101b93f4f3b5dc33d152d1eb6..6251a36b544a03955361b445c9f= 5dfad3740eea8 100644=0A= --- a/gcc/config/aarch64/aarch64.opt=0A= +++ b/gcc/config/aarch64/aarch64.opt=0A= @@ -299,3 +299,7 @@ Constant memset size in bytes from which to start using= MOPS sequence.=0A= -param=3Daarch64-vect-unroll-limit=3D=0A= Target Joined UInteger Var(aarch64_vect_unroll_limit) Init(4) Param=0A= Limit how much the autovectorizer may unroll a loop.=0A= +=0A= +mdirect-extern-access=0A= +Target Var(aarch64_direct_extern_access) Init(0)=0A= +Do not indirect accesses to external symbols via the GOT.=0A= diff --git a/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarc= h64-options.rst b/gcc/doc/gcc/gcc-command-options/machine-dependent-options= /aarch64-options.rst=0A= index c2b23a6ee97ef2b7c74119f22c1d3e3d85385f4d..599c37fe299dc142d25d2133a4c= d0b861e34fd01 100644=0A= --- a/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarch64-opt= ions.rst=0A= +++ b/gcc/doc/gcc/gcc-command-options/machine-dependent-options/aarch64-opt= ions.rst=0A= @@ -389,6 +389,20 @@ These options are defined for AArch64 implementations:= =0A= The default is :samp:`-msve-vector-bits=3Dscalable`, which produces=0A= vector-length agnostic code.=0A= =0A= +.. option:: -mdirect-extern-access, -mno-direct-extern-access=0A= +=0A= + Use direct accesses for external data symbols. It avoids a GOT indirect= ion=0A= + on all external data symbols with :option:`-fpie` or :option:`-fPIE`. T= his is=0A= + useful for executables linked with :option:`-static` or :option:`-static= -pie`.=0A= + With :option:`-fpic` or :option:`-fPIC`, it only affects accesses to pro= tected=0A= + data symbols. It has no effect on non-position independent code. The d= efault=0A= + is :option:`-mno-direct-extern-access`.=0A= +=0A= + .. warning::=0A= +=0A= + Use :option:`-mdirect-extern-access` either in shared libraries or in= =0A= + executables, but not in both. Protected symbols used both in a shared= =0A= + library and executable may cause linker errors or fail to work correct= ly.=0A= =0A= .. _aarch64-feature-modifiers:=0A= =0A= diff --git a/gcc/doc/gcc/gcc-command-options/option-summary.rst b/gcc/doc/g= cc/gcc-command-options/option-summary.rst=0A= index d068f98feac27d95f1402a530a78b553d623d2e9..dbc9b45ae1db12737aca3a6fd24= 6b88a0e9467c2 100644=0A= --- a/gcc/doc/gcc/gcc-command-options/option-summary.rst=0A= +++ b/gcc/doc/gcc/gcc-command-options/option-summary.rst=0A= @@ -634,7 +634,8 @@ in the following sections.=0A= :option:`-moverride=3Dstring` :option:`-mverbose-cost-dump` |gol|=0A= :option:`-mstack-protector-guard=3Dguard` :option:`-mstack-protector-gua= rd-reg=3Dsysreg` |gol|=0A= :option:`-mstack-protector-guard-offset=3Doffset` :option:`-mtrack-specu= lation` |gol|=0A= - :option:`-moutline-atomics`=0A= + :option:`-moutline-atomics` |gol|=0A= + :option:`-mdirect-extern-access`=0A= =0A= *Adapteva Epiphany Options*=0A= =0A= diff --git a/gcc/testsuite/gcc.target/aarch64/pr66912-2.c b/gcc/testsuite/g= cc.target/aarch64/pr66912-2.c=0A= new file mode 100644=0A= index 0000000000000000000000000000000000000000..58e6e1f37116bff77015a732189= 0ece30c9e6a5c=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.target/aarch64/pr66912-2.c=0A= @@ -0,0 +1,41 @@=0A= +/* { dg-do compile { target *-*-linux* } } */=0A= +/* { dg-options "-O2 -fpic" } */=0A= +/* { dg-require-effective-target fpic } */=0A= +=0A= +__attribute__((visibility("protected")))=0A= +int n_common;=0A= +=0A= +__attribute__((weak, visibility("protected")))=0A= +int n_weak_common;=0A= +=0A= +__attribute__((visibility("protected")))=0A= +int n_init =3D -1;=0A= +=0A= +__attribute__((weak, visibility("protected")))=0A= +int n_weak_init =3D -1;=0A= +=0A= +int=0A= +f1 ()=0A= +{=0A= + return n_common;=0A= +}=0A= +=0A= +int=0A= +f2 ()=0A= +{=0A= + return n_weak_common;=0A= +}=0A= +=0A= +int=0A= +f3 ()=0A= +{=0A= + return n_init;=0A= +}=0A= +=0A= +int=0A= +f4 ()=0A= +{=0A= + return n_weak_init;=0A= +}=0A= +=0A= +/* { dg-final { scan-assembler-times ":got" 0 } } */=0A= =0A=