public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR27128, nm -P portable output format regression
@ 2021-03-01  4:19 Alan Modra
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2021-03-01  4:19 UTC (permalink / raw)
  To: binutils

Add nm --without-symbol-versions.

binutils/
	PR 27128
	* doc/binutils.texi: Add nm --with-symbol-versions and
	--without-symbol-versions documentation.
	* nm.c (with_symbol_versions): New variable.
	(enum long_option_values): Delete OPTION_WITH_SYMBOL_VERSIONS.
	(long_options): Make --with-symbol-versions entry twiddle the flag.
	Add --without-symbol-versions.
	(print_symname): Strip version when !with_symbol_versions.  Add
	dynamic version info under control of with_symbol_versions.
	(main): Remove OPTION_WITH_SYMBOL_VERSIONS case.
ld/
	* testsuite/ld-elf/pr25708.d: Add --with-symbol-versions to nm.
	* 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.

diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index b7740dfc8a..ee898331dd 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -808,7 +808,8 @@ nm [@option{-A}|@option{-o}|@option{--print-file-name}] [@option{-a}|@option{--d
    [@option{--plugin} @var{name}]
    [@option{--no-recurse-limit}|@option{--recurse-limit}]]
    [@option{--size-sort}] [@option{--special-syms}]
-   [@option{--synthetic}] [@option{--target=}@var{bfdname}]
+   [@option{--synthetic}] [@option{--with-symbol-versions}]
+   [@option{--without-symbol-versions}] [@option{--target=}@var{bfdname}]
    [@var{objfile}@dots{}]
 @c man end
 @end smallexample
@@ -1169,6 +1170,16 @@ Include synthetic symbols in the output.  These are special symbols
 created by the linker for various purposes.  They are not shown by
 default since they are not part of the binary's original source code.
 
+@item --with-symbol-versions
+@item --without-symbol-versions
+Enables or disables the display of symbol version information.  The
+version string is displayed as a suffix to the symbol name, preceded
+by an @@ character.  For example @samp{foo@@VER_1}.  If the version is
+the default version to be used when resolving unversioned references
+to the symbol then it is displayed as a suffix preceded by two @@
+characters.  For example @samp{foo@@@@VER_2}.  By default, symbol
+version information is displayed.
+
 @item --target=@var{bfdname}
 @cindex object code format
 Specify an object code format other than your system's default format.
diff --git a/binutils/nm.c b/binutils/nm.c
index a51d2eff75..2637756c64 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -161,6 +161,7 @@ static int show_version = 0;	/* Show the version number.  */
 static int show_synthetic = 0;	/* Display synthesized symbols too.  */
 static int line_numbers = 0;	/* Print line numbers for symbols.  */
 static int allow_special_symbols = 0;  /* Allow special symbols.  */
+static int with_symbol_versions = -1; /* Output symbol version information.  */
 static int quiet = 0;		/* Suppress "no symbols" diagnostic.  */
 
 /* The characters to use for global and local ifunc symbols.  */
@@ -201,7 +202,6 @@ enum long_option_values
   OPTION_RECURSE_LIMIT,
   OPTION_NO_RECURSE_LIMIT,
   OPTION_IFUNC_CHARS,
-  OPTION_WITH_SYMBOL_VERSIONS,
   OPTION_QUIET
 };
 
@@ -238,8 +238,8 @@ static struct option long_options[] =
   {"defined-only", no_argument, &defined_only, 1},
   {"undefined-only", no_argument, &undefined_only, 1},
   {"version", no_argument, &show_version, 1},
-  {"with-symbol-versions", no_argument, NULL,
-   OPTION_WITH_SYMBOL_VERSIONS},
+  {"with-symbol-versions", no_argument, &with_symbol_versions, 1},
+  {"without-symbol-versions", no_argument, &with_symbol_versions, 0},
   {0, no_argument, 0, 0}
 };
 \f
