Skip to content

Commit

Permalink
Fix undefined symbol error around SharedCtor() (#8827)
Browse files Browse the repository at this point in the history
* Fix undefined symbol error around SharedCtor()

Apparently, #8532 was incorrect if applied to 3.17.x branch.

3.17.x changed code generation to mark `SharedCtor()` and `SharedDtor()` as inline in .pb.cc.

It looks like we have a compile-time undefined behavior in C++ now. As cppreference.com [says](https://en.cppreference.com/w/cpp/language/inline):

_The definition of an inline function <...> must be reachable in the translation unit where it is accessed (not necessarily before the point of access)._

As protobuf allows custom plugins to generate custom code, there is no limitation on where SharedCtor couble be possible referenced from. In our case we have SharedCtor invoked from corresponding `.pb.h` code, thus triggering:
```
ld: error: undefined symbol: package::Message::SharedCtor()`
>>> referenced by file.pb.h:$$$$
```

If this patch is not applicable, I can take a look into changing the code generation, but doing this will be harder then removing _inline_.

* Regenerate checked-in generated .pb.cc files
  • Loading branch information
georgthegreat committed Jul 29, 2021
1 parent 5336506 commit 7326b57
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/google/protobuf/any.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/google/protobuf/any.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/google/protobuf/api.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/cpp/cpp_message.cc
Expand Up @@ -2381,7 +2381,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(
void MessageGenerator::GenerateSharedConstructorCode(io::Printer* printer) {
Formatter format(printer, variables_);

format("inline void $classname$::SharedCtor() {\n");
format("void $classname$::SharedCtor() {\n");

std::vector<bool> processed(optimized_order_.size(), false);
GenerateConstructorBody(printer, processed, false);
Expand Down
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 27 additions & 27 deletions src/google/protobuf/descriptor.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/duration.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/empty.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/field_mask.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/source_context.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7326b57

Please sign in to comment.