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 <mdou...@mdounin.ru>
# 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

Reply via email to