Skip to content

Commit d0bcacd

Browse files
authored
Make API visibility hidden by default. (#9698)
This PR fixes #9691 by making PyTorch/XLA library visibility property hidden by default. This is to make sure we don't share data unexpectedly with other libraries.
1 parent c8b09f5 commit d0bcacd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.bazelrc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,38 @@ build:clang --spawn_strategy=sandboxed
6464

6565
###########################################################################
6666

67+
# Make all symbols hidden, by default.
68+
# Ref: https://github.com/pytorch/xla/pull/9693
69+
#
70+
# Without this flag, GCC was associating some variables as "global unique".
71+
# Meaning that the linker would make sure that there was only one instance
72+
# of that variable per process.
73+
#
74+
# Which Variables?
75+
# ================
76+
# - Function-local static variables
77+
# - Inside an inline function (e.g. class member functions)
78+
# - Inside an non-internal linkage context
79+
#
80+
# One example is: `protobuf` holds [a `ShutdownData`][1] which is function-local
81+
# and static, living inside an inline function, which lives inside a class with
82+
# external linkage.
83+
#
84+
# What Happens?
85+
# =============
86+
# [GCC marks those variables with STB_GNU_UNIQUE binding][2], making sure those
87+
# variables are unique for the entire process.
88+
#
89+
# Alternatives
90+
# ============
91+
# There is also the `--no-gnu-unique` option, which disables exactly that.
92+
# However, I believe this is a good opportunity to make everything hidden, unless
93+
# otherwise specified.
94+
#
95+
# [1]: https://github.com/protocolbuffers/protobuf/blob/13fe37f25f187b7a2e79faa962df6a69bdb3d5b8/src/google/protobuf/message_lite.cc#L776
96+
# [2]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html?utm_source=chatgpt.com#index-fno-gnu-unique
97+
build:posix --copt=-fvisibility=hidden
98+
6799
build:posix --copt=-Wno-sign-compare
68100
build:posix --cxxopt=-std=c++17
69101
build:posix --host_cxxopt=-std=c++17

0 commit comments

Comments
 (0)