From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) by mx.groups.io with SMTP id smtpd.web10.1429.1641425497891218871 for ; Wed, 05 Jan 2022 15:31:38 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kyUcgfVI; spf=pass (domain: gmail.com, ip: 209.85.222.52, mailfrom: pedro.falcato@gmail.com) Received: by mail-ua1-f52.google.com with SMTP id u6so1419572uaq.0 for ; Wed, 05 Jan 2022 15:31:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5qpIb+pPrI0pJJTw3MPQkoAojyyytx0f0LGfQb2kuZQ=; b=kyUcgfVIZadODmgnrUUxdvqdLJmtOxh8wbpJYkVtsFCdZ2RhntqB/4SxyaLCsPTpiq QJnR4laFnwdSUeBhbGFNWUtUiJrnff82j+W+WI1QP/ynxp1o/HHeAnuYR6c8KLo8iQHr 93VtaFV7bC8BEx8i1Ge0GlK1IP2oPUv9XWVW8ZpwVkdg5wtzhB4ZrAG4XvWTHJSKfTaW oXCNgAS0ydBgCkVyGqcAPY10DtgMP7x6f4uviHFcuxhLLwSAJwC+8l7LhTxoxT1pnvI3 qFaf45hDvTLm8oiwNkOKe4tY8LCJExxlJJtICNC3TE4+gbUpMmEesaCqoZ6XaGgNrlhq LU0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5qpIb+pPrI0pJJTw3MPQkoAojyyytx0f0LGfQb2kuZQ=; b=LDYvN8Q3RAz3AFAv7d4W61c+od+mWhaFdjcfrAGzwrgfCJM2DNuxP0jDevq+euT1pC /eP/no4xQjpFPbyGQSOpDEvBTn3jgL9+qEpVV+b10vPc0112B/CmSHFpxuFkZkRxhn4g Stj8fvFnsguY+cw33jEMXajTmAsi8tldnd+DCvGCKjI28SxzmtaS0I7E5fEOhu9aK5ji Y1MK3LIN+qZ4H8cd9787+wVgfBr9ZLGqPFUP2N49B2PFhCO7ySL/lfHYxTElPE9m1AL5 V2luK8eFHAdMDSf9slD3ps7CR3e5x8XYAtQEm2OkPZzHdgCTtf2YLODoEmeRiFr7Zptv lVvw== X-Gm-Message-State: AOAM532O1hpPoj4vPrdRku8y4c0/lPQrOGmQT+KaUjMK9wNELpDGP9jw 648HsQvKaOfhbN1vC4JIVCOG4P4/YB4gco219SYJDWXw774= X-Google-Smtp-Source: ABdhPJxnNOdkVMPRdYDsjwUg41h9ECMNOCTqdpNzdwDtDcJi3EpE6/hdR7wIWNC2Vw1gDUlP/Yr54MVQi/pI0wSLe14= X-Received: by 2002:a05:6102:cca:: with SMTP id g10mr9750007vst.75.1641425496754; Wed, 05 Jan 2022 15:31:36 -0800 (PST) MIME-Version: 1.0 References: <962A1DA2-CB34-49F5-A721-AE7E5C82FA04@apple.com> In-Reply-To: <962A1DA2-CB34-49F5-A721-AE7E5C82FA04@apple.com> From: "Pedro Falcato" Date: Wed, 5 Jan 2022 23:31:24 +0000 Message-ID: Subject: Re: [edk2-devel] AArch64 assembly compatibility for Xcode and GCC To: edk2-devel-groups-io , Andrew Fish Cc: Leif Lindholm Content-Type: multipart/alternative; boundary="000000000000a8d0e205d4de2779" --000000000000a8d0e205d4de2779 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, GNU Assembler and the clang assembler support more complex macros natively (using the .macro and.endm directives), without the need for the C preprocessor. This completely sidesteps the need for explicit ";" as the GAS macros respect newlines inside the macro. See https://godbolt.org/z/6zzqoeKE4 for a very simple example. Of course, you can also pass arguments, see https://sourceware.org/binutils/docs/as/Macro.html for the full documentation. Best regards, Pedro On Wed, Jan 5, 2022 at 8:36 PM Andrew Fish via groups.io wrote: > I was playing around with getting Xcode to compile AArch64 code and I hit > an interesting compatibility issue. The assembler line continuation token > for GCC (;) is a comment for the Xcode clang assembler. For Xcode clang y= ou > need to use %%. Yikes [1] > > I was wondering if any one else has hit this in another project and if > there was any cool workaround? > > The only thing I can think of is the =E2=80=9Cbig hammer=E2=80=9D on both= (well you only > need one) ends. We could replace ; with a #define that matches the > assembler. It looks like this issue mostly hits in Code that is using C > pre-processor macros so we could refactor the code. I=E2=80=99m a little = concerned > that the C pre processor is getting used since the macro languages of the > assembler might also have some compatibility issues? > > Looking for ideas and opinions on the best way to fix this if we want to > add Xcode as an ARM compiler in the future. > > > [1] > https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/AArc= h64/SetJumpLongJump.S#L13 > > #define GPR_LAYOUT \ > REG_PAIR (x19, x20, 0); \ > REG_PAIR (x21, x22, 16); \ > REG_PAIR (x23, x24, 32); \ > REG_PAIR (x25, x26, 48); \ > REG_PAIR (x27, x28, 64); \ > REG_PAIR (x29, x30, 80);/*FP, LR*/ \ > REG_ONE (x16, 96) /*IP0*/ > I had to change it to: > > #define GPR_LAYOUT \ > REG_PAIR (x19, x20, 0)%% \ > REG_PAIR (x21, x22, 16)%% \ > REG_PAIR (x23, x24, 32)%% \ > REG_PAIR (x25, x26, 48)%% \ > REG_PAIR (x27, x28, 64)%% \ > REG_PAIR (x29, x30, 80)%%/*FP, LR*/ \ > REG_ONE (x16, 96) /*IP0*/ > > Thanks, > > Andrew Fish > >=20 > > --=20 Pedro Falcato --000000000000a8d0e205d4de2779 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

