diff --git a/api/librdb-api.h b/api/librdb-api.h index 76a4048..0f707ec 100644 --- a/api/librdb-api.h +++ b/api/librdb-api.h @@ -8,7 +8,7 @@ extern "C" { #endif #ifndef _LIBRDB_API -#define _LIBRDB_API +#define _LIBRDB_API __attribute__((visibility("default"))) #endif typedef char *RdbBulk; diff --git a/deps/redis/Makefile b/deps/redis/Makefile index 40eda6d..a7b0f13 100644 --- a/deps/redis/Makefile +++ b/deps/redis/Makefile @@ -5,7 +5,7 @@ OPTIMIZATION?=-O3 STD = -std=c99 WARNS = -Wall -Wextra -pedantic -Werror -CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(WARNS) +CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(WARNS) -fvisibility=hidden DEBUG = -g3 -DDEBUG=1 LIBS = diff --git a/deps/redis/crc64.h b/deps/redis/crc64.h index e0fccd9..d41155b 100644 --- a/deps/redis/crc64.h +++ b/deps/redis/crc64.h @@ -2,9 +2,10 @@ #define CRC64_H #include +#include "librdb-hidden-api.h" -void crc64_init(void); -uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); +_LIBRDB_HIDDEN_API void crc64_init(void); +_LIBRDB_HIDDEN_API uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); #ifdef REDIS_TEST int crc64Test(int argc, char *argv[], int flags); diff --git a/deps/redis/librdb-hidden-api.h b/deps/redis/librdb-hidden-api.h new file mode 100644 index 0000000..f7ca3e9 --- /dev/null +++ b/deps/redis/librdb-hidden-api.h @@ -0,0 +1,27 @@ +/* + * The core library of LIBRDB is librdb.so. It is also responsible for linking + * and combining Redis object files from this folder. The extension library of + * LIBRDB (librdb-ext.so) also requires certain functionality from this folder, + * such as the use of the rax data structure or CRC. + * + * Instead of refactoring and creating an additional shared library, or making + * copies for each library (with all the associated implications) we shall expose + * specific symbols from librdb.so that are needed by librdb-ext.so. These symbols + * won't be documented in the API, but they will be available for use. Since we + * compile by default with hidden visibility, we need to mark them explicitly as + * visible using the following macro. + * + * While it might initially seem cumbersome to manually designate each function as + * visible, this approach has its benefits. By carefully selecting the functions + * to expose, we are encouraged to contemplate what we are exposing and why. + * Moreover, it helps prevent the cluttering clients of librdb with unnecessary + * symbols. + * + */ + +#ifndef __HIDDEN_API_H__ +#define __HIDDEN_API_H__ + +#define _LIBRDB_HIDDEN_API __attribute__((visibility("default"))) + +#endif /*__HIDDEN_API_H__*/ diff --git a/deps/redis/rax.h b/deps/redis/rax.h index a836b84..5756632 100644 --- a/deps/redis/rax.h +++ b/deps/redis/rax.h @@ -32,6 +32,7 @@ #define RAX_H #include +#include "librdb-hidden-api.h" /* Representation of a radix tree as implemented in this file, that contains * the strings "foo", "foobar" and "footer" after the insertion of each @@ -186,19 +187,19 @@ typedef struct raxIterator { } raxIterator; /* A special pointer returned for not found items. */ -extern void *raxNotFound; +_LIBRDB_HIDDEN_API extern void *raxNotFound; /* Exported API. */ -rax *raxNew(void); +_LIBRDB_HIDDEN_API rax *raxNew(void); int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old); -int raxTryInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old); +_LIBRDB_HIDDEN_API int raxTryInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old); int raxRemove(rax *rax, unsigned char *s, size_t len, void **old); -void *raxFind(rax *rax, unsigned char *s, size_t len); -void raxFree(rax *rax); +_LIBRDB_HIDDEN_API void *raxFind(rax *rax, unsigned char *s, size_t len); +_LIBRDB_HIDDEN_API void raxFree(rax *rax); void raxFreeWithCallback(rax *rax, void (*free_callback)(void*)); -void raxStart(raxIterator *it, rax *rt); -int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len); -int raxNext(raxIterator *it); +_LIBRDB_HIDDEN_API void raxStart(raxIterator *it, rax *rt); +_LIBRDB_HIDDEN_API int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len); +_LIBRDB_HIDDEN_API int raxNext(raxIterator *it); int raxPrev(raxIterator *it); //int raxRandomWalk(raxIterator *it, size_t steps); int raxCompare(raxIterator *iter, const char *op, unsigned char *key, size_t key_len); diff --git a/deps/redis/util.h b/deps/redis/util.h index 4c7e541..0aa1508 100644 --- a/deps/redis/util.h +++ b/deps/redis/util.h @@ -2,6 +2,7 @@ #define LIBRDB_UTIL_H #include +#include "librdb-hidden-api.h" #ifdef __GNUC__ #define likely(x) __builtin_expect(!!(x), 1) @@ -19,7 +20,7 @@ #define MAX_D2STRING_CHARS 128 int string2ll(const char *s, size_t slen, long long *value); -int ll2string(char *s, size_t len, long long value); +_LIBRDB_HIDDEN_API int ll2string(char *s, size_t len, long long value); int ull2string(char *s, size_t len, unsigned long long value); int lpStringToInt64(const char *s, unsigned long slen, int64_t *value); unsigned int getEnvVar(const char* varName, unsigned int defaultVal); @@ -29,6 +30,6 @@ unsigned int getEnvVar(const char* varName, unsigned int defaultVal); * incompatibilities as you can also convert double to string that results in * loss of precision, or it might not represent inf, -inf or nan values * similar to this function output. */ -int d2string(char *buf, size_t len, double value); +_LIBRDB_HIDDEN_API int d2string(char *buf, size_t len, double value); #endif /*LIBRDB_UTIL_H*/ diff --git a/src/cli/Makefile b/src/cli/Makefile index d445148..a94ef0a 100644 --- a/src/cli/Makefile +++ b/src/cli/Makefile @@ -1,8 +1,8 @@ default: all -LIB_NAME = rdb LIB_DIR = ../../lib -LIB_NAME_EXT = $(LIB_NAME)-ext +LIB_NAME = librdb.a +LIB_NAME_EXT = librdb-ext.a # Artifacts: TARGET_APP = rdb-cli @@ -19,7 +19,7 @@ STACK = -fstack-protector-all -Wstack-protector WARNS = -Wall -Wextra -pedantic -Werror CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(STACK) $(WARNS) DEBUG = -g3 -DDEBUG=1 -LIBS = -L /usr/lib -L $(LIB_DIR) -l $(LIB_NAME) -l $(LIB_NAME_EXT) +LIBS = -L /usr/lib -L $(LIB_DIR) -l:$(LIB_NAME_EXT) -l:$(LIB_NAME) ifeq ($(BUILD_TLS),yes) CFLAGS+=-DUSE_OPENSSL=1 diff --git a/src/ext/Makefile b/src/ext/Makefile index cf821ad..582d1c5 100644 --- a/src/ext/Makefile +++ b/src/ext/Makefile @@ -13,13 +13,14 @@ TARGET_LIB_STATIC_EXT = $(LIB_DIR)/lib$(LIB_NAME_EXT).a SOURCES = $(notdir $(basename $(wildcard *.c))) OBJECTS = $(patsubst %,%.o,$(SOURCES)) + OPTIMIZATION?=-O3 LIBRDB_DEBUG?=0 STD = -std=c99 STACK = -fstack-protector-all -Wstack-protector WARNS = -Wall -Wextra -pedantic -Werror -CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(STACK) $(WARNS) +CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(STACK) $(WARNS) -fvisibility=hidden DEBUG = -g3 -DLIBRDB_DEBUG=$(LIBRDB_DEBUG) LDFLAGS = LIBS = -L $(LIB_DIR) -l $(LIB_NAME) @@ -37,6 +38,7 @@ $(TARGET_LIB_EXT): $(OBJECTS) $(TARGET_LIB_STATIC_EXT): $(OBJECTS) ar rcs $@ $^ +# Include object file dependencies -include $(OBJECTS:.o=.d) %.o: %.c diff --git a/src/lib/Makefile b/src/lib/Makefile index cf61b64..fd62724 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -21,7 +21,7 @@ LIBRDB_DEBUG?=0 STD = -std=c99 STACK = -fstack-protector-all -Wstack-protector WARNS = -Wall -Wextra -pedantic -Werror -CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(STACK) $(WARNS) +CFLAGS = -fPIC $(OPTIMIZATION) $(STD) $(STACK) $(WARNS) -fvisibility=hidden DEBUG = -g3 LIBS =