@@ -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+
6799build:posix --copt=-Wno-sign-compare
68100build:posix --cxxopt=-std=c++17
69101build:posix --host_cxxopt=-std=c++17
0 commit comments