This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: target/19520: protected function pointer doesn't work right


On Thu, Jan 20, 2005 at 07:37:21PM -0800, H. J. Lu wrote:
> > Then come up with somewhere else to put the test, if you object to
> > adding it to the LD tests.  I think it is a very bad idea to add this
> > much code for an unintuitive behavior without testing it anywhere.
> 
> I will try to add something to gcc.misc-tests.
> 
> 

Here is the testcase.


H.J.
----
2005-01-21  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/19520
	* gcc.misc-tests/shlib/pic/protfunc-1-dso.c: New file.
	* gcc.misc-tests/shlib/pic/protfunc-1-dso.x: Likewise.
	* gcc.misc-tests/shlib/protfunc-1.c: Likewise.
	* gcc.misc-tests/shlib/protfunc-1.x: Likewise.
	* gcc.misc-tests/shlib/shlib.exp: Likewise.
	* lib/gcc-shlib.exp: Likewise.

--- gcc/testsuite/gcc.misc-tests/shlib/pic/protfunc-1-dso.c.shlib	2005-01-21 15:01:01.000000000 -0800
+++ gcc/testsuite/gcc.misc-tests/shlib/pic/protfunc-1-dso.c	2005-01-21 14:04:45.000000000 -0800
@@ -0,0 +1,13 @@
+void
+__attribute__ ((visibility ("protected")))
+foo ()
+{
+}
+
+void (*foo_p) () = foo;
+
+void *
+bar (void)
+{
+  return foo;
+}
--- gcc/testsuite/gcc.misc-tests/shlib/pic/protfunc-1-dso.x.shlib	2005-01-21 15:01:01.000000000 -0800
+++ gcc/testsuite/gcc.misc-tests/shlib/pic/protfunc-1-dso.x	2005-01-21 14:21:15.000000000 -0800
@@ -0,0 +1,11 @@
+#
+# compile PIC objects
+#
+
+set obj [c-shlib-compile $srcdir/$subdir/pic/protfunc-1-dso.c "-fPIC -O"]
+
+#
+# build shared libraries
+#
+
+c-shlib-compile $obj -shared
--- gcc/testsuite/gcc.misc-tests/shlib/protfunc-1.c.shlib	2005-01-21 15:01:01.000000000 -0800
+++ gcc/testsuite/gcc.misc-tests/shlib/protfunc-1.c	2005-01-21 15:00:26.000000000 -0800
@@ -0,0 +1,14 @@
+extern void (*foo_p) (void);
+extern void foo (void);
+extern void* bar (void);
+
+int
+main ()
+{
+  void *p;
+  p = bar ();
+  if (p == foo && p == foo_p)
+    return 0;
+  else
+    return 1;
+}
--- gcc/testsuite/gcc.misc-tests/shlib/protfunc-1.x.shlib	2005-01-21 15:01:01.000000000 -0800
+++ gcc/testsuite/gcc.misc-tests/shlib/protfunc-1.x	2005-01-21 15:13:21.000000000 -0800
@@ -0,0 +1,3 @@
+set shlib "$tmpdir/protfunc-1-dso.so"
+set cleanup "$shlib $tmpdir/protfunc-1-dso.o"
+return 0
--- gcc/testsuite/gcc.misc-tests/shlib/shlib.exp.shlib	2005-01-21 15:01:01.000000000 -0800
+++ gcc/testsuite/gcc.misc-tests/shlib/shlib.exp	2005-01-21 14:59:48.000000000 -0800
@@ -0,0 +1,39 @@
+# Copyright (C) 2005 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# load support procs
+load_lib gcc-shlib.exp
+
+#
+# build shared libraries 
+#
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/pic/*.x]] {
+    source $src
+}
+
+#
+#
+# compile and run main executable
+#
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
+    c-shlib-execute $src
+}
--- gcc/testsuite/lib/gcc-shlib.exp.shlib	2005-01-21 13:48:35.000000000 -0800
+++ gcc/testsuite/lib/gcc-shlib.exp	2005-01-21 15:17:10.000000000 -0800
@@ -0,0 +1,156 @@
+# Copyright (C) 2005 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.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-dejagnu@gnu.org.
+
+load_lib file-format.exp
+
+#
+# c-shlib-compile -- compile source file or build shared library.
+#
+# SRC is the full pathname of the testcase.
+# OPTION is the specific compiler flag we're testing (eg: -O2).
+#
+proc c-shlib-compile { src option } {
+    global output
+    global srcdir tmpdir
+    global host_triplet
+
+    if [string match "-shared" $option] {
+	set type "executable"
+	set output "$tmpdir/[file tail [file rootname $src]].so"
+    } else {
+	set type "object"
+	set output "$tmpdir/[file tail [file rootname $src]].o"
+    }
+
+    regsub "^$srcdir/?" $src "" testcase
+    # If we couldn't rip $srcdir out of `src' then just do the best we can.
+    # The point is to reduce the unnecessary noise in the logs.  Don't strip
+    # out too much because different testcases with the same name can confuse
+    # `test-tool'.
+    if [string match "/*" $testcase] {
+	set testcase "[file tail [file dirname $src]]/[file tail $src]"
+    }
+
+    verbose "Testing $testcase, $option" 1
+
+    # Run the compiler and analyze the results.
+    set options ""
+    lappend options "additional_flags=-w $option"
+
+    set comp_output [gcc_target_compile "$src" "$output" $type $options];
+    gcc_check_compile $testcase $option $output $comp_output
+    return $output
+}
+
+#
+# c-shlib-execute -- utility to compile and execute a testcase
+#
+# SOURCES is a list of full pathnames to the test source files.
+# The first filename in this list forms the "testcase".
+#
+# If the testcase has an associated .x file, we source that to run the
+# test instead.  We use .x so that we don't lengthen the existing filename
+# to more than 14 chars.
+#
+proc c-shlib-execute { sources args } {
+    global tmpdir tool srcdir output compiler_conditional_xfail_data
+
+    # Use the first source filename given as the filename under test.
+    set src [lindex $sources 0]
+
+    if { [llength $args] > 0 } {
+	set additional_flags [lindex $args 0];
+    } else {
+	set additional_flags "";
+    }
+
+    set option "-O"
+    set shlib ""
+    set cleanup ""
+
+    # Check for alternate driver.
+    if [file exists [file rootname $src].x] {
+	verbose "Using alternate driver [file rootname [file tail $src]].x" 2
+	set done_p 0
+	catch "set done_p \[source [file rootname $src].x\]"
+	if { $done_p } {
+	    return
+	}
+    }
+
+    set executable $tmpdir/[file tail [file rootname $src].x]
+
+    regsub "^$srcdir/?" $src "" testcase
+    # If we couldn't rip $srcdir out of `src' then just do the best we can.
+    # The point is to reduce the unnecessary noise in the logs.  Don't strip
+    # out too much because different testcases with the same name can confuse
+    # `test-tool'.
+    if [string match "/*" $testcase] {
+	set testcase "[file tail [file dirname $src]]/[file tail $src]"
+    }
+
+    # torture_{compile,execute}_xfail are set by the .x script
+    # (if present)
+    if [info exists torture_compile_xfail] {
+	setup_xfail $torture_compile_xfail
+    }
+
+    # torture_execute_before_{compile,execute} can be set by the .x script
+    # (if present)
+    if [info exists torture_eval_before_compile] {
+	set ignore_me [eval $torture_eval_before_compile]
+    }
+
+    verbose "Testing $testcase, $option" 1
+
+    set options ""
+    lappend options "additional_flags=-w $option $shlib"
+    if { $additional_flags != "" } {
+	lappend options "additional_flags=$additional_flags";
+    }
+    set comp_output [gcc_target_compile "$sources" "${executable}" executable $options];
+
+    if ![gcc_check_compile "$testcase compilation" $option $executable $comp_output] {
+	unresolved "$testcase execution, $option"
+	remote_file build delete $executable
+	foreach file $cleanup {
+	    remote_file build delete $file
+	}
+	return
+    }
+
+    if [info exists torture_execute_xfail] {
+	setup_xfail $torture_execute_xfail
+    }
+
+    if [info exists torture_eval_before_execute] {
+	set ignore_me [eval $torture_eval_before_execute]
+    }
+
+    set result [gcc_load "$executable" "" ""]
+    set status [lindex $result 0];
+    set output [lindex $result 1];
+    $status "$testcase execution, $option"
+    if { $status == "pass" } {
+	remote_file build delete $executable
+	foreach file $cleanup {
+	    remote_file build delete $file
+	}
+    }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]