Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#903 closed defect (fixed)

nginx 1.9.11+: Can`t build static nginx any more

Reported by: emmeran.seehuber@… Owned by:
Priority: major Milestone:
Component: nginx-core Version: 1.9.x
Keywords: Cc:
uname -a: Linux nginx-build-server 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.9.12 built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) built with OpenSSL 1.0.2f 28 Jan 2016 TLS SNI support enabled configure arguments: --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gzip_static_module --without-http_scgi_module --without-http_uwsgi_module --without-http_fastcgi_module --with-openssl=../openssl-1.0.2f --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-ld-opt='-Bstatic -static -static-libgcc -static-libstdc++ -static -Bstatic'

Description

I try to always be up to date with nginx, and build nginx myself as a static module. This allows me to deploy nginx to my different environments (testing, production) without any library dependency problems. Till nginx 1.9.10 this worked like Charme.

I`ve got this directory layout for my build directory:

  • nginx
    • openssl-1.0.2f
    • nginx_src

nginx_src is a git checkout of the git mirror.

I use this script to build nginx:

#!/bin/sh
cd nginx_src/
make clean
./auto/configure \
        --with-http_ssl_module \
        --with-http_v2_module \
        --with-http_realip_module \
        --with-http_gzip_static_module \
        --without-http_scgi_module  \
        --without-http_uwsgi_module  \
        --without-http_fastcgi_module \
        --with-openssl=../openssl-1.0.2f \
        --prefix=/etc/nginx \
        --conf-path=/etc/nginx/nginx.conf \
        --error-log-path=/var/log/nginx/error.log \
        --http-client-body-temp-path=/var/lib/nginx/body \
         --http-log-path=/var/log/nginx/access.log \
         --http-proxy-temp-path=/var/lib/nginx/proxy \
         --lock-path=/var/lock/nginx.lock \
         --pid-path=/var/run/nginx.pid \
        --with-ld-opt="-Bstatic -static -static-libgcc -static-libstdc++ -static -Bstatic"   

make

This script worked fine till 1.9.10. Now I get this linker error:

....
        objs/src/http/modules/ngx_http_upstream_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_least_conn_module.o \
        objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
        objs/src/http/modules/ngx_http_upstream_zone_module.o \
        objs/ngx_modules.o \
        -Bstatic -static -static-libgcc -static-libstdc++ -static -Bstatic -ldl -lpthread -lcrypt -lpcre ../openssl-1.0.2f/.openssl/lib/libssl.a ../openssl-1.0.2f/.openssl/lib/libcrypto.a -lz
objs/src/core/nginx.o: In function `ngx_load_module':
/home/emmy/nginx/nginx_src/src/core/nginx.c:1453: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
objs/src/os/unix/ngx_process_cycle.o: In function `ngx_worker_process_init':
/home/emmy/nginx/nginx_src/src/os/unix/ngx_process_cycle.c:838: warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
objs/src/core/nginx.o: In function `ngx_set_user':
/home/emmy/nginx/nginx_src/src/core/nginx.c:1182: warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/emmy/nginx/nginx_src/src/core/nginx.c:1170: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
objs/src/core/ngx_inet.o: In function `ngx_inet_resolve_host':
/home/emmy/nginx/nginx_src/src/core/ngx_inet.c:1118: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../openssl-1.0.2f/.openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x6be): undefined reference to `dladdr'
collect2: ld gab 1 als Ende-Status zurück
make[1]: *** [objs/nginx] Fehler 1
make[1]: Verlasse Verzeichnis '/home/emmy/nginx/nginx_src'
make: *** [build] Fehler 2

If I add '-ldl' at the end of the linker command line, it works and correctly links nginx.

....
        objs/src/http/modules/ngx_http_proxy_module.o \
        objs/src/http/modules/ngx_http_memcached_module.o \
        objs/src/http/modules/ngx_http_empty_gif_module.o \
        objs/src/http/modules/ngx_http_browser_module.o \
        objs/src/http/modules/ngx_http_upstream_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_least_conn_module.o \
        objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
        objs/src/http/modules/ngx_http_upstream_zone_module.o \
        objs/ngx_modules.o \
        -Bstatic -static -static-libgcc -static-libstdc++ -static -Bstatic -ldl -lpthread -lcrypt -lpcre ../openssl-1.0.2f/.openssl/lib/libssl.a ../openssl-1.0.2f/.openssl/lib/libcrypto.a -lz -ldl

This problem happens with the 1.9.11 tag and with current master. I did not find a way to fix this problem with configure parameters. Am I missing something? For now I just will patch the generated Makefile and append -ldl.

Thanks and keep up the good work!

Attachments (1)

p (3.1 KB) - added by ru 3 years ago.

Download all attachments as: .zip

Change History (5)

Changed 3 years ago by ru

  • Attachment p added

comment:1 Changed 3 years ago by ru

  • Status changed from new to accepted

Please check if the attached patch fixes it.

comment:2 Changed 3 years ago by Ruslan Ermilov <ru@…>

In 6403:e59e617f8fcb/nginx:

Configure: fixed static nginx build with OpenSSL (ticket #903).

Before 7142b04337d6, it was possible to build the OpenSSL library
along with nginx, and link nginx statically with this library
(--with-openssl=DIR --with-ld-opt=-static --with-http_ssl_module).
This was broken on Linux by not adding -ldl after -lcrypto.

The fix also makes it possible to link nginx statically on Linux
with the system OpenSSL library, which never worked before.

comment:3 Changed 3 years ago by ru

  • Resolution set to fixed
  • Status changed from accepted to closed

comment:4 Changed 3 years ago by emmeran.seehuber@…

Thanks, I can confirm that this issue is fixed on current master. Sorry for this late response, I did forget to set my email address in the Trac preferences and didn`t get any notification because of this.

Note: See TracTickets for help on using tickets.