From 7bde72661cb0cf950d2d7dc48f2bf95eab969e77 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 31 Jul 2023 08:20:01 -0700 Subject: [PATCH] Ensured that 32-bit targets use aligned pointers for 8-byte fields. On 32-bit targets (including WASM), the base message pointer was aligned to 4 instead of 8, causing reads to 8-byte fields to fail, since TypedArray does not support unaligned reads. The pointer was 4-byte aligned because upb adds the size of its "internal" pointer before returning the `upb_Message*`. We should probably stop doing this, and instead have the MiniTable offsets reflect their full and true offset from the pointer returned by `malloc()`. PiperOrigin-RevId: 552486609 --- upb/message/internal.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/upb/message/internal.h b/upb/message/internal.h index c71e189514..95423c63f8 100644 --- a/upb/message/internal.h +++ b/upb/message/internal.h @@ -86,7 +86,13 @@ typedef struct { } upb_Message_InternalData; typedef struct { - upb_Message_InternalData* internal; + union { + upb_Message_InternalData* internal; + + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; /* Message data follows. */ } upb_Message_Internal;