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