]> xenbits.xensource.com Git - unikraft/libs/libcxx.git/commitdiff
Fix crash due to atomics on bare-metal arm64 RELEASE-0.5
authorFelipe Huici <felipe.huici@neclab.eu>
Tue, 28 Jan 2020 12:55:45 +0000 (13:55 +0100)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Wed, 18 Mar 2020 14:42:18 +0000 (15:42 +0100)
At the moment atomic operations are working on ARM64 for KVM; however,
they are not working on baremetal on ARM64 (i.e., on the Raspberry Pi
3B+).  This can be most likely be solved by enabling the caches and
setting up a compatible memory configuration.  In the meantime, these
patches allow us to have functionally-equivalent non-atomic
implementations of the gcc builtins working on baremetal on ARM64.
Once the issue is fixed this workaround can be removed.

Signed-off-by: Felipe Huici <felipe.huici@neclab.eu>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
patches/0004-Fix-arm-atomics-memory.patch [new file with mode: 0644]
patches/0005-Fix-arm-atomics-header.patch [new file with mode: 0644]

diff --git a/patches/0004-Fix-arm-atomics-memory.patch b/patches/0004-Fix-arm-atomics-memory.patch
new file mode 100644 (file)
index 0000000..852805e
--- /dev/null
@@ -0,0 +1,28 @@
+--- a/include/memory   2020-01-28 13:27:53.843204834 +0100
++++ b/include/memory   2020-01-28 13:29:45.109925361 +0100
+@@ -675,6 +675,7 @@
+ _LIBCPP_PUSH_MACROS
+ #include <__undef_macros>
++#include <uk/arch/atomic.h>
+ _LIBCPP_BEGIN_NAMESPACE_STD
+@@ -3458,7 +3459,7 @@
+ __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
+ {
+ #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
+-    return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
++    return ukarch_fetch_add(&__t, 1);
+ #else
+     return __t += 1;
+ #endif
+@@ -3469,7 +3470,7 @@
+ __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
+ {
+ #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
+-    return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
++  return ukarch_dec(&__t);
+ #else
+     return __t -= 1;
+ #endif
diff --git a/patches/0005-Fix-arm-atomics-header.patch b/patches/0005-Fix-arm-atomics-header.patch
new file mode 100644 (file)
index 0000000..75e27d2
--- /dev/null
@@ -0,0 +1,19 @@
+--- a/src/include/atomic_support.h     2020-01-28 13:33:44.139173682 +0100
++++ b/src/include/atomic_support.h     2020-01-28 13:34:43.986484257 +0100
+@@ -12,6 +12,7 @@
+ #include "__config"
+ #include "memory" // for __libcpp_relaxed_load
++#include <uk/arch/atomic.h>
+ #if defined(__clang__) && __has_builtin(__atomic_load_n)             \
+                        && __has_builtin(__atomic_store_n)            \
+@@ -80,7 +81,7 @@
+ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
+                                int __order = _AO_Seq)
+ {
+-    return __atomic_add_fetch(__val, __a, __order);
++  return ukarch_fetch_add(__val, __a);
+ }
+ template <class _ValueType>