Closed Bug 1602386 Opened 5 years ago Closed 5 years ago

Fix build on FreeBSD/powerpc*

Categories

(NSS :: Build, defect)

3.48
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: pkubaj, Unassigned, NeedInfo)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

Attached patch patch-lib_freebl_blinit.c (obsolete) — Splinter Review

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

Steps to reproduce:

On FreeBSD/powerpc64 box:

  1. portsnap fetch extract
  2. make -C /usr/ports/security/nss install clean

Actual results:

blinit.c:417:27: error: use of undeclared identifier 'hwcaps'
ppc_crypto_support_ = hwcaps & PPC_FEATURE2_VEC_CRYPTO && disable_hw_crypto == NULL;
^
1 error generated.

Expected results:

NSS should install.

I copied from a wrong window, the actual error is:
blinit.c:410:19: error: implicit declaration of function 'getauxval' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
long hwcaps = getauxval(AT_HWCAP2);
^

Attachment #9114492 - Attachment is patch: true
Attachment #9114492 - Attachment mime type: text/x-csrc → text/plain
Attachment #9114492 - Flags: review?(kjacobs.bugzilla)
Attachment #9114492 - Flags: review?(jbeich)
Comment on attachment 9114492 [details] [diff] [review] patch-lib_freebl_blinit.c Thanks - the fix looks ok, but I don't have such a machine to confirm. We should probably include other BSDs: https://searchfox.org/mozilla-central/source/config/external/nspr/prcpucfg.h#21 Piotr: could you please attach an exported patch rather than just the diff, or (preferably) use [phabricator](https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html)? This way you'll get credit for the fix :).
Attachment #9114492 - Flags: review?(kjacobs.bugzilla) → review+
Comment on attachment 9114492 [details] [diff] [review] patch-lib_freebl_blinit.c Review of attachment 9114492 [details] [diff] [review]: ----------------------------------------------------------------- Contains a bug. Please, fix and resubmit. FWIW, attachment 9087350 [details] [diff] [review] has an example how to fix FreeBSD < 12 which lacks <sys/auxv.h>. ::: lib/freebl/blinit.c.orig @@ +411,3 @@ > long hwcaps = getauxval(AT_HWCAP2); > +#elif defined(__FreeBSD__) > + long hwcaps; IMPORTANT: Initialize to `0` in case `elf_aux_info` fails e.g., when run via qemu-user. NOTE: `AT_HWCAP2` returns `unsigned long`, not `long`. Affects Linux as well.
Attachment #9114492 - Flags: review?(jbeich) → review-

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.

Attachment #9115139 - Flags: review+
Regressed by: 1566126
Has Regression Range: --- → yes
Keywords: regression

Comment on attachment 9115139 [details]
Fix build on FreeBSD/powerpc platforms.

 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

gcm.c and rijndael.c dispatch into SIMD only when CPU supports it. Building them with -maltivec may lead to a crash on older CPUs. There's probably a better way...

Can you show more context of the error e.g., command line used to build gcm-ppc.c that failed? I can't reproduce when using #include e.g.,

$ ssh ref12-ppc64.freebsd.org

$ cat a.c
#include "altivec-types.h"
vec_u64 foo(void) { }

$ gcc8 -maltivec -c a.c
$ echo $?
0

$ gcc8 -maltivec -c altivec-types.h
altivec-types.h:19:1: error: use of 'long long' in AltiVec types is invalid without '-mvsx'
 typedef __vector unsigned long long vec_u64;
 ^~~~~~~
altivec-types.h:20:1: error: use of 'long long' in AltiVec types is invalid without '-mvsx'
 typedef __vector signed long long vec_s64;
 ^~~~~~~
Attachment #9114492 - Attachment is obsolete: true

