Welcome! Log In Create A New Profile

Advanced

1.13.9 compile errors

Posted by Evgenij Krupchenko 
Evgenij Krupchenko
1.13.9 compile errors
March 12, 2018 11:40AM
i'm building custom nginx binary on debian 9 using latest zlib and openssl
sources.

../configure \
--prefix=/nginx \
--sbin-path=/nginx/sbin/nginx-https \
--conf-path=/nginx/conf/https \
--pid-path=/run/nginx-https.pid \
--error-log-path=/log/nginx-https_error.log \
--http-log-path=/log/nginx-https_access.log \
--http-client-body-temp-path=/nginx/tmp/https_client-body \
--http-proxy-temp-path=/nginx/tmp/https_proxy \
--http-fastcgi-temp-path=/nginx/tmp/http_fastcgi \
--user=www \
--group=www \
--without-select_module \
--without-poll_module \
--without-http_ssi_module \
--without-http_userid_module \
--without-http_geo_module \
--without-http_map_module \
--without-http_split_clients_module \
--without-http_referer_module \
--without-http_uwsgi_module \
--without-http_scgi_module \
--without-http_memcached_module \
--without-http_limit_conn_module \
--without-http_limit_req_module \
--without-http_empty_gif_module \
--without-http_browser_module \
--without-http_upstream_hash_module \
--without-http_upstream_ip_hash_module \
--without-http_upstream_least_conn_module \
--without-http_upstream_keepalive_module \
--without-http_upstream_zone_module \
--with-threads \
--with-file-aio \
--with-zlib=/install/zlib-1.2.11 \
--with-openssl=/install/openssl-1.1.1-pre2 \
--with-http_ssl_module

in the end of "make" i got this:

