1diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc 2index 05a228fb8fe6a..c055640d56214 100644 3--- a/src/google/protobuf/generated_message_util.cc 4+++ b/src/google/protobuf/generated_message_util.cc 5@@ -69,25 +69,16 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT 6 fixed_address_empty_string{}; // NOLINT 7 8 9-PROTOBUF_CONSTINIT std::atomic<bool> init_protobuf_defaults_state{false}; 10-static bool InitProtobufDefaultsImpl() { 11- fixed_address_empty_string.DefaultConstruct(); 12- OnShutdownDestroyString(fixed_address_empty_string.get_mutable()); 13- 14- 15- init_protobuf_defaults_state.store(true, std::memory_order_release); 16- return true; 17-} 18- 19+PROTOBUF_CONSTINIT bool init_protobuf_defaults_state{false}; 20 void InitProtobufDefaultsSlow() { 21- static bool is_inited = InitProtobufDefaultsImpl(); 22- (void)is_inited; 23+ fixed_address_empty_string.DefaultConstruct(); 24+ init_protobuf_defaults_state = true; 25 } 26 // Force the initialization of the empty string. 27 // Normally, registration would do it, but we don't have any guarantee that 28 // there is any object with reflection. 29 PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 static std::true_type init_empty_string = 30- (InitProtobufDefaultsSlow(), std::true_type{}); 31+ (InitProtobufDefaults(), std::true_type{}); 32 33 const std::string& GetEmptyString() { 34 InitProtobufDefaults(); 35diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h 36index 0aee548ed2796..a722c9126026d 100644 37--- a/src/google/protobuf/generated_message_util.h 38+++ b/src/google/protobuf/generated_message_util.h 39@@ -89,11 +89,14 @@ inline To DownCast(From& f) { 40 // This fastpath inlines a single branch instead of having to make the 41 // InitProtobufDefaults function call. 42 // It also generates less inlined code than a function-scope static initializer. 43-PROTOBUF_EXPORT extern std::atomic<bool> init_protobuf_defaults_state; 44+PROTOBUF_EXPORT extern bool init_protobuf_defaults_state; 45 PROTOBUF_EXPORT void InitProtobufDefaultsSlow(); 46 PROTOBUF_EXPORT inline void InitProtobufDefaults() { 47- if (PROTOBUF_PREDICT_FALSE( 48- !init_protobuf_defaults_state.load(std::memory_order_acquire))) { 49+ // This is not thread-safe, but is called within a static initializer. As long 50+ // as there are no calls to this function from off the main thread, before 51+ // main() starts, this is safe. After main() starts, 52+ // init_protobuf_defaults_state will always be true. 53+ if (PROTOBUF_PREDICT_FALSE(!init_protobuf_defaults_state)) { 54 InitProtobufDefaultsSlow(); 55 } 56 } 57-- 582.37.0.rc0.104.g0611611a94-goog 59