Skip to content

Commit 1802ead

Browse files
authored
bugfix: config: ensured LuaJIT FFI check and static PCRE builds succeed on all platforms.
- fix the LuaJIT FFI check (tested on Linux and Darwin) - fix static libpcre builds on Darwin
1 parent 2a19073 commit 1802ead

File tree

1 file changed

+47
-43
lines changed

1 file changed

+47
-43
lines changed

config

+47-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ngx_lua_opt_I=
22
ngx_lua_opt_L=
3+
luajit_ld_opt=
34

45
if [ -n "$LUAJIT_INC" -o -n "$LUAJIT_LIB" ]; then
56
# explicitly set LuaJIT paths
@@ -30,6 +31,7 @@ if [ -n "$LUAJIT_INC" -o -n "$LUAJIT_LIB" ]; then
3031
ngx_feature_path="$LUAJIT_INC"
3132
ngx_lua_opt_I="-I$LUAJIT_INC"
3233
ngx_lua_opt_L="-L$LUAJIT_LIB"
34+
luajit_ld_opt="-lm -ldl"
3335

3436
# ensure that -I$LUAJIT_INC and -L$LUAJIT_LIB come first
3537
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
@@ -38,9 +40,9 @@ if [ -n "$LUAJIT_INC" -o -n "$LUAJIT_LIB" ]; then
3840
NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
3941

4042
if [ $NGX_RPATH = YES ]; then
41-
ngx_feature_libs="-R$LUAJIT_LIB $ngx_lua_opt_L -lluajit-5.1 -lm -ldl"
43+
ngx_feature_libs="-R$LUAJIT_LIB $ngx_lua_opt_L -lluajit-5.1 $luajit_ld_opt"
4244
else
43-
ngx_feature_libs="$ngx_lua_opt_L -lluajit-5.1 -lm -ldl"
45+
ngx_feature_libs="$ngx_lua_opt_L -lluajit-5.1 $luajit_ld_opt"
4446
fi
4547

4648
. auto/feature
@@ -55,6 +57,7 @@ if [ -n "$LUAJIT_INC" -o -n "$LUAJIT_LIB" ]; then
5557
ngx_feature_path="$LUAJIT_INC"
5658
ngx_lua_opt_I="-I$LUAJIT_INC"
5759
ngx_lua_opt_L="-L$LUAJIT_LIB"
60+
luajit_ld_opt="-lm"
5861

5962
# ensure that -I$LUAJIT_INC and -L$LUAJIT_LIB come first
6063
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
@@ -63,9 +66,9 @@ if [ -n "$LUAJIT_INC" -o -n "$LUAJIT_LIB" ]; then
6366
NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
6467

6568
if [ $NGX_RPATH = YES ]; then
66-
ngx_feature_libs="-R$LUAJIT_LIB $ngx_lua_opt_L -lluajit-5.1 -lm"
69+
ngx_feature_libs="-R$LUAJIT_LIB $ngx_lua_opt_L -lluajit-5.1 $luajit_ld_opt"
6770
else
68-
ngx_feature_libs="$ngx_lua_opt_L -lluajit-5.1 -lm"
71+
ngx_feature_libs="$ngx_lua_opt_L -lluajit-5.1 $luajit_ld_opt"
6972
fi
7073

7174
. auto/feature
@@ -88,6 +91,7 @@ END
8891
case "$NGX_MACHINE" in
8992
amd64 | x86_64 | i386)
9093
echo "adding extra linking options needed by LuaJIT on $NGX_MACHINE"
94+
luajit_ld_opt="$luajit_ld_opt -pagezero_size 10000 -image_base 100000000"
9195
ngx_feature_libs="$ngx_feature_libs -pagezero_size 10000 -image_base 100000000"
9296
;;
9397

@@ -105,6 +109,8 @@ else
105109
# FreeBSD with luajit-2.0 from ports collection
106110
ngx_feature="LuaJIT library in /usr/local/"
107111
ngx_feature_path="/usr/local/include/luajit-2.0"
112+
luajit_ld_opt="-lm"
113+
LUAJIT_LIB="/usr/local/lib"
108114
if [ $NGX_RPATH = YES ]; then
109115
ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lluajit-5.1 -lm"
110116
else
@@ -117,6 +123,8 @@ else
117123
# Gentoo with LuaJIT-2.0, try with -ldl
118124
ngx_feature="LuaJIT library in /usr/"
119125
ngx_feature_path="/usr/include/luajit-2.0"
126+
luajit_ld_opt="-lm -ldl"
127+
LUAJIT_LIB="/usr/lib"
120128
if [ $NGX_RPATH = YES ]; then
121129
ngx_feature_libs="-R/usr/lib -L/usr/lib -lm -lluajit-5.1 -ldl"
122130
else
@@ -129,6 +137,8 @@ else
129137
# Gentoo with LuaJIT 2.0
130138
ngx_feature="LuaJIT library in /usr/"
131139
ngx_feature_path="/usr/include/luajit-2.0"
140+
luajit_ld_opt="-lm"
141+
LUAJIT_LIB="/usr/lib"
132142
if [ $NGX_RPATH = YES ]; then
133143
ngx_feature_libs="-R/usr/lib -L/usr/lib -lm -lluajit-5.1"
134144
else
@@ -159,15 +169,11 @@ fi
159169
# ----------------------------------------
160170

