Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Hide private symbols in shared library #12944

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,16 @@ if(ROCKSDB_BUILD_SHARED)
VERSION ${rocksdb_VERSION}
SOVERSION ${rocksdb_VERSION_MAJOR}
OUTPUT_NAME "rocksdb${ARTIFACT_SUFFIX}")

if(HIDE_PRIVATE_SYMBOLS AND CMAKE_BUILD_TYPE STREQUAL "Release") # Do not export private symbols in output shared library
message("HIDING symbols")
set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
target_compile_definitions(${ROCKSDB_SHARED_LIB} PUBLIC HIDE_PRIVATE_SYMBOLS)
endif()

endif()
endif()

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ endif
ifeq ($(DEBUG_LEVEL),0)
OPT += -DNDEBUG

#Only in non debug mode
ifeq ($(HIDE_PRIVATE_SYMBOLS), 1)
CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -DHIDE_PRIVATE_SYMBOLS
endif

ifneq ($(USE_RTTI), 1)
CXXFLAGS += -fno-rtti
else
Expand Down
5 changes: 5 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@
#define ROCKSDB_LIBRARY_API
#endif
#else

#ifdef HIDE_PRIVATE_SYMBOLS
#define ROCKSDB_LIBRARY_API __attribute__((visibility("default")))
#else
#define ROCKSDB_LIBRARY_API
#endif

#endif
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
Loading