[RFC] Alternative LD_LIBRARY_PATH

John David Anglin dave@hiauly1.hia.nrc.ca
Fri Nov 19 06:18:00 GMT 2004


Here is an alternative patch for handling LD_LIBRARY_PATH and related
environment variables.  There are a couple of signicant improvements
over what we do now.

1) The code to set these variables is consolidated in one file and
   isn't duplicated across many different files.

2) I believe that there is an improvment in handling environment
   variables on systems that don't use LD_LIBRARY_PATH, or use
   multiple variables.

3) There is a proc to restore the initial saved state.

I've tested this change on hppa-unknown-linux-gnu.

Comments?

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

2004-11-18  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	* lib/target-libpath.exp: New file defining set_ld_library_path_env_vars
	and restore_ld_library_path_env_vars.
	* g++.dg/compat/compat.exp, lib/g++.exp, lib/gcc-dg.exp,
	lib/gfortran.exp, lib/objc.exp, lib/treelang.exp: Use new procs.
	* ada/acats/run_acats (LD_LIBRARY_PATH): Include existing path
	when setting LD_LIBRARY_PATH.  Export LD_LIBRARY_PATH.

	* testsuite/lib/libffi-dg.exp: Use new procs in target-libpath.exp.

	* testsuite/lib/libjava.exp, testsuite/libjava.jacks/jacks.exp: Use new
	procs in target-libpath.exp.

	* testsuite/lib/libmudflap.exp: Use new procs in target-libpath.exp.

	* testsuite/lib/libstdc++.exp: Use new procs in target-libpath.exp.

