This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: When to use AT_HWCAP or AT_HWCAP2



On 07/08/2017 10:06, Jeffrey Walton wrote:
> Hi Everyone,
> 
> Please forgive my ignorance. The getauxval (3) man page discusses both
> AT_HWCAP and AT_HWCAP2. I'm less clear on about when I should use one
> or the other?

AT_HWCAP2 was added because for some architectures (arm and powerpc for
instance) the bits on AT_HWCAP was exhausted.  So it would depend of what 
kind of information you want to get from the kernel, which kernel version
(since it may not have support for such information) and the underlying 
architecture. 

> 
> For example, suppose I'm on an Aarch64 Opteron. Testing shows I need
> AT_HWCAP for HWCAP_AES, HWCAP_PMULL, etc. Now suppose I am in a
> Aarch32 execution environment on the same machine. Do I check AT_HWCAP
> or AT_HWCAP2? How do I know the difference at runtime?

For AArch64, current 4.13-rc4 only uses AT_HWCAP [1]. Now for AArch32
execution environment it is handled a different underlying architecture
and thus kernel abi is different. Kernel it will also expose AT_HWCAP2
and it will depend of what kind of information you would like to check [2].

For instance, to check for hardware AES support on AArch64 you will
need to check for AT_HWCAP & HWCAP_AES, while for AArch64 you will
need to check for AT_HWCAP2 & HWCAP2_AES.

For instance the test:

---
#include <stdio.h>
#include <sys/auxv.h>

int main (void)
{
  printf ("0x%lx\n", getauxval (AT_HWCAP));
  printf ("0x%lx\n", getauxval (AT_HWCAP2));
  return 0;
}
---

Run on same machine (3.19.0-33-generic aarch64):

$ ./test-aarch64 
0x7
0x0
$ ./test-aarch32 # on a sysroot
0x37b0d6
0x0

You can also check with LD_SHOW_AUXV=1, since it will print HWCAP (I think
you will need an updated GLIBC to actually print HWCAP2)

[1] arch/arm64/include/uapi/asm/hwcap.h
[2] arch/arm/include/uapi/asm/hwcap.h


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]