This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: When to use AT_HWCAP or AT_HWCAP2
On 07/08/2017 11:27, Jeffrey Walton wrote:
> On Mon, Aug 7, 2017 at 10:08 AM, Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>> ...
>> 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.
>
> OK, thanks. So the detection code might look something like:
>
> bool HasPMULL()
> {
> # if defined(__linux__) && defined(__aarch64__)
> if (getauxval(AT_HWCAP) & HWCAP_PMULL)
> return true;
> # elif defined(__linux__) && defined(__aarch32__)
> if (getauxval(AT_HWCAP2) & HWCAP2_PMULL)
> return true;
> # endif
> }
It looks correct.
>
> (We are trying to guard at runtime, but need need to make the compile
> decisions at compile time).
>
>> 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
>
> Thanks. That's kind of unexpected (to me) because:
>
>> cat /usr/include/asm-arm/hwcap.h
> ...
> /*
> * HWCAP2 flags - for elf_hwcap2 (in kernel) and AT_HWCAP2
> */
> #define HWCAP2_AES (1 << 0)
> #define HWCAP2_PMULL (1 << 1)
> #define HWCAP2_SHA1 (1 << 2)
> #define HWCAP2_SHA2 (1 << 3)
> #define HWCAP2_CRC32 (1 << 4)
>
> I would expect the second test (test-aarch32) to be non-zero if the
> features are present. Even old Mustang boards have CRC32, so the CRC32
> bit should be set.
Advertise availability of v8 Crypto instructions by hwcap support was added
on kernel v4.1 (commit a092aedb8115). Since I am running on an older kernel
(3.19) these information are no set on hwcap2 in compat mode.