]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf: Keep only one '@' for undefined versioned symbols
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 22 Aug 2020 15:31:53 +0000 (08:31 -0700)
committerAlan Modra <amodra@gmail.com>
Thu, 31 Dec 2020 23:47:29 +0000 (10:17 +1030)
The symbol string table in the .symtab section is optional and cosmetic.
Keep only one '@' for undefined versioned symbols, which are defined in
shared objects, in the symbol string table.  Update "nm -D" to display
only one '@' for undefined versioned symbols.

bfd/

PR ld/26382
* elflink.c (elf_link_output_symstrtab): Keep only one '@' for
versioned symbols, which are defined in shared objects, in
symbol string table.

binutils/

PR ld/26382
* nm.c (print_symname): Display only one '@' for undefined
versioned symbols.
* doc/binutils.texi: Update nm version information.

ld/

PR ld/26382
* testsuite/ld-elf/pr26302.nd: Updated.
* testsuite/ld-elf/pr26302.rd: New file.
* testsuite/ld-elf/shared.exp: Add a test for readelf -sW.

(cherry picked from commit 3f2e9699234ca31d083bc93ea6e03903f10baeaf)

bfd/ChangeLog
bfd/elflink.c
binutils/ChangeLog
binutils/doc/binutils.texi
binutils/nm.c
ld/ChangeLog
ld/testsuite/ld-elf/pr26302.nd
ld/testsuite/ld-elf/pr26302.rd [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 6114b73a052686bec7d11323f477cb22cf3e7edb..4c629d4be63448d0d8a98c67150cd4f90b252b7e 100644 (file)
@@ -1,3 +1,12 @@
+2021-01-01  Alan Modra  <amodra@gmail.com>
+
+       Apply from master
+       2020-08-22  H.J. Lu  <hongjiu.lu@intel.com>
+       PR ld/26382
+       * elflink.c (elf_link_output_symstrtab): Keep only one '@' for
+       versioned symbols, which are defined in shared objects, in
+       symbol string table.
+
 2020-12-04  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/27016
index 998b72f2281c5b9b5482795b9b55dfffe284ee23..222a4573b00f11419dc5f52fa29ff871220f3c7d 100644 (file)
@@ -9636,9 +9636,29 @@ elf_link_output_symstrtab (struct elf_final_link_info *flinfo,
     {
       /* Call _bfd_elf_strtab_offset after _bfd_elf_strtab_finalize
         to get the final offset for st_name.  */
+      char *versioned_name = (char *) name;
+      if (h != NULL && h->versioned == versioned && h->def_dynamic)
+       {
+         /* Keep only one '@' for versioned symbols defined in shared
+            objects.  */
+         char *version = strrchr (name, ELF_VER_CHR);
+         char *base_end = strchr (name, ELF_VER_CHR);
+         if (version != base_end)
+           {
+             size_t base_len;
+             size_t len = strlen (name);
+             versioned_name = bfd_alloc (flinfo->output_bfd, len);
+             if (versioned_name == NULL)
+               return 0;
+             base_len = base_end - name;
+             memcpy (versioned_name, name, base_len);
+             memcpy (versioned_name + base_len, version,
+                     len - base_len);
+           }
+       }
       elfsym->st_name
        = (unsigned long) _bfd_elf_strtab_add (flinfo->symstrtab,
-                                              name, FALSE);
+                                              versioned_name, FALSE);
       if (elfsym->st_name == (unsigned long) -1)
        return 0;
     }
index 54c575a8d2e5cc47348f98baf423352bfe2f77d5..c54b39f395425b4e334fbd887c9d8f80e8e59fec 100644 (file)
@@ -1,6 +1,12 @@
 2021-01-01  Alan Modra  <amodra@gmail.com>
 
        Apply from master
+       2020-08-22  H.J. Lu  <hongjiu.lu@intel.com>
+       PR ld/26382
+       * nm.c (print_symname): Display only one '@' for undefined
+       versioned symbols.
+       * doc/binutils.texi: Update nm version information.
+
        2020-08-10  H.J. Lu  <hongjiu.lu@intel.com>
        PR binutils/26302
        * nm.c (with_symbol_versions): Removed.
index a2afcba3dbce9fe965db190e53c172a26fb9970b..cf8d0ea7f1c7a5674f41231d06d102c2a11c1765 100644 (file)
@@ -924,7 +924,13 @@ The symbol type is unknown, or object file format specific.
 @end table
 
 @item
-The symbol name.
+The symbol name.  If a symbol has version information associated with it,
+then the version information is displayed as well.  If the versioned
+symbol is undefined or hidden from linker, 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}.
 @end itemize
 
 @c man end
index 69e697ae9252816fb1958eaebe3ccb8cc3a76cad..3501f48d29eff43d0ef027c00dbaec05adcfed20 100644 (file)
@@ -421,7 +421,10 @@ 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 ? "@" : "@@", version_string);
+       printf ("%s%s",
+              (hidden || bfd_is_und_section (info->elfinfo->symbol.section)
+               ? "@" : "@@"),
+              version_string);
     }
 }
 
index e2469c0cf34d8a3014be2cf92d1216c4e9ae1e1b..4d85dbf1aee53120b3f42f6023d2296203bb00f8 100644 (file)
@@ -1,6 +1,12 @@
 2021-01-01  Alan Modra  <amodra@gmail.com>
 
        Apply from master
+       2020-08-22  H.J. Lu  <hongjiu.lu@intel.com>
+       PR ld/26382
+       * testsuite/ld-elf/pr26302.nd: Updated.
+       * testsuite/ld-elf/pr26302.rd: New file.
+       * testsuite/ld-elf/shared.exp: Add a test for readelf -sW.
+
        2020-08-10  H.J. Lu  <hongjiu.lu@intel.com>
        PR binutils/26302
        * testsuite/ld-elf/pr26302.nd: New file.
index 1f2fbdf9a3f70ec0446afc5022953989d5ab7f16..bc9a675789a8b576c7a5d2d22ec162eae09890bc 100644 (file)
@@ -1,3 +1,3 @@
 #...
- +U foo@@FOO
+ +U foo@FOO
 #pass
diff --git a/ld/testsuite/ld-elf/pr26302.rd b/ld/testsuite/ld-elf/pr26302.rd
new file mode 100644 (file)
index 0000000..8f7b8a9
--- /dev/null
@@ -0,0 +1,12 @@
+#...
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +FUNC +GLOBAL +DEFAULT +UND +foo@FOO \([0-9]+\)
+#...
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +FUNC +GLOBAL +DEFAULT +UND +foo@FOO
+#pass
index 014937175fc9985574016ff6cdeec8ce08ed9bb5..4de5b341834135dc8006c2be7809e66c0ecbaa0b 100644 (file)
@@ -856,7 +856,8 @@ run_cc_link_tests [list \
        "-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
        "-fPIC" \
        {pr26302b.c} \
-       {{nm {-u} pr26302.nd} \
+       {{readelf {-sW} pr26302.rd} \
+        {nm {-u} pr26302.nd} \
         {nm {-u -D} pr26302.nd} \
         {nm {-u -D --with-symbol-versions} pr26302.nd}} \
        "pr26302b.so" \