Skip to content

cmake: apply static API visibility to shared library - #4789

Open
yqtian-se wants to merge 1 commit into
facebook:devfrom
yqtian-se:fix-shared-static-api-visibility
Open

yqtian-se wants to merge 1 commit into
facebook:devfrom
yqtian-se:fix-shared-static-api-visibility

Conversation

@yqtian-se

Copy link
Copy Markdown

zstd distinguishes its stable API from functions declared with
ZSTDLIB_STATIC_API and ZDICTLIB_STATIC_API. The latter macros can be set to
hidden visibility when those static-only APIs should not be exported from the
shared library.

The CMake build exposes cache settings for both macros and accepts hidden,
but passes the resulting definitions only to libzstd_static. Consequently,
configuring a shared build with
-DZSTDLIB_STATIC_API=hidden -DZDICTLIB_STATIC_API=hidden succeeds without
applying either definition to libzstd_shared; its shared object continues to
export the static-only APIs.

This change passes both existing definitions to libzstd_shared, where their
visibility attributes can affect the shared export set. Both cache settings
remain empty by default, so the default build is unchanged.

Validation:

  • the patched shared compile commands contain both hidden definitions;
  • the shared export set falls from 188 to 75 symbols;
  • the 113 removed symbols are the requested ZSTD_* and ZDICT_* static-only
    APIs, while stable APIs remain exported;
  • all four configured CMake tests pass, including the fuzzer test.

This is related to the broader CMake/Make consistency discussion in issue
#2261, but specifically fixes the two existing CMake cache settings.

The ZSTDLIB_STATIC_API and ZDICTLIB_STATIC_API cache settings are currently applied only to libzstd_static. Setting them to hidden therefore leaves static-only APIs exported from libzstd_shared.

Apply the existing definitions to the shared target as well so the documented visibility controls affect the library for which symbol hiding matters.

Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>
@meta-cla meta-cla Bot added the CLA Signed label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant