aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-05-05 20:28:39 -0700
committerH.J. Lu <hjl.tools@gmail.com>2021-05-05 20:29:01 -0700
commit4467df35a93e4c8e5ff7549e8d23324c64f527bd (patch)
treecab3952c02e0352b2bac138cf6e55f5da5ebff1d /bfd
parent9311cd60e18ccc92c36747265aacc6cb6025f66d (diff)
downloadgdb-4467df35a93e4c8e5ff7549e8d23324c64f527bd.zip
gdb-4467df35a93e4c8e5ff7549e8d23324c64f527bd.tar.gz
gdb-4467df35a93e4c8e5ff7549e8d23324c64f527bd.tar.bz2
elf: Always append ".COUNT" to local symbols
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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/elflink.c39
2 files changed, 25 insertions, 20 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index c574570..e481c1b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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
diff --git a/bfd/elflink.c b/bfd/elflink.c
index cb38a02..0e1871a 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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;
}