1*635a8641SAndroid Build Coastguard WorkerFrom 5177b28400e03d8666dfb3e65c3016b5062ce0f7 Mon Sep 17 00:00:00 2001 2*635a8641SAndroid Build Coastguard WorkerFrom: Chih-Hung Hsieh <[email protected]> 3*635a8641SAndroid Build Coastguard WorkerDate: Thu, 15 Nov 2018 16:07:02 -0800 4*635a8641SAndroid Build Coastguard WorkerSubject: [PATCH] Update asserts in mojo about int64_t's alignment 5*635a8641SAndroid Build Coastguard Worker 6*635a8641SAndroid Build Coastguard WorkerThe purpose of these asserts is to check that the options structs are aligned 7*635a8641SAndroid Build Coastguard Workersufficiently that an int64_t (or similar) could be added to them. The asserts 8*635a8641SAndroid Build Coastguard Workerwere added in https://codereview.chromium.org/295383012 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard WorkerHowever, the alignment of int64_t on 32-bit x86 is actually 4 bytes, not 8. So 11*635a8641SAndroid Build Coastguard Workerhow did this ever work? Before Clang r345419, the alignof() operator (which is what 12*635a8641SAndroid Build Coastguard WorkerMOJO_ALIGNOF maps to) would return the *preferred alignment* of a type, not 13*635a8641SAndroid Build Coastguard Workerthe *ABI alignment*. That's not what the C and C++ standards specify, so the 14*635a8641SAndroid Build Coastguard Workerbug was fixed and the asserts started firing. (See also 15*635a8641SAndroid Build Coastguard Workerhttps://llvm.org/pr26547) 16*635a8641SAndroid Build Coastguard Worker 17*635a8641SAndroid Build Coastguard WorkerTo fix the build, change the asserts to check that int64_t requires 8 bytes 18*635a8641SAndroid Build Coastguard Workeralignment *or less*. 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard WorkerBug: 900406 21*635a8641SAndroid Build Coastguard WorkerBug: 119634736 22*635a8641SAndroid Build Coastguard WorkerChange-Id: Icf80cea80ac31082423faab8c192420d0b98d515 23*635a8641SAndroid Build Coastguard WorkerReviewed-on: https://chromium-review.googlesource.com/c/1318971 24*635a8641SAndroid Build Coastguard WorkerCommit-Queue: Ken Rockot <[email protected]> 25*635a8641SAndroid Build Coastguard WorkerReviewed-by: Ken Rockot <[email protected]> 26*635a8641SAndroid Build Coastguard WorkerCr-Commit-Position: refs/heads/master@{#605699} 27*635a8641SAndroid Build Coastguard Worker--- 28*635a8641SAndroid Build Coastguard Worker mojo/core/options_validation_unittest.cc | 2 +- 29*635a8641SAndroid Build Coastguard Worker mojo/public/c/system/buffer.h | 2 +- 30*635a8641SAndroid Build Coastguard Worker mojo/public/c/system/data_pipe.h | 2 +- 31*635a8641SAndroid Build Coastguard Worker mojo/public/c/system/message_pipe.h | 2 +- 32*635a8641SAndroid Build Coastguard Worker 4 files changed, 4 insertions(+), 4 deletions(-) 33*635a8641SAndroid Build Coastguard Worker 34*635a8641SAndroid Build Coastguard Workerdiff --git a/mojo/core/options_validation_unittest.cc b/mojo/core/options_validation_unittest.cc 35*635a8641SAndroid Build Coastguard Workerindex 52e0032..b4b02dc 100644 36*635a8641SAndroid Build Coastguard Worker--- a/mojo/core/options_validation_unittest.cc 37*635a8641SAndroid Build Coastguard Worker+++ b/mojo/core/options_validation_unittest.cc 38*635a8641SAndroid Build Coastguard Worker@@ -18,7 +18,7 @@ namespace { 39*635a8641SAndroid Build Coastguard Worker 40*635a8641SAndroid Build Coastguard Worker using TestOptionsFlags = uint32_t; 41*635a8641SAndroid Build Coastguard Worker 42*635a8641SAndroid Build Coastguard Worker-static_assert(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 43*635a8641SAndroid Build Coastguard Worker+static_assert(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 44*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) TestOptions { 45*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 46*635a8641SAndroid Build Coastguard Worker TestOptionsFlags flags; 47*635a8641SAndroid Build Coastguard Workerdiff --git a/mojo/public/c/system/buffer.h b/mojo/public/c/system/buffer.h 48*635a8641SAndroid Build Coastguard Workerindex 2cc5427..83b198b 100644 49*635a8641SAndroid Build Coastguard Worker--- a/mojo/public/c/system/buffer.h 50*635a8641SAndroid Build Coastguard Worker+++ b/mojo/public/c/system/buffer.h 51*635a8641SAndroid Build Coastguard Worker@@ -30,7 +30,7 @@ struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { 52*635a8641SAndroid Build Coastguard Worker // See |MojoCreateSharedBufferFlags|. 53*635a8641SAndroid Build Coastguard Worker MojoCreateSharedBufferFlags flags; 54*635a8641SAndroid Build Coastguard Worker }; 55*635a8641SAndroid Build Coastguard Worker-MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 56*635a8641SAndroid Build Coastguard Worker+MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 57*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, 58*635a8641SAndroid Build Coastguard Worker "MojoCreateSharedBufferOptions has wrong size"); 59*635a8641SAndroid Build Coastguard Worker 60*635a8641SAndroid Build Coastguard Workerdiff --git a/mojo/public/c/system/data_pipe.h b/mojo/public/c/system/data_pipe.h 61*635a8641SAndroid Build Coastguard Workerindex 3702cdb..c72f553 100644 62*635a8641SAndroid Build Coastguard Worker--- a/mojo/public/c/system/data_pipe.h 63*635a8641SAndroid Build Coastguard Worker+++ b/mojo/public/c/system/data_pipe.h 64*635a8641SAndroid Build Coastguard Worker@@ -40,7 +40,7 @@ struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions { 65*635a8641SAndroid Build Coastguard Worker // system-dependent capacity of at least one element in size. 66*635a8641SAndroid Build Coastguard Worker uint32_t capacity_num_bytes; 67*635a8641SAndroid Build Coastguard Worker }; 68*635a8641SAndroid Build Coastguard Worker-MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 69*635a8641SAndroid Build Coastguard Worker+MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 70*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, 71*635a8641SAndroid Build Coastguard Worker "MojoCreateDataPipeOptions has wrong size"); 72*635a8641SAndroid Build Coastguard Worker 73*635a8641SAndroid Build Coastguard Workerdiff --git a/mojo/public/c/system/message_pipe.h b/mojo/public/c/system/message_pipe.h 74*635a8641SAndroid Build Coastguard Workerindex 9f222f9..0f642dd 100644 75*635a8641SAndroid Build Coastguard Worker--- a/mojo/public/c/system/message_pipe.h 76*635a8641SAndroid Build Coastguard Worker+++ b/mojo/public/c/system/message_pipe.h 77*635a8641SAndroid Build Coastguard Worker@@ -35,7 +35,7 @@ struct MOJO_ALIGNAS(8) MojoCreateMessagePipeOptions { 78*635a8641SAndroid Build Coastguard Worker // See |MojoCreateMessagePipeFlags|. 79*635a8641SAndroid Build Coastguard Worker MojoCreateMessagePipeFlags flags; 80*635a8641SAndroid Build Coastguard Worker }; 81*635a8641SAndroid Build Coastguard Worker-MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 82*635a8641SAndroid Build Coastguard Worker+MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 83*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoCreateMessagePipeOptions) == 8, 84*635a8641SAndroid Build Coastguard Worker "MojoCreateMessagePipeOptions has wrong size"); 85*635a8641SAndroid Build Coastguard Worker 86*635a8641SAndroid Build Coastguard Worker-- 87*635a8641SAndroid Build Coastguard Worker2.20.0.rc0.387.gc7a69e6b6c-goog 88*635a8641SAndroid Build Coastguard Worker 89