public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] nm: Ignore --with-symbol-versions for backward compatibility
@ 2020-07-27 13:44 H.J. Lu
  2020-07-30 12:04 ` H.J. Lu
  2020-08-06 11:33 ` PING " H.J. Lu
  0 siblings, 2 replies; 8+ messages in thread
From: H.J. Lu @ 2020-07-27 13:44 UTC (permalink / raw)
  To: binutils

Since

commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Mar 24 04:23:11 2020 -0700

    bfd: Display symbol version for nm -D

always displays symbol version for nm, ignore --with-symbol-versions for
backward compatibility.

binutils/

	PR binutils/26302
	* nm.c (with_symbol_versions): Removed.
	(long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
	(long_options): Update --with-symbol-versions entry.
	(print_symbol): Remove the with_symbol_versions check.
	(main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
	compatibility.
	* doc/binutils.texi: Update --with-symbol-versions documentation.

ld/

	PR binutils/26302
	* testsuite/ld-elf/pr26302.nd: New file.
	* testsuite/ld-elf/pr26302.ver: Likewise.
	* testsuite/ld-elf/pr26302a.c: Likewise.
	* testsuite/ld-elf/pr26302b.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
---
 binutils/doc/binutils.texi      |  3 ++-
 binutils/nm.c                   | 26 +++++++-------------------
 ld/testsuite/ld-elf/pr26302.nd  |  3 +++
 ld/testsuite/ld-elf/pr26302.ver |  5 +++++
 ld/testsuite/ld-elf/pr26302a.c  |  4 ++++
 ld/testsuite/ld-elf/pr26302b.c  |  7 +++++++
 ld/testsuite/ld-elf/shared.exp  | 18 ++++++++++++++++++
 7 files changed, 46 insertions(+), 20 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pr26302.nd
 create mode 100644 ld/testsuite/ld-elf/pr26302.ver
 create mode 100644 ld/testsuite/ld-elf/pr26302a.c
 create mode 100644 ld/testsuite/ld-elf/pr26302b.c

diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 4a11bf1f1a..d4a3bd69ee 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -1136,7 +1136,8 @@ 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}.
+characters.  For example @samp{foo@@@@VER_2}.  Note that this option
+is always enabled.
 
 @item --target=@var{bfdname}
 @cindex object code format
diff --git a/binutils/nm.c b/binutils/nm.c
index 1b5122d56a..69e697ae92 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -161,7 +161,6 @@ 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 = 0; /* Include symbol version information in the output.  */
 
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
 
@@ -192,7 +191,8 @@ enum long_option_values
   OPTION_PLUGIN,
   OPTION_SIZE_SORT,
   OPTION_RECURSE_LIMIT,
-  OPTION_NO_RECURSE_LIMIT
+  OPTION_NO_RECURSE_LIMIT,
+  OPTION_WITH_SYMBOL_VERSIONS
 };
 
 static struct option long_options[] =
@@ -226,7 +226,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, &with_symbol_versions, 1},
+  {"with-symbol-versions", no_argument, NULL,
+   OPTION_WITH_SYMBOL_VERSIONS},
   {0, no_argument, 0, 0}
 };
 \f
