Skip to content

Commit 61d10f9

Browse files
ivanivanov884jeffmahoney
authored andcommitted
gdb-glibc-strstr-workaround.patch
;; Workaround PR libc/14166 for inferior calls of strstr. ;;=fedora: Compatibility with RHELs (unchecked which ones).
1 parent 05a0c58 commit 61d10f9

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

gdb/dwarf2read.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21553,6 +21553,26 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
2155321553
/* Cache this symbol's name and the name's demangled form (if any). */
2155421554
SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
2155521555
linkagename = dwarf2_physname (name, die, cu);
21556+
21557+
/* Workaround for:
21558+
* invalid IFUNC DW_AT_linkage_name: memmove strstr time
21559+
* http://sourceware.org/bugzilla/show_bug.cgi?id=14166 */
21560+
if (strcmp (linkagename, "strstr") == 0
21561+
&& strstr (objfile_name (objfile), "/libc") != NULL)
21562+
{
21563+
struct objfile *objfile_msym;
21564+
struct bound_minimal_symbol bmsym;
21565+
21566+
if (objfile->separate_debug_objfile_backlink)
21567+
objfile_msym = objfile->separate_debug_objfile_backlink;
21568+
else
21569+
objfile_msym = objfile;
21570+
bmsym = lookup_minimal_symbol ("strstr", NULL, objfile_msym);
21571+
if (bmsym.minsym != NULL
21572+
&& MSYMBOL_TYPE (bmsym.minsym) == mst_text_gnu_ifunc)
21573+
linkagename = "__strstr";
21574+
}
21575+
2155621576
SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
2155721577

2155821578
/* Fortran does not have mangling standard and the mangling does differ
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright (C) 2012 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
# Workaround for:
17+
# invalid IFUNC DW_AT_linkage_name: memmove strstr time
18+
# http://sourceware.org/bugzilla/show_bug.cgi?id=14166
19+
20+
if {[skip_shlib_tests]} {
21+
return 0
22+
}
23+
24+
set testfile "gnu-ifunc-strstr-workaround"
25+
set executable ${testfile}
26+
set srcfile start.c
27+
set binfile [standard_output_file ${executable}]
28+
29+
if [prepare_for_testing ${testfile}.exp $executable $srcfile] {
30+
return -1
31+
}
32+
33+
if ![runto_main] {
34+
return 0
35+
}
36+
37+
set test "ptype atoi"
38+
gdb_test_multiple $test $test {
39+
-re "type = int \\(const char \\*\\)\r\n$gdb_prompt $" {
40+
pass $test
41+
}
42+
-re "type = int \\(\\)\r\n$gdb_prompt $" {
43+
untested "$test (no DWARF)"
44+
return 0
45+
}
46+
}
47+
48+
set addr ""
49+
set test "print strstr"
50+
gdb_test_multiple $test $test {
51+
-re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <strstr>\r\n$gdb_prompt $" {
52+
set addr $expect_out(1,string)
53+
pass $test
54+
}
55+
-re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__strstr>\r\n$gdb_prompt $" {
56+
set addr $expect_out(1,string)
57+
pass "$test (GDB workaround)"
58+
}
59+
-re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__libc_strstr>\r\n$gdb_prompt $" {
60+
set addr $expect_out(1,string)
61+
pass "$test (fixed glibc)"
62+
}
63+
-re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
64+
untested "$test (gnu-ifunc not in use by glibc)"
65+
return 0
66+
}
67+
}
68+
69+
set test "info sym"
70+
gdb_test_multiple "info sym $addr" $test {
71+
-re "strstr in section \\.text of /lib\[^/\]*/libc.so.6\r\n$gdb_prompt $" {
72+
pass $test
73+
}
74+
-re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
75+
# unexpected
76+
xfail "$test (not in libc.so.6)"
77+
return 0
78+
}
79+
}
80+
81+
set test "info addr strstr"
82+
gdb_test_multiple $test $test {
83+
-re "Symbol \"strstr\" is a function at address $addr\\.\r\n$gdb_prompt $" {
84+
fail "$test (DWARF for strstr)"
85+
}
86+
-re "Symbol \"strstr\" is at $addr in a file compiled without debugging\\.\r\n$gdb_prompt $" {
87+
pass "$test"
88+
}
89+
}
90+
91+
set test "print strstr second time"
92+
gdb_test_multiple "print strstr" $test {
93+
-re " = {<text gnu-indirect-function variable, no debug info>} $addr <strstr>\r\n$gdb_prompt $" {
94+
pass $test
95+
}
96+
-re " = {<text gnu-indirect-function variable, no debug info>} $addr <__strstr>\r\n$gdb_prompt $" {
97+
pass "$test (GDB workaround)"
98+
}
99+
-re " = {<text gnu-indirect-function variable, no debug info>} $addr <__libc_strstr>\r\n$gdb_prompt $" {
100+
pass "$test (fixed glibc)"
101+
}
102+
-re " = {void \\*\\(void\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
103+
fail $test
104+
}
105+
}
106+
107+
gdb_test {print strstr("abc","b")} { = 0x[0-9a-f]+ "bc"}
108+
gdb_test {print strstr("def","e")} { = 0x[0-9a-f]+ "ef"}

0 commit comments

Comments
 (0)