Skip to content

Commit

Permalink
make "-fvisibility=hidden" and static link rdb-cli with librdb
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Oct 15, 2023
1 parent f17a7ec commit fddf5a9
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/librdb-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
#endif

#ifndef _LIBRDB_API
#define _LIBRDB_API
#define _LIBRDB_API __attribute__((visibility("default")))
#endif

typedef char *RdbBulk;
Expand Down
2 changes: 1 addition & 1 deletion deps/redis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down
5 changes: 3 additions & 2 deletions deps/redis/crc64.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define CRC64_H

#include <stdint.h>
#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);
Expand Down
27 changes: 27 additions & 0 deletions deps/redis/librdb-hidden-api.h
Original file line number Diff line number Diff line change
@@ -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__*/
17 changes: 9 additions & 8 deletions deps/redis/rax.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define RAX_H

#include <stdint.h>
#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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions deps/redis/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIBRDB_UTIL_H

#include <stdint.h>
#include "librdb-hidden-api.h"

#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
Expand All @@ -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);
Expand All @@ -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*/
6 changes: 3 additions & 3 deletions src/cli/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down

0 comments on commit fddf5a9

Please sign in to comment.