Skip to contentSkip to conversation

zeromq: check if -latomic is needed.

PATCH Superseded Asaf Kahlon 2 participants 2 messages May 7, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zeromq: check if -latomic is needed.

Fixes:
http://autobuild.buildroot.net/results/b149aa2ee00e4d6a53c884cf99ecb2dd8af58b65/
http://autobuild.buildroot.net/results/e4b3616ac2695d3b6898185a70da6509b1faa2b8/

Patch the package to check if -latomic is needed to be added, depending on the result of AC_LINK_IFELSE.

The patch was sent to upstream, see:
https://github.com/zeromq/libzmq/pull/3083

---
 ...nclude.m4-check-if-latomic-is-needed.patch | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch
package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch new file +61 -0
new file mode 100644
index 0000000000..3fe290474c
@@ -0,0 +1,61 @@
+From 2ec5a33f6e986661dc92f3585ea400f919a39cae Mon Sep 17 00:00:00 2001
+From: Asaf Kahlon <[email protected]>
+Date: Mon, 7 May 2018 22:02:25 +0300
+Subject: [PATCH 1/1] acinclude.m4: check if -latomic is needed.
+
+On some cases, -latomic is needed for likning, and since the current
+acinclude.m4 checks only compilation we can sometimes miss the need for -latomic
+and the linking process will fail.
+Therefore, the AC_CHECK_IFELSE was replaced with AC_LINK_IFELSE. If the first
+try fails, we try to link again with -latomic and add LIBS="-latmoic" in case we
+succeeded.
+
+Signed-off-by: Asaf Kahlon <[email protected]>
+---
+ acinclude.m4 | 23 +++++++++++++++++++----
+ 1 file changed, 19 insertions(+), 4 deletions(-)
+
+diff --git a/acinclude.m4 b/acinclude.m4
+index f648ed0f..26c83ad9 100644
+--- a/acinclude.m4
++++ b/acinclude.m4
+@@ -668,7 +668,7 @@ dnl # Check if compiler supoorts __atomic_Xxx intrinsics
+ dnl ################################################################################
+ AC_DEFUN([LIBZMQ_CHECK_ATOMIC_INTRINSICS], [{
+     AC_MSG_CHECKING(whether compiler supports __atomic_Xxx intrinsics)
+-    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
++    AC_LINK_IFELSE([AC_LANG_SOURCE([
+ /* atomic intrinsics test */
+ int v = 0;
+ int main (int, char **)
+@@ -677,9 +677,24 @@ int main (int, char **)
+     return t;
+ }
+     ])],
+-    [AC_MSG_RESULT(yes) ; libzmq_cv_has_atomic_instrisics="yes" ; $1],
+-    [AC_MSG_RESULT(no)  ; libzmq_cv_has_atomic_instrisics="no"  ; $2]
+-    )
++    [AC_MSG_RESULT(yes) ; GCC_ATOMIC_BUILTINS_SUPPORTED=1 libzmq_cv_has_atomic_instrisics="yes" ; $1])
++
++    if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != x1; then
++        save_LDFLAGS=$LDFLAGS
++        LDFLAGS="$LDFLAGS -latomic"
++        AC_LINK_IFELSE([AC_LANG_SOURCE([
++        /* atomic intrinsics test */
++        int v = 0;
++        int main (int, char **)
++        {
++            int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
++            return t;
++        }
++        ])],
++        [AC_MSG_RESULT(yes) ; libzmq_cv_has_atomic_instrisics="yes" LIBS="-latomic" ; $1],
++        [AC_MSG_RESULT(no) ; libzmq_cv_has_atomic_instrisics="no"; $2])
++        LDFLAGS=$save_LDFLAGS
++    fi
+ }])
+ 
+ dnl ################################################################################
+-- 
+2.17.0
+
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/1 zeromq: check if -latomic is needed.

Hello,

package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch line 6