161171
ngx_feature="LuaJIT 2.x"
162-
ngx_feature_name=
163172
ngx_feature_run=no
164173
ngx_feature_incs="#include <luajit.h>"
165-
ngx_feature_path=
166174
ngx_feature_test='#if !defined(LUAJIT_VERSION_NUM) || (LUAJIT_VERSION_NUM < 20000)
167175
# error unsupported LuaJIT version
168176
#endif'
169-
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
170-
CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
171177

172178
. auto/feature
173179

@@ -178,22 +184,17 @@ END
178184
exit 1
179185
fi
180186

181-
CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
182-
183187
# ----------------------------------------
184188

185189
ngx_feature="LuaJIT has FFI"
186-
ngx_feature_name=
190+
ngx_feature_libs="$LUAJIT_LIB/libluajit-5.1.a $luajit_ld_opt"
187191
ngx_feature_run=yes
188192
ngx_feature_incs="#include <lualib.h>
189193
#include <lauxlib.h>
190194
#include <assert.h>"
191-
ngx_feature_path=
192-
ngx_feature_test='lua_State *L = luaL_newstate();
195+
ngx_feature_test="lua_State *L = luaL_newstate();
193196
assert(L != NULL);
194-
luaopen_ffi(L);'
195-
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
196-
CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
197+
luaopen_ffi(L);"
197198

198199
. auto/feature
199200

@@ -204,8 +205,6 @@ END
204205
exit 1
205206
fi
206207

207-
CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
208-
209208
# ----------------------------------------
210209

211210
ngx_addon_name=ngx_http_lua_module
@@ -468,36 +467,41 @@ fi
468467

469468
# ----------------------------------------
470469

471-
if [ $PCRE != NO -a $PCRE != YES ]; then
472-
# force pcre_version symbol to be undefined when PCRE is statically linked
473-
ngx_feature="force undefined symbols (--undefined)"
474-
ngx_feature_libs="-Wl,--undefined=printf"
475-
ngx_feature_name=
476-
ngx_feature_run=no
477-
ngx_feature_incs="#include <stdio.h>"
478-
ngx_feature_path=
479-
ngx_feature_test='printf("hello");'
470+
if [ $USE_PCRE = YES -o $PCRE != NONE ] && [ $PCRE != NO -a $PCRE != YES ]; then
471+
# force pcre_version symbol to be required when PCRE is statically linked
472+
case "$NGX_PLATFORM" in
473+
Darwin:*)
474+
ngx_feature="require defined symbols (-u)"
475+
ngx_feature_name=
476+
ngx_feature_path=
477+
ngx_feature_libs="-Wl,-u,_strerror"
478+
ngx_feature_run=no
479+
ngx_feature_incs="#include <stdio.h>"
480+
ngx_feature_test='printf("hello");'
480481

481-
. auto/feature
482+
. auto/feature
482483

483-
if [ $ngx_found = yes ]; then
484-
CORE_LIBS="$CORE_LIBS -Wl,--undefined=pcre_version"
485-
fi
484+
if [ $ngx_found = yes ]; then
485+
CORE_LIBS="-Wl,-u,_pcre_version $CORE_LIBS"
486+
fi
487+
;;
486488

487-
# for LLVM ld (Darwin)
488-
ngx_feature="force undefined symbols (-all_load -U)"
489-
ngx_feature_libs="-all_load -U printf"
490-
ngx_feature_name=
491-
ngx_feature_run=no
492-
ngx_feature_incs="#include <stdio.h>"
493-
ngx_feature_path=
494-
ngx_feature_test='printf("hello");'
489+
*)
490+
ngx_feature="require defined symbols (--require-defined)"
491+
ngx_feature_name=
492+
ngx_feature_path=
493+
ngx_feature_libs="-Wl,--require-defined=strerror"
494+
ngx_feature_run=no
495+
ngx_feature_incs="#include <stdio.h>"
496+
ngx_feature_test='printf("hello");'
495497

496-
. auto/feature
498+
. auto/feature
497499

498-
if [ $ngx_found = yes ]; then
499-
CORE_LIBS="$CORE_LIBS -all_load -U pcre_version"
500-
fi
500+
if [ $ngx_found = yes ]; then
501+
CORE_LIBS="-Wl,--require-defined=pcre_version $CORE_LIBS"
502+
fi
503+
;;
504+
esac
501505
fi
502506

503507
# ----------------------------------------

0 commit comments

Comments
 (0)