Blame SOURCES/memstomp-rh1133815.patch

e165a3
diff -Nrup a/memstomp.c b/memstomp.c
e165a3
--- a/memstomp.c	2014-08-26 13:13:30.004485804 -0600
e165a3
+++ b/memstomp.c	2014-08-26 13:17:00.450138891 -0600
e165a3
@@ -241,6 +241,16 @@ static char* generate_stacktrace(void)
e165a3
         int const n = real_backtrace(retaddr, frames_max);
e165a3
         assert(n >= 0);
e165a3
 
e165a3
+	/* Adjust the frame addresses since they point to the next
e165a3
+	   instruction to execute, not the call site which may be
e165a3
+	   associated with different line numbers. 
e165a3
+
e165a3
+	   For the cases we care about in memstomp, just subtracting
e165a3
+	   1 works the vast majority of the time.  It may not work for
e165a3
+	   a tail-call into an intercepted routine though.  */
e165a3
+	for (int i = 0; i < n; i++)
e165a3
+		retaddr[i]--;
e165a3
+	    
e165a3
         char **const strings = real_backtrace_symbols(retaddr, n);
e165a3
         assert(strings);
e165a3
 
e165a3
diff -Nrup a/testsuite/lib/memstomp.exp b/testsuite/lib/memstomp.exp
e165a3
--- a/testsuite/lib/memstomp.exp	2014-08-26 13:13:29.964485869 -0600
e165a3
+++ b/testsuite/lib/memstomp.exp	2014-08-26 14:29:37.334241044 -0600
e165a3
@@ -13,3 +13,11 @@ proc find_libmemstomp {} {
e165a3
   set file [findfile $base_dir/../.libs/libmemstomp.so $base_dir/../.libs/libmemstomp.so libmemstomp.so]
e165a3
   return $file
e165a3
 }
