[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patches] LD_PRELOAD and cross-test-wrapper don't mix



A few of the GLIBC tests set LD_PRELOAD while running the test
executable.  When cross-test-wrapper is set, this results in the tests
being invoked like this:

      LD_PRELOAD=foo.so $(cross-test-wrapper) tst-foo

This means that the LD_PRELOAD assignment affects the wrapper program
itself, producing a lot of noisy error messages when foo.so is of the
wrong architecture for the wrapper, and who knows what when it's
actually loadable.

Ideally, one would declare cross-test wrappers responsible for passing
through LD_PRELOAD transparently, but this isn't really practical: by
its nature, the dynamic linker attempts the preload before passing
control to the wrapper, whether it's a script or an ordinary
executable.  cross-test-wrapper could be some horrible sequence of
shell magic, but that wouldn't work in cases where cross-test-wrapper
is passed into a script as a variable's value: substituted variable
values get broken into words, but not re-parsed as commands.

So, here's a patch which takes what seemed to me the most
straightforward approach.  I've committed it (to 2.5 and trunk) to
avoid noise in tonight's tests, but comments are welcome.

ChangeLog.eglibc:
2007-03-22  Jim Blandy  <jimb@xxxxxxxxxxxxxxxx>

	Run tests that set LD_PRELOAD properly, even when
	cross-test-wrapper is set.
	* scripts/run-with-preload.sh: New script.
	* Makeconfig (run-program-prefix, built-program-cmd): If
	$*-WRAPPER is set, include it in the command.
	* nptl/Makefile: Pass path to run-with-preload.sh script to
	tst-tls6.sh.
	* nptl/tst-tls6.sh: Pass LD_PRELOAD to test programs in a
	cross-test-wrapper-friendly way.
	* elf/Makefile (preloadtest-ENV, vismain-ENV): Set
	EGLIBC_TEST_LD_PRELOAD, not LD_PRELOAD.
	(preloadtest-WRAPPER, vismain-WRAPPER): Set to
	run-with-preload.sh.

Index: scripts/run-with-preload.sh
===================================================================
--- scripts/run-with-preload.sh	(revision 0)
+++ scripts/run-with-preload.sh	(revision 0)
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Usage: run-with-preload.sh CMD ...
+#
+# Set the LD_PRELOAD environment variable to the value of the
+# $EGLIBC_TEST_LD_PRELOAD environment variable, and run CMD ... .
+#
+# The EGLIBC test suite uses this to set LD_PRELOAD for test programs.
+# If we simply say:
+#    LD_PRELOAD=smootz \
+#    $(cross-test-wrapper) \
+#    tst-foo arg1 arg2
+# then the LD_PRELOAD setting inteferes with the execution of
+# $(cross-test-wrapper).  If we instead say:
+#    EGLIBC_TEST_LD_PRELOAD=smootz \
+#    $(cross-test-wrapper) \
+#    run-with-preload.sh \
+#    tst-foo arg1 arg2
+# then things work fine.
+
+LD_PRELOAD="$EGLIBC_TEST_LD_PRELOAD" exec "$@"

Property changes on: scripts/run-with-preload.sh
___________________________________________________________________
Name: svn:executable
   + *

Index: Makeconfig
===================================================================
--- Makeconfig	(revision 1781)
+++ Makeconfig	(working copy)
@@ -564,8 +564,10 @@
 else
 run-via-rtld-prefix =
 endif
-run-program-prefix = $(cross-test-wrapper) $(run-via-rtld-prefix)
-built-program-cmd = $(cross-test-wrapper) $(run-via-rtld-prefix) $(built-program-file)
+run-program-prefix = $(cross-test-wrapper) $($*-WRAPPER) \
+	             $(run-via-rtld-prefix)
+built-program-cmd = $(cross-test-wrapper) $($*-WRAPPER) \
+		    $(run-via-rtld-prefix) $(built-program-file)
 
 # Same as built-program-cmd, but without the cross-test-wrapper.  Used 
 # to run programs from the test machine, as in nptl/tst-cancel7.
