AIX compilation with g++

36 views
Skip to first unread message

Bob Wilkinson

unread,
Jan 11, 2018, 11:04:19 AM1/11/18
to Crypto++ Users
I am trying to compile cryptopp on AIX 6.1. I use gcc/g++ there (full support for C++11 etc being the main reason).

I modified GNUMakefile ...

   # GCC and some compatibles
   HAVE_CRYPTO = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mcpu=power8 -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c -E '_ARCH_PWR8|_ARCH_PWR9|__CRYPTO')
   ifneq ($(HAVE_CRYPTO),0)
-    ALTIVEC_FLAG = -mcpu=power8 -maltivec
-    AES_FLAG = -mcpu=power8 -maltivec
-    GCM_FLAG = -mcpu=power8 -maltivec
-    SHA_FLAG = -mcpu=power8 -maltivec
-    SIMON_FLAG = -mcpu=power8 -maltivec
-    SPECK_FLAG = -mcpu=power8 -maltivec
+    ALTIVEC_FLAG = -mcpu=power7 -maltivec
+    AES_FLAG = -mcpu=power7 -maltivec
+    GCM_FLAG = -mcpu=power7 -maltivec
+    SHA_FLAG = -mcpu=power7 -maltivec
+    SIMON_FLAG = -mcpu=power7 -maltivec
+    SPECK_FLAG = -mcpu=power7 -maltivec
   endif

because my version of as does not output power8 instructions.

The build gets as far as ...

g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -c poly1305.cpp
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -c polynomi.cpp
g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -mcpu=power7 -maltivec -c ppc-simd.cpp
In file included from ppc-simd.cpp:14:0:
ppc-simd.h: In function 'bool CryptoPP::CPU_ProbeAES()':
ppc-simd.h:444:40: error: Builtin function __builtin_crypto_vcipher is not supported with the current options
     return (T1)__builtin_crypto_vcipher((uint64x2_p)state, (uint64x2_p)key);
                ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ppc-simd.h:464:44: error: Builtin function __builtin_crypto_vcipherlast is not supported with the current options
     return (T1)__builtin_crypto_vcipherlast((uint64x2_p)state, (uint64x2_p)key);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ppc-simd.h:484:41: error: Builtin function __builtin_crypto_vncipher is not supported with the current options
     return (T1)__builtin_crypto_vncipher((uint64x2_p)state, (uint64x2_p)key);
                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and a few more similar errors before stopping.

Anyone get any ideas as to what to try next?

Jeffrey Walton

unread,
Jan 11, 2018, 11:54:50 AM1/11/18
to Crypto++ Users
Yeah, you are getting into Power8 paths.

Anyone get any ideas as to what to try next?

It looks like availability is being set incorrectly. To get past it, you should only need to add -DCRYPTOPP_DISABLE_POWER8=1 to CXXFLAGS. Maybe something like:

    CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1" make -j 16

The question for me is, why are we getting into the bad state. Looking at config.h : 655 (https://github.com/weidai11/cryptopp/blob/master/config.h#L657) :

// We need Power8 for in-core crypto
#if !defined(CRYPTOPP_POWER8_AVAILABLE) && !defined(CRYPTOPP_DISABLE_POWER8) && defined(CRYPTOPP_POWER7_AVAILABLE)
# if defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800)
# define CRYPTOPP_POWER8_AVAILABLE 1
# endif
#endif

What version of GCC are you using?

The only machine I have to test non-Power7 and non-Power8 is an old PowerMac. The PowerMac stays out of the code paths. But the PowerMac is ancient, so there is a big gap in testing for cases like yours. Could I get SSH access to the machine?

Jeff

Jeffrey Walton

unread,
Jan 11, 2018, 12:01:16 PM1/11/18
to Crypto++ Users


On Thursday, January 11, 2018 at 11:54:50 AM UTC-5, Jeffrey Walton wrote:
...
   # GCC and some compatibles
   HAVE_CRYPTO = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mcpu=power8 -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c -E '_ARCH_PWR8|_ARCH_PWR9|__CRYPTO')
   ifneq ($(HAVE_CRYPTO),0)
