public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* AArch64 assembly compatibility for Xcode and GCC
@ 2022-01-05 20:36 Andrew Fish
  2022-01-05 23:31 ` [edk2-devel] " Pedro Falcato
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Fish @ 2022-01-05 20:36 UTC (permalink / raw)
  To: edk2-devel-groups-io; +Cc: Leif Lindholm

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

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 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 think of is the “big hammer” 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’m 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/AArch64/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


[-- Attachment #2: Type: text/html, Size: 23748 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] AArch64 assembly compatibility for Xcode and GCC
  2022-01-05 20:36 AArch64 assembly compatibility for Xcode and GCC Andrew Fish
@ 2022-01-05 23:31 ` Pedro Falcato
  2022-01-06 10:38   ` Akira Moroo
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Falcato @ 2022-01-05 23:31 UTC (permalink / raw)
  To: edk2-devel-groups-io, Andrew Fish; +Cc: Leif Lindholm

[-- Attachment #1: Type: text/plain, Size: 2232 bytes --]

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 <afish=
apple.com@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 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 think of is the “big hammer” 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’m 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/AArch64/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
>
> 
>
>

-- 
Pedro Falcato

[-- Attachment #2: Type: text/html, Size: 17350 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] AArch64 assembly compatibility for Xcode and GCC
  2022-01-05 23:31 ` [edk2-devel] " Pedro Falcato
@ 2022-01-06 10:38   ` Akira Moroo
  0 siblings, 0 replies; 3+ messages in thread
From: Akira Moroo @ 2022-01-06 10:38 UTC (permalink / raw)
  To: devel, pedro.falcato, Andrew Fish; +Cc: Leif Lindholm

Hi,

I tried to add support AArch64 XCODE5 about three months ago, too. I had the same compatibility issue in the other code. I just ended up adding ugly #ifdef as a workaround [1]. I think there are other compatibility issues in the current EDK2 code base. I’m not sure if the GAS macro and Apple Clang Assembler are compatible, but the C standard guarantees C preprocessor macro compatibility.

[1] https://github.com/retrage/edk2/commit/89b166758b9f858373bb20eb8e006914f7f13373

Best regards,

Akira Moroo

> On Jan 6, 2022, at 8:31, Pedro Falcato <pedro.falcato@gmail.com> wrote:
> 
> 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 <afish=apple.com@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 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 think of is the “big hammer” 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’m 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/AArch64/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
> 
> 
> 
> 
> 
> -- 
> Pedro Falcato
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-06 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-05 20:36 AArch64 assembly compatibility for Xcode and GCC Andrew Fish
2022-01-05 23:31 ` [edk2-devel] " Pedro Falcato
2022-01-06 10:38   ` Akira Moroo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox