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