@@ -412,9 +412,17 @@ print_symname (const char *form, struct extended_symbol_info *info,
 	       const char *name, bfd *abfd)
 {
   char *alloc = NULL;
+  char *atver = NULL;
 
   if (name == NULL)
     name = info->sinfo->name;
+  if (!with_symbol_versions
+      && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+    {
+      atver = strchr (name, '@');
+      if (atver)
+	*atver = 0;
+    }
   if (do_demangle && *name)
     {
       alloc = bfd_demangle (abfd, name, demangle_flags);
@@ -422,7 +430,7 @@ print_symname (const char *form, struct extended_symbol_info *info,
 	name = alloc;
     }
 
-  if (info != NULL && info->elfinfo)
+  if (info != NULL && info->elfinfo && with_symbol_versions)
     {
       const char *version_string;
       bfd_boolean hidden;
@@ -441,6 +449,8 @@ print_symname (const char *form, struct extended_symbol_info *info,
 	}
     }
   printf (form, name);
+  if (atver)
+    *atver = '@';
   free (alloc);
 }
 
@@ -1780,9 +1790,6 @@ main (int argc, char **argv)
 	case OPTION_NO_RECURSE_LIMIT:
 	  demangle_flags |= DMGL_NO_RECURSE_LIMIT;
 	  break;
-	case OPTION_WITH_SYMBOL_VERSIONS:
-	  /* Ignored for backward compatibility.  */
-	  break;
 	case OPTION_QUIET:
 	  quiet = 1;
 	  break;
diff --git a/ld/testsuite/ld-elf/pr25708.d b/ld/testsuite/ld-elf/pr25708.d
index 30cae8cd51..60b8e31807 100644
--- a/ld/testsuite/ld-elf/pr25708.d
+++ b/ld/testsuite/ld-elf/pr25708.d
@@ -1,6 +1,6 @@
 #source: pr13195.s
 #ld: -shared -version-script pr13195.t
-#nm: -D
+#nm: -D --with-symbol-versions
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
 #xfail: hppa64-*-* ![check_shared_lib_support] 
 # h8300 doesn't support -shared, and hppa64 creates .foo
diff --git a/ld/testsuite/ld-elf/pr27128a.d b/ld/testsuite/ld-elf/pr27128a.d
index 9ce8eaa546..645d0ccf01 100644
--- a/ld/testsuite/ld-elf/pr27128a.d
+++ b/ld/testsuite/ld-elf/pr27128a.d
@@ -1,6 +1,6 @@
 #source: pr27128.s
 #ld: -shared -version-script pr27128.t
-#nm: -n -P
+#nm: -n -P --with-symbol-versions
 #target: [check_shared_lib_support]
 #notarget: [is_underscore_target]
 # _Zrm1XS_ doesn't have an extra underscore.
diff --git a/ld/testsuite/ld-elf/pr27128b.d b/ld/testsuite/ld-elf/pr27128b.d
index 934f8330d7..0721117edf 100644
--- a/ld/testsuite/ld-elf/pr27128b.d
+++ b/ld/testsuite/ld-elf/pr27128b.d
@@ -1,6 +1,6 @@
 #source: pr27128.s
 #ld: -shared -version-script pr27128.t
-#nm: -n -D --format=posix
+#nm: -n -D --format=posix --with-symbol-versions
 #target: [check_shared_lib_support]
 #notarget: [is_underscore_target]
 # _Zrm1XS_ doesn't have an extra underscore.
diff --git a/ld/testsuite/ld-elf/pr27128c.d b/ld/testsuite/ld-elf/pr27128c.d
index f80c57b64c..d9cee44a71 100644
--- a/ld/testsuite/ld-elf/pr27128c.d
+++ b/ld/testsuite/ld-elf/pr27128c.d
@@ -1,6 +1,6 @@
 #source: pr27128.s
 #ld: -shared -version-script pr27128.t
-#nm: -n --format=sysv
+#nm: -n --format=sysv --with-symbol-versions
 #target: [check_shared_lib_support]
 #notarget: [is_underscore_target]
 # _Zrm1XS_ doesn't have an extra underscore.
diff --git a/ld/testsuite/ld-elf/pr27128d.d b/ld/testsuite/ld-elf/pr27128d.d
index ba628d22de..45d1972948 100644
--- a/ld/testsuite/ld-elf/pr27128d.d
+++ b/ld/testsuite/ld-elf/pr27128d.d
@@ -1,6 +1,6 @@
 #source: pr27128.s
 #ld: -shared -version-script pr27128.t
-#nm: -n -D --format=sysv
+#nm: -n -D --format=sysv --with-symbol-versions
 #target: [check_shared_lib_support]
 #notarget: [is_underscore_target]
 # _Zrm1XS_ doesn't have an extra underscore.
diff --git a/ld/testsuite/ld-elf/pr27128e.d b/ld/testsuite/ld-elf/pr27128e.d
index b8b1657fe7..4263a059b5 100644
--- a/ld/testsuite/ld-elf/pr27128e.d
+++ b/ld/testsuite/ld-elf/pr27128e.d
@@ -1,6 +1,6 @@
 #source: pr27128.s
 #ld: -shared -version-script pr27128.t
-#nm: -n --demangle -D --format=posix
+#nm: -n --demangle -D --format=posix --with-symbol-versions
 #target: [check_shared_lib_support]
 #notarget: [is_underscore_target]
 # _Zrm1XS_ doesn't have an extra underscore.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR27128, nm -P portable output format regression
  2020-12-31 18:02     ` Fangrui Song
@ 2020-12-31 18:15       ` H.J. Lu
  0 siblings, 0 replies; 6+ messages in thread
From: H.J. Lu @ 2020-12-31 18:15 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Alan Modra, Binutils

On Thu, Dec 31, 2020 at 10:02 AM Fangrui Song <i@maskray.me> wrote:
>
> On 2020-12-31, Alan Modra via Binutils wrote:
> >On Wed, Dec 30, 2020 at 06:10:34AM -0800, H.J. Lu wrote:
> >> I think they are useful.   Here is a patch to add tests.
> >
> >Fails on mips due to mips overriding .byte and then foo and _Zrm1XS_
> >having the same address.  Which is quite weird.  This results in -n
> >sort not ordering the symbols as expected.  I'm modifying the tests to
> >use .space 16 instead.
> >
> >Also, this
> >> +VERS_2.0 +|0+| +A +| +|0+1|.*
> >matches anything.  I'm adding backslash escapes to match literal '|'
> >and '.', plus correcting the sysv expected lines.
> >
> >Committed.
> >
> >binutils/
> >       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.
> >ld/
> >       PR 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.
>
> Oh, I did not know "gas: Extend .symver directive" (`.symver ... , remove`) has been committed.
>
> `remove` will pretty much be always preferred
> (https://maskray.me/blog/2020-11-26-all-about-symbol-versioning#Assembler-behavior)

It has been checked into binutils 2.35:

ommit 6914be53bd662eefd979d0c82d2e20e108c4ee66
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Apr 21 05:33:04 2020 -0700

    gas: Extend .symver directive

    Extend .symver directive to update visibility of the original symbol and
    assign one original symbol to different versioned symbols:

      .symver foo, foo@VERS_1, local    # Change foo to a local symbol.
      .symver foo, foo@VERS_2, hidden   # Change foo to a hidden symbol.
      .symver foo, foo@@VERS_3, remove  # Remove foo from symbol table.
      .symver foo, bar@V1               # Assign foo to bar@V1 and baz@V2.
      .symver foo, baz@V2

I don't think we need to make any changes now.

> However, it can be confusing. Instead of adding an optional argument to .symver, what about adding a new directive?
>
>
>
> Note that copying attributes (.symver) isn't traditional behavior: for .set foo, bar, the visibility/binding bits of foo and bar are separate.
> The new directive can just do renaming.



-- 
H.J.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR27128, nm -P portable output format regression
  2020-12-31  8:41   ` Alan Modra
@ 2020-12-31 18:02     ` Fangrui Song
  2020-12-31 18:15       ` H.J. Lu
  0 siblings, 1 reply; 6+ messages in thread
From: Fangrui Song @ 2020-12-31 18:02 UTC (permalink / raw)
  To: Alan Modra; +Cc: H.J. Lu, Binutils

On 2020-12-31, Alan Modra via Binutils wrote:
>On Wed, Dec 30, 2020 at 06:10:34AM -0800, H.J. Lu wrote:
>> I think they are useful.   Here is a patch to add tests.
>
>Fails on mips due to mips overriding .byte and then foo and _Zrm1XS_
>having the same address.  Which is quite weird.  This results in -n
>sort not ordering the symbols as expected.  I'm modifying the tests to
>use .space 16 instead.
>
>Also, this
>> +VERS_2.0 +|0+| +A +| +|0+1|.*
>matches anything.  I'm adding backslash escapes to match literal '|'
>and '.', plus correcting the sysv expected lines.
>
>Committed.
>
>binutils/
>	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.
>ld/
>	PR 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.

Oh, I did not know "gas: Extend .symver directive" (`.symver ... , remove`) has been committed.

`remove` will pretty much be always preferred
(https://maskray.me/blog/2020-11-26-all-about-symbol-versioning#Assembler-behavior)

However, it can be confusing. Instead of adding an optional argument to .symver, what about adding a new directive?



Note that copying attributes (.symver) isn't traditional behavior: for .set foo, bar, the visibility/binding bits of foo and bar are separate.
The new directive can just do renaming.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR27128, nm -P portable output format regression
  2020-12-30 14:10 ` H.J. Lu
@ 2020-12-31  8:41   ` Alan Modra
  2020-12-31 18:02     ` Fangrui Song
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2020-12-31  8:41 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils, Nick Clifton

On Wed, Dec 30, 2020 at 06:10:34AM -0800, H.J. Lu wrote:
> I think they are useful.   Here is a patch to add tests.

Fails on mips due to mips overriding .byte and then foo and _Zrm1XS_
having the same address.  Which is quite weird.  This results in -n
sort not ordering the symbols as expected.  I'm modifying the tests to
use .space 16 instead.

Also, this
> +VERS_2.0 +|0+| +A +| +|0+1|.*
matches anything.  I'm adding backslash escapes to match literal '|'
and '.', plus correcting the sysv expected lines.

Committed.

binutils/
	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.
ld/
	PR 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.

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
diff --git a/ld/testsuite/ld-elf/pr27128.s b/ld/testsuite/ld-elf/pr27128.s
new file mode 100644
index 0000000000..7af5be183b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128.s
@@ -0,0 +1,13 @@
+	.text
+	.globl	foo
+	.type	foo,%function
+foo:
+	.space 16
+	.size foo, .-foo
+	.symver foo,foo@@VERS_2.0,remove
+	.globl	_Zrm1XS_
+	.type	_Zrm1XS_,%function
+_Zrm1XS_:
+	.space 16
+	.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..9ce8eaa546
--- /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: [check_shared_lib_support]
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* tic6x-*-*
+# hppa64 uses dot-symbols, tic6x DYN lacks dynamic sections for this testcase
+
+#...
+VERS_2\.0 A 0+ 
+#...
+foo@@VERS_2\.0 T [0-9a-f]+ 10
+#...
+_Zrm1XS_@@VERS_2\.0 T [0-9a-f]+ 10
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128b.d b/ld/testsuite/ld-elf/pr27128b.d
new file mode 100644
index 0000000000..934f8330d7
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128b.d
@@ -0,0 +1,16 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -n -D --format=posix
+#target: [check_shared_lib_support]
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* tic6x-*-*
+# hppa64 uses dot-symbols, tic6x DYN lacks dynamic sections for this testcase
+
+#...
+VERS_2\.0 A 0+ 
+#...
+foo@@VERS_2\.0 T [0-9a-f]+ 10
+#...
+_Zrm1XS_@@VERS_2\.0 T [0-9a-f]+ 10
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128c.d b/ld/testsuite/ld-elf/pr27128c.d
new file mode 100644
index 0000000000..f80c57b64c
--- /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: [check_shared_lib_support]
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* tic6x-*-*
+# hppa64 uses dot-symbols, tic6x DYN lacks dynamic sections for this testcase
+
+#...
+VERS_2\.0 +\|0+\| +A +\| +OBJECT\| +\| +\|\*ABS\*
+#...
+foo@@VERS_2\.0 +\|[0-9a-f]+\| +T +\| +FUNC\|0+10\| +\|\.text
+#...
+_Zrm1XS_@@VERS_2\.0 +\|[0-9a-f]+\| +T +\| +FUNC\|0+10\| +\|\.text
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128d.d b/ld/testsuite/ld-elf/pr27128d.d
new file mode 100644
index 0000000000..ba628d22de
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128d.d
@@ -0,0 +1,16 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -n -D --format=sysv
+#target: [check_shared_lib_support]
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* tic6x-*-*
+# hppa64 uses dot-symbols, tic6x DYN lacks dynamic sections for this testcase
+
+#...
+VERS_2\.0 +\|0+\| +A +\| +OBJECT\| +\| +\|\*ABS\*
+#...
+foo@@VERS_2\.0 +\|[0-9a-f]+\| +T +\| +FUNC\|0+10\| +\|\.text
+#...
+_Zrm1XS_@@VERS_2\.0 +\|[0-9a-f]+\| +T +\| +FUNC\|0+10\| +\|\.text
+#pass
diff --git a/ld/testsuite/ld-elf/pr27128e.d b/ld/testsuite/ld-elf/pr27128e.d
new file mode 100644
index 0000000000..b8b1657fe7
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr27128e.d
@@ -0,0 +1,16 @@
+#source: pr27128.s
+#ld: -shared -version-script pr27128.t
+#nm: -n --demangle -D --format=posix
+#target: [check_shared_lib_support]
+#notarget: [is_underscore_target]
+# _Zrm1XS_ doesn't have an extra underscore.
+#xfail: hppa64-*-* tic6x-*-*
+# hppa64 uses dot-symbols, tic6x DYN lacks dynamic sections for this testcase
+
+#...
+VERS_2\.0 A 0+ 
+#...
+foo@@VERS_2\.0 T [0-9a-f]+ 10
+#...
+operator%\(X, X\)@@VERS_2\.0 T [0-9a-f]+ 10
+#pass


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR27128, nm -P portable output format regression
  2020-12-30 11:50 Alan Modra
@ 2020-12-30 14:10 ` H.J. Lu
  2020-12-31  8:41   ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: H.J. Lu @ 2020-12-30 14:10 UTC (permalink / raw)
  To: Alan Modra; +Cc: Binutils, Nick Clifton

[-- 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* PR27128, nm -P portable output format regression
@ 2020-12-30 11:50 Alan Modra
  2020-12-30 14:10 ` H.J. Lu
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2020-12-30 11:50 UTC (permalink / raw)
  To: binutils

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.

	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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-01  4:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01  4:19 PR27128, nm -P portable output format regression Alan Modra
  -- strict thread matches above, loose matches on Subject: below --
2020-12-30 11:50 Alan Modra
2020-12-30 14:10 ` H.J. Lu
2020-12-31  8:41   ` Alan Modra
2020-12-31 18:02     ` Fangrui Song
2020-12-31 18:15       ` H.J. Lu

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).