Page MenuHome GnuPG

libgcrypt-1.9.4 build failure on ppc64le
Closed, ResolvedPublic

Description

This is a forward of a downstream bug report in Gentoo here.

libtool: compile:  powerpc64le-unknown-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I/cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher -I.. -I../src -I/cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/src -I../mpi -I/cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/mpi -DGNUSTEP_BASE_VERSION -I/cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/usr/include -fvisibility=hidden -fno-delete-null-pointer-checks -Wall -c /cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c  -fPIC -DPIC -o .libs/chacha20-ppc.o
In file included from /cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c:28:
/cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c: In function '_gcry_chacha20_ppc8_blocks1':
/cvmfs/pilot.eessi-hpc.org/2021.12/compat/linux/ppc64le/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c:60:10: error: argument 3 must be a 4-bit unsigned literal
   60 |   return vec_sld (v, v, (16 - (4 * idx)) & 15);
      |          ^~~~~~~

User mentions 1.8.8 is OK but 1.9.4 isn't.

Details

External Link
https://bugs.gentoo.org/825722
Version
1.9.4

Related Objects

Event Timeline

Looks like it's triggered if e.g. -mcpu=power9 isn't in CFLAGS.

On behalf of @gyakovlev (pending approval for his account):

[03:05:23]  <@gyakovlev>  AC_DEFINE(HAVE_COMPATIBLE_CC_PPC_ALTIVEC,1,
[03:05:23]  <@gyakovlev>         [Defined if underlying compiler supports PowerPC AltiVec/VSX/crypto intrinsics])
[03:05:34]  <@gyakovlev> they should definitely check for __POWER8_VECTOR__ 1
[03:05:44]  <@gyakovlev> it's not plain altivec
[03:06:52]  <@gyakovlev> that power check should check for __POWER8_VECTOR__
[03:06:52]  <@gyakovlev> not only for what they check already.
[03:08:59]  <@gyakovlev> it probably should be checked after __powerpc64__ or instead of it.

thanks for approving account.
build error happens in automatic configuration (when --enable-ppc-crypto-support is omitted from ./configure) and -mcpu=powerpc64le, -mcpu=power8 or power9 or -mpower8-vector flags are not passed to compiler.

steps to reproduce:
./configure
make # CFLAGS should NOT contain -mcpu, or contain -mcpu=G5 for example

build will fail

gcc -mcpu=powerpc64 -dM -E - < /dev/null | grep -i power
#define __powerpc__ 1
#define __powerpc64__ 1
gcc -mcpu=power8 -dM -E - < /dev/null | grep -i power
#define __powerpc__ 1
#define __powerpc64__ 1
#define __POWER8_VECTOR__ 1
gcc -mcpu=powerpc64 -mpower8-vector -dM -E - < /dev/null | grep -i power
#define __powerpc__ 1
#define __powerpc64__ 1
#define __POWER8_VECTOR__ 1

also maybe worth checking __VSX__ , for instance vec_sld wants -mvsx, which will not be passed by build system.

basically it looks like ./configure does a great job at checking what cpu actually supports, but it checks host cpu.
but does not pass proper flags to include proper headers/directives.
building with -mcpu=G5 or -mcpu=powerpc64 will replicate the problem

# log from build with -mcpu=G5 on power9 system
checking whether compiler supports PowerPC AltiVec/VSX/crypto intrinsics with extra GCC flags... yes
checking whether GCC inline assembler supports PowerPC AltiVec/VSX/crypto instructions... yes
checking whether GCC inline assembler supports PowerISA 3.00 instructions... yes
checking whether GCC inline assembler supports zSeries instructions... n/a

^

....snip
libtool: compile:  powerpc64le-unknown-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher -I.. -I../src -I/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/src -I../mpi -I/var/tmp/po
rtage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/mpi -mcpu=G5 -fvisibility=hidden -fno-delete-null-pointer-checks -Wall -c /var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/gost28147.c  -fPIC -DPIC -o .libs/gost28147.o         
In file included from /var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c:28:                                                                                                                                            
/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c: In function '_gcry_chacha20_ppc8_blocks1':                                                                                                                          
/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/chacha20-ppc.c:60:10: error: argument 3 must be a 4-bit unsigned literal                                                                                                            
   60 |   return vec_sld (v, v, (16 - (4 * idx)) & 15);                                                                                                                                                                                                   
      |          ^~~~~~~                                                                                                   
......snip
make[2]: *** [Makefile:1459: crc-ppc.lo] Error 1                                                                             
In file included from /var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/sha256-ppc.c:28:                 
/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/sha256-ppc.c: In function '_gcry_sha256_transform_ppc8':
/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/sha256-ppc.c:73:10: error: argument 3 must be a 4-bit unsigned literal
   73 |   return vec_sld (v, v, (16 - (4 * idx)) & 15);
      |          ^~~~~~~                                      
/var/tmp/portage/dev-libs/libgcrypt-1.9.4/work/libgcrypt-1.9.4/cipher/sha256-ppc.c:73:10: error: argument 3 must be a 4-bit unsigned literal
   73 |   return vec_sld (v, v, (16 - (4 * idx)) & 15);
      |          ^~~~~~~

sorry, I'm a bit confused now and probably everything I wrote above is incorrect.

seems what triggers the error is absence of -O2 flag in user's build log and my testing environment there I tried to match users' one.
it builds just fine as is, forced absence of -O2 or -O1 makes it fail, which makes sense in a way.

Thanks for report. Those powerpc vector implementations expect that compiler optimizations are enabled and here provided CFLAGS did not have '-Ox' parameter. This could be worked around by introducing -O2 always when building those files (confiugre.ac & cipher/Makefile.am change) or using 'optimize' attributes to required functions (cipher/*-ppc*.c change).

I added check to configure.ac for missing -O flag and tests with -O2. If adding -O2 does not help, then powerpc vector implementations wont be build at all.

(note: -O2 is added only for compiling powerpc vector implementation files)