@@ -51,13 +51,34 @@ ctypes_tls_callback(void* a, DWORD reason, PVOID b)
5151 }
5252}
5353
54- #ifdef _MSC_VER
55- #pragma const_seg(".CRT$XLB") EXTERN_C const PIMAGE_TLS_CALLBACK \
56- __crt_ctypes_tls_callback__ = ctypes_tls_callback;
57- #else
54+ #ifndef _MSC_VER
5855PIMAGE_TLS_CALLBACK __crt_ctypes_tls_callback__ __attribute__ \
5956 ((section (".CRT$XLB" ))) = ctypes_tls_callback ;
60- #endif
57+
58+ #else
59+
60+ #ifdef _WIN64
61+
62+ #pragma comment(linker, "/INCLUDE:_tls_used")
63+ #pragma comment(linker, "/INCLUDE:crt_ctypes_tls_callback")
64+ #pragma data_seg(push, old_seg)
65+ #pragma const_seg(".CRT$XLB")
66+ extern const PIMAGE_TLS_CALLBACK crt_ctypes_tls_callback ;
67+ const PIMAGE_TLS_CALLBACK crt_ctypes_tls_callback = ctypes_tls_callback ;
68+ #pragma data_seg(pop, old_seg)
69+
70+ #else
71+
72+ #pragma comment(linker, "/INCLUDE:__tls_used")
73+ #pragma comment(linker, "/INCLUDE:_crt_ctypes_tls_callback")
74+ #pragma data_seg(push, old_seg)
75+ #pragma data_seg(".CRT$XLB")
76+ PIMAGE_TLS_CALLBACK crt_ctypes_tls_callback = ctypes_tls_callback ;
77+ #pragma data_seg(pop, old_seg)
78+
79+ #endif /* _WIN64 */
80+
81+ #endif /* _MSC_VER */
6182
6283static int ctypes_thread_actually_register (void )
6384{
@@ -104,7 +125,7 @@ static int ctypes_thread_actually_register(void)
104125 will always succeed. Consequently, there is no need to protect
105126 the TLS-creation code with pthread_once. (And at worst, if the
106127 assumption is violated then caml_c_thread_unregister will be
107- called multiple times, which is harmless.) */
128+ called multiple times, which is harmless.) */
108129 pthread_key_create (& cleanup_key , ctypes_thread_unregister );
109130 pthread_setspecific (cleanup_key , & cleanup_key );
110131 }
0 commit comments