GNU Assembler and the clang assembl= er support more complex macros natively (using the .macro and.endm directiv= es), without the need for the C preprocessor.
This completely sid= esteps the need for explicit ";" as the GAS macros respect newlin= es inside the macro.

See=C2=A0https://godbolt.org/z/6zzqoeKE4 for a very simp= le example.
Of course, you can also pass arguments, see=C2=A0https://sourcewa= re.org/binutils/docs/as/Macro.html for the full documentation.

Best regards,
Pedro

On Wed, Jan 5, 2022 at = 8:36 PM Andrew Fish via groups.io <afis= h=3Dapple.com@groups.io> wrot= e:
I was playing around with getting Xcode to com= pile AArch64 code and I hit an interesting compatibility issue. The assembl= er line continuation token for GCC (;) is a comment for the Xcode clang ass= embler. For Xcode clang you need to use %%. Yikes [1]

I = was wondering if any one else has hit this in another project and if there = was any cool workaround?

The only thing I can thin= k of is the =E2=80=9Cbig hammer=E2=80=9D on both (well you only need one) e= nds. We could replace ; with a #define that matches the assembler. It looks= like this issue mostly hits in Code that is using C pre-processor macros s= o we could refactor the code. I=E2=80=99m a little concerned that the C pre= processor is getting used since the macro languages of the assembler might= also have some compatibility issues?

Looking for = ideas and opinions on the best way to fix this if we want to add Xcode as a= n ARM compiler in the future.=C2=A0



= <= /tbody>
#define GPR_LAYOUT \
REG_PAIR (x19, x20, 0); \
REG_PAIR (x21, x22, 16); \
REG_PAIR (x23, x24, 32); \
REG_PAIR (x25, x26, 48); \
REG_PAIR (x27, x28, 64); \
REG_PAIR (x29, x30, 80);/*FP, LR*/ \
REG_ONE (x16, 96) /*IP0*/
I had to change it to:

= <= /tbody>
#define GPR_LAYOUT \
REG_PAIR (x19, x20, 0)%% \
REG_PAIR (x21, x22, 16)%% \
REG_PAIR (x23, x24,= 32)%% \
REG_PAIR (x25, x= 26, 48)%% \
REG_PAIR (x27= , x28, 64)%% \
REG_PAIR (= x29, x30, 80)%%/*FP, LR*/ \
REG_ONE (x16, 96) /*IP= 0*/
<= /td>
Thanks,

Andrew Fish

=20



--
Pedro Falcato
--000000000000a8d0e205d4de2779--