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

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