Blame SOURCES/gdb-glibc-strstr-workaround.patch

26bbde
Index: gdb-7.7.90.20140613/gdb/dwarf2read.c
26bbde
===================================================================
26bbde
--- gdb-7.7.90.20140613.orig/gdb/dwarf2read.c	2014-06-13 21:56:54.744653443 +0200
26bbde
+++ gdb-7.7.90.20140613/gdb/dwarf2read.c	2014-06-13 22:01:51.529990684 +0200
26bbde
@@ -17695,6 +17695,26 @@ new_symbol_full (struct die_info *die, s
26bbde
       /* Cache this symbol's name and the name's demangled form (if any).  */
26bbde
       SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
26bbde
       linkagename = dwarf2_physname (name, die, cu);
26bbde
+
26bbde
+      /* Workaround for:
26bbde
+       * invalid IFUNC DW_AT_linkage_name: memmove strstr time
26bbde
+       * http://sourceware.org/bugzilla/show_bug.cgi?id=14166  */
26bbde
+      if (strcmp (linkagename, "strstr") == 0
26bbde
+	  && strstr (objfile_name (objfile), "/libc") != NULL)
26bbde
+	{
26bbde
+	  struct objfile *objfile_msym;
26bbde
+	  struct bound_minimal_symbol bmsym;
26bbde
+
26bbde
+	  if (objfile->separate_debug_objfile_backlink)
26bbde
+	    objfile_msym = objfile->separate_debug_objfile_backlink;
26bbde
+	  else
26bbde
+	    objfile_msym = objfile;
26bbde
+	  bmsym = lookup_minimal_symbol ("strstr", NULL, objfile_msym);
26bbde
+	  if (bmsym.minsym != NULL
26bbde
+	      && MSYMBOL_TYPE (bmsym.minsym) == mst_text_gnu_ifunc)
26bbde
+	    linkagename = "__strstr";
26bbde
+	}
26bbde
+
26bbde
       SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
26bbde
 
26bbde
       /* Fortran does not have mangling standard and the mangling does differ
26bbde
Index: gdb-7.7.90.20140613/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp
26bbde
===================================================================
26bbde
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
26bbde
+++ gdb-7.7.90.20140613/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp	2014-06-13 21:59:41.174840871 +0200
26bbde
@@ -0,0 +1,108 @@
26bbde
+# Copyright (C) 2012 Free Software Foundation, Inc.
26bbde
+
26bbde
+# This program is free software; you can redistribute it and/or modify
26bbde
+# it under the terms of the GNU General Public License as published by
26bbde
+# the Free Software Foundation; either version 3 of the License, or
26bbde
+# (at your option) any later version.
26bbde
+#
26bbde
+# This program is distributed in the hope that it will be useful,
26bbde
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26bbde
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26bbde
+# GNU General Public License for more details.
26bbde
+#
26bbde
+# You should have received a copy of the GNU General Public License
26bbde
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
26bbde
+
26bbde
+# Workaround for:
26bbde
+# invalid IFUNC DW_AT_linkage_name: memmove strstr time
26bbde
+# http://sourceware.org/bugzilla/show_bug.cgi?id=14166
26bbde
+
26bbde
+if {[skip_shlib_tests]} {
26bbde
+    return 0
26bbde
+}
26bbde
+
26bbde
+set testfile "gnu-ifunc-strstr-workaround"
26bbde
+set executable ${testfile}
26bbde
+set srcfile start.c
26bbde
+set binfile ${objdir}/${subdir}/${executable}
26bbde
+
26bbde
+if [prepare_for_testing ${testfile}.exp $executable $srcfile] {
26bbde
+    return -1
26bbde
+}
26bbde
+
26bbde
+if ![runto_main] {
26bbde
+    return 0
26bbde
+}
26bbde
+
26bbde
+set test "ptype atoi"
26bbde
+gdb_test_multiple $test $test {
26bbde
+    -re "type = int \\(const char \\*\\)\r\n$gdb_prompt $" {
26bbde
+	pass $test
26bbde
+    }
26bbde
+    -re "type = int \\(\\)\r\n$gdb_prompt $" {
26bbde
+	untested "$test (no DWARF)"
26bbde
+	return 0
26bbde
+    }
26bbde
+}
26bbde
+
26bbde
+set addr ""
26bbde
+set test "print strstr"
26bbde
+gdb_test_multiple $test $test {
26bbde
+    -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <strstr>\r\n$gdb_prompt $" {
26bbde
+	set addr $expect_out(1,string)
26bbde
+	pass $test
26bbde
+    }
26bbde
+    -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__strstr>\r\n$gdb_prompt $" {
26bbde
+	set addr $expect_out(1,string)
26bbde
+	pass "$test (GDB workaround)"
26bbde
+    }
26bbde
+    -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__libc_strstr>\r\n$gdb_prompt $" {
26bbde
+	set addr $expect_out(1,string)
26bbde
+	pass "$test (fixed glibc)"
26bbde
+    }
26bbde
+    -re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
26bbde
+	untested "$test (gnu-ifunc not in use by glibc)"
26bbde
+	return 0
26bbde
+    }
26bbde
+}
26bbde
+
26bbde
+set test "info sym"
26bbde
+gdb_test_multiple "info sym $addr" $test {
26bbde
+    -re "strstr in section \\.text of /lib\[^/\]*/libc.so.6\r\n$gdb_prompt $" {
26bbde
+	pass $test
26bbde
+    }
26bbde
+    -re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
26bbde
+	# unexpected
26bbde
+	xfail "$test (not in libc.so.6)"
26bbde
+	return 0
26bbde
+    }
26bbde
+}
26bbde
+
26bbde
+set test "info addr strstr"
26bbde
+gdb_test_multiple $test $test {
26bbde
+    -re "Symbol \"strstr\" is a function at address $addr\\.\r\n$gdb_prompt $" {
26bbde
+	fail "$test (DWARF for strstr)"
26bbde
+    }
26bbde
+    -re "Symbol \"strstr\" is at $addr in a file compiled without debugging\\.\r\n$gdb_prompt $" {
26bbde
+	pass "$test"
26bbde
+    }
26bbde
+}
26bbde
+
26bbde
+set test "print strstr second time"
26bbde
+gdb_test_multiple "print strstr" $test {
26bbde
+    -re " = {<text gnu-indirect-function variable, no debug info>} $addr <strstr>\r\n$gdb_prompt $" {
26bbde
+	pass $test
26bbde
+    }
26bbde
+    -re " = {<text gnu-indirect-function variable, no debug info>} $addr <__strstr>\r\n$gdb_prompt $" {
26bbde
+	pass "$test (GDB workaround)"
26bbde
+    }
26bbde
+    -re " = {<text gnu-indirect-function variable, no debug info>} $addr <__libc_strstr>\r\n$gdb_prompt $" {
26bbde
+	pass "$test (fixed glibc)"
26bbde
+    }
26bbde
+    -re " = {void \\*\\(void\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
26bbde
+	fail $test
26bbde
+    }
26bbde
+}
26bbde
+
26bbde
+gdb_test {print strstr("abc","b")} { = 0x[0-9a-f]+ "bc"}
26bbde
+gdb_test {print strstr("def","e")} { = 0x[0-9a-f]+ "ef"}