-    ALTIVEC_FLAG = -mcpu=power8 -maltivec
-    AES_FLAG = -mcpu=power8 -maltivec
-    GCM_FLAG = -mcpu=power8 -maltivec
-    SHA_FLAG = -mcpu=power8 -maltivec
-    SIMON_FLAG = -mcpu=power8 -maltivec
-    SPECK_FLAG = -mcpu=power8 -maltivec
+    ALTIVEC_FLAG = -mcpu=power7 -maltivec
+    AES_FLAG = -mcpu=power7 -maltivec
+    GCM_FLAG = -mcpu=power7 -maltivec
+    SHA_FLAG = -mcpu=power7 -maltivec
+    SIMON_FLAG = -mcpu=power7 -maltivec
+    SPECK_FLAG = -mcpu=power7 -maltivec
   endif

because my version of as does not output power8 instructions.

OK, this was the problem - 'as' is too old.

(My bad, I missed that on first pass).

It looks like availability is being set incorrectly. To get past it, you should only need to add -DCRYPTOPP_DISABLE_POWER8=1 to CXXFLAGS. Maybe something like:

    CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1" make -j 16

Yeah, this should clear it for you.

Jeff

Bob Wilkinson

unread,
Jan 11, 2018, 12:26:45 PM1/11/18
to Crypto++ Users

bash-4.4$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/6.2.0/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: ../gcc-6.2.0/configure --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --with-local-prefix=/opt/freeware --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran,objc,obj-c++ --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-cloog=no --with-ppl=no --disable-libstdcxx-pch --enable-__cxa_atexit --host=powerpc-ibm-aix6.1.0.0
Thread model: aix
gcc version 6.2.0 (GCC)
bash-4.4$

bash-4.4$     CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1" make
g++ -DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -fPIC -pthread -pipe -mcpu=power7 -maltivec -c ppc-simd.cpp
ppc-simd.cpp: In function 'bool CryptoPP::CPU_ProbeSHA256()':
ppc-simd.cpp:238:13: error: 'VectorSHA256' was not declared in this scope
         x = VectorSHA256<0,0>(x);
             ^~~~~~~~~~~~
ppc-simd.cpp: In function 'bool CryptoPP::CPU_ProbeSHA512()':
ppc-simd.cpp:282:13: error: 'VectorSHA512' was not declared in this scope
         x = VectorSHA512<0,0>(x);
             ^~~~~~~~~~~~
GNUmakefile:1059: recipe for target 'ppc-simd.o' failed
make: *** [ppc-simd.o] Error 1
bash-4.4$

bob@bobspc ~/s/cryptopp> grep -C 2 ppc-simd ./ppc-simd.cpp
// ppc-simd.cpp - written and placed in the public domain by
//                Jeffrey Walton, Uri Blumenthal and Marcel Raad.
//
--

#if defined(CRYPTOPP_ALTIVEC_AVAILABLE)
# include "ppc-simd.h"
#endif

bob@bobspc ~/s/cryptopp>

So I try adding -DCRYPTOPP_ALTIVEC_AVAILABLE=1 so I get the header file

bash-4.4$     CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -DCRYPTOPP_ALTIVEC_AVAILABLE=1" make     
g++ -DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -DCRYPTOPP_ALTIVEC_AVAILABLE=1 -fPIC -pthread -pipe -mcpu=power7 -maltivec -c ppc-simd.cpp
ppc-simd.cpp: In function 'bool CryptoPP::CPU_ProbeSHA256()':
ppc-simd.cpp:238:13: error: 'VectorSHA256' was not declared in this scope
         x = VectorSHA256<0,0>(x);
             ^~~~~~~~~~~~
