[compiler-rt] [builtins] Fix CPU feature detection for FreeBSD on AArch64 (PR #76532)

Dimitry Andric via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 13:22:22 PST 2023


https://github.com/DimitryAndric updated https://github.com/llvm/llvm-project/pull/76532

>From ef7cd10ec46f772cf06a16ef8784d810f9417c92 Mon Sep 17 00:00:00 2001
From: Dimitry Andric <dimitry at andric.com>
Date: Thu, 28 Dec 2023 21:48:14 +0100
Subject: [PATCH 1/2] [builtins] Fix CPU feature detection for FreeBSD on
 AArch64

This is a follow-up to #75635 which broke the build for FreeBSD on
AArch64:

```
compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/freebsd.inc:3:16: error: call to undeclared function 'elf_aux_info'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    3 |   int result = elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
      |                ^
```

Using `elf_aux_info()` requires including `<sys/auxv.h>` first. To
prevent redeclaration issues with `hwcap.inc` attempting to define
`HWCAP_xxx` macros before `<sys/auxv.h>` does so, include `<sys/auxv.h>`
before any of the `.inc` files on FreeBSD.
---
 compiler-rt/lib/builtins/cpu_model/aarch64.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64.c b/compiler-rt/lib/builtins/cpu_model/aarch64.c
index 8e85de2218f7db..1a8bd9a5b7b5d2 100644
--- a/compiler-rt/lib/builtins/cpu_model/aarch64.c
+++ b/compiler-rt/lib/builtins/cpu_model/aarch64.c
@@ -34,6 +34,7 @@ _Bool __aarch64_have_lse_atomics
     __attribute__((visibility("hidden"), nocommon)) = false;
 
 #if defined(__FreeBSD__)
+#include <sys/auxv.h>
 #include "aarch64/hwcap.inc"
 #include "aarch64/lse_atomics/freebsd.inc"
 #elif defined(__Fuchsia__)

>From a831732a52a5fae5ee16f279e1bc88c3ab1e4153 Mon Sep 17 00:00:00 2001
From: Dimitry Andric <dimitry at andric.com>
Date: Thu, 28 Dec 2023 22:21:56 +0100
Subject: [PATCH 2/2] Work around clang-format overzealously reordering system
 headers after user headers.

---
 compiler-rt/lib/builtins/cpu_model/aarch64.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64.c b/compiler-rt/lib/builtins/cpu_model/aarch64.c
index 1a8bd9a5b7b5d2..44e1cf49d1e927 100644
--- a/compiler-rt/lib/builtins/cpu_model/aarch64.c
+++ b/compiler-rt/lib/builtins/cpu_model/aarch64.c
@@ -34,7 +34,9 @@ _Bool __aarch64_have_lse_atomics
     __attribute__((visibility("hidden"), nocommon)) = false;
 
 #if defined(__FreeBSD__)
+// clang-format off: should not reorder sys/auxv.h alphabetically
 #include <sys/auxv.h>
+// clang-format on
 #include "aarch64/hwcap.inc"
 #include "aarch64/lse_atomics/freebsd.inc"
 #elif defined(__Fuchsia__)



More information about the llvm-commits mailing list