e165a3
+
e165a3
+proc find_libmemstomp_backtrace_symbols {} {
e165a3
+  global tool_root_dir 
e165a3
+  global base_dir
e165a3
+
e165a3
+  set file [findfile $base_dir/../.libs/libmemstomp-backtrace-symbols.so $base_dir/../.libs/libmemstomp-backtrace-symbols.so libmemstomp-backtrace-symbols.so]
e165a3
+  return $file
e165a3
+}
e165a3
diff -Nrup a/testsuite/memstomp.lineinfo/linenumber.c b/testsuite/memstomp.lineinfo/linenumber.c
e165a3
--- a/testsuite/memstomp.lineinfo/linenumber.c	1969-12-31 17:00:00.000000000 -0700
e165a3
+++ b/testsuite/memstomp.lineinfo/linenumber.c	2014-08-26 13:23:12.535518727 -0600
e165a3
@@ -0,0 +1,23 @@
e165a3
+#define __NO_STRING_INLINES
e165a3
+#include <string.h>
e165a3
+
e165a3
+void
e165a3
+something (void)
e165a3
+{
e165a3
+  char a[20] = "     hello";
e165a3
+  memcpy (a, a + 5, 6);
e165a3
+}
e165a3
+
e165a3
+void
e165a3
+nothing (void)
e165a3
+{
e165a3
+  something ();
e165a3
+}
e165a3
+
e165a3
+int
e165a3
+main (void)
e165a3
+{
e165a3
+  nothing ();
e165a3
+  return 0;
e165a3
+}
e165a3
+
e165a3
diff -Nrup a/testsuite/memstomp.lineinfo/linenumber.exp b/testsuite/memstomp.lineinfo/linenumber.exp
e165a3
--- a/testsuite/memstomp.lineinfo/linenumber.exp	1969-12-31 17:00:00.000000000 -0700
e165a3
+++ b/testsuite/memstomp.lineinfo/linenumber.exp	2014-08-26 17:49:55.493353200 -0600
e165a3
@@ -0,0 +1,65 @@
e165a3
+# Copyright (C) 2014 Free Software Foundation, Inc.
e165a3
+
e165a3
+# This program is free software; you can redistribute it and/or modify
e165a3
+# it under the terms of the GNU General Public License as published by
e165a3
+# the Free Software Foundation; either version 3 of the License, or
e165a3
+# (at your option) any later version.
e165a3
+#
e165a3
+# This program is distributed in the hope that it will be useful,
e165a3
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
e165a3
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e165a3
+# GNU General Public License for more details.
e165a3
+#
e165a3
+# You should have received a copy of the GNU General Public License
e165a3
+# along with GCC; see the file COPYING3.  If not see
e165a3
+# <http://www.gnu.org/licenses/>.
e165a3
+#
e165a3
+# This was originally copied from GCC's dejagnu testing framework
e165a3
+#
e165a3
+# This is a hack.  If we need more of these tests we'll want to use
e165a3
+# something like dj's framework so that we can mark the lines where
e165a3
+# we want errors/warnings.
e165a3
+#
e165a3
+
e165a3
+load_lib memstomp.exp
e165a3
+set libmemstomp [find_libmemstomp]
e165a3
+set libmemstomp_backtrace_symbols [find_libmemstomp_backtrace_symbols]
e165a3
+
e165a3
+if $tracelevel then {
e165a3
+    strace $tracelevel
e165a3
+}
e165a3
+
e165a3
+#
e165a3
+# main test loop
e165a3
+#
e165a3
+
e165a3
+proc compile-and-execute { sources } {
e165a3
+  global libmemstomp
e165a3
+  global libmemstomp_backtrace_symbols
e165a3
+
e165a3
+  set src [lindex $sources 0]
e165a3
+
e165a3
+  if {[catch {exec gcc -g -fno-builtin $src} results]} {
e165a3
+    fail "$src compilation $results"
e165a3
+  } else {
e165a3
+    pass "$src compilation $results"
e165a3
+  }
e165a3
+
e165a3
+  # ARM's unwinder seems broken, assuming aarch64 is broken as well
e165a3
+  setup_xfail arm*-*-* aarch64-*-*
e165a3
+  catch {exec /bin/bash -c "LD_PRELOAD=$libmemstomp:$libmemstomp_backtrace_symbols ./a.out"} results
e165a3
+  if {[regexp "linenumber.c:8" $results]} {
e165a3
+    pass "$src found overlap on right line $results"
e165a3
+  } else {
e165a3
+    fail "$src found overlap on right line $results"
e165a3
+  }
e165a3
+}
e165a3
+
e165a3
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
e165a3
+    # If we're only testing specific files and this isn't one of them, skip it.
e165a3
+    if ![runtest_file_p $runtests $src] then {
e165a3
+        continue
e165a3
+    }
e165a3
+
e165a3
+   compile-and-execute $src
e165a3
+}
e165a3
diff -Nrup a/testsuite/memstomp.overlap/linenumber.c b/testsuite/memstomp.overlap/linenumber.c
e165a3
--- a/testsuite/memstomp.overlap/linenumber.c	1969-12-31 17:00:00.000000000 -0700
e165a3
+++ b/testsuite/memstomp.overlap/linenumber.c	2014-08-26 13:17:30.057090085 -0600
e165a3
@@ -0,0 +1,23 @@
e165a3
+#define __NO_STRING_INLINES
e165a3
+#include <string.h>
e165a3
+
e165a3
+void
e165a3
+something (void)
e165a3
+{
e165a3
+  char a[20] = "     hello";
e165a3
+  memcpy (a, a + 5, 6);
e165a3
+}
e165a3
+
e165a3
+void
e165a3
+nothing (void)
e165a3
+{
e165a3
+  something ();
e165a3
+}
e165a3
+
e165a3
+int
e165a3
+main (void)
e165a3
+{
e165a3
+  nothing ();
e165a3
+  return 0;
e165a3
+}
e165a3
+