Document a mechanism to always link the object file for a generated `.pb.cc` file
Some .proto files only contain gRPC service definitions and no messages. For example:
https://github.com/googleapis/googleapis/blob/master/google/iam/credentials/v1/iamcredentials.proto
For such files, the generated *.pb.cc contains global symbols that are needed for reflection to work. In that example the generated code contains:
// Force running AddDescriptors() at dynamic initialization time.
PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fiam_2fcredentials_2fv1_2fiamcredentials_2eproto(&descriptor_table_google_2fiam_2fcredentials_2fv1_2fiamcredentials_2eproto);
Note that with such files, no symbols in *.pb.cc or *.pb.h are things that the application can use. They are all undocumented implementation details. The comments warn against using them:
// Internal implementation detail -- do not use these members.
struct TableStruct_google_2fiam_2fcredentials_2fv1_2fiamcredentials_2eproto {
static const uint32_t offsets[];
};
extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fiam_2fcredentials_2fv1_2fiamcredentials_2eproto;
Unfortunately, a statically linked application will not link the corresponding *.pb.o: the linker will cleverly notice that no symbols from that file are used by the application, and simply skip the file. Consequently, the static constructor for things like dynamic_init_dummy_google_2fiam_2fcredentials_2fv1_2fiamcredentials_2eproto will not run, and the application will not be able to do reflection on any services defined on the file. This is true even if the application links and uses the symbols generated by gRPC.
~It would be desirable to have one symbol that applications can use to always link the corresponding *.pb.o.~
One of my colleagues points out that this is not enough. Maybe a better feature request would be a function to initialize the reflection data structures with all the elements in a file? Or a function to return the descriptors in a file?
For .proto files under the control of a project this can be achieved with a dummy message type. But for .proto files outside the control of a project there is no documented (and supported) symbols that the project could use.
PS: more background on https://github.com/googleapis/google-cloud-cpp/pull/12560#issuecomment-1712306813
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago.
Any thoughts on this?
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.
This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.