diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-05-05 20:28:39 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-05-05 20:29:01 -0700 |
commit | 4467df35a93e4c8e5ff7549e8d23324c64f527bd (patch) | |
tree | cab3952c02e0352b2bac138cf6e55f5da5ebff1d | |
parent | 9311cd60e18ccc92c36747265aacc6cb6025f66d (diff) | |
download | gdb-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.
-rw-r--r-- | bfd/ChangeLog | 6 | ||||
-rw-r--r-- | bfd/elflink.c | 39 | ||||
-rw-r--r-- | ld/ChangeLog | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26391.nd | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-1.d | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-1a.s | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-1b.s | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-2.d | 18 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-2a.s | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-2b.s | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr27825-2c.s | 4 |
11 files changed, 99 insertions, 21 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; } diff --git a/ld/ChangeLog b/ld/ChangeLog index 5262938..0c7c759 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -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. diff --git a/ld/testsuite/ld-elf/pr26391.nd b/ld/testsuite/ld-elf/pr26391.nd index d01f338..07bfd7f 100644 --- a/ld/testsuite/ld-elf/pr26391.nd +++ b/ld/testsuite/ld-elf/pr26391.nd @@ -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 index 0000000..c9b1b92 --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-1.d @@ -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 index 0000000..e6940e1 --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-1a.s @@ -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 index 0000000..2128e80 --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-1b.s @@ -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 index 0000000..12a1863 --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-2.d @@ -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 index 0000000..40fc05b --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-2a.s @@ -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 index 0000000..9e6f96a --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-2b.s @@ -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 index 0000000..762f886 --- /dev/null +++ b/ld/testsuite/ld-elf/pr27825-2c.s @@ -0,0 +1,4 @@ + .text +bar.1: +bar.2: + .nop |