From d24b987c1485fedc4b8e57cb7ec7760ce598501b Mon Sep 17 00:00:00 2001 From: "Robert S. Edmonds" Date: Sat, 13 Sep 2014 19:31:12 -0400 Subject: [PATCH 1/2] Remove GOOGLE_PROTOBUF_ARCH_PPC The macro GOOGLE_PROTOBUF_ARCH_PPC is not used anywhere in the protobuf source; there is no Power-specific atomics implementation, etc. Funnily enough, the macro __ppc__ is not actually defined on 32-bit Power on GCC/Linux, according to the following webpage: http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros#POWER and verified on a 32-bit Debian sid 'powerpc' chroot: (sid_powerpc-dchroot)edmonds@partch:~$ gcc -dM -E - < /dev/null | grep -c __ppc__ 0 (sid_powerpc-dchroot)edmonds@partch:~$ gcc -dM -E - < /dev/null | grep -c __LP64__ 0 --- src/google/protobuf/stubs/platform_macros.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 1705b4162dc4..4cc46df45300 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -62,9 +62,6 @@ #endif #elif defined(__pnacl__) #define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(__ppc__) -#define GOOGLE_PROTOBUF_ARCH_PPC 1 -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 #elif defined(__GNUC__) && \ (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) // We fallback to the generic GCC >= 4.7 implementation in atomicops.h From 628a23ba8d8e233815075735c4967bcfae3de342 Mon Sep 17 00:00:00 2001 From: "Robert S. Edmonds" Date: Sat, 13 Sep 2014 19:44:27 -0400 Subject: [PATCH 2/2] Expose generic atomicops on Clang The generic atomicops implementation is only exposed if GCC >= 4.7 is available, but Clang, where the underlying __atomic built-ins are also available, typically only claims to be GCC 4.2. This causes build failures when compiling protobuf or the output of protoc's C++ code generator on an architecture that needs the generic atomicops implementation with Clang. Clang has a "c_atomic" extension which can be tested for which almost does what we want: C11 atomic operations Use __has_feature(c_atomic) or __has_extension(c_atomic) to determine if support for atomic types using _Atomic is enabled. Clang also provides a set of builtins which can be used to implement the operations on _Atomic types. I'm not sure if this guarantees that the GNU atomic builtins (the ones with the __atomic prefix) are also available, but in practice this should guarantee that Clang is new enough. With this change in place, Clang generates several diagnostics when compiling the generic atomicops implementation. These appear to be bugs in the generic atomicops implementation and are not Clang-specific. --- src/google/protobuf/stubs/atomicops.h | 3 ++- src/google/protobuf/stubs/platform_macros.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h index 76c026c9158e..8ddd2508f587 100644 --- a/src/google/protobuf/stubs/atomicops.h +++ b/src/google/protobuf/stubs/atomicops.h @@ -192,7 +192,8 @@ GOOGLE_PROTOBUF_ATOMICOPS_ERROR #include #elif defined(__native_client__) #include -#elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) +#elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) || \ + (defined(__clang__) && __has_extension(c_atomic)) #include #else GOOGLE_PROTOBUF_ATOMICOPS_ERROR diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 4cc46df45300..02c79a6159a1 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -63,7 +63,8 @@ #elif defined(__pnacl__) #define GOOGLE_PROTOBUF_ARCH_32_BIT 1 #elif defined(__GNUC__) && \ - (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) + ((((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) || \ + (defined(__clang__) && __has_extension(c_atomic))) // We fallback to the generic GCC >= 4.7 implementation in atomicops.h # if __LP64__ # define GOOGLE_PROTOBUF_ARCH_64_BIT 1