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

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