From f8889858f63d7b78a6af0bb4dd8f8c479bb3b39f Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Thu, 8 Mar 2018 17:43:34 +0100 Subject: [PATCH] dynamically load getauxval so as to support older android devices --- CMakeLists.txt | 4 ++++ Jamfile | 5 +++++ configure.ac | 15 +++++++++++++++ src/Makefile.am | 4 ++++ src/cpuid.cpp | 21 +++++++++++++++++---- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 782ef0da7..79eb5b59b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -619,6 +619,10 @@ if (WIN32) endif() endif() +if(ANDROID) + target_link_libraries(torrent-rasterbar dl) +endif() + if(APPLE) # for ip_notifier target_link_libraries(torrent-rasterbar "-framework CoreFoundation" "-framework SystemConfiguration") diff --git a/Jamfile b/Jamfile index b43520eb0..c5bcf1d01 100644 --- a/Jamfile +++ b/Jamfile @@ -88,6 +88,11 @@ rule linking ( properties * ) } } + if android in $(properties) + { + result += dl ; + } + if beos in $(properties) { result += netkit gcc ; diff --git a/configure.ac b/configure.ac index 4d5ba4b3e..39ba0207b 100644 --- a/configure.ac +++ b/configure.ac @@ -89,6 +89,21 @@ AS_ECHO "Initializing Libtool:" LT_PREREQ([2.2.6]) LT_INIT +AS_IF([test "$SYS" = linux],[ + AC_PREPROC_IFELSE([AC_LANG_PROGRAM( + [[#ifndef __ANDROID__ + # error Not Android + #endif + ]],[[;]]) + ],[ + HAVE_ANDROID="1" + AC_MSG_RESULT([yes]) + ],[ + AC_MSG_RESULT([no]) + ]) +]) +AM_CONDITIONAL(HAVE_ANDROID, test "${HAVE_ANDROID}" = "1") + ############################################################################### # Checking for needed base libraries diff --git a/src/Makefile.am b/src/Makefile.am index dd20cbc32..7062f5a1d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -174,6 +174,10 @@ libtorrent_rasterbar_la_SOURCES = \ libtorrent_rasterbar_la_LDFLAGS = -version-info $(INTERFACE_VERSION_INFO) libtorrent_rasterbar_la_LIBADD = @OPENSSL_LIBS@ +if HAVE_ANDROID +libtorrent_rasterbar_la_LIBADD += -ldl +endif + AM_CPPFLAGS = -DTORRENT_BUILDING_LIBRARY -I$(top_srcdir)/include -I$(top_srcdir)/ed25519/src @DEBUGFLAGS@ @OPENSSL_INCLUDES@ AM_CFLAGS = -I$(top_srcdir)/ed25519/src -std=c99 diff --git a/src/cpuid.cpp b/src/cpuid.cpp index 243c0850f..e5cf3b3a1 100644 --- a/src/cpuid.cpp +++ b/src/cpuid.cpp @@ -55,8 +55,21 @@ POSSIBILITY OF SUCH DAMAGE. #endif -#if TORRENT_HAS_ARM && TORRENT_HAS_AUXV +#if defined(TORRENT_ANDROID) && TORRENT_HAS_AUXV +#include +namespace { +unsigned long int helper_getauxval(unsigned long int type) +{ + using getauxval_t = unsigned long int(*)(unsigned long int); + getauxval_t pf_getauxval = reinterpret_cast(dlsym(RTLD_DEFAULT, "getauxval")); + if (pf_getauxval == nullptr) + return 0; + return pf_getauxval(type); +} +} +#elif TORRENT_HAS_ARM && TORRENT_HAS_AUXV #include +#define helper_getauxval getauxval #endif namespace libtorrent { namespace aux { @@ -107,7 +120,7 @@ namespace libtorrent { namespace aux { #if TORRENT_HAS_ARM_NEON && TORRENT_HAS_AUXV #if defined __arm__ //return (getauxval(AT_HWCAP) & HWCAP_NEON); - return (getauxval(16) & (1 << 12)); + return (helper_getauxval(16) & (1 << 12)); #elif defined __aarch64__ //return (getauxval(AT_HWCAP) & HWCAP_ASIMD); //return (getauxval(16) & (1 << 1)); @@ -126,10 +139,10 @@ namespace libtorrent { namespace aux { return true; #elif defined __arm__ //return (getauxval(AT_HWCAP2) & HWCAP2_CRC32); - return (getauxval(26) & (1 << 4)); + return (helper_getauxval(26) & (1 << 4)); #elif defined __aarch64__ //return (getauxval(AT_HWCAP) & HWCAP_CRC32); - return (getauxval(16) & (1 << 7)); + return (helper_getauxval(16) & (1 << 7)); #endif #else return false;