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
This commit is contained in:
Derek Bailey
2026-10-21 20:32:54 +00:00
parent 9a8a511b52
commit 30850e1d75
+1 -1
View File
@@ -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_ += " };";