From 9b4ceb477099b7b4dd2bf98f6b0790573ddfda3f Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 14 Jun 2023 14:03:33 -0700 Subject: [PATCH] Remove workaround for whole-archive linker behavior. PiperOrigin-RevId: 540373752 --- src/google/protobuf/compiler/cpp/file.cc | 18 ++++++------------ src/google/protobuf/descriptor.cc | 8 +------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 708339623527..41e9a330dd3f 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -1137,18 +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") { - p->Emit({{"dummy", UniqueName("dynamic_init_dummy", file_, options_)}}, - R"cc( - // Force running AddDescriptors() at dynamic initialization time. - PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 - static ::_pbi::AddDescriptorsRunner $dummy$(&$desc_table$); - )cc"); - } + p->Emit({{"dummy", UniqueName("dynamic_init_dummy", file_, options_)}}, + R"cc( + // Force running AddDescriptors() at dynamic initialization time. + PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 + static ::_pbi::AddDescriptorsRunner $dummy$(&$desc_table$); + )cc"); // However, we must provide a way to force initialize the default instances // of FileDescriptorProto which will be used during registration of other diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 6716eda0c69b..b7e79c331e63 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -1963,13 +1963,7 @@ 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. - DescriptorProto::descriptor(); - return pool; + return internal_generated_pool(); }