PATCH: Backport installed-compiler support to 3.4 branch

Mark Mitchell mark@codesourcery.com
Mon May 2 23:37:00 GMT 2005


This patch backports the machinery necessary for testing an installed
compiler to the 3.4 branch.  (Just the compiler bits; no libstdc++
bits in this patch.)  I'll be posting a similar patch for the 4.0
branch shortly.  The purpose of these patches is to make it easier to
test compilers and toolchains built from these branches.  Tested by
running the testsuite using an installed compiler and an uninstalled
compiler on x86_64-unknown-linux-gnu, applied on the 3.4 branch.

V3 people: it's my intention to backport a minimal set of
patches necessary for testing an install libstdc++.  That will be a
subset of all the work done on the mainline; principally the DejaGNU
bits, but not all of the Makefile bits, as I don't want to break any
existing testing procedures that people are using for the branches.
Before I check anything in, I'll post and solicit comments for 24
hours, but if you have objections to this plan in principle please let
me know.

Thanks,

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-05-02  Mark Mitchell  <mark@codesourcery.com>

	Backport:
	2005-03-25  Mark Mitchell  <mark@codesourcery.com>
	* lib/g++.exp (g++_link_flags): Use gcc-set-multilib-library-path.
	(g++_init): Make sure that CXXFLAGS is set.
	* lib/gcc-defs.exp (gcc-set-multilib-library-path): New function.
	* lib/objc.exp (objc_init): Likewise.
	2004-11-27  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
	* lib/target-libpath.exp (restore_ld_library_path_env_vars):
	Check existence of ld library path variables before unsetting.
	2004-11-24  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
	* lib/target-libpath.exp (orig_ld_library_path_saved): Add missing set.
	2004-11-23  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/objc.exp: Use new procs.

Index: g++.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/g++.exp,v
retrieving revision 1.35.4.2
diff -c -5 -p -r1.35.4.2 g++.exp
*** g++.exp	24 Jan 2005 05:05:04 -0000	1.35.4.2
--- g++.exp	2 May 2005 23:27:52 -0000
***************
*** 22,31 ****
--- 22,32 ----
  #
  # g++ support library routines
  #
  load_lib prune.exp
  load_lib gcc-defs.exp
+ load_lib target-libpath.exp
  
  #
  # GXX_UNDER_TEST is the compiler under test.
  #
  
*************** proc g++_include_flags { paths } {
*** 94,104 ****
  # g++_link_flags -- provide new version of g++_link_flags
  # (originally from libgloss.exp) which knows about the gcc tree structure
  #
  
  proc g++_link_flags { paths } {
-     global rootme
      global srcdir
      global ld_library_path
      global GXX_UNDER_TEST
  
      set gccpath ${paths}
--- 95,104 ----
*************** proc g++_link_flags { paths } {
*** 126,150 ****
            append flags "-L${gccpath}/libiberty "
        }
        if [file exists "${gccpath}/librx/librx.a"] {
            append flags "-L${gccpath}/librx "
        }
!       append ld_library_path ":${rootme}"
!       set compiler [lindex $GXX_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}"
! 	  }
! 	}
!       }
      } else {
        global tool_root_dir;
  
        set libgpp [lookfor_file ${tool_root_dir} libg++];
        if { $libgpp != "" } {
--- 126,136 ----
            append flags "-L${gccpath}/libiberty "
        }
        if [file exists "${gccpath}/librx/librx.a"] {
            append flags "-L${gccpath}/librx "
        }
!       append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
      } else {
        global tool_root_dir;
  
        set libgpp [lookfor_file ${tool_root_dir} libg++];
        if { $libgpp != "" } {
*************** proc g++_link_flags { paths } {
*** 164,187 ****
        if { $librx != "" } {
            append flags "-L${librx} ";
        }
      }
  
!     # 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]} {
! 	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  DYLD_LIBRARY_PATH   $ld_library_path
!     }
  
      return "$flags"
  }
  
  #
--- 150,160 ----
        if { $librx != "" } {
            append flags "-L${librx} ";
        }
      }
  
!     set_ld_library_path_env_vars
  
      return "$flags"
  }
  
  #
*************** proc g++_init { args } {
*** 195,204 ****
--- 168,178 ----
      global tmpdir
      global libdir
      global gluefile wrap_flags;
      global objdir srcdir
      global ALWAYS_CXXFLAGS
+     global CXXFLAGS
      global TOOL_EXECUTABLE TOOL_OPTIONS
      global GXX_UNDER_TEST
      global TESTING_IN_BUILD_TREE
      global target_triplet
  
*************** proc g++_init { args } {
*** 242,251 ****
--- 216,229 ----
  	} else {
  	    unset gluefile
  	}
      }
  
+     if {![info exists CXXFLAGS]} {
+ 	set CXXFLAGS ""
+     }
+ 
      set ALWAYS_CXXFLAGS ""
  
      if ![is_remote host] {
  	if [info exists TOOL_OPTIONS] {
  	    lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
Index: gcc-defs.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/gcc-defs.exp,v
retrieving revision 1.2
diff -c -5 -p -r1.2 gcc-defs.exp
*** gcc-defs.exp	5 Jun 2003 22:18:54 -0000	1.2
--- gcc-defs.exp	2 May 2005 23:27:52 -0000
*************** proc dg-additional-files-options { optio
*** 215,219 ****
--- 215,251 ----
  	}
      }
  
      return $options
  }
