* [libiberty] don't demangle functions named "."
@ 2008-01-09 17:15 Thiago Jung Bauermann
2008-01-09 19:26 ` Jim Blandy
2008-01-19 3:02 ` Ian Lance Taylor
0 siblings, 2 replies; 7+ messages in thread
From: Thiago Jung Bauermann @ 2008-01-09 17:15 UTC (permalink / raw)
To: gcc-patches; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]
Hi folks,
This patch is to stop the C++ demangler from trying to demangle a symbol
which is not a C++ mangled function.
The problem is happening in Linux/ppc64 with symbols marking the start
of function instructions in the text section, which begin with a dot.
When the function name starts with __, it's symbol will be something
like .__<function name>. If the demangler is able to derive a valid
argument list from <function name>, it will find a demangled "function"
called . with some random argument list. This is happening with several
functions in glibc:
.__frexpf -> .(float, long double,...)(long long, float *)
.__flbf -> .(float, long, bool, float)
.__ffs -> .(float, float, short)
.__ffsll -> .(float, float, short, long, long)
.__sleep -> .(short, long,...)(...)( *)
.__execve -> .(...)(long long,...)(char, void,...)
.__dup -> .(double, *__restrict)
.__fixdfdi -> .(float, int, long long, double, float, double, int)
.__fixsfdi -> .(float, int, long long, short, float, double, int)
This is a problem in GDB, for instance when showing a backtrace which
goes through these functions in glibc:
(gdb) bt
#0 0x000004000015edf8 in .__libc_nanosleep () from /lib64/tls/libc.so.6
#1 0x000004000015eb74 in . () from /lib64/tls/libc.so.6
#2 0x0000000010000784 in sleeping_thread (p=0x0) at libc-nanosleep.c:8
(gdb) info symbol 0x000004000015eb74
.(short, long,...)(...)( *) + 148 in section .text
With the patch applied:
(gdb) bt
#0 0x000004000015edf8 in .__libc_nanosleep () from /lib64/tls/libc.so.6
#1 0x000004000015eb74 in .__sleep () from /lib64/tls/libc.so.6
#2 0x0000000010000784 in sleeping_thread (p=0x0) at libc-nanosleep.c:8
(gdb) info symbol 0x000004000015eb74
.__sleep + 148 in section .text
All the libiberty and GDB tests related to demangling continue to pass.
Is this ok?
--
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center
[-- Attachment #2: demangle-fix.diff --]
[-- Type: text/x-patch, Size: 2703 bytes --]
2008-01-09 Thiago Jung Bauermann <bauerman@br.ibm.com>
* cplus-dem.c (demangle_function_name): Changed to return value
indicating if a name was correctly demangled.
(iterate_demangle_function): Use demangle_function_name return value.
Index: src-git.demangle-fix/libiberty/cplus-dem.c
===================================================================
--- src-git.demangle-fix.orig/libiberty/cplus-dem.c 2008-01-08 15:48:12.000000000 -0200
+++ src-git.demangle-fix/libiberty/cplus-dem.c 2008-01-08 15:48:54.000000000 -0200
@@ -414,7 +414,7 @@ static int do_type (struct work_stuff *,
static int do_arg (struct work_stuff *, const char **, string *);
-static void
+static int
demangle_function_name (struct work_stuff *, const char **, string *,
const char *);
@@ -2493,10 +2493,7 @@ iterate_demangle_function (struct work_s
"__"-sequence. This is the normal case. */
if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING
|| strstr (scan + 2, "__") == NULL)
- {
- demangle_function_name (work, mangled, declp, scan);
- return 1;
- }
+ return demangle_function_name (work, mangled, declp, scan);
/* Save state so we can restart if the guess at the correct "__" was
wrong. */
@@ -2513,10 +2510,12 @@ iterate_demangle_function (struct work_s
while (scan[2])
{
- demangle_function_name (work, mangled, declp, scan);
- success = demangle_signature (work, mangled, declp);
- if (success)
- break;
+ if (demangle_function_name (work, mangled, declp, scan))
+ {
+ success = demangle_signature (work, mangled, declp);
+ if (success)
+ break;
+ }
/* Reset demangle state for the next round. */
*mangled = mangle_init;
@@ -4421,7 +4420,9 @@ demangle_nested_args (struct work_stuff
return result;
}
-static void
+/* Returns 1 if a valid function name was found or 0 otherwise. */
+
+static int
demangle_function_name (struct work_stuff *work, const char **mangled,
string *declp, const char *scan)
{
@@ -4461,13 +4462,13 @@ demangle_function_name (struct work_stuf
{
work -> constructor += 1;
string_clear (declp);
- return;
+ return 1;
}
else if (strcmp (declp -> b, "__dt") == 0)
{
work -> destructor += 1;
string_clear (declp);
- return;
+ return 1;
}
}
@@ -4575,6 +4576,13 @@ demangle_function_name (struct work_stuf
}
}
}
+
+ /* If a function name was obtained but it's not valid, we were not
+ successful. */
+ if (LEN_STRING (declp) == 1 && declp->b[0] == '.')
+ return 0;
+ else
+ return 1;
}
/* a mini string-handling package */
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [libiberty] don't demangle functions named "."
2008-01-09 17:15 [libiberty] don't demangle functions named "." Thiago Jung Bauermann
@ 2008-01-09 19:26 ` Jim Blandy
2008-01-09 19:55 ` Thiago Jung Bauermann
2008-01-19 3:02 ` Ian Lance Taylor
1 sibling, 1 reply; 7+ messages in thread
From: Jim Blandy @ 2008-01-09 19:26 UTC (permalink / raw)
To: Thiago Jung Bauermann; +Cc: gcc-patches, gdb-patches
Thiago Jung Bauermann <bauerman at br.ibm.com> writes:
> @@ -2513,10 +2510,12 @@ iterate_demangle_function (struct work_s
>
> while (scan[2])
> {
> - demangle_function_name (work, mangled, declp, scan);
> - success = demangle_signature (work, mangled, declp);
> - if (success)
> - break;
> + if (demangle_function_name (work, mangled, declp, scan))
> + {
> + success = demangle_signature (work, mangled, declp);
> + if (success)
> + break;
> + }
>
> /* Reset demangle state for the next round. */
> *mangled = mangle_init;
Why not simply:
if (demangle_function_name (work, mangled, declp, scan)
&& demangle_signature (work, mangled, declp))
break;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [libiberty] don't demangle functions named "."
2008-01-09 19:26 ` Jim Blandy
@ 2008-01-09 19:55 ` Thiago Jung Bauermann
0 siblings, 0 replies; 7+ messages in thread
From: Thiago Jung Bauermann @ 2008-01-09 19:55 UTC (permalink / raw)
To: Jim Blandy; +Cc: gcc-patches, gdb-patches
On Wed, 2008-01-09 at 11:26 -0800, Jim Blandy wrote:
> Thiago Jung Bauermann <bauerman at br.ibm.com> writes:
> > + if (demangle_function_name (work, mangled, declp, scan))
> > + {
> > + success = demangle_signature (work, mangled, declp);
> > + if (success)
> > + break;
> > + }
>
> Why not simply:
>
> if (demangle_function_name (work, mangled, declp, scan)
> && demangle_signature (work, mangled, declp))
> break;
success is used later on as the return value of the function. I can
change this to:
if (demangle_function_name (work, mangled, declp, scan)
&& demangle_signature (work, mangled, declp))
{
success = 1;
break;
}
--
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [libiberty] don't demangle functions named "."
2008-01-09 17:15 [libiberty] don't demangle functions named "." Thiago Jung Bauermann
2008-01-09 19:26 ` Jim Blandy
@ 2008-01-19 3:02 ` Ian Lance Taylor
2008-01-23 1:05 ` Thiago Jung Bauermann
1 sibling, 1 reply; 7+ messages in thread
From: Ian Lance Taylor @ 2008-01-19 3:02 UTC (permalink / raw)
To: Thiago Jung Bauermann; +Cc: gcc-patches, gdb-patches
Thiago Jung Bauermann <bauerman@br.ibm.com> writes:
> 2008-01-09 Thiago Jung Bauermann <bauerman@br.ibm.com>
>
> * cplus-dem.c (demangle_function_name): Changed to return value
> indicating if a name was correctly demangled.
> (iterate_demangle_function): Use demangle_function_name return value.
This is OK.
Thanks.
Ian
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [libiberty] don't demangle functions named "."
2008-01-19 3:02 ` Ian Lance Taylor
@ 2008-01-23 1:05 ` Thiago Jung Bauermann
2008-01-23 5:03 ` Ben Elliston
0 siblings, 1 reply; 7+ messages in thread
From: Thiago Jung Bauermann @ 2008-01-23 1:05 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-patches, gdb-patches
On Fri, 2008-01-18 at 19:01 -0800, Ian Lance Taylor wrote:
> Thiago Jung Bauermann <bauerman@br.ibm.com> writes:
>
> > 2008-01-09 Thiago Jung Bauermann <bauerman@br.ibm.com>
> >
> > * cplus-dem.c (demangle_function_name): Changed to return value
> > indicating if a name was correctly demangled.
> > (iterate_demangle_function): Use demangle_function_name return value.
>
> This is OK.
Thanks! I don't have commit access to the svn repo, though. Could you or
someone else commit this please?
--
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [libiberty] don't demangle functions named "."
2008-01-23 1:05 ` Thiago Jung Bauermann
@ 2008-01-23 5:03 ` Ben Elliston
2008-01-23 16:58 ` Thiago Jung Bauermann
0 siblings, 1 reply; 7+ messages in thread
From: Ben Elliston @ 2008-01-23 5:03 UTC (permalink / raw)
To: Thiago Jung Bauermann; +Cc: Ian Lance Taylor, gcc-patches, gdb-patches
> > > 2008-01-09 Thiago Jung Bauermann <bauerman@br.ibm.com>
> > >
> > > * cplus-dem.c (demangle_function_name): Changed to return value
> > > indicating if a name was correctly demangled.
> > > (iterate_demangle_function): Use demangle_function_name return value.
> >
> > This is OK.
>
> Thanks! I don't have commit access to the svn repo, though. Could you or
> someone else commit this please?
I've checked this in for you (in gcc and src).
Cheers, Ben
--
Ben Elliston <bje@au.ibm.com>
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [libiberty] don't demangle functions named "."
2008-01-23 5:03 ` Ben Elliston
@ 2008-01-23 16:58 ` Thiago Jung Bauermann
0 siblings, 0 replies; 7+ messages in thread
From: Thiago Jung Bauermann @ 2008-01-23 16:58 UTC (permalink / raw)
To: Ben Elliston; +Cc: Ian Lance Taylor, gcc-patches, gdb-patches
On Wed, 2008-01-23 at 16:03 +1100, Ben Elliston wrote:
> > > > 2008-01-09 Thiago Jung Bauermann <bauerman@br.ibm.com>
> > > >
> > > > * cplus-dem.c (demangle_function_name): Changed to return value
> > > > indicating if a name was correctly demangled.
> > > > (iterate_demangle_function): Use demangle_function_name return value.
> > >
> > > This is OK.
> >
> > Thanks! I don't have commit access to the svn repo, though. Could you or
> > someone else commit this please?
>
> I've checked this in for you (in gcc and src).
Thanks!
--
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-01-23 16:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-09 17:15 [libiberty] don't demangle functions named "." Thiago Jung Bauermann
2008-01-09 19:26 ` Jim Blandy
2008-01-09 19:55 ` Thiago Jung Bauermann
2008-01-19 3:02 ` Ian Lance Taylor
2008-01-23 1:05 ` Thiago Jung Bauermann
2008-01-23 5:03 ` Ben Elliston
2008-01-23 16:58 ` Thiago Jung Bauermann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox