Skip to content

Commit c351717

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Bump flatbuffer version
Summary: As titled, bump flatbuffer version from v12 to v23.5. In flatbuffer v23.5 the default alignment became 32 and it may cause some issue because it starts to diverge from the fbcode flatbuffer version v12. To close the gap, in `program.cpp` we want to check if the flatbuffer is aligned with the max alignment (the size of `long double` according to https://en.cppreference.com/w/cpp/types/max_align_t) instead of following `FLATBUFFERS_MAX_ALIGNMENT`(which is 16 because internal flatbuffer version is lacking behind). Reviewed By: dbort Differential Revision: D48325610 fbshipit-source-id: d45febf468ad99fe516e2ed86181dd922de899c1
1 parent 3817862 commit c351717

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

runtime/executor/program.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ namespace executor {
3131

3232
namespace {
3333

34-
bool IsAligned(const void* data, size_t alignment) {
34+
/**
35+
* Program data must be aligned to this value to properly parse it. Must be a
36+
* power of 2. Note that max_align_t is the alignment that malloc() and new
37+
* guarantee.
38+
*/
39+
constexpr size_t kMinimumAlignment = alignof(std::max_align_t);
40+
41+
bool IsAligned(const void* data) {
3542
uintptr_t addr = reinterpret_cast<uintptr_t>(data);
36-
return addr % alignment == 0;
43+
return addr % kMinimumAlignment == 0;
3744
}
3845

3946
/**
@@ -54,12 +61,12 @@ const executorch_flatbuffer::Program* DeserializeFlatbufferData(
5461

5562
// The provided pointer must start at an aligned address to ensure internal
5663
// alignment of flatbuffer fields.
57-
if (!IsAligned(data, FLATBUFFERS_MAX_ALIGNMENT)) {
64+
if (!IsAligned(data)) {
5865
ET_LOG(
5966
Error,
60-
"Program data 0x%p must be aligned to %u",
67+
"Program data 0x%p must be aligned to %zu",
6168
data,
62-
FLATBUFFERS_MAX_ALIGNMENT);
69+
kMinimumAlignment);
6370
return nullptr;
6471
}
6572

@@ -172,11 +179,11 @@ Program::Program(const void* serialized_content)
172179
// The flatbuffer data must start at an aligned address to ensure internal
173180
// alignment of flatbuffer fields.
174181
ET_CHECK_OR_RETURN_ERROR(
175-
IsAligned(program_data->data(), FLATBUFFERS_MAX_ALIGNMENT),
182+
IsAligned(program_data->data()),
176183
InvalidArgument,
177-
"Program data 0x%p must be aligned to %u",
184+
"Program data 0x%p must be aligned to %zu",
178185
program_data->data(),
179-
FLATBUFFERS_MAX_ALIGNMENT);
186+
kMinimumAlignment);
180187

181188
// Get the pointer to the root flatbuffer table.
182189
const executorch_flatbuffer::Program* flatbuffer_program =

third-party/TARGETS

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,36 +166,46 @@ runtime.cxx_binary(
166166
"flatbuffers/grpc/src/compiler/python_generator.cc",
167167
"flatbuffers/grpc/src/compiler/swift_generator.cc",
168168
"flatbuffers/grpc/src/compiler/ts_generator.cc",
169+
"flatbuffers/src/annotated_binary_text_gen.cpp",
170+
"flatbuffers/src/bfbs_gen_lua.cpp",
171+
"flatbuffers/src/bfbs_gen_nim.cpp",
172+
"flatbuffers/src/binary_annotator.cpp",
173+
"flatbuffers/src/code_generators.cpp",
174+
"flatbuffers/src/file_binary_writer.cpp",
175+
"flatbuffers/src/file_name_saving_file_manager.cpp",
176+
"flatbuffers/src/file_writer.cpp",
177+
"flatbuffers/src/flatc.cpp",
169178
"flatbuffers/src/flatc_main.cpp",
179+
"flatbuffers/src/idl_gen_binary.cpp",
170180
"flatbuffers/src/idl_gen_cpp.cpp",
171181
"flatbuffers/src/idl_gen_csharp.cpp",
172182
"flatbuffers/src/idl_gen_dart.cpp",
183+
"flatbuffers/src/idl_gen_fbs.cpp",
173184
"flatbuffers/src/idl_gen_go.cpp",
174185
"flatbuffers/src/idl_gen_grpc.cpp",
175186
"flatbuffers/src/idl_gen_java.cpp",
176-
"flatbuffers/src/idl_gen_js_ts.cpp",
177187
"flatbuffers/src/idl_gen_json_schema.cpp",
178188
"flatbuffers/src/idl_gen_kotlin.cpp",
179189
"flatbuffers/src/idl_gen_lobster.cpp",
180-
"flatbuffers/src/idl_gen_lua.cpp",
181190
"flatbuffers/src/idl_gen_php.cpp",
182191
"flatbuffers/src/idl_gen_python.cpp",
183192
"flatbuffers/src/idl_gen_rust.cpp",
184193
"flatbuffers/src/idl_gen_swift.cpp",
185194
"flatbuffers/src/idl_gen_text.cpp",
195+
"flatbuffers/src/idl_gen_ts.cpp",
196+
"flatbuffers/src/idl_parser.cpp",
197+
"flatbuffers/src/reflection.cpp",
186198
"flatbuffers/src/util.cpp",
187199
],
188200
include_directories = [
189201
"flatbuffers/grpc",
190202
"flatbuffers/include",
191203
],
192204
raw_headers = [
193-
"flatbuffers/grpc/src/compiler/config.h",
194205
"flatbuffers/grpc/src/compiler/cpp_generator.h",
195206
"flatbuffers/grpc/src/compiler/go_generator.h",
196207
"flatbuffers/grpc/src/compiler/java_generator.h",
197208
"flatbuffers/grpc/src/compiler/python_generator.h",
198-
"flatbuffers/grpc/src/compiler/python_private_generator.h",
199209
"flatbuffers/grpc/src/compiler/schema_interface.h",
200210
"flatbuffers/grpc/src/compiler/swift_generator.h",
201211
"flatbuffers/grpc/src/compiler/ts_generator.h",

third-party/flatbuffers

Submodule flatbuffers updated 1636 files

0 commit comments

Comments
 (0)