--- /dev/null	2004-09-12 21:40:02.000000000 -0700
+++ gcc/testsuite/lib/target-libpath.exp	2004-09-26 10:27:31.000000000 -0700
@@ -0,0 +1,236 @@
+# Copyright (C) 2004 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This file was contributed by John David Anglin (dave.anglin@nrc-cnrc.gc.ca)
+
+set orig_environment_saved 0
+set orig_ld_run_path_saved 0
+set orig_shlib_path_saved 0
+set orig_ld_libraryn32_path_saved 0
+set orig_ld_library64_path_saved 0
+set orig_ld_library_path_32_saved 0
+set orig_ld_library_path_64_saved 0
+set orig_dyld_library_path_saved 0
+
+
+#######################################
+# proc set_ld_library_path_env_vars { }
+#######################################
+
+proc set_ld_library_path_env_vars { } {
+  global ld_library_path
+  global orig_environment_saved
+  global orig_ld_library_path_saved
+  global orig_ld_run_path_saved
+  global orig_shlib_path_saved
+  global orig_ld_libraryn32_path_saved
+  global orig_ld_library64_path_saved
+  global orig_ld_library_path_32_saved
+  global orig_ld_library_path_64_saved
+  global orig_dyld_library_path_saved
+  global orig_ld_library_path
+  global orig_ld_run_path
+  global orig_shlib_path
+  global orig_ld_libraryn32_path
+  global orig_ld_library64_path
+  global orig_ld_library_path_32
+  global orig_ld_library_path_64
+  global orig_dyld_library_path
+
+  # Setting the ld library path causes trouble when testing cross-compilers.
+  if { [is_remote target] } {
+    return
+  }
+
+  if { $orig_environment_saved == 0 } {
+    global env;
+
+    set orig_environment_saved 1
+
+    # Save the original environment.
+    if [info exists env(LD_LIBRARY_PATH)] {
+      set orig_ld_library_path "$env(LD_LIBRARY_PATH)"
+      set orig_ld_library_path_saved 1
+    }
+    if [info exists env(LD_RUN_PATH)] {
+      set orig_ld_run_path "$env(LD_RUN_PATH)"
+      set orig_ld_run_path_saved 1
+    }
+    if [info exists env(SHLIB_PATH)] {
+      set orig_shlib_path "$env(SHLIB_PATH)"
+      set orig_shlib_path_saved 1
+    }
+    if [info exists env(LD_LIBRARYN32_PATH)] {
+      set orig_ld_libraryn32_path "$env(LD_LIBRARYN32_PATH)"
+      set orig_ld_libraryn32_path_saved 1
+    }
+    if [info exists env(LD_LIBRARY64_PATH)] {
+      set orig_ld_library64_path "$env(LD_LIBRARY64_PATH)"
+      set orig_ld_library64_path_saved 1
+    }
+    if [info exists env(LD_LIBRARY_PATH_32)] {
+      set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)"
+      set orig_ld_library_path_32_saved 1
+    }
+    if [info exists env(LD_LIBRARY_PATH_64)] {
+      set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)"
+      set orig_ld_library_path_64_saved 1
+    }
+    if [info exists env(DYLD_LIBRARY_PATH)] {
+      set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)"
+      set orig_dyld_library_path_saved 1
+    }
+  }
+
+  # We need to set ld library path in the environment.  Currently,
+  # unix.exp doesn't set the environment correctly for all systems.
+  # It only sets SHLIB_PATH and LD_LIBRARY_PATH when it executes a
+  # program.  We also need the environment set for compilations, etc.
+  #
+  # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
+  # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
+  # (for the 64-bit ABI).  The same applies to Darwin (DYLD_LIBRARY_PATH),
+  # Solaris 32 bit (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64),
+  # and HP-UX (SHLIB_PATH).  In some cases, the variables are independent
+  # of LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the
+  # variable is not defined.
+  #
+  # Doing this is somewhat of a hack as ld_library_path gets repeated in
+  # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables.
+  if { $orig_ld_library_path_saved } {
+    setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
+  } else {
+    setenv LD_LIBRARY_PATH "$ld_library_path"
+  }
+  if { $orig_ld_run_path_saved } {
+    setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path"
+  } else {
+    setenv LD_RUN_PATH "$ld_library_path"
+  }
+  # The default shared library dynamic path search for 64-bit
+  # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH.
+  # LD_LIBRARY_PATH isn't used for 32-bit executables.  Thus, we
+  # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent.
+  if { $orig_shlib_path_saved } {
+    setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path"
+  } else {
+    setenv SHLIB_PATH "$ld_library_path"
+  }
+  if { $orig_ld_libraryn32_path_saved } {
+    setenv LD_LIBRARYN32_PATH "$ld_library_path:$orig_ld_libraryn32_path"
+  } elseif { $orig_ld_library_path_saved } {
+    setenv LD_LIBRARYN32_PATH "$ld_library_path:$orig_ld_library_path"
+  } else {
+    setenv LD_LIBRARYN32_PATH "$ld_library_path"
+  }
+  if { $orig_ld_library64_path_saved } {
+    setenv LD_LIBRARY64_PATH "$ld_library_path:$orig_ld_library64_path"
+  } elseif { $orig_ld_library_path_saved } {
+    setenv LD_LIBRARY64_PATH "$ld_library_path:$orig_ld_library_path"
+  } else {
+    setenv LD_LIBRARY64_PATH "$ld_library_path"
+  }
+  if { $orig_ld_library_path_32_saved } {
+    setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32"
+  } elseif { $orig_ld_library_path_saved } {
+    setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path"
+  } else {
+    setenv LD_LIBRARY_PATH_32 "$ld_library_path"
+  }
+  if { $orig_ld_library_path_64_saved } {
+    setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64"
+  } elseif { $orig_ld_library_path_saved } {
+    setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path"
+  } else {
+    setenv LD_LIBRARY_PATH_64 "$ld_library_path"
+  }
+  if { $orig_dyld_library_path_saved } {
+    setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path"
+  } else {
+    setenv DYLD_LIBRARY_PATH "$ld_library_path"
+  }
+
+  verbose -log "set_ld_library_path_env_vars: ld_library_path=$ld_library_path"
+}
+
+#######################################
+# proc restore_ld_library_path_env_vars { }
+#######################################
+
+proc restore_ld_library_path_env_vars { } {
+  global orig_environment_saved
+  global orig_ld_library_path_saved
+  global orig_ld_run_path_saved
+  global orig_shlib_path_saved
+  global orig_ld_libraryn32_path_saved
+  global orig_ld_library64_path_saved
+  global orig_ld_library_path_32_saved
+  global orig_ld_library_path_64_saved
+  global orig_dyld_library_path_saved
+  global orig_ld_library_path
+  global orig_ld_run_path
+  global orig_shlib_path
+  global orig_ld_libraryn32_path
+  global orig_ld_library64_path
+  global orig_ld_library_path_32
+  global orig_ld_library_path_64
+  global orig_dyld_library_path
+
+  if { $orig_environment_saved == 0 } {
+    return
+  }
+
+  if { $orig_ld_library_path_saved } {
+    setenv LD_LIBRARY_PATH "$orig_ld_library_path"
+  } else {
+    unsetenv LD_LIBRARY_PATH
+  }
+  if { $orig_ld_run_path_saved } {
+    setenv LD_RUN_PATH "$orig_ld_run_path"
+  } else {
+    unsetenv LD_RUN_PATH
+  }
+  if { $orig_shlib_path_saved } {
+    setenv SHLIB_PATH "$orig_shlib_path"
+  } else {
+    unsetenv SHLIB_PATH
+  }
+  if { $orig_ld_libraryn32_path_saved } {
+    setenv LD_LIBRARYN32_PATH "$orig_ld_libraryn32_path"
+  } else {
+    unsetenv LD_LIBRARYN32_PATH
+  }
+  if { $orig_ld_library64_path_saved } {
+    setenv LD_LIBRARY64_PATH "$orig_ld_library64_path"
+  } else {
+    unsetenv LD_LIBRARY64_PATH
+  }
+  if { $orig_ld_library_path_32_saved } {
+    setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
+  } else {
+    unsetenv LD_LIBRARY_PATH_32
+  }
+  if { $orig_ld_library_path_64_saved } {
+    setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
+  } else {
+    unsetenv LD_LIBRARY_PATH_64
+  }
+  if { $orig_dyld_library_path_saved } {
+    setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
+  } else {
+    unsetenv DYLD_LIBRARY_PATH
+  }
+}
Index: gcc/testsuite/ada/acats/run_acats
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/ada/acats/run_acats,v
retrieving revision 1.5
diff -u -3 -p -r1.5 run_acats
--- gcc/testsuite/ada/acats/run_acats	8 Jan 2004 15:19:36 -0000	1.5
+++ gcc/testsuite/ada/acats/run_acats	19 Nov 2004 03:13:14 -0000
@@ -14,6 +14,7 @@ BASE=`cd $ROOT/../../..; ${PWDCMD-pwd}`
 
 PATH=$BASE:$ROOT:$PATH
 ADA_INCLUDE_PATH=$BASE/ada/rts
