From f6539408afdf48b27b9fb2092f033a5a917b9dc9 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 5 Aug 2008 21:41:30 +0000 Subject: [PATCH] Overhaul Makefile.in and configure.ac to link NSE C modules explicitly with liblua and libm. This is necessary for static builds of Nmap, such as RPM builds. Before this the error that was caused looked like SCRIPT ENGINE: error while initializing script rules: error loading module 'bit' from file '/usr/libexec/nmap/nselib-bin/bit.so': /usr/libexec/nmap/nselib-bin/bit.so: undefined symbol: lua_pushnumber stack traceback: [C]: ? [C]: in function 'require' /usr/share/nmap/nselib/packet.lua:12: in main chunk [C]: in function 'require' /usr/share/nmap/scripts/rpcinfo.nse:10: in main chunk [C]: ? [C]: in function 'Entry' /usr/share/nmap/scripts/script.db:8: in main chunk [C]: ? [C]: ? --- CHANGELOG | 9 ++ nselib-bin/Makefile.in | 23 ++-- nselib-bin/configure | 229 ++++++++++++++++++++++++++++++++++------ nselib-bin/configure.ac | 46 ++++++-- 4 files changed, 258 insertions(+), 49 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b4db2ec6c..bc82eb55a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -129,6 +129,15 @@ o A bug that could cause some host discovery probes to be incorrectly protocol ping (-PO) option was combined with other ping types. [David] +o The NSE C modules in nselib-bin are now linked explicitly against + liblua. Before this, loading such modules from a static build of + Nmap failed, leading to this error whenever one was used: + SCRIPT ENGINE: error while initializing script rules: + error loading module 'bit' from file '/usr/libexec/nmap/nselib-bin/bit.so': + /usr/libexec/nmap/nselib-bin/bit.so: undefined symbol: lua_pushnumber + Because RPM builds are static this fixes NSE C modules in + RPMs. [David] + Nmap 4.68 [2008-6-28] o Doug integrated all of your version detection submissions and diff --git a/nselib-bin/Makefile.in b/nselib-bin/Makefile.in index 30ce5b83b..72e5c2b5c 100644 --- a/nselib-bin/Makefile.in +++ b/nselib-bin/Makefile.in @@ -1,22 +1,25 @@ -PLATFORM=@host@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +sbindir = @sbindir@ +mandir = @mandir@ +libexecdir = @libexecdir@ +nselib_bindir = $(libexecdir)/nmap/nselib-bin CC = @CC@ -CXX = @CXX@ -CCOPT = -DBGFLAGS = +CPPFLAGS = @CPPFLAGS@ +CFLAGS = @CFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ - -SHTOOL = ../shtool -INSTALL = $(SHTOOL) install - LIBTOOL= ./libtool LTFLAGS = --tag=CC --silent all: bit.so bit.so: bit.c @LIBTOOL_DEPS@ - $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) @LUAINCLUDE@ $(CFLAGS) -c bit.c - $(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -avoid-version -module -rpath /usr/local/lib -o bit.la bit.lo + $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -c bit.c + $(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -avoid-version -module -rpath $(nselib_bindir) $(LDFLAGS) -o bit.la bit.lo $(LIBS) mv .libs/bit.so bit.so clean: diff --git a/nselib-bin/configure b/nselib-bin/configure index 803fadfb7..0e58de3dd 100755 --- a/nselib-bin/configure +++ b/nselib-bin/configure @@ -836,7 +836,6 @@ FFLAGS ac_ct_F77 LIBTOOL LIBTOOL_DEPS -LUAINCLUDE LIBOBJS LTLIBOBJS' ac_subst_files='' @@ -1440,6 +1439,9 @@ Optional Packages: --with-pic try to use only PIC/non-PIC objects [default=use both] --with-tags[=TAGS] include additional configurations [automatic] + --with-liblua=DIR Use an existing (compiled) lua lib from DIR/include + and DIR/lib. + --with-liblua=included Use the liblua version included with Nmap Some influential environment variables: CC C compiler command @@ -3631,7 +3633,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 3634 "configure"' > conftest.$ac_ext + echo '#line 3636 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -6253,11 +6255,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6256: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6258: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6260: \$? = $ac_status" >&5 + echo "$as_me:6262: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -6521,11 +6523,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6524: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6526: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6528: \$? = $ac_status" >&5 + echo "$as_me:6530: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -6625,11 +6627,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6628: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6630: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:6632: \$? = $ac_status" >&5 + echo "$as_me:6634: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -8922,7 +8924,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:11367: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:11369: \$? = $ac_status" >&5 + echo "$as_me:11371: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -11466,11 +11468,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:11469: $lt_compile\"" >&5) + (eval echo "\"\$as_me:11471: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:11473: \$? = $ac_status" >&5 + echo "$as_me:11475: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -13027,11 +13029,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:13030: $lt_compile\"" >&5) + (eval echo "\"\$as_me:13032: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:13034: \$? = $ac_status" >&5 + echo "$as_me:13036: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -13131,11 +13133,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:13134: $lt_compile\"" >&5) + (eval echo "\"\$as_me:13136: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:13138: \$? = $ac_status" >&5 + echo "$as_me:13140: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -15322,11 +15324,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:15325: $lt_compile\"" >&5) + (eval echo "\"\$as_me:15327: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:15329: \$? = $ac_status" >&5 + echo "$as_me:15331: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -15590,11 +15592,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:15593: $lt_compile\"" >&5) + (eval echo "\"\$as_me:15595: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:15597: \$? = $ac_status" >&5 + echo "$as_me:15599: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -15694,11 +15696,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:15697: $lt_compile\"" >&5) + (eval echo "\"\$as_me:15699: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:15701: \$? = $ac_status" >&5 + echo "$as_me:15703: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -18387,8 +18389,101 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac -# needed for lua-includes -if test "${ac_cv_header_lua_h+set}" = set; then +# liblua appears to need libm. + +{ echo "$as_me:$LINENO: checking for pow in -lm" >&5 +echo $ECHO_N "checking for pow in -lm... $ECHO_C" >&6; } +if test "${ac_cv_lib_m_pow+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pow (); +int +main () +{ +return pow (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_m_pow=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_m_pow=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_m_pow" >&5 +echo "${ECHO_T}$ac_cv_lib_m_pow" >&6; } +if test $ac_cv_lib_m_pow = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBM 1 +_ACEOF + + LIBS="-lm $LIBS" + +fi + + +# Don't bother with --without-liblua because this directory isn't even +# configured if that's the case. + +# Check whether --with-liblua was given. +if test "${with_liblua+set}" = set; then + withval=$with_liblua; case "$with_liblua" in + yes) + with_liblua= + ;; + included) + with_liblua=../liblua + ;; + *) + ;; +esac + +fi + + +# If no liblua location was given search for one. +if test "x$with_liblua" = "x"; then + if test "${ac_cv_header_lua_h+set}" = set; then { echo "$as_me:$LINENO: checking for lua.h" >&5 echo $ECHO_N "checking for lua.h... $ECHO_C" >&6; } if test "${ac_cv_header_lua_h+set}" = set; then @@ -18514,14 +18609,86 @@ echo "${ECHO_T}$ac_cv_header_lua_h" >&6; } fi if test $ac_cv_header_lua_h = yes; then - : + { echo "$as_me:$LINENO: checking for lua_call in -llua" >&5 +echo $ECHO_N "checking for lua_call in -llua... $ECHO_C" >&6; } +if test "${ac_cv_lib_lua_lua_call+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - { echo "$as_me:$LINENO: using lua-includefiles provided with nmap" >&5 -echo "$as_me: using lua-includefiles provided with nmap" >&6;};LUAINCLUDE=-I../liblua/ + ac_check_lib_save_LIBS=$LIBS +LIBS="-llua $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char lua_call (); +int +main () +{ +return lua_call (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_lua_lua_call=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_lua_lua_call=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ echo "$as_me:$LINENO: result: $ac_cv_lib_lua_lua_call" >&5 +echo "${ECHO_T}$ac_cv_lib_lua_lua_call" >&6; } +if test $ac_cv_lib_lua_lua_call = yes; then + system_liblua=yes +fi + fi + # If none was found use the included liblua. + if test "$system_liblua" != "yes"; then + with_liblua=../liblua + fi +fi +if test "x$with_liblua" != "x"; then + CPPFLAGS="-I$with_liblua $CPPFLAGS" + LDFLAGS="-L$with_liblua $LDFLAGS" +fi + +LIBS="-llua $LIBS" ac_config_files="$ac_config_files Makefile" @@ -19222,12 +19389,11 @@ FFLAGS!$FFLAGS$ac_delim ac_ct_F77!$ac_ct_F77$ac_delim LIBTOOL!$LIBTOOL$ac_delim LIBTOOL_DEPS!$LIBTOOL_DEPS$ac_delim -LUAINCLUDE!$LUAINCLUDE$ac_delim LIBOBJS!$LIBOBJS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 72; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 71; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 @@ -19554,4 +19720,3 @@ if test "$no_create" != yes; then $ac_cs_success || { (exit 1); exit 1; } fi - diff --git a/nselib-bin/configure.ac b/nselib-bin/configure.ac index a83e672ad..71970c528 100644 --- a/nselib-bin/configure.ac +++ b/nselib-bin/configure.ac @@ -1,4 +1,4 @@ -AC_PREREQ(2.13) +AC_PREREQ([2.13]) AC_INIT([nselib.h]) AC_PROG_CC @@ -8,16 +8,48 @@ AC_PROG_CC AC_DISABLE_STATIC AC_LIBTOOL_DLOPEN AC_PROG_LIBTOOL -AC_SUBST(LIBTOOL) +AC_SUBST([LIBTOOL]) -AC_SUBST(LIBTOOL_DEPS) +AC_SUBST([LIBTOOL_DEPS]) AC_CANONICAL_HOST -# needed for lua-includes -AC_CHECK_HEADER([lua.h],,[AC_MSG_NOTICE(using lua-includefiles provided with nmap);[LUAINCLUDE=-I../liblua/]],) -AC_SUBST(LUAINCLUDE) +# liblua appears to need libm. +AC_CHECK_LIB([m], [pow]) + +# Don't bother with --without-liblua because this directory isn't even +# configured if that's the case. +AC_ARG_WITH([liblua], +AC_HELP_STRING([--with-liblua=DIR], [Use an existing (compiled) lua lib from DIR/include and DIR/lib.]) +AC_HELP_STRING([--with-liblua=included], [Use the liblua version included with Nmap]), +[ case "$with_liblua" in + yes) + with_liblua= + ;; + included) + with_liblua=../liblua + ;; + *) + ;; +esac ] +) + +# If no liblua location was given search for one. +if test "x$with_liblua" = "x"; then + AC_CHECK_HEADER([lua.h], + AC_CHECK_LIB([lua], [lua_call], [system_liblua=yes])) + # If none was found use the included liblua. + if test "$system_liblua" != "yes"; then + with_liblua=../liblua + fi +fi + +if test "x$with_liblua" != "x"; then + CPPFLAGS="-I$with_liblua $CPPFLAGS" + LDFLAGS="-L$with_liblua $LDFLAGS" +fi + +LIBS="-llua $LIBS" AC_CONFIG_FILES([Makefile]) AC_OUTPUT -