Commit e619cdeb authored by Piotr Kubaj's avatar Piotr Kubaj

Bug 1602386 - Fix build on FreeBSD/powerpc platforms. r=jcj

FreeBSD has elf_aux_info instead of getauxval, but only since FreeBSD 12. Previous versions (11 is still supported) don't have any equivalent and users need to query sysctl manually.

Differential Revision: https://phabricator.services.mozilla.com/D56712

--HG--
extra : moz-landing-system : lando
parent 97df5ade
......@@ -778,7 +778,9 @@ $(OBJDIR)/$(PROG_PREFIX)gcm-aarch64$(OBJ_SUFFIX): CFLAGS += -march=armv8-a+crypt
endif
ifeq ($(CPU_ARCH),ppc)
$(OBJDIR)/$(PROG_PREFIX)gcm-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec
$(OBJDIR)/$(PROG_PREFIX)gcm-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)gcm$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)rijndael$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
endif
$(OBJDIR)/$(PROG_PREFIX)Hacl_Chacha20_Vec128$(OBJ_SUFFIX): CFLAGS += -mssse3 -msse4 -mavx -maes
......
......@@ -431,7 +431,11 @@ ppc_crypto_support()
#if defined(__powerpc__)
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 12)
#include <sys/auxv.h>
#elif (defined(__FreeBSD__) && __FreeBSD__ < 12)
#include <sys/sysctl.h>
#endif
// Defines from cputable.h in Linux kernel - PPC, letting us build on older kernels
#ifndef PPC_FEATURE2_VEC_CRYPTO
......@@ -443,7 +447,17 @@ CheckPPCSupport()
{
char *disable_hw_crypto = PR_GetEnvSecure("NSS_DISABLE_PPC_GHASH");
long hwcaps = getauxval(AT_HWCAP2);
unsigned long hwcaps = 0;
#if defined(__linux__)
hwcaps = getauxval(AT_HWCAP2);
#elif defined(__FreeBSD__)
# if __FreeBSD__ >= 12
elf_aux_info(AT_HWCAP2, &hwcaps, sizeof(hwcaps));
# else
size_t len = sizeof(hwcaps);
sysctlbyname("hw.cpu_features2", &hwcaps, &len, NULL, 0);
# endif
#endif
ppc_crypto_support_ = hwcaps & PPC_FEATURE2_VEC_CRYPTO && disable_hw_crypto == NULL;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment