Building with Android LLVM STL library causes build error in EventCount.h
Submitted by Linus Mårtensson
Assigned to Nobody
Link to original bugzilla bug (#1350)
Operating system: Android
Description
I'm currently working on building Google's Tensorflow for Android using LLVM STL. When in the build process, there's an error as some Eigen components are utilized, more specifically in EventCount.h, here:
https://bitbucket.org/eigen/eigen/src/3011dc94efcabf609ce4bd766fa0461c4f17b5e3/unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h?at=default&fileviewer=file-view-default#EventCount.h-99
"error: invalid failure memory model for __atomic_compare_exchange".
According to the C++11 standard, the failure state for compare_exchange cannot be memory_order_release, as this would result in an erroneous state. Further, setting only a single memory_order parameter should resolve correctly to memory_order_relaxed on failure, but this isn't done in LLVM for whatever reason, and it's unlikely that the Android NDK version of LLVM will be updated in a timely manner and expose it to all platforms.
The faster solution to allow a correct build would instead be to explicitly define the two result states explicitly instead of implicitly as:
compare_exchange_weak(..., std::memory_order_release, std::memory_order_relaxed)
I tested this on my local build, and it resolves the build error as expected.
The error MAY also be present if building with LLVM for x86 / linux, but I was not in a position to test.