From 18459cfcf8fcbbbbd631b51d20842205809c65b3 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Sat, 21 Oct 2017 16:56:52 +0200 Subject: [PATCH] Configuration/build system: ensure test runs in user environment.. On the OpenCSW cluster i have found myself in the grotesque situation that the test is running whereas the binary as such is unusable: ?0[sdaoden@unstable11x nail.git]$ make test ... [t_behave_s_mime] behave:s/mime: .. generating test key and certificate .. behave:s/mime:sign/verify: ok ... behave:s/mime:decrypt:disproof-1: ok ... ?0[sdaoden@unstable11x nail.git]$ ./s-nail -R ld.so.1: s-nail: fatal: relocation error: file s-nail: symbol SSL_CONF_CTX_new: referenced symbol not found Killed So despite that the gcc there is buggy by placing /usr/lib first in the searchlist no matter what i do $ gcc -Wl,-R/opt/csw/lib -Wl,-R/usr/xpg4/lib -Wl,-R/home/sdaoden/usr/lib -Wl,-R/lib -Wl,-R/usr/lib -Wl,-R/usr/X11/lib -pie -o s-nail ... $ elfdump -d s-nail ... [11] RUNPATH 0x4690 /usr/lib:/opt/csw/lib:/usr/xpg4/lib:/home/sdaoden/usr/lib:/lib:/usr/X11/lib [12] RPATH 0x4690 /usr/lib:/opt/csw/lib:/usr/xpg4/lib:/home/sdaoden/usr/lib:/lib:/usr/X11/lib that can be fixed with Solaris Studio: $ make all CC=/opt/solarisstudio12.4/bin/cc ... [11] RUNPATH 0x50a4 /opt/csw/lib:/usr/xpg4/lib:/home/sdaoden/usr/lib:/lib:/usr/lib:/usr/X11/lib:/usr/lib [12] RPATH 0x50a4 /opt/csw/lib:/usr/xpg4/lib:/home/sdaoden/usr/lib:/lib:/usr/lib:/usr/X11/lib:/usr/lib though that blindly seems to append /usr/lib even though that already is included (or is that a bug of mine :-o???) but it seems as if LD_LIBRARY_PATH is preferred not only over DT_RUNPATH, which is fine, but also over DT_RPATH? That is surely a bug in the linker, then. I already committed a change that avoids checking for -Wl,--enable-new-dtags when we modify LD_LIBRARY_PATH (make-config.sh: prefer DT_RPATH over DT_RUNPATH when modified LD_LIBRARY_PATH) In order to be able to get such problems reflected by the test, avoid to modify the users environment as much as possible. --- cc-test.sh | 3 +++ make-config.in | 6 ------ make-config.sh | 41 +++++++++++++++++++++++------------------ makefile | 12 +++++++----- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/cc-test.sh b/cc-test.sh index 8ee45a9c..10bdb343 100755 --- a/cc-test.sh +++ b/cc-test.sh @@ -5,6 +5,9 @@ #@ TODO _All_ the tests should happen in a temporary subdir. # Public Domain +# Instead of figuring out the environment in here, require a configured build +# system and include that! Our makefile and configure ensure that this test +# does not run in the configured, but the user environment nonetheless! if [ -f ./mk-config.ev ]; then . ./mk-config.ev if [ -z "${MAILX__CC_TEST_RUNNING}" ]; then diff --git a/make-config.in b/make-config.in index f13d144f..e39143eb 100644 --- a/make-config.in +++ b/make-config.in @@ -35,12 +35,6 @@ privsep.o: $(SRCDIR)privsep.c mk-config.h config.h \ $(SRCDIR)nail.h $(SRCDIR)dotlock.h $(ECHO_CC)$(CC) $(CFLAGS) $(BASE_INCS) -c $(SRCDIR)privsep.c -test: all - $(ECHO_TEST)\ - MAKE=$(MAKE) SHELL=$(SHELL) \ - awk=$(awk) cat=$(cat) cksum=$(cksum) rm=$(rm) sed=$(sed) grep=$(grep) \ - $(SHELL) $(SRCDIR)cc-test.sh --check-only ./$(VAL_UAGENT) - gen-mime-types.h: $(SRCDIR)mime.types $(ECHO_GEN)\ LC_ALL=C < $(SRCDIR)mime.types > $(@) $(awk) '\ diff --git a/make-config.sh b/make-config.sh index 5e597296..2ee73157 100644 --- a/make-config.sh +++ b/make-config.sh @@ -457,7 +457,7 @@ _cc_flags_tcc() { if [ -z "${ld_rpath_not_runpath}" ]; then ld_check -Wl,--enable-new-dtags else - msg '$LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags' + msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags' fi ld_runtime_flags # update! fi @@ -474,7 +474,7 @@ _cc_flags_generic() { # E.g., valgrind does not work well with high optimization if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG && feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then - msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)' + msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)' cc_maxopt=1 fi # Check -g first since some others may rely upon -g / optim. level @@ -531,9 +531,9 @@ _cc_flags_generic() { cc_check -D_FORTIFY_SOURCE=2 fi else - msg 'Not checking for -fstack-protector compiler option,' - msg 'since that caused errors in a "similar" configuration.' - msg 'You may turn off OPT_AUTOCC and use your own settings, rerun' + msg ' ! Not checking for -fstack-protector compiler option,' + msg ' ! since that caused errors in a "similar" configuration.' + msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun' fi fi @@ -572,7 +572,7 @@ _cc_flags_generic() { if [ -z "${ld_rpath_not_runpath}" ]; then ld_check -Wl,--enable-new-dtags else - msg '$LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags' + msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags' fi ld_runtime_flags # update! elif ld_check -Wl,-R ./ no; then @@ -580,7 +580,7 @@ _cc_flags_generic() { if [ -z "${ld_rpath_not_runpath}" ]; then ld_check -Wl,--enable-new-dtags else - msg '$LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags' + msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags' fi ld_runtime_flags # update! fi @@ -1196,10 +1196,25 @@ msg_nonl 'Evaluating all configuration items ... ' option_evaluate msg 'done' -# Add the known utility and some other variables printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh} printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk} +# The problem now is that the test should be able to run in the users linker +# and path environment, so we need to place the test: rule first, before +# injecting the relevant make variables. Set up necessary environment +if [ -z "${VERBOSE}" ]; then + printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk} + printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk} + printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk} + printf -- "ECHO_TEST = @\n" >> ${newmk} + printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk} + printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk} + printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk} +fi +printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \ + "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk} + +# Add the known utility and some other variables printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh} printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk} if feat_yes DOTLOCK; then @@ -1311,16 +1326,6 @@ ${mv} -f ${newev} ${ev} ${mv} -f ${newh} ${h} ${mv} -f ${newmk} ${mk} -if [ -z "${VERBOSE}" ]; then - printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk} - printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk} - printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk} - printf -- "ECHO_TEST = @\n" >> ${mk} - printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk} - printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk} - printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk} -fi - ## Compile and link checking tmp3=./${tmp0}3$$ diff --git a/makefile b/makefile index dae6d39f..715a4a78 100644 --- a/makefile +++ b/makefile @@ -29,9 +29,6 @@ clean: distclean: @$(_prestop); LC_ALL=C $${MAKE} -f mk-config.mk distclean -test: - @$(_prestop); LC_ALL=C $${MAKE} -f mk-config.mk $(MAKEJOBS) test - devel: @CONFIG=DEVEL; export CONFIG; $(_prego); $(_prestop);\ LC_ALL=C $${MAKE} -f mk-config.mk _update-version &&\ @@ -45,6 +42,10 @@ d-b: LC_ALL=C $${MAKE} -f mk-config.mk _update-version &&\ LC_ALL=C $${MAKE} -f mk-config.mk $(MAKEJOBS) all +# The test should inherit the user runtime environment! +test: + @$(__prestop); LC_ALL=C $(MAKE) -f mk-config.mk test + d-gettext: cd "$(SRCDIR)" &&\ LC_ALL=C xgettext --sort-by-file --strict --add-location \ @@ -56,11 +57,12 @@ _prego = if CWDDIR="$(CWDDIR)" SRCDIR="$(SRCDIR)" \ SHELL="$(SHELL)" MAKE="$(MAKE)" CC="$(CC)" \ CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \ $(SHELL) "$(SRCDIR)"make-config.sh; then :; else exit 1; fi -_prestop = if [ -f ./mk-config.mk ]; then :; else \ +__prestop = if [ -f ./mk-config.mk ]; then :; else \ echo 'Program not configured, nothing to do';\ echo 'Use one of the targets: config, all, tangerine, citron';\ exit 1;\ - fi;\ + fi +_prestop = $(__prestop);\ < ./mk-config.ev read __ev__; eval $${__ev__}; unset __ev__ # s-mk-mode -- 2.11.4.GIT