+LD_LIBRARY_PATH=$ADA_INCLUDE_PATH:$LD_LIBRARY_PATH
 ADA_OBJECTS_PATH=$ADA_INCLUDE_PATH
 
 if [ ! -d $ADA_INCLUDE_PATH ]; then
@@ -33,7 +34,7 @@ fi
 
 GCC_DRIVER="$BASE/xgcc"
 GCC="$BASE/xgcc -B$BASE/"
-export PATH ADA_INCLUDE_PATH ADA_OBJECTS_PATH GCC_DRIVER GCC
+export PATH ADA_INCLUDE_PATH ADA_OBJECTS_PATH GCC_DRIVER GCC LD_LIBRARY_PATH
 
 echo '#!/bin/sh' > host_gnatchop
 echo PATH=`dirname $host_gnatchop`:'$PATH' >> host_gnatchop
Index: gcc/testsuite/g++.dg/compat/compat.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/compat/compat.exp,v
retrieving revision 1.5
diff -u -3 -p -r1.5 compat.exp
--- gcc/testsuite/g++.dg/compat/compat.exp	23 Jan 2004 04:42:39 -0000	1.5
+++ gcc/testsuite/g++.dg/compat/compat.exp	19 Nov 2004 03:13:15 -0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2002 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -35,25 +35,7 @@ global ld_library_path
 # Load procedures from common libraries. 
 load_lib standard.exp
 load_lib g++.exp
-
-#
-# compat-fix-library-path -- switch LD_LIBRARY_PATH
-#
-proc compat-fix-library-path { } {
-    global ld_library_path
-
-    # See comments in lib/g++.exp for why this is needed.
-    if {![is_remote target]} {
-	# See comments in lib/g++.exp for why this is needed.
-	setenv  LD_LIBRARY_PATH     $ld_library_path
-	setenv  SHLIB_PATH          $ld_library_path
-	setenv  LD_LIBRARYN32_PATH  $ld_library_path
-	setenv  LD_LIBRARY64_PATH   $ld_library_path
-	setenv  LD_LIBRARY_PATH_32  $ld_library_path
-	setenv  LD_LIBRARY_PATH_64  $ld_library_path
-	setenv  DYLD_LIBRARY_PATH   $ld_library_path
-    }
-}
+load_lib target-libpath.exp
 
 #
 # compat-use-alt-compiler -- make the alternate compiler the default
@@ -72,7 +54,7 @@ proc compat-use-alt-compiler { } {
 	set CXXFLAGS ""
 	set ALWAYS_CXXFLAGS ""
 	set ld_library_path $alt_ld_library_path
-	compat-fix-library-path
+	set_ld_library_path_env_vars
     }
 }
 
@@ -94,7 +76,7 @@ proc compat-use-tst-compiler { } {
 	set CXXFLAGS $save_cxxflags
 	set ALWAYS_CXXFLAGS $save_always_cxxflags
 	set ld_library_path $save_ld_library_path
-	compat-fix-library-path
+	set_ld_library_path_env_vars
     }
 }
 
Index: gcc/testsuite/lib/g++.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/g++.exp,v
retrieving revision 1.43
diff -u -3 -p -r1.43 g++.exp
--- gcc/testsuite/lib/g++.exp	12 Nov 2004 19:43:57 -0000	1.43
+++ gcc/testsuite/lib/g++.exp	19 Nov 2004 03:13:16 -0000
@@ -24,6 +24,7 @@
 #
 load_lib prune.exp
 load_lib gcc-defs.exp
+load_lib target-libpath.exp
 
 #
 # GXX_UNDER_TEST is the compiler under test.
@@ -166,36 +167,7 @@ proc g++_link_flags { paths } {
       }
     }
 
-    # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-    # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-    # (for the 64-bit ABI).  The right way to do this would be to modify
-    # unix.exp -- but that's not an option since it's part of DejaGNU
-    # proper, so we do it here.
-    # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
-    # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
-    # (SHLIB_PATH).
-    # Doing this does cause trouble when testing cross-compilers.
-    if {![is_remote target]} {
-	global env;
-	if [info exists env(LD_LIBRARY_PATH)] {
-	    # If we've already added these directories once, keep the
-	    # existing path.
-	    if {$ld_library_path == $env(LD_LIBRARY_PATH)
-		|| [string first $ld_library_path: \
-				 $env(LD_LIBRARY_PATH)] == 0} {
-		set ld_library_path $env(LD_LIBRARY_PATH)
-	    } elseif { $env(LD_LIBRARY_PATH) != "" } {
-		append ld_library_path ":$env(LD_LIBRARY_PATH)"
-	    }
-	}
-	setenv  LD_LIBRARY_PATH     $ld_library_path
-	setenv  SHLIB_PATH          $ld_library_path
-	setenv  LD_LIBRARYN32_PATH  $ld_library_path
-	setenv  LD_LIBRARY64_PATH   $ld_library_path
-	setenv  LD_LIBRARY_PATH_32  $ld_library_path
-	setenv  LD_LIBRARY_PATH_64  $ld_library_path
-	setenv  DYLD_LIBRARY_PATH   $ld_library_path
-    }
+    set_ld_library_path_env_vars
 
     return "$flags"
 }
