Skip to content

Commit

Permalink
Remove workaround for whole-archive linker behavior.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 540373752
  • Loading branch information
mkruskal-google authored and copybara-github committed Jun 14, 2023
1 parent aba0341 commit 9b4ceb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
18 changes: 6 additions & 12 deletions src/google/protobuf/compiler/cpp/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down

0 comments on commit 9b4ceb4

Please sign in to comment.