@@ -152,15 +152,37 @@ typedef int (*secp256k1_nonce_function)(
152152# endif
153153#endif
154154#ifndef SECP256K1_API
155- /* All cases not captured by the Windows-specific logic. */
156155# if defined(__GNUC__ ) && (__GNUC__ >= 4 ) && defined(SECP256K1_BUILD )
157- /* Building libsecp256k1 using GCC or compatible. */
158- # define SECP256K1_API extern __attribute__ ((visibility ("default")))
159- # else
160- /* Fall back to standard C's extern. */
161- # define SECP256K1_API extern
156+ /* Building libsecp256k1 using GCC or compatible on non-Windows. */
157+ # if defined(SECP256K1_FORCE_HIDDEN_VISIBILITY )
158+ /* Hidden visibility is requested explicitly.
159+ *
160+ * Forcing hidden visibility can be useful, e.g., when building a static
161+ * library which is linked into a shared library, and the latter should not
162+ * reexport the libsecp256k1 API. Since this will create an unusable shared
163+ * library, SECP256K1_FORCE_HIDDEN_VISIBILITY should only be used when
164+ * building a static library. (You want to ./configure with --disable-shared
165+ * if using Autotools.)
166+ *
167+ * While visibility is a concept that applies only to shared libraries,
168+ * setting visibility will still make a difference when building a static
169+ * library: the visibility settings will be stored in the static library,
170+ * solely for the potential case that the static library will be linked into
171+ * a shared library. In that case, the stored visibility settings will
172+ * resurface and be honored for the shared library. */
173+ # define SECP256K1_API extern __attribute__ ((visibility("hidden")))
174+ # else
175+ /* Set default visibility explicit. This is to not break the build for users
176+ * who pass `-fvisibility=hidden` in the expection that this is a
177+ * visibility-aware library. */
178+ # define SECP256K1_API extern __attribute__ ((visibility("default")))
179+ # endif
162180# endif
163181#endif
182+ #ifndef SECP256K1_API
183+ /* Fall back to standard C's extern. */
184+ # define SECP256K1_API extern
185+ #endif
164186
165187/* Warning attributes
166188 * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out
0 commit comments