public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Alan Modra <amodra@gmail.com>
Cc: Binutils <binutils@sourceware.org>, Nick Clifton <nickc@redhat.com>
Subject: Re: PR27128, nm -P portable output format regression
Date: Wed, 30 Dec 2020 06:10:34 -0800	[thread overview]
Message-ID: <CAMe9rOrSM0TDCVF=+qwbM4CiD9m4Fk6MWJZnYv0GB8tH843tNQ@mail.gmail.com> (raw)
In-Reply-To: <20201230115054.GF8873@bubble.grove.modra.org>

[-- Attachment #1: Type: text/plain, Size: 2420 bytes --]

On Wed, Dec 30, 2020 at 3:51 AM Alan Modra <amodra@gmail.com> 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.

[-- Attachment #2: 0001-Add-PR-binutils-27128-tests.patch --]
[-- Type: text/x-patch, Size: 5142 bytes --]

From a24349e0619481929c5346f3965191007f361cdf Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 30 Dec 2020 06:07:31 -0800
Subject: [PATCH] Add PR binutils/27128 tests

	PR binutils/27128
	* testsuite/ld-elf/pr27128.s: New file.
	* testsuite/ld-elf/pr27128.t: Likewise.
	* testsuite/ld-elf/pr27128a.d: Likewise.
	* testsuite/ld-elf/pr27128b.d: Likewise.
	* testsuite/ld-elf/pr27128c.d: Likewise.
	* testsuite/ld-elf/pr27128d.d: Likewise.
	* testsuite/ld-elf/pr27128e.d: Likewise.
---
 ld/testsuite/ld-elf/pr27128.s  | 13 +++++++++++++
 ld/testsuite/ld-elf/pr27128.t  |  6 ++++++
 ld/testsuite/ld-elf/pr27128a.d | 16 ++++++++++++++++
 ld/testsuite/ld-elf/pr27128b.d | 14 ++++++++++++++
 ld/testsuite/ld-elf/pr27128c.d | 16 ++++++++++++++++
 ld/testsuite/ld-elf/pr27128d.d | 14 ++++++++++++++
 ld/testsuite/ld-elf/pr27128e.d | 14 ++++++++++++++
 7 files changed, 93 insertions(+)
 create mode 100644 ld/testsuite/ld-elf/pr27128.s
 create mode 100644 ld/testsuite/ld-elf/pr27128.t
 create mode 100644 ld/testsuite/ld-elf/pr27128a.d
 create mode 100644 ld/testsuite/ld-elf/pr27128b.d
 create mode 100644 ld/testsuite/ld-elf/pr27128c.d
 create mode 100644 ld/testsuite/ld-elf/pr27128d.d
 create mode 100644 ld/testsuite/ld-elf/pr27128e.d

diff --git a/ld/testsuite/ld-elf/pr27128.s b/ld/testsuite/ld-elf/pr27128.s
new file mode 100644
index 0000000000..81b198115b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128.s
@@ -0,0 +1,13 @@
+	.text
+	.globl	foo
+	.type	foo,%function
+foo:
+	.byte 0
+	.size foo, .-foo
+	.symver foo,foo@@VERS_2.0,remove
+	.globl	_Zrm1XS_
+	.type	_Zrm1XS_,%function
+_Zrm1XS_:
+	.byte 0
+	.size _Zrm1XS_, .-_Zrm1XS_
+	.symver _Zrm1XS_,_Zrm1XS_@@VERS_2.0,remove
diff --git a/ld/testsuite/ld-elf/pr27128.t b/ld/testsuite/ld-elf/pr27128.t
new file mode 100644
index 0000000000..27669a505b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128.t
@@ -0,0 +1,6 @@
+VERS_2.0 {
+global:
+  foo; _Zrm1XS_;
+local:
+  *;
+};
diff --git a/ld/testsuite/ld-elf/pr27128a.d b/ld/testsuite/ld-elf/pr27128a.d
new file mode 100644
index 0000000000..a2c1702b3e
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128a.d
@@ -0,0 +1,16 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -n -P
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* ![check_shared_lib_support] 
+# h8300 doesn't support -shared, and hppa64 creates .foo
+
+#...
+VERS_2.0 A 0+ 
+#...
+foo@@VERS_2.0 T [0-9a-f]+ 1
+#...
+_Zrm1XS_@@VERS_2.0 T [0-9a-f]+ 1
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128b.d b/ld/testsuite/ld-elf/pr27128b.d
new file mode 100644
index 0000000000..593b99a0ad
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128b.d
@@ -0,0 +1,14 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -D --format=posix
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* ![check_shared_lib_support] 
+# h8300 doesn't support -shared, and hppa64 creates .foo
+
+#...
+VERS_2.0 A 0+ 
+_Zrm1XS_@@VERS_2.0 T [0-9a-f]+ 1
+foo@@VERS_2.0 T [0-9a-f]+ 1
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128c.d b/ld/testsuite/ld-elf/pr27128c.d
new file mode 100644
index 0000000000..9275f9e30f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128c.d
@@ -0,0 +1,16 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -n --format=sysv
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* ![check_shared_lib_support] 
+# h8300 doesn't support -shared, and hppa64 creates .foo
+
+#...
+VERS_2.0 +|0+| +A +| +|0+1|.*
+#...
+foo@@VERS_2.0 +|[0-9a-f]+| +T +|0+1|.*
+#...
+_Zrm1XS_@@VERS_2.0 +|[0-9a-f]+| +T +|0+1|.*
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128d.d b/ld/testsuite/ld-elf/pr27128d.d
new file mode 100644
index 0000000000..0189aec40c
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128d.d
@@ -0,0 +1,14 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -D --format=sysv
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* ![check_shared_lib_support] 
+# h8300 doesn't support -shared, and hppa64 creates .foo
+
+#...
+VERS_2.0 +|0+| +A +| +|0+1|.*
+_Zrm1XS_@@VERS_2.0 +|[0-9a-f]+| +T +|0+1|.*
+foo@@VERS_2.0 +|[0-9a-f]+| +T +|0+1|.*
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128e.d b/ld/testsuite/ld-elf/pr27128e.d
new file mode 100644
index 0000000000..7db34c073d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128e.d
@@ -0,0 +1,14 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: --demangle -D --format=posix
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* ![check_shared_lib_support] 
+# h8300 doesn't support -shared, and hppa64 creates .foo
+
+#...
+VERS_2.0 A 0+ 
+operator%\(X, X\)@@VERS_2.0 T [0-9a-f]+ 1
+foo@@VERS_2.0 T [0-9a-f]+ 1
+#pass
-- 
2.29.2


  reply	other threads:[~2020-12-30 14:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30 11:50 Alan Modra
2020-12-30 14:10 ` H.J. Lu [this message]
2020-12-31  8:41   ` Alan Modra
2020-12-31 18:02     ` Fangrui Song
2020-12-31 18:15       ` H.J. Lu
2021-03-01  4:19 Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOrSM0TDCVF=+qwbM4CiD9m4Fk6MWJZnYv0GB8tH843tNQ@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=nickc@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).