llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.09k stars 12k forks source link

build libc++ for armv6m-none-eabi failed #52874

Open SquallATF opened 2 years ago

SquallATF commented 2 years ago

this commit 92832e4889ae6038cc8b3e6e449af2a9b9374ab4 enable \<atomic> when threads are disable. but armv6m target does not have any signed/unsigned lock-free types

#define __CLANG_ATOMIC_BOOL_LOCK_FREE 1
#define __CLANG_ATOMIC_CHAR16_T_LOCK_FREE 1
#define __CLANG_ATOMIC_CHAR32_T_LOCK_FREE 1
#define __CLANG_ATOMIC_CHAR_LOCK_FREE 1
#define __CLANG_ATOMIC_INT_LOCK_FREE 1
#define __CLANG_ATOMIC_LLONG_LOCK_FREE 1
#define __CLANG_ATOMIC_LONG_LOCK_FREE 1
#define __CLANG_ATOMIC_POINTER_LOCK_FREE 1
#define __CLANG_ATOMIC_SHORT_LOCK_FREE 1
#define __CLANG_ATOMIC_WCHAR_T_LOCK_FREE 1
#define __GCC_ATOMIC_BOOL_LOCK_FREE 1
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1
#define __GCC_ATOMIC_CHAR_LOCK_FREE 1
#define __GCC_ATOMIC_INT_LOCK_FREE 1
#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
#define __GCC_ATOMIC_LONG_LOCK_FREE 1
#define __GCC_ATOMIC_POINTER_LOCK_FREE 1
#define __GCC_ATOMIC_SHORT_LOCK_FREE 1

https://github.com/llvm/llvm-project/blob/3042091168e99323217223a959df8675bdfa9b3c/libcxx/include/atomic#L1079-L1107 https://github.com/llvm/llvm-project/blob/3042091168e99323217223a959df8675bdfa9b3c/libcxx/include/atomic#L2680-L2698

libcxx build log

FAILED: src/CMakeFiles/cxx_static.dir/ryu/d2fixed.cpp.obj
E:\llvm14\bin\clang++.exe --target=armv6m-none-eabi  -DNDEBUG -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_LINK_PTHREAD_LIB -D_LIBCPP_LINK_RT_LIB -Iinclude/c++build -IK:/llvm-project/libcxx/src --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -ffunction-sections -fdata-sections -fno-ident --sysroot E:/llvm14/lib/clang-runtimes/armv6m_soft_nofp -D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION --target=armv6m-none-eabi -Os -DNDEBUG   --target=armv6m-none-eabi -DLIBCXX_BUILDING_LIBCXXABI -faligned-allocation -nostdinc++ -fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wformat-nonliteral -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -fno-exceptions -fno-rtti -IK:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1 -std=c++2a -MD -MT src/CMakeFiles/cxx_static.dir/ryu/d2fixed.cpp.obj -MF src\CMakeFiles\cxx_static.dir\ryu\d2fixed.cpp.obj.d -o src/CMakeFiles/cxx_static.dir/ryu/d2fixed.cpp.obj -c K:/llvm-project/libcxx/src/ryu/d2fixed.cpp
In file included from K:/llvm-project/libcxx/src/ryu/d2fixed.cpp:45:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/system_error:151:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/string:522:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/algorithm:653:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/functional:506:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__functional/function.h:21:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__memory/shared_ptr.h:35:
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/atomic:2696:16: error: use of undeclared identifier '__libcpp_signed_lock_free'; did you mean '__libcpp_signed_integer'?
typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
               ^~~~~~~~~~~~~~~~~~~~~~~~~
               __libcpp_signed_integer
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__concepts/arithmetic.h:42:9: note: '__libcpp_signed_integer' declared here
concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
        ^
In file included from K:/llvm-project/libcxx/src/ryu/d2fixed.cpp:45:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/system_error:151:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/string:522:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/algorithm:653:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/functional:506:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__functional/function.h:21:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__memory/shared_ptr.h:35:
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/atomic:2696:16: error: too few template arguments for concept '__libcpp_signed_integer'
typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
               ^
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__concepts/arithmetic.h:42:9: note: template is declared here
concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
        ^
