Skip to content

Commit

Permalink
Bug 1687164 - Introduce NSS_DISABLE_CRYPTO_VSX and disable_crypto_vsx…
Browse files Browse the repository at this point in the history
… r=bbeurdouche

Currently, NSS assumes that every PowerPC target supports the crypto
and VSX extensions of the PowerPC ABI. However, VSX was only introduced
with ISA version 2.06 and the crypto extensions with ISA version 2.07
and enabling them on older PowerPC targets will result in a SIGILL. Thus,
make their use configurable and enable them by default on ppc64le only.

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
glaubitz committed Apr 6, 2021
1 parent ec6cf69 commit 9dab433
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 45 deletions.
5 changes: 5 additions & 0 deletions coreconf/Linux.mk
Expand Up @@ -54,6 +54,11 @@ ifeq (,$(filter-out ppc64 ppc64le,$(OS_TEST)))
ifeq ($(USE_64),1)
ARCHFLAG = -m64
endif
ifeq (,$(filter-out ppc ppc64,$(OS_TEST)))
ifneq ($(NSS_DISABLE_CRYPTO_VSX),0)
NSS_DISABLE_CRYPTO_VSX=1
endif
endif
else
ifeq ($(OS_TEST),alpha)
OS_REL_CFLAGS = -D_ALPHA_
Expand Down
1 change: 1 addition & 0 deletions coreconf/config.gypi
Expand Up @@ -107,6 +107,7 @@
'disable_libpkix%': 1,
'disable_werror%': 0,
'disable_altivec%': 0,
'disable_crypto_vsx%': 0,
'disable_arm32_neon%': 0,
'mozilla_client%': 0,
'comm_client%': 0,
Expand Down
7 changes: 6 additions & 1 deletion coreconf/config.mk
Expand Up @@ -231,10 +231,15 @@ DEFINES += -DNSS_DISABLE_ARM32_NEON
endif

# Avoid building with PowerPC's Altivec acceleration
ifdef NSS_DISABLE_ALTIVEC
ifeq ($(NSS_DISABLE_ALTIVEC),1)
DEFINES += -DNSS_DISABLE_ALTIVEC
endif

# Avoid building with PowerPC's Crypto and VSX instructions
ifeq ($(NSS_DISABLE_CRYPTO_VSX),1)
DEFINES += -DNSS_DISABLE_CRYPTO_VSX
endif

# This allows all library and tools code to use the util function
# implementations directly from libnssutil3, rather than the wrappers
# in libnss3 which are present for binary compatibility only
Expand Down
23 changes: 14 additions & 9 deletions lib/freebl/Makefile
Expand Up @@ -760,15 +760,20 @@ $(OBJDIR)/$(PROG_PREFIX)sha256-armv8$(OBJ_SUFFIX): CFLAGS += -march=armv8-a+cryp
endif

ifeq ($(CPU_ARCH),ppc)
ifndef NSS_DISABLE_ALTIVEC
$(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
$(OBJDIR)/$(PROG_PREFIX)sha512$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx \
-funroll-loops -fpeel-loops
ifeq ($(OS_TEST),ppc64le)
$(OBJDIR)/$(PROG_PREFIX)chacha20poly1305-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
endif # ppc64le
$(OBJDIR)/$(PROG_PREFIX)sha512$(OBJ_SUFFIX): CFLAGS += -funroll-loops -fpeel-loops
ifneq ($(NSS_DISABLE_ALTIVEC),1)
$(OBJDIR)/$(PROG_PREFIX)gcm-ppc$(OBJ_SUFFIX): CFLAGS += -maltivec
$(OBJDIR)/$(PROG_PREFIX)gcm$(OBJ_SUFFIX): CFLAGS += -maltivec
$(OBJDIR)/$(PROG_PREFIX)rijndael$(OBJ_SUFFIX): CFLAGS += -maltivec
$(OBJDIR)/$(PROG_PREFIX)sha512$(OBJ_SUFFIX): CFLAGS += -maltivec
$(OBJDIR)/$(PROG_PREFIX)chacha20poly1305-ppc$(OBJ_SUFFIX): CFLAGS += -maltivec
endif
ifneq ($(NSS_DISABLE_CRYPTO_VSX),1)
$(OBJDIR)/$(PROG_PREFIX)gcm-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -mvsx
$(OBJDIR)/$(PROG_PREFIX)gcm$(OBJ_SUFFIX): CFLAGS += -mcrypto -mvsx
$(OBJDIR)/$(PROG_PREFIX)rijndael$(OBJ_SUFFIX): CFLAGS += -mcrypto -mvsx
$(OBJDIR)/$(PROG_PREFIX)sha512$(OBJ_SUFFIX): CFLAGS += -mcrypto -mvsx
$(OBJDIR)/$(PROG_PREFIX)chacha20poly1305-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -mvsx
endif
endif

Expand Down
121 changes: 86 additions & 35 deletions lib/freebl/freebl.gyp
Expand Up @@ -264,14 +264,25 @@
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports'
],
'cflags': [
'-mcrypto',
'-maltivec'
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec'
],
'conditions': [
[ 'disable_crypto_vsx==0', {
'cflags': [
'-mcrypto',
'-maltivec'
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec'
],
}, 'disable_crypto_vsx==1', {
'cflags': [
'-maltivec'
],
'cflags_mozilla': [
'-maltivec'
],
}]
]
},
{
'target_name': 'gcm-sha512-nodepend-ppc_c_lib',
Expand All @@ -282,20 +293,35 @@
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports'
],
'cflags': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
'conditions': [
[ 'disable_crypto_vsx==0', {
'cflags': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops'
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops'
],
}, 'disable_crypto_vsx==1', {
'cflags': [
'-maltivec',
'-funroll-loops',
'-fpeel-loops'
],
'cflags_mozilla': [
'-maltivec',
'-funroll-loops',
'-fpeel-loops'
],
}]
]
},
{
'target_name': 'gcm-sha512-ppc_c_lib',
Expand All @@ -306,19 +332,34 @@
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports'
],
'cflags': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
'conditions': [
[ 'disable_crypto_vsx==0', {
'cflags': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops'
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops'
],
}, 'disable_crypto_vsx==1', {
'cflags': [
'-maltivec',
'-funroll-loops',
'-fpeel-loops'
],
'cflags_mozilla': [
'-maltivec',
'-funroll-loops',
'-fpeel-loops'
],
}]
],
'defines!': [
'FREEBL_NO_DEPEND',
Expand Down Expand Up @@ -432,6 +473,11 @@
'NSS_DISABLE_ALTIVEC',
],
}],
[ 'disable_crypto_vsx==1 and (target_arch=="ppc" or target_arch=="ppc64" or target_arch=="ppc64le")', {
'defines!': [
'NSS_DISABLE_CRYPTO_VSX',
],
}],
[ 'OS=="linux"', {
'defines!': [
'FREEBL_NO_DEPEND',
Expand Down Expand Up @@ -500,6 +546,11 @@
'NSS_DISABLE_ALTIVEC',
],
}],
[ 'disable_crypto_vsx==1 and (target_arch=="ppc" or target_arch=="ppc64" or target_arch=="ppc64le")', {
'defines!': [
'NSS_DISABLE_CRYPTO_VSX',
],
}],
[ 'OS!="linux"', {
'conditions': [
[ 'moz_fold_libs==0', {
Expand Down

0 comments on commit 9dab433

Please sign in to comment.