Index: gcc/testsuite/lib/gcc-dg.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/gcc-dg.exp,v
retrieving revision 1.44
diff -u -3 -p -r1.44 gcc-dg.exp
--- gcc/testsuite/lib/gcc-dg.exp	17 Nov 2004 17:21:41 -0000	1.44
+++ gcc/testsuite/lib/gcc-dg.exp	19 Nov 2004 03:13:16 -0000
@@ -1,4 +1,4 @@
-#   Copyright (C) 1997, 1999, 2000, 2003 Free Software Foundation, Inc.
+#   Copyright (C) 1997, 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@ load_lib scanasm.exp
 load_lib scantree.exp
 load_lib prune.exp
 load_lib libgloss.exp
+load_lib target-libpath.exp
 
 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
 setenv LC_ALL C
@@ -51,55 +52,28 @@ if ![info exists GCC_UNDER_TEST] {
 }
 
 global rootme
-set libgcc_s_path "${rootme}"
-set compiler [lindex $GCC_UNDER_TEST 0]
-if { [is_remote host] == 0 && [which $compiler] != 0 } {
-    foreach i "[exec $compiler --print-multi-lib]" {
-	set mldir ""
-	regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
-	set mldir [string trimright $mldir "\;@"]
-	if { "$mldir" == "." } {
-	    continue
-	}
-	if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
-	    append libgcc_s_path ":${rootme}/${mldir}"
-	}
-    }
-}
+global ld_library_path
+global orig_environment_saved
 
-# On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-# called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-# (for the 64-bit ABI).  The right way to do this would be to modify
-# unix.exp -- but that's not an option since it's part of DejaGNU
-# proper, so we do it here.  We really only need to do 
-# this on IRIX, but it shouldn't hurt to do it anywhere else.
-# Doing this does cause trouble when testing cross-compilers.
-if {![is_remote target]} {
-    if [info exists env(LD_LIBRARY_PATH)] {
-	setenv  LD_LIBRARY_PATH    "$libgcc_s_path:$env(LD_LIBRARY_PATH)"
-    } else {
-	setenv  LD_LIBRARY_PATH     $libgcc_s_path
-    }
-    if [info exists env(SHLIB_PATH)] {
-	setenv  SHLIB_PATH          "$libgcc_s_path:$env(SHLIB_PATH)"
-    } else {
-	setenv  SHLIB_PATH          $libgcc_s_path
-    }
-    if [info exists env(LD_LIBRARYN32_PATH)] {
-	setenv  LD_LIBRARYN32_PATH  "$libgcc_s_path:$env(LD_LIBRARYN32_PATH)"
-    } else {
-	setenv  LD_LIBRARYN32_PATH  $libgcc_s_path
-    }
-    if [info exists env(LD_LIBRARY64_PATH)] {
-	setenv  LD_LIBRARY64_PATH  "$libgcc_s_path:$env(LD_LIBRARY64_PATH)"
-    } else {
-	setenv  LD_LIBRARY64_PATH   $libgcc_s_path
-    }
-    if [info exists env(DYLD_LIBRARY_PATH)] {
-	setenv  DYLD_LIBRARY_PATH  "$libgcc_s_path:$env(DYLD_LIBRARY_PATH)"
-    } else {
-	setenv  DYLD_LIBRARY_PATH   $libgcc_s_path
+# This file may be sourced, so don't override environment settings
+# that have been previously setup.
+if { $orig_environment_saved == 0 } {
+    set ld_library_path "${rootme}"
+    set compiler [lindex $GCC_UNDER_TEST 0]
+    if { [is_remote host] == 0 && [which $compiler] != 0 } {
+	foreach i "[exec $compiler --print-multi-lib]" {
+	    set mldir ""
+	    regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
+	    set mldir [string trimright $mldir "\;@"]
+	    if { "$mldir" == "." } {
+		continue
+	    }
+	    if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
+		append ld_library_path ":${rootme}/${mldir}"
+	    }
+	}
     }
+    set_ld_library_path_env_vars
 }
 
 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
Index: gcc/testsuite/lib/gfortran.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/gfortran.exp,v
retrieving revision 1.8
diff -u -3 -p -r1.8 gfortran.exp
--- gcc/testsuite/lib/gfortran.exp	12 Nov 2004 19:43:57 -0000	1.8
+++ gcc/testsuite/lib/gfortran.exp	19 Nov 2004 03:13:16 -0000
@@ -24,6 +24,7 @@
 #
 load_lib prune.exp
 load_lib gcc-defs.exp
+load_lib target-libpath.exp
 
 #
 # GFORTRAN_UNDER_TEST is the compiler under test.
@@ -110,36 +111,7 @@ proc gfortran_link_flags { paths } {
       }
     }
 