@@ -901,22 +902,6 @@ print_symbol (bfd *        abfd,
 
   format->print_symbol_info (&info, abfd);
 
-  if (with_symbol_versions)
-    {
-      const char *  version_string = NULL;
-      bfd_boolean   hidden = FALSE;
-
-      if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
-	version_string = bfd_get_symbol_version_string (abfd, sym,
-							TRUE, &hidden);
-
-      if (bfd_is_und_section (bfd_asymbol_section (sym)))
-	hidden = TRUE;
-
-      if (version_string && *version_string != '\0')
-	printf (hidden ? "@%s" : "@@%s", version_string);
-    }
-
   if (line_numbers)
     {
       static asymbol **syms;
@@ -1761,6 +1746,9 @@ 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 'D':
 	  dynamic = 1;
 	  break;
diff --git a/ld/testsuite/ld-elf/pr26302.nd b/ld/testsuite/ld-elf/pr26302.nd
new file mode 100644
index 0000000000..1f2fbdf9a3
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302.nd
@@ -0,0 +1,3 @@
+#...
+ +U foo@@FOO
+#pass
diff --git a/ld/testsuite/ld-elf/pr26302.ver b/ld/testsuite/ld-elf/pr26302.ver
new file mode 100644
index 0000000000..f2c03ac7a1
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302.ver
@@ -0,0 +1,5 @@
+FOO
+{
+global:
+  foo;
+};
diff --git a/ld/testsuite/ld-elf/pr26302a.c b/ld/testsuite/ld-elf/pr26302a.c
new file mode 100644
index 0000000000..cd0130cacd
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302a.c
@@ -0,0 +1,4 @@
+void
+foo (void)
+{
+}
diff --git a/ld/testsuite/ld-elf/pr26302b.c b/ld/testsuite/ld-elf/pr26302b.c
new file mode 100644
index 0000000000..eae278df96
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302b.c
@@ -0,0 +1,7 @@
+extern void foo (void);
+
+void
+bar (void)
+{
+  foo ();
+}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index e9e9012058..014937175f 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -843,6 +843,24 @@ run_cc_link_tests [list \
 	{{readelf {--dyn-syms --wide} pr26094-1b.rd}} \
 	"pr26094-1" \
     ] \
+    [list \
+	"Build pr26302a.so" \
+	"-shared -Wl,--version-script=pr26302.ver" \
+	"-fPIC" \
+	{pr26302a.c} \
+	{} \
+	"pr26302a.so"
+    ] \
+    [list \
+	"Build pr26302b.so" \
+	"-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
+	"-fPIC" \
+	{pr26302b.c} \
+	{{nm {-u} pr26302.nd} \
+	 {nm {-u -D} pr26302.nd} \
+	 {nm {-u -D --with-symbol-versions} pr26302.nd}} \
+	"pr26302b.so" \
+    ] \
 ]
 
 run_ld_link_tests [list \
-- 
2.26.2


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

* Re: [PATCH] nm: Ignore --with-symbol-versions for backward compatibility
  2020-07-27 13:44 [PATCH] nm: Ignore --with-symbol-versions for backward compatibility H.J. Lu
@ 2020-07-30 12:04 ` H.J. Lu
  2020-08-06 11:33 ` PING " H.J. Lu
  1 sibling, 0 replies; 8+ messages in thread
From: H.J. Lu @ 2020-07-30 12:04 UTC (permalink / raw)
  To: Binutils, Nick Clifton, Alan Modra

On Mon, Jul 27, 2020 at 6:44 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Since
>
> commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Tue Mar 24 04:23:11 2020 -0700
>
>     bfd: Display symbol version for nm -D
>
> always displays symbol version for nm, ignore --with-symbol-versions for
> backward compatibility.
>
> binutils/
>
>         PR binutils/26302
>         * nm.c (with_symbol_versions): Removed.
>         (long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
>         (long_options): Update --with-symbol-versions entry.
>         (print_symbol): Remove the with_symbol_versions check.
>         (main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
>         compatibility.
>         * doc/binutils.texi: Update --with-symbol-versions documentation.
>
> ld/
>
>         PR binutils/26302
>         * testsuite/ld-elf/pr26302.nd: New file.
>         * testsuite/ld-elf/pr26302.ver: Likewise.
>         * testsuite/ld-elf/pr26302a.c: Likewise.
>         * testsuite/ld-elf/pr26302b.c: Likewise.
>         * testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
> ---
>  binutils/doc/binutils.texi      |  3 ++-
>  binutils/nm.c                   | 26 +++++++-------------------
>  ld/testsuite/ld-elf/pr26302.nd  |  3 +++
>  ld/testsuite/ld-elf/pr26302.ver |  5 +++++
>  ld/testsuite/ld-elf/pr26302a.c  |  4 ++++
>  ld/testsuite/ld-elf/pr26302b.c  |  7 +++++++
>  ld/testsuite/ld-elf/shared.exp  | 18 ++++++++++++++++++
>  7 files changed, 46 insertions(+), 20 deletions(-)
>  create mode 100644 ld/testsuite/ld-elf/pr26302.nd
>  create mode 100644 ld/testsuite/ld-elf/pr26302.ver
>  create mode 100644 ld/testsuite/ld-elf/pr26302a.c
>  create mode 100644 ld/testsuite/ld-elf/pr26302b.c
>
> diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
> index 4a11bf1f1a..d4a3bd69ee 100644
> --- a/binutils/doc/binutils.texi
> +++ b/binutils/doc/binutils.texi
> @@ -1136,7 +1136,8 @@ 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}.
> +characters.  For example @samp{foo@@@@VER_2}.  Note that this option
> +is always enabled.
>
>  @item --target=@var{bfdname}
>  @cindex object code format
> diff --git a/binutils/nm.c b/binutils/nm.c
> index 1b5122d56a..69e697ae92 100644
> --- a/binutils/nm.c
> +++ b/binutils/nm.c
> @@ -161,7 +161,6 @@ 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 = 0; /* Include symbol version information in the output.  */
>
>  static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
>
> @@ -192,7 +191,8 @@ enum long_option_values
>    OPTION_PLUGIN,
>    OPTION_SIZE_SORT,
>    OPTION_RECURSE_LIMIT,
> -  OPTION_NO_RECURSE_LIMIT
> +  OPTION_NO_RECURSE_LIMIT,
> +  OPTION_WITH_SYMBOL_VERSIONS
>  };
>
>  static struct option long_options[] =
> @@ -226,7 +226,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, &with_symbol_versions, 1},
> +  {"with-symbol-versions", no_argument, NULL,
> +   OPTION_WITH_SYMBOL_VERSIONS},
>    {0, no_argument, 0, 0}
>  };
>
> @@ -901,22 +902,6 @@ print_symbol (bfd *        abfd,
>
>    format->print_symbol_info (&info, abfd);
>
> -  if (with_symbol_versions)
> -    {
> -      const char *  version_string = NULL;
> -      bfd_boolean   hidden = FALSE;
> -
> -      if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
> -       version_string = bfd_get_symbol_version_string (abfd, sym,
> -                                                       TRUE, &hidden);
> -
> -      if (bfd_is_und_section (bfd_asymbol_section (sym)))
> -       hidden = TRUE;
> -
> -      if (version_string && *version_string != '\0')
> -       printf (hidden ? "@%s" : "@@%s", version_string);
> -    }
> -
>    if (line_numbers)
>      {
>        static asymbol **syms;
> @@ -1761,6 +1746,9 @@ 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 'D':
>           dynamic = 1;
>           break;
> diff --git a/ld/testsuite/ld-elf/pr26302.nd b/ld/testsuite/ld-elf/pr26302.nd
> new file mode 100644
> index 0000000000..1f2fbdf9a3
> --- /dev/null
> +++ b/ld/testsuite/ld-elf/pr26302.nd
> @@ -0,0 +1,3 @@
> +#...
> + +U foo@@FOO
> +#pass
> diff --git a/ld/testsuite/ld-elf/pr26302.ver b/ld/testsuite/ld-elf/pr26302.ver
> new file mode 100644
> index 0000000000..f2c03ac7a1
> --- /dev/null
> +++ b/ld/testsuite/ld-elf/pr26302.ver
> @@ -0,0 +1,5 @@
> +FOO
> +{
> +global:
> +  foo;
> +};
> diff --git a/ld/testsuite/ld-elf/pr26302a.c b/ld/testsuite/ld-elf/pr26302a.c
> new file mode 100644
> index 0000000000..cd0130cacd
> --- /dev/null
> +++ b/ld/testsuite/ld-elf/pr26302a.c
> @@ -0,0 +1,4 @@
> +void
> +foo (void)
> +{
> +}
> diff --git a/ld/testsuite/ld-elf/pr26302b.c b/ld/testsuite/ld-elf/pr26302b.c
> new file mode 100644
> index 0000000000..eae278df96
> --- /dev/null
> +++ b/ld/testsuite/ld-elf/pr26302b.c
> @@ -0,0 +1,7 @@
> +extern void foo (void);
> +
> +void
> +bar (void)
> +{
> +  foo ();
> +}
> diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
> index e9e9012058..014937175f 100644
> --- a/ld/testsuite/ld-elf/shared.exp
> +++ b/ld/testsuite/ld-elf/shared.exp
> @@ -843,6 +843,24 @@ run_cc_link_tests [list \
>         {{readelf {--dyn-syms --wide} pr26094-1b.rd}} \
>         "pr26094-1" \
>      ] \
> +    [list \
> +       "Build pr26302a.so" \
> +       "-shared -Wl,--version-script=pr26302.ver" \
> +       "-fPIC" \
> +       {pr26302a.c} \
> +       {} \
> +       "pr26302a.so"
> +    ] \
> +    [list \
> +       "Build pr26302b.so" \
> +       "-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
> +       "-fPIC" \
> +       {pr26302b.c} \
> +       {{nm {-u} pr26302.nd} \
> +        {nm {-u -D} pr26302.nd} \
> +        {nm {-u -D --with-symbol-versions} pr26302.nd}} \
> +       "pr26302b.so" \
> +    ] \
>  ]
>
>  run_ld_link_tests [list \
> --
> 2.26.2
>

Hi Nick, Alan,

Can you take a look at this?

Thanks.


--
H.J.

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

* PING [PATCH] nm: Ignore --with-symbol-versions for backward compatibility
  2020-07-27 13:44 [PATCH] nm: Ignore --with-symbol-versions for backward compatibility H.J. Lu
  2020-07-30 12:04 ` H.J. Lu
@ 2020-08-06 11:33 ` H.J. Lu
  2020-08-07 14:55   ` [PATCH] nm: Remove --with-symbol-versions H.J. Lu
  1 sibling, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2020-08-06 11:33 UTC (permalink / raw)
  To: Binutils

On Mon, Jul 27, 2020 at 6:44 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Since
>
> commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Tue Mar 24 04:23:11 2020 -0700
>
>     bfd: Display symbol version for nm -D
>
> always displays symbol version for nm, ignore --with-symbol-versions for
> backward compatibility.
>
> binutils/
>
>         PR binutils/26302
>         * nm.c (with_symbol_versions): Removed.
>         (long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
>         (long_options): Update --with-symbol-versions entry.
>         (print_symbol): Remove the with_symbol_versions check.
>         (main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
>         compatibility.
>         * doc/binutils.texi: Update --with-symbol-versions documentation.
>
> ld/
>
>         PR binutils/26302
>         * testsuite/ld-elf/pr26302.nd: New file.
>         * testsuite/ld-elf/pr26302.ver: Likewise.
>         * testsuite/ld-elf/pr26302a.c: Likewise.
>         * testsuite/ld-elf/pr26302b.c: Likewise.
>         * testsuite/ld-elf/shared.exp: Run binutils/26302 tests.

https://sourceware.org/pipermail/binutils/2020-July/112556.html

-- 
H.J.

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

* [PATCH] nm: Remove --with-symbol-versions
  2020-08-06 11:33 ` PING " H.J. Lu
@ 2020-08-07 14:55   ` H.J. Lu
  2020-08-13  2:42     ` Fangrui Song
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2020-08-07 14:55 UTC (permalink / raw)
  To: Alan Modra, Nick Clifton; +Cc: Binutils

On Thu, Aug 06, 2020 at 04:33:27AM -0700, H.J. Lu wrote:
> On Mon, Jul 27, 2020 at 6:44 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > Since
> >
> > commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
> > Author: H.J. Lu <hjl.tools@gmail.com>
> > Date:   Tue Mar 24 04:23:11 2020 -0700
> >
> >     bfd: Display symbol version for nm -D
> >
> > always displays symbol version for nm, ignore --with-symbol-versions for
> > backward compatibility.
> >
> > binutils/
> >
> >         PR binutils/26302
> >         * nm.c (with_symbol_versions): Removed.
> >         (long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
> >         (long_options): Update --with-symbol-versions entry.
> >         (print_symbol): Remove the with_symbol_versions check.
> >         (main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
> >         compatibility.
> >         * doc/binutils.texi: Update --with-symbol-versions documentation.
> >
> > ld/
> >
> >         PR binutils/26302
> >         * testsuite/ld-elf/pr26302.nd: New file.
> >         * testsuite/ld-elf/pr26302.ver: Likewise.
> >         * testsuite/ld-elf/pr26302a.c: Likewise.
> >         * testsuite/ld-elf/pr26302b.c: Likewise.
> >         * testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
> 
> https://sourceware.org/pipermail/binutils/2020-July/112556.html
> 
> -- 
> H.J.

I am checking in this patch next Monday if there are no objections.


---
Since

commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Mar 24 04:23:11 2020 -0700

    bfd: Display symbol version for nm -D

always displays symbol version for nm, remove --with-symbol-versions and
silently accept it for backward compatibility.

binutils/

	PR binutils/26302
	* nm.c (with_symbol_versions): Removed.
	(long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
	(long_options): Update --with-symbol-versions entry.
	(print_symbol): Remove the with_symbol_versions check.
	(main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
	compatibility.
	* doc/binutils.texi: Remove --with-symbol-versions.

ld/

	PR binutils/26302
	* testsuite/ld-elf/pr26302.nd: New file.
	* testsuite/ld-elf/pr26302.ver: Likewise.
	* testsuite/ld-elf/pr26302a.c: Likewise.
	* testsuite/ld-elf/pr26302b.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
---
 binutils/doc/binutils.texi      | 10 +---------
 binutils/nm.c                   | 26 +++++++-------------------
 ld/testsuite/ld-elf/pr26302.nd  |  3 +++
 ld/testsuite/ld-elf/pr26302.ver |  5 +++++
 ld/testsuite/ld-elf/pr26302a.c  |  4 ++++
 ld/testsuite/ld-elf/pr26302b.c  |  7 +++++++
 ld/testsuite/ld-elf/shared.exp  | 18 ++++++++++++++++++
 7 files changed, 45 insertions(+), 28 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pr26302.nd
 create mode 100644 ld/testsuite/ld-elf/pr26302.ver
 create mode 100644 ld/testsuite/ld-elf/pr26302a.c
 create mode 100644 ld/testsuite/ld-elf/pr26302b.c

diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 4a11bf1f1a..0822b5c8b3 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -796,7 +796,7 @@ 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{--with-symbol-versions}] [@option{--target=}@var{bfdname}]
+   [@option{--synthetic}] [@option{--target=}@var{bfdname}]
    [@var{objfile}@dots{}]
 @c man end
 @end smallexample
@@ -1130,14 +1130,6 @@ 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
-Enables the display of symbol version information if any exists.  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}.
-
 @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 1b5122d56a..69e697ae92 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -161,7 +161,6 @@ 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 = 0; /* Include symbol version information in the output.  */
 
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
 
@@ -192,7 +191,8 @@ enum long_option_values
   OPTION_PLUGIN,
   OPTION_SIZE_SORT,
   OPTION_RECURSE_LIMIT,
-  OPTION_NO_RECURSE_LIMIT
+  OPTION_NO_RECURSE_LIMIT,
+  OPTION_WITH_SYMBOL_VERSIONS
 };
 
 static struct option long_options[] =
@@ -226,7 +226,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, &with_symbol_versions, 1},
+  {"with-symbol-versions", no_argument, NULL,
+   OPTION_WITH_SYMBOL_VERSIONS},
   {0, no_argument, 0, 0}
 };
 \f
@@ -901,22 +902,6 @@ print_symbol (bfd *        abfd,
 
   format->print_symbol_info (&info, abfd);
 
-  if (with_symbol_versions)
-    {
-      const char *  version_string = NULL;
-      bfd_boolean   hidden = FALSE;
-
-      if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
-	version_string = bfd_get_symbol_version_string (abfd, sym,
-							TRUE, &hidden);
-
-      if (bfd_is_und_section (bfd_asymbol_section (sym)))
-	hidden = TRUE;
-
-      if (version_string && *version_string != '\0')
-	printf (hidden ? "@%s" : "@@%s", version_string);
-    }
-
   if (line_numbers)
     {
       static asymbol **syms;
@@ -1761,6 +1746,9 @@ 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 'D':
 	  dynamic = 1;
 	  break;
diff --git a/ld/testsuite/ld-elf/pr26302.nd b/ld/testsuite/ld-elf/pr26302.nd
new file mode 100644
index 0000000000..1f2fbdf9a3
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302.nd
@@ -0,0 +1,3 @@
+#...
+ +U foo@@FOO
+#pass
diff --git a/ld/testsuite/ld-elf/pr26302.ver b/ld/testsuite/ld-elf/pr26302.ver
new file mode 100644
index 0000000000..f2c03ac7a1
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302.ver
@@ -0,0 +1,5 @@
+FOO
+{
+global:
+  foo;
+};
diff --git a/ld/testsuite/ld-elf/pr26302a.c b/ld/testsuite/ld-elf/pr26302a.c
new file mode 100644
index 0000000000..cd0130cacd
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302a.c
@@ -0,0 +1,4 @@
+void
+foo (void)
+{
+}
diff --git a/ld/testsuite/ld-elf/pr26302b.c b/ld/testsuite/ld-elf/pr26302b.c
new file mode 100644
index 0000000000..eae278df96
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26302b.c
@@ -0,0 +1,7 @@
+extern void foo (void);
+
+void
+bar (void)
+{
+  foo ();
+}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index e9e9012058..014937175f 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -843,6 +843,24 @@ run_cc_link_tests [list \
 	{{readelf {--dyn-syms --wide} pr26094-1b.rd}} \
 	"pr26094-1" \
     ] \
+    [list \
+	"Build pr26302a.so" \
+	"-shared -Wl,--version-script=pr26302.ver" \
+	"-fPIC" \
+	{pr26302a.c} \
+	{} \
+	"pr26302a.so"
+    ] \
+    [list \
+	"Build pr26302b.so" \
+	"-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
+	"-fPIC" \
+	{pr26302b.c} \
+	{{nm {-u} pr26302.nd} \
+	 {nm {-u -D} pr26302.nd} \
+	 {nm {-u -D --with-symbol-versions} pr26302.nd}} \
+	"pr26302b.so" \
+    ] \
 ]
 
 run_ld_link_tests [list \
-- 
2.26.2


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

* Re: [PATCH] nm: Remove --with-symbol-versions
  2020-08-07 14:55   ` [PATCH] nm: Remove --with-symbol-versions H.J. Lu
@ 2020-08-13  2:42     ` Fangrui Song
  2020-08-13  3:44       ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Fangrui Song @ 2020-08-13  2:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Alan Modra, Nick Clifton, Binutils

"bfd: Display symbol version for nm -D" has a minor problem: an
undefined symbol (e.g. strlen@GLIBC_2.2.5 in cat) should use one @,
instead of two @@. nm -D output is currently inconsistent with readelf -Ws's
output and ld -y's behavior.

On 2020-08-07, H.J. Lu via Binutils wrote:
>Since
>
>commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
>Author: H.J. Lu <hjl.tools@gmail.com>
>Date:   Tue Mar 24 04:23:11 2020 -0700
>
>    bfd: Display symbol version for nm -D
>
>always displays symbol version for nm, remove --with-symbol-versions and
>silently accept it for backward compatibility.
>
>binutils/
>
>	PR binutils/26302
>	* nm.c (with_symbol_versions): Removed.
>	(long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
>	(long_options): Update --with-symbol-versions entry.
>	(print_symbol): Remove the with_symbol_versions check.
>	(main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
>	compatibility.
>	* doc/binutils.texi: Remove --with-symbol-versions.
>
>ld/
>
>	PR binutils/26302
>	* testsuite/ld-elf/pr26302.nd: New file.
>	* testsuite/ld-elf/pr26302.ver: Likewise.
>	* testsuite/ld-elf/pr26302a.c: Likewise.
>	* testsuite/ld-elf/pr26302b.c: Likewise.
>	* testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
>---
> binutils/doc/binutils.texi      | 10 +---------
> binutils/nm.c                   | 26 +++++++-------------------
> ld/testsuite/ld-elf/pr26302.nd  |  3 +++
> ld/testsuite/ld-elf/pr26302.ver |  5 +++++
> ld/testsuite/ld-elf/pr26302a.c  |  4 ++++
> ld/testsuite/ld-elf/pr26302b.c  |  7 +++++++
> ld/testsuite/ld-elf/shared.exp  | 18 ++++++++++++++++++
> 7 files changed, 45 insertions(+), 28 deletions(-)
> create mode 100644 ld/testsuite/ld-elf/pr26302.nd
> create mode 100644 ld/testsuite/ld-elf/pr26302.ver
> create mode 100644 ld/testsuite/ld-elf/pr26302a.c
> create mode 100644 ld/testsuite/ld-elf/pr26302b.c
>
>diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
>index 4a11bf1f1a..0822b5c8b3 100644
>--- a/binutils/doc/binutils.texi
>+++ b/binutils/doc/binutils.texi
>@@ -796,7 +796,7 @@ 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{--with-symbol-versions}] [@option{--target=}@var{bfdname}]
>+   [@option{--synthetic}] [@option{--target=}@var{bfdname}]
>    [@var{objfile}@dots{}]
> @c man end
> @end smallexample
>@@ -1130,14 +1130,6 @@ 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
>-Enables the display of symbol version information if any exists.  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}.
>-
> @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 1b5122d56a..69e697ae92 100644
>--- a/binutils/nm.c
>+++ b/binutils/nm.c
>@@ -161,7 +161,6 @@ 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 = 0; /* Include symbol version information in the output.  */
>
> static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
>
>@@ -192,7 +191,8 @@ enum long_option_values
>   OPTION_PLUGIN,
>   OPTION_SIZE_SORT,
>   OPTION_RECURSE_LIMIT,
>-  OPTION_NO_RECURSE_LIMIT
>+  OPTION_NO_RECURSE_LIMIT,
>+  OPTION_WITH_SYMBOL_VERSIONS
> };
>
> static struct option long_options[] =
>@@ -226,7 +226,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, &with_symbol_versions, 1},
>+  {"with-symbol-versions", no_argument, NULL,
>+   OPTION_WITH_SYMBOL_VERSIONS},
>   {0, no_argument, 0, 0}
> };
> \f
>@@ -901,22 +902,6 @@ print_symbol (bfd *        abfd,
>
>   format->print_symbol_info (&info, abfd);
>
>-  if (with_symbol_versions)
>-    {
>-      const char *  version_string = NULL;
>-      bfd_boolean   hidden = FALSE;
>-
>-      if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
>-	version_string = bfd_get_symbol_version_string (abfd, sym,
>-							TRUE, &hidden);
>-
>-      if (bfd_is_und_section (bfd_asymbol_section (sym)))
>-	hidden = TRUE;
>-
>-      if (version_string && *version_string != '\0')
>-	printf (hidden ? "@%s" : "@@%s", version_string);
>-    }
>-
>   if (line_numbers)
>     {
>       static asymbol **syms;
>@@ -1761,6 +1746,9 @@ 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 'D':
> 	  dynamic = 1;
> 	  break;
>diff --git a/ld/testsuite/ld-elf/pr26302.nd b/ld/testsuite/ld-elf/pr26302.nd
>new file mode 100644
>index 0000000000..1f2fbdf9a3
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/pr26302.nd
>@@ -0,0 +1,3 @@
>+#...
>+ +U foo@@FOO
>+#pass
>diff --git a/ld/testsuite/ld-elf/pr26302.ver b/ld/testsuite/ld-elf/pr26302.ver
>new file mode 100644
>index 0000000000..f2c03ac7a1
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/pr26302.ver
>@@ -0,0 +1,5 @@
>+FOO
>+{
>+global:
>+  foo;
>+};
>diff --git a/ld/testsuite/ld-elf/pr26302a.c b/ld/testsuite/ld-elf/pr26302a.c
>new file mode 100644
>index 0000000000..cd0130cacd
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/pr26302a.c
>@@ -0,0 +1,4 @@
>+void
>+foo (void)
>+{
>+}
>diff --git a/ld/testsuite/ld-elf/pr26302b.c b/ld/testsuite/ld-elf/pr26302b.c
>new file mode 100644
>index 0000000000..eae278df96
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/pr26302b.c
>@@ -0,0 +1,7 @@
>+extern void foo (void);
>+
>+void
>+bar (void)
>+{
>+  foo ();
>+}
>diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
>index e9e9012058..014937175f 100644
>--- a/ld/testsuite/ld-elf/shared.exp
>+++ b/ld/testsuite/ld-elf/shared.exp
>@@ -843,6 +843,24 @@ run_cc_link_tests [list \
> 	{{readelf {--dyn-syms --wide} pr26094-1b.rd}} \
> 	"pr26094-1" \
>     ] \
>+    [list \
>+	"Build pr26302a.so" \
>+	"-shared -Wl,--version-script=pr26302.ver" \
>+	"-fPIC" \
>+	{pr26302a.c} \
>+	{} \
>+	"pr26302a.so"
>+    ] \
>+    [list \
>+	"Build pr26302b.so" \
>+	"-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
>+	"-fPIC" \
>+	{pr26302b.c} \
>+	{{nm {-u} pr26302.nd} \
>+	 {nm {-u -D} pr26302.nd} \
>+	 {nm {-u -D --with-symbol-versions} pr26302.nd}} \
>+	"pr26302b.so" \
>+    ] \
> ]
>
> run_ld_link_tests [list \
>-- 
>2.26.2
>

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

* Re: [PATCH] nm: Remove --with-symbol-versions
  2020-08-13  2:42     ` Fangrui Song
@ 2020-08-13  3:44       ` H.J. Lu
  2020-08-13  5:42         ` Fangrui Song
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2020-08-13  3:44 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Alan Modra, Nick Clifton, Binutils

On Wed, Aug 12, 2020 at 7:42 PM Fangrui Song <i@maskray.me> wrote:
>
> "bfd: Display symbol version for nm -D" has a minor problem: an
> undefined symbol (e.g. strlen@GLIBC_2.2.5 in cat) should use one @,
> instead of two @@. nm -D output is currently inconsistent with readelf -Ws's
> output and ld -y's behavior.
>

nm -D is consistent with readelf -sW and nm:

[hjl@gnu-cfl-2 tmp]$ cat x.c
#include <stdio.h>

void
foo (void)
{
  printf ("foo\n");
}
[hjl@gnu-cfl-2 tmp]$ gcc -shared -fPIC x.c
[hjl@gnu-cfl-2 tmp]$ readelf -sW a.out | grep UND | grep @@
    47: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@@GLIBC_2.2.5
    51: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND
__cxa_finalize@@GLIBC_2.2.5
[hjl@gnu-cfl-2 tmp]$ nm a.out | grep " U "  | grep @@
                 U puts@@GLIBC_2.2.5
[hjl@gnu-cfl-2 tmp]$ nm -D a.out | grep " U "  | grep @@
                 U puts@@GLIBC_2.2.5
[hjl@gnu-cfl-2 tmp]$

But readelf --dyn-syms only displays a single @

-- 
H.J.

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

* Re: [PATCH] nm: Remove --with-symbol-versions
  2020-08-13  3:44       ` H.J. Lu
@ 2020-08-13  5:42         ` Fangrui Song
  2020-08-13 12:45           ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Fangrui Song @ 2020-08-13  5:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Alan Modra, Nick Clifton, Binutils

On 2020-08-12, H.J. Lu wrote:
>On Wed, Aug 12, 2020 at 7:42 PM Fangrui Song <i@maskray.me> wrote:
>>
>> "bfd: Display symbol version for nm -D" has a minor problem: an
>> undefined symbol (e.g. strlen@GLIBC_2.2.5 in cat) should use one @,
>> instead of two @@. nm -D output is currently inconsistent with readelf -Ws's
>> output and ld -y's behavior.
>>
>
>nm -D is consistent with readelf -sW and nm:
>
>[hjl@gnu-cfl-2 tmp]$ cat x.c
>#include <stdio.h>
>
>void
>foo (void)
>{
>  printf ("foo\n");
>}
>[hjl@gnu-cfl-2 tmp]$ gcc -shared -fPIC x.c
>[hjl@gnu-cfl-2 tmp]$ readelf -sW a.out | grep UND | grep @@
>    47: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@@GLIBC_2.2.5
>    51: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND
>__cxa_finalize@@GLIBC_2.2.5
>[hjl@gnu-cfl-2 tmp]$ nm a.out | grep " U "  | grep @@
>                 U puts@@GLIBC_2.2.5
>[hjl@gnu-cfl-2 tmp]$ nm -D a.out | grep " U "  | grep @@
>                 U puts@@GLIBC_2.2.5
>[hjl@gnu-cfl-2 tmp]$
>
>But readelf --dyn-syms only displays a single @

puts@GLIBC_2.2.5 in .dynsym (st_name concatenated with the version string in
.gnu.version_r) and puts@@GLIBC_2.2.5 in .symtab (st_name).  This looks like
another minor thing which should be fixed in ld.

Version strings in VERNEED should use a single @.

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

* Re: [PATCH] nm: Remove --with-symbol-versions
  2020-08-13  5:42         ` Fangrui Song
@ 2020-08-13 12:45           ` H.J. Lu
  0 siblings, 0 replies; 8+ messages in thread
From: H.J. Lu @ 2020-08-13 12:45 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Alan Modra, Nick Clifton, Binutils

On Wed, Aug 12, 2020 at 10:42 PM Fangrui Song <i@maskray.me> wrote:
>
> On 2020-08-12, H.J. Lu wrote:
> >On Wed, Aug 12, 2020 at 7:42 PM Fangrui Song <i@maskray.me> wrote:
> >>
> >> "bfd: Display symbol version for nm -D" has a minor problem: an
> >> undefined symbol (e.g. strlen@GLIBC_2.2.5 in cat) should use one @,
> >> instead of two @@. nm -D output is currently inconsistent with readelf -Ws's
> >> output and ld -y's behavior.
> >>
> >
> >nm -D is consistent with readelf -sW and nm:
> >
> >[hjl@gnu-cfl-2 tmp]$ cat x.c
> >#include <stdio.h>
> >
> >void
> >foo (void)
> >{
> >  printf ("foo\n");
> >}
> >[hjl@gnu-cfl-2 tmp]$ gcc -shared -fPIC x.c
> >[hjl@gnu-cfl-2 tmp]$ readelf -sW a.out | grep UND | grep @@
> >    47: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@@GLIBC_2.2.5
> >    51: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND
> >__cxa_finalize@@GLIBC_2.2.5
> >[hjl@gnu-cfl-2 tmp]$ nm a.out | grep " U "  | grep @@
> >                 U puts@@GLIBC_2.2.5
> >[hjl@gnu-cfl-2 tmp]$ nm -D a.out | grep " U "  | grep @@
> >                 U puts@@GLIBC_2.2.5
> >[hjl@gnu-cfl-2 tmp]$
> >
> >But readelf --dyn-syms only displays a single @
>
> puts@GLIBC_2.2.5 in .dynsym (st_name concatenated with the version string in
> .gnu.version_r) and puts@@GLIBC_2.2.5 in .symtab (st_name).  This looks like
> another minor thing which should be fixed in ld.
>
> Version strings in VERNEED should use a single @.

I opened:

https://sourceware.org/bugzilla/show_bug.cgi?id=26382

-- 
H.J.

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

end of thread, other threads:[~2020-08-13 12:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 13:44 [PATCH] nm: Ignore --with-symbol-versions for backward compatibility H.J. Lu
2020-07-30 12:04 ` H.J. Lu
2020-08-06 11:33 ` PING " H.J. Lu
2020-08-07 14:55   ` [PATCH] nm: Remove --with-symbol-versions H.J. Lu
2020-08-13  2:42     ` Fangrui Song
2020-08-13  3:44       ` H.J. Lu
2020-08-13  5:42         ` Fangrui Song
2020-08-13 12:45           ` 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).