• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
2index 24f2ccba46c3f..9526c6752f32c 100644
3--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
4+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
5@@ -499,7 +499,15 @@ void FileGenerator::GenerateSourceDefaultInstance(int idx,
6   // enough. However, the empty destructor fails to be elided in some
7   // configurations (like non-opt or with certain sanitizers). NO_DESTROY is
8   // there just to improve performance and binary size in these builds.
9-  format("PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT "
10+  //
11+  // Use PROTOBUF_CONSTINIT_WITH_PTR instead of PROTOBUF_CONSTINIT because, in
12+  // Windows shared library builds, this constructor takes a pointer to a
13+  // dllimport variable, fixed_address_empty_string. This is not constinit on
14+  // Windows. This is a bug in protobuf as the default instance was intended to
15+  // be constant-initialized. But the components build in Chromium is a
16+  // developer configuration, so we tolerate an initializer as long as the build
17+  // works, until protobuf has a proper fix.
18+  format("PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT_WITH_PTR "
19          "PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 $1$ $2$;\n",
20          DefaultInstanceType(generator->descriptor_, options_),
21          DefaultInstanceName(generator->descriptor_, options_));
22diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
23index 8bd06d340f7c3..cae9ebe01ec2c 100644
24--- a/src/google/protobuf/port_def.inc
25+++ b/src/google/protobuf/port_def.inc
26@@ -434,19 +434,26 @@
27 #  define PROTOBUF_EXPORT __declspec(dllexport)
28 #  define PROTOBUF_EXPORT_TEMPLATE_DECLARE
29 #  define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
30+#  define PROTOBUF_CONSTINIT_WITH_PTR PROTOBUF_CONSTINIT
31 # else
32 #  define PROTOBUF_EXPORT __declspec(dllimport)
33 #  define PROTOBUF_EXPORT_TEMPLATE_DECLARE
34 #  define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
35+// Pointers to dllimport extern variables on Windows require a static
36+// initialization and cannot be constant-initialized. This macro disables
37+// constinit in files where we cannot support it.
38+#  define PROTOBUF_CONSTINIT_WITH_PTR
39 # endif  // defined(LIBPROTOBUF_EXPORTS)
40 #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
41 # define PROTOBUF_EXPORT __attribute__((visibility("default")))
42 # define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
43 # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
44+# define PROTOBUF_CONSTINIT_WITH_PTR PROTOBUF_CONSTINIT
45 #else
46 # define PROTOBUF_EXPORT
47 # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
48 # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
49+# define PROTOBUF_CONSTINIT_WITH_PTR PROTOBUF_CONSTINIT
50 #endif
51
52 #ifdef PROTOC_EXPORT
53diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc
54index 58136a4b47350..056c9b790ba4d 100644
55--- a/src/google/protobuf/port_undef.inc
56+++ b/src/google/protobuf/port_undef.inc
57@@ -80,6 +80,7 @@
58 #undef PROTOBUF_THREAD_LOCAL
59 #undef PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT
60 #undef PROTOBUF_CONSTINIT
61+#undef PROTOBUF_CONSTINIT_WITH_PTR
62 #undef PROTOBUF_CONSTEXPR
63 #undef PROTOBUF_ATTRIBUTE_WEAK
64 #undef PROTOBUF_HAVE_ATTRIBUTE_WEAK
65--
662.37.0.rc0.104.g0611611a94-goog
67