Aarch64 ASM quirk

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Aarch64 ASM quirk

Tom Stellard via cfe-dev
I'm running Clang 9.0.0 on Windows, with target aarch64-unknown-windows.  I get the same error building on Linux.  Code below.

The difference is a CR/LF.  The original builds fine with GCC.  

By design, or bug?


Joel


### Code ###

.global MyFunc ; .section ".text.My Func" ; .type My Func, %function ; MyFunc:

 # do something really important
  ret

.global MyFunSize

MyFunSize
  .long . - MyFunc


### Error ###

error: symbol 'My Func' can not be undefined in a subtraction expression
  .long . - MyFunc
            ^

### Resolution ###

global MyFunc; .section ".text.MyFunc" .type MyFunc, %function;
My Func:

  # do something really important
  ret

.global MyFuncSize

MyFuncSize
  .long . - MyFunc

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Aarch64 ASM quirk

Tom Stellard via cfe-dev
Hello Joel,

The root cause is that the AArch64 target is using ';' as a comment
character, whereas in GNU as (and many other llvm MC backends),  the
';' is used as a statement separator. In your example only the text up
to ';' is being parsed.

Looking at AArch64MCAsmInfo.cpp
  SeparatorString = "%%";
  CommentString = ";";

I think that this is likely to have been derived from Darwin as I
can't get the "%%" to work as a statement separator for
aarch64-linux-gnu targets.

Is this intentional? Probably, as the initial implementation is likely
to have come from Darwin. Is it a bug? At least for linux targets it
is a difference from GNU which documents ";" as the statement
separator https://sourceware.org/binutils/docs/as/AArch64_002dChars.html#AArch64_002dChars
, Is it fixable? I don't know, changing the separator to ';' even for
non darwin targets could break code that has only been assembled with
clang, yet only used ';' as a comment character.

Feel free to raise a PR if you have a strong opinion. Alternatively,
always use a newline for statement separator to be compatible with
both GNU and LLVM.

Peter


On Thu, 7 Nov 2019 at 23:53, Joel Winarske via cfe-dev
<[hidden email]> wrote:

>
> I'm running Clang 9.0.0 on Windows, with target aarch64-unknown-windows.  I get the same error building on Linux.  Code below.
>
> The difference is a CR/LF.  The original builds fine with GCC.
>
> By design, or bug?
>
>
> Joel
>
>
> ### Code ###
>
> .global MyFunc ; .section ".text.My Func" ; .type My Func, %function ; MyFunc:
>
>  # do something really important
>   ret
>
> .global MyFunSize
>
> MyFunSize
>   .long . - MyFunc
>
>
> ### Error ###
>
> error: symbol 'My Func' can not be undefined in a subtraction expression
>   .long . - MyFunc
>             ^
>
> ### Resolution ###
>
> global MyFunc; .section ".text.MyFunc" .type MyFunc, %function;
> My Func:
>
>   # do something really important
>   ret
>
> .global MyFuncSize
>
> MyFuncSize
>   .long . - MyFunc
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Aarch64 ASM quirk

Tom Stellard via cfe-dev
On Fri, 8 Nov 2019, Peter Smith via cfe-dev wrote:

> Hello Joel,
>
> The root cause is that the AArch64 target is using ';' as a comment
> character, whereas in GNU as (and many other llvm MC backends),  the
> ';' is used as a statement separator. In your example only the text up
> to ';' is being parsed.
>
> Looking at AArch64MCAsmInfo.cpp
>  SeparatorString = "%%";
>  CommentString = ";";
>
> I think that this is likely to have been derived from Darwin as I
> can't get the "%%" to work as a statement separator for
> aarch64-linux-gnu targets.

I don't know about the separator string, but if you look in
AArch64MCAsmInfoELF (and AArch64MCAsmInfoGNUCOFF), the comment string is
set to "//" instead.

I suggested changing this for the GNUCOFF (aka MinGW) target, as mingw-w64
contains a number of assembler files that uses this pattern of piling up a
few directives on one line.

As there's very little predecent for GNU style .s assembler for
aarch64-windows-msvc targets (as the official tool from microsoft,
armasm64, uses a totally different syntax), I'm guess it would be fine to
change the comment string to "//" there as well, as there apparently is a
demand for it?

With a target that doesn't treat ";" as a comment char, your assembler
example errors out due to issues with the section and type directives
though, now that they actually are interpreted and not stripped out as
comments.

// Martin

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Aarch64 ASM quirk

Tom Stellard via cfe-dev
Ah yes, a comment...

Is there a seperator character that works?

On Fri, Nov 8, 2019, 5:43 AM Martin Storsjö <[hidden email]> wrote:
On Fri, 8 Nov 2019, Peter Smith via cfe-dev wrote:

> Hello Joel,
>
> The root cause is that the AArch64 target is using ';' as a comment
> character, whereas in GNU as (and many other llvm MC backends),  the
> ';' is used as a statement separator. In your example only the text up
> to ';' is being parsed.
>
> Looking at AArch64MCAsmInfo.cpp
>  SeparatorString = "%%";
>  CommentString = ";";
>
> I think that this is likely to have been derived from Darwin as I
> can't get the "%%" to work as a statement separator for
> aarch64-linux-gnu targets.

I don't know about the separator string, but if you look in
AArch64MCAsmInfoELF (and AArch64MCAsmInfoGNUCOFF), the comment string is
set to "//" instead.