Error for gcm.c:
gcc9 -o FreeBSD12.1_OPT.OBJ/FreeBSD_SINGLE_SHLIB/gcm.o -c -std=c99 -O2 -pipe -I/usr/local/include/nspr -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9 -fno-strict-aliasing
-fPIC -Wall -Wno-switch -DFREEBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK -Wall -Wshadow -Werror -DXP_UNIX -UDEBUG -DNDEBUG -D_THREAD_SAFE -D_REENTRANT -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIR
ECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -I./../dist/FreeBSD12.1_OPT.OBJ/include -I./../dist/public/ -I./../dist/private/ -fPIC -Wall -Wno-switch -DFR
EEBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK -Wall -Wshadow -Werror -DXP_UNIX -UDEBUG -DNDEBUG -D_THREAD_SAFE -D_REENTRANT -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -D
SSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -I../../dist/FreeBSD12.1_OPT.OBJ/include -I../../dist/public/ -I../../dist/private/ -fPIC -Wall -Wno-switch -DFREEBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK -Wall -Wshadow -Werror -DXP_UNIX -DSHLIB_SUFFIX="so" -DSHLIB_PREFIX="lib" -DSHLIB_VERSION="3" -DSOFTOKEN_SHLIB_VERSION="3" -DRIJNDAEL_INCLUDE_TABLES -UDEBUG -DNDEBUG -D_THREAD_SAFE -D_REENTRANT -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -DNSS_USE_64 -DFREEBL_LOWHASH -DNSS_NO_INIT_SUPPORT -DHAVE_INT128_SUPPORT -DMP_API_COMPATIBLE -I../../../dist/FreeBSD12.1_OPT.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss -Impi -Iecl -Iverified -fPIC
-Wall -Wno-switch -DFREEBSD -DHAVE_STRERROR -DHAVE_BSD_FLOCK -Wall -Wshadow -Werror -DXP_UNIX -DSHLIB_SUFFIX="so" -DSHLIB_PREFIX="lib" -DSHLIB_VERSION="3" -DSOFTOKEN_SHLIB_VERSION="3" -DRIJNDAEL_INCLUDE_TABLES -UDEBUG -DNDEBUG -D_THREAD_SAFE -D_REENTRANT -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -DNSS_USE_64 -DFREEBL_LOWHASH -DNSS_NO_INIT_SUPPORT -DHAVE_INT128_SUPPORT -DMP_API_COMPATIBLE -I../../../dist/FreeBSD12.1_OPT.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss -Impi -Iecl -Iverified gcm.c
In file included from altivec-types.h:11,
from gcm.h:34,
from gcm.c:12:
/usr/local/lib/gcc9/gcc/powerpc64-portbld-freebsd12.1/9.2.0/include/altivec.h:34:2: error: #error Use the "-maltivec" flag to enable PowerPC AltiVec support
34 | #error Use the "-maltivec" flag to enable PowerPC AltiVec support
| ^~~~~
In file included from gcm.h:34,
from gcm.c:12:
altivec-types.h:19:1: error: use of 'long long' in AltiVec types is invalid without '-mvsx'
19 | typedef __vector unsigned long long vec_u64;
| ^~~~~~~
altivec-types.h:20:1: error: use of 'long long' in AltiVec types is invalid without '-mvsx'
20 | typedef __vector signed long long vec_s64;
| ^~~~~~~

Note that it's actually a bit inaccurate, adding -mvsx alone is actually enough (VSX probably implies AltiVec).

Piotr, can you try enabling #define USE_PPC_CRYPTO from lib/freebl/gcm.h on big-endian then test build and runtime on FreeBSD powerpc64? -mcrypto -maltivec only need to be passed if USE_PPC_CRYPTO is set.

Flags: needinfo?(pkubaj)

I've posted a couple of questions in the Phabricator review, but I do want to get this PPC fix into tree.

(In reply to Piotr Kubaj from comment #10)

In file included from altivec-types.h:11,
from gcm.h:34,
from gcm.c:12:
/usr/local/lib/gcc9/gcc/powerpc64-portbld-freebsd12.1/9.2.0/include/altivec.h:34:2: error: #error Use the "-maltivec" flag to enable PowerPC AltiVec support

Try pragma target (a la sse2 in the same file) then revert lib/freebl/Makefile changes.

#pragma GCC push_options
#pragma GCC target("altivec")
#include "altivec-types.h"
#pragma GCC pop_options

Clang has attribute pragma but it doesn't seem to work with headers. Maybe Clang should port https://github.com/llvm/llvm-project/commit/9fc7fb274e53 to <altivec.h> instead.

Just to reiterate, I'm happy to accept a patch, via any means!

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 3.50
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: