Submitted By:            Douglas R. Reno <renodr at linuxfromscratch dot org>
Date:                    2019-01-19
Initial Package Version: 5.12.0
Upstream Status:         Not submitted
Origin:                  Arch Linux 32 / Self (improvements in comments)
Description:             This fixes usage of the alignof operator to use
                         the proper behavior implemented before gcc8. Without
                         this change, alignof will return 4 instead of 8.
                         Applied manually for 5.12.1 and rediffed [ken].

diff -Naur a/src/3rdparty/chromium/mojo/public/c/system/macros.h b/src/3rdparty/chromium/mojo/public/c/system/macros.h
--- a/src/3rdparty/chromium/mojo/public/c/system/macros.h	2019-01-16 10:59:47.000000000 +0000
+++ b/src/3rdparty/chromium/mojo/public/c/system/macros.h	2019-02-02 21:12:22.439864631 +0000
@@ -45,7 +45,15 @@
 // Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
 // type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
 // non-C++11 MSVS version).
-#if __cplusplus >= 201103L
+#if defined(__GNUC__) && __GNUC__ >= 8
+/*
+ * GCC 8 changed the alignof operator to return the minimal alignment
+ * required by the target ABI, instead of the preferred alignment.
+ * This means that on 32-bit x86 (i686), it will return 4 instead of 8.
+ * Use __alignof__ to avoid this.
+ */
+#define MOJO_ALIGNOF(type) __alignof__(type)
+#elif __cplusplus >= 201103L
 #define MOJO_ALIGNAS(alignment) alignas(alignment)
 #elif defined(__GNUC__)
 #define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
diff -Naur a/src/3rdparty/chromium/mojo/public/c/system/macros.h.orig b/src/3rdparty/chromium/mojo/public/c/system/macros.h.orig
--- a/src/3rdparty/chromium/mojo/public/c/system/macros.h.orig	1970-01-01 01:00:00.000000000 +0100
+++ b/src/3rdparty/chromium/mojo/public/c/system/macros.h.orig	2019-02-02 21:09:50.240382016 +0000
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_
+#define MOJO_PUBLIC_C_SYSTEM_MACROS_H_
+
+#include <stddef.h>
+
+// Assert things at compile time. (|msg| should be a valid identifier name.)
+// This macro is currently C++-only, but we want to use it in the C core.h.
+// Use like:
+//   MOJO_STATIC_ASSERT(sizeof(Foo) == 12, "Foo has invalid size");
+#if defined(__cplusplus)
+#define MOJO_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
+#else
+#define MOJO_STATIC_ASSERT(expr, msg)
+#endif
+
+// Defines a pointer-sized struct field of the given type. This ensures that the
+// field has an 8-byte footprint on both 32-bit and 64-bit systems, using an
+// anonymous bitfield of either 32 or 0 bits, depending on pointer size. Weird
+// formatting here courtesy of clang-format.
+#define MOJO_POINTER_FIELD(type, name) \
+  type name;                           \
+  uint32_t:                            \
+  (sizeof(void*) == 4 ? 32 : 0)
+
+// Like the C++11 |alignof| operator.
+#if defined(__GNUC__)
+#define MOJO_ALIGNOF(type) __alignof__(type)
+#elif __cplusplus >= 201103L
+#define MOJO_ALIGNOF(type) alignof(type)
+#elif defined(_MSC_VER)
+// The use of |sizeof| is to work around a bug in MSVC 2010 (see
+// http://goo.gl/isH0C; supposedly fixed since then).
+#define MOJO_ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
+#else
+#error "Please define MOJO_ALIGNOF() for your compiler."
+#endif
+
+// Specify the alignment of a |struct|, etc.
+// Use like:
+//   struct MOJO_ALIGNAS(8) Foo { ... };
+// Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
+// type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
+// non-C++11 MSVS version).
+#if __cplusplus >= 201103L
+#define MOJO_ALIGNAS(alignment) alignas(alignment)
+#elif defined(__GNUC__)
+#define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
+#elif defined(_MSC_VER)
+#define MOJO_ALIGNAS(alignment) __declspec(align(alignment))
+#else
+#error "Please define MOJO_ALIGNAS() for your compiler."
+#endif
+
+#endif  // MOJO_PUBLIC_C_SYSTEM_MACROS_H_
diff -Naur a/src/3rdparty/chromium/mojo/public/c/system/macros.h.rej b/src/3rdparty/chromium/mojo/public/c/system/macros.h.rej
--- a/src/3rdparty/chromium/mojo/public/c/system/macros.h.rej	1970-01-01 01:00:00.000000000 +0100
+++ b/src/3rdparty/chromium/mojo/public/c/system/macros.h.rej	2019-02-02 21:09:50.240382016 +0000
@@ -0,0 +1,19 @@
+--- src/3rdparty/chromium/mojo/public/c/system/macros.h	2018-11-13 12:25:11.000000000 -0600
++++ src/3rdparty/chromium/mojo/public/c/system/macros.h	2019-01-19 11:45:57.175570538 -0600
+@@ -27,7 +27,15 @@
+   (sizeof(void*) == 4 ? 32 : 0)
+ 
+ // Like the C++11 |alignof| operator.
+-#if __cplusplus >= 201103L
++#if defined(__GNUC__) && __GNUC__ >= 8
++/*
++ * GCC 8 changed the alignof operator to return the minimal alignment
++ * required by the target ABI, instead of the preferred alignment.
++ * This means that on 32-bit x86 (i686), it will return 4 instead of 8.
++ * Use __alignof__ to avoid this.
++ */
++#define MOJO_ALIGNOF(type) __alignof__(type)
++#elif __cplusplus >= 201103L
+ #define MOJO_ALIGNOF(type) alignof(type)
+ #elif defined(__GNUC__)
+ #define MOJO_ALIGNOF(type) __alignof__(type)
