git: 379597b79b3a - main - databases/rocksdb: Fix build on aarch64.

From: Mikael Urankar <mikael_at_FreeBSD.org>
Date: Sun, 10 Oct 2021 17:00:08 UTC
The branch main has been updated by mikael:

URL: https://cgit.FreeBSD.org/ports/commit/?id=379597b79b3a22dbd1995440c69e003a7ae17a35

commit 379597b79b3a22dbd1995440c69e003a7ae17a35
Author:     Mikael Urankar <mikael@FreeBSD.org>
AuthorDate: 2021-10-10 16:52:59 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2021-10-10 17:00:06 +0000

    databases/rocksdb: Fix build on aarch64.
    
    Approved by:    portmgr (build fix blanket)
---
 databases/rocksdb/files/patch-CMakeLists.txt       | 14 ++++++++++
 .../files/patch-build_tools-build_detect_platform  | 11 ++++++++
 databases/rocksdb/files/patch-util_crc32c.cc       | 29 ++++++++++++++++++++-
 .../rocksdb/files/patch-util_crc32c__arm64.cc      | 30 ++++++++++++++++++++++
 4 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/databases/rocksdb/files/patch-CMakeLists.txt b/databases/rocksdb/files/patch-CMakeLists.txt
new file mode 100644
index 000000000000..eeefd6074532
--- /dev/null
+++ b/databases/rocksdb/files/patch-CMakeLists.txt
@@ -0,0 +1,14 @@
+--- CMakeLists.txt.orig	2021-10-10 13:48:40 UTC
++++ CMakeLists.txt
+@@ -521,6 +521,11 @@ if(HAVE_AUXV_GETAUXVAL)
+   add_definitions(-DROCKSDB_AUXV_GETAUXVAL_PRESENT)
+ endif()
+ 
++check_cxx_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
++if(HAVE_ELF_AUX_INFO)
++  add_definitions(-DROCKSDB_AUXV_GETAUXVAL_PRESENT)
++endif()
++
+ include_directories(${PROJECT_SOURCE_DIR})
+ include_directories(${PROJECT_SOURCE_DIR}/include)
+ if(WITH_FOLLY_DISTRIBUTED_MUTEX)
diff --git a/databases/rocksdb/files/patch-build_tools-build_detect_platform b/databases/rocksdb/files/patch-build_tools-build_detect_platform
index b685a2dfc33a..1984674f19ec 100644
--- a/databases/rocksdb/files/patch-build_tools-build_detect_platform
+++ b/databases/rocksdb/files/patch-build_tools-build_detect_platform
@@ -100,3 +100,14 @@ Remove -fno-builtin-memcmp and -ltcmalloc
          fi
      fi
  
+@@ -558,8 +558,8 @@ EOF
+ fi
+ 
+ # TODO(tec): Fix -Wshorten-64-to-32 errors on FreeBSD and enable the warning.
+-# -Wshorten-64-to-32 breaks compilation on FreeBSD i386
+-if ! [ "$TARGET_OS" = FreeBSD -a "$TARGET_ARCHITECTURE" = i386 ]; then
++# -Wshorten-64-to-32 breaks compilation on FreeBSD i386 and aarch64
++if ! { [ "$TARGET_OS" = FreeBSD ] && [ "$TARGET_ARCHITECTURE" = i386 -o "$TARGET_ARCHITECTURE" = "arm64" ]; }; then
+   # Test whether -Wshorten-64-to-32 is available
+   $CXX $CFLAGS -x c++ - -o /dev/null -Wshorten-64-to-32 2>/dev/null  <<EOF
+     int main() {}
diff --git a/databases/rocksdb/files/patch-util_crc32c.cc b/databases/rocksdb/files/patch-util_crc32c.cc
index 71f38e5898ca..a57cbf2803fe 100644
--- a/databases/rocksdb/files/patch-util_crc32c.cc
+++ b/databases/rocksdb/files/patch-util_crc32c.cc
@@ -1,4 +1,4 @@
---- util/crc32c.cc.orig	2020-12-01 23:49:39 UTC
+--- util/crc32c.cc.orig	2021-10-10 17:19:37 UTC
 +++ util/crc32c.cc
 @@ -463,6 +463,21 @@ static int arch_ppc_probe(void) {
  
@@ -22,3 +22,30 @@
  #endif  // __linux__
  
  static bool isAltiVec() {
+@@ -474,7 +489,7 @@ static bool isAltiVec() {
+ }
+ #endif
+ 
+-#if defined(__linux__) && defined(HAVE_ARM64_CRC)
++#if (defined(__FreeBSD__) || defined(__linux__)) && defined(HAVE_ARM64_CRC)
+ uint32_t ExtendARMImpl(uint32_t crc, const char *buf, size_t size) {
+   return crc32c_arm64(crc, (const unsigned char *)buf, size);
+ }
+@@ -494,7 +509,7 @@ std::string IsFastCrc32Supported() {
+   has_fast_crc = false;
+   arch = "PPC";
+ #endif
+-#elif defined(__linux__) && defined(HAVE_ARM64_CRC)
++#elif (defined(__FreeBSD__) || defined(__linux__)) && defined(HAVE_ARM64_CRC)
+   if (crc32c_runtime_check()) {
+     has_fast_crc = true;
+     arch = "Arm64";
+@@ -1226,7 +1241,7 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, si
+ static inline Function Choose_Extend() {
+ #ifdef HAVE_POWER8
+   return isAltiVec() ? ExtendPPCImpl : ExtendImpl<Slow_CRC32>;
+-#elif defined(__linux__) && defined(HAVE_ARM64_CRC)
++#elif (defined(__FreeBSD__) || defined(__linux__)) && defined(HAVE_ARM64_CRC)
+   if(crc32c_runtime_check()) {
+     return ExtendARMImpl;
+   } else {
diff --git a/databases/rocksdb/files/patch-util_crc32c__arm64.cc b/databases/rocksdb/files/patch-util_crc32c__arm64.cc
new file mode 100644
index 000000000000..bc2a2a775b6b
--- /dev/null
+++ b/databases/rocksdb/files/patch-util_crc32c__arm64.cc
@@ -0,0 +1,30 @@
+--- util/crc32c_arm64.cc.orig	2021-10-10 13:50:13 UTC
++++ util/crc32c_arm64.cc
+@@ -5,9 +5,11 @@
+ 
+ #include "util/crc32c_arm64.h"
+ 
+-#if defined(__linux__) && defined(HAVE_ARM64_CRC)
++#if (defined(__FreeBSD__) || defined(__linux__)) && defined(HAVE_ARM64_CRC)
+ 
++#if !defined(__FreeBSD__)
+ #include <asm/hwcap.h>
++#endif
+ #ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT
+ #include <sys/auxv.h>
+ #endif
+@@ -37,7 +39,14 @@
+ 
+ uint32_t crc32c_runtime_check(void) {
+ #ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT
++#if defined(__FreeBSD__)
++  uint64_t auxv;
++  int result = elf_aux_info(AT_HWCAP, &auxv, sizeof auxv);
++  if (result != 0)
++    return 0;
++#else
+   uint64_t auxv = getauxval(AT_HWCAP);
++#endif
+   return (auxv & HWCAP_CRC32) != 0;
+ #else
+   return 0;