Fix visibility of libprotobuf symbols in protoc_compiler.so on Mac#24992
Merged
gnossen merged 4 commits intogrpc:masterfrom Dec 15, 2020
Merged
Fix visibility of libprotobuf symbols in protoc_compiler.so on Mac#24992gnossen merged 4 commits intogrpc:masterfrom
gnossen merged 4 commits intogrpc:masterfrom
Conversation
lidizheng
approved these changes
Dec 15, 2020
Contributor
Author
gnossen
added a commit
to gnossen/grpc
that referenced
this pull request
Dec 15, 2020
Fix visibility of libprotobuf symbols in protoc_compiler.so on Mac
ravidcottopia
pushed a commit
to ottopia-tech/grpc
that referenced
this pull request
Dec 29, 2020
Fix visibility of libprotobuf symbols in protoc_compiler.so on Mac
rowillia
pushed a commit
to rowillia/protobuf
that referenced
this pull request
Feb 25, 2021
@gnossen gave a great overview in grpc/grpc#24992 of the overall problem. If a python process using both protobuf _and_ another native library linking in libprotobuf frequently can cause crashes. This seems to frequently affect tensorflow as well: tensorflow/tensorflow#8394, tensorflow/tensorflow#9525 (comment) tensorflow/tensorflow#24976, tensorflow/tensorflow#35573, https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/contrib/makefile/rename_protobuf.sh, tensorflow/tensorflow#16104 Testing locally this fixes both crashes when linking in multiple versions of protobuf and fixes `DescriptorPool` clashes as well (e.g. Python and Native code import different versions of the same message).
TeBoring
pushed a commit
to protocolbuffers/protobuf
that referenced
this pull request
Apr 24, 2021
@gnossen gave a great overview in grpc/grpc#24992 of the overall problem. If a python process using both protobuf _and_ another native library linking in libprotobuf frequently can cause crashes. This seems to frequently affect tensorflow as well: tensorflow/tensorflow#8394, tensorflow/tensorflow#9525 (comment) tensorflow/tensorflow#24976, tensorflow/tensorflow#35573, https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/contrib/makefile/rename_protobuf.sh, tensorflow/tensorflow#16104 Testing locally this fixes both crashes when linking in multiple versions of protobuf and fixes `DescriptorPool` clashes as well (e.g. Python and Native code import different versions of the same message).
goaway
pushed a commit
to envoyproxy/envoy-mobile
that referenced
this pull request
Jun 8, 2021
Description: This PR modifies the build recipe for `envoy_engine.so` to hide all symbols except for `_PyInit_envoy_engine` by default on maOS, so that envoy_engine can be loaded alongside a [protobuf](http://pypi.org/project/protobuf) wheel without breaking. Loading in protobuf alongside `envoy_engine.so` would register two sets of the same symbols and, on macOS, the runtime linker chooses the first symbol it finds causing problems. See the [similar protobuf change](protocolbuffers/protobuf#8346) and its [sister change in grpc](grpc/grpc#24992) for more information on what's going on. Risk Level: Low Testing: See the now-closed #1504 for how I've been testing this. Docs Changes: N/A Release Notes: N/A Signed-off-by: Cerek Hillen <chillen@lyft.com>
acozzette
pushed a commit
to acozzette/protobuf
that referenced
this pull request
Jan 22, 2022
@gnossen gave a great overview in grpc/grpc#24992 of the overall problem. If a python process using both protobuf _and_ another native library linking in libprotobuf frequently can cause crashes. This seems to frequently affect tensorflow as well: tensorflow/tensorflow#8394, tensorflow/tensorflow#9525 (comment) tensorflow/tensorflow#24976, tensorflow/tensorflow#35573, https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/contrib/makefile/rename_protobuf.sh, tensorflow/tensorflow#16104 Testing locally this fixes both crashes when linking in multiple versions of protobuf and fixes `DescriptorPool` clashes as well (e.g. Python and Native code import different versions of the same message).
acozzette
pushed a commit
to protocolbuffers/protobuf
that referenced
this pull request
Jan 25, 2022
@gnossen gave a great overview in grpc/grpc#24992 of the overall problem. If a python process using both protobuf _and_ another native library linking in libprotobuf frequently can cause crashes. This seems to frequently affect tensorflow as well: tensorflow/tensorflow#8394, tensorflow/tensorflow#9525 (comment) tensorflow/tensorflow#24976, tensorflow/tensorflow#35573, https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/contrib/makefile/rename_protobuf.sh, tensorflow/tensorflow#16104 Testing locally this fixes both crashes when linking in multiple versions of protobuf and fixes `DescriptorPool` clashes as well (e.g. Python and Native code import different versions of the same message). Co-authored-by: Roy Williams <roy.williams.iii@gmail.com>
jpsim
pushed a commit
to envoyproxy/envoy
that referenced
this pull request
Nov 28, 2022
Description: This PR modifies the build recipe for `envoy_engine.so` to hide all symbols except for `_PyInit_envoy_engine` by default on maOS, so that envoy_engine can be loaded alongside a [protobuf](http://pypi.org/project/protobuf) wheel without breaking. Loading in protobuf alongside `envoy_engine.so` would register two sets of the same symbols and, on macOS, the runtime linker chooses the first symbol it finds causing problems. See the [similar protobuf change](protocolbuffers/protobuf#8346) and its [sister change in grpc](grpc/grpc#24992) for more information on what's going on. Risk Level: Low Testing: See the now-closed #1504 for how I've been testing this. Docs Changes: N/A Release Notes: N/A Signed-off-by: Cerek Hillen <chillen@lyft.com> Signed-off-by: JP Simard <jp@jpsim.com>
jpsim
pushed a commit
to envoyproxy/envoy
that referenced
this pull request
Nov 29, 2022
Description: This PR modifies the build recipe for `envoy_engine.so` to hide all symbols except for `_PyInit_envoy_engine` by default on maOS, so that envoy_engine can be loaded alongside a [protobuf](http://pypi.org/project/protobuf) wheel without breaking. Loading in protobuf alongside `envoy_engine.so` would register two sets of the same symbols and, on macOS, the runtime linker chooses the first symbol it finds causing problems. See the [similar protobuf change](protocolbuffers/protobuf#8346) and its [sister change in grpc](grpc/grpc#24992) for more information on what's going on. Risk Level: Low Testing: See the now-closed #1504 for how I've been testing this. Docs Changes: N/A Release Notes: N/A Signed-off-by: Cerek Hillen <chillen@lyft.com> Signed-off-by: JP Simard <jp@jpsim.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24897
@yulin-liang This will require a backport (and patch to) to
v1.34.x.Our Mac OS build currently produces many global weak symbols corresponding to static variables in libprotobuf:
On Mac OS, clang will produce global weak symbols for function-local static variables when the function is a class method. For example:
This C++ snippet produces the following symbol table:
When given a choice between two weak symbols with the same name in the same process, the Mac OS runtime linker will prefer the first one:
Above, you see references to
libprotobufsymbols in_protoc_compiler.so(grpcio-tools) resolving to addresses corresponding to symbols in_message.so(protobufwheel).When this happens, as in #24897, the initializer for static variables may come from one version of
libprotobufwhile, the runtime code may come from another version of it. When data layouts or other pertinent invariants change, this may result in segmentation faults, data corruption, or other "bad behavior."The fix in this PR is to make all symbols in
_protoc_compiler.sobesides_PyInit__protoc_compiler(the Python interpreter's entrypoint to thegrpcio-toolsC extension) local:This issue only ever affected Mac OS. Our Linux shared object libraries contain no global weak symbols and (somewhat perplexingly), the
.pydfiles in our Windows artifacts contain no symbols at all, according towinedump.