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

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