This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] build shared objects in C++ compatibility testsuite
- From: Janis Johnson <janis187 at us dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 22 Oct 2002 13:56:35 -0700
- Subject: [PATCH] build shared objects in C++ compatibility testsuite
This patch extends the C++ binary compatibility tests to build pieces
of the tests into shared objects on targets that support shared objects.
This extension of the tests also provides a place for test cases that
demonstrate fixes that only affect shared objects.
The command line used for linking currently specifies the name of the
shared object, rather than "-L. -lname"; are there reasons for changing
this? The current method makes it easy to check to see if the library
was built successfully.
I haven't found a way to pass environment variables through to expect
other than adding them to site.exp. If someone knows a way to do that,
please let me know.
I picked up the information about target-specific options for building
shared libraries from boehm-gc/ltconfig; the new procedures in
target-support.exp probably need more tweaking, particularly if there
are targets that don't support shared objects.
Tested on i686-pc-linux-gnu, ia64-unknown-linux-gnu and powerpc-easisim.
OK for the mainline?
2002-10-22 Janis Johnson <janis187@us.ibm.com>
* Makefile.in (site.exp): Add ALT_LD_LIBRARY_PATH, ALT_SHOBJ_OPTIONS.
2002-10-22 Janis Johnson <janis187@us.ibm.com>
* README.compat: Tell how to run only compat tests, and remove
to-do item for shared libraries.
* lib/compat.exp (compat-shobj): New procedure.
(compat-execute): Build tests with shared libraries as well as
relocatable object files.
* lib/target-supports.exp (check_shobj_available): New procedure.
(shobj_compile_options): New procedure.
* g++.dg/compat/compat.exp: Add support for shared libraries.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.953
diff -u -r1.953 Makefile.in
--- Makefile.in 19 Oct 2002 10:12:33 -0000 1.953
+++ Makefile.in 22 Oct 2002 20:22:46 -0000
@@ -3111,12 +3111,24 @@
fi
echo "set tmpdir $(objdir)/testsuite" >> ./tmp0
@echo "set srcdir \"\$${srcdir}/testsuite\"" >> ./tmp0
+# The following are used for binary compatibility tests to specify an
+# alternate compiler, the location of its shared libraries, how to build
+# a shared object with it, and sets of compilation options to use for the
+# compiler under test and the alternate compiler.
@if [ "X$(ALT_CXX_UNDER_TEST)" != "X" ] ; then \
- echo "set ALT_CXX_UNDER_TEST $(ALT_CXX_UNDER_TEST)" >> ./tmp0; \
+ echo "set ALT_CXX_UNDER_TEST \"$(ALT_CXX_UNDER_TEST)\"" >> ./tmp0; \
+ else true; \
+ fi
+ @if [ "X$(ALT_LD_LIBRARY_PATH)" != "X" ] ; then \
+ echo "set ALT_LD_LIBRARY_PATH \"$(ALT_LD_LIBRARY_PATH)\"" >> ./tmp0; \
+ else true; \
+ fi
+ @if [ "X$(ALT_SHOBJ_OPTIONS)" != "X" ] ; then \
+ echo "set ALT_SHOBJ_OPTIONS \"$(ALT_SHOBJ_OPTIONS)\"" >> ./tmp0; \
else true; \
fi
@if [ "X$(COMPAT_OPTIONS)" != "X" ] ; then \
- echo "set COMPAT_OPTIONS $(COMPAT_OPTIONS)" >> ./tmp0; \
+ echo "set COMPAT_OPTIONS \"$(COMPAT_OPTIONS)\"" >> ./tmp0; \
else true; \
fi
@echo "## All variables above are generated by configure. Do Not Edit ##" >> ./tmp0
Index: README.compat
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/README.compat,v
retrieving revision 1.1
diff -u -r1.1 README.compat
--- README.compat 18 Oct 2002 00:22:55 -0000 1.1
+++ README.compat 22 Oct 2002 20:22:59 -0000
@@ -24,7 +24,19 @@
with the compiler under test using the first of each pair of compiler
options from COMPAT_OPTIONS. When ALT_CXX_UNDER_TEST is "same", each
test is built using the compiler under test but with combinations of
- the options from COMPAT_OPTIONS.
+ the options from COMPAT_OPTIONS. If the alternate compiler needs a
+ different setting for LD_LIBRARY_PATH, specify it in the environment
+ varible ALT_LD_LIBRARY_PATH. If it needs different options to build
+ a shared object, define those in ALT_SHOBJ_OPTIONS.
+
+To run only the C++ compatibility tests, optionally specifying an
+alternate compiler and/or sets of options, do from $objdir/gcc:
+
+ rm site.exp
+ make -k ALT_CXX_UNDER_TEST=<prefix>/bin/g++ \
+ ALT_LD_LIBRARY_PATH=<prefix>/lib \
+ COMPAT_OPTIONS="list as shown above" check-c++ \
+ RUNTESTFLAGS="compat.exp"
A test that fails when the pieces are compiled with different compilers
but passes when the pieces are compiled with the same compiler
@@ -52,10 +64,6 @@
- link using the alternate compiler; this requires support for
LD_LIBRARY_PATH for the alternate compiler in the support for each
language
-
- - build pieces of the test into shared libraries; this requires
- support for LD_LIBRARY_PATH for the alternate compiler, and
- knowledge about how to build a shared library for each target
- build pieces of the test into static libraries; this requires
knowledge about how to build a static library for each target
Index: lib/compat.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/compat.exp,v
retrieving revision 1.2
diff -u -r1.2 compat.exp
--- lib/compat.exp 19 Oct 2002 19:27:24 -0000 1.2
+++ lib/compat.exp 22 Oct 2002 20:23:10 -0000
@@ -34,6 +34,9 @@
if [string match "" [info procs "compat-use-tst-compiler"]] then {
error "Proc compat-use-tst-compiler is not defined."
}
+if [string match "" [info procs "compat-combine-lib-paths"]] then {
+ error "Proc compat-combine-lib-paths is not defined."
+}
# Each test is run with each pair of compiler options from this list.
# The first set of options in each pair is used by the compiler under
@@ -65,6 +68,26 @@
${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
}
+#
+# compat-shobj -- compile to a shared object file
+#
+# SOURCE is the source file
+# DEST is the shared object file
+# OPTIONS is the list of compiler options
+# OPTSTR is the options to print with test messages
+#
+proc compat-shobj { source dest options optstr } {
+ global testcase
+ global tool
+ global shobj_options
+
+ set shopt $options
+ lappend shopt "additional_flags=$shobj_options"
+
+ set comp_output [${tool}_target_compile "$source" "$dest" object $shopt]
+ ${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
+}
+
# compat-run -- link and run an executable
#
# TESTNAME is the mixture of object files to link
@@ -114,7 +137,7 @@
# USE_ALT is nonzero if we're using an alternate compiler as well as
# the compiler under test.
#
-proc compat-execute { src1 use_alt } {
+proc compat-execute { src1 use_alt use_shobj } {
global srcdir tmpdir
global option_list
global tool
@@ -142,13 +165,19 @@
regsub "_main" $src1 "_x" src2
regsub "_main" $src1 "_y" src3
- # Define the names of the object files.
+ # Define the names of the relocatable object files.
set obj1 "main_tst.o"
set obj2_tst "x_tst.o"
set obj2_alt "x_alt.o"
set obj3_tst "y_tst.o"
set obj3_alt "y_alt.o"
+ # Define the names of the shared object files.
+ set shobj2_tst "libx_tst.so"
+ set shobj2_alt "libx_alt.so"
+ set shobj3_tst "liby_tst.so"
+ set shobj3_alt "liby_alt.so"
+
# Get the base name of this test, for use in messages.
regsub "^$srcdir/?" $src1 "" testcase
regsub "_main.*" $testcase "" testcase
@@ -187,16 +216,29 @@
# There's a unique name for each executable we generate, based on
# the set of options and how the pieces of the tests are compiled.
- set execname1 "${execbase}-${count}1"
- set execname2 "${execbase}-${count}2"
- set execname3 "${execbase}-${count}3"
- set execname4 "${execbase}-${count}4"
+ set execname1 "${execbase}-${count}01"
+ set execname2 "${execbase}-${count}02"
+ set execname3 "${execbase}-${count}03"
+ set execname4 "${execbase}-${count}04"
+ set execname5 "${execbase}-${count}05"
+ set execname6 "${execbase}-${count}06"
+ set execname7 "${execbase}-${count}07"
+ set execname8 "${execbase}-${count}08"
+ set execname9 "${execbase}-${count}09"
+ set execname10 "${execbase}-${count}10"
+ set execname11 "${execbase}-${count}11"
+ set execname12 "${execbase}-${count}12"
+ set execname13 "${execbase}-${count}13"
+ set execname14 "${execbase}-${count}14"
+ set execname15 "${execbase}-${count}15"
+ set execname16 "${execbase}-${count}16"
incr count
- remote_file build delete $execname1
- remote_file build delete $execname2
- remote_file build delete $execname3
- remote_file build delete $execname4
+ # Clean up executable files left from previous test runs.
+ set files [glob -nocomplain ${execbase}*]
+ if { $files != "" } {
+ eval "remote_file build delete $files"
+ }
# Compile pieces with the alternate compiler; we'll catch problems
# later. Skip this if we don't have an alternate compiler.
@@ -204,6 +246,10 @@
compat-use-alt-compiler
compat-obj "$src2" "$obj2_alt" $alt_options $optstr
compat-obj "$src3" "$obj3_alt" $alt_options $optstr
+ if { $use_shobj != 0 } then {
+ compat-shobj "$src2" "$shobj2_alt" $alt_options $optstr
+ compat-shobj "$src3" "$shobj3_alt" $alt_options $optstr
+ }
}
# Compile pieces with the compiler under test.
@@ -211,23 +257,76 @@
compat-obj "$src1" "$obj1" $tst_options $optstr
compat-obj "$src2" "$obj2_tst" $tst_options $optstr
compat-obj "$src3" "$obj3_tst" $tst_options $optstr
+ if { $use_shobj != 0 } then {
+ compat-shobj "$src2" "$shobj2_tst" $tst_options $optstr
+ compat-shobj "$src3" "$shobj3_tst" $tst_options $optstr
+ }
# Link (using the compiler under test), run, and clean up tests.
+ compat-combine-lib-paths
compat-run "${obj2_tst}-${obj3_tst}" \
"$obj1 $obj2_tst $obj3_tst" $execname1 $tst_options $optstr
- # If we've got an alternate compiler try some combinations.
+ # if we're testing with shared objects, run some more tests that
+ # involve only the compiler under test.
+ if { $use_shobj != 0 } then {
+ compat-run "${obj2_tst}-${shobj3_tst}" \
+ "$obj1 $obj2_tst $shobj3_tst" $execname2 $tst_options $optstr
+ compat-run "${shobj2_tst}-${obj3_tst}" \
+ "$obj1 $shobj2_tst $obj3_tst" $execname3 $tst_options $optstr
+ compat-run "${shobj2_tst}-${shobj3_tst}" \
+ "$obj1 $shobj2_tst $shobj3_tst" $execname4 $tst_options $optstr
+ }
+
+ # If we've got an alternate compiler, try some combinations.
if { $use_alt != 0 } then {
compat-run "${obj2_tst}-${obj3_alt}" "$obj1 $obj2_tst $obj3_alt" \
- $execname2 $tst_options $optstr
+ $execname5 $tst_options $optstr
compat-run "${obj2_alt}-${obj3_tst}" "$obj1 $obj2_alt $obj3_tst" \
- $execname3 $tst_options $optstr
+ $execname6 $tst_options $optstr
compat-run "${obj2_alt}-${obj3_alt}" "$obj1 $obj2_alt $obj3_alt" \
- $execname4 $tst_options $optstr
+ $execname7 $tst_options $optstr
+
+ # If we're also testing with shared objects, link and run lots
+ # more tests.
+
+ if { $use_shobj != 0 } then {
+ compat-run "${obj2_tst}-${shobj3_alt}" \
+ "$obj1 $obj2_tst $shobj3_alt" \
+ $execname8 $tst_options $optstr
+ compat-run "${obj2_alt}-${shobj3_tst}" \
+ "$obj1 $obj2_alt $shobj3_tst" \
+ $execname9 $tst_options $optstr
+ compat-run "${obj2_alt}-${shobj3_alt}" \
+ "$obj1 $obj2_alt $shobj3_alt" \
+ $execname10 $tst_options $optstr
+ compat-run "${shobj2_tst}-${obj3_alt}" \
+ "$obj1 $shobj2_tst $obj3_alt" \
+ $execname11 $tst_options $optstr
+ compat-run "${shobj2_tst}-${shobj3_alt}" \
+ "$obj1 $shobj2_tst $shobj3_alt" \
+ $execname12 $tst_options $optstr
+ compat-run "${shobj2_alt}-${obj3_tst}" \
+ "$obj1 $shobj2_tst $obj3_tst" \
+ $execname13 $tst_options $optstr
+ compat-run "${shobj2_alt}-${obj3_alt}" \
+ "$obj1 $shobj2_alt $obj3_alt" \
+ $execname14 $tst_options $optstr
+ compat-run "${shobj2_alt}-${shobj3_tst}" \
+ "$obj1 $shobj2_alt $shobj3_tst" \
+ $execname15 $tst_options $optstr
+ compat-run "${shobj2_alt}-${shobj3_alt}" \
+ "$obj1 $shobj2_tst $shobj3_alt" \
+ $execname16 $tst_options $optstr
+ }
}
# Clean up object files.
set files [glob -nocomplain *.o]
+ if { $files != "" } {
+ eval "remote_file build delete $files"
+ }
+ set files [glob -nocomplain *.so]
if { $files != "" } {
eval "remote_file build delete $files"
}
Index: lib/target-supports.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/target-supports.exp,v
retrieving revision 1.4
diff -u -r1.4 target-supports.exp
--- lib/target-supports.exp 27 Sep 2002 02:14:12 -0000 1.4
+++ lib/target-supports.exp 22 Oct 2002 20:23:27 -0000
@@ -112,3 +112,42 @@
return $alias_available_saved
}
+
+###############################
+# proc check_shobj_available { }
+###############################
+
+# Determine whether the target supports shared objects.
+# Return 1 if they are supported, 0 if they are not.
+
+proc check_shobj_available { } {
+ global target_os
+
+ # Anything that isn't specifically listed as not supporting
+ # shared libraries is assumed to support them.
+ return 1
+}
+
+###############################
+# proc shobj_compile_options { }
+###############################
+
+# Return a string of compiler options for building a shared library.
+
+proc shobj_compile_options { } {
+ global target_triplet
+
+ switch -regexp $target_triplet {
+ ".*-beos" { return "-shared" }
+ ".*-irix" { return "-shared" }
+ ".*-osf" { return "-shared" }
+ ".*-aix.*" { return "-shared" }
+ ".*-cygwin.*" { return "-shared" }
+ ".*-mingw.*" { return "-shared" }
+ ".*-os2.*" { return "-shared" }
+ ".*-sysv4.*MP.*" { return "-Kconform_pic -shared" }
+ }
+
+ # Anything else should handle this, although many don't need -fPIC.
+ return "-fPIC -shared"
+}
Index: g++.dg/compat/compat.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/compat/compat.exp,v
retrieving revision 1.1
diff -u -r1.1 compat.exp
--- g++.dg/compat/compat.exp 18 Oct 2002 00:22:57 -0000 1.1
+++ g++.dg/compat/compat.exp 22 Oct 2002 20:23:40 -0000
@@ -31,10 +31,12 @@
global GXX_UNDER_TEST
global ld_library_path
+global shobj_options
# Load procedures from common libraries.
load_lib standard.exp
load_lib g++.exp
+load_lib target-supports.exp
#
# compat-fix-library-path -- switch LD_LIBRARY_PATH
@@ -57,6 +59,7 @@
global CXXFLAGS
global ALWAYS_CXXFLAGS
global ld_library_path alt_ld_library_path
+ global shobj_options alt_shobj_options
global same_alt
# We don't need to do this if the alternate compiler is actually
@@ -66,6 +69,7 @@
set CXXFLAGS ""
set ALWAYS_CXXFLAGS ""
set ld_library_path $alt_ld_library_path
+ set shobj_options $alt_shobj_options
compat-fix-library-path
}
}
@@ -78,6 +82,7 @@
global CXXFLAGS save_cxxflags
global ALWAYS_CXXFLAGS save_always_cxxflags
global ld_library_path save_ld_library_path
+ global shobj_options save_shobj_options
global same_alt
# We don't need to do this if the alternate compiler is actually
@@ -88,22 +93,35 @@
set CXXFLAGS $save_cxxflags
set ALWAYS_CXXFLAGS $save_always_cxxflags
set ld_library_path $save_ld_library_path
+ set shobj_options $save_shobj_options
compat-fix-library-path
}
}
+#
+# compat-combine-lib-paths -- specify both sets of libraries
+#
+proc compat-combine-lib-paths { } {
+ global ld_library_path save_ld_library_path alt_ld_library_path
+
+ set ld_library_path $save_ld_library_path
+ append ld_library_path ":${alt_ld_library_path}"
+ compat-fix-library-path
+}
+
# Load the language-independent compabibility support procedures.
# This must be done after the compat-use-*-compiler definitions.
load_lib compat.exp
g++_init
-# Save variables for the C++ compiler under test, which each test will
-# change a couple of times. This must be done after calling g++-init.
-set save_gxx_under_test $GXX_UNDER_TEST
-set save_cxxflags $CXXFLAGS
-set save_always_cxxflags $ALWAYS_CXXFLAGS
-set save_ld_library_path $ld_library_path
+# Find out whether shared objects are supported on this target and if so,
+# what additional options are needed to build them.
+set shobj_options ""
+set use_shobj [ check_shobj_available ]
+if { $use_shobj == 1 } then {
+ set shobj_options [ shobj_compile_options ]
+}
# Find out whether there is an alternate compiler to test. If the
# variable is defined but is set to "same", that means we use the same
@@ -112,6 +130,7 @@
set use_alt 0
set same_alt 0
set alt_ld_library_path "."
+set alt_shobj_options $shobj_options
if [info exists ALT_CXX_UNDER_TEST] then {
set use_alt 1
if [string match "same" $ALT_CXX_UNDER_TEST] then {
@@ -120,9 +139,20 @@
if [info exists ALT_LD_LIBRARY_PATH] then {
append alt_ld_library_path ":${ALT_LD_LIBRARY_PATH}"
}
+ if [info exists ALT_SHOBJ_OPTIONS] then {
+ set alt_shobj_options ${ALT_SHOBJ_OPTIONS}
+ }
}
}
+# Save variables for the C++ compiler under test, which each test will
+# change a couple of times. This must be done after calling g++-init.
+set save_gxx_under_test $GXX_UNDER_TEST
+set save_cxxflags $CXXFLAGS
+set save_always_cxxflags $ALWAYS_CXXFLAGS
+set save_ld_library_path $ld_library_path
+set save_shobj_options $shobj_options
+
# Main loop.
foreach src [lsort [find $srcdir/$subdir *_main.C]] {
# If we're only testing specific files and this isn't one of them, skip it.
@@ -130,7 +160,7 @@
continue
}
- compat-execute $src $use_alt
+ compat-execute $src $use_alt $use_shobj
}
# Restore the original compiler under test.