Skip to content

Commit 4e731ab

Browse files
committed
[compiler-rt][AArch64] Initialize __aarch64_have_lse_atomics for Fuchsia
Use Fuchsia's zx_system_get_features API to determine whether LSE atomics are available on the machine. Reviewed By: abrachet Differential Revision: https://reviews.llvm.org/D118839
1 parent ca844ab commit 4e731ab

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

compiler-rt/lib/builtins/cpu_model.c

+11
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,23 @@ _Bool __aarch64_have_lse_atomics
801801
#if defined(__ANDROID__)
802802
#include <string.h>
803803
#include <sys/system_properties.h>
804+
#elif defined(__Fuchsia__)
805+
#include <zircon/features.h>
806+
#include <zircon/syscalls.h>
804807
#endif
805808
static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
806809
#if defined(__FreeBSD__)
807810
unsigned long hwcap;
808811
int result = elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
809812
__aarch64_have_lse_atomics = result == 0 && (hwcap & HWCAP_ATOMICS) != 0;
813+
#elif defined(__Fuchsia__)
814+
// This ensures the vDSO is a direct link-time dependency of anything that
815+
// needs this initializer code.
816+
#pragma comment(lib, "zircon")
817+
uint32_t features;
818+
zx_status_t status = _zx_system_get_features(ZX_FEATURE_KIND_CPU, &features);
819+
__aarch64_have_lse_atomics =
820+
status == ZX_OK && (features & ZX_ARM64_FEATURE_ISA_ATOMICS) != 0;
810821
#else
811822
unsigned long hwcap = getauxval(AT_HWCAP);
812823
_Bool result = (hwcap & HWCAP_ATOMICS) != 0;

0 commit comments

Comments
 (0)