-    # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-    # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-    # (for the 64-bit ABI).  The right way to do this would be to modify
-    # unix.exp -- but that's not an option since it's part of DejaGNU
-    # proper, so we do it here.
-    # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
-    # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
-    # (SHLIB_PATH).
-    # Doing this does cause trouble when testing cross-compilers.
-    if {![is_remote target]} {
-        global env;
-	if [info exists env(LD_LIBRARY_PATH)] {
-	    # If we've already added these directories once, keep the
-	    # existing path.
-	    if {$ld_library_path == $env(LD_LIBRARY_PATH)
-		|| [string first $ld_library_path: \
-				 $env(LD_LIBRARY_PATH)] == 0} {
-		set ld_library_path $env(LD_LIBRARY_PATH)
-	    } elseif { $env(LD_LIBRARY_PATH) != "" } {
-		append ld_library_path ":$env(LD_LIBRARY_PATH)"
-	    }
-	}
-        setenv  LD_LIBRARY_PATH     $ld_library_path
-        setenv  SHLIB_PATH          $ld_library_path
-        setenv  LD_LIBRARYN32_PATH  $ld_library_path
-        setenv  LD_LIBRARY64_PATH   $ld_library_path
-        setenv  LD_LIBRARY_PATH_32  $ld_library_path
-        setenv  LD_LIBRARY_PATH_64  $ld_library_path
-        setenv  DYLD_LIBRARY_PATH   $ld_library_path
-    }
+    set_ld_library_path_env_vars
 
     return "$flags"
 }
Index: gcc/testsuite/lib/objc.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/objc.exp,v
retrieving revision 1.28
diff -u -3 -p -r1.28 objc.exp
--- gcc/testsuite/lib/objc.exp	12 Nov 2004 19:43:57 -0000	1.28
+++ gcc/testsuite/lib/objc.exp	19 Nov 2004 03:13:16 -0000
@@ -28,6 +28,7 @@
 load_lib libgloss.exp
 load_lib prune.exp
 load_lib gcc-defs.exp
+load_lib target-libpath.exp
 
 #
 # OBJC_UNDER_TEST is the compiler under test.
@@ -187,21 +188,7 @@ proc objc_target_compile { source dest t
     }
     lappend options "compiler=$OBJC_UNDER_TEST"
 
-    # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-    # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-    # (for the 64-bit ABI).  The right way to do this would be to modify
-    # unix.exp -- but that's not an option since it's part of DejaGNU
-    # proper, so we do it here.
-    # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
-    # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
-    # (SHLIB_PATH).
-    setenv  LD_LIBRARY_PATH     $ld_library_path
-    setenv  SHLIB_PATH          $ld_library_path
-    setenv  LD_LIBRARYN32_PATH  $ld_library_path
-    setenv  LD_LIBRARY64_PATH   $ld_library_path
-    setenv  LD_LIBRARY_PATH_32  $ld_library_path
-    setenv  LD_LIBRARY_PATH_64  $ld_library_path
-    setenv  DYLD_LIBRARY_PATH   $ld_library_path
+    set_ld_library_path_env_vars
 
     return [target_compile $source $dest $type $options]
 }
Index: gcc/testsuite/lib/treelang.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/treelang.exp,v
retrieving revision 1.6
diff -u -3 -p -r1.6 treelang.exp
--- gcc/testsuite/lib/treelang.exp	12 Nov 2004 19:43:57 -0000	1.6
+++ gcc/testsuite/lib/treelang.exp	19 Nov 2004 03:13:16 -0000
@@ -33,6 +33,7 @@
 load_lib libgloss.exp
 load_lib prune.exp
 load_lib gcc-defs.exp
+load_lib target-libpath.exp
 
 #
 # TREELANG_UNDER_TEST is the compiler under test.
