Skip to content

Commit 972832d

Browse files
authored
AT_HWCAP2 not always defined (#1682)
### Issues: Addresses: aws/aws-lc-rs#427 ### Description of changes: * Allow fallback when `AT_HWCAP2` is not defined (for older glibc). > > AT_HWCAP2 (since glibc 2.18) > Further machine-dependent hints about processor > capabilities. > ### Testing: * I've not yet been able to setup an environment that replicates [the failure seen downstream](https://github.com/rust-lang/rustup/actions/runs/9720503984/job/26831972336?pr=3898) for `arm-unknown-linux-gnueabihf`: ``` In file included from /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.18.0/aws-lc/crypto/fipsmodule/bcm.c:81: /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.18.0/aws-lc/crypto/fipsmodule/cpucap/cpu_arm_linux.c: In function 'aws_lc_0_18_0_OPENSSL_cpuid_setup': /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.18.0/aws-lc/crypto/fipsmodule/cpucap/cpu_arm_linux.c:121:38: error: 'AT_HWCAP2' undeclared (first use in this function); did you mean 'AT_HWCAP'? unsigned long hwcap2 = getauxval(AT_HWCAP2); ^~~~~~~~~ AT_HWCAP /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.18.0/aws-lc/crypto/fipsmodule/cpucap/cpu_arm_linux.c:121:38: note: each undeclared identifier is reported only once for each function it appears in /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.18.0/aws-lc/crypto/fipsmodule/bcm.c: At top level: cc1: error: unrecognized command line option '-Wno-c11-extensions' [-Werror] cc1: all warnings being treated as errors ninja: build stopped: subcommand failed. ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent ba94617 commit 972832d

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

crypto/fipsmodule/cpucap/cpu_arm_freebsd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ void OPENSSL_cpuid_setup(void) {
3030
// left at zero. The rest of this function will then gracefully report
3131
// the features are absent.
3232
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
33+
#if defined(AT_HWCAP2)
3334
elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
35+
#endif
3436

3537
// Matching OpenSSL, only report other features if NEON is present.
3638
if (hwcap & HWCAP_NEON) {

crypto/fipsmodule/cpucap/cpu_arm_linux.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ void OPENSSL_cpuid_setup(void) {
118118
// this is now rare (see Chrome's Net.NeedsHWCAP2Workaround metric), but AES
119119
// and PMULL extensions are very useful, so we still carry the workaround
120120
// for now.
121+
#if defined(AT_HWCAP2)
121122
unsigned long hwcap2 = getauxval(AT_HWCAP2);
123+
#else
124+
unsigned long hwcap2 = 0;
125+
#endif
122126
if (hwcap2 == 0) {
123127
hwcap2 = crypto_get_arm_hwcap2_from_cpuinfo(&cpuinfo);
124128
g_needs_hwcap2_workaround = hwcap2 != 0;

crypto/fipsmodule/cpucap/cpu_ppc64le.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ static void handle_cpu_env(unsigned long *out, const char *in) {
6868
extern uint8_t OPENSSL_cpucap_initialized;
6969

7070
void OPENSSL_cpuid_setup(void) {
71+
#if defined(AT_HWCAP2)
7172
OPENSSL_ppc64le_hwcap2 = getauxval(AT_HWCAP2);
73+
#else
74+
OPENSSL_ppc64le_hwcap2 = 0;
75+
#endif
7276
OPENSSL_cpucap_initialized = 1;
7377

7478
// OPENSSL_ppccap is a 64-bit hex string which may start with "0x".

0 commit comments

Comments
 (0)