Opened 9 years ago

Closed 3 years ago

#859 closed defect (wontfix)

-lpcre should preceed -lpthread in objs/Makefile

Reported by: sinner-@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.9.x
Keywords: Cc:
uname -a: Linux hidden 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.9.9

Description

Hi nginx team,

Firstly, thanks very much for the awesome webserver software!

I was compiling nginx 1.99 from source today using Debian 8 (stable/jessie) and the following configure options:

./configure \

--with-cpu-opt=amd64 \
--with-ld-opt="-static" \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-file-aio \
--with-pcre \
--with-cc-opt="-O2 -static -static-libgcc -fstack-protector-all --param ssp-buffer-size=4 -ftrapv -Wl,-z,relro,-z,now -D_FORTIFY_SOURCE=2" \
--without-http_charset_module \
--without-http_ssi_module \
--without-http_userid_module \
--without-http_auth_basic_module \
--without-http_autoindex_module \
--without-http_geo_module \
--without-http_map_module \
--without-http_split_clients_module \
--without-http_referer_module \
--without-http_proxy_module \
--without-http_uwsgi_module \
--without-http_scgi_module \
--without-http_memcached_module \
--without-http_empty_gif_module \
--without-http_browser_module \
--without-http_upstream_ip_hash_module \
--without-http_upstream_least_conn_module \
--without-http_upstream_keepalive_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module

and during the compile I got this error:

/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `sljit_free_exec':
(.text+0x66c): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `_pcre_jit_compile':
(.text+0x24d26): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `_pcre_jit_compile':
(.text+0x24e19): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `_pcre_jit_compile':
(.text+0x25854): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `_pcre_jit_compile':
(.text+0x25a89): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `pcre_jit_free_unused_memory':
(.text+0x262a9): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `sljit_free_exec':
(.text+0x6d4): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpcre.a(libpcre_la-pcre_jit_compile.o): In function `pcre_jit_free_unused_memory':
(.text+0x26319): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `register_frame_info_bases':
(.text+0x16f7): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `
register_frame_info':
(.text+0x1792): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `register_frame':
(.text+0x1834): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `
register_frame_info_table_bases':
(.text+0x18bb): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `deregister_frame_info_bases':
(.text+0x195e): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `
deregister_frame_info_bases':
(.text+0x19f8): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `_Unwind_Find_FDE':
(.text+0x1ac6): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `_Unwind_Find_FDE':
(.text+0x1b16): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `_Unwind_Find_FDE':
(.text+0x1c00): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `register_frame_info_bases':
(.text+0x1716): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `
register_frame_info':
(.text+0x17b1): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `register_frame':
(.text+0x1858): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a(unwind-dw2-fde-dip.o):(.text+0x18da): more undefined references to `pthread_mutex_unlock' follow
collect2: error: ld returned 1 exit status
objs/Makefile:198: recipe for target 'objs/nginx' failed
make[1]: * [objs/nginx] Error 1
make[1]: Leaving directory '/root/hidden-nginx/nginx-1.9.9'
Makefile:8: recipe for target 'build' failed
make:
* [build] Error 2

I googled this error and it seemed to have something to do with the precedence of -lpthread and -lpcre in the Makefile.

So just to test, I changed objs/Makefile line 294 from:

-static -lpthread -lpcre -lz

to:

-static -lpcre -lpthread -lz

and the compilation worked.

Here is an example mailing list post discussing same issue for a different software package:

https://mail.haskell.org/pipermail/ghc-devs/2013-January/000146.html

Thanks.

Change History (2)

comment:1 by Maxim Dounin, 8 years ago

The -lpthread parameter as seen in the build is added for POSIX semaphores (as they are in libpthread on Linux). This is completely unrelated to the PCRE library, and it after the PCRE library looks wrong.

In this particular case most trivial solution seems to use

./auto/configure --with-ld-opt="-static -lpcre -lpthread"

to provide bits needed to link libpcre.

Alternatively, we can introduce something like this to try if adding -lpthread improves things:

diff -r fc72784b1f52 auto/lib/pcre/conf
--- a/auto/lib/pcre/conf        Fri Mar 18 06:44:49 2016 +0300
+++ b/auto/lib/pcre/conf        Wed Sep 21 23:58:00 2016 +0300
@@ -182,6 +182,20 @@
                               if (jit != 1) return 1;"
             . auto/feature
 
+            if [ $ngx_found = no ]; then
+
+                # PCRE JIT test may fail if linking statically
+                # if static linking requires libpthread
+
+                ngx_feature="PCRE JIT support with libpthread"
+                ngx_feature_libs="$ngx_feature_libs -lpthread"
+                . auto/feature
+
+                if [ $ngx_found = yes ]; then
+                    CORE_LIBS="$CORE_LIBS -lpthread"
+                fi
+            fi
+
             if [ $ngx_found = yes ]; then
                 PCRE_JIT=YES
             fi

While it doesn't cover all possible cases (and old PCRE versions without JIT in particular), it will probably fix the problem in all practical cases.

comment:2 by Maxim Dounin, 3 years ago

Resolution: wontfix
Status: newclosed

Closing this, does not seem to be practical: no activity on the ticket for 5 years. If static linking is desired and PCRE needs -lpthread for static linking on the particular platform, appropriate --with-ld-opt option can be used to provide it.

Note that in general it is not recommended to use static linking unless you understand what you are doing and why, and understand possible consequences. In particular, it might be non-trivial to provide appropriate static dependencies for each library you are compiling nginx with, and this is not something nginx will generally do for you.

Note: See TracTickets for help on using tickets.