From f5847c93f3b0ae7e3c36601b5049c4c3fba627f4 Mon Sep 17 00:00:00 2001 From: wangguokun Date: Mon, 5 Aug 2024 11:48:44 +0800 Subject: [PATCH] lib/complier-rt[bug/fix]: fix the bug that atomic flag not defined when GNU Signed-off-by: wangguokun --- include/gcc_atomics.h | 4 + ...-header-for-GCC-atomic-flag-builtins.patch | 128 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 patches/0002-Add-header-for-GCC-atomic-flag-builtins.patch diff --git a/include/gcc_atomics.h b/include/gcc_atomics.h index 0b35ba9..b9f03c7 100644 --- a/include/gcc_atomics.h +++ b/include/gcc_atomics.h @@ -103,4 +103,8 @@ __atomic_thread_fence(order) #endif +#ifndef __c11_atomic_signal_fence +#define __c11_atomic_signal_fence(order) __atomic_signal_fence(order) +#endif + #endif /* __UKPATCH_GCC_ATOMICS_H__ */ diff --git a/patches/0002-Add-header-for-GCC-atomic-flag-builtins.patch b/patches/0002-Add-header-for-GCC-atomic-flag-builtins.patch new file mode 100644 index 0000000..416d20f --- /dev/null +++ b/patches/0002-Add-header-for-GCC-atomic-flag-builtins.patch @@ -0,0 +1,128 @@ +diff --git a/lib/builtins/atomic_flag_clear.c b/lib/builtins/atomic_flag_clear.c +index 983e5d7..c0037b2 100644 +--- a/lib/builtins/atomic_flag_clear.c ++++ b/lib/builtins/atomic_flag_clear.c +@@ -16,10 +16,18 @@ + + #if __has_include() + ++#if defined(__GNUC__) && !defined(__clang__) ++#include "gcc_atomics.h" ++#endif /* __GNUC__ && !defined(__clang__) */ ++ + #include + #undef atomic_flag_clear + void atomic_flag_clear(volatile atomic_flag *object) { +- __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST); ++#if defined(__GNUC__) && !defined(__clang__) ++ __c11_atomic_store(&(object)->__val, 0, __ATOMIC_SEQ_CST); ++#else ++ __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST); ++#endif /* __GNUC__ && !defined(__clang__) */ + } + + #endif +diff --git a/lib/builtins/atomic_flag_clear_explicit.c b/lib/builtins/atomic_flag_clear_explicit.c +index e61c064..e0f1d28 100644 +--- a/lib/builtins/atomic_flag_clear_explicit.c ++++ b/lib/builtins/atomic_flag_clear_explicit.c +@@ -16,11 +16,19 @@ + + #if __has_include() + ++#if defined(__GNUC__) && !defined(__clang__) ++#include "gcc_atomics.h" ++#endif /* __GNUC__ && !defined(__clang__) */ ++ + #include + #undef atomic_flag_clear_explicit + void atomic_flag_clear_explicit(volatile atomic_flag *object, + memory_order order) { +- __c11_atomic_store(&(object)->_Value, 0, order); ++#if defined(__GNUC__) && !defined(__clang__) ++ __c11_atomic_store(&(object)->__val, 0, order); ++#else ++ __c11_atomic_store(&(object)->_Value, 0, order); ++#endif /* __GNUC__ && !defined(__clang__) */ + } + + #endif +diff --git a/lib/builtins/atomic_flag_test_and_set.c b/lib/builtins/atomic_flag_test_and_set.c +index ee22b08..ead8cfb 100644 +--- a/lib/builtins/atomic_flag_test_and_set.c ++++ b/lib/builtins/atomic_flag_test_and_set.c +@@ -16,10 +16,18 @@ + + #if __has_include() + ++#if defined(__GNUC__) && !defined(__clang__) ++#include "gcc_atomics.h" ++#endif /* __GNUC__ && !defined(__clang__) */ ++ + #include + #undef atomic_flag_test_and_set + _Bool atomic_flag_test_and_set(volatile atomic_flag *object) { +- return __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST); ++#if defined(__GNUC__) && !defined(__clang__) ++ return __c11_atomic_exchange(&(object)->__val, 1, __ATOMIC_SEQ_CST); ++#else ++ return __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST); ++#endif /* __GNUC__ && !defined(__clang__) */ + } + + #endif +diff --git a/lib/builtins/atomic_flag_test_and_set_explicit.c b/lib/builtins/atomic_flag_test_and_set_explicit.c +index 8c9d039..e3035d5 100644 +--- a/lib/builtins/atomic_flag_test_and_set_explicit.c ++++ b/lib/builtins/atomic_flag_test_and_set_explicit.c +@@ -16,11 +16,19 @@ + + #if __has_include() + ++#if defined(__GNUC__) && !defined(__clang__) ++#include "gcc_atomics.h" ++#endif /* __GNUC__ && !defined(__clang__) */ ++ + #include + #undef atomic_flag_test_and_set_explicit + _Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *object, + memory_order order) { +- return __c11_atomic_exchange(&(object)->_Value, 1, order); ++#if defined(__GNUC__) && !defined(__clang__) ++ return __c11_atomic_exchange(&(object)->__val, 1, order); ++#else ++ return __c11_atomic_exchange(&(object)->_Value, 1, order); ++#endif /* __GNUC__ && !defined(__clang__) */ + } + + #endif +diff --git a/lib/builtins/atomic_signal_fence.c b/lib/builtins/atomic_signal_fence.c +index f4f5169..de345ce 100644 +--- a/lib/builtins/atomic_signal_fence.c ++++ b/lib/builtins/atomic_signal_fence.c +@@ -16,6 +16,10 @@ + + #if __has_include() + ++#if defined(__GNUC__) && !defined(__clang__) ++#include "gcc_atomics.h" ++#endif /* __GNUC__ && !defined(__clang__) */ ++ + #include + #undef atomic_signal_fence + void atomic_signal_fence(memory_order order) { +diff --git a/lib/builtins/atomic_thread_fence.c b/lib/builtins/atomic_thread_fence.c +index 5659ecb..04be0e6 100644 +--- a/lib/builtins/atomic_thread_fence.c ++++ b/lib/builtins/atomic_thread_fence.c +@@ -16,6 +16,10 @@ + + #if __has_include() + ++#if defined(__GNUC__) && !defined(__clang__) ++#include "gcc_atomics.h" ++#endif /* __GNUC__ && !defined(__clang__) */ ++ + #include + #undef atomic_thread_fence + void atomic_thread_fence(memory_order order) { -- Gitee