diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 51afdbdafe..6577a36692 100644 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -519,7 +519,7 @@ ThreadSafeArena::ThreadCache& ThreadSafeArena::thread_cache() { new internal::ThreadLocalStorage(); return *thread_cache_->Get(); } -#elif defined(PROTOBUF_USE_DLLS) +#elif defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER) ThreadSafeArena::ThreadCache& ThreadSafeArena::thread_cache() { static PROTOBUF_THREAD_LOCAL ThreadCache thread_cache; return thread_cache; diff --git a/src/google/protobuf/reflection_mode.cc b/src/google/protobuf/reflection_mode.cc index 7611c7b69c..2f6eec286e 100644 --- a/src/google/protobuf/reflection_mode.cc +++ b/src/google/protobuf/reflection_mode.cc @@ -39,7 +39,7 @@ namespace internal { #if !defined(PROTOBUF_NO_THREADLOCAL) -#if defined(PROTOBUF_USE_DLLS) +#if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER) ReflectionMode& ScopedReflectionMode::reflection_mode() { static PROTOBUF_THREAD_LOCAL ReflectionMode reflection_mode = ReflectionMode::kDefault; diff --git a/src/google/protobuf/reflection_mode.h b/src/google/protobuf/reflection_mode.h index e9ff3408f0..5e1f237a35 100644 --- a/src/google/protobuf/reflection_mode.h +++ b/src/google/protobuf/reflection_mode.h @@ -95,18 +95,20 @@ class PROTOBUF_EXPORT ScopedReflectionMode final { private: #if !defined(PROTOBUF_NO_THREADLOCAL) const ReflectionMode previous_mode_; -#if defined(PROTOBUF_USE_DLLS) +#if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER) + // Thread local variables cannot be exposed through MSVC DLL interface but we + // can wrap them in static functions. static ReflectionMode& reflection_mode(); #else PROTOBUF_CONSTINIT static PROTOBUF_THREAD_LOCAL ReflectionMode reflection_mode_; -#endif // PROTOBUF_USE_DLLS +#endif // PROTOBUF_USE_DLLS && _MSC_VER #endif // !PROTOBUF_NO_THREADLOCAL }; #if !defined(PROTOBUF_NO_THREADLOCAL) -#if defined(PROTOBUF_USE_DLLS) +#if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER) inline ScopedReflectionMode::ScopedReflectionMode(ReflectionMode mode) : previous_mode_(reflection_mode()) { @@ -140,7 +142,7 @@ inline ReflectionMode ScopedReflectionMode::current_reflection_mode() { return reflection_mode_; } -#endif // PROTOBUF_USE_DLLS +#endif // PROTOBUF_USE_DLLS && _MSC_VER #else diff --git a/src/google/protobuf/thread_safe_arena.h b/src/google/protobuf/thread_safe_arena.h index 5a527bc637..5b5b4e6eb6 100644 --- a/src/google/protobuf/thread_safe_arena.h +++ b/src/google/protobuf/thread_safe_arena.h @@ -261,9 +261,9 @@ class PROTOBUF_EXPORT ThreadSafeArena { // iOS does not support __thread keyword so we use a custom thread local // storage class we implemented. static ThreadCache& thread_cache(); -#elif defined(PROTOBUF_USE_DLLS) - // Thread local variables cannot be exposed through DLL interface but we can - // wrap them in static functions. +#elif defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER) + // Thread local variables cannot be exposed through MSVC DLL interface but we + // can wrap them in static functions. static ThreadCache& thread_cache(); #else PROTOBUF_CONSTINIT static PROTOBUF_THREAD_LOCAL ThreadCache thread_cache_;