public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed
@ 2023-09-28 10:48 vries at gcc dot gnu.org
2023-09-28 10:49 ` [Bug exp/30911] " vries at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-28 10:48 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
Bug ID: 30911
Summary: [gdb/exp] Cannot call ifunc strstr with debuginfo
installed
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: exp
Assignee: unassigned at sourceware dot org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
[ This report is based on fedora patch gdb-glibc-strstr-workaround.patch (see
also PR glibc/14166). ]
Consider a hello world a.out with debug info. Without glibc debug info
installed, I'm able to call strstr:
...
$ gdb -q a.out -ex start -ex "p strstr" -ex "ptype strstr"
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.
Starting program: /data/vries/gdb/a.out
Temporary breakpoint 1, main () at hello.c:6
6 printf ("hello\n");
$1 = {<text gnu-indirect-function variable, no debug info>} 0x7ffff7e4f9ce
<strstr>
type = <unknown return type> ()
(gdb) p strstr ("haha", "ah")
'__strstr_sse2_unaligned' has unknown return type; cast the call to its
declared return type
(gdb) p (char *)strstr ("haha", "ah")
$2 = 0x7ffff7dab1b1 "aha"
(gdb)
...
Now with glibc debug info installed:
...
$ gdb -q a.out -ex start -ex "p strstr" -ex "ptype strstr"
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.
Starting program: /data/vries/gdb/a.out
Temporary breakpoint 1, main () at hello.c:6
6 printf ("hello\n");
$1 = {<text gnu-indirect-function variable, no debug info>} 0x7ffff7e4e9ce
<__libc_strstr_ifunc>
type = <unknown return type> ()
(gdb) p strstr ("haha", "ah")
$2 = void
(gdb) p (char *)strstr ("haha", "ah")
Invalid cast.
(gdb)
...
This is with glibc 2.31 on openSUSE Leap 15.4.
With glibc 2.38 on openSUSE Tumbleweed this doesn't happen.
This seems to be caused by the fact that in the tumbleweed case we have an
unspecified_type return type:
...
<1><11dd5e>: Abbrev Number: 1 (DW_TAG_subprogram)
<11dd5f> DW_AT_name : __strstr_sse2_unaligned
<11dd63> DW_AT_external : 1
<11dd63> DW_AT_type : <0x11dd6e>
<11dd64> DW_AT_low_pc : 0xb9c9e
<11dd6c> DW_AT_high_pc : 1173
<1><11dd6e>: Abbrev Number: 3 (DW_TAG_unspecified_type)
<1><11dd6f>: Abbrev Number: 0
...
and in the failing case there's no type at all, which defaults to void:
...
<1><3e1e58>: Abbrev Number: 2 (DW_TAG_subprogram)
<3e1e59> DW_AT_name : __strstr_sse2_unaligned
<3e1e5d> DW_AT_external : 1
<3e1e5e> DW_AT_low_pc : 0xbbd2e
<3e1e66> DW_AT_high_pc : 0xbc1c3
...
This is basically PR gas/29517, fixed in 2.40 but present in 2.39.
What is curious though is that we do manage to find the correct type for the
revolver function:
...
(gdb) p __libc_strstr_ifunc
$3 = {char *(*(void))(const char *, const char *)} 0x7ffff7e4e9ce
<__libc_strstr_ifunc>
...
but we don't use it.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug exp/30911] [gdb/exp] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
@ 2023-09-28 10:49 ` vries at gcc dot gnu.org
2023-09-28 10:50 ` sam at gentoo dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-28 10:49 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Tentative fix: swap the order here:
...
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 0f9ad34bbb4..20d0f9acca5 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -316,17 +316,20 @@ find_function_addr (struct value *function,
FUNCTION_TYPE have been asked for. */
if (retval_type != NULL || function_type != NULL)
{
- type *target_ftype = find_function_type (funaddr);
- /* If we don't have debug info for the target function,
- see if we can instead extract the target function's
- type from the type that the resolver returns. */
- if (target_ftype == NULL)
- target_ftype = find_gnu_ifunc_target_type (resolver_addr);
+ /* Try to get the target function's type from the type that
+ the resolver returns. We do this first to work around
+ PR gas/29517. */
+ type *target_ftype = find_gnu_ifunc_target_type (resolver_addr);
if (target_ftype != NULL)
{
value_type = check_typedef (target_ftype)->target_type ();
ftype = target_ftype;
}
+
+ /* Try to get the target function's type from the target
+ function. */
+ if (target_ftype == NULL)
+ target_ftype = find_function_type (funaddr);
}
}
else
...
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug exp/30911] [gdb/exp] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
2023-09-28 10:49 ` [Bug exp/30911] " vries at gcc dot gnu.org
@ 2023-09-28 10:50 ` sam at gentoo dot org
2023-09-28 11:24 ` vries at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sam at gentoo dot org @ 2023-09-28 10:50 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
Sam James <sam at gentoo dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |sam at gentoo dot org
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug exp/30911] [gdb/exp] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
2023-09-28 10:49 ` [Bug exp/30911] " vries at gcc dot gnu.org
2023-09-28 10:50 ` sam at gentoo dot org
@ 2023-09-28 11:24 ` vries at gcc dot gnu.org
2023-09-28 11:54 ` vries at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-28 11:24 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
> Tentative fix: swap the order here:
And we get:
...
FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=0: final_debug=1:
p gnu_ifunc (3)
FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=0: final_debug=1:
p gnu_ifunc()
FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=1:
p gnu_ifunc (3)
FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=1:
p gnu_ifunc()
...
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug exp/30911] [gdb/exp] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
` (2 preceding siblings ...)
2023-09-28 11:24 ` vries at gcc dot gnu.org
@ 2023-09-28 11:54 ` vries at gcc dot gnu.org
2023-09-28 13:09 ` [Bug symtab/30911] " vries at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-28 11:54 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Alternatively, we detect the problem while reading the debug info and fix it:
...
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5bbc8e24cf9..e547653d7fe 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10161,7 +10161,20 @@ read_func_scope (struct die_info *die, struct
dwarf2_cu *cu)
gdb_assert (cu->get_builder () != nullptr);
newobj = cu->get_builder ()->push_context (0, lowpc);
- newobj->name = new_symbol (die, read_type_die (die, cu), cu, templ_func);
+ struct type *type = read_type_die (die, cu);
+ if (type->code () == TYPE_CODE_FUNC
+ && type->num_fields () == 0
+ && type->target_type ()->code () == TYPE_CODE_VOID
+ && !type->target_type ()->is_stub ()
+ && strcmp (cu->producer, "GNU AS 2.39.0") == 0)
+ {
+ /* Work around PR gas/29517. */
+ type = (type_allocator (cu->per_objfile->objfile, cu->lang ())
+ .new_type (TYPE_CODE_VOID, 0, nullptr));
+ type->set_is_stub (true);
+ set_die_type (die, type, cu);
+ }
+ newobj->name = new_symbol (die, type, cu, templ_func);
if (dwarf2_func_is_main_p (die, cu))
set_objfile_main_name (objfile, newobj->name->linkage_name (),
...
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug symtab/30911] [gdb/exp] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
` (3 preceding siblings ...)
2023-09-28 11:54 ` vries at gcc dot gnu.org
@ 2023-09-28 13:09 ` vries at gcc dot gnu.org
2023-09-28 16:08 ` vries at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-28 13:09 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
Tom de Vries <vries at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|exp |symtab
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug symtab/30911] [gdb/exp] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
` (4 preceding siblings ...)
2023-09-28 13:09 ` [Bug symtab/30911] " vries at gcc dot gnu.org
@ 2023-09-28 16:08 ` vries at gcc dot gnu.org
2023-09-30 8:37 ` [Bug symtab/30911] [gdb/symtab] " vries at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-28 16:08 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2023-September/202828.html
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug symtab/30911] [gdb/symtab] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
` (5 preceding siblings ...)
2023-09-28 16:08 ` vries at gcc dot gnu.org
@ 2023-09-30 8:37 ` vries at gcc dot gnu.org
2023-10-16 14:32 ` cvs-commit at gcc dot gnu.org
2023-10-16 14:33 ` vries at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-09-30 8:37 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
Tom de Vries <vries at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[gdb/exp] Cannot call ifunc |[gdb/symtab] Cannot call
|strstr with debuginfo |ifunc strstr with debuginfo
|installed |installed
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug symtab/30911] [gdb/symtab] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
` (6 preceding siblings ...)
2023-09-30 8:37 ` [Bug symtab/30911] [gdb/symtab] " vries at gcc dot gnu.org
@ 2023-10-16 14:32 ` cvs-commit at gcc dot gnu.org
2023-10-16 14:33 ` vries at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-16 14:32 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1d45d90934b10862c00a22bcf4075815a785001b
commit 1d45d90934b10862c00a22bcf4075815a785001b
Author: Tom de Vries <tdevries@suse.de>
Date: Mon Oct 16 16:32:28 2023 +0200
[gdb/symtab] Work around PR gas/29517
When using glibc debuginfo generated with gas 2.39, we run into PR
gas/29517:
...
$ gdb -q -batch a.out -ex start -ex "p (char *)strstr (\"haha\", \"ah\")"
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.
Temporary breakpoint 1, main () at hello.c:6
6 printf ("hello\n");
Invalid cast.
...
while without glibc debuginfo installed we get the expected result:
...
$n = 0x7ffff7daa1b1 "aha"
...
and likewise with glibc debuginfo generated with gas 2.40.
The strstr ifunc resolves to __strstr_sse2_unaligned. The problem is that
gas
generates dwarf that states that the return type is void:
...
<1><3e1e58>: Abbrev Number: 2 (DW_TAG_subprogram)
<3e1e59> DW_AT_name : __strstr_sse2_unaligned
<3e1e5d> DW_AT_external : 1
<3e1e5e> DW_AT_low_pc : 0xbbd2e
<3e1e66> DW_AT_high_pc : 0xbc1c3
...
while the return type should be a DW_TAG_unspecified_type, as is the case
with gas 2.40.
We can still use the workaround of casting to another function type for
both
__strstr_sse2_unaligned:
...
(gdb) p ((char * (*) (const char *, const char *))__strstr_sse2_unaligned)
\
("haha", "ah")
$n = 0x7ffff7daa211 "aha"
...
and strstr (which requires using *strstr to dereference the ifunc before we
cast):
...
gdb) p ((char * (*) (const char *, const char *))*strstr) ("haha", "ah")
$n = 0x7ffff7daa251 "aha"
...
but that's a bit cumbersome to use.
Work around this in the dwarf reader, such that we have instead:
...
(gdb) p (char *)strstr ("haha", "ah")
$n = 0x7ffff7daa1b1 "aha"
...
This also requires fixing producer_is_gcc to stop returning true for
producer "GNU AS 2.39.0".
Tested on x86_64-linux.
Approved-By: Andrew Burgess <aburgess@redhat.com>
PR symtab/30911
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30911
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug symtab/30911] [gdb/symtab] Cannot call ifunc strstr with debuginfo installed
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
` (7 preceding siblings ...)
2023-10-16 14:32 ` cvs-commit at gcc dot gnu.org
@ 2023-10-16 14:33 ` vries at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-10-16 14:33 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=30911
Tom de Vries <vries at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |15.1
--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-10-16 14:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28 10:48 [Bug exp/30911] New: [gdb/exp] Cannot call ifunc strstr with debuginfo installed vries at gcc dot gnu.org
2023-09-28 10:49 ` [Bug exp/30911] " vries at gcc dot gnu.org
2023-09-28 10:50 ` sam at gentoo dot org
2023-09-28 11:24 ` vries at gcc dot gnu.org
2023-09-28 11:54 ` vries at gcc dot gnu.org
2023-09-28 13:09 ` [Bug symtab/30911] " vries at gcc dot gnu.org
2023-09-28 16:08 ` vries at gcc dot gnu.org
2023-09-30 8:37 ` [Bug symtab/30911] [gdb/symtab] " vries at gcc dot gnu.org
2023-10-16 14:32 ` cvs-commit at gcc dot gnu.org
2023-10-16 14:33 ` vries at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).