From 30850e1d75cb87ccefda9731943a794514d3a96c Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Wed, 21 Oct 2026 15:30:53 +0000 Subject: [PATCH] Ensure embedded FlatBuffers binary schemas are 8-byte aligned In `src/idl_gen_cpp.cpp`, code generated by `flatc --bfbs-gen-embed` emits `static const uint8_t bfbsData[...] = { ... };`. Because `uint8_t` has 1-byte alignment, the array may be placed at an unaligned address in `.rodata`, triggering alignment traps under Clang UBSan on Arm when accessed via FlatBuffers root accessors. Add `alignas(uint64_t)` to the generated `bfbsData` array declaration in `GenerateBinarySchema` so embedded binary schemas are 8-byte aligned across all architectures. PiperOrigin-RevId: 1003962636 --- src/idl_gen_cpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 9ad18a7b4..29e8d3a9e 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -404,7 +404,7 @@ class CppGenerator : public BaseGenerator { code_ += "struct {{STRUCT_NAME}}BinarySchema {"; code_ += " static const uint8_t *data() {"; code_ += " // Buffer containing the binary schema."; - code_ += " static const uint8_t bfbsData[" + + code_ += " alignas(uint64_t) static const uint8_t bfbsData[" + NumToString(parser_.builder_.GetSize()) + "] = {"; code_ += binary_schema_hex_text; code_ += " };";