objs/ngx_modules.o \
-ldl -lpthread -lpthread -lcrypt -lpcre
/install/openssl-1.1.1-pre2/.openssl/lib/libssl.a
/install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a -ldl
/install/zlib-1.2.11/libz.a \
-Wl,-E
/install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a(threads_pthread.o): In
function `fork_once_func':
threads_pthread.c:(.text+0x16): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
objs/Makefile:223: recipe for target 'objs/nginx' failed
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory '/install/nginx-1.13.9'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2

previous version 1.13.8 and all before was build successfully with the same
configure parameters.

also, i've found this post:
https://www.coldawn.com/compile-nginx-on-centos-7-to-enable-tls13/
as suggested, after "configure" i've modified objs/Makefile: removed the
first -lpthread and the second -lpthread moved to the end of the line. in my
case it was the line #331:

before:
-ldl -lpthread -lpthread -lcrypt -lpcre
/install/openssl-1.1.1-pre2/.openssl/lib/libssl.a
/install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a -ldl
/install/zlib-1.2.11/libz.a \

after:
-ldl -lcrypt -lpcre /install/openssl-1.1.1-pre2/.openssl/lib/libssl.a
/install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a -ldl
/install/zlib-1.2.11/libz.a -lpthread \

and then it builds successfully.
and also success when i'm using openssl-1.0.2n in configure parameters.

so the problem only occurs in combination nginx-1.13.9 + openssl-1.1.1-pre2

and my question is: someone would fix bug this in the next 1.13.10 or should
we now always edit the makefile before compiling?
or this is not a bug and i'm just missing something?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,279002,279002#msg-279002

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: 1.13.9 compile errors
March 13, 2018 07:00AM
Hello!

On Mon, Mar 12, 2018 at 06:32:23AM -0400, Evgenij Krupchenko wrote:

[...]

> in the end of "make" i got this:
>
> objs/ngx_modules.o \
> -ldl -lpthread -lpthread -lcrypt -lpcre
> /install/openssl-1.1.1-pre2/.openssl/lib/libssl.a
> /install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a -ldl
> /install/zlib-1.2.11/libz.a \
> -Wl,-E
> /install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a(threads_pthread.o): In
> function `fork_once_func':
> threads_pthread.c:(.text+0x16): undefined reference to `pthread_atfork'
> collect2: error: ld returned 1 exit status
> objs/Makefile:223: recipe for target 'objs/nginx' failed
> make[1]: *** [objs/nginx] Error 1
> make[1]: Leaving directory '/install/nginx-1.13.9'
> Makefile:8: recipe for target 'build' failed
> make: *** [build] Error 2
>
> previous version 1.13.8 and all before was build successfully with the same
> configure parameters.
>
> also, i've found this post:
> https://www.coldawn.com/compile-nginx-on-centos-7-to-enable-tls13/
> as suggested, after "configure" i've modified objs/Makefile: removed the
> first -lpthread and the second -lpthread moved to the end of the line. in my
> case it was the line #331:
>
> before:
> -ldl -lpthread -lpthread -lcrypt -lpcre
> /install/openssl-1.1.1-pre2/.openssl/lib/libssl.a
> /install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a -ldl
> /install/zlib-1.2.11/libz.a \
>
> after:
> -ldl -lcrypt -lpcre /install/openssl-1.1.1-pre2/.openssl/lib/libssl.a
> /install/openssl-1.1.1-pre2/.openssl/lib/libcrypto.a -ldl
> /install/zlib-1.2.11/libz.a -lpthread \
>
> and then it builds successfully.
> and also success when i'm using openssl-1.0.2n in configure parameters.
>
> so the problem only occurs in combination nginx-1.13.9 + openssl-1.1.1-pre2
>
> and my question is: someone would fix bug this in the next 1.13.10 or should
> we now always edit the makefile before compiling?
> or this is not a bug and i'm just missing something?

The problem is that OpenSSL 1.1.1-pre2 requires -lpthread for
static linking on Linux. This wasn't the case with previous
OpenSSL versions, hence nginx doesn't try to provide -lpthread for
it. The same problem will occur with any nginx version when
trying to compile with OpenSSL 1.1.1-pre2.

The following patch should fix this, please test if it works for
you:

# HG changeset patch
# User Maxim Dounin <[email protected]>
# Date 1520919437 -10800
# Tue Mar 13 08:37:17 2018 +0300
# Node ID 649427794a74c74eca80c942477d893678fb6036
# Parent 0b1eb40de6da32196b21d1ed086f7030c10b40d2
Configure: fixed static compilation with OpenSSL 1.1.1-pre2.

OpenSSL now uses pthread_atfork(), and this requires -lpthread on Linux.
Introduced NGX_LIBPTHREAD to add it as appropriate, similar to existing
NGX_LIBDL.

diff -r 0b1eb40de6da -r 649427794a74 auto/lib/openssl/conf
--- a/auto/lib/openssl/conf Wed Mar 07 18:28:12 2018 +0300
+++ b/auto/lib/openssl/conf Tue Mar 13 08:37:17 2018 +0300
@@ -41,6 +41,7 @@
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
+ CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"

if [ "$NGX_PLATFORM" = win32 ]; then
CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
@@ -59,7 +60,7 @@
ngx_feature_run=no
ngx_feature_incs="#include <openssl/ssl.h>"
ngx_feature_path=
- ngx_feature_libs="-lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-lssl -lcrypto $NGX_LIBDL $NGX_LIBPTHREAD"
ngx_feature_test="SSL_CTX_set_options(NULL, 0)"
. auto/feature

@@ -71,11 +72,13 @@
ngx_feature_path="/usr/local/include"

if [ $NGX_RPATH = YES ]; then
- ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lssl -lcrypto"
else
- ngx_feature_libs="-L/usr/local/lib -lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-L/usr/local/lib -lssl -lcrypto"
fi

+ ngx_feature_libs="$ngx_feature_libs $NGX_LIBDL $NGX_LIBPTHREAD"
+
. auto/feature
fi

@@ -87,11 +90,13 @@
ngx_feature_path="/usr/pkg/include"

if [ $NGX_RPATH = YES ]; then
- ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lssl -lcrypto"
else
- ngx_feature_libs="-L/usr/pkg/lib -lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-L/usr/pkg/lib -lssl -lcrypto"
fi

+ ngx_feature_libs="$ngx_feature_libs $NGX_LIBDL $NGX_LIBPTHREAD"
+
. auto/feature
fi

@@ -103,11 +108,13 @@
ngx_feature_path="/opt/local/include"

if [ $NGX_RPATH = YES ]; then
- ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lssl -lcrypto"
else
- ngx_feature_libs="-L/opt/local/lib -lssl -lcrypto $NGX_LIBDL"
+ ngx_feature_libs="-L/opt/local/lib -lssl -lcrypto"
fi

+ ngx_feature_libs="$ngx_feature_libs $NGX_LIBDL $NGX_LIBPTHREAD"
+
. auto/feature
fi

diff -r 0b1eb40de6da -r 649427794a74 auto/unix
--- a/auto/unix Wed Mar 07 18:28:12 2018 +0300
+++ b/auto/unix Tue Mar 13 08:37:17 2018 +0300
@@ -901,6 +901,7 @@

if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS -lpthread"
+ NGX_LIBPTHREAD="-lpthread"
fi
fi


--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
shiz
Re: 1.13.9 compile errors
March 13, 2018 04:20PM
Maxim Dounin Wrote:
-------------------------------------------------------
>
> The following patch should fix this, please test if it works for
> you:
>
> # HG changeset patch
> # User Maxim Dounin <[email protected]>
> # Date 1520919437 -10800
> # Tue Mar 13 08:37:17 2018 +0300
> # Node ID 649427794a74c74eca80c942477d893678fb6036
> # Parent 0b1eb40de6da32196b21d1ed086f7030c10b40d2
> Configure: fixed static compilation with OpenSSL 1.1.1-pre2.
>
> OpenSSL now uses pthread_atfork(), and this requires -lpthread on
> Linux.
> Introduced NGX_LIBPTHREAD to add it as appropriate, similar to
> existing
> NGX_LIBDL.
>

Patch works beautifully for me.

Thanks Maxim!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,279002,279019#msg-279019

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login