diff mbox

configure: libatomic check

Message ID 20170210142650.23061-1-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Feb. 10, 2017, 2:26 p.m. UTC
upcoming patch ip fragmentation example fails to with
gcc 4.8.4 on linking __atomic_compare_exchange_16 functions
on x86. Both -latomic and -mcx16 needs to be provided in that
case. This patch adds additional checks to find combination
of required -latomic and -mcx16 options.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

---
 configure.ac                           | 16 ---------
 platform/Makefile.inc                  |  2 ++
 platform/linux-generic/m4/configure.m4 | 59 ++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 16 deletions(-)

-- 
2.11.0.295.gd7dffce

Comments

Maxim Uvarov Feb. 13, 2017, 7:37 p.m. UTC | #1
patch fixes build on my machine but not in CI.

In CI gcc compiles ok, but clang-3.4 and clang-3.7 not. I have locally
clang-3.8 and maybe somehow CI needs to go with 3.8. Looking into this...

Maxim.

On 02/10/17 17:26, Maxim Uvarov wrote:
> upcoming patch ip fragmentation example fails to with

> gcc 4.8.4 on linking __atomic_compare_exchange_16 functions

> on x86. Both -latomic and -mcx16 needs to be provided in that

> case. This patch adds additional checks to find combination

> of required -latomic and -mcx16 options.

> 

> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

> ---

>  configure.ac                           | 16 ---------

>  platform/Makefile.inc                  |  2 ++

>  platform/linux-generic/m4/configure.m4 | 59 ++++++++++++++++++++++++++++++++++

>  3 files changed, 61 insertions(+), 16 deletions(-)

> 

> diff --git a/configure.ac b/configure.ac

> index 6153efd2..a514f6be 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -314,22 +314,6 @@ ODP_CFLAGS="$ODP_CFLAGS -std=c99"

>  # Extra flags for example to suppress certain warning types

>  ODP_CFLAGS="$ODP_CFLAGS $ODP_CFLAGS_EXTRA"

>  

> -#########################################################################

> -# Check if compiler supports cmpxchng16

> -##########################################################################

> -if test "${CC}" != "gcc" -o ${CC_VERSION_MAJOR} -ge 5; then

> -   my_save_cflags="$CFLAGS"

> -

> -   CFLAGS=-mcx16

> -   AC_MSG_CHECKING([whether CC supports -mcx16])

> -   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],

> -	    [AC_MSG_RESULT([yes])]

> -	    [ODP_CFLAGS="$ODP_CFLAGS $CFLAGS"],

> -	    [AC_MSG_RESULT([no])]

> -	    )

> -   CFLAGS="$my_save_cflags"

> -fi

> -

>  ##########################################################################

>  # Default include setup

>  ##########################################################################

> diff --git a/platform/Makefile.inc b/platform/Makefile.inc

> index 7059d910..8fde4062 100644

> --- a/platform/Makefile.inc

> +++ b/platform/Makefile.inc

> @@ -9,9 +9,11 @@ VPATH = $(srcdir) $(builddir)

>  lib_LTLIBRARIES = $(LIB)/libodp-linux.la

>  

>  AM_LDFLAGS += -version-number '$(ODP_LIBSO_VERSION)'

> +AM_LDFLAGS += $(LD_LIBATOMIC)

>  

>  AM_CFLAGS += "-DGIT_HASH=$(VERSION)"

>  AM_CFLAGS += $(VISIBILITY_CFLAGS)

> +AM_CFLAGS += $(MCX16_CFLAGS)

>  

>  #The implementation will need to retain the deprecated implementation

>  AM_CFLAGS += -Wno-deprecated-declarations

> diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4

> index d3e5528c..ec77075a 100644

> --- a/platform/linux-generic/m4/configure.m4

> +++ b/platform/linux-generic/m4/configure.m4

> @@ -28,6 +28,65 @@ AC_LINK_IFELSE(

>      echo "Use newer version. For gcc > 4.7.0"

>      exit -1)

>  

> +#########################################################################

> +# Check if compiler supports cmpxchng16

> +##########################################################################

> +my_save_cflags="$CFLAGS"

> +

> +CFLAGS=-mcx16

> +AC_MSG_CHECKING([whether CC supports -mcx16])

> +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],

> +    [AC_MSG_RESULT([yes])]

> +    [MCX16_CFLAGS="-mcx16"],

> +    [AC_MSG_RESULT([no])]

> +    )

> +CFLAGS="$my_save_cflags"

> +AC_SUBST(MCX16_CFLAGS)

> +

> +

> +#########################################################################

> +# Check if compiler supports __atomic_compare_exchange

> +##########################################################################

> +my_save_cflags="$CFLAGS"

> +LD_LIBATOMIC=""

> +

> +AC_MSG_CHECKING(if libatomic required)

> +AC_LINK_IFELSE(

> +    [AC_LANG_SOURCE(

> +      [[int main() {

> +        unsigned __int128 x = 0, y = 0;

> +        y = __atomic_load_16(&x, 0);

> +        __atomic_store_16(&x, y, 0);

> +        __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);

> +        return 0;

> +        }

> +    ]])],

> +    AC_MSG_RESULT(yes),

> +    AC_MSG_RESULT(no)

> +    echo "libatomic is needed."

> +    LD_LIBATOMIC="-latomic")

> +

> +CFLAGS="$ODP_CFLAGS -latomic $MCX16_CFLAGS"

