Skip to content

Commit

Permalink
[compiler-rt][AArch64] Initialize __aarch64_have_lse_atomics for Fuchsia
Browse files Browse the repository at this point in the history
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
  • Loading branch information
frobtech committed Mar 28, 2022
1 parent ca844ab commit 4e731ab
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler-rt/lib/builtins/cpu_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,23 @@ _Bool __aarch64_have_lse_atomics
#if defined(__ANDROID__)
#include <string.h>
#include <sys/system_properties.h>
#elif defined(__Fuchsia__)
#include <zircon/features.h>
#include <zircon/syscalls.h>
#endif
static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
#if defined(__FreeBSD__)
unsigned long hwcap;
int result = elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
__aarch64_have_lse_atomics = result == 0 && (hwcap & HWCAP_ATOMICS) != 0;
#elif defined(__Fuchsia__)
// This ensures the vDSO is a direct link-time dependency of anything that
// needs this initializer code.
#pragma comment(lib, "zircon")
uint32_t features;
zx_status_t status = _zx_system_get_features(ZX_FEATURE_KIND_CPU, &features);
__aarch64_have_lse_atomics =
status == ZX_OK && (features & ZX_ARM64_FEATURE_ISA_ATOMICS) != 0;
#else
unsigned long hwcap = getauxval(AT_HWCAP);
_Bool result = (hwcap & HWCAP_ATOMICS) != 0;
Expand Down

0 comments on commit 4e731ab

Please sign in to comment.