Skip to content

Commit

Permalink
Automated rollback of commit 9b4ceb4.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 540399237
  • Loading branch information
mkruskal-google authored and copybara-github committed Jun 14, 2023
1 parent 9b4ceb4 commit 25a9547
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 12 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,18 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) {
}
)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");
// 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");
}

// However, we must provide a way to force initialize the default instances
// of FileDescriptorProto which will be used during registration of other
Expand Down
8 changes: 7 additions & 1 deletion src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,13 @@ DescriptorPool* DescriptorPool::internal_generated_pool() {
}

const DescriptorPool* DescriptorPool::generated_pool() {
return internal_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;
}


Expand Down

0 comments on commit 25a9547

Please sign in to comment.