> +AC_MSG_CHECKING([CFLAGS=$CFLAGS])

> +AC_LINK_IFELSE(

> +    [AC_LANG_SOURCE(

> +      [[int main() {

> +        unsigned __int128 x = 0, y = 0;

> +        y = __atomic_load_16(&x, 0);

> +        __atomic_store_16(&x, y, 0);

> +        __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);

> +        return 0;

> +        }

> +    ]])],

> +    AC_MSG_RESULT(yes),

> +    AC_MSG_RESULT(no)

> +    echo "atomic operations compilation fail."

> +    exit -1)

> +

> +# Restore LDFLAGS

> +CFLAGS="$my_save_cflags"

> +AC_SUBST(LD_LIBATOMIC)

> +

>  m4_include([platform/linux-generic/m4/odp_pthread.m4])

>  m4_include([platform/linux-generic/m4/odp_openssl.m4])

>  m4_include([platform/linux-generic/m4/odp_pcap.m4])

>
diff mbox

Patch

diff --git a/configure.ac b/configure.ac
index 6153efd2..a514f6be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -314,22 +314,6 @@  ODP_CFLAGS="$ODP_CFLAGS -std=c99"
 # Extra flags for example to suppress certain warning types
 ODP_CFLAGS="$ODP_CFLAGS $ODP_CFLAGS_EXTRA"
 
-#########################################################################
-# Check if compiler supports cmpxchng16
-##########################################################################
-if test "${CC}" != "gcc" -o ${CC_VERSION_MAJOR} -ge 5; then
-   my_save_cflags="$CFLAGS"
-
-   CFLAGS=-mcx16
-   AC_MSG_CHECKING([whether CC supports -mcx16])
-   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
-	    [AC_MSG_RESULT([yes])]
-	    [ODP_CFLAGS="$ODP_CFLAGS $CFLAGS"],
-	    [AC_MSG_RESULT([no])]
-	    )
-   CFLAGS="$my_save_cflags"
-fi
-
 ##########################################################################
 # Default include setup
 ##########################################################################
diff --git a/platform/Makefile.inc b/platform/Makefile.inc
index 7059d910..8fde4062 100644
--- a/platform/Makefile.inc
+++ b/platform/Makefile.inc
@@ -9,9 +9,11 @@  VPATH = $(srcdir) $(builddir)
 lib_LTLIBRARIES = $(LIB)/libodp-linux.la
 
 AM_LDFLAGS += -version-number '$(ODP_LIBSO_VERSION)'
+AM_LDFLAGS += $(LD_LIBATOMIC)
 
 AM_CFLAGS += "-DGIT_HASH=$(VERSION)"
 AM_CFLAGS += $(VISIBILITY_CFLAGS)
+AM_CFLAGS += $(MCX16_CFLAGS)
 
 #The implementation will need to retain the deprecated implementation
 AM_CFLAGS += -Wno-deprecated-declarations
diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4
index d3e5528c..ec77075a 100644
--- a/platform/linux-generic/m4/configure.m4
+++ b/platform/linux-generic/m4/configure.m4
@@ -28,6 +28,65 @@  AC_LINK_IFELSE(
     echo "Use newer version. For gcc > 4.7.0"
     exit -1)
 
+#########################################################################
+# Check if compiler supports cmpxchng16
+##########################################################################
+my_save_cflags="$CFLAGS"
+
+CFLAGS=-mcx16
+AC_MSG_CHECKING([whether CC supports -mcx16])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
+    [AC_MSG_RESULT([yes])]
+    [MCX16_CFLAGS="-mcx16"],
+    [AC_MSG_RESULT([no])]
+    )
+CFLAGS="$my_save_cflags"
+AC_SUBST(MCX16_CFLAGS)
+
+
+#########################################################################
+# Check if compiler supports __atomic_compare_exchange
+##########################################################################
+my_save_cflags="$CFLAGS"
+LD_LIBATOMIC=""
+
+AC_MSG_CHECKING(if libatomic required)
+AC_LINK_IFELSE(
+    [AC_LANG_SOURCE(
+      [[int main() {
+        unsigned __int128 x = 0, y = 0;
+        y = __atomic_load_16(&x, 0);
+        __atomic_store_16(&x, y, 0);
+        __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);
+        return 0;
+        }
+    ]])],
+    AC_MSG_RESULT(yes),
+    AC_MSG_RESULT(no)
+    echo "libatomic is needed."
+    LD_LIBATOMIC="-latomic")
+
+CFLAGS="$ODP_CFLAGS -latomic $MCX16_CFLAGS"
+AC_MSG_CHECKING([CFLAGS=$CFLAGS])
+AC_LINK_IFELSE(
+    [AC_LANG_SOURCE(
+      [[int main() {
+        unsigned __int128 x = 0, y = 0;
+        y = __atomic_load_16(&x, 0);
+        __atomic_store_16(&x, y, 0);
+        __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);
+        return 0;
+        }
+    ]])],
+    AC_MSG_RESULT(yes),
+    AC_MSG_RESULT(no)
+    echo "atomic operations compilation fail."
+    exit -1)
+
+# Restore LDFLAGS
+CFLAGS="$my_save_cflags"
+AC_SUBST(LD_LIBATOMIC)
+
 m4_include([platform/linux-generic/m4/odp_pthread.m4])
 m4_include([platform/linux-generic/m4/odp_openssl.m4])
 m4_include([platform/linux-generic/m4/odp_pcap.m4])