Bug 27825 - ld: -z unique-symbol behavior when .1 exists
Summary: ld: -z unique-symbol behavior when .1 exists
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.37
: P2 normal
Target Milestone: 2.37
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-04 18:45 UTC by Fangrui Song
Modified: 2021-05-06 13:39 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-05-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-05-04 18:45:45 UTC
[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.
Comment 1 H.J. Lu 2021-05-05 15:50:21 UTC
A patch is posted at

https://sourceware.org/pipermail/binutils/2021-May/116506.html
Comment 2 cvs-commit@gcc.gnu.org 2021-05-06 03:32:43 UTC
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.
Comment 3 H.J. Lu 2021-05-06 13:39:52 UTC
Fixed for 2.37.