From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <olivier.matz@6wind.com>
Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com
 [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 4DD503B5
 for <dev@dpdk.org>; Fri, 27 Jan 2017 15:23:34 +0100 (CET)
Received: from glumotte.dev.6wind.com (unknown [10.16.0.195])
 by proxy.6wind.com (Postfix) with ESMTP id BBFB3276ED;
 Fri, 27 Jan 2017 15:23:29 +0100 (CET)
From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org,
	byron.marohn@intel.com,
	pablo.de.lara.guarch@intel.com
Date: Fri, 27 Jan 2017 15:23:17 +0100
Message-Id: <1485526997-31111-1-git-send-email-olivier.matz@6wind.com>
X-Mailer: git-send-email 2.8.1
Subject: [dpdk-dev] [PATCH] efd: fix compilation by removing dep to libmath
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 27 Jan 2017 14:23:34 -0000

When we compile the dpdk with:
  CONFIG_RTE_LIBRTE_EFD=y
  CONFIG_RTE_LIBRTE_NFP_PMD=n
  CONFIG_RTE_LIBRTE_THUNDERX_NICVF_PMD=n
  CONFIG_RTE_LIBRTE_SCHED=n
  CONFIG_RTE_LIBRTE_METER=n

The linker gives the following error:
  lib/librte_efd.a(rte_efd.o): In function `rte_efd_create':
  lib/librte_efd/rte_efd.c:560: undefined reference to `log2'
  collect2: error: ld returned 1 exit status

This is because the '-lm' is missing in mk/rte.app.mk.

An alternative, which is proposed by this patch, is to use the compiler
builtin rte_bsf32() to process log2 instead of the libmath log2() that
requires to include math.h and link with -lm.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 lib/librte_efd/Makefile  | 2 --
 lib/librte_efd/rte_efd.c | 3 +--
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/librte_efd/Makefile b/lib/librte_efd/Makefile
index 8848c58..a442c62 100644
--- a/lib/librte_efd/Makefile
+++ b/lib/librte_efd/Makefile
@@ -34,8 +34,6 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_efd.a
 
-LDLIBS += -lm
-
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)
 
diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c
index 68e6dab..f601d62 100644
--- a/lib/librte_efd/rte_efd.c
+++ b/lib/librte_efd/rte_efd.c
@@ -36,7 +36,6 @@
 #include <inttypes.h>
 #include <errno.h>
 #include <stdarg.h>
-#include <math.h>
 #include <sys/queue.h>
 
 #include <rte_log.h>
@@ -557,7 +556,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
 		num_chunks = rte_align32pow2((max_num_rules /
 			EFD_TARGET_CHUNK_NUM_RULES) + 1);
 
-	num_chunks_shift = log2(num_chunks);
+	num_chunks_shift = rte_bsf32(num_chunks);
 
 	rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
 
-- 
2.8.1