-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] fix aarch64 GCC build #97932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] fix aarch64 GCC build #97932
Conversation
@llvm/pr-subscribers-libc Author: Schrodinger ZHU Yifan (SchrodingerZhu) ChangesFull diff: https://github.com/llvm/llvm-project/pull/97932.diff 8 Files Affected:
diff --git a/libc/hdr/math_macros.h b/libc/hdr/math_macros.h
index d13c5ff7647ad2..ae42dbe2bc4e51 100644
--- a/libc/hdr/math_macros.h
+++ b/libc/hdr/math_macros.h
@@ -15,6 +15,9 @@
#else // Overlay mode
+// GCC will include CXX headers when __cplusplus is defined. This behavior
+// can be suppressed by defining _GLIBCXX_INCLUDE_NEXT_C_HEADERS.
+#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
#include <math.h>
// Some older math.h header does not have FP_INT_* constants yet.
diff --git a/libc/src/__support/File/linux/CMakeLists.txt b/libc/src/__support/File/linux/CMakeLists.txt
index ccf27f73d6aa8c..8436a687116bd9 100644
--- a/libc/src/__support/File/linux/CMakeLists.txt
+++ b/libc/src/__support/File/linux/CMakeLists.txt
@@ -1,3 +1,4 @@
+# TODO: migrate to proxy headers
add_object_library(
file
SRCS
@@ -8,6 +9,7 @@ add_object_library(
libc.include.fcntl
libc.include.stdio
libc.include.sys_syscall
+ libc.include.sys_stat
libc.src.__support.CPP.new
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
diff --git a/libc/src/__support/threads/sleep.h b/libc/src/__support/threads/sleep.h
index 9a2dff598ece8b..6433bc3badd505 100644
--- a/libc/src/__support/threads/sleep.h
+++ b/libc/src/__support/threads/sleep.h
@@ -22,8 +22,10 @@ LIBC_INLINE void sleep_briefly() {
__builtin_amdgcn_s_sleep(2);
#elif defined(LIBC_TARGET_ARCH_IS_X86)
__builtin_ia32_pause();
-#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
+#elif defined(LIBC_TARGET_ARCH_IS_AARCH64) && __has_builtin(__builtin_arm_isb)
__builtin_arm_isb(0xf);
+#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
+ asm volatile("isb\n" ::: "memory");
#else
// Simply do nothing if sleeping isn't supported on this platform.
#endif
diff --git a/libc/src/math/generic/cos.cpp b/libc/src/math/generic/cos.cpp
index a2cfe758fe4cc0..0eb6d9d6a6de85 100644
--- a/libc/src/math/generic/cos.cpp
+++ b/libc/src/math/generic/cos.cpp
@@ -61,7 +61,7 @@ LLVM_LIBC_FUNCTION(double, cos, (double x)) {
DoubleDouble y;
unsigned k;
- generic::LargeRangeReduction<NO_FMA> range_reduction_large;
+ generic::LargeRangeReduction<NO_FMA> range_reduction_large{};
// |x| < 2^32 (with FMA) or |x| < 2^23 (w/o FMA)
if (LIBC_LIKELY(x_e < FPBits::EXP_BIAS + FAST_PASS_EXPONENT)) {
diff --git a/libc/src/math/generic/sin.cpp b/libc/src/math/generic/sin.cpp
index 207435d4385ae1..e7a43245408bfd 100644
--- a/libc/src/math/generic/sin.cpp
+++ b/libc/src/math/generic/sin.cpp
@@ -62,7 +62,7 @@ LLVM_LIBC_FUNCTION(double, sin, (double x)) {
DoubleDouble y;
unsigned k;
- generic::LargeRangeReduction<NO_FMA> range_reduction_large;
+ generic::LargeRangeReduction<NO_FMA> range_reduction_large{};
// |x| < 2^32 (with FMA) or |x| < 2^23 (w/o FMA)
if (LIBC_LIKELY(x_e < FPBits::EXP_BIAS + FAST_PASS_EXPONENT)) {
diff --git a/libc/src/math/generic/sincos.cpp b/libc/src/math/generic/sincos.cpp
index a0dd3a018af59c..ed70e380b72e8a 100644
--- a/libc/src/math/generic/sincos.cpp
+++ b/libc/src/math/generic/sincos.cpp
@@ -63,7 +63,7 @@ LLVM_LIBC_FUNCTION(void, sincos, (double x, double *sin_x, double *cos_x)) {
DoubleDouble y;
unsigned k;
- generic::LargeRangeReduction<NO_FMA> range_reduction_large;
+ generic::LargeRangeReduction<NO_FMA> range_reduction_large{};
// |x| < 2^32 (with FMA) or |x| < 2^23 (w/o FMA)
if (LIBC_LIKELY(x_e < FPBits::EXP_BIAS + FAST_PASS_EXPONENT)) {
diff --git a/libc/src/search/hsearch.cpp b/libc/src/search/hsearch.cpp
index 5aeb5c29449e1e..a30803c5a0de72 100644
--- a/libc/src/search/hsearch.cpp
+++ b/libc/src/search/hsearch.cpp
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(ENTRY *, hsearch, (ENTRY item, ACTION action)) {
- ENTRY *result;
+ ENTRY *result = nullptr;
if (internal::global_hash_table == nullptr) {
// If global_hash_table is null, we create a new hash table with a minimal
// capacity. Such hashtable will be expanded as needed.
diff --git a/libc/startup/linux/aarch64/tls.cpp b/libc/startup/linux/aarch64/tls.cpp
index f2579e821b1bf2..9f143f962892d8 100644
--- a/libc/startup/linux/aarch64/tls.cpp
+++ b/libc/startup/linux/aarch64/tls.cpp
@@ -80,7 +80,18 @@ void cleanup_tls(uintptr_t addr, uintptr_t size) {
}
bool set_thread_ptr(uintptr_t val) {
- __arm_wsr64("tpidr_el0", val);
+// The PR for __arm_wsr64 support in GCC was merged on Dec 6, 2023, and it is
+// not yet usable in 13.3.0
+// https://github.com/gcc-mirror/gcc/commit/fc42900d21abd5eacb7537c3c8ffc5278d510195
+#if __has_builtin(__builtin_arm_wsr64)
+ __builtin_arm_wsr64("tpidr_el0", val);
+#elif __has_builtin(__builtin_aarch64_wsr)
+ __builtin_aarch64_wsr("tpidr_el0", val);
+#elif defined(__GNUC__)
+ asm volatile("msr tpidr_el0, %0" ::"r"(val));
+#else
+#error "Unsupported compiler"
+#endif
return true;
}
} // namespace LIBC_NAMESPACE
|
@lntue BTW, there are massive amount of conversion warnings for fp16 tests. |
Can you create an issue with examples / reproduction and assign it to @overmighty ? |
iirc, it's because of test templates that have, e.g., |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/2203 Here is the relevant piece of the build log for the reference:
|
This PR fix several build errors on aarch64 targets when building with gcc:
Werrors