[compiler-rt] [FMV][AArch64] Add initial AT_HWCAP3 / AT_HWCAP4 support (PR #161595)

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 2 11:57:26 PST 2025


Hi Brad!

I followed up on the commit, but just in case it was missed :)

On older glibc versions combined with this compiler-rt we end up getting
crashes in elf_aux_info with these calls when support isn't already there
for AT_HWCAP3/4. Would you mind updating this or reverting and reapplying
with a change to detect if we know about the constants before using them?
(or something similar)

Thoughts?

Thanks!

-eric


On Wed, Oct 1, 2025 at 3:44 PM Brad Smith via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> https://github.com/brad0 created
> https://github.com/llvm/llvm-project/pull/161595
>
> Add support for AT_HWCAP3 / AT_HWCAP4 which is supported by glibc, musl,
> Android and FreeBSD 15/-current.
>
> Stop using sys/ifunc.h as libgcc has done. This is more portable as
> older glibc will not have the hwcap3/4 fields.
>
> >From 77155981d86b43cdf59d98f7b527e187c9c8c422 Mon Sep 17 00:00:00 2001
> From: Brad Smith <brad at comstyle.com>
> Date: Wed, 1 Oct 2025 17:50:53 -0400
> Subject: [PATCH] [FMV][AArch64] Add initial AT_HWCAP3 / AT_HWCAP4 support
>
> Add support for AT_HWCAP3 / AT_HWCAP4 which is supported by glibc, musl,
> Android and FreeBSD 15/-current.
>
> Stop using sys/ifunc.h as libgcc has done. This is more portable as
> older glibc will not have the hwcap3/4 fields.
> ---
>  compiler-rt/lib/builtins/cpu_model/aarch64.c     |  6 ++----
>  .../builtins/cpu_model/aarch64/fmv/android.inc   |  4 ++++
>  .../cpu_model/aarch64/fmv/elf_aux_info.inc       |  8 ++++++--
>  .../builtins/cpu_model/aarch64/fmv/getauxval.inc |  4 ++++
>  .../lib/builtins/cpu_model/aarch64/hwcap.inc     | 16 ++++++++++++++++
>  5 files changed, 32 insertions(+), 6 deletions(-)
>
> diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64.c
> b/compiler-rt/lib/builtins/cpu_model/aarch64.c
> index d7880529ebe70..ca487cbcc3817 100644
> --- a/compiler-rt/lib/builtins/cpu_model/aarch64.c
> +++ b/compiler-rt/lib/builtins/cpu_model/aarch64.c
> @@ -19,15 +19,13 @@
>  #error This file is intended only for aarch64-based targets
>  #endif
>
> -#if __has_include(<sys/ifunc.h>)
> -#include <sys/ifunc.h>
> -#else
>  typedef struct __ifunc_arg_t {
>    unsigned long _size;
>    unsigned long _hwcap;
>    unsigned long _hwcap2;
> +  unsigned long _hwcap3;
> +  unsigned long _hwcap4;
>  } __ifunc_arg_t;
> -#endif // __has_include(<sys/ifunc.h>)
>
>  // LSE support detection for out-of-line atomics
>  // using HWCAP and Auxiliary vector
> diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/android.inc
> b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/android.inc
> index a9e3594e93c2d..d19beca690580 100644
> --- a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/android.inc
> +++ b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/android.inc
> @@ -27,10 +27,14 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
>
>    unsigned long hwcap = getauxval(AT_HWCAP);
>    unsigned long hwcap2 = getauxval(AT_HWCAP2);
> +  unsigned long hwcap3 = getauxval(AT_HWCAP3);
> +  unsigned long hwcap4 = getauxval(AT_HWCAP4);
>
>    __ifunc_arg_t arg;
>    arg._size = sizeof(__ifunc_arg_t);
>    arg._hwcap = hwcap;
>    arg._hwcap2 = hwcap2;
> +  arg._hwcap3 = hwcap3;
> +  arg._hwcap4 = hwcap4;
>    __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);
>  }
> diff --git
> a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/elf_aux_info.inc
> b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/elf_aux_info.inc
> index aa975dc854f97..ef6fbbe767829 100644
> --- a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/elf_aux_info.inc
> +++ b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/elf_aux_info.inc
> @@ -7,8 +7,7 @@ void __init_cpu_features_resolver(unsigned long hwcap,
>  }
>
>  void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
> -  unsigned long hwcap = 0;
> -  unsigned long hwcap2 = 0;
> +  unsigned long hwcap, hwcap2, hwcap3, hwcap4 = 0;
>    // CPU features already initialized.
>    if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED))
>      return;
> @@ -19,9 +18,14 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
>    if (res)
>      return;
>
> +  elf_aux_info(AT_HWCAP2, &hwcap3, sizeof hwcap3);
> +  elf_aux_info(AT_HWCAP2, &hwcap4, sizeof hwcap4);
> +
>    __ifunc_arg_t arg;
>    arg._size = sizeof(__ifunc_arg_t);
>    arg._hwcap = hwcap;
>    arg._hwcap2 = hwcap2;
> +  arg._hwcap2 = hwcap3;
> +  arg._hwcap2 = hwcap4;
>    __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);
>  }
> diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/getauxval.inc
> b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/getauxval.inc
> index 486f77a1e4d2f..9a603ac761e60 100644
> --- a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/getauxval.inc
> +++ b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/getauxval.inc
> @@ -12,10 +12,14 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
>
>    unsigned long hwcap = getauxval(AT_HWCAP);
>    unsigned long hwcap2 = getauxval(AT_HWCAP2);
> +  unsigned long hwcap3 = getauxval(AT_HWCAP3);
> +  unsigned long hwcap4 = getauxval(AT_HWCAP4);
>
>    __ifunc_arg_t arg;
>    arg._size = sizeof(__ifunc_arg_t);
>    arg._hwcap = hwcap;
>    arg._hwcap2 = hwcap2;
> +  arg._hwcap2 = hwcap3;
> +  arg._hwcap2 = hwcap4;
>    __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);
>  }
> diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64/hwcap.inc
> b/compiler-rt/lib/builtins/cpu_model/aarch64/hwcap.inc
> index 2f44e9e5f635e..1ce757147e0ae 100644
> --- a/compiler-rt/lib/builtins/cpu_model/aarch64/hwcap.inc
> +++ b/compiler-rt/lib/builtins/cpu_model/aarch64/hwcap.inc
> @@ -190,3 +190,19 @@
>  #ifndef HWCAP2_CSSC
>  #define HWCAP2_CSSC (1UL << 34)
>  #endif
> +
> +#ifndef AT_HWCAP3
> +#if defined(__linux__) || defined(__ANDROID__)
> +#define AT_HWCAP3 29
> +#else
> +#define AT_HWCAP 38
> +#endif
> +#endif
> +
> +#ifndef AT_HWCAP4
> +#if defined(__linux__) || defined(__ANDROID__)
> +#define AT_HWCAP4 30
> +#else
> +#define AT_HWCAP4 39
> +#endif
> +#endif
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20251202/a0c0ec9a/attachment.html>


More information about the llvm-commits mailing list