]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf: Always append ".COUNT" to local symbols
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 6 May 2021 03:28:39 +0000 (20:28 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 6 May 2021 03:29:01 +0000 (20:29 -0700)
Always append ".COUNT" to local symbols to avoid potential conflicts
with existing local symbol "XXX.COUNT".

bfd/

PR ld/27825
* elflink.c (elf_link_output_symstrtab): Always append ".COUNT"
to local symbols.

ld/

PR ld/27825
* testsuite/ld-elf/pr27825-1.d: New file.
* testsuite/ld-elf/pr27825-1a.s: Likewise.
* testsuite/ld-elf/pr27825-1b.s: Likewise.
* testsuite/ld-elf/pr27825-2.d: Likewise.
* testsuite/ld-elf/pr27825-2a.s: Likewise.
* testsuite/ld-elf/pr27825-2b.s: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-elf/pr26391.nd
ld/testsuite/ld-elf/pr27825-1.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr27825-1a.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr27825-1b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr27825-2.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr27825-2a.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr27825-2b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr27825-2c.s [new file with mode: 0644]

index c574570fbe9e417fe15ad0cda91b892c6197b122..e481c1b0a25e363bb30c0d7b6efed107d9099f43 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27825
+       * elflink.c (elf_link_output_symstrtab): Always append ".COUNT"
+       to local symbols.
+
 2021-05-05  Alan Modra  <amodra@gmail.com>
 
        * vms-lib.c (vms_traverse_index): Account for vms_kbn size when
index cb38a025349bb44fede8f1bf11e98e23a0046446..0e1871aaac989df653d4ecc837f81bbcdbf9db90 100644 (file)
@@ -9830,6 +9830,9 @@ elf_link_output_symstrtab (void *finf,
               && ELF_ST_BIND (elfsym->st_info) == STB_LOCAL)
        {
          struct local_hash_entry *lh;
+         size_t count_len;
+         size_t base_len;
+         char buf[30];
          switch (ELF_ST_TYPE (elfsym->st_info))
            {
            case STT_FILE:
@@ -9840,28 +9843,24 @@ elf_link_output_symstrtab (void *finf,
                     (&flinfo->local_hash_table, name, true, false);
              if (lh == NULL)
                return 0;
-             if (lh->count)
+             /* Always append ".COUNT" to local symbols to avoid
+                potential conflicts with local symbol "XXX.COUNT".  */
+             sprintf (buf, "%lx", lh->count);
+             base_len = lh->size;
+             if (!base_len)
                {
-                 /* Append ".COUNT" to duplicated local symbols.  */
-                 size_t count_len;
-                 size_t base_len = lh->size;
-                 char buf[30];
-                 sprintf (buf, "%lx", lh->count);
-                 if (!base_len)
-                   {
-                     base_len = strlen (name);
-                     lh->size = base_len;
-                   }
-                 count_len = strlen (buf);
-                 versioned_name = bfd_alloc (flinfo->output_bfd,
-                                             base_len + count_len + 2);
-                 if (versioned_name == NULL)
-                   return 0;
-                 memcpy (versioned_name, name, base_len);
-                 versioned_name[base_len] = '.';
-                 memcpy (versioned_name + base_len + 1, buf,
-                         count_len + 1);
+                 base_len = strlen (name);
+                 lh->size = base_len;
                }
+             count_len = strlen (buf);
+             versioned_name = bfd_alloc (flinfo->output_bfd,
+                                         base_len + count_len + 2);
+             if (versioned_name == NULL)
+               return 0;
+             memcpy (versioned_name, name, base_len);
+             versioned_name[base_len] = '.';
+             memcpy (versioned_name + base_len + 1, buf,
+                     count_len + 1);
              lh->count++;
              break;
            }
index 52629384aba437ce07584894e71a24a0f69c23a8..0c7c759b42707d0f5343f16a157d33d9b3c3610e 100644 (file)
@@ -1,3 +1,13 @@
+2021-05-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27825
+       * testsuite/ld-elf/pr27825-1.d: New file.
+       * testsuite/ld-elf/pr27825-1a.s: Likewise.
+       * testsuite/ld-elf/pr27825-1b.s: Likewise.
+       * testsuite/ld-elf/pr27825-2.d: Likewise.
+       * testsuite/ld-elf/pr27825-2a.s: Likewise.
+       * testsuite/ld-elf/pr27825-2b.s: Likewise.
+
 2021-05-05  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-powerpc/empty.s: New file.
index d01f3381340d0d31b69bc7d6036f819cb795d034..07bfd7fb5b5be2e28f7055c590736d8799f47d1e 100644 (file)
@@ -1,5 +1,5 @@
 #...
-[0-9a-z]+ [td] _?bar
+[0-9a-z]+ [td] _?bar.0
 #...
 [0-9a-z]+ [td] _?bar.1
 #...
diff --git a/ld/testsuite/ld-elf/pr27825-1.d b/ld/testsuite/ld-elf/pr27825-1.d
new file mode 100644 (file)
index 0000000..c9b1b92
--- /dev/null
@@ -0,0 +1,21 @@
+#source: pr27825-1a.s
+#source: pr27825-1b.s
+#ld: -e _start --emit-relocs -z unique-symbol
+#nm: --defined-only
+#xfail: [is_generic]
+#xfail: fr30-*-* frv-*-* ft32-*-* iq2000-*-* mn10200-*-* msp*-* mt-*-*
+# These targets don't support -z.
+
+#...
+[0-9a-f]+ t bar.0
+#...
+[0-9a-f]+ t bar.1
+#...
+[0-9a-f]+ t bar.1.0
+#...
+[0-9a-f]+ t bar.1.1
+#...
+[0-9a-f]+ t bar.2.0
+#...
+[0-9a-f]+ t bar.2.1
+#pass
diff --git a/ld/testsuite/ld-elf/pr27825-1a.s b/ld/testsuite/ld-elf/pr27825-1a.s
new file mode 100644 (file)
index 0000000..e6940e1
--- /dev/null
@@ -0,0 +1,7 @@
+       .text
+       .globl _start
+_start:
+bar:
+bar.1:
+bar.2:
+       .nop
diff --git a/ld/testsuite/ld-elf/pr27825-1b.s b/ld/testsuite/ld-elf/pr27825-1b.s
new file mode 100644 (file)
index 0000000..2128e80
--- /dev/null
@@ -0,0 +1,5 @@
+       .text
+bar:
+bar.1:
+bar.2:
+       .nop
diff --git a/ld/testsuite/ld-elf/pr27825-2.d b/ld/testsuite/ld-elf/pr27825-2.d
new file mode 100644 (file)
index 0000000..12a1863
--- /dev/null
@@ -0,0 +1,18 @@
+#source: pr27825-2a.s
+#source: pr27825-2b.s
+#source: pr27825-2c.s
+#ld: -e _start --emit-relocs -z unique-symbol
+#nm: --defined-only
+#xfail: [is_generic]
+#xfail: fr30-*-* frv-*-* ft32-*-* iq2000-*-* mn10200-*-* msp*-* mt-*-*
+# These targets don't support -z.
+
+#...
+[0-9a-f]+ t bar.0
+#...
+[0-9a-f]+ t bar.1
+#...
+[0-9a-f]+ t bar.1.0
+#...
+[0-9a-f]+ t bar.2.0
+#pass
diff --git a/ld/testsuite/ld-elf/pr27825-2a.s b/ld/testsuite/ld-elf/pr27825-2a.s
new file mode 100644 (file)
index 0000000..40fc05b
--- /dev/null
@@ -0,0 +1,5 @@
+       .text
+       .globl _start
+_start:
+bar:
+       .nop
diff --git a/ld/testsuite/ld-elf/pr27825-2b.s b/ld/testsuite/ld-elf/pr27825-2b.s
new file mode 100644 (file)
index 0000000..9e6f96a
--- /dev/null
@@ -0,0 +1,3 @@
+       .text
+bar:
+       .nop
diff --git a/ld/testsuite/ld-elf/pr27825-2c.s b/ld/testsuite/ld-elf/pr27825-2c.s
new file mode 100644 (file)
index 0000000..762f886
--- /dev/null
@@ -0,0 +1,4 @@
+       .text
+bar.1:
+bar.2:
+       .nop