From 33e8a2685ad8a769a5e8e295a3b14dac2e50b236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9B=D1=83=D1=85?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Tue, 12 Nov 2024 11:55:26 +0300 Subject: [PATCH] Correct cpu features detection during cross-compiation Closes https://github.com/pjsip/pjproject/issues/4150 --- aclocal.m4 | 68 +++++++++++++++++++++++++++++++++ aconfigure | 102 ++++++++++++++++++++++++++++++++++++++++++++++---- aconfigure.ac | 21 +++++++++-- 3 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 aclocal.m4 diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 0000000000..395457bb64 --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,68 @@ +# generated automatically by aclocal 1.16.5 -*- Autoconf -*- + +# Copyright (C) 1996-2021 Free Software Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS + diff --git a/aconfigure b/aconfigure index 47fce480ee..e3b9f74133 100755 --- a/aconfigure +++ b/aconfigure @@ -4505,11 +4505,11 @@ if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5 printf %s "checking for $CXX option to enable C++11 features... " >&6; } -if test ${ac_cv_prog_cxx_11+y} +if test ${ac_cv_prog_cxx_cxx11+y} then : printf %s "(cached) " >&6 else $as_nop - ac_cv_prog_cxx_11=no + ac_cv_prog_cxx_cxx11=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -4551,11 +4551,11 @@ if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5 printf %s "checking for $CXX option to enable C++98 features... " >&6; } -if test ${ac_cv_prog_cxx_98+y} +if test ${ac_cv_prog_cxx_cxx98+y} then : printf %s "(cached) " >&6 else $as_nop - ac_cv_prog_cxx_98=no + ac_cv_prog_cxx_cxx98=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -10270,6 +10270,88 @@ printf "%s\n" "Checking if libyuv is disabled...no" >&6; } fi +case $target_cpu in + arm*) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mfpu=neon" >&5 +printf %s "checking whether C compiler accepts -mfpu=neon... " >&6; } +if test ${ax_cv_check_cflags___mfpu_neon+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -mfpu=neon" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ax_cv_check_cflags___mfpu_neon=yes +else $as_nop + ax_cv_check_cflags___mfpu_neon=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS=$ax_check_save_flags +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___mfpu_neon" >&5 +printf "%s\n" "$ax_cv_check_cflags___mfpu_neon" >&6; } +if test "x$ax_cv_check_cflags___mfpu_neon" = xyes +then : + ax_cv_support_neon_ext=yes +else $as_nop + : +fi + + ;; + aarch64*) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -march=armv8-a+simd" >&5 +printf %s "checking whether C compiler accepts -march=armv8-a+simd... " >&6; } +if test ${ax_cv_check_cflags___march_armv8_apsimd+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -march=armv8-a+simd" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ax_cv_check_cflags___march_armv8_apsimd=yes +else $as_nop + ax_cv_check_cflags___march_armv8_apsimd=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS=$ax_check_save_flags +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___march_armv8_apsimd" >&5 +printf "%s\n" "$ax_cv_check_cflags___march_armv8_apsimd" >&6; } +if test "x$ax_cv_check_cflags___march_armv8_apsimd" = xyes +then : + ax_cv_support_neon_ext=yes +else $as_nop + : +fi + + ;; +esac @@ -10338,10 +10420,14 @@ printf "%s\n" "Checking if libwebrtc is disabled...no" >&6; } ;; *win32* | *w32* | *darwin* | *linux*) case $target in - armv7l*gnueabihf) - ac_webrtc_instset=neon - ac_webrtc_cflags="-DWEBRTC_ARCH_ARM_V7 -mfloat-abi=hard -mfpu=neon" - ;; + armv*gnueabihf) + if test "x$ax_cv_support_neon_ext" = "xyes"; then + ac_webrtc_instset=neon + ac_webrtc_cflags="-DWEBRTC_ARCH_ARM_V7 -mfloat-abi=hard -mfpu=neon" + else + ac_webrtc_instset=generic + fi + ;; arm-apple-darwin* | aarch64*) ac_webrtc_instset=neon ac_webrtc_cflags="-DWEBRTC_ARCH_ARM64" diff --git a/aconfigure.ac b/aconfigure.ac index df91fbe0e2..bd8a5f655f 100644 --- a/aconfigure.ac +++ b/aconfigure.ac @@ -2415,6 +2415,15 @@ AC_ARG_ENABLE(libyuv, fi], AC_MSG_RESULT([Checking if libyuv is disabled...no])) +dnl proper neon detector +case $target_cpu in + arm*) + AX_CHECK_COMPILE_FLAG(-mfpu=neon, ax_cv_support_neon_ext=yes, []) + ;; + aarch64*) + AX_CHECK_COMPILE_FLAG(-march=armv8-a+simd, ax_cv_support_neon_ext=yes, []) + ;; +esac dnl # Include webrtc AC_SUBST(ac_no_webrtc) @@ -2480,10 +2489,14 @@ AC_ARG_ENABLE(libwebrtc, ;; *win32* | *w32* | *darwin* | *linux*) case $target in - armv7l*gnueabihf) - ac_webrtc_instset=neon - ac_webrtc_cflags="-DWEBRTC_ARCH_ARM_V7 -mfloat-abi=hard -mfpu=neon" - ;; + armv*gnueabihf) + if test "x$ax_cv_support_neon_ext" = "xyes"; then + ac_webrtc_instset=neon + ac_webrtc_cflags="-DWEBRTC_ARCH_ARM_V7 -mfloat-abi=hard -mfpu=neon" + else + ac_webrtc_instset=generic + fi + ;; arm-apple-darwin* | aarch64*) ac_webrtc_instset=neon ac_webrtc_cflags="-DWEBRTC_ARCH_ARM64"