Index: nptl/Makefile
===================================================================
--- nptl/Makefile	(revision 1781)
+++ nptl/Makefile	(working copy)
@@ -470,7 +470,8 @@
 		       $(objpfx)tst-tls5modc.so $(objpfx)tst-tls5modd.so \
 		       $(objpfx)tst-tls5mode.so $(objpfx)tst-tls5modf.so
 	$(SHELL) -e tst-tls6.sh $(common-objpfx) $(elf-objpfx) \
-		    $(rtld-installed-name) '$(cross-test-wrapper)'
+		    $(rtld-installed-name) '$(cross-test-wrapper)' \
+		    $(..)scripts/run-with-preload.sh
 endif
 
 $(objpfx)tst-dlsym1: $(libdl) $(shared-thread-library)
Index: nptl/tst-tls6.sh
===================================================================
--- nptl/tst-tls6.sh	(revision 1781)
+++ nptl/tst-tls6.sh	(working copy)
@@ -4,13 +4,14 @@
 elf_objpfx=$1; shift
 rtld_installed_name=$1; shift
 cross_test_wrapper=$1; shift
+run_with_preload=$1; shift
 logfile=$common_objpfx/nptl/tst-tls6.out
 
 # We have to find libc and nptl
 library_path=${common_objpfx}:${common_objpfx}nptl
 tst_tls5="${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
 	  ${common_objpfx}/nptl/tst-tls5"
-tst_tls5="$cross_test_wrapper $tst_tls5"
+tst_tls5="$cross_test_wrapper $run_with_preload $tst_tls5"
 
 LC_ALL=C
 export LC_ALL
@@ -23,32 +24,32 @@
 for aligned in a e f; do
   echo "preload tst-tls5mod{$aligned,b,c,d}.so" >> $logfile
   echo "===============" >> $logfile
-  LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{$aligned,b,c,d}.so \
+  EGLIBC_TEST_LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{$aligned,b,c,d}.so \
 	      | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
   echo >> $logfile
 
   echo "preload tst-tls5mod{b,$aligned,c,d}.so" >> $logfile
   echo "===============" >> $logfile
-  LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{b,$aligned,c,d}.so \
+  EGLIBC_TEST_LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{b,$aligned,c,d}.so \
 	      | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
   echo >> $logfile
 
   echo "preload tst-tls5mod{b,c,d,$aligned}.so" >> $logfile
   echo "===============" >> $logfile
-  LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{b,c,d,$aligned}.so \
+  EGLIBC_TEST_LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{b,c,d,$aligned}.so \
 	      | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
   echo >> $logfile
 done
 
 echo "preload tst-tls5mod{d,a,b,c,e}" >> $logfile
 echo "===============" >> $logfile
-LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{d,a,b,c,e}.so \
+EGLIBC_TEST_LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{d,a,b,c,e}.so \
 	    | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
 echo >> $logfile
 
 echo "preload tst-tls5mod{d,a,b,e,f}" >> $logfile
 echo "===============" >> $logfile
-LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{d,a,b,e,f}.so \
+EGLIBC_TEST_LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{d,a,b,e,f}.so \
 	    | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
 echo >> $logfile
 
Index: elf/Makefile
===================================================================
--- elf/Makefile	(revision 1781)
+++ elf/Makefile	(working copy)
@@ -541,7 +541,8 @@
 LDFLAGS-preloadtest = -rdynamic
 $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so)
 preloadtest-ENV = \
-  LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
+  EGLIBC_TEST_LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
+preloadtest-WRAPPER = $(..)scripts/run-with-preload.sh
 
 $(objpfx)loadfail: $(libdl)
 LDFLAGS-loadfail = -rdynamic
@@ -587,7 +588,8 @@
 
 $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so)
 $(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so)
-vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)
+vismain-ENV = EGLIBC_TEST_LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)
+vismain-WRAPPER = $(..)scripts/run-with-preload.sh
 
 $(objpfx)noload: $(objpfx)testobj1.so
 LDFLAGS-noload = -rdynamic