Skip to content

Commit

Permalink
Automated rollback of commit 53382db.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 541076146
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jun 17, 2023
1 parent 53382db commit 8997b54
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 38 deletions.
2 changes: 0 additions & 2 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,8 @@ 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",
Expand Down
27 changes: 6 additions & 21 deletions src/google/protobuf/compiler/cpp/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ 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,
Expand Down Expand Up @@ -179,20 +172,12 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
"#endif\n");
}

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);
}
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
Expand Down
11 changes: 5 additions & 6 deletions src/google/protobuf/compiler/cpp/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1137,12 +1137,11 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) {
}
)cc");

// 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"
) {
// 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") {
p->Emit({{"dummy", UniqueName("dynamic_init_dummy", file_, options_)}},
R"cc(
// Force running AddDescriptors() at dynamic initialization time.
Expand Down
9 changes: 4 additions & 5 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1964,11 +1964,10 @@ DescriptorPool* DescriptorPool::internal_generated_pool() {

const DescriptorPool* DescriptorPool::generated_pool() {
const DescriptorPool* pool = internal_generated_pool();
// 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.
// 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.
DescriptorProto::descriptor();
return pool;
}
Expand Down
4 changes: 0 additions & 4 deletions src/google/protobuf/extension_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@
#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"
Expand Down Expand Up @@ -1538,7 +1535,6 @@ 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
Expand Down

0 comments on commit 8997b54

Please sign in to comment.