MLCE-1276 Fix for ExecuteNetwork abort after inference

* The abort is caused during destruction of flatbuffers::ClassicLocale
* Set FLATBUFFERS_LOCALE_INDEPENDENT=0 in delegates and parser so that
  ClassicLocale is not included

Signed-off-by: Kevin May <kevin.may@arm.com>
Change-Id: I34584b05998a62bae2263a2281414fcf8c12d668
Signed-off-by: Colm Donelan <colm.donelan@arm.com>
diff --git a/delegate/CMakeLists.txt b/delegate/CMakeLists.txt
index f8b0300..ebde7c6 100644
--- a/delegate/CMakeLists.txt
+++ b/delegate/CMakeLists.txt
@@ -17,6 +17,9 @@
 option(BUILD_DELEGATE_JNI_INTERFACE "Builds a library to allow accessing the Arm NN delegate from Java code.
                                      This is an experimental feature." ON)
 
+## Do not include flatbuffers::ClassicLocale which can cause abort when destroyed
+add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=0)
+
 set(armnnDelegate_sources)
 list(APPEND armnnDelegate_sources
         common/include/DelegateOptions.hpp
diff --git a/docs/FAQ.md b/docs/FAQ.md
index 12fcdad..797413a 100644
--- a/docs/FAQ.md
+++ b/docs/FAQ.md
@@ -78,3 +78,16 @@
 ArmNN supports multithreading at kernel level and this is implemented in Arm Compute Library (ACL) (https://github.com/ARM-software/ComputeLibrary/).
 During inference, at the operator level, the main thread will create multiple threads and execute the same kernel on different parts of the data. At runtime ACL will detect the number of CPU cores in the system and use one thread per cpu core for each kernel.
 Multithreading at operator level is not supported due to limitations in ACL, for more information please refer to https://arm-software.github.io/ComputeLibrary/latest/architecture.xhtml#architecture_thread_safety
+
+On Android, Executables containing Arm NN delegate or Arm NN TfLite Parser occasionally SIGABORT during destruction of Flatbuffers.
+------------------------------
+Unloading some TfLite models occasionally throws a SIGABORT. The error looks similar to this:
+~~~
+#0  0x0000007ff22df5c4 in abort () from target:/apex/com.android.runtime/lib64/bionic/libc.so
+#1  0x0000007ff22ca61c in scudo::die() () from target:/apex/com.android.runtime/lib64/bionic/libc.so
+#2  0x0000007ff22cb244 in scudo::ScopedErrorReport::~ScopedErrorReport() () from target:/apex/com.android.runtime/lib64/bionic/libc.so
+#3  0x0000007ff22cb768 in scudo::reportInvalidChunkState(scudo::AllocatorAction, void*) () from target:/apex/com.android.runtime/lib64/bionic/libc.so
+#4  0x0000007ff22cd520 in scudo::Allocator<scudo::AndroidConfig, &scudo_malloc_postinit>::deallocate(void*, scudo::Chunk::Origin, unsigned long, unsigned long) () from target:/apex/com.android.runtime/lib64/bionic/libc.so
+#5  0x0000007fee6f96f8 in flatbuffers::ClassicLocale::~ClassicLocale() () from target:/data/local/tmp/build.android.aarch64/armnn/libarmnnTfLiteParser.so
+~~~
+The solution to set the flag "-DFLATBUFFERS_LOCALE_INDEPENDENT=0" in the build. By default, this is already done for our internal executables, for example, ExecuteNetwork.
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index 3fd81ff..3a4c084 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -3,6 +3,10 @@
 // SPDX-License-Identifier: MIT
 //
 
+// Do not include flatbuffers::ClassicLocale which can cause abort when destroyed
+// This define must be added before the include or it causes a macro redefine error
+#define FLATBUFFERS_LOCALE_INDEPENDENT 0
+
 #include "TfLiteParser.hpp"
 
 #include "armnnTfLiteParser/Version.hpp"