llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

LLVM defines __GNUC__ but can't compile __builtin_crypto_vcipher on POWER8

Open noloader opened this issue 8 years ago • 5 comments

Bugzilla Link 38378
Resolution WORKSFORME
Resolved on Oct 22, 2018 12:21
Version unspecified
OS Linux
CC @hfinkel,@nemanjai,@noloader,@stefanp-ibm,@TNorthover

Extended Description

This is a piece of existing code that has worked well for the last several years.

template <class T1, class T2> inline T1 VectorEncrypt(const T1& state, const T2& key) { #if defined(xlc) || defined(xlC) return (T1)__vcipher((uint8x16_p)state, (uint8x16_p)key); #elif defined(GNUC) return (T1)__builtin_crypto_vcipher((uint64x2_p)state, (uint64x2_p)key); #else _ASSERT(0); #endif }

Attempting to compile with IBM XL C/C++ 13.1 on GCC112 from the compile farm results in:

$ CXX=xlC make aes-simd.o xlC -DNDEBUG -g2 -O3 -qrtti -qpic -qarch=pwr8 -qaltivec -c aes-simd.cpp In file included from aes-simd.cpp:29: ./ppc-simd.h:443:16: error: use of undeclared identifier '__builtin_crypto_vcipher'; did you mean '__builtin_vec_vcipher'? return (T1)__builtin_crypto_vcipher((uint64x2_p)state, (uint64x2_p)key);

This should have been well tested before making those claims. We should not be experiencing the failure in the field.

Please stop pretending to be other compilers when you can't compile the program.


$ xlC -qshowmacros -qarch=pwr8 -qaltivec -E test.cpp | egrep -i -E 'xlc|clang|llvm|gnuc' #define GNUC_GNU_INLINE 1 #define GNUC_MINOR 2 #define GNUC_PATCHLEVEL 1 #define __GNUC_PREREQ(maj,min) ((GNUC << 16) + GNUC_MINOR >= ((maj) << 16) + (min)) #define __GNUC_VA_LIST 1 #define GNUC 4 #define XLC_BUILTIN_VAARG 1 #define clang 1 #define clang_major 4 #define clang_minor 0 #define clang_patchlevel 1 #define clang_version "4.0.1 (tags/RELEASE_401/final)" #define llvm 1

noloader avatar Jul 31 '18 02:07 noloader

Checked altivec.h and both of the __builtin and _builtin_altivec forms are there. The function in the example given: __builtin_crypto_vcipher has been part of altivec.h since 2015. It looks like LLVM does have all of the PPC crypto functions available for use.

A quick test with this example:

$ cat builtins-ppc-crypto-vcipher.c #include <altivec.h>

#define D_INIT1 { 0x0102030405060708,
0x090A0B0C0D0E0F10 }; #define D_INIT2 { 0x7172737475767778,
0x797A7B7C7D7E7F70 };

// <2 x i64> test_vcipher_e vector unsigned long long test_vcipher_e(void) { vector unsigned long long a = D_INIT1 vector unsigned long long b = D_INIT2 return __builtin_crypto_vcipher(a, b); }

$ clang -c builtins-ppc-crypto-vcipher.c $ echo $? 0

Looks like __builtin_crypto_vcipher is working.

There is a passing test case that is part of LLVM that tests all of the PPC crypto builtins: ./tools/clang/test/CodeGen/builtins-ppc-crypto.c

I see that you are using xlC to compile instead of LLVM. This may be an xlC only issue.

stefanp-synopsys avatar Oct 22 '18 19:10 stefanp-synopsys

The Clang naming of Altivec builtins includes the _altivec_ prefix. This is clearly an incompatibility with GCC that we should remedy, but there will not be a channel to push this change into the 4.0 release. Would it be meaningful to you to provide the GCC names as well as the previously available Clang names in the upcoming Clang release?

For the specific builtin you mention, we should provide both of the following: __builtin_altivec_crypto_vcipher() __builtin_crypto_vcipher()

My personal feeling is avoid new names. We have __vcipher (and friends) for XLC; and we have __builtin_crypto_vcipher (and friends) for GCC and compatibles.

I think there are two high level engineering failures. The first is, the common case no longer works. The second is, LLVM pretends to be other compilers.

I think this is only the tip of the iceberg with respect to the problems LLVM and its idiosyncrasies are going to cause on PPC platform. I think XLC needs to provide a sandbox with higher walls to keep LLVM contained within its bowels and out of my user programs.

For what it is worth, I think LLVM and Clang are good projects and Clang is a good compiler. The problem is keeping LLVM in its code paths and out of other compiler code paths.

== First Failure ==

...

The behavior that you desire from XLC should be discussed elsewhere.

== Second Failure ==

For the second failure, LLVM has a long history of pretending to be other compiler but not accepting the same options and not consuming the program. Worse, there are no options to stop the behavior (unlike Intel ICC, which does the same but provides options to disable the behavior).

Fair point, but on most existing systems, this would lead to a failure to usefully process the system headers, and so would be of limited utility. Nevertheless, please feel free to contribute a patch adding such a feature.

If LLVM cannot consume the same program then it has no business advertising it is the target compiler.

Because, in the common case, this works and provide the best user experience ;)

To be clear, there are no good solutions here, and we've picked what we believe to be the least bad one. YMMV.

The GCC folks have been telling them for years to stop doing it. Confer, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61146#c2 .

What we have done, is stopped increasing the GCC version that we pretend to be. It is our hope to eventually remove this behavior entirely, but we're not there yet.

