[Extracted from my reply to [PATCH v4 00/10] Function Granular KASLR in January] mkdir -p ./a echo 'a: a.1: a.2: nop' > ./a/a.s echo 'a: nop' > ./a/b.s echo 'a: nop' > ./a/c.s gcc -c a/a.s -o a/a.o gcc -c a/b.s -o a/b.o gcc -c a/c.s -o a/c.o ld-new a/a.o a/b.o a/c.o -z unique-symbol % readelf -Ws a.out Symbol table '.symtab' contains 13 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS a.o 2: 0000000000401000 0 NOTYPE LOCAL DEFAULT 2 a 3: 0000000000401000 0 NOTYPE LOCAL DEFAULT 2 a.1 4: 0000000000401000 0 NOTYPE LOCAL DEFAULT 2 a.2 5: 0000000000000000 0 FILE LOCAL DEFAULT ABS b.o 6: 0000000000401001 0 NOTYPE LOCAL DEFAULT 2 a.1 7: 0000000000000000 0 FILE LOCAL DEFAULT ABS c.o 8: 0000000000401002 0 NOTYPE LOCAL DEFAULT 2 a.2 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _start 10: 0000000000402000 0 NOTYPE GLOBAL DEFAULT 2 __bss_start 11: 0000000000402000 0 NOTYPE GLOBAL DEFAULT 2 _edata 12: 0000000000402000 0 NOTYPE GLOBAL DEFAULT 2 _end Note that there are multiple a.1 and a.2, which are probably not desired.
A patch is posted at https://sourceware.org/pipermail/binutils/2021-May/116506.html
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4467df35a93e4c8e5ff7549e8d23324c64f527bd commit 4467df35a93e4c8e5ff7549e8d23324c64f527bd Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed May 5 20:28:39 2021 -0700 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.
Fixed for 2.37.