Bug 27931

Summary: objcopy --localize-hidden/--keep-global-symbol: drop GRP_COMDAT if the signature symbol becomes local?
Product: binutils Reporter: Fangrui Song <i>
Component: binutilsAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: hjl.tools, jh7370, pinskia
Priority: P2    
Version: unspecified   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59842
Host: Target:
Build: Last reconfirmed: 2021-12-06 00:00:00

Description Fangrui Song 2021-05-29 23:54:11 UTC
cat > ./a.s <<eof
.section        .text._Z3foov,"axG",@progbits,_Z3foov,comdat
.hidden _Z3foov
.weak   _Z3foov
.type   _Z3foov,@function
_Z3foov:
  ret
eof
cc -c a.s

GRP_COMDAT deduplication is based on name, so after objcopy --localize-hidden,
the group may keep deduplication semantics. This may be undesired if the user
intention is to make the hidden symbols fully internal.

% objcopy --localize-hidden a.o b.o && readelf -Ws -x .group b.o

Symbol table '.symtab' contains 8 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    LOCAL  HIDDEN     5 _Z3foov
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    2 
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    5 
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    6 

Hex dump of section '.group':
  0x00000000 01000000 05000000                   ........


-G is similar.

See https://groups.google.com/g/generic-abi/c/2X6mR-s2zoc "GRP_COMDAT group with STB_LOCAL signature" for a generic-abi discussion.
Comment 1 Fangrui Song 2021-07-26 05:19:34 UTC
Ping:)

I am updating llvm-objcopy to drop GRP_COMDAT
Comment 2 Andrew Pinski 2021-12-05 08:55:39 UTC
There was an old (7 years ago) bug filed against GCC about __x86.get_pc_thunk and "objcopy --keep-global-symbol" (https://gcc.gnu.org/PR59842) which seems like the same issue here.
Comment 3 H.J. Lu 2021-12-06 16:55:45 UTC
A patch is posted at

https://sourceware.org/pipermail/binutils/2021-December/118824.html