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