protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

FileOptions with dynamic libraries: Multiple extension registrations

Open gudvinr opened this issue 5 years ago • 6 comments

What version of protobuf and what language are you using? Version: v3.6.1 Language: C++

What operating system (Linux, Windows, ...) and version? Linux: Ubuntu 18.04 (KDE Neon)

What runtime / compiler are you using (e.g., python version or gcc version) GCC: 7.5.0 gRPC: v1.16.1

What did you do? Steps to reproduce the behavior:

  1. Add custom option to .proto
  2. Compile .proto files to static lib
  3. Link this library to executable (compiled with -rdynamic)
  4. Link this library to dynamic libraries
  5. Open dynamic libraries using dlopen (with RTLD_GLOBAL)
  6. Executable not loading and libprobobuf producing an error

What did you expect to see Correctly running application which uses protobuf extensions

What did you see instead? Application not working and libprotobuf throwing exception:

[libprotobuf FATAL …/protobuf/src/google/protobuf/extension_set.cc:93] Multiple extension registrations for type "google.protobuf.FileOptions", field number 50000.
terminate called after throwing an instance of 'google::protobuf::FatalException'
  what():  Multiple extension registrations for type "google.protobuf.FileOptions", field number 50000.

Anything else we should know about your project / environment

There are no extensions with same field number (and no extensions with same name either).
It is not possible to link static library only with executable because symbols inside shared libraries can't be found.
There are usage of protobuf types inside executable so you can't link library to dynamic libs too.
Using shared library is not possible without significant changes to build process.

gudvinr avatar Aug 18 '20 14:08 gudvinr

It sounds like this custom option is either getting linked in more than once place, or getting dynamically loaded multiple times. To fix the problem you will have to make sure the option is only registered once.

acozzette avatar Aug 18 '20 23:08 acozzette

@acozzette

It sounds like this custom option is either getting linked in more than once place, or getting dynamically loaded multiple times.

It is exactly what I said: 2. Compile .proto files to static lib 3. Link this library to executable (compiled with -rdynamic) 4. Link this library to dynamic libraries

libprotobuf then then calls Register function for extensions every time it loads. And this causing errors.

gudvinr avatar Aug 19 '20 08:08 gudvinr

Is there any workaround for this?

Dlougach avatar Feb 24 '21 09:02 Dlougach

We use "MessageOptions" to check a type which should be de-serialized in several dynamic libraries in one app. And the same issue occurs. Please provide solution for this issue or any workaround.

fmvin avatar May 15 '22 06:05 fmvin

Sorry for the long delay. Are you still seeing this error in newer versions of protobuf?

deannagarcia avatar Jul 26 '22 16:07 deannagarcia

We encountered this issue previously in the Eclipse sim@openPASS Project. A short test with protobuf v21.4 didn't show the problem anymore.

ReinhardBiegelIntech avatar Aug 10 '22 08:08 ReinhardBiegelIntech

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.

github-actions[bot] avatar Mar 10 '24 10:03 github-actions[bot]

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.

github-actions[bot] avatar Mar 25 '24 10:03 github-actions[bot]