Quoted 12 lines · Asaf Kahlon
package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch new file +6 -0
new file mode 100644
index 0000000000..3fe290474c
@@ -0,0 +1,61 @@
+From 2ec5a33f6e986661dc92f3585ea400f919a39cae Mon Sep 17 00:00:00 2001
+From: Asaf Kahlon <[email protected]>
+Date: Mon, 7 May 2018 22:02:25 +0300
+Subject: [PATCH 1/1] acinclude.m4: check if -latomic is needed.
+
+On some cases, -latomic is needed for likning, and since the current

Typo: linking.

package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch line 10

Quoted 4 lines
package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch new file +4 -0
+acinclude.m4 checks only compilation we can sometimes miss the need for -latomic
+and the linking process will fail.
+Therefore, the AC_CHECK_IFELSE was replaced with AC_LINK_IFELSE. If the first
+try fails, we try to link again with -latomic and add LIBS="-latmoic" in case we

Typo: atomic.

package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch line 38

Quoted 5 lines
package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch new file +5 -0
+     ])],
+-    [AC_MSG_RESULT(yes) ; libzmq_cv_has_atomic_instrisics="yes" ; $1],
+-    [AC_MSG_RESULT(no)  ; libzmq_cv_has_atomic_instrisics="no"  ; $2]
+-    )
++    [AC_MSG_RESULT(yes) ; GCC_ATOMIC_BUILTINS_SUPPORTED=1 libzmq_cv_has_atomic_instrisics="yes" ; $1])

I don't understand why you need a new GCC_ATOMIC_BUILTINS_SUPPORTED variable, and why you remove the AC_MSG_RESULT(no) case.

Quoted 7 lines
package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch new file +7 -0
++    if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != x1; then
++        save_LDFLAGS=$LDFLAGS
++        LDFLAGS="$LDFLAGS -latomic"
++        AC_LINK_IFELSE([AC_LANG_SOURCE([
++        /* atomic intrinsics test */
++        int v = 0;
++        int main (int, char **)

package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch line 56

Quoted 10 lines
package/zeromq/0002-acinclude.m4-check-if-latomic-is-needed.patch new file +10 -0
++        {
++            int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
++            return t;
++        }
++        ])],
++        [AC_MSG_RESULT(yes) ; libzmq_cv_has_atomic_instrisics="yes" LIBS="-latomic" ; $1],
++        [AC_MSG_RESULT(no) ; libzmq_cv_has_atomic_instrisics="no"; $2])
++        LDFLAGS=$save_LDFLAGS
++    fi
+ }])

Here is what I would do instead:

AC_DEFUN([LIBZMQ_CHECK_ATOMIC_INTRINSICS], [{
AC_MSG_CHECKING(whether compiler supports __atomic_Xxx intrinsics) AC_LINK_IFELSE([AC_LANG_SOURCE([
/* atomic intrinsics test */
int v = 0;
int main (int, char **)

{
    int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
    return t;
}
    ])],
    [libzmq_cv_has_atomic_instrisics="yes"],
    [libzmq_cv_has_atomic_instrisics="no"]
    )

    if test "${libzmq_cv_has_atomic_instrisics}" = "no"; then
	save_LDFLAGS=$LDFLAGS
	LDFLAGS="$LDFLAGS -latomic"
	AC_LINK_IFELSE([AC_LANG_SOURCE([
/* atomic intrinsics test */
int v = 0;
int main (int, char **)
{
    int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
    return t;
}
    	])],
    	[libzmq_cv_has_atomic_instrisics="yes" LIBS="-latomic"],
    	[libzmq_cv_has_atomic_instrisics="no"]
    )

if test "${libzmq_cv_has_atomic_intrisics}" = "yes"; then

	AC_MSG_RESULT(yes)
	$1
   else
	AC_MSG_RESULT(no)
	$2

fi
}])

Or something along those lines. Note: this has been written directly in my e-mail client, so I'm not sure about all the parenthesis and curly braces, the indentation is crappy, and it has not been tested in any way.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com