From 2ebe3a468cd6da1bf3caa4506619423c5e87edb8 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 16 Aug 2025 16:35:12 +0300 Subject: [PATCH] Mark all symbols hidden by default, export only required ones --- src/CMakeLists.txt | 5 ++++- src/blockstore/blockstore.h | 4 ++-- src/blockstore/fio_engine.cpp | 2 +- src/client/cluster_client.h | 4 ++-- src/client/etcd_state_client.h | 2 +- src/client/fio_cluster.cpp | 2 +- src/client/fio_sec_osd.cpp | 2 +- src/client/messenger.h | 2 +- src/client/msgr_op.h | 2 +- src/client/pg_states.h | 4 ++++ src/client/qemu_driver.c | 4 ++-- src/client/vitastor_c.h | 4 ++++ src/kv/vitastor_kv.h | 2 +- src/liburing/include/liburing.h | 1 - src/util/addr_util.h | 4 ++++ src/util/allocator.h | 4 ++++ src/util/crc32c.h | 4 ++++ src/util/epoll_manager.h | 2 +- src/util/json_util.h | 4 ++++ src/util/malloc_or_die.h | 4 ++++ src/util/ringloop.h | 2 +- src/util/rw_blocking.h | 4 ++++ src/util/sha256.h | 4 ++++ src/util/str_util.h | 4 ++++ src/util/timerfd_manager.h | 2 +- 25 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 684bd154..101fe36a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,12 +21,15 @@ if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$") endif() add_definitions(-DVITASTOR_VERSION="2.2.3") -add_definitions(-D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fdiagnostics-color=always -fno-omit-frame-pointer -I ${CMAKE_SOURCE_DIR}/src) +add_definitions(-D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fdiagnostics-color=always -fno-omit-frame-pointer -fvisibility=hidden -I ${CMAKE_SOURCE_DIR}/src) add_link_options(-fno-omit-frame-pointer) if (${WITH_ASAN}) add_definitions(-fsanitize=address) add_link_options(-fsanitize=address -fno-omit-frame-pointer) endif (${WITH_ASAN}) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility-inlines-hidden") +set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -fvisibility-inlines-hidden") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fvisibility-inlines-hidden") set(CMAKE_BUILD_TYPE RelWithDebInfo) string(REGEX REPLACE "([\\/\\-]O)[^ \t\r\n]*" "\\13" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") diff --git a/src/blockstore/blockstore.h b/src/blockstore/blockstore.h index 80bfa2d4..af1d3004 100644 --- a/src/blockstore/blockstore.h +++ b/src/blockstore/blockstore.h @@ -135,7 +135,7 @@ Output: */ -struct blockstore_op_t +struct __attribute__ ((visibility("default"))) blockstore_op_t { // operation uint64_t opcode = 0; @@ -173,7 +173,7 @@ typedef std::map blockstore_config_t; class blockstore_impl_t; -class blockstore_t +class __attribute__((visibility("default"))) blockstore_t { blockstore_impl_t *impl; public: diff --git a/src/blockstore/fio_engine.cpp b/src/blockstore/fio_engine.cpp index e3eb3952..ea4c4058 100644 --- a/src/blockstore/fio_engine.cpp +++ b/src/blockstore/fio_engine.cpp @@ -301,7 +301,7 @@ static int bs_invalidate(struct thread_data *td, struct fio_file *f) return 0; } -struct ioengine_ops ioengine = { +struct ioengine_ops __attribute__((visibility("default"))) ioengine = { .name = "vitastor_blockstore", .version = FIO_IOOPS_VERSION, .flags = FIO_MEMALIGN | FIO_DISKLESSIO | FIO_NOEXTEND, diff --git a/src/client/cluster_client.h b/src/client/cluster_client.h index 0e0d0539..ad148972 100644 --- a/src/client/cluster_client.h +++ b/src/client/cluster_client.h @@ -31,7 +31,7 @@ struct cluster_op_part_t osd_op_t op; }; -struct cluster_op_t +struct __attribute__((visibility("default"))) cluster_op_t { uint64_t opcode; // OSD_OP_READ, OSD_OP_WRITE, OSD_OP_SYNC, OSD_OP_DELETE, OSD_OP_READ_BITMAP, OSD_OP_READ_CHAIN_BITMAP uint64_t inode; @@ -81,7 +81,7 @@ struct inode_list_pg_t; class writeback_cache_t; // FIXME: Split into public and private interfaces -class cluster_client_t +class __attribute__((visibility("default"))) cluster_client_t { #ifdef __MOCK__ public: diff --git a/src/client/etcd_state_client.h b/src/client/etcd_state_client.h index a664ec35..c1e0f97f 100644 --- a/src/client/etcd_state_client.h +++ b/src/client/etcd_state_client.h @@ -92,7 +92,7 @@ struct inode_watch_t struct http_co_t; -struct etcd_state_client_t +struct __attribute__((visibility("default"))) etcd_state_client_t { protected: std::vector local_ips; diff --git a/src/client/fio_cluster.cpp b/src/client/fio_cluster.cpp index 89f579f1..3515d96a 100644 --- a/src/client/fio_cluster.cpp +++ b/src/client/fio_cluster.cpp @@ -525,7 +525,7 @@ static int sec_invalidate(struct thread_data *td, struct fio_file *f) return 0; } -struct ioengine_ops ioengine = { +struct ioengine_ops __attribute__((visibility("default"))) ioengine = { .name = "vitastor_cluster", .version = FIO_IOOPS_VERSION, .flags = FIO_MEMALIGN | FIO_DISKLESSIO | FIO_NOEXTEND, diff --git a/src/client/fio_sec_osd.cpp b/src/client/fio_sec_osd.cpp index d9ab3387..e6219342 100644 --- a/src/client/fio_sec_osd.cpp +++ b/src/client/fio_sec_osd.cpp @@ -437,7 +437,7 @@ static int sec_invalidate(struct thread_data *td, struct fio_file *f) return 0; } -struct ioengine_ops ioengine = { +struct ioengine_ops __attribute__((visibility("default"))) ioengine = { .name = "vitastor_secondary_osd", .version = FIO_IOOPS_VERSION, .flags = FIO_MEMALIGN | FIO_DISKLESSIO | FIO_NOEXTEND, diff --git a/src/client/messenger.h b/src/client/messenger.h index 24443a18..a52634a8 100644 --- a/src/client/messenger.h +++ b/src/client/messenger.h @@ -174,7 +174,7 @@ struct osd_messenger_t; struct rdmacm_connecting_t; #endif -struct osd_messenger_t +struct __attribute__((visibility("default"))) osd_messenger_t { protected: int keepalive_timer_id = -1; diff --git a/src/client/msgr_op.h b/src/client/msgr_op.h index 300c41fd..61fd2429 100644 --- a/src/client/msgr_op.h +++ b/src/client/msgr_op.h @@ -152,7 +152,7 @@ struct blockstore_op_t; struct osd_primary_op_data_t; -struct osd_op_t +struct __attribute__((visibility("default"))) osd_op_t { timespec tv_begin = { 0 }, tv_end = { 0 }; uint64_t op_type = OSD_OP_IN; diff --git a/src/client/pg_states.h b/src/client/pg_states.h index c2e21c38..54d5215e 100644 --- a/src/client/pg_states.h +++ b/src/client/pg_states.h @@ -3,6 +3,8 @@ #pragma once +#pragma GCC visibility push(default) + // Placement group states // STARTING -> [acquire lock] -> PEERING -> INCOMPLETE|ACTIVE // ACTIVE -> REPEERING -> PEERING @@ -50,3 +52,5 @@ extern const int pg_state_bit_count; extern const int object_state_bits[]; extern const char *object_state_names[]; extern const int object_state_bit_count; + +#pragma GCC visibility pop diff --git a/src/client/qemu_driver.c b/src/client/qemu_driver.c index 7c400f08..d8356dab 100644 --- a/src/client/qemu_driver.c +++ b/src/client/qemu_driver.c @@ -57,11 +57,11 @@ #include "vitastor_c.h" #ifdef VITASTOR_SOURCE_TREE -void qemu_module_dummy(void) +void __attribute__((visibility("default"))) qemu_module_dummy(void) { } -void DSO_STAMP_FUN(void) +void __attribute__((visibility("default"))) DSO_STAMP_FUN(void) { } #endif diff --git a/src/client/vitastor_c.h b/src/client/vitastor_c.h index ae4f1fec..7849e546 100644 --- a/src/client/vitastor_c.h +++ b/src/client/vitastor_c.h @@ -22,6 +22,8 @@ #include #include +#pragma GCC visibility push(default) + #ifdef __cplusplus extern "C" { #endif @@ -85,4 +87,6 @@ uint32_t vitastor_c_inode_get_immediate_commit(vitastor_c *client, uint64_t inod } #endif +#pragma GCC visibility pop + #endif diff --git a/src/kv/vitastor_kv.h b/src/kv/vitastor_kv.h index d7281a54..55de8c68 100644 --- a/src/kv/vitastor_kv.h +++ b/src/kv/vitastor_kv.h @@ -19,7 +19,7 @@ class cluster_client_t; struct kv_db_t; -struct vitastorkv_dbw_t +struct __attribute__((visibility("default"))) vitastorkv_dbw_t { // cli = vitastor_c_get_internal_client(client) vitastorkv_dbw_t(cluster_client_t *cli); diff --git a/src/liburing/include/liburing.h b/src/liburing/include/liburing.h index 96eeed3b..c2c90151 100644 --- a/src/liburing/include/liburing.h +++ b/src/liburing/include/liburing.h @@ -19,7 +19,6 @@ #include "liburing/io_uring_version.h" #include "liburing/barrier.h" - #ifndef uring_unlikely #define uring_unlikely(cond) __builtin_expect(!!(cond), 0) #endif diff --git a/src/util/addr_util.h b/src/util/addr_util.h index e8a044d3..2d77965b 100644 --- a/src/util/addr_util.h +++ b/src/util/addr_util.h @@ -13,6 +13,8 @@ struct addr_mask_t uint8_t bits; }; +#pragma GCC visibility push(default) + bool string_to_addr(std::string str, bool parse_port, int default_port, struct sockaddr_storage *addr); std::string addr_to_string(const sockaddr_storage &addr); addr_mask_t cidr_parse(std::string mask); @@ -22,3 +24,5 @@ bool cidr_sockaddr_match(const sockaddr_storage &addr, const addr_mask_t &mask); std::vector getifaddr_list(const std::vector & masks = std::vector(), bool include_v6 = false); int create_and_bind_socket(std::string bind_address, int bind_port, int listen_backlog, int *listening_port); std::string gethostname_str(); + +#pragma GCC visibility pop diff --git a/src/util/allocator.h b/src/util/allocator.h index 336a400d..d35f5664 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -5,6 +5,8 @@ #include +#pragma GCC visibility push(default) + // Hierarchical bitmap allocator class allocator_t { @@ -25,3 +27,5 @@ public: void bitmap_set(void *bitmap, uint64_t start, uint64_t len, uint64_t bitmap_granularity); void bitmap_clear(void *bitmap, uint64_t start, uint64_t len, uint64_t bitmap_granularity); bool bitmap_check(void *bitmap, uint64_t start, uint64_t len, uint64_t bitmap_granularity); + +#pragma GCC visibility pop diff --git a/src/util/crc32c.h b/src/util/crc32c.h index c5800939..a1b61114 100644 --- a/src/util/crc32c.h +++ b/src/util/crc32c.h @@ -8,6 +8,8 @@ // unsigned __int64 _mm_crc32_u64 (unsigned __int64 crc, unsigned __int64 v) // unsigned int _mm_crc32_u8 (unsigned int crc, unsigned char v) +#pragma GCC visibility push(default) + #ifdef __cplusplus extern "C" { #endif @@ -17,3 +19,5 @@ uint32_t crc32c_nopad(uint32_t prev_crc, const void *buf, size_t len, size_t lef #ifdef __cplusplus }; #endif + +#pragma GCC visibility pop diff --git a/src/util/epoll_manager.h b/src/util/epoll_manager.h index 2316d329..96a1c8b3 100644 --- a/src/util/epoll_manager.h +++ b/src/util/epoll_manager.h @@ -8,7 +8,7 @@ #include "ringloop.h" #include "timerfd_manager.h" -class epoll_manager_t +class __attribute__((visibility("default"))) epoll_manager_t { int epoll_fd; bool pending; diff --git a/src/util/json_util.h b/src/util/json_util.h index 7594860d..b091df9a 100644 --- a/src/util/json_util.h +++ b/src/util/json_util.h @@ -8,7 +8,11 @@ #include "json11/json11.hpp" +#pragma GCC visibility push(default) + std::map json_to_string_map(const json11::Json::object & config); bool json_is_true(const json11::Json & val); bool json_is_false(const json11::Json & val); std::string implode(const std::string & sep, json11::Json array); + +#pragma GCC visibility pop diff --git a/src/util/malloc_or_die.h b/src/util/malloc_or_die.h index 89ea0511..f35d2a8d 100644 --- a/src/util/malloc_or_die.h +++ b/src/util/malloc_or_die.h @@ -6,6 +6,8 @@ #include #include +#pragma GCC visibility push(default) + inline void* memalign_or_die(size_t alignment, size_t size) { void *buf = memalign(alignment, size); @@ -49,3 +51,5 @@ inline void* calloc_or_die(size_t nmemb, size_t size) } return buf; } + +#pragma GCC visibility pop diff --git a/src/util/ringloop.h b/src/util/ringloop.h index 916f6e58..0990d729 100644 --- a/src/util/ringloop.h +++ b/src/util/ringloop.h @@ -32,7 +32,7 @@ struct ring_consumer_t std::function loop; }; -class ring_loop_t +class __attribute__((visibility("default"))) ring_loop_t { std::vector> immediate_queue, immediate_queue2; std::vector consumers; diff --git a/src/util/rw_blocking.h b/src/util/rw_blocking.h index 1a6f41d7..983b4ed7 100644 --- a/src/util/rw_blocking.h +++ b/src/util/rw_blocking.h @@ -6,8 +6,12 @@ #include #include +#pragma GCC visibility push(default) + size_t read_blocking(int fd, void *read_buf, size_t remaining); size_t write_blocking(int fd, void *write_buf, size_t remaining); int readv_blocking(int fd, iovec *iov, int iovcnt); int writev_blocking(int fd, iovec *iov, int iovcnt); int sendv_blocking(int fd, iovec *iov, int iovcnt, int flags); + +#pragma GCC visibility pop diff --git a/src/util/sha256.h b/src/util/sha256.h index 17987c62..5bdd94fa 100644 --- a/src/util/sha256.h +++ b/src/util/sha256.h @@ -12,6 +12,8 @@ /*************************** HEADER FILES ***************************/ #include +#pragma GCC visibility push(default) + /****************************** MACROS ******************************/ #define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest @@ -38,4 +40,6 @@ void sha256_final(SHA256_CTX *ctx, BYTE hash[]); }; #endif +#pragma GCC visibility pop + #endif // SHA256_H diff --git a/src/util/str_util.h b/src/util/str_util.h index 5e8b5cb3..c601122f 100644 --- a/src/util/str_util.h +++ b/src/util/str_util.h @@ -8,6 +8,8 @@ #define is_white(a) ((a) == ' ' || (a) == '\t' || (a) == '\r' || (a) == '\n') +#pragma GCC visibility push(default) + std::string base64_encode(const std::string &in); std::string base64_decode(const std::string &in); uint64_t parse_size(std::string size_str, bool *ok = NULL); @@ -32,3 +34,5 @@ std::string addslashes(const std::string & str, const char *toescape = "\\\""); std::string realpath_str(std::string path, bool nofail = true); std::string format_datetime(uint64_t unixtime); bool is_zero(void *buf, size_t size); + +#pragma GCC visibility pop diff --git a/src/util/timerfd_manager.h b/src/util/timerfd_manager.h index 6525579e..58c58465 100644 --- a/src/util/timerfd_manager.h +++ b/src/util/timerfd_manager.h @@ -16,7 +16,7 @@ struct timerfd_timer_t std::function callback; }; -class timerfd_manager_t +class __attribute__((visibility("default"))) timerfd_manager_t { int wait_state = 0; int timerfd;