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

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