Internal changes

PiperOrigin-RevId: 541035586
pull/13097/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent cab25b98a7
commit 53382db0fd
  1. 2
      src/google/protobuf/BUILD.bazel
  2. 27
      src/google/protobuf/compiler/cpp/extension.cc
  3. 11
      src/google/protobuf/compiler/cpp/file.cc
  4. 9
      src/google/protobuf/descriptor.cc
  5. 4
      src/google/protobuf/extension_set.h

@ -398,8 +398,10 @@ cc_library(
":varint_shuffle",
"//src/google/protobuf/io",
"//src/google/protobuf/stubs:lite",
"@com_google_absl//absl/base",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",

@ -44,6 +44,13 @@ namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {
namespace {
bool RequiresLazyInitialization(const FieldDescriptor* descriptor) {
return false;
}
} // namespace
ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
const Options& options,
@ -172,12 +179,20 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
"#endif\n");
}
format(
"PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 "
"::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
" ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n"
" $scoped_name$($constant_name$, $1$, $verify_fn$);\n",
default_str);
if (RequiresLazyInitialization(descriptor_)) {
format(
"PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2\n"
"::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
" ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n"
" $scoped_name$($constant_name$);\n");
} else {
format(
"PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 "
"::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
" ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n"
" $scoped_name$($constant_name$, $1$, $verify_fn$);\n",
default_str);
}
}
} // namespace cpp

@ -1137,11 +1137,12 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) {
}
)cc");
// For descriptor.proto we want to avoid doing any dynamic initialization,
// because in some situations that would otherwise pull in a lot of
// unnecessary code that can't be stripped by --gc-sections. Descriptor
// initialization will still be performed lazily when it's needed.
if (file_->name() != "net/proto2/proto/descriptor.proto") {
// For descriptor.proto and cpp_features.proto we want to avoid doing any
// dynamic initialization, because in some situations that would otherwise
// pull in a lot of unnecessary code that can't be stripped by --gc-sections.
// Descriptor initialization will still be performed lazily when it's needed.
if (file_->name() != "net/proto2/proto/descriptor.proto"
) {
p->Emit({{"dummy", UniqueName("dynamic_init_dummy", file_, options_)}},
R"cc(
// Force running AddDescriptors() at dynamic initialization time.

@ -1964,10 +1964,11 @@ DescriptorPool* DescriptorPool::internal_generated_pool() {
const DescriptorPool* DescriptorPool::generated_pool() {
const DescriptorPool* pool = internal_generated_pool();
// Ensure that descriptor.proto gets registered in the generated pool. It is a
// special case because it is included in the full runtime. We have to avoid
// registering it pre-main, because we need to ensure that the linker
// --gc-sections step can strip out the full runtime if it is unused.
// Ensure that descriptor.proto and cpp_features.proto get registered in the
// generated pool. They're special cases because they're included in the full
// runtime. We have to avoid registering it pre-main, because we need to
// ensure that the linker --gc-sections step can strip out the full runtime if
// it is unused.
DescriptorProto::descriptor();
return pool;
}

@ -41,11 +41,14 @@
#include <algorithm>
#include <cassert>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "google/protobuf/stubs/common.h"
#include "absl/base/call_once.h"
#include "absl/container/btree_map.h"
#include "absl/functional/any_invocable.h"
#include "absl/log/absl_check.h"
#include "google/protobuf/port.h"
#include "google/protobuf/port.h"
@ -1535,6 +1538,7 @@ class ExtensionIdentifier {
extern PROTOBUF_ATTRIBUTE_WEAK ExtensionSet::LazyMessageExtension*
MaybeCreateLazyExtension(Arena* arena);
} // namespace internal
// Call this function to ensure that this extensions's reflection is linked into

Loading…
Cancel
Save