dynamically load getauxval so as to support older android devices

This commit is contained in:
Alexandre Janniaux 2018-03-08 17:43:34 +01:00 committed by Arvid Norberg
parent 5c1b65e9b8
commit f8889858f6
5 changed files with 45 additions and 4 deletions

View File

@ -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")

View File

@ -88,6 +88,11 @@ rule linking ( properties * )
}
}
if <target-os>android in $(properties)
{
result += <library>dl ;
}
if <target-os>beos in $(properties)
{
result += <library>netkit <library>gcc ;

View File

@ -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

View File

@ -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

View File

@ -55,8 +55,21 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#if TORRENT_HAS_ARM && TORRENT_HAS_AUXV
#if defined(TORRENT_ANDROID) && TORRENT_HAS_AUXV
#include <dlfcn.h>
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<getauxval_t>(dlsym(RTLD_DEFAULT, "getauxval"));
if (pf_getauxval == nullptr)
return 0;
return pf_getauxval(type);
}
}
#elif TORRENT_HAS_ARM && TORRENT_HAS_AUXV
#include <sys/auxv.h>
#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;