In file included from K:/llvm-project/libcxx/src/ryu/d2fixed.cpp:45:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/system_error:151:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/string:522:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/algorithm:653:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/functional:506:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__functional/function.h:21:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__memory/shared_ptr.h:35:
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/atomic:2697:16: error: use of undeclared identifier '__libcpp_unsigned_lock_free'; did you mean '__libcpp_unsigned_integer'?
typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
               __libcpp_unsigned_integer
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__concepts/arithmetic.h:40:9: note: '__libcpp_unsigned_integer' declared here
concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
        ^
In file included from K:/llvm-project/libcxx/src/ryu/d2fixed.cpp:45:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/system_error:151:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/string:522:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/algorithm:653:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/functional:506:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__functional/function.h:21:
In file included from K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__memory/shared_ptr.h:35:
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/atomic:2697:16: error: too few template arguments for concept '__libcpp_unsigned_integer'
typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
               ^
K:/llvm14build/armv6m_soft_nofp/libcxx/include/c++/v1/__concepts/arithmetic.h:40:9: note: template is declared here
concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
        ^
4 errors generated.
DimitryAndric commented 2 years ago

See also freebsd/freebsd-src@8ae4c8aadfbd1ec3484dcd06336417c77ab1d2e0 (which uses a 32-bit type for __cxx_contention_t) and freebsd/freebsd-src@0e426a4a346876e61adc0b3981a91fe1e039c1ee (which applies the abandoned review https://reviews.llvm.org/D75183.

Something similar could also be done for other achitectures, though the big #ifdef might better be moved somewhere else.

ldionne commented 2 years ago

@DimitryAndric Any appetite for upstreaming these FreeBSD fixes?

DimitryAndric commented 2 years ago

Hmm now that I'm looking at this again, I wonder why @ogiroux added the #ifdef for __cxx_contention_t at all... Oliver, any idea if this could possibly always be an int32_t? What is the gain of using a 64-bit integer specifically?

In FreeBSD's version, Adrian Chadd added another #if case specifically for 32-bit mips (freebsd/freebsd-src@d061adc48d54ebb91b1709b16c59e8ceca895be2), and I added a bunch of others to help with 32-bit arm pre-v5 which doesn't have 64-bit atomics.

If we do need 64 bits if at all possible, it might be better to check for __LP64__ or something like that instead. Or check if ATOMIC_LLONG_LOCK_FREE == 2 in combination with sizeof(long long) == sizeof(int64_t), and in that case use int64_t, otherwise always use int32_t? That should work generically for all platforms.

philnik777 commented 1 year ago

Is this still an issue?

DimitryAndric commented 1 year ago

Is this still an issue?

This dropped off my radar, but in FreeBSD we're still carrying this patch on top of libc++. So I should get to work again and submit a review for libc++. :)

DimitryAndric commented 1 year ago

So another form of https://reviews.llvm.org/D75183 was landed in c04bcadf30ee07d437a238f78c2fb2c90be5c40c, and the only diff regarding atomic we have left in FreeBSD is now (effectively):

--- a/libcxx/include/__atomic/contention_t.h
+++ b/libcxx/include/__atomic/contention_t.h
@@ -19,11 +19,11 @@

 _LIBCPP_BEGIN_NAMESPACE_STD

-#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__))
+#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__)) || (defined(__FreeBSD__) && defined(__mips__))
     using __cxx_contention_t = int32_t;
 #else
     using __cxx_contention_t = int64_t;
-#endif // __linux__ || (_AIX && !__64BIT__)
+#endif // __linux__ || (_AIX && !__64BIT__) || (__FreeBSD__ && __mips__)

 using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;

Since we have already dropped mips support in FreeBSD 13, and have no further plans for it, I think I will leave it at this. @emaste do you agree?

Another solution might be to use the existing __cxx_atomic_is_lock_free() macro:

--- a/libcxx/include/__atomic/contention_t.h
+++ b/libcxx/include/__atomic/contention_t.h
@@ -19,11 +19,11 @@

 _LIBCPP_BEGIN_NAMESPACE_STD

-#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__))
+#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__)) || !__cxx_atomic_is_lock_free(sizeof(int64_t))
     using __cxx_contention_t = int32_t;
 #else
     using __cxx_contention_t = int64_t;
-#endif // __linux__ || (_AIX && !__64BIT__)
+#endif // __linux__ || (_AIX && !__64BIT__) || !is_lock_free(int64_t)

 using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;

But I don't really have enough time to write tests for this.