@@ -141,6 +142,7 @@ proc treelang_target_compile { source de
     global treelang_libgcc_s_path
 
     set ld_library_path ".:${treelang_libgcc_s_path}"
+    set_ld_library_path_env_vars
     lappend options "libs=-ltreelang"
 
     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
Index: libffi/testsuite/lib/libffi-dg.exp
===================================================================
RCS file: /cvs/gcc/gcc/libffi/testsuite/lib/libffi-dg.exp,v
retrieving revision 1.10
diff -u -3 -p -r1.10 libffi-dg.exp
--- libffi/testsuite/lib/libffi-dg.exp	27 Oct 2004 10:56:06 -0000	1.10
+++ libffi/testsuite/lib/libffi-dg.exp	19 Nov 2004 03:13:16 -0000
@@ -21,6 +21,7 @@ proc load_gcc_lib { filename } {
 
 load_lib dg.exp
 load_lib libgloss.exp
+load_gcc_lib target-libpath.exp
 load_gcc_lib wrapper.exp
 
 
@@ -83,6 +84,7 @@ proc libffi-init { args } {
     global libffi_include
     global libffi_link_flags
     global tool_root_dir
+    global ld_library_path
 
     set blddirffi [lookfor_file [get_multilibs] libffi]
     verbose "libffi $blddirffi"
@@ -131,29 +133,7 @@ proc libffi-init { args } {
 	lappend libffi_link_flags "-L${blddircxx}/src/.libs"
     }
 
-    # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-    # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-    # (for the 64-bit ABI).  The right way to do this would be to modify
-    # unix.exp -- but that's not an option since it's part of DejaGNU
-    # proper, so we do it here.
-    # The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
-    # (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
-    # (SHLIB_PATH).
-    if {![is_remote target]} {
-	set ld_path "LD_LIBRARY_PATH SHLIB_PATH LD_LIBRARYN32_PATH LD_LIBRARY64_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 DYLD_LIBRARY_PATH"
-	foreach path $ld_path {
-	    if [info exists env($path)] {
-		# If we've already added these directories once, keep
-		# the existing path.
-		if {$ld_library_path != $env($path)
-		    && [string first $ld_library_path: $env($path)] != 0} {
-		    setenv $path "$ld_library_path:$env($path)"
-		}
-	    } else {
-		setenv $path "$ld_library_path"
-	    }
-	}
-    }
+    set_ld_library_path_env_vars
     libffi_maybe_build_wrapper "${objdir}/testglue.o"
 }
 
Index: libjava/testsuite/lib/libjava.exp
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/lib/libjava.exp,v
retrieving revision 1.62
diff -u -3 -p -r1.62 libjava.exp
--- libjava/testsuite/lib/libjava.exp	12 Nov 2004 19:43:42 -0000	1.62
+++ libjava/testsuite/lib/libjava.exp	19 Nov 2004 03:13:16 -0000
@@ -1,6 +1,12 @@
 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation
 
-load_lib "libgloss.exp"
+proc load_gcc_lib { filename } {
+    global srcdir
+    load_file $srcdir/../../gcc/testsuite/lib/$filename
+}
+
+load_lib libgloss.exp
+load_gcc_lib target-libpath.exp
 
 # GCJ_UNDER_TEST is the compiler under test.
 
@@ -133,7 +139,6 @@ proc libjava_init { args } {
     global libjava_initialized libjava_uses_threads
     global GCJ_UNDER_TEST
     global TOOL_EXECUTABLE
-    global original_ld_library_path
     global env objdir
     global env libgcj_jar
     global tool_root_dir
@@ -177,24 +182,6 @@ proc libjava_init { args } {
     # Always set encoding used by gcj.
     append GCJ_UNDER_TEST " --encoding=UTF-8"
 
-    if [info exists env(LD_LIBRARY_PATH)] {
-	set original_ld_library_path $env(LD_LIBRARY_PATH)
-	# For HP-UX.
-    } elseif [info exists env(SHLIB_PATH)] {
-	set original_ld_library_path $env(SHLIB_PATH)
-	# For Darwin.
-    } elseif [info exists env(DYLD_LIBRARY_PATH)] {
-	set original_ld_library_path $env(DYLD_LIBRARY_PATH)
-	# For Solaris 32 bit.
-    } elseif [info exists env(LD_LIBRARY_PATH_32)] {
-	set original_ld_library_path $env(LD_LIBRARY_PATH_32)
-	# For Solaris 64 bit.
-    } elseif [info exists env(LD_LIBRARY_PATH_64)] {
-	set original_ld_library_path $env(LD_LIBRARY_PATH_64)
-    } else {
-	set original_ld_library_path ""
-    }
-
     set wrapper_file "";
     set wrap_compile_flags "";
     if [target_info exists needs_status_wrapper] {
@@ -336,6 +323,7 @@ proc libjava_arguments {{mode compile}} 
     global tool_root_dir
     global libgcj_jar
     global libjava_libgcc_s_path
+    global ld_library_path
     global target_triplet
 
     if [info exists LIBJAVA] {
@@ -369,11 +357,10 @@ proc libjava_arguments {{mode compile}} 
     # If we wanted to handle an arbitrary value of libjava,
     # then we'd have to do a lot more work.
 
-    # Set variables the dynamic linker looks at.
-    global original_ld_library_path
-    setenv LD_LIBRARY_PATH "$ld_library_path:$original_ld_library_path"
-
-    verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    set_ld_library_path_env_vars
+    if [info exists env(LD_LIBRARY_PATH)] {
+	verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    }
 
     # Determine CLASSPATH separator
     if { [string match "i?86-pc-mingw32*" $target_triplet] } {
@@ -466,24 +453,24 @@ proc gcj_link {program main files {optio
 # Invoke the program and see what happens.  Return 0 on failure.
 proc gcj_invoke {program expectFile ld_library_additions} {
   global env
-  set lib_path $env(LD_LIBRARY_PATH)
+  global ld_library_path
 
-  set newval .
+  set ld_library_path .
   if {[llength $ld_library_additions] > 0} {
-    append newval :[join $ld_library_additions :]
+    append ld_library_path :[join $ld_library_additions :]
   }
-  append newval :$lib_path
-
-  setenv LD_LIBRARY_PATH $newval
 
-  verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+  set_ld_library_path_env_vars
+  if [info exists env(LD_LIBRARY_PATH)] {
+    verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+  }
 
   set result [libjava_load ./$program]
   set status [lindex $result 0]
   set output [lindex $result 1]
 
   # Restore setting
-  setenv LD_LIBRARY_PATH $lib_path
+  restore_ld_library_path_env_vars
 
   if {$status != "pass"} {
     verbose "got $output"
@@ -511,18 +498,18 @@ proc gcj_invoke {program expectFile ld_l
 proc libjava_invoke {errname testName optName executable inpfile resultfile
 		      ld_library_additions args} {
     global env
-    set lib_path $env(LD_LIBRARY_PATH)
+    global ld_library_path
 
-    set newval .
+    set ld_library_path .
     if {[llength $ld_library_additions] > 0} {
-	append newval :[join $ld_library_additions :]
+	append ld_library_path :[join $ld_library_additions :]
     }
 
-    append newval :$lib_path
-
-    setenv LD_LIBRARY_PATH $newval
+    set_ld_library_path_env_vars
+    if [info exists env(LD_LIBRARY_PATH)] {
+	verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+    }
 
-    verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
     upvar $optName opts
 
     if {[info exists opts(no-exec)]} {
@@ -541,7 +528,7 @@ proc libjava_invoke {errname testName op
     set output [lindex $result 1]
 
     # Restore LD_LIBRARY_PATH setting.
-    setenv LD_LIBRARY_PATH $lib_path
+    restore_ld_library_path_env_vars
 
     if {[info exists opts(xfail-exec)]} then {
 	setup_xfail *-*-*
@@ -934,25 +921,6 @@ proc default_libjava_version {} {
 proc default_libjava_start { } {
 }
 
-# On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-# called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-# (for the 64-bit ABI).  The right way to do this would be to modify
-# unix.exp -- but that's not an option since it's part of DejaGNU
-# proper, so we do it here, by trickery.
-# The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
-# (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
-# (SHLIB_PATH).
-proc ${tool}_set_ld_library_path { name element op } {
-  setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
-  setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
-  setenv SHLIB_PATH [getenv LD_LIBRARY_PATH]
-  setenv DYLD_LIBRARY_PATH [getenv LD_LIBRARY_PATH]
-  setenv LD_LIBRARY_PATH_32 [getenv LD_LIBRARY_PATH]
-  setenv LD_LIBRARY_PATH_64 [getenv LD_LIBRARY_PATH]
-}
-
-trace variable env(LD_LIBRARY_PATH) w ${tool}_set_ld_library_path
-
 # Local Variables:
 # tcl-indent-level:4
 # End:
Index: libjava/testsuite/libjava.jacks/jacks.exp
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.jacks/jacks.exp,v
retrieving revision 1.7
diff -u -3 -p -r1.7 jacks.exp
--- libjava/testsuite/libjava.jacks/jacks.exp	14 Jul 2004 20:45:54 -0000	1.7
+++ libjava/testsuite/libjava.jacks/jacks.exp	19 Nov 2004 03:13:16 -0000
@@ -1,6 +1,13 @@
 # Run the Jacks test suite.
 # See http://www-124.ibm.com/developerworks/oss/cvs/jikes/~checkout~/jacks/jacks.html
 
+proc load_gcc_lib { filename } {
+    global srcdir
+    load_file $srcdir/../../gcc/testsuite/lib/$filename
+}
+
+load_gcc_lib target-libpath.exp
+
 proc gcj_jacks_setup_xfail {ary} {
   upvar $ary array
   global srcdir
@@ -16,7 +23,7 @@ proc gcj_jacks_write {filename} {
   global GCJ_UNDER_TEST
   global libgcj_jar
   global libjava_libgcc_s_path
-  global original_ld_library_path
+  global ld_library_path
 
   set gcjl [split $GCJ_UNDER_TEST]
   set gcj_cmd [lindex $gcjl 0]
@@ -43,7 +50,8 @@ proc gcj_jacks_write {filename} {
   # puts $fd "set tcltest::testConstraints(jvm) 1"
   close $fd
 
-  setenv LD_LIBRARY_PATH $libjava_libgcc_s_path:$original_ld_library_path
+  set ld_library_path $libjava_libgcc_s_path
+  set_ld_library_path_env_vars
 }
 
 proc gcj_jacks_parse {file} {
Index: libmudflap/testsuite/lib/libmudflap.exp
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/testsuite/lib/libmudflap.exp,v
retrieving revision 1.6
diff -u -3 -p -r1.6 libmudflap.exp
--- libmudflap/testsuite/lib/libmudflap.exp	25 Oct 2004 09:01:14 -0000	1.6
+++ libmudflap/testsuite/lib/libmudflap.exp	19 Nov 2004 03:13:16 -0000
@@ -17,22 +17,27 @@
 # Define libmudflap callbacks for dg.exp.
 # This file is a copy of libstdc++-v3's dejagnu driver, with minor changes.
 
+# Useful hook:  if ${hostname}_init exists, it will be called, almost
+# the last thing before testing begins.  This can be defined in, e.g.,
+# ~/.dejagnurc or $DEJAGNU.
+
+proc load_gcc_lib { filename } {
+    global srcdir
+    load_file $srcdir/../../gcc/testsuite/lib/$filename
+}
+
 load_lib mfdg.exp
 load_lib libgloss.exp
-
+load_gcc_lib target-libpath.exp
 
 proc libmudflap-init { language } {
-    global srcdir
-    global outdir
-    global blddir
-    global cxx
+    global env
+    global srcdir outdir blddir objdir tool_root_dir
+    global cxx cxxflags
     global includes
     global libs
-    global cxxflags
-    global objdir
     global gluefile wrap_flags
     global ld_library_path
-    global tool_root_dir
 
     switch $language {
         "c" { set cxx [find_gcc] }
@@ -96,12 +101,10 @@ proc libmudflap-init { language } {
     global add_flags
     append add_flags " $mfconfig_libs"
 
-    verbose -log "ld_library_path=$ld_library_path"
-    setenv  LD_LIBRARY_PATH     $ld_library_path
-    setenv  SHLIB_PATH          $ld_library_path
-    setenv  LD_RUN_PATH         $ld_library_path
-    setenv  LD_LIBRARYN32_PATH  $ld_library_path
-    setenv  LD_LIBRARY64_PATH   $ld_library_path
+    set_ld_library_path_env_vars
+    if [info exists env(LD_LIBRARY_PATH)] {
+	verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    }
 
     if { [target_info needs_status_wrapper]!=""} {
       file delete ${objdir}/testglue.o;
Index: libstdc++-v3/testsuite/lib/libstdc++.exp
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/lib/libstdc++.exp,v
retrieving revision 1.28
diff -u -3 -p -r1.28 libstdc++.exp
--- libstdc++-v3/testsuite/lib/libstdc++.exp	12 Nov 2004 19:43:41 -0000	1.28
+++ libstdc++-v3/testsuite/lib/libstdc++.exp	19 Nov 2004 03:13:17 -0000
@@ -49,6 +49,7 @@ load_lib libgloss.exp
 load_gcc_lib target-supports.exp
 load_lib prune.exp
 load_lib dg-options.exp
+load_gcc_lib target-libpath.exp
 load_gcc_lib wrapper.exp
 
 # Useful for debugging.  Pass the name of a variable and the verbosity
@@ -81,7 +82,7 @@ proc libstdc++_init { testfile } {
     global cxx cxxflags
     global includes
     global gluefile wrap_flags
-    global original_ld_library_path
+    global ld_library_path
     global target_triplet
 
     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
@@ -123,26 +124,6 @@ proc libstdc++_init { testfile } {
     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
 
-    # Setup LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
-    # Find the existing LD_LIBRARY_PATH.
-    if [info exists env(LD_LIBRARY_PATH)] {
-	set original_ld_library_path $env(LD_LIBRARY_PATH)
-	# For HP-UX
-    } elseif [info exists env(SHLIB_PATH)] {
-	set original_ld_library_path $env(SHLIB_PATH)
-	# For Darwin:
-    } elseif [info exists env(DYLD_LIBRARY_PATH)] {
-	set original_ld_library_path $env(DYLD_LIBRARY_PATH)
-	# For Solaris 32 bit:
-    } elseif [info exists env(LD_LIBRARY_PATH_32)] {
-	set original_ld_library_path $env(LD_LIBRARY_PATH_32)
-	# For Solaris 64 bit:
-    } elseif [info exists env(LD_LIBRARY_PATH_64)] {
-	set original_ld_library_path $env(LD_LIBRARY_PATH_64)
-    } else {
-	set original_ld_library_path ""
-    }
-
     # Locate libgcc.a so we don't need to account for different values of
     # SHLIB_EXT on different platforms
     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
@@ -170,23 +151,10 @@ proc libstdc++_init { testfile } {
     }
     append ld_library_path ":${blddir}/src/.libs"
 
-    # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-    # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-    # (for the 64-bit ABI).  The right way to do this would be to modify
-    # unix.exp -- but that's not an option since it's part of DejaGNU
-    # proper, so we do it here.
-    # The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
-    # (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
-    # (SHLIB_PATH).
-    setenv  LD_LIBRARY_PATH     "$ld_library_path:$original_ld_library_path"
-    setenv  SHLIB_PATH          "$ld_library_path:$original_ld_library_path"
-    setenv  LD_LIBRARYN32_PATH  "$ld_library_path:$original_ld_library_path"
-    setenv  LD_LIBRARY64_PATH   "$ld_library_path:$original_ld_library_path"
-    setenv  LD_RUN_PATH         "$ld_library_path:$original_ld_library_path"
-    setenv  LD_LIBRARY_PATH_32  "$ld_library_path:$original_ld_library_path"
-    setenv  LD_LIBRARY_PATH_64  "$ld_library_path:$original_ld_library_path"
-    setenv  DYLD_LIBRARY_PATH   "$ld_library_path:$original_ld_library_path"
-    verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    set_ld_library_path_env_vars
+    if [info exists env(LD_LIBRARY_PATH)] {
+      verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    }
 
     # Do a bunch of handstands and backflips for cross compiling and
     # finding simulators...



More information about the Gcc-patches mailing list