From e25e4d7ef16b8aa84de7b0c93c48260b68c86fbe Mon Sep 17 00:00:00 2001 From: Intel Date: Wed, 18 Sep 2013 12:00:00 +0200 Subject: [PATCH] mk: shared libraries Allow to build shared libraries (.so) instead of static ones (.a). Signed-off-by: Intel --- app/test/test_red.c | 8 ++++ config/defconfig_x86_64-default-linuxapp-gcc | 5 +++ lib/Makefile | 1 + lib/librte_eal/common/eal_common_cpuflags.c | 38 +++++++++++++------ .../common/include/i686/arch/rte_atomic.h | 18 ++++++++- mk/exec-env/linuxapp/rte.vars.mk | 10 ++++- mk/rte.lib.mk | 35 +++++++++++++++-- mk/rte.vars.mk | 4 ++ 8 files changed, 103 insertions(+), 16 deletions(-) diff --git a/app/test/test_red.c b/app/test/test_red.c index 2fb19383e5..526bfb4f1d 100644 --- a/app/test/test_red.c +++ b/app/test/test_red.c @@ -150,7 +150,15 @@ static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name) static inline void rdtsc_prof_start(struct rdtsc_prof *p) { +#ifdef __PIC__ + asm volatile ( + "mov %%ebx, %%edi\n" + "cpuid\n" + "xchgl %%ebx, %%edi;\n" + : : : "%eax", "%edi", "%ecx", "%edx" ); +#else asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" ); +#endif p->clk_start = rte_rdtsc(); } diff --git a/config/defconfig_x86_64-default-linuxapp-gcc b/config/defconfig_x86_64-default-linuxapp-gcc index e1bcfe59be..d134c4e07c 100644 --- a/config/defconfig_x86_64-default-linuxapp-gcc +++ b/config/defconfig_x86_64-default-linuxapp-gcc @@ -73,6 +73,11 @@ CONFIG_RTE_TOOLCHAIN_GCC=y # CONFIG_RTE_FORCE_INTRINSICS=n +# +# Compile to share library +# +CONFIG_RTE_BUILD_SHARED_LIB=n + # # # Compile libc directory diff --git a/lib/Makefile b/lib/Makefile index efc04bfee0..779c53f3eb 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -54,4 +54,5 @@ ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y) DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni endif +include $(RTE_SDK)/mk/rte.sharelib.mk include $(RTE_SDK)/mk/rte.subdir.mk diff --git a/lib/librte_eal/common/eal_common_cpuflags.c b/lib/librte_eal/common/eal_common_cpuflags.c index 74316e987a..445cfd521c 100644 --- a/lib/librte_eal/common/eal_common_cpuflags.c +++ b/lib/librte_eal/common/eal_common_cpuflags.c @@ -190,17 +190,33 @@ rte_cpu_get_features(struct cpuid_parameters_t params) { int eax, ebx, ecx, edx; /* registers */ - asm volatile ("cpuid" - /* output */ - : "=a" (eax), - "=b" (ebx), - "=c" (ecx), - "=d" (edx) - /* input */ - : "a" (params.eax), - "b" (params.ebx), - "c" (params.ecx), - "d" (params.edx)); +#ifndef __PIC__ + asm volatile ("cpuid" + /* output */ + : "=a" (eax), + "=b" (ebx), + "=c" (ecx), + "=d" (edx) + /* input */ + : "a" (params.eax), + "b" (params.ebx), + "c" (params.ecx), + "d" (params.edx)); +#else + asm volatile ( + "mov %%ebx, %%edi\n" + "cpuid\n" + "xchgl %%ebx, %%edi;\n" + : "=a" (eax), + "=D" (ebx), + "=c" (ecx), + "=d" (edx) + /* input */ + : "a" (params.eax), + "D" (params.ebx), + "c" (params.ecx), + "d" (params.edx)); +#endif switch (params.return_register) { case REG_EAX: diff --git a/lib/librte_eal/common/include/i686/arch/rte_atomic.h b/lib/librte_eal/common/include/i686/arch/rte_atomic.h index 12a9d16818..5a44242da0 100644 --- a/lib/librte_eal/common/include/i686/arch/rte_atomic.h +++ b/lib/librte_eal/common/include/i686/arch/rte_atomic.h @@ -83,17 +83,33 @@ rte_atomic64_cmpset(volatile uint64_t *dst, uint64_t exp, uint64_t src) _exp.u64 = exp; _src.u64 = src; +#ifndef __PIC__ + asm volatile ( + MPLOCKED + "cmpxchg8b (%[dst]);" + "setz %[res];" + : [res] "=a" (res) /* result in eax */ + : [dst] "S" (dst), /* esi */ + "b" (_src.l32), /* ebx */ + "c" (_src.h32), /* ecx */ + "a" (_exp.l32), /* eax */ + "d" (_exp.h32) /* edx */ + : "memory" ); /* no-clobber list */ +#else asm volatile ( + "mov %%ebx, %%edi\n" MPLOCKED "cmpxchg8b (%[dst]);" "setz %[res];" + "xchgl %%ebx, %%edi;\n" : [res] "=a" (res) /* result in eax */ : [dst] "S" (dst), /* esi */ - "b" (_src.l32), /* ebx */ + "D" (_src.l32), /* ebx */ "c" (_src.h32), /* ecx */ "a" (_exp.l32), /* eax */ "d" (_exp.h32) /* edx */ : "memory" ); /* no-clobber list */ +#endif return res; } diff --git a/mk/exec-env/linuxapp/rte.vars.mk b/mk/exec-env/linuxapp/rte.vars.mk index 2a1611d459..eb7474f5ef 100644 --- a/mk/exec-env/linuxapp/rte.vars.mk +++ b/mk/exec-env/linuxapp/rte.vars.mk @@ -39,12 +39,20 @@ # # examples for RTE_EXEC_ENV: linuxapp, baremetal # - +ifeq ($(RTE_BUILD_SHARED_LIB),y) +EXECENV_CFLAGS = -pthread -fPIC +else EXECENV_CFLAGS = -pthread +endif + EXECENV_LDFLAGS = EXECENV_LDLIBS = -lrt -lm EXECENV_ASFLAGS = +ifeq ($(RTE_BUILD_SHARED_LIB),y) +EXECENV_LDLIBS += -lgcc_s +endif + # force applications to link with gcc/icc instead of using ld LINK_USING_CC := 1 diff --git a/mk/rte.lib.mk b/mk/rte.lib.mk index b1b7a7fe6b..f56df5cf97 100644 --- a/mk/rte.lib.mk +++ b/mk/rte.lib.mk @@ -38,6 +38,10 @@ include $(RTE_SDK)/mk/internal/rte.depdirs-pre.mk # VPATH contains at least SRCDIR VPATH += $(SRCDIR) +ifeq ($(RTE_BUILD_SHARED_LIB),y) +LIB := $(patsubst %.a,%.so,$(LIB)) +endif + _BUILD = $(LIB) _INSTALL = $(INSTALL-FILES-y) $(SYMLINK-FILES-y) $(RTE_OUTPUT)/lib/$(LIB) _CLEAN = doclean @@ -64,25 +68,50 @@ O_TO_A_DO = @set -e; \ $(O_TO_A) && \ echo $(O_TO_A_CMD) > $(call exe2cmd,$(@)) +O_TO_S = $(LD) $(CPU_LDFLAGS) -z muldefs -share $(OBJS-y) -o $(LIB) +O_TO_S_STR = $(subst ','\'',$(O_TO_S)) #'# fix syntax highlight +O_TO_S_DISP = $(if $(V),"$(O_TO_S_STR)"," LD $(@)") +O_TO_S_DO = @set -e; \ + echo $(O_TO_S_DISP); \ + $(O_TO_S) && \ + echo $(O_TO_S_CMD) > $(call exe2cmd,$(@)) + -include .$(LIB).cmd # # Archive objects in .a file if needed # +ifeq ($(RTE_BUILD_SHARED_LIB),y) $(LIB): $(OBJS-y) $(DEP_$(LIB)) FORCE @[ -d $(dir $@) ] || mkdir -p $(dir $@) $(if $(D),\ @echo -n "$< -> $@ " ; \ echo -n "file_missing=$(call boolean,$(file_missing)) " ; \ - echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_A_STR))) " ; \ + echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_S_STR))) " ; \ echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \ echo "depfile_newer=$(call boolean,$(depfile_newer)) ") $(if $(or \ $(file_missing),\ - $(call cmdline_changed,$(O_TO_A_STR)),\ + $(call cmdline_changed,$(O_TO_S_STR)),\ $(depfile_missing),\ $(depfile_newer)),\ - $(O_TO_A_DO)) + $(O_TO_S_DO)) +else +$(LIB): $(OBJS-y) $(DEP_$(LIB)) FORCE + @[ -d $(dir $@) ] || mkdir -p $(dir $@) + $(if $(D),\ + @echo -n "$< -> $@ " ; \ + echo -n "file_missing=$(call boolean,$(file_missing)) " ; \ + echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_A_STR))) " ; \ + echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \ + echo "depfile_newer=$(call boolean,$(depfile_newer)) ") + $(if $(or \ + $(file_missing),\ + $(call cmdline_changed,$(O_TO_A_STR)),\ + $(depfile_missing),\ + $(depfile_newer)),\ + $(O_TO_A_DO)) +endif # # install lib in $(RTE_OUTPUT)/lib diff --git a/mk/rte.vars.mk b/mk/rte.vars.mk index 586b844e94..801b5857d6 100644 --- a/mk/rte.vars.mk +++ b/mk/rte.vars.mk @@ -63,6 +63,10 @@ ifneq ($(BUILDING_RTE_SDK),) RTE_TOOLCHAIN := $(CONFIG_RTE_TOOLCHAIN:"%"=%) RTE_TARGET := $(RTE_ARCH)-$(RTE_MACHINE)-$(RTE_EXEC_ENV)-$(RTE_TOOLCHAIN) RTE_SDK_BIN := $(RTE_OUTPUT) + RTE_BUILD_SHARED_LIB := $(CONFIG_RTE_BUILD_SHARED_LIB:"%"=%) + ifeq ($(RTE_BUILD_SHARED_LIB),) + RTE_BUILD_SHARED_LIB := n + endif endif # RTE_TARGET is deducted from config when we are building the SDK. -- 2.20.1