I suggested changing this for the GNUCOFF (aka MinGW) target, as mingw-w64
contains a number of assembler files that uses this pattern of piling up a
few directives on one line.

As there's very little predecent for GNU style .s assembler for
aarch64-windows-msvc targets (as the official tool from microsoft,
armasm64, uses a totally different syntax), I'm guess it would be fine to
change the comment string to "//" there as well, as there apparently is a
demand for it?

With a target that doesn't treat ";" as a comment char, your assembler
example errors out due to issues with the section and type directives
though, now that they actually are interpreted and not stripped out as
comments.

// Martin


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Aarch64 ASM quirk

Tom Stellard via cfe-dev
I don't think that there is an alternative separator for the Windows
target as both the CommentString and SeparatorString are ";". I don't
have a strong opinion over changing the comment character for AArch64
Windows target. Probably best addressed by the people that use/develop
on it. It is true that armasm(64) uses ";" as its comment character,
but as Martin says many of the directives and other bits of syntax are
different so at least some form of scripted conversion is likely to be
needed anyway.

Peter

On Fri, 8 Nov 2019 at 20:31, Joel Winarske <[hidden email]> wrote:

>
> Ah yes, a comment...
>
> Is there a seperator character that works?
>
> On Fri, Nov 8, 2019, 5:43 AM Martin Storsjö <[hidden email]> wrote:
>>
>> On Fri, 8 Nov 2019, Peter Smith via cfe-dev wrote:
>>
>> > Hello Joel,
>> >
>> > The root cause is that the AArch64 target is using ';' as a comment
>> > character, whereas in GNU as (and many other llvm MC backends),  the
>> > ';' is used as a statement separator. In your example only the text up
>> > to ';' is being parsed.
>> >
>> > Looking at AArch64MCAsmInfo.cpp
>> >  SeparatorString = "%%";
>> >  CommentString = ";";
>> >
>> > I think that this is likely to have been derived from Darwin as I
>> > can't get the "%%" to work as a statement separator for
>> > aarch64-linux-gnu targets.
>>
>> I don't know about the separator string, but if you look in
>> AArch64MCAsmInfoELF (and AArch64MCAsmInfoGNUCOFF), the comment string is
>> set to "//" instead.
>>
>> I suggested changing this for the GNUCOFF (aka MinGW) target, as mingw-w64
>> contains a number of assembler files that uses this pattern of piling up a
>> few directives on one line.
>>
>> As there's very little predecent for GNU style .s assembler for
>> aarch64-windows-msvc targets (as the official tool from microsoft,
>> armasm64, uses a totally different syntax), I'm guess it would be fine to
>> change the comment string to "//" there as well, as there apparently is a
>> demand for it?
>>
>> With a target that doesn't treat ";" as a comment char, your assembler
>> example errors out due to issues with the section and type directives
>> though, now that they actually are interpreted and not stripped out as
>> comments.
>>
>> // Martin
>>
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Aarch64 ASM quirk

Tom Stellard via cfe-dev
I added a Sed step.  I double up the semicolon, and only convert for  Clang aarch64-unkown-windows.  Not ideal, but it works.

I'm onto lld-link problems now.


Thanks for all the input.

On Mon, Nov 11, 2019, 9:41 AM Peter Smith <[hidden email]> wrote:
I don't think that there is an alternative separator for the Windows
target as both the CommentString and SeparatorString are ";". I don't
have a strong opinion over changing the comment character for AArch64
Windows target. Probably best addressed by the people that use/develop
on it. It is true that armasm(64) uses ";" as its comment character,
but as Martin says many of the directives and other bits of syntax are
different so at least some form of scripted conversion is likely to be
needed anyway.

Peter

On Fri, 8 Nov 2019 at 20:31, Joel Winarske <[hidden email]> wrote:
>
> Ah yes, a comment...
>
> Is there a seperator character that works?
>
> On Fri, Nov 8, 2019, 5:43 AM Martin Storsjö <[hidden email]> wrote:
>>
>> On Fri, 8 Nov 2019, Peter Smith via cfe-dev wrote:
>>
>> > Hello Joel,
>> >
>> > The root cause is that the AArch64 target is using ';' as a comment
>> > character, whereas in GNU as (and many other llvm MC backends),  the
>> > ';' is used as a statement separator. In your example only the text up
>> > to ';' is being parsed.
>> >
>> > Looking at AArch64MCAsmInfo.cpp
>> >  SeparatorString = "%%";
>> >  CommentString = ";";
>> >
>> > I think that this is likely to have been derived from Darwin as I
>> > can't get the "%%" to work as a statement separator for
>> > aarch64-linux-gnu targets.
>>
>> I don't know about the separator string, but if you look in
>> AArch64MCAsmInfoELF (and AArch64MCAsmInfoGNUCOFF), the comment string is
>> set to "//" instead.
>>
>> I suggested changing this for the GNUCOFF (aka MinGW) target, as mingw-w64
>> contains a number of assembler files that uses this pattern of piling up a
>> few directives on one line.
>>
>> As there's very little predecent for GNU style .s assembler for
>> aarch64-windows-msvc targets (as the official tool from microsoft,
>> armasm64, uses a totally different syntax), I'm guess it would be fine to
>> change the comment string to "//" there as well, as there apparently is a
>> demand for it?
>>
>> With a target that doesn't treat ";" as a comment char, your assembler
>> example errors out due to issues with the section and type directives
>> though, now that they actually are interpreted and not stripped out as
>> comments.
>>
>> // Martin
>>

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev