Mailing List Archive

libgcrypt clang asm configure issue.
Hello,

I found a strange libgcrypt behavior on ARM with clang built.

There is a big gap in performance of libgcrypt, built by clang, in
comparison with gcc on my ARM target machine.
The simple profile test shows 100-500% advantage of gcc gcrypt.
I found an awkward workaround to beat this issue, but need your help to
find the best way to fix it.

The root cause is next:
Due to clang strict assembler syntax rules the unified assembler ARM check
doesn't pass.
Assembler check fails while ./configure for flags:
HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS
HAVE_GCC_INLINE_ASM_NEON

As a workaround I remove '%' from registers names in
configure.ac,
arm mips lib *.S files,
cipher/*arm.S,*armv7-neon.S files.

Could you please help with a more correct - polite way to compile libgcrypt
with assembler code?

Tested on:
libgcrypt-1.8.6
libgcrypt-1.9.3

Equipment:

build machine:
intel based cpu x86_64
Ubnuntu-20.04

Software
compiler : clang 11.1.0
linker lld : lld 11.1.0
assembler : llvm-as 11.1.0
cflags : "-m32 -march=armv7-a -mthumb -mfpu=vfpv3-d16
--target=arm-linux-gnueabihf"

arm-linux-gnueabihf sysroot based on glibc 2.31

libgcrypt configuring:
CC="arm-linux-gnueabihf-clang" \
./configure \
--with-libgpg-error-prefix=<libgpg.so path> \
--prefix=<output path> \
--host=arm-linux-gnueabihf \
--enable-static \
--disable-doc


target machine:
hardware:
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 2304.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
vfpd32 lpae aes pmull sha1 sha2 crc32


Best Regards,
Dmytro Kovalov
Dmytro.a.kovalov@globallogic.com
Re: libgcrypt clang asm configure issue. [ In reply to ]
Dmytro Kovalov via Gnupg-users wrote:
> Hello,
>
> I found a strange libgcrypt behavior on ARM with clang built.
>
> There is a big gap in performance of libgcrypt, built by clang, in
> comparison with gcc on my ARM target machine.
> The simple profile test shows 100-500% advantage of gcc gcrypt.
> I found an awkward workaround to beat this issue, but need your help
> to find the best way to fix it.
>
> The root cause is next:
> Due to clang strict assembler syntax rules the unified assembler ARM
> check doesn't pass.
> Assembler check fails while ./configure for flags:
> HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS
> HAVE_GCC_INLINE_ASM_NEON
>
> As a workaround I remove '%' from registers names in
> configure.ac <http://configure.ac/>,
> arm mips lib *.S files,
> cipher/*arm.S,*armv7-neon.S files.
>
> Could you please help with a more correct - polite way to compile
> libgcrypt with assembler code?

I would suggest using the GNU toolchain. :-)

The problem is that the GNU assembler traditionally expects register
names to be prefixed with %, using a syntax based on that of the old
AT&T assembler and known (simply enough) as "AT&T syntax" while many
vendor assemblers use a different syntax. Note that the configure tests
in question are for GCC-or-strictly-compatible. If clang does not
support the GNU assembler syntax, then it is not fully compatible with
GCC, and libgcrypt is being compiled correctly.

Since LLVM claims compatibility with GCC, you should direct your
complaints there: CLang apparently claims compatibility with the GNU
toolchain, but does not support GNU assembler syntax.


-- Jacob

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
Re: libgcrypt clang asm configure issue. [ In reply to ]
Hello Jacob ,

Thanks for the fast response!

So you mentioned the problem is in clang ATT compatibility. But could you
please confirm the UAL supports ATT style , because I haven't found any
information there.

Thanks,
Best Regards.

On Mon, 31 Oct 2022, 04:56 Jacob Bachmeyer, <jcb62281@gmail.com> wrote:

> Dmytro Kovalov via Gnupg-users wrote:
> > Hello,
> >
> > I found a strange libgcrypt behavior on ARM with clang built.
> >
> > There is a big gap in performance of libgcrypt, built by clang, in
> > comparison with gcc on my ARM target machine.
> > The simple profile test shows 100-500% advantage of gcc gcrypt.
> > I found an awkward workaround to beat this issue, but need your help
> > to find the best way to fix it.
> >
> > The root cause is next:
> > Due to clang strict assembler syntax rules the unified assembler ARM
> > check doesn't pass.
> > Assembler check fails while ./configure for flags:
> > HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS
> > HAVE_GCC_INLINE_ASM_NEON
> >
> > As a workaround I remove '%' from registers names in
> > configure.ac <http://configure.ac/
> <http://configure.ac>
> >,
> > arm mips lib *.S files,
> > cipher/*arm.S,*armv7-neon.S files.
> >
> > Could you please help with a more correct - polite way to compile
> > libgcrypt with assembler code?
>
> I would suggest using the GNU toolchain. :-)
>
> The problem is that the GNU assembler traditionally expects register
> names to be prefixed with %, using a syntax based on that of the old
> AT&T assembler and known (simply enough) as "AT&T syntax" while many
> vendor assemblers use a different syntax. Note that the configure tests
> in question are for GCC-or-strictly-compatible. If clang does not
> support the GNU assembler syntax, then it is not fully compatible with
> GCC, and libgcrypt is being compiled correctly.
>
> Since LLVM claims compatibility with GCC, you should direct your
> complaints there: CLang apparently claims compatibility with the GNU
> toolchain, but does not support GNU assembler syntax.
>
>
> -- Jacob
>
Re: libgcrypt clang asm configure issue. [ In reply to ]
Dmytro Kovalov wrote:
> Hello Jacob ,
>
> Thanks for the fast response!
>
> So you mentioned the problem is in clang ATT compatibility. But could
> you please confirm the UAL supports ATT style , because I haven't
> found any information there.

UAL is ?

The key hint here for me was that you mentioned removing '%' from
register names; the use of '%' in that context is (as far as I know)
characteristic of "AT&T syntax" assembler, which the GNU assembler
generally supports, even for processors where the vendor assembler is
radically different. (x86 is a good example, where GNU as has both AT&T
syntax and Intel syntax modes.)


-- Jacob

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
Re: libgcrypt clang asm configure issue. [ In reply to ]
Hello,

On 28.10.2022 22.00, Dmytro Kovalov via Gnupg-users wrote:
> Hello,
>
> I found a strange libgcrypt behavior on ARM with clang built.
>
> There is a big gap in performance of libgcrypt, built by clang, in comparison with gcc on my ARM target machine.
> The simple profile test shows 100-500% advantage of gcc gcrypt.
> I found an awkward workaround to beat this issue, but need your help to find the best way to fix it.
>
> The root cause is next:
> Due to clang strict assembler syntax rules the unified assembler ARM check doesn't pass.
> Assembler check fails while ./configure for flags:
> HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS
> HAVE_GCC_INLINE_ASM_NEON
>
> As a workaround I remove '%' from registers names in
> configure.ac <http://configure.ac/>,
> arm mips lib *.S files,
> cipher/*arm.S,*armv7-neon.S files.
>
> Could you please help with a more correct - polite way to compile libgcrypt with assembler code?

This looks correct fix for improving compatibility with clang. It seems that GNU assembler works with those extra '%', but clang arm assembler does not. Only some of the arm assembly in libgcrypt have those extra '%' on register names but not all.

-Jussi

>
> Tested on:
> libgcrypt-1.8.6
> libgcrypt-1.9.3
>
> Equipment:
>
> build machine:
> intel based cpu x86_64
> Ubnuntu-20.04
>
> Software
> compiler        : clang 11.1.0
> linker lld      : lld 11.1.0
> assembler       : llvm-as 11.1.0
> cflags          : "-m32 -march=armv7-a -mthumb -mfpu=vfpv3-d16 --target=arm-linux-gnueabihf"
>
> arm-linux-gnueabihf sysroot based on glibc 2.31
>
> libgcrypt configuring:
> CC="arm-linux-gnueabihf-clang" \
> ./configure \
>   --with-libgpg-error-prefix=<libgpg.so path> \
>   --prefix=<output path> \
>   --host=arm-linux-gnueabihf \
>   --enable-static \
>   --disable-doc
>
>
> target machine:
> hardware:
> model name : ARMv7 Processor rev 4 (v7l)
> BogoMIPS : 2304.00
> Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae aes pmull sha1 sha2 crc32
>
>
> Best Regards,
> Dmytro Kovalov
> Dmytro.a.kovalov@globallogic.com <mailto:Dmytro.a.kovalov@globallogic.com>
>
> _______________________________________________
> Gnupg-users mailing list
> Gnupg-users@gnupg.org
> https://lists.gnupg.org/mailman/listinfo/gnupg-users


_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users