diff --git a/Makefile.in b/Makefile.in index 4668b8a6..a12ade44 100644 --- a/Makefile.in +++ b/Makefile.in @@ -60,11 +60,12 @@ DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ auto/missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ - $(top_srcdir)/m4/inet_ntop.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/polarssl.m4 \ - $(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/ax_tls.m4 $(top_srcdir)/m4/inet_ntop.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/polarssl.m4 $(top_srcdir)/libev/libev.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ diff --git a/aclocal.m4 b/aclocal.m4 index 370bd147..e9136d93 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1163,6 +1163,7 @@ AC_SUBST([am__untar]) ]) # _AM_PROG_TAR m4_include([m4/acx_pthread.m4]) +m4_include([m4/ax_tls.m4]) m4_include([m4/inet_ntop.m4]) m4_include([m4/libtool.m4]) m4_include([m4/ltoptions.m4]) diff --git a/config.h.in b/config.h.in index 9d86b1cc..05098ecb 100644 --- a/config.h.in +++ b/config.h.in @@ -298,6 +298,9 @@ /* Define to 1 if you can safely include both and . */ #undef TIME_WITH_SYS_TIME +/* If the compiler supports a TLS storage class define it to that here */ +#undef TLS + /* Use Apple CommonCrypto library */ #undef USE_CRYPTO_APPLECC diff --git a/configure b/configure index 1d81488e..2d20a848 100755 --- a/configure +++ b/configure @@ -12851,6 +12851,60 @@ case $host in ;; esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread local storage (TLS) class" >&5 +$as_echo_n "checking for thread local storage (TLS) class... " >&6; } + if ${ac_cv_tls+:} false; then : + $as_echo_n "(cached) " >&6 +else + for ax_tls_keyword in __thread '__declspec(thread)' none; do + case $ax_tls_keyword in #( + none) : + ac_cv_tls=none ; break ;; #( + *) : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + static void + foo(void) { + static $ax_tls_keyword int bar; + exit(1); + } +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_tls=$ax_tls_keyword ; break +else + ac_cv_tls=none + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; +esac + done + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_tls" >&5 +$as_echo "$ac_cv_tls" >&6; } + + if test "$ac_cv_tls" != "none"; then : + +cat >>confdefs.h <<_ACEOF +#define TLS $ac_cv_tls +_ACEOF + + : +else + : +fi + + case "${with_crypto_library}" in openssl) diff --git a/configure.ac b/configure.ac index 2451466d..07f6654a 100755 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,9 @@ case $host in ;; esac +dnl Checks for TLS +AX_TLS([:], [:]) + dnl Checks for crypto library case "${with_crypto_library}" in openssl) diff --git a/libcork/Makefile.in b/libcork/Makefile.in index 73c1fea5..596876ad 100644 --- a/libcork/Makefile.in +++ b/libcork/Makefile.in @@ -73,11 +73,12 @@ subdir = libcork DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in COPYING ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ - $(top_srcdir)/m4/inet_ntop.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/polarssl.m4 \ - $(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/ax_tls.m4 $(top_srcdir)/m4/inet_ntop.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/polarssl.m4 $(top_srcdir)/libev/libev.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d diff --git a/libcork/include/libcork/config/gcc.h b/libcork/include/libcork/config/gcc.h index d7bbffac..debcbbda 100644 --- a/libcork/include/libcork/config/gcc.h +++ b/libcork/include/libcork/config/gcc.h @@ -75,10 +75,10 @@ #endif /* Thread-local storage has been available since GCC 3.3, but not on Mac - * OS X. */ + * OS X. Also disable TLS for uClibc*/ #if !(defined(__APPLE__) && defined(__MACH__)) -#if CORK_CONFIG_GCC_VERSION >= 30300 +#if CORK_CONFIG_GCC_VERSION >= 30300 && defined(TLS) #define CORK_CONFIG_HAVE_THREAD_STORAGE_CLASS 1 #else #define CORK_CONFIG_HAVE_THREAD_STORAGE_CLASS 0 diff --git a/libev/Makefile.in b/libev/Makefile.in index 1410b1f9..c30edb91 100644 --- a/libev/Makefile.in +++ b/libev/Makefile.in @@ -57,11 +57,12 @@ DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ - $(top_srcdir)/m4/inet_ntop.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/polarssl.m4 \ - $(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/ax_tls.m4 $(top_srcdir)/m4/inet_ntop.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/polarssl.m4 $(top_srcdir)/libev/libev.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d diff --git a/libipset/Makefile.in b/libipset/Makefile.in index 1ff22d1c..4fc2709a 100644 --- a/libipset/Makefile.in +++ b/libipset/Makefile.in @@ -73,11 +73,12 @@ subdir = libipset DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ - $(top_srcdir)/m4/inet_ntop.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/polarssl.m4 \ - $(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/ax_tls.m4 $(top_srcdir)/m4/inet_ntop.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/polarssl.m4 $(top_srcdir)/libev/libev.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d diff --git a/libudns/Makefile.in b/libudns/Makefile.in index ef61149d..da14515d 100644 --- a/libudns/Makefile.in +++ b/libudns/Makefile.in @@ -73,11 +73,12 @@ subdir = libudns DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in NEWS TODO ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ - $(top_srcdir)/m4/inet_ntop.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/polarssl.m4 \ - $(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/ax_tls.m4 $(top_srcdir)/m4/inet_ntop.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/polarssl.m4 $(top_srcdir)/libev/libev.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d diff --git a/m4/ax_tls.m4 b/m4/ax_tls.m4 new file mode 100644 index 00000000..809b761a --- /dev/null +++ b/m4/ax_tls.m4 @@ -0,0 +1,74 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_tls.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_TLS([action-if-found], [action-if-not-found]) +# +# DESCRIPTION +# +# Provides a test for the compiler support of thread local storage (TLS) +# extensions. Defines TLS if it is found. Currently knows about GCC/ICC +# and MSVC. I think SunPro uses the same as GCC, and Borland apparently +# supports either. +# +# LICENSE +# +# Copyright (c) 2008 Alan Woodland +# Copyright (c) 2010 Diego Elio Petteno` +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 11 + +AC_DEFUN([AX_TLS], [ + AC_MSG_CHECKING([for thread local storage (TLS) class]) + AC_CACHE_VAL([ac_cv_tls], + [for ax_tls_keyword in __thread '__declspec(thread)' none; do + AS_CASE([$ax_tls_keyword], + [none], [ac_cv_tls=none ; break], + [AC_TRY_COMPILE( + [#include + static void + foo(void) { + static ] $ax_tls_keyword [ int bar; + exit(1); + }], + [], + [ac_cv_tls=$ax_tls_keyword ; break], + ac_cv_tls=none + )]) + done + ]) + AC_MSG_RESULT([$ac_cv_tls]) + + AS_IF([test "$ac_cv_tls" != "none"], + [AC_DEFINE_UNQUOTED([TLS],[$ac_cv_tls],[If the compiler supports a TLS storage class define it to that here]) + m4_ifnblank([$1],[$1])], + [m4_ifnblank([$2],[$2])]) +]) diff --git a/openwrt/Makefile b/openwrt/Makefile index 6f28bc6c..5b2ee9f4 100644 --- a/openwrt/Makefile +++ b/openwrt/Makefile @@ -28,14 +28,14 @@ define Package/shadowsocks-libev $(call Package/shadowsocks-libev/Default) TITLE+= (OpenSSL) VARIANT:=openssl - DEPENDS:=+libopenssl + DEPENDS:=+libopenssl +libpthread endef define Package/shadowsocks-libev-polarssl $(call Package/shadowsocks-libev/Default) TITLE+= (PolarSSL) VARIANT:=polarssl - DEPENDS:=+libpolarssl + DEPENDS:=+libpolarssl +libpthread endef define Package/shadowsocks-libev/description diff --git a/src/Makefile.am b/src/Makefile.am index 666b23de..73d70936 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,7 @@ VERSION_INFO = 1:0:0 AM_CFLAGS = -g -O2 -Wall -Werror -Wno-deprecated-declarations -fno-strict-aliasing -std=gnu99 -D_GNU_SOURCE +AM_CFLAGS += $(PTHREAD_CFLAGS) AM_CFLAGS += -I$(top_srcdir)/libev AM_CFLAGS += -I$(top_srcdir)/libudns AM_CFLAGS += -I$(top_srcdir)/libipset/include @@ -9,7 +10,8 @@ AM_CFLAGS += -I$(top_srcdir)/libsodium/src/libsodium/include AM_LDFLAGS = -static -SS_COMMON_LIBS = $(top_builddir)/libev/libev.la \ +SS_COMMON_LIBS = $(PTHREAD_LIBS) \ + $(top_builddir)/libev/libev.la \ $(top_builddir)/libipset/libipset.la \ $(top_builddir)/libcork/libcork.la \ $(top_builddir)/libsodium/src/libsodium/libsodium.la \ diff --git a/src/Makefile.in b/src/Makefile.in index c0ddb6f2..545e103a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -64,11 +64,12 @@ DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ - $(top_srcdir)/m4/inet_ntop.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/polarssl.m4 \ - $(top_srcdir)/libev/libev.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/ax_tls.m4 $(top_srcdir)/m4/inet_ntop.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/polarssl.m4 $(top_srcdir)/libev/libev.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -106,7 +107,8 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ "$(DESTDIR)$(includedir)" LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = -am__DEPENDENCIES_2 = $(top_builddir)/libev/libev.la \ +am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) \ + $(top_builddir)/libev/libev.la \ $(top_builddir)/libipset/libipset.la \ $(top_builddir)/libcork/libcork.la \ $(top_builddir)/libsodium/src/libsodium/libsodium.la \ @@ -355,12 +357,13 @@ top_srcdir = @top_srcdir@ VERSION_INFO = 1:0:0 AM_CFLAGS = -g -O2 -Wall -Werror -Wno-deprecated-declarations \ -fno-strict-aliasing -std=gnu99 -D_GNU_SOURCE \ - -I$(top_srcdir)/libev -I$(top_srcdir)/libudns \ - -I$(top_srcdir)/libipset/include \ + $(PTHREAD_CFLAGS) -I$(top_srcdir)/libev \ + -I$(top_srcdir)/libudns -I$(top_srcdir)/libipset/include \ -I$(top_srcdir)/libcork/include \ -I$(top_srcdir)/libsodium/src/libsodium/include AM_LDFLAGS = -static -SS_COMMON_LIBS = $(top_builddir)/libev/libev.la \ +SS_COMMON_LIBS = $(PTHREAD_LIBS) \ + $(top_builddir)/libev/libev.la \ $(top_builddir)/libipset/libipset.la \ $(top_builddir)/libcork/libcork.la \ $(top_builddir)/libsodium/src/libsodium/libsodium.la \