From 7aeecbff7178d72da1786ed30817fe8071c4d9ea Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 10 Mar 2017 23:35:30 +0000 Subject: 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. --- lib/lz4.h | 4 ++++ lib/lz4frame.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/lz4.h b/lib/lz4.h index bebe761..b0537fc 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -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 diff --git a/lib/lz4frame.h b/lib/lz4frame.h index 9d9fe89..f33eee1 100644 --- a/lib/lz4frame.h +++ b/lib/lz4frame.h @@ -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 -- cgit v0.12 From 25b243588585b06a2d947372284cbfe00da930e9 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 10 Mar 2017 23:35:30 +0000 Subject: Export deprecated symbols Deprecated symbols are still a part of ABI and have to be exported, so mark them with LZ4LIB_API attribute. --- lib/lz4.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/lz4.h b/lib/lz4.h index b0537fc..fa8312e 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -435,12 +435,12 @@ union LZ4_streamDecode_u { #endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */ /* Obsolete compression functions */ -LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress (const char* source, char* dest, int sourceSize); -LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); -LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); -LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); -LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); -LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress (const char* source, char* dest, int sourceSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); /* Obsolete decompression functions */ /* These function names are completely deprecated and must no longer be used. @@ -453,14 +453,14 @@ LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_limi /* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */ /* Obsolete streaming functions; use new streaming interface whenever possible */ -LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer); -LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); -LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer); -LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); /* Obsolete streaming decoding functions */ -LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize); -LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize); #if defined (__cplusplus) -- cgit v0.12 From 883ebdcee0aae3e8339dd3658c794ca49dfb18b1 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 10 Mar 2017 23:35:30 +0000 Subject: Export only those symbols that are part of public API Specify -fvisibility=hidden parameter when linking the shared library using -fPIC, assuming that gcc >= 4 is used. This change results to unexporting of the following 42 functions: LZ4F_getErrorCode LZ4_XXH32 LZ4_XXH32_canonicalFromHash LZ4_XXH32_copyState LZ4_XXH32_createState LZ4_XXH32_digest LZ4_XXH32_freeState LZ4_XXH32_hashFromCanonical LZ4_XXH32_reset LZ4_XXH32_update LZ4_XXH64 LZ4_XXH64_canonicalFromHash LZ4_XXH64_copyState LZ4_XXH64_createState LZ4_XXH64_digest LZ4_XXH64_freeState LZ4_XXH64_hashFromCanonical LZ4_XXH64_reset LZ4_XXH64_update LZ4_XXH_versionNumber LZ4_compressHC LZ4_compressHC2 LZ4_compressHC2_continue LZ4_compressHC2_limitedOutput LZ4_compressHC2_limitedOutput_continue LZ4_compressHC2_limitedOutput_withStateHC LZ4_compressHC2_withStateHC LZ4_compressHC_continue LZ4_compressHC_limitedOutput LZ4_compressHC_limitedOutput_continue LZ4_compressHC_limitedOutput_withStateHC LZ4_compressHC_withStateHC LZ4_compress_fast_force LZ4_compress_forceExtDict LZ4_createHC LZ4_decompress_safe_forceExtDict LZ4_freeHC LZ4_resetStreamStateHC LZ4_sizeofStreamStateHC LZ4_slideInputBufferHC LZ4_uncompress LZ4_uncompress_unknownOutputSize --- lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile b/lib/Makefile index c4bc7d2..9a794b8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -95,7 +95,7 @@ ifneq (,$(filter Windows%,$(OS))) @$(CC) $(FLAGS) -DLZ4_DLL_EXPORT=1 -shared $^ -o dll\$@.dll dlltool -D dll\liblz4.dll -d dll\liblz4.def -l dll\liblz4.lib else - @$(CC) $(FLAGS) -shared $^ -fPIC $(SONAME_FLAGS) -o $@ + @$(CC) $(FLAGS) -shared $^ -fPIC -fvisibility=hidden $(SONAME_FLAGS) -o $@ @echo creating versioned links @ln -sf $@ liblz4.$(SHARED_EXT_MAJOR) @ln -sf $@ liblz4.$(SHARED_EXT) -- cgit v0.12