This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: nm -C no longer strips leading underscores?
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sourceware dot org, yselkowitz at users dot sourceforge dot net
- Date: Mon, 7 Jul 2008 21:17:12 +0930
- Subject: Re: nm -C no longer strips leading underscores?
- References: <20080625031840.GA22222@ednor.casa.cgf.cx>
On Tue, Jun 24, 2008 at 11:18:40PM -0400, Christopher Faylor wrote:
> A Cygwin user has noticed that "nm -C" no longer removes the leading
> underscore from symbols despite documentation to the contrary.
>
> That behavior seems to have been caused by the introduction of the
> bfd_demangle function which returns NULL when a symbol is not translated
> by cplus_demangle rather than returning the symbol without the leading
> underscore.
>
> I think this is a bug
[snip]
Agreed. If the name is demangled we remove bfd_symbol_leading_char,
so I think bfd_demangle ought to always remove it.
* bfd.c (bfd_demangle): Always trim off bfd_get_symbol_leading_char.
Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.102
diff -u -p -r1.102 bfd.c
--- bfd/bfd.c 28 Mar 2008 06:49:44 -0000 1.102
+++ bfd/bfd.c 7 Jul 2008 11:12:46 -0000
@@ -1829,10 +1829,12 @@ bfd_demangle (bfd *abfd, const char *nam
char *res, *alloc;
const char *pre, *suf;
size_t pre_len;
+ bfd_boolean skip_lead;
- if (abfd != NULL
- && *name != '\0'
- && bfd_get_symbol_leading_char (abfd) == *name)
+ skip_lead = (abfd != NULL
+ && *name != '\0'
+ && bfd_get_symbol_leading_char (abfd) == *name);
+ if (skip_lead)
++name;
/* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
@@ -1863,7 +1865,18 @@ bfd_demangle (bfd *abfd, const char *nam
free (alloc);
if (res == NULL)
- return NULL;
+ {
+ if (skip_lead)
+ {
+ size_t len = strlen (pre) + 1;
+ alloc = bfd_malloc (len);
+ if (alloc == NULL)
+ return NULL;
+ memcpy (alloc, pre, len);
+ return alloc;
+ }
+ return NULL;
+ }
/* Put back any prefix or suffix. */
if (pre_len != 0 || suf != NULL)
--
Alan Modra
Australia Development Lab, IBM