summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/ld/ldmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/binutils/ld/ldmisc.c')
-rw-r--r--contrib/binutils/ld/ldmisc.c65
1 files changed, 43 insertions, 22 deletions
diff --git a/contrib/binutils/ld/ldmisc.c b/contrib/binutils/ld/ldmisc.c
index 42adcee..2869ba9 100644
--- a/contrib/binutils/ld/ldmisc.c
+++ b/contrib/binutils/ld/ldmisc.c
@@ -65,28 +65,6 @@ static void vfinfo PARAMS ((FILE *, const char *, va_list));
%u integer, like printf
*/
-char *
-demangle (string)
- const char *string;
-{
- char *res;
- const char *p;
-
- if (output_bfd != NULL
- && bfd_get_symbol_leading_char (output_bfd) == string[0])
- ++string;
-
- /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
- or the MS PE format. These formats have a number of leading '.'s
- on at least some symbols, so we remove all dots. */
- p = string;
- while (*p == '.')
- ++p;
-
- res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS);
- return res ? res : xstrdup (string);
-}
-
static void
vfinfo (fp, fmt, arg)
FILE *fp;
@@ -407,6 +385,49 @@ vfinfo (fp, fmt, arg)
xexit (1);
}
+/* Wrapper around cplus_demangle. Strips leading underscores and
+ other such chars that would otherwise confuse the demangler. */
+
+char *
+demangle (name)
+ const char *name;
+{
+ char *res;
+ const char *p;
+
+ if (output_bfd != NULL
+ && bfd_get_symbol_leading_char (output_bfd) == name[0])
+ ++name;
+
+ /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
+ or the MS PE format. These formats have a number of leading '.'s
+ on at least some symbols, so we remove all dots to avoid
+ confusing the demangler. */
+ p = name;
+ while (*p == '.')
+ ++p;
+
+ res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS);
+ if (res)
+ {
+ size_t dots = p - name;
+
+ /* Now put back any stripped dots. */
+ if (dots != 0)
+ {
+ size_t len = strlen (res) + 1;
+ char *add_dots = xmalloc (len + dots);
+
+ memcpy (add_dots, name, dots);
+ memcpy (add_dots + dots, res, len);
+ free (res);
+ res = add_dots;
+ }
+ return res;
+ }
+ return xstrdup (name);
+}
+
/* Format info message and print on stdout. */
/* (You would think this should be called just "info", but then you
OpenPOWER on IntegriCloud