Blame chromium-79-gcc-protobuf-alignas.patch

4f31ec8
From 5d66d5907ac3e76d1e382b8a8e8afe653bd00f4c Mon Sep 17 00:00:00 2001
4f31ec8
From: Stephan Hartmann <stha09@googlemail.com>
4f31ec8
Date: Sun, 31 May 2020 13:59:15 +0000
4f31ec8
Subject: [PATCH] Fix GCC build with PROTOBUF_USE_DLLS enabled
4f31ec8
4f31ec8
GCC does not allow mixing __attribute__(()) syntax and alignas()
4f31ec8
syntax. Re-use approach from chromium base/compiler_specific.h
2fff85b
---
4f31ec8
 .../protobuf/src/google/protobuf/arena.h      |  2 +-
4f31ec8
 .../protobuf/src/google/protobuf/port_def.inc | 29 +++++++++++++++++++
4f31ec8
 .../src/google/protobuf/port_undef.inc        |  1 +
4f31ec8
 3 files changed, 31 insertions(+), 1 deletion(-)
2fff85b
2fff85b
diff --git a/third_party/protobuf/src/google/protobuf/arena.h b/third_party/protobuf/src/google/protobuf/arena.h
2fff85b
index dedc221..a8515ce 100644
2fff85b
--- a/third_party/protobuf/src/google/protobuf/arena.h
2fff85b
+++ b/third_party/protobuf/src/google/protobuf/arena.h
2fff85b
@@ -245,7 +245,7 @@ struct ArenaOptions {
2fff85b
 // well as protobuf container types like RepeatedPtrField and Map. The protocol
2fff85b
 // is internal to protobuf and is not guaranteed to be stable. Non-proto types
2fff85b
 // should not rely on this protocol.
2fff85b
-class PROTOBUF_EXPORT alignas(8) Arena final {
2fff85b
+class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
2fff85b
  public:
2fff85b
   // Arena constructor taking custom options. See ArenaOptions below for
2fff85b
   // descriptions of the options available.
2fff85b
diff --git a/third_party/protobuf/src/google/protobuf/port_def.inc b/third_party/protobuf/src/google/protobuf/port_def.inc
2fff85b
index f1bd85d..6d02b53 100644
2fff85b
--- a/third_party/protobuf/src/google/protobuf/port_def.inc
2fff85b
+++ b/third_party/protobuf/src/google/protobuf/port_def.inc
2fff85b
@@ -528,6 +528,35 @@ PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport));
2fff85b
 #undef IN
2fff85b
 #endif  // _MSC_VER
2fff85b
 
2fff85b
+// Specify memory alignment for structs, classes, etc.
2fff85b
+// Use like:
2fff85b
+//   class PROTOBUF_ALIGNAS(16) MyClass { ... }
2fff85b
+//   PROTOBUF_ALIGNAS(16) int array[4];
2fff85b
+//
2fff85b
+// In most places you can use the C++11 keyword "alignas", which is preferred.
2fff85b
+//
2fff85b
+// But compilers have trouble mixing __attribute__((...)) syntax with
2fff85b
+// alignas(...) syntax.
2fff85b
+//
2fff85b
+// Doesn't work in clang or gcc:
2fff85b
+//   struct alignas(16) __attribute__((packed)) S { char c; };
2fff85b
+// Works in clang but not gcc:
2fff85b
+//   struct __attribute__((packed)) alignas(16) S2 { char c; };
2fff85b
+// Works in clang and gcc:
2fff85b
+//   struct alignas(16) S3 { char c; } __attribute__((packed));
2fff85b
+//
2fff85b
+// There are also some attributes that must be specified *before* a class
2fff85b
+// definition: visibility (used for exporting functions/classes) is one of
2fff85b
+// these attributes. This means that it is not possible to use alignas() with a
2fff85b
+// class that is marked as exported.
2fff85b
+#if defined(_MSC_VER)
2fff85b
+#define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
2fff85b
+#elif defined(__GNUC__)
2fff85b
+#define PROTOBUF_ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
2fff85b
+#else
2fff85b
+#define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment)
2fff85b
+#endif
2fff85b
+
2fff85b
 #if defined(__clang__)
2fff85b
 #pragma clang diagnostic push
2fff85b
 // TODO(gerbens) ideally we cleanup the code. But a cursory try shows many
2fff85b
diff --git a/third_party/protobuf/src/google/protobuf/port_undef.inc b/third_party/protobuf/src/google/protobuf/port_undef.inc
2fff85b
index b7e67fe..ba1fffc 100644
2fff85b
--- a/third_party/protobuf/src/google/protobuf/port_undef.inc
2fff85b
+++ b/third_party/protobuf/src/google/protobuf/port_undef.inc
2fff85b
@@ -80,6 +80,7 @@
2fff85b
 #undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec
2fff85b
 #undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport
2fff85b
 #undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport
2fff85b
+#undef PROTOBUF_ALIGNAS
2fff85b
 
2fff85b
 
2fff85b
 
4f31ec8
-- 
4f31ec8
2.26.2
4f31ec8