From c86ca8c0f0ef759db2cda41def6f9ff4830e5a13 Mon Sep 17 00:00:00 2001 From: Leonard Lausen Date: Tue, 2 Oct 2018 07:11:00 +0000 Subject: [PATCH] Fix static / dynamic linking of gperftools and jemalloc --- Makefile | 63 +++++++++++++++----------------------------------- make/config.mk | 6 +++++ 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index 69b25daa9d1c..1c8d70ecc695 100644 --- a/Makefile +++ b/Makefile @@ -231,25 +231,19 @@ endif # gperftools malloc library (tcmalloc) ifeq ($(USE_GPERFTOOLS), 1) -FIND_LIBFILE=$(wildcard $(USE_GPERFTOOLS_PATH)/libtcmalloc.a) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard $(USE_GPERFTOOLS_PATH)/libtcmalloc.so) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /lib/libtcmalloc.a) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /lib/libtcmalloc.so) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib/libtcmalloc.a) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib/libtcmalloc.so) +FIND_LIBFILEEXT=so +ifeq ($(USE_GPERFTOOLS_STATIC), 1) +FIND_LIBFILEEXT=a +endif +FIND_LIBFILE=$(wildcard $(USE_GPERFTOOLS_PATH)/libtcmalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/local/lib/libtcmalloc.a) +FIND_LIBFILE=$(wildcard /lib/libtcmalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/local/lib/libtcmalloc.so) +FIND_LIBFILE=$(wildcard /usr/lib/libtcmalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib64/libtcmalloc.a) +FIND_LIBFILE=$(wildcard /usr/local/lib/libtcmalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib64/libtcmalloc.so) +FIND_LIBFILE=$(wildcard /usr/lib64/libtcmalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) USE_GPERFTOOLS=0 endif @@ -257,11 +251,6 @@ endif endif endif endif -endif -endif -endif -endif -endif ifeq ($(USE_GPERFTOOLS), 1) CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free LDFLAGS += $(FIND_LIBFILE) @@ -270,29 +259,21 @@ endif # jemalloc malloc library (if not using gperftools) else ifeq ($(USE_JEMALLOC), 1) -FIND_LIBFILE=$(wildcard $(USE_JEMALLOC_PATH)/libjemalloc.a) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard $(USE_JEMALLOC_PATH)/libjemalloc.so) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /lib/libjemalloc.a) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /lib/libjemalloc.so) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib/libjemalloc.a) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib/libjemalloc.so) -ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/local/lib/libjemalloc.a) +FIND_LIBFILEEXT=so +ifeq ($(USE_JEMALLOC_STATIC), 1) +FIND_LIBFILEEXT=a +endif +FIND_LIBFILE=$(wildcard $(USE_JEMALLOC_PATH)/libjemalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/local/lib/libjemalloc.so) +FIND_LIBFILE=$(wildcard /lib/libjemalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib/x86_64-linux-gnu/libjemalloc.a) +FIND_LIBFILE=$(wildcard /usr/lib/libjemalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib/x86_64-linux-gnu/libjemalloc.so) +FIND_LIBFILE=$(wildcard /usr/local/lib/libjemalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib64/libjemalloc.a) +FIND_LIBFILE=$(wildcard /usr/lib/x86_64-linux-gnu/libjemalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) -FIND_LIBFILE=$(wildcard /usr/lib64/libjemalloc.so) +FIND_LIBFILE=$(wildcard /usr/lib64/libjemalloc.$(FIND_LIBFILEEXT)) ifeq (,$(FIND_LIBFILE)) USE_JEMALLOC=0 endif @@ -301,12 +282,6 @@ endif endif endif endif -endif -endif -endif -endif -endif -endif ifeq ($(USE_JEMALLOC), 1) CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc \ -fno-builtin-free -DUSE_JEMALLOC diff --git a/make/config.mk b/make/config.mk index 2fd8f6ec22f6..03f438db89d5 100644 --- a/make/config.mk +++ b/make/config.mk @@ -182,12 +182,18 @@ USE_GPERFTOOLS = 1 # path to gperftools (tcmalloc) library in case of a non-standard installation USE_GPERFTOOLS_PATH = +# Link gperftools statically +USE_GPERFTOOLS_STATIC = + # Use JEMalloc if found, and not using gperftools USE_JEMALLOC = 1 # path to jemalloc library in case of a non-standard installation USE_JEMALLOC_PATH = +# Link jemalloc statically +USE_JEMALLOC_STATIC = + #---------------------------- # additional operators #----------------------------