git: 3951881016b7 - main - sysutils/cpuid2cpuflags: make the port build and work on ARM

From: Alexey Dokuchaev <danfe_at_FreeBSD.org>
Date: Tue, 17 May 2022 07:53:43 UTC
The branch main has been updated by danfe:

URL: https://cgit.FreeBSD.org/ports/commit/?id=3951881016b76468ed9e558b26e23ab3d2a4d3db

commit 3951881016b76468ed9e558b26e23ab3d2a4d3db
Author:     Alexey Dokuchaev <danfe@FreeBSD.org>
AuthorDate: 2022-05-17 07:53:14 +0000
Commit:     Alexey Dokuchaev <danfe@FreeBSD.org>
CommitDate: 2022-05-17 07:53:14 +0000

    sysutils/cpuid2cpuflags: make the port build and work on ARM
    
    - Replace getauxval(3), a non-standard glibc extension, with
      our native elf_aux_info(3) call
    - Return features supported by the specific machine processor
      architecture (uname -p) rather than the hardware platform
      (uname -m), because the latter is too vague on FreeBSD/arm
    
    PR:             258445
    Reported by:    pkg-fallout
---
 sysutils/cpuid2cpuflags/files/patch-src_hwcap.c | 48 +++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/sysutils/cpuid2cpuflags/files/patch-src_hwcap.c b/sysutils/cpuid2cpuflags/files/patch-src_hwcap.c
new file mode 100644
index 000000000000..89c88e4f92b8
--- /dev/null
+++ b/sysutils/cpuid2cpuflags/files/patch-src_hwcap.c
@@ -0,0 +1,48 @@
+--- src/hwcap.c.orig	2020-07-13 17:14:55 UTC
++++ src/hwcap.c
+@@ -14,13 +14,19 @@
+ #ifdef HAVE_SYS_AUXV_H
+ #	include <sys/auxv.h>
+ #endif
++#ifdef __FreeBSD__
++#include <sys/sysctl.h>
++#else
+ #include <sys/utsname.h>
+-
+-#ifndef __linux__
+-#	error "Platform not supported (only Linux supported at the moment)"
+ #endif
++
+ #ifndef HAVE_GETAUXVAL
+-#	error "Platform not supported (no getauxval())"
++static unsigned long getauxval(int aux)
++{
++	unsigned long auxval = 0;
++	elf_aux_info(aux, &auxval, sizeof(auxval));
++	return auxval;
++}
+ #endif
+ 
+ #include "hwcap.h"
+@@ -53,9 +59,21 @@ unsigned long get_hwcap2()
+  */
+ char* get_uname_machine()
+ {
++#ifdef __FreeBSD__
++	/**
++	 * Contrary to this code expectation, on FreeBSD/arm, `uname -m'
++	 * is always `arm', so we return more unique `uname -p' instead.
++	 */
++	int mib[] = { CTL_HW, HW_MACHINE_ARCH };
++	static char buf[48];
++	size_t len = sizeof(buf);
++	if (sysctl(mib, 2, &buf, &len, NULL, 0) == 0)
++		return buf;
++#else
+ 	static struct utsname uname_res;
+ 	if (uname(&uname_res) != -1)
+ 		return uname_res.machine;
++#endif
+ 	else
+ 		return NULL;
+ }