ppc-simd.cpp: In function 'bool CryptoPP::CPU_ProbeSHA512()':
ppc-simd.cpp:282:13: error: 'VectorSHA512' was not declared in this scope
         x = VectorSHA512<0,0>(x);
             ^~~~~~~~~~~~
GNUmakefile:1059: recipe for target 'ppc-simd.o' failed
make: *** [ppc-simd.o] Error 1
bash-4.4$

So next I try  CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -DCRYPTOPP_NO_CPU_FEATURE_PROBES=1" make

which does compile the errant file.

I do not know whether adding -DCRYPTOPP_NO_CPU_FEATURE_PROBES=1 is a good idea?

However, thank you for your swift help in getting my compilation to work - it is still going, but I am optimistic :-)

Maybe you could use this information to patch the build system?

The build has just completed :-)

Bob

Jeffrey Walton

unread,
Jan 11, 2018, 1:06:34 PM1/11/18
to Crypto++ Users


On Thursday, January 11, 2018 at 12:26:45 PM UTC-5, Bob Wilkinson wrote:

...

So I try adding -DCRYPTOPP_ALTIVEC_AVAILABLE=1 so I get the header file

bash-4.4$     CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -DCRYPTOPP_ALTIVEC_AVAILABLE=1" make     
g++ -DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -DCRYPTOPP_ALTIVEC_AVAILABLE=1 -fPIC -pthread -pipe -mcpu=power7 -maltivec -c ppc-simd.cpp
ppc-simd.cpp: In function 'bool CryptoPP::CPU_ProbeSHA256()':
ppc-simd.cpp:238:13: error: 'VectorSHA256' was not declared in this scope
         x = VectorSHA256<0,0>(x);
             ^~~~~~~~~~~~
ppc-simd.cpp: In function 'bool CryptoPP::CPU_ProbeSHA512()':
ppc-simd.cpp:282:13: error: 'VectorSHA512' was not declared in this scope
         x = VectorSHA512<0,0>(x);
             ^~~~~~~~~~~~
GNUmakefile:1059: recipe for target 'ppc-simd.o' failed
make: *** [ppc-simd.o] Error 1
bash-4.4$

So next I try  CXX=g++ CXXFLAGS="-DNDEBUG -g2 -O3 -DCRYPTOPP_DISABLE_POWER8=1 -DCRYPTOPP_NO_CPU_FEATURE_PROBES=1" make

which does compile the errant file.

I do not know whether adding -DCRYPTOPP_NO_CPU_FEATURE_PROBES=1 is a good idea?

The idea behind  CRYPTOPP_NO_CPU_FEATURE_PROBES was to stop the SIGILL-based probes on OSes that appear to munge things when a SIGILL is raised. We try an instruction and if a SIGILL is raised then the instruction is not available. As far as I know, Apple OSes are the ones that trash memory when a SIGILL happens.

CRYPTOPP_ALTIVEC_AVAILABLE is needed because the defines are wrong for ppc-simd.cpp. It was cleared at https://github.com/weidai11/cryptopp/commit/691e7af29a493418 .

We still misdetect AS and LD availability of Power8 for this platform, so you still need CRYPTOPP_DISABLE_POWER8. But you won't need the other hacks.

However, thank you for your swift help in getting my compilation to work - it is still going, but I am optimistic :-)

Maybe you could use this information to patch the build system?

Yes, thank you very much.

Jeff

Bob Wilkinson

unread,
Jan 12, 2018, 3:51:47 AM1/12/18
to Crypto++ Users

I ran away once it had built, but first thing this morning, I typed 'make check' which worked fine, ending with ...

Generating signature key from seed...
passed    signature key validation
passed    signature and verification
passed    checking invalid signature

All tests passed!

Seed used was 1515745681     
Test started at Fri Jan 12 02:28:01 2018
Test ended at Fri Jan 12 02:28:06 2018
bash-4.4$

So, thank you again :-)
 
Reply all
Reply to author
Forward
0 new messages