This fixes the build of spotify-player on aarch64 by pulling in the
last C version of cpu_aarch64_openbsd before BoringSSL switched to C++
which provides the missing OPENSSL_cpuid_setup() symbol.

This is needed since the #ifdef maze ends up defining NEED_CPUID for
OpenBSD/aarch64, but for some reason this file was lost in aws-lc.

There are many things not to like about this, but it might be preferable
to disabling assembly altogether on aarch64 (which I haven't really
looked into).

A runtime test by a spotify user would be nice.

The same sort of gymnastics should work for ncspot as well. I haven't
tried.

Index: Makefile
===================================================================
RCS file: /cvs/ports/audio/spotify-player/Makefile,v
diff -u -p -r1.3 Makefile
--- Makefile    3 Feb 2025 05:37:26 -0000       1.3
+++ Makefile    5 Feb 2025 12:28:23 -0000
@@ -10,6 +10,7 @@ COMMENT =             Spotify TUI client
 GH_ACCOUNT =           aome510
 GH_PROJECT =           spotify-player
 GH_TAGNAME =           v0.20.4
+REVISION =             0
 
 CATEGORIES =           audio
 
@@ -42,6 +43,9 @@ MODCARGO_FEATURES =   portaudio-backend me
 MODCARGO_INSTALL_TARGET_PATHS =        ./spotify_player
 
 .include "crates.inc"
+
+post-patch:
+       cp ${FILESDIR}/cpu_aarch64_openbsd.c 
${MODCARGO_VENDOR_DIR}/aws-lc-sys-0.23.1/aws-lc/crypto/fipsmodule/cpucap/
 
 post-install:
        ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/spotify-player
Index: files/cpu_aarch64_openbsd.c
===================================================================
RCS file: files/cpu_aarch64_openbsd.c
diff -N files/cpu_aarch64_openbsd.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ files/cpu_aarch64_openbsd.c 5 Feb 2025 12:28:23 -0000
@@ -0,0 +1,61 @@
+/* Copyright (c) 2022, Robert Nagy <robert.n...@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+#include <openssl/cpu.h>
+
+#if defined(OPENSSL_AARCH64) && defined(OPENSSL_OPENBSD) && \
+    !defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
+
+#include <machine/armreg.h>
+#include <machine/cpu.h>
+#include <sys/sysctl.h>
+
+#include <openssl/arm_arch.h>
+
+#include "internal.h"
+
+
+void OPENSSL_cpuid_setup(void) {
+  int isar0_mib[] = {CTL_MACHDEP, CPU_ID_AA64ISAR0};
+  uint64_t cpu_id = 0;
+  size_t len = sizeof(cpu_id);
+
+  if (sysctl(isar0_mib, 2, &cpu_id, &len, NULL, 0) < 0) {
+    return;
+  }
+
+  OPENSSL_armcap_P |= ARMV7_NEON;
+
+  if (ID_AA64ISAR0_AES(cpu_id) >= ID_AA64ISAR0_AES_BASE) {
+    OPENSSL_armcap_P |= ARMV8_AES;
+  }
+
+  if (ID_AA64ISAR0_AES(cpu_id) >= ID_AA64ISAR0_AES_PMULL) {
+    OPENSSL_armcap_P |= ARMV8_PMULL;
+  }
+
+  if (ID_AA64ISAR0_SHA1(cpu_id) >= ID_AA64ISAR0_SHA1_BASE) {
+    OPENSSL_armcap_P |= ARMV8_SHA1;
+  }
+
+  if (ID_AA64ISAR0_SHA2(cpu_id) >= ID_AA64ISAR0_SHA2_BASE) {
+    OPENSSL_armcap_P |= ARMV8_SHA256;
+  }
+
+  if (ID_AA64ISAR0_SHA2(cpu_id) >= ID_AA64ISAR0_SHA2_512) {
+    OPENSSL_armcap_P |= ARMV8_SHA512;
+  }
+}
+
+#endif  // OPENSSL_AARCH64 && OPENSSL_OPENBSD && !OPENSSL_STATIC_ARMCAP
Index: 
patches/patch-modcargo-crates_aws-lc-sys-0_23_1_aws-lc_crypto_fipsmodule_bcm_c
===================================================================
RCS file: 
patches/patch-modcargo-crates_aws-lc-sys-0_23_1_aws-lc_crypto_fipsmodule_bcm_c
diff -N 
patches/patch-modcargo-crates_aws-lc-sys-0_23_1_aws-lc_crypto_fipsmodule_bcm_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ 
patches/patch-modcargo-crates_aws-lc-sys-0_23_1_aws-lc_crypto_fipsmodule_bcm_c  
    5 Feb 2025 12:28:23 -0000
@@ -0,0 +1,21 @@
+Index: modcargo-crates/aws-lc-sys-0.23.1/aws-lc/crypto/fipsmodule/bcm.c
+--- modcargo-crates/aws-lc-sys-0.23.1/aws-lc/crypto/fipsmodule/bcm.c.orig
++++ modcargo-crates/aws-lc-sys-0.23.1/aws-lc/crypto/fipsmodule/bcm.c
+@@ -15,6 +15,9 @@
+ #if !defined(_GNU_SOURCE)
+ #define _GNU_SOURCE  // needed for syscall() on Linux.
+ #endif
++#if !defined(_BSD_SOURCE)
++#define _BSD_SOURCE  // needed for arc4random_buf() and bsd-style u_foo types
++#endif
+ 
+ #include <openssl/crypto.h>
+ 
+@@ -77,6 +80,7 @@
+ #include "cpucap/cpu_aarch64_apple.c"
+ #include "cpucap/cpu_aarch64_fuchsia.c"
+ #include "cpucap/cpu_aarch64_linux.c"
++#include "cpucap/cpu_aarch64_openbsd.c"
+ #include "cpucap/cpu_aarch64_win.c"
+ #include "cpucap/cpu_arm_freebsd.c"
+ #include "cpucap/cpu_arm_linux.c"

Reply via email to