Skip to content

Commit fe4a27a

Browse files
build: Add SECP256K1_FORCE_HIDDEN_VISIBILITY
The name should make it clear that this is intended for ELF platforms only.
1 parent 43bb4be commit fe4a27a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

include/secp256k1.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,30 @@ typedef int (*secp256k1_nonce_function)(
151151
# define SECP256K1_API extern __declspec (dllimport)
152152
# endif
153153
#endif
154+
#if !defined(SECP256K1_API) \
155+
&& defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD) \
156+
&& defined(SECP256K1_FORCE_HIDDEN_VISIBILITY)
157+
/* Building libsecp256k1 using GCC or compatible on non-Windows, and hidden
158+
* 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 building
164+
* a static library. (You want to ./configure with --disable-shared if using
165+
* Autotools.)
166+
*
167+
* While visibility is a concept that applies only to shared libraries, setting
168+
* visibility will still make a difference when building a static library: the
169+
* visibility settings will be stored in the static library, solely for the
170+
* potential case that the static library will be linked into a shared library.
171+
* In that case, the stored visibility settings will resurface and be honored
172+
* for the shared library. */
173+
# define SECP256K1_API extern __attribute__ ((visibility ("hidden")))
174+
#endif
154175
#ifndef SECP256K1_API
155-
/* All cases not captured by the Windows-specific logic. */
156-
# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
157-
/* Building libsecp256k1 using GCC or compatible. */
158-
# define SECP256K1_API extern
159-
# else
160-
/* Fall back to standard C's extern. */
161-
# define SECP256K1_API extern
162-
# endif
176+
/* Fall back to standard C's extern. */
177+
# define SECP256K1_API extern
163178
#endif
164179

165180
/* Warning attributes

0 commit comments

Comments
 (0)