Skip to contentSkip to conversation

package/libevent: fix static build

PATCH New Romain Naour 2 participants 6 messages Feb 15, 2015 – Feb 27, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/libevent: fix static build

For some reason, libevent silently fail to enable openssl support even when it's explicitly requested.

Somes flags are missing when checking for zlib and openssl.

Fixes:
http://autobuild.buildroot.net/results/713/71362af474461e99b7c188a316aa644a0faaad2e

---
 .../0002-Fix-openssl-check-for-static-build.patch  | 93 ++++++++++++++++++++++
 package/libevent/libevent.mk                       |  1 +
 2 files changed, 94 insertions(+)
 create mode 100644 package/libevent/0002-Fix-openssl-check-for-static-build.patch
package/libevent/0002-Fix-openssl-check-for-static-build.patch new file +93 -0
new file mode 100644
index 0000000..6db0c4d
@@ -0,0 +1,93 @@
+From 17e7b2bca663d0f434d35ecc3b3ecead49669ecf Mon Sep 17 00:00:00 2001
+From: Romain Naour <[email protected]>
+Date: Sun, 15 Feb 2015 19:43:11 +0100
+Subject: [PATCH] Fix openssl check for static build
+
+For some reason, AC_SEARCH_LIBS([inflateEnd], [z] forget to link with -lz
+
+config.log:
+configure:12914: checking for library containing inflateEnd
+configure:12945: Path/to/usr/bin/arm-linux-gcc -o conftest    -Os -g2 -static -Wall -fno-strict-aliasing   -static conftest.c  >&5
+/tmp/cc4iscfI.o: In function `main':
+Path/to/libevent-2.0.22-stable/conftest.c:36: undefined reference to `inflateEnd'
+collect2: error: ld returned 1 exit status
+
+Ditto for AC_SEARCH_LIBS([SSL_new], [ssl] (forget to link with -lssl -lcrypto
+and -lz)
+
+config.log:
+configure:13015: checking for library containing SSL_new
+configure:13046: Path/to/usr/bin/arm-linux-gcc -o conftest    -Os -g2 -static -Wall -fno-strict-aliasing   -static conftest.c  >&5
+/tmp/cc65AA50.o: In function `main':
+Path/to/libevent-2.0.22-stable/conftest.c:38: undefined reference to `SSL_new'
+collect2: error: ld returned 1 exit status
+
+Also add $(ZLIB_LIBS) when linking with ../libevent_openssl.la.
+
+Signed-off-by: Romain Naour <[email protected]>
+---
+ configure.ac       | 6 +++---
+ sample/Makefile.am | 2 +-
+ test/Makefile.am   | 2 +-
+ 3 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index d42edd8..814bd01 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -147,7 +147,7 @@ if test "x$ac_cv_header_zlib_h" = "xyes"; then
+ dnl Determine if we have zlib for regression tests
+ dnl Don't put this one in LIBS
+ save_LIBS="$LIBS"
+-LIBS=""
++LIBS="-lz"
+ ZLIB_LIBS=""
+ have_zlib=no
+ AC_SEARCH_LIBS([inflateEnd], [z],
+@@ -175,7 +175,7 @@ AC_CHECK_HEADERS([openssl/bio.h])
+ 
+ if test "$enable_openssl" = "yes"; then
+ save_LIBS="$LIBS"
+-LIBS=""
++LIBS="-lssl -lcrypto $ZLIB_LIBS"
+ OPENSSL_LIBS=""
+ have_openssl=no
+ AC_SEARCH_LIBS([SSL_new], [ssl],
+@@ -183,7 +183,7 @@ AC_SEARCH_LIBS([SSL_new], [ssl],
+ 	OPENSSL_LIBS="$LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"
+ 	AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])],
+ 	[have_openssl=no],
+-	[-lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
++	[$ZLIB_LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
+ LIBS="$save_LIBS"
+ AC_SUBST(OPENSSL_LIBS)
+ fi
+diff --git a/sample/Makefile.am b/sample/Makefile.am
+index c926f4e..37329ef 100644
+--- a/sample/Makefile.am
++++ b/sample/Makefile.am
+@@ -21,7 +21,7 @@ http_server_SOURCES = http-server.c
+ if OPENSSL
+ noinst_PROGRAMS += le-proxy
+ le_proxy_SOURCES = le-proxy.c
+-le_proxy_LDADD = $(LDADD) ../libevent_openssl.la -lssl -lcrypto ${OPENSSL_LIBADD}
++le_proxy_LDADD = $(LDADD) ../libevent_openssl.la -lssl -lcrypto ${OPENSSL_LIBADD} $(ZLIB_LIBS)
+ endif
+ 
+ verify:
+diff --git a/test/Makefile.am b/test/Makefile.am
+index 0253a49..5b1998e 100644
+--- a/test/Makefile.am
++++ b/test/Makefile.am
+@@ -72,7 +72,7 @@ regress_LDFLAGS = $(PTHREAD_CFLAGS)
+ 
+ if OPENSSL
+ regress_SOURCES += regress_ssl.c
+-regress_LDADD += ../libevent_openssl.la -lssl -lcrypto ${OPENSSL_LIBADD}
++regress_LDADD += ../libevent_openssl.la -lssl -lcrypto ${OPENSSL_LIBADD} $(ZLIB_LIBS)
+ endif
+ 
+ bench_SOURCES = bench.c
+-- 
+1.9.3
+
package/libevent/libevent.mk +1 -0
index c50b1d2..d469bd2 100644
@@ -11,6 +11,7 @@ LIBEVENT_INSTALL_STAGING = YES
 LIBEVENT_LICENSE = BSD-3c, OpenBSD
 LIBEVENT_LICENSE_FILES = LICENSE
 # For 0001-Disable-building-test-programs.patch
+# and 0002-Fix-openssl-check-for-static-build.patch
 LIBEVENT_AUTORECONF = YES
 
 define LIBEVENT_REMOVE_PYSCRIPT
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 package/libevent: fix static build

Dear Romain Naour,

Quoted 9 lines · Romain Naour

For some reason, libevent silently fail to enable openssl support even when it's explicitly requested.

Somes flags are missing when checking for zlib and openssl.

Fixes:
http://autobuild.buildroot.net/results/713/71362af474461e99b7c188a316aa644a0faaad2e

Do you have a defconfig that exhibits the build failure? I've tried the following minimal defconfig, and it builds fine here:

BR2_bfin=y
BR2_BINFMT_FLAT=y
BR2_COMPILER_PARANOID_UNSAFE_PATH=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_INIT_NONE=y
# BR2_PACKAGE_BUSYBOX is not set
BR2_PACKAGE_OPENSSL=y
BR2_PACKAGE_LIBEVENT=y
# BR2_TARGET_ROOTFS_TAR is not set

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 package/libevent: fix static build

Hi Thomas,

----- Mail original -----

| De: "Thomas Petazzoni" <[email protected]>
| ?: "Romain Naour" <[email protected]>
| Cc: buildroot at buildroot.org
| Envoy?: Lundi 23 F?vrier 2015 19:00:40
| Objet: Re: [Buildroot] [PATCH] package/libevent: fix static build
| 
| Dear Romain Naour,
| 
| On Sun, 15 Feb 2015 22:33:00 +0100, Romain Naour wrote:
| > For some reason, libevent silently fail to enable openssl support
| > even when it's explicitly requested.
| > 
| > Somes flags are missing when checking for zlib and openssl.
| > 
| > Fixes:
| > http://autobuild.buildroot.net/results/713/71362af474461e99b7c188a316aa644a0faaad2e
| > 
| > Signed-off-by: Romain Naour <[email protected]>
| 
| Do you have a defconfig that exhibits the build failure? I've tried
| the
| following minimal defconfig, and it builds fine here:
| 

Can you try to build libwebsock with your config ?

Sorry, I meant libwebsock fix static build.

libevent break libwebsock's build because libevent_openssl.pc is not installed.

Best regards,
Romain

| BR2_bfin=y
| BR2_BINFMT_FLAT=y
| BR2_COMPILER_PARANOID_UNSAFE_PATH=y
| BR2_TOOLCHAIN_EXTERNAL=y
| BR2_INIT_NONE=y
| # BR2_PACKAGE_BUSYBOX is not set
| BR2_PACKAGE_OPENSSL=y
| BR2_PACKAGE_LIBEVENT=y
| # BR2_TARGET_ROOTFS_TAR is not set
| 
| Thanks,
| 
| Thomas
| --
| Thomas Petazzoni, CTO, Free Electrons
| Embedded Linux, Kernel and Android engineering
| http://free-electrons.com
| 
#3 lore raw

PATCH 1/1 package/libevent: fix static build

Dear Romain Naour,

Quoted 6 lines · Romain Naour

Can you try to build libwebsock with your config ?

Sorry, I meant libwebsock fix static build.

libevent break libwebsock's build because libevent_openssl.pc is not installed.

Ah, right, now I can reproduce the problem. Instead of trying to get AC_SEARCH_LIB to work properly with static libraries, how about using PKG_CHECK_MODULES() instead to rely on pkg-config? Something like:

#4 lore raw

PATCH 1/1 package/libevent: fix static build

Hi Thomas,

Le 23/02/2015 20:07, Thomas Petazzoni a ?crit :

Quoted 15 lines

Dear Romain Naour,

Quoted 6 lines · Romain Naour

Can you try to build libwebsock with your config ?

Sorry, I meant libwebsock fix static build.

libevent break libwebsock's build because libevent_openssl.pc is not installed.

Ah, right, now I can reproduce the problem. Instead of trying to get AC_SEARCH_LIB to work properly with static libraries, how about using PKG_CHECK_MODULES() instead to rely on pkg-config? Something like:

Quoted 6 lines

From c603940f3d54189a3ef4a430580166cfdda468d0 Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <[email protected]>
Date: Mon, 23 Feb 2015 19:58:21 +0100
Subject: [PATCH 2/2] Use pkg-config to discover openssl and zlib

It's much better, thanks.
I was not really happy with my patch, but at least it fixed the build.

Build tested from scratch with your patch and the same config. Can you add my:

Best regards,
Romain

Quoted 80 lines
---
 configure.ac       | 25 ++-----------------------
 sample/Makefile.am |  2 +-
 test/Makefile.am   |  2 +-
 3 files changed, 4 insertions(+), 25 deletions(-)
configure.ac +2 -23
index d42edd8..da5bc49 100644
@@ -146,16 +146,7 @@ AC_CHECK_HEADERS([zlib.h])
 if test "x$ac_cv_header_zlib_h" = "xyes"; then
 dnl Determine if we have zlib for regression tests
 dnl Don't put this one in LIBS
-save_LIBS="$LIBS"
-LIBS=""
-ZLIB_LIBS=""
-have_zlib=no
-AC_SEARCH_LIBS([inflateEnd], [z],
-	[have_zlib=yes
-	ZLIB_LIBS="$LIBS"
-	AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
-LIBS="$save_LIBS"
-AC_SUBST(ZLIB_LIBS)
+    PKG_CHECK_MODULES([ZLIB], [zlib], [have_zlib=yes])
 fi
 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
 
@@ -169,23 +160,11 @@ else
 fi
 AC_SUBST(EV_LIB_WS32)
 AC_SUBST(EV_LIB_GDI)
-AC_SUBST(OPENSSL_LIBADD)
 
 AC_CHECK_HEADERS([openssl/bio.h])
 
 if test "$enable_openssl" = "yes"; then
-save_LIBS="$LIBS"
-LIBS=""
-OPENSSL_LIBS=""
-have_openssl=no
-AC_SEARCH_LIBS([SSL_new], [ssl],
-	[have_openssl=yes
-	OPENSSL_LIBS="$LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"
-	AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])],
-	[have_openssl=no],
-	[-lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
-LIBS="$save_LIBS"
-AC_SUBST(OPENSSL_LIBS)
+   PKG_CHECK_MODULES([OPENSSL], [openssl], [have_openssl=yes], [have_openssl=no])
 fi
 
 dnl Checks for header files.
sample/Makefile.am +1 -1
index c926f4e..a986b18 100644
@@ -21,7 +21,7 @@ http_server_SOURCES = http-server.c
 if OPENSSL
 noinst_PROGRAMS += le-proxy
 le_proxy_SOURCES = le-proxy.c
-le_proxy_LDADD = $(LDADD) ../libevent_openssl.la -lssl -lcrypto ${OPENSSL_LIBADD}
+le_proxy_LDADD = $(LDADD) ../libevent_openssl.la -lssl -lcrypto $(OPENSSL_LIBS)
 endif
 
 verify:
test/Makefile.am +1 -1
index 0253a49..4ab6ae5 100644
@@ -72,7 +72,7 @@ regress_LDFLAGS = $(PTHREAD_CFLAGS)
 
 if OPENSSL
 regress_SOURCES += regress_ssl.c
-regress_LDADD += ../libevent_openssl.la -lssl -lcrypto ${OPENSSL_LIBADD}
+regress_LDADD += ../libevent_openssl.la -lssl -lcrypto $(OPENSSL_LIBS)
 endif
 
 bench_SOURCES = bench.c
#5 lore raw

PATCH 1/1 package/libevent: fix static build

Hi Thomas,

[...]

Quoted 8 lines
Quoted 7 lines

From c603940f3d54189a3ef4a430580166cfdda468d0 Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <[email protected]>
Date: Mon, 23 Feb 2015 19:58:21 +0100
Subject: [PATCH 2/2] Use pkg-config to discover openssl and zlib

[...]

Quoted 19 lines
Quoted 19 lines
---
 configure.ac       | 25 ++-----------------------
 sample/Makefile.am |  2 +-
 test/Makefile.am   |  2 +-
 3 files changed, 4 insertions(+), 25 deletions(-)
configure.ac +0 -5
index d42edd8..da5bc49 100644
@@ -146,16 +146,7 @@ AC_CHECK_HEADERS([zlib.h])
 if test "x$ac_cv_header_zlib_h" = "xyes"; then
 dnl Determine if we have zlib for regression tests
 dnl Don't put this one in LIBS
-save_LIBS="$LIBS"
-LIBS=""
-ZLIB_LIBS=""
-have_zlib=no
-AC_SEARCH_LIBS([inflateEnd], [z],
Quoted 8 lines

configure.ac AC_CHECK_HEADERS([zlib.h]) · line 151

Quoted 8 lines
configure.ac +1 -5
-	[have_zlib=yes
-	ZLIB_LIBS="$LIBS"
-	AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
-LIBS="$save_LIBS"
-AC_SUBST(ZLIB_LIBS)
+    PKG_CHECK_MODULES([ZLIB], [zlib], [have_zlib=yes])
 fi
 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])

The first part of your patch can be upstreamed easily.

Quoted 9 lines
Quoted 9 lines
configure.ac +0 -1
@@ -169,23 +160,11 @@ else
 fi
 AC_SUBST(EV_LIB_WS32)
 AC_SUBST(EV_LIB_GDI)
-AC_SUBST(OPENSSL_LIBADD)
 
 AC_CHECK_HEADERS([openssl/bio.h])
 
Quoted 16 lines
Quoted 6 lines
configure.ac +0 -5
 if test "$enable_openssl" = "yes"; then
-save_LIBS="$LIBS"
-LIBS=""
-OPENSSL_LIBS=""
-have_openssl=no
-AC_SEARCH_LIBS([SSL_new], [ssl],

configure.ac else · line 169

Quoted 10 lines
configure.ac +1 -7
-	[have_openssl=yes
-	OPENSSL_LIBS="$LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"
-	AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])],
-	[have_openssl=no],
-	[-lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
-LIBS="$save_LIBS"
-AC_SUBST(OPENSSL_LIBS)
+   PKG_CHECK_MODULES([OPENSSL], [openssl], [have_openssl=yes], [have_openssl=no])
 fi
 

The second part doesn't apply since the following patch has been merged:

"Provide the autoconf m4 macros for the new OpenSSL via pkg-config stuff"
https://github.com/libevent/libevent/commit/674dc3d34ed0e46890f9db35402841527f2432f3

"Use pkg-config (if available) to handle OpenSSL"
https://github.com/libevent/libevent/commit/1c63860758f5ddb0bd00e9d3c841d488779be1bd

It seems that upstream want to make pkg-config optional and fall back to legacy way if it's not found.
So, the PKG_CHECK_MODULES for zlib needs to be reworked to check if pkg-config is available...

I'm not convinced about with/without pkg-config handling, the legacy way is still broken for some corner case.
But from Buildroot point of view, it doesn't matter since pkg-config is always available.

For the last part of the patch, sample/Makefile.am and test/Makefile.am has been removed/renamed upstream.

What do you suggest ?

Best regards,
Romain