eal: fix compiler detection in public headers
PATCH 1/1 eal: fix compiler detection in public headers
RTE_TOOLCHAIN_* macros are defining the target compiler. Some API may be used in a host application like pmdinfogen. That's why the the public headers should check the effective compiler in use instead of the target compiler.
Detecting the compiler with macros is easy, except for __GNUC__ which is defined in all compilers supporting some GNU compatibility.
It is improved by defining RTE_CC_CLANG, RTE_CC_ICC and RTE_CC_GCC. The extra macro RTE_CC_IS_GNU is defined to 0 or 1 in GCC case, so it can be used simply with #if.
---
This patch is probably useless.
The first intent was fixing pmdinfogen compilation with clang while compiling the target with GCC, with MinGW support patch.
This case is now better fixed with a patch removing EAL dependencies from the PCI library, which drops rte_common.h inclusion from pmdinfogen:
http://patches.dpdk.org/patch/66701/
As a consequence, I send this EAL patch just in case we need it in future. We can decide to apply or leave it.
--- .../common/include/arch/arm/rte_memcpy_64.h | 2 +- .../common/include/arch/arm/rte_vect.h | 4 ++-- lib/librte_eal/common/include/rte_common.h | 19 +++++++++++++++++-- lib/librte_table/rte_lru_x86.h | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-)
lib/librte_eal/common/include/arch/arm/rte_memcpy_64.h +1 -1
@@ -89,7 +89,7 @@ n <= (size_t)RTE_ARM64_MEMCPY_UNALIGNED_THRESHOLD)**************************************/ -#if defined(RTE_TOOLCHAIN_GCC ) && !defined(RTE_ARM64_MEMCPY_SKIP_GCC_VER_CHECK ) +#if RTE_CC_IS_GNU && !definedRTE_ARM64_MEMCPY_SKIP_GCC_VER_CHECK #if (GCC_VERSION <50400 )#warning "The GCC version is quite old, which may result in sub-optimal \ performance of the compiled code. It is suggested that at least GCC 5.4.0 \
lib/librte_eal/common/include/arch/arm/rte_vect.h +2 -2
@@ -62,7 +62,7 @@ vaddvq_u16(uint16x8_t a)#endif -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION <70000 ) +#if RTE_CC_IS_GNU && (GCC_VERSION <70000 )static inline uint32x4_t vcopyq_laneq_u32 (uint32x4_t a,const int lane_a,uint32x4_t b,const int lane_b)
@@ -72,7 +72,7 @@ vcopyq_laneq_u32(uint32x4_t a, const int lane_a,#endif #if defined(RTE_ARCH_ARM64 ) -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION <70000 ) +#if RTE_CC_IS_GNU && (GCC_VERSION <70000 )#if (GCC_VERSION <40900 )typedef uint64_t poly64_t ;
lib/librte_eal/common/include/rte_common.h +17 -2
@@ -42,8 +42,23 @@ extern "C" {#define RTE_STD_C11 #endif -/** Define GCC_VERSION **/ -#ifdef RTE_TOOLCHAIN_GCC +/* +* RTE_TOOLCHAIN_GCC is defined if the target is built with GCC, +* while a host application (like pmdinfogen) may have another compiler. +* RTE_CC_IS_GNU is true if the file is compiled with GCC, +* no matter it is a target or host application. +*/ +#define RTE_CC_IS_GNU 0 +#if defined __clang__ +#define RTE_CC_CLANG +#elif defined __INTEL_COMPILER +#define RTE_CC_ICC +#elif defined __GNUC__ +#define RTE_CC_GCC +#undef RTE_CC_IS_GNU +#define RTE_CC_IS_GNU 1 +#endif +#if RTE_CC_IS_GNU #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \ __GNUC_PATCHLEVEL__)#endif
lib/librte_table/rte_lru_x86.h +2 -2
@@ -19,7 +19,7 @@ extern "C" {#if RTE_TABLE_HASH_LRU_STRATEGY ==2 -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >40306 ) +#if RTE_CC_IS_GNU && (GCC_VERSION >40306 )#include <x86intrin.h> #else #include <emmintrin.h>
@@ -63,7 +63,7 @@ do { \#elif RTE_TABLE_HASH_LRU_STRATEGY ==3 -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >40306 ) +#if RTE_CC_IS_GNU && (GCC_VERSION >40306 )#include <x86intrin.h> #else #include <emmintrin.h>
Signature · 1 line
2.25.1
16/03/2020 13:04, Thomas Monjalon:
Quoted 15 lines
RTE_TOOLCHAIN_* macros are defining the target compiler. Some API may be used in a host application like pmdinfogen. That's why the the public headers should check the effective compiler in use instead of the target compiler.
Detecting the compiler with macros is easy, except for
__GNUC__which is defined in all compilers supporting some GNU compatibility.It is improved by defining
RTE_CC_CLANG,RTE_CC_ICCandRTE_CC_GCC. The extra macroRTE_CC_IS_GNUis defined to 0 or 1 in GCC case, so it can be used simply with #if.Signed-off-by Thomas Monjalon <[email protected]>---
Quoted 7 lines
This patch is probably useless.
The first intent was fixing pmdinfogen compilation with clang while compiling the target with GCC, with MinGW support patch.This case is now better fixed with a patch removing EAL dependencies from the PCI library, which drops
rte_common.hinclusion from pmdinfogen:http://patches.dpdk.org/patch/66701/
Actually rte_common.h is directly included by buildtools/pmdinfogen/pmdinfogen.c so we need this patch in my opinion.
Quoted 2 lines
As a consequence, I send this EAL patch just in case we need it in future. We can decide to apply or leave it.
This patch is now gating acceptance of MinGW support.
Dmitry Kozlyuk
Acked-byQuoted 11 lines
Quoted 3 lines
This case is now better fixed with a patch removing EAL dependencies from the PCI library, which drops
rte_common.hinclusion from pmdinfogen:http://patches.dpdk.org/patch/66701/Actually
rte_common.his directly included bybuildtools/pmdinfogen/pmdinfogen.cso we need this patch in my opinion.Quoted 2 lines
As a consequence, I send this EAL patch just in case we need it in future. We can decide to apply or leave it.
This patch is now gating acceptance of MinGW support.
Applied on top of this patch, MinGW patchset builds OK:
* by host Clang and target GCC on Linux,
* by host Clang and target MinGW on Linux,
* by Clang on Windows,
* and by MinGW on Windows.
Signature · 1 line
Dmitry Kozlyuk
Thomas Monjalon
Applied17/03/2020 08:09, Dmitry Kozlyuk:
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
This case is now better fixed with a patch removing EAL dependencies from the PCI library, which drops
rte_common.hinclusion from pmdinfogen:http://patches.dpdk.org/patch/66701/Actually
rte_common.his directly included bybuildtools/pmdinfogen/pmdinfogen.cso we need this patch in my opinion.Quoted 2 lines
As a consequence, I send this EAL patch just in case we need it in future. We can decide to apply or leave it.
This patch is now gating acceptance of MinGW support.
Quoted 8 lines
Applied on top of this patch, MinGW patchset builds OK:
* by host Clang and target GCC on Linux,
* by host Clang and target MinGW on Linux,
* by Clang on Windows,
* and by MinGW on Windows.Acked-by Dmitry Kozlyuk <[email protected]>
Applied