From: Vadim Zeitlin Date: Sun, 17 Jun 2012 21:34:47 +0000 (+0000) Subject: Add wxUSE_COMPILER_TLS to allow disabling compiler TLS support. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b33e9f4031e64e957dcb873bf5e7c9a3b08d0c0d?hp=233f786e8e6abfe1f5fca6209c63dc12764d6887 Add wxUSE_COMPILER_TLS to allow disabling compiler TLS support. Compiler TLS support is broken under Win32/MSVC when used for a code which is part of a dynamically loaded DLL, so allow disabling it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71792 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/configure b/configure index 80f2f30f3a..a629c2ec3e 100755 --- a/configure +++ b/configure @@ -32030,7 +32030,7 @@ EOF $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } ; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } ax_gcc_version_option=yes @@ -32038,7 +32038,7 @@ $as_echo "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } ax_gcc_version_option=no @@ -32509,6 +32509,9 @@ done fi +$as_echo "#define wxUSE_COMPILER_TLS 1" >>confdefs.h + + if test "$wxUSE_THREADS" = "yes"; then $as_echo "#define wxUSE_THREADS 1" >>confdefs.h diff --git a/configure.in b/configure.in index 95a2720ad7..b38d6b7b16 100644 --- a/configure.in +++ b/configure.in @@ -5226,6 +5226,10 @@ dnl AC_CHECK_FUNC(getaddrinfo, AC_DEFINE(HAVE_GETADDRINFO), [ dnl ] dnl ) +dnl This is currently always defined under Unix, there is no reason to ever +dnl disable compiler TLS support there. +AC_DEFINE(wxUSE_COMPILER_TLS) + if test "$wxUSE_THREADS" = "yes"; then AC_DEFINE(wxUSE_THREADS) diff --git a/docs/doxygen/mainpages/const_wxusedef.h b/docs/doxygen/mainpages/const_wxusedef.h index c7be578182..2cbc3639d4 100644 --- a/docs/doxygen/mainpages/const_wxusedef.h +++ b/docs/doxygen/mainpages/const_wxusedef.h @@ -92,6 +92,7 @@ library: @itemdef{wxUSE_COLOURPICKERCTRL, Use wxColourPickerCtrl class.} @itemdef{wxUSE_COMBOBOX, Use wxComboBox class.} @itemdef{wxUSE_COMBOCTRL, Use wxComboCtrl class.} +@itemdef{wxUSE_COMPILER_TLS, Can be set to 0 to prevent using compile thread-specific variables support.} @itemdef{wxUSE_CONFIG, Use wxConfig and related classes.} @itemdef{wxUSE_CONFIG_NATIVE, When enabled use native OS configuration instead of the wxFileConfig class.} @itemdef{wxUSE_CONSOLE_EVENTLOOP, Enable event loop in console programs.} diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index b1c741e43d..467dbdae3b 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -92,6 +92,14 @@ # endif #endif /* wxUSE_ANY */ +#ifndef wxUSE_COMPILER_TLS +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxUSE_COMPILER_TLS must be defined, please read comment near the top of this file." +# else +# define wxUSE_COMPILER_TLS 0 +# endif +#endif /* !defined(wxUSE_COMPILER_TLS) */ + #ifndef wxUSE_CONSOLE_EVENTLOOP # ifdef wxABORT_ON_CONFIG_ERROR # error "wxUSE_CONSOLE_EVENTLOOP must be defined, please read comment near the top of this file." diff --git a/include/wx/gtk/setup0.h b/include/wx/gtk/setup0.h index 2561a19e1b..197862a574 100644 --- a/include/wx/gtk/setup0.h +++ b/include/wx/gtk/setup0.h @@ -267,6 +267,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/motif/setup0.h b/include/wx/motif/setup0.h index a6eab82ee2..ce146a7adf 100644 --- a/include/wx/motif/setup0.h +++ b/include/wx/motif/setup0.h @@ -267,6 +267,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index 22feb8ff63..453a5a0ed7 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -267,6 +267,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/msw/wince/setup.h b/include/wx/msw/wince/setup.h index d91fbf8843..feacc9d617 100644 --- a/include/wx/msw/wince/setup.h +++ b/include/wx/msw/wince/setup.h @@ -267,6 +267,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/os2/setup0.h b/include/wx/os2/setup0.h index 45379059d8..c5522b1f17 100644 --- a/include/wx/os2/setup0.h +++ b/include/wx/os2/setup0.h @@ -267,6 +267,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/osx/setup0.h b/include/wx/osx/setup0.h index 1bc7474fb2..a20acabe4b 100644 --- a/include/wx/osx/setup0.h +++ b/include/wx/osx/setup0.h @@ -268,6 +268,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h index 9b8dade936..712dcca883 100644 --- a/include/wx/setup_inc.h +++ b/include/wx/setup_inc.h @@ -263,6 +263,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/include/wx/tls.h b/include/wx/tls.h index 4fbc287c5c..6886434c00 100644 --- a/include/wx/tls.h +++ b/include/wx/tls.h @@ -22,10 +22,13 @@ #if !wxUSE_THREADS #define wxHAS_COMPILER_TLS #define wxTHREAD_SPECIFIC_DECL +// otherwise try to find the compiler-specific way to handle TLS unless +// explicitly disabled by setting wxUSE_COMPILER_TLS to 0 (it is 1 by default). +#elif wxUSE_COMPILER_TLS // __thread keyword is not supported correctly by MinGW, at least in some // configurations, see http://sourceforge.net/support/tracker.php?aid=2837047 // and when in doubt we prefer to not use it at all. -#elif defined(HAVE___THREAD_KEYWORD) && !defined(__MINGW32__) +#if defined(HAVE___THREAD_KEYWORD) && !defined(__MINGW32__) #define wxHAS_COMPILER_TLS #define wxTHREAD_SPECIFIC_DECL __thread // MSVC has its own version which might be supported by some other Windows @@ -33,7 +36,8 @@ #elif wxCHECK_VISUALC_VERSION(7) #define wxHAS_COMPILER_TLS #define wxTHREAD_SPECIFIC_DECL __declspec(thread) -#endif +#endif // compilers +#endif // wxUSE_COMPILER_TLS // ---------------------------------------------------------------------------- // define wxTLS_TYPE() diff --git a/include/wx/univ/setup0.h b/include/wx/univ/setup0.h index bdac6a94a2..66227d0b77 100644 --- a/include/wx/univ/setup0.h +++ b/include/wx/univ/setup0.h @@ -266,6 +266,17 @@ // Recommended setting: 1 if you want to support multiple languages #define wxUSE_PRINTF_POS_PARAMS 1 +// Enable the use of compiler-specific thread local storage keyword, if any. +// This is used for wxTLS_XXX() macros implementation and normally should use +// the compiler-provided support as it's simpler and more efficient, but must +// not use it if wxWidgets is used in a dynamically loaded Win32 (i.e. using +// LoadLibrary()/GetProcAddress()) as this triggers a bug in compiler TLS +// support that results in crashes when any TLS variables are used. So if you +// are building a Win32 DLL using wxWidgets that can be loaded dynamically, set +// this to 0. +// +// Default is 1, but set to 0 if the scenario above is applicable. +#define wxUSE_COMPILER_TLS 1 // ---------------------------------------------------------------------------- // Interoperability with the standard library. diff --git a/setup.h.in b/setup.h.in index c324fe185a..6f21cdae9b 100644 --- a/setup.h.in +++ b/setup.h.in @@ -202,6 +202,7 @@ #define wxUSE_PRINTF_POS_PARAMS 0 +#define wxUSE_COMPILER_TLS 0 #define wxUSE_STL 0