[committed] Fix ever-growing LD_LIBRARY_PATH

Richard Sandiford rsandifo@redhat.com
Fri Jul 30 18:49:00 GMT 2004


This is a revision of the patch I posted here:

    http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01877.html

Mark conditionally approved it:

    http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01884.html

saying:

    I think you should split the existing value by colons; otherwise,
    you could think you have a match when the desired LD_LIBRARY_PATH is
    a substring of something in the existing value. OK with that change,
    and appropriate testing.

but I decided to defer to a more far-reaching clean-up by Dave Anglin.
Since Dave's final patch hasn't been submitted yet, and since I keep
tripping over this, I thought I'd go back to what I posted above.

As Mark says, my original patch could trigger false positives, since it
simply checked whether the new $ld_library_path was a substring of the
current LD_LIBRARY_PATH.  I don't think we need to split the path into
colons though: we can make the test more robust by simply checking
whether LD_LIBRARY_PATH == "$ld_library_path" or starts with
"$ld_library_path:".  If it doesn't, then we should add the new path to
the beginning, even if (for whatever reason) it already occurs elsewhere
in LD_LIBRARY_PATH.

Tested on i686-pc-linux-gnu and mips-sgi-irix6.5.  The change from the
approved version seemed pretty obvious, so I went ahead and applied it
to mainline.

Richard


	* lib/g++.exp (g++_link_flags): Check whether LD_LIBRARY_PATH already
	contains $ld_library_path.
	* lib/gfortran.exp (gfortran_link_flags): Likewise.

Index: testsuite/lib/g++.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/g++.exp,v
retrieving revision 1.39
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.39 g++.exp
*** testsuite/lib/g++.exp	18 Jun 2004 23:48:43 -0000	1.39
--- testsuite/lib/g++.exp	30 Jul 2004 10:27:59 -0000
*************** proc g++_link_flags { paths } {
*** 177,185 ****
      # Doing this does cause trouble when testing cross-compilers.
      if {![is_remote target]} {
  	global env;
! 	if { [info exists env(LD_LIBRARY_PATH)] 
! 	     && $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
--- 177,192 ----
      # 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
Index: testsuite/lib/gfortran.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/gfortran.exp,v
retrieving revision 1.4
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.4 gfortran.exp
*** testsuite/lib/gfortran.exp	18 Jun 2004 23:48:44 -0000	1.4
--- testsuite/lib/gfortran.exp	30 Jul 2004 10:27:59 -0000
*************** proc gfortran_link_flags { paths } {
*** 121,130 ****
      # Doing this does cause trouble when testing cross-compilers.
      if {![is_remote target]} {
          global env;
!         if { [info exists env(LD_LIBRARY_PATH)]
!              && $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
--- 121,137 ----
      # 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



More information about the Gcc-patches mailing list