Explicitly set visibility of public API functions when gcc is used

Windows builds already limit exporting of functions to those marked
with LZ4LIB_API tag.  The same behaviour could be achieved on other
platforms when a relatively fresh gcc is used.

This change assigns public visibility to all symbols marked with
LZ4LIB_API tag.  When the library is built in -fvisibility=hidden
mode, only these marked symbols will be exported.
This commit is contained in:
Dmitry V. Levin 2017-03-10 23:35:30 +00:00
parent 93b3b08ef6
commit 7aeecbff71
2 changed files with 8 additions and 0 deletions

View File

@ -72,11 +72,15 @@ extern "C" {
/*
* LZ4_DLL_EXPORT :
* Enable exporting of functions when building a Windows DLL
* LZ4LIB_API :
* Control library symbols visibility.
*/
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
# define LZ4LIB_API __declspec(dllexport)
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
# define LZ4LIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
#elif defined(__GNUC__) && (__GNUC__ >= 4)
# define LZ4LIB_API __attribute__ ((__visibility__ ("default")))
#else
# define LZ4LIB_API
#endif

View File

@ -63,11 +63,15 @@ extern "C" {
/*
* LZ4_DLL_EXPORT :
* Enable exporting of functions when building a Windows DLL
* LZ4FLIB_API :
* Control library symbols visibility.
*/
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
# define LZ4FLIB_API __declspec(dllexport)
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
# define LZ4FLIB_API __declspec(dllimport)
#elif defined(__GNUC__) && (__GNUC__ >= 4)
# define LZ4FLIB_API __attribute__ ((__visibility__ ("default")))
#else
# define LZ4FLIB_API
#endif