Skip to content

Commit

Permalink
Explicitly hide static symbols
Browse files Browse the repository at this point in the history
Even with -fvisibility=hidden added to CFLAGS, any symbol which is
given a default visibility attribute ends up exported in the dynamic
library. This happens through zstd_internal.h which defines
..._STATIC_LINKING_ONLY before including various header files, and is
included for example in lib/common/pool.c.

To avoid this, this patch distinguishes static and non-static APIs;
only the latter are exported, the former are hidden.

In addition, -fvisibility=hidden is moved to CFLAGS for libzstd-mt (as
done previously for libzstd).

Signed-off-by: Stephen Kitt <[email protected]>
  • Loading branch information
skitt committed Feb 17, 2021
1 parent b2bff75 commit 87ddbfc
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 107 deletions.
3 changes: 2 additions & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ include $(wildcard $(DEPFILES))
# Special case : building library in single-thread mode _and_ without zstdmt_compress.c
ZSTDMT_FILES = compress/zstdmt_compress.c
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
libzstd-nomt: CFLAGS += -fvisibility=hidden
libzstd-nomt: LDFLAGS += -shared -fPIC
libzstd-nomt: $(ZSTD_NOMT_FILES)
@echo compiling single-thread dynamic library $(LIBVER)
@echo files : $(ZSTD_NOMT_FILES)
Expand Down
4 changes: 2 additions & 2 deletions lib/compress/zstd_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ size_t ZSTD_CCtx_loadDictionary_advanced(
return 0;
}

ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference(
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_byReference(
ZSTD_CCtx* cctx, const void* dict, size_t dictSize)
{
return ZSTD_CCtx_loadDictionary_advanced(
Expand Down Expand Up @@ -3794,7 +3794,7 @@ ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize,
&cctxParams, customMem);
}

ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced2(
ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_advanced2(
const void* dict, size_t dictSize,
ZSTD_dictLoadMethod_e dictLoadMethod,
ZSTD_dictContentType_e dictContentType,
Expand Down
Loading

0 comments on commit 87ddbfc

Please sign in to comment.