+ 
+ # Return a colon-separate list of directories to search for libraries
+ # for COMPILER, including multilib directories.
+ 
+ proc gcc-set-multilib-library-path { compiler } {
+     global rootme
+ 
+     # ??? rootme will not be set when testing an installed compiler.
+     # In that case, we should perhaps use some other method to find
+     # libraries.
+     if {![info exists rootme]} {
+ 	return ""
+     }
+ 
+     set libpath ":${rootme}"
+     set compiler [lindex $compiler 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 libpath ":${rootme}/${mldir}"
+ 	    }
+ 	}
+     }
+ 
+     return $libpath
+ }
Index: objc.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/objc.exp,v
retrieving revision 1.20.4.2
diff -c -5 -p -r1.20.4.2 objc.exp
*** objc.exp	24 Jan 2005 05:05:04 -0000	1.20.4.2
--- objc.exp	2 May 2005 23:27:52 -0000
***************
*** 26,35 ****
--- 26,36 ----
  # where to find stdio.h, libc.a, etc.
  
  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.
  #
  
*************** proc objc_version { } {
*** 83,93 ****
  #
  
  set objc_initialized 0
  
  proc objc_init { args } {
-     global rootme
      global tmpdir
      global libdir
      global gluefile wrap_flags
      global objc_initialized
      global OBJC_UNDER_TEST
--- 84,93 ----
*************** proc objc_init { args } {
*** 116,144 ****
  	} else {
  	    unset gluefile
  	}
      }
  
!     set objc_libgcc_s_path "${rootme}"
!     set compiler [lindex $OBJC_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 objc_libgcc_s_path ":${rootme}/${mldir}"
! 	    }
! 	}
!     }
  }
  
  proc objc_target_compile { source dest type options } {
-     global rootme;
      global tmpdir;
      global gluefile wrap_flags;
      global srcdir
      global OBJC_UNDER_TEST
      global TOOL_OPTIONS
--- 116,129 ----
  	} else {
  	    unset gluefile
  	}
      }
  
!     append objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST]
  }
  
  proc objc_target_compile { source dest type options } {
      global tmpdir;
      global gluefile wrap_flags;
      global srcdir
      global OBJC_UNDER_TEST
      global TOOL_OPTIONS
*************** proc objc_target_compile { source dest t
*** 182,202 ****
  	lappend options "additional_flags=${objc_link_flags}"
  	append ld_library_path ":${libobjc_dir}"
      }
      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.  We really only need to do 
!     # this on IRIX, but it shouldn't hurt to do it anywhere else.
!     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  DYLD_LIBRARY_PATH   $ld_library_path 
  
      return [target_compile $source $dest $type $options]
  }
  
  #
--- 167,177 ----
  	lappend options "additional_flags=${objc_link_flags}"
  	append ld_library_path ":${libobjc_dir}"
      }
      lappend options "compiler=$OBJC_UNDER_TEST"
  
!     set_ld_library_path_env_vars
  
      return [target_compile $source $dest $type $options]
  }
  
  #
Index: target-libpath.exp
===================================================================
RCS file: target-libpath.exp
diff -N target-libpath.exp
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- target-libpath.exp	2 May 2005 23:27:52 -0000
***************
*** 0 ****
--- 1,237 ----
+ # 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_library_path_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"
+   } elseif [info exists env(LD_LIBRARY_PATH)] {
+     unsetenv LD_LIBRARY_PATH
+   }
+   if { $orig_ld_run_path_saved } {
+     setenv LD_RUN_PATH "$orig_ld_run_path"
+   } elseif [info exists env(LD_RUN_PATH)] {
+     unsetenv LD_RUN_PATH
+   }
+   if { $orig_shlib_path_saved } {
+     setenv SHLIB_PATH "$orig_shlib_path"
+   } elseif [info exists env(SHLIB_PATH)] {
+     unsetenv SHLIB_PATH
+   }
+   if { $orig_ld_libraryn32_path_saved } {
+     setenv LD_LIBRARYN32_PATH "$orig_ld_libraryn32_path"
+   } elseif [info exists env(LD_LIBRARYN32_PATH)] {
+     unsetenv LD_LIBRARYN32_PATH
+   }
+   if { $orig_ld_library64_path_saved } {
+     setenv LD_LIBRARY64_PATH "$orig_ld_library64_path"
+   } elseif [info exists env(LD_LIBRARY64_PATH)] {
+     unsetenv LD_LIBRARY64_PATH
+   }
+   if { $orig_ld_library_path_32_saved } {
+     setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
+   } elseif [info exists env(LD_LIBRARY_PATH_32)] {
+     unsetenv LD_LIBRARY_PATH_32
+   }
+   if { $orig_ld_library_path_64_saved } {
+     setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
+   } elseif [info exists env(LD_LIBRARY_PATH_64)] {
+     unsetenv LD_LIBRARY_PATH_64
+   }
+   if { $orig_dyld_library_path_saved } {
+     setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
+   } elseif [info exists env(DYLD_LIBRARY_PATH)] {
+     unsetenv DYLD_LIBRARY_PATH
+   }
+ }



More information about the Libstdc++ mailing list