As I understand things, LLVM defines GNUC and friends for the runtime library. Instead of going to the glibc/libstdc++ folks and asking them to recognize LLVM or Clang as a supported compiler, LLVM does this half-ass crap of defining GCC defines.

The C standard library and other system headers are probably the largest motivator. The problem is that, even if we could change all of the system headers today upstream, we'd still need to keep this compatibility work-around for many more years in practice.

In fact when LLVM manipulates symbols with double underscore, like GNUC, it is undefined behavior (as I understand things) because LLVM does not own the symbols. GNU owns the symbols and only GCC/glibc/libstdc++ are free to manipulate them.

It's not undefined behavior, all implementations own all symbols in the implementation-defined namespace. The rest is governed by practical considerations.

LLVM did the same thing on Windows for the MSC compiler, but LLVM cannot consume Intel-style inline assembly (which GCC and MSC share on Windows). It broke us so badly we fail the compile if we find Clang pretending to be MSC. It was too cost prohibitive to try and fix the thousands of lines of code for LLVM.

I believe that this is no longer true (but if it's not, and there's no corresponding bug report, please file one).

== Just for Fun ==

...

The behavior that you desire from XLC should be discussed elsewhere.

hfinkel avatar Jul 31 '18 17:07 hfinkel

The Clang naming of Altivec builtins includes the _altivec_ prefix. This is clearly an incompatibility with GCC that we should remedy, but there will not be a channel to push this change into the 4.0 release. Would it be meaningful to you to provide the GCC names as well as the previously available Clang names in the upcoming Clang release?

For the specific builtin you mention, we should provide both of the following: __builtin_altivec_crypto_vcipher() __builtin_crypto_vcipher()

My personal feeling is avoid new names. We have __vcipher (and friends) for XLC; and we have __builtin_crypto_vcipher (and friends) for GCC and compatibles.

I think there are two high level engineering failures. The first is, the common case no longer works. The second is, LLVM pretends to be other compilers.

I think this is only the tip of the iceberg with respect to the problems LLVM and its idiosyncrasies are going to cause on PPC platform. I think XLC needs to provide a sandbox with higher walls to keep LLVM contained within its bowels and out of my user programs.

For what it is worth, I think LLVM and Clang are good projects and Clang is a good compiler. The problem is keeping LLVM in its code paths and out of other compiler code paths.

== First Failure ==

For the first failure, the common case is, when I use XLC I expect to get XLC. I should not have to do anything special like RTFM and add additional options like -qcompatmacros. There's nothing "compatibility" about them. I am using XLC and I expect them to be defined.

The converse is also true. Folks who want special behavior should have to do something special. Folks who want XLC but don't want the compiler to identify itself as XLC should be doing the extra work, like adding -qnocompatmacros. It preserves the common case.

== Second Failure ==

For the second failure, LLVM has a long history of pretending to be other compiler but not accepting the same options and not consuming the program. Worse, there are no options to stop the behavior (unlike Intel ICC, which does the same but provides options to disable the behavior).

If LLVM cannot consume the same program then it has no business advertising it is the target compiler. The GCC folks have been telling them for years to stop doing it. Confer, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61146#c2 .

As I understand things, LLVM defines GNUC and friends for the runtime library. Instead of going to the glibc/libstdc++ folks and asking them to recognize LLVM or Clang as a supported compiler, LLVM does this half-ass crap of defining GCC defines.

In fact when LLVM manipulates symbols with double underscore, like GNUC, it is undefined behavior (as I understand things) because LLVM does not own the symbols. GNU owns the symbols and only GCC/glibc/libstdc++ are free to manipulate them.

LLVM did the same thing on Windows for the MSC compiler, but LLVM cannot consume Intel-style inline assembly (which GCC and MSC share on Windows). It broke us so badly we fail the compile if we find Clang pretending to be MSC. It was too cost prohibitive to try and fix the thousands of lines of code for LLVM.

== Just for Fun ==

I got a kick out of this last night. The compiler seems to be suffering multiple personality disorder. It is claiming to be three different compilers.

$ xlc -qxlcompatmacros -qshowmacros -qarch=pwr8 -qaltivec -E test.cpp | egrep -i -E 'xlc|clang|llvm|gnuc' #define GNUC_GNU_INLINE 1 #define GNUC_MINOR 2 #define GNUC_PATCHLEVEL 1 #define __GNUC_PREREQ(maj,min) ((GNUC << 16) + GNUC_MINOR >= ((maj) << 16) + (min)) #define __GNUC_VA_LIST 1 #define GNUC 4 #define XLC_BUILTIN_VAARG 1 #define clang 1 #define clang_major 4 #define clang_minor 0 #define clang_patchlevel 1 #define clang_version "4.0.1 (tags/RELEASE_401/final)" #define llvm 1 #define xlC 0x0d01 #define xlC_ver 0x00000601

noloader avatar Jul 31 '18 16:07 noloader

The Clang naming of Altivec builtins includes the _altivec_ prefix. This is clearly an incompatibility with GCC that we should remedy, but there will not be a channel to push this change into the 4.0 release. Would it be meaningful to you to provide the GCC names as well as the previously available Clang names in the upcoming Clang release?

For the specific builtin you mention, we should provide both of the following: __builtin_altivec_crypto_vcipher() __builtin_crypto_vcipher()

nemanjai avatar Jul 31 '18 12:07 nemanjai

assigned to @stefanp-ibm

noloader avatar Jul 31 '18 02:07 noloader