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

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