From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m9a0013g.houston.softwaregrp.com (m9a0013g.houston.softwaregrp.com [15.124.64.91]) by mx.groups.io with SMTP id smtpd.web10.3970.1590630052353718959 for ; Wed, 27 May 2020 18:40:59 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: suse.com, ip: 15.124.64.91, mailfrom: glin@suse.com) Received: FROM m9a0013g.houston.softwaregrp.com (15.121.0.190) BY m9a0013g.houston.softwaregrp.com WITH ESMTP; Thu, 28 May 2020 01:40:07 +0000 Received: from M9W0067.microfocus.com (2002:f79:be::f79:be) by M9W0067.microfocus.com (2002:f79:be::f79:be) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Thu, 28 May 2020 01:36:48 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (15.124.72.10) by M9W0067.microfocus.com (15.121.0.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Thu, 28 May 2020 01:36:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I/RI6Nmk8P7C7h7p+f4fbn2pJKTM7F1Eqtyj+R6ELrssmCPwbGiKBvxGMWnU775BHhlVnYaT7puMqHIrdHmw7FqcIvqNqyV+SlgV5cqmB5zkd4fJ3q+IkxMdXae0HdlpZ+P7P/BTcLhUp13Z9LkjiiszPi9wqYHRNlWHhtneT3pheKb80C9yrynXZPXmh6044EV/U3ziv5CaRyuYzj5ODOMAWJB8M1kHqAVixsN+Nw7iI9wsUjcs6svRJabTosq/UB/dnW0b6tLcQzJmHyF1me4Do2w2rCFBbKt/xDUdkEQAAQNbAYe8yjEckOc1LxnxKm+u132dA8qEX0v/V0d+LQ== 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=QXp43zWUNvfuCrgAJ/eu9s/k4/lv9tsdiPr3fE8z6vQ=; b=TfOMELHwKoskpD/CyXMsy3AkT8+0H6vrNntXZpC1DZV0Xku/yYBXrD9ykeIBy2Gy3sw+pJFLVFyTqbg95Ds9K7Nq9nV9zhHcSVjNNC0tO5j536BIbwTpVUV4LIPrkAcLpRKldxyB1VxMjX6tmqO9Ewosap0YkLMuoKF9n44c0PFOg6BzX97uzKFIw6y3Y9OYQYniovz1tLmzBJKoPWm/SI8SeLEsnFSVzPWtqmFdmN2tpGnZ350WRf0KJ1w1a+4Zlqwy7UEfVF+TaS1W4iU6Q+Qg8jVNx6aZX3VeM0c1zumv0LkUjzsG/FP6wKua8WVk++EEtkfmLUjcjrRVWiGwdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=suse.com; Received: from SN1PR18MB2237.namprd18.prod.outlook.com (2603:10b6:802:24::17) by SN1PR18MB2096.namprd18.prod.outlook.com (2603:10b6:802:2f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Thu, 28 May 2020 01:36:45 +0000 Received: from SN1PR18MB2237.namprd18.prod.outlook.com ([fe80::a85d:80ef:1ad3:e8c4]) by SN1PR18MB2237.namprd18.prod.outlook.com ([fe80::a85d:80ef:1ad3:e8c4%7]) with mapi id 15.20.3021.030; Thu, 28 May 2020 01:36:44 +0000 Date: Thu, 28 May 2020 09:36:33 +0800 From: "Gary Lin" To: , CC: , , Subject: Re: [edk2-devel] [PATCH v2] ArmPkg/CompilerIntrinsicsLib: provide atomics intrinsics Message-ID: <20200528013633.GF24379@GaryWorkstation> References: <20200520114448.26104-1-ard.biesheuvel@arm.com> In-Reply-To: <20200520114448.26104-1-ard.biesheuvel@arm.com> X-ClientProxiedBy: LO2P123CA0006.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::18) To SN1PR18MB2237.namprd18.prod.outlook.com (2603:10b6:802:24::17) Return-Path: GLin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation (60.251.47.115) by LO2P123CA0006.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Thu, 28 May 2020 01:36:42 +0000 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a83f6568-164a-45b0-73b0-08d802a79441 X-MS-TrafficTypeDiagnostic: SN1PR18MB2096: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-Forefront-PRVS: 0417A3FFD2 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3zZDeco2z4sgT7cEJkgPuPTHk3/bKJ6FfvN/ZKDIJHEQ4j57hPvYpUj3y6r2UMrO+XzSCzT20UNS06Cyi7WMlGaaZdWyCgfOo+W9Dp9IUha7btUhhAltjftRuMJLs6cnZkpWYkYIJ6GOQUeL1NQ2xAJA+sL1ResU3xVWU5628AB07V49nm/+LtU6OKKVIolUuMqpR2GB/UVwit10ckyT5N8WaDx5JVApz1C/+OOnoYOMCHB3RNc/FEJP58ojNvw12rxyll1E9rUgDP0AyYqHGVCjnPaiIazAa+O/LscQzuYZ1HG1CeZmOMbqKSUYOzzCSgstm/KVIivT/5hMRRKoyblPbU/o2mI+gPpezzLrZ2B5VfehJJqwQVqPTGkl+/t+fZUzpxjh42PPTx/QyPi0aA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN1PR18MB2237.namprd18.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(376002)(366004)(39860400002)(136003)(346002)(6666004)(186003)(4326008)(33656002)(33716001)(55016002)(316002)(8936002)(8676002)(2906002)(956004)(9686003)(1076003)(26005)(86362001)(5660300002)(966005)(55236004)(66556008)(66476007)(52116002)(83380400001)(16526019)(478600001)(66946007)(6496006);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: fNJUJQZpvsTjLs8M5TOktcwTjcxwSNVrUBG5qiEHSK1aLTGLU7OkFunI9oD2+yWKyfZulpbmuJ08y5LXkSq9aEL+THfJeW+QxpSB1MHNi5YMgYUK8NdtQ68qi8oFZKwwM1uFSRSRR7lK2AkQbh0r0QBELqbgM54Jnds4umgNAM5j5vs2Aa1jbDrQFpRPPFAS+6eUty98Qam5L62Z0/ZIDmo7fyvhGUZ01X/5EJ9qTvTn1y4H6qLITwP6UoshBfWQZ1BAwkdJlHJZOQ4tiwZhqnFlxpf/pM9UeCMXUedHvy1g/oJ4Jb2kS3xhzJ2OgVVoUG15R0fD2bSDTvxK+RDB8p/+F0RKnPB7b5cb9m1fWZZSU561RAR7lKGC0G06vp3SqOTMKU0xdrf2LXv7kQLtQZP02LxqsuuAQH7WimTwww7OoFiGICUTLQf3WJVweZOR3/xNnEu+1eJdCrkLViISB9HM/zIKIOwh4z7EdYy4NhA= X-MS-Exchange-CrossTenant-Network-Message-Id: a83f6568-164a-45b0-73b0-08d802a79441 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2020 01:36:44.7803 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 337LUMCwiI1gR+JpZnAbl7rVknP6gaz1xJchWQowEs31g0mchDYVNLO6w+gLMb5P X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR18MB2096 X-OriginatorOrg: suse.com Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline On Wed, May 20, 2020 at 01:44:48PM +0200, Ard Biesheuvel wrote: > Gary reports the GCC 10 will emit calls to atomics intrinsics routines > unless -mno-outline-atomics is specified. This means GCC-10 introduces > new intrinsics, and even though it would be possible to work around this > by specifying the command line option, this would require a new GCC10 > toolchain profile to be created, which we prefer to avoid. > > So instead, add the new intrinsics to our library so they are provided > when necessary. > > Signed-off-by: Ard Biesheuvel After applying this patch, gcc 10 can build ArmVirtPkg without the linking error. Tested-by: Gary Lin > --- > v2: > - add missing .globl to export the functions from the object file > - add function end markers so the size of each is visible in the ELF metadata > - add some comments to describe what is going on > > ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf | 3 + > ArmPkg/Library/CompilerIntrinsicsLib/AArch64/Atomics.S | 142 ++++++++++++++++++++ > 2 files changed, 145 insertions(+) > > diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf b/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf > index d5bad9467758..fcf48c678119 100644 > --- a/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf > +++ b/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf > @@ -79,6 +79,9 @@ [Sources.ARM] > Arm/ldivmod.asm | MSFT > Arm/llsr.asm | MSFT > > +[Sources.AARCH64] > + AArch64/Atomics.S | GCC > + > [Packages] > MdePkg/MdePkg.dec > ArmPkg/ArmPkg.dec > diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/Atomics.S b/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/Atomics.S > new file mode 100644 > index 000000000000..dc61d6bb8e52 > --- /dev/null > +++ b/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/Atomics.S > @@ -0,0 +1,142 @@ > +#------------------------------------------------------------------------------ > +# > +# Copyright (c) 2020, Arm, Limited. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#------------------------------------------------------------------------------ > + > + /* > + * Provide the GCC intrinsics that are required when using GCC 9 or > + * later with the -moutline-atomics options (which became the default > + * in GCC 10) > + */ > + .arch armv8-a > + > + .macro reg_alias, pfx, sz > + r0_\sz .req \pfx\()0 > + r1_\sz .req \pfx\()1 > + tmp0_\sz .req \pfx\()16 > + tmp1_\sz .req \pfx\()17 > + .endm > + > + /* > + * Define register aliases of the right type for each size > + * (xN for 8 bytes, wN for everything smaller) > + */ > + reg_alias w, 1 > + reg_alias w, 2 > + reg_alias w, 4 > + reg_alias x, 8 > + > + .macro fn_start, name:req > + .section .text.\name > + .globl \name > + .type \name, %function > +\name\(): > + .endm > + > + .macro fn_end, name:req > + .size \name, . - \name > + .endm > + > + /* > + * Emit an atomic helper for \model with operands of size \sz, using > + * the operation specified by \insn (which is the LSE name), and which > + * can be implemented using the generic load-locked/store-conditional > + * (LL/SC) sequence below, using the arithmetic operation given by > + * \opc. > + */ > + .macro emit_ld_sz, sz:req, insn:req, opc:req, model:req, s, a, l > + fn_start __aarch64_\insn\()\sz\()\model > + mov tmp0_\sz, r0_\sz > +0: ld\a\()xr\s r0_\sz, [x1] > + .ifnc \insn, swp > + \opc tmp1_\sz, r0_\sz, tmp0_\sz > + .else > + \opc tmp1_\sz, tmp0_\sz > + .endif > + st\l\()xr\s w15, tmp1_\sz, [x1] > + cbnz w15, 0b > + ret > + fn_end __aarch64_\insn\()\sz\()\model > + .endm > + > + /* > + * Emit atomic helpers for \model for operand sizes in the > + * set {1, 2, 4, 8}, for the instruction pattern given by > + * \insn. (This is the LSE name, but this implementation uses > + * the generic LL/SC sequence using \opc as the arithmetic > + * operation on the target.) > + */ > + .macro emit_ld, insn:req, opc:req, model:req, a, l > + emit_ld_sz 1, \insn, \opc, \model, b, \a, \l > + emit_ld_sz 2, \insn, \opc, \model, h, \a, \l > + emit_ld_sz 4, \insn, \opc, \model, , \a, \l > + emit_ld_sz 8, \insn, \opc, \model, , \a, \l > + .endm > + > + /* > + * Emit the compare and swap helper for \model and size \sz > + * using LL/SC instructions. > + */ > + .macro emit_cas_sz, sz:req, model:req, uxt:req, s, a, l > + fn_start __aarch64_cas\sz\()\model > + \uxt tmp0_\sz, r0_\sz > +0: ld\a\()xr\s r0_\sz, [x2] > + cmp r0_\sz, tmp0_\sz > + bne 1f > + st\l\()xr\s w15, r1_\sz, [x2] > + cbnz w15, 0b > +1: ret > + fn_end __aarch64_cas\sz\()\model > + .endm > + > + /* > + * Emit compare-and-swap helpers for \model for operand sizes in the > + * set {1, 2, 4, 8, 16}. > + */ > + .macro emit_cas, model:req, a, l > + emit_cas_sz 1, \model, uxtb, b, \a, \l > + emit_cas_sz 2, \model, uxth, h, \a, \l > + emit_cas_sz 4, \model, mov , , \a, \l > + emit_cas_sz 8, \model, mov , , \a, \l > + > + /* > + * We cannot use the parameterized sequence for 16 byte CAS, so we > + * need to define it explicitly. > + */ > + fn_start __aarch64_cas16\model > + mov x16, x0 > + mov x17, x1 > +0: ld\a\()xp x0, x1, [x4] > + cmp x0, x16 > + ccmp x1, x17, #0, eq > + bne 1f > + st\l\()xp w15, x16, x17, [x4] > + cbnz w15, 0b > +1: ret > + fn_end __aarch64_cas16\model > + .endm > + > + /* > + * Emit the set of GCC outline atomic helper functions for > + * the memory ordering model given by \model: > + * - relax unordered loads and stores > + * - acq load-acquire, unordered store > + * - rel unordered load, store-release > + * - acq_rel load-acquire, store-release > + */ > + .macro emit_model, model:req, a, l > + emit_ld ldadd, add, \model, \a, \l > + emit_ld ldclr, bic, \model, \a, \l > + emit_ld ldeor, eor, \model, \a, \l > + emit_ld ldset, orr, \model, \a, \l > + emit_ld swp, mov, \model, \a, \l > + emit_cas \model, \a, \l > + .endm > + > + emit_model _relax > + emit_model _acq, a > + emit_model _rel,, l > + emit_model _acq_rel, a, l > -- > 2.17.1 > > > >