On Wed, Dec 30, 2020 at 3:51 AM Alan Modra wrote: > > https://sourceware.org/pipermail/binutils/2020-March/000233.html > appended a symbol version string for nm -D, but got it wrong for > --format=posix and --format=sysv. This patch fixes that problem, and > also prints versions for demangled names. > > Should we print versions when demangling? I'm inclined to think they > are useful, but am open to argument. I think they are useful. Here is a patch to add tests. Thanks. > PR 27128 > * nm.c (print_symname): Append version string to symbol name > before printing the lot under control of "form". Append version > to demangled names too. > > diff --git a/binutils/nm.c b/binutils/nm.c > index 2946bd6904..e77828eeff 100644 > --- a/binutils/nm.c > +++ b/binutils/nm.c > @@ -407,21 +407,17 @@ static void > print_symname (const char *form, struct extended_symbol_info *info, > const char *name, bfd *abfd) > { > + char *alloc = NULL; > + > if (name == NULL) > name = info->sinfo->name; > if (do_demangle && *name) > { > - char *res = bfd_demangle (abfd, name, demangle_flags); > - > - if (res != NULL) > - { > - printf (form, res); > - free (res); > - return; > - } > + alloc = bfd_demangle (abfd, name, demangle_flags); > + if (alloc != NULL) > + name = alloc; > } > > - printf (form, name); > if (info != NULL && info->elfinfo) > { > const char *version_string; > @@ -431,11 +427,17 @@ print_symname (const char *form, struct extended_symbol_info *info, > = bfd_get_symbol_version_string (abfd, &info->elfinfo->symbol, > FALSE, &hidden); > if (version_string && version_string[0]) > - printf ("%s%s", > - (hidden || bfd_is_und_section (info->elfinfo->symbol.section) > - ? "@" : "@@"), > - version_string); > + { > + const char *at = "@@"; > + if (hidden || bfd_is_und_section (info->elfinfo->symbol.section)) > + at = "@"; > + alloc = reconcat (alloc, name, at, version_string, NULL); > + if (alloc != NULL) > + name = alloc; > + } > } > + printf (form, name); > + free (alloc); > } > > static void > > -- > Alan Modra > Australia Development Lab, IBM -- H.J.