Patchwork Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 14, 2012, 11:11 a.m.
Message ID <20121114111112.GD1886@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/198873/
State New
Headers show

Comments

Jakub Jelinek - Nov. 14, 2012, 11:11 a.m.
Hi!

And here is an updated patch with start of the symbolizer (just showing
where it can be hooked, the symbolizer returns the output text unmodified right
now).  Writing an initial native only version shouldn't be that hard,
I guess one will need something like:
  set addr2line_name [find_binutils_prog addr2line]
  ...
  set res [remote_exec host "$addr2line_name" "-f -e $object $address1 $address2"]
or so, the bigger problem is with cross testing, I really have no idea where
addr2line should be run, what files need to be copied which way etc.

Anyway, once asan_symbolize actually symbolizes the output, we could use
something like:
/* { dg-output "ERROR: AddressSanitizer stack-buffer-overflow.*" } */
/* { dg-output "    #0 0x\[0-9a-f\]+ (in _*(interceptor_|)memcmp |\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "    #1 0x\[0-9a-f\]+ (in _*main|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
(this way it will check function names if symbolizer was actually
successful, and just accept #0 0xdeadbeef (foobarbaz.so+0xbeef) style
if it wasn't), but will not accept other function names in the backtrace.

2012-11-14  Jakub Jelinek  <jakub@redhat.com>

	* lib/asan-dg.exp: New file.
	* gcc.dg/asan/asan.exp: New file.
	* g++.dg/dg.exp: Prune also asan tests.
	* g++.dg/asan/asan.exp: New file.
	* c-c++-common/asan/memcmp-1.c: New test.



	Jakub

Patch

--- gcc/testsuite/lib/asan-dg.exp.jj	2012-11-14 09:11:13.086054131 +0100
+++ gcc/testsuite/lib/asan-dg.exp	2012-11-14 11:45:40.142061595 +0100
@@ -0,0 +1,111 @@ 
+# Copyright (C) 2012 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 3 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 GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib target-libpath.exp
+
+# Return 1 if compilation with -faddress-sanitizer is error-free for trivial
+# code, 0 otherwise.
+
+proc check_effective_target_faddress_sanitizer {} {
+    return [check_no_compiler_messages faddress_sanitizer object {
+	void foo (void) { }
+    } "-faddress-sanitizer"]
+}
+
+#
+# asan_link_flags -- compute library path and flags to find libasan.
+# (originally from g++.exp)
+#
+
+proc asan_link_flags { paths } {
+    global srcdir
+    global ld_library_path
+    global shlib_ext
+
+    set gccpath ${paths}
+    set flags ""
+
+    set shlib_ext [get_shlib_extension]
+
+    if { $gccpath != "" } {
+      if { [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.a"]
+	   || [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.${shlib_ext}"] } {
+	  append flags " -L${gccpath}/libsanitizer/asan/.libs "
+	  append ld_library_path ":${gccpath}/libsanitizer/asan/.libs"
+      }
+    } else {
+      global tool_root_dir
+
+      set libasan [lookfor_file ${tool_root_dir} libasan]
+      if { $libasan != "" } {
+	  append flags "-L${libasan} "
+	  append ld_library_path ":${libasan}"
+      }
+    }
+
+    set_ld_library_path_env_vars
+
+    return "$flags"
+}
+
+#
+# asan_init -- called at the start of each subdir of tests
+#
+
+proc asan_init { args } {
+    global TEST_ALWAYS_FLAGS
+    global ALWAYS_CXXFLAGS
+    global TOOL_OPTIONS
+
+    set link_flags ""
+    if ![is_remote host] {
+	if [info exists TOOL_OPTIONS] {
+	    set link_flags "[asan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
+	} else {
+	    set link_flags "[asan_link_flags [get_multilibs]]"
+	}
+    }
+
+    if [info exists ALWAYS_CXXFLAGS] {
+	set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
+	set ALWAYS_CXXFLAGS [concat "{additional_flags=-faddress-sanitizer}" $ALWAYS_CXXFLAGS]
+    } else {
+	set TEST_ALWAYS_FLAGS "$link_flags -faddress-sanitizer $TEST_ALWAYS_FLAGS"
+    }
+}
+
+# Symbolize lines like
+#   #2 0xdeadbeef (/some/path/libsanitizer.so.0.0.0+0xbeef)
+# in $output using addr2line to
+#   #2 0xdeadbeef in foobar file:123
+proc asan_symbolize { output } {
+    return "$output"
+}
+
+# Replace ${tool}_load with a wrapper so that we can symbolize the output.
+if { [info procs ${tool}_load] != [list] \
+      && [info procs saved_asan_${tool}_load] == [list] } {
+    rename ${tool}_load saved_asan_${tool}_load
+
+    proc ${tool}_load { program args } {
+	global tool
+	set result [eval [list saved_asan_${tool}_load $program] $args]
+	set output [lindex $result 1]
+	set symbolized_output [asan_symbolize "$output"]
+	set result [list [lindex $result 0] $symbolized_output]
+	return $result
+    }
+}
--- gcc/testsuite/gcc.dg/asan/asan.exp.jj	2012-11-14 10:25:31.504713624 +0100
+++ gcc/testsuite/gcc.dg/asan/asan.exp	2012-11-14 10:27:08.109935623 +0100
@@ -0,0 +1,37 @@ 
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC 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 3, or (at your option)
+# any later version.
+#
+# GCC 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 GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib gcc-dg.exp
+load_lib asan-dg.exp
+
+if ![check_effective_target_faddress_sanitizer] {
+  return
+}
+
+# Initialize `dg'.
+dg-init
+asan_init
+
+# Main loop.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c $srcdir/c-c++-common/asan/*.c]] ""
+
+# All done.
+dg-finish
--- gcc/testsuite/g++.dg/dg.exp.jj	2011-11-10 18:09:12.000000000 +0100
+++ gcc/testsuite/g++.dg/dg.exp	2012-11-14 09:07:04.043033232 +0100
@@ -1,4 +1,5 @@ 
-#   Copyright (C) 2000, 2007, 2009, 2010 Free Software Foundation, Inc.
+#   Copyright (C) 2000, 2007, 2009, 2010, 2011, 2012
+#   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
@@ -50,6 +51,7 @@  set tests [prune $tests $srcdir/$subdir/
 set tests [prune $tests $srcdir/$subdir/tm/*]
 set tests [prune $tests $srcdir/$subdir/guality/*]
 set tests [prune $tests $srcdir/$subdir/simulate-thread/*]
+set tests [prune $tests $srcdir/$subdir/asan/*]
 
 # Main loop.
 g++-dg-runtest $tests $DEFAULT_CXXFLAGS
--- gcc/testsuite/g++.dg/asan/asan.exp.jj	2012-11-14 09:08:58.748511740 +0100
+++ gcc/testsuite/g++.dg/asan/asan.exp	2012-11-14 10:27:13.571985934 +0100
@@ -0,0 +1,35 @@ 
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC 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 3, or (at your option)
+# any later version.
+#
+# GCC 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 GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+load_lib g++-dg.exp
+load_lib asan-dg.exp
+
+if ![check_effective_target_faddress_sanitizer] {
+  return
+}
+
+# Initialize `dg'.
+dg-init
+asan_init
+
+# Main loop.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C $srcdir/c-c++-common/asan/*.c]] ""
+
+# All done.
+dg-finish
--- gcc/testsuite/c-c++-common/asan/memcmp-1.c.jj	2012-11-14 10:21:19.881128491 +0100
+++ gcc/testsuite/c-c++-common/asan/memcmp-1.c	2012-11-14 11:42:27.912312236 +0100
@@ -0,0 +1,16 @@ 
+/* { dg-do run } */
+/* { dg-options "-fno-builtin-memcmp" } */
+/* { dg-shouldfail "asan" } */
+
+#include <string.h>
+
+int
+main (int argc, char **argv)
+{
+  char a1[] = {argc, 2, 3, 4};
+  char a2[] = {1, 2*argc, 3, 4};
+  int res = memcmp (a1, a2, 5 + argc);
+  return res;
+}
+
+/* { dg-output "ERROR: AddressSanitizer stack-buffer-overflow" } */