Skip to content

[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

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libc/hdr/math_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#else // Overlay mode

// GCC will include CXX headers when __cplusplus is defined. This behavior
// can be suppressed by defining _GLIBCXX_INCLUDE_NEXT_C_HEADERS.
#if defined(__GNUC__) && !defined(__clang__)
#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
#endif
#include <math.h>

// Some older math.h header does not have FP_INT_* constants yet.
Expand Down
2 changes: 2 additions & 0 deletions libc/src/__support/File/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: migrate to proxy headers
add_object_library(
file
SRCS
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/threads/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/cos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/sin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/sincos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/search/hsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion libc/startup/linux/aarch64/tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading