compiler-rt: Use FreeBSD's elf_aux_info to detect AArch64 HW features
authorDimitry Andric <dimitry@andric.com>
Sat, 20 Nov 2021 11:10:06 +0000 (12:10 +0100)
committerDimitry Andric <dimitry@andric.com>
Sat, 20 Nov 2021 11:12:03 +0000 (12:12 +0100)
Using the out-of-line LSE atomics helpers for AArch64 on FreeBSD also
requires adding support for initializing __aarch64_have_lse_atomics
correctly. On Linux this is done with getauxval(3), on FreeBSD with
elf_aux_info(3), which has a slightly different interface.

Differential Revision: https://reviews.llvm.org/D109330

compiler-rt/lib/builtins/cpu_model.c

index b8d807e..53e2d89 100644 (file)
@@ -799,8 +799,14 @@ _Bool __aarch64_have_lse_atomics
 #define HWCAP_ATOMICS (1 << 8)
 #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;
+#else
   unsigned long hwcap = getauxval(AT_HWCAP);
   __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0;
+#endif
 }
 #endif // defined(__has_include)
 #endif // __has_include(<sys/auxv.h>)