[PATCH v3] elf: Don't set its DT_VERSYM entry for unversioned symbol

Andreas Schwab schwab@suse.de
Wed Nov 12 08:54:28 GMT 2025
On Nov 11 2025, Fangrui Song wrote:

> Two values are reserved:
>
>   VER_NDX_LOCAL  0 - The symbol is private, and is not available
> outside this object.

Doesn't this mean that the mold behaviour is correct?

ld.bfd now marks the symbols ext_var, print and print64 as local, and
mold refuses to link against this object if one of these symbols are
referenced:

$ binutils/readelf -WDsV c.so

Symbol table for image contains 9 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTable
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.2.5 (2)
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     4: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
     5: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.2.5 (2)
     6: 0000000000004010    56 OBJECT  GLOBAL DEFAULT   21 ext_var
     7: 000000000000112a    43 FUNC    GLOBAL DEFAULT   12 print
     8: 0000000000001155    46 FUNC    GLOBAL DEFAULT   12 print64

Version symbols section '.gnu.version' contains 9 entries:
 Addr: 0x0000000000000390  Offset: 0x00000390  Link: 3 (.dynsym)
  000:   0 (*local*)       0 (*local*)       2 (GLIBC_2.2.5)   0 (*local*)    
  004:   0 (*local*)       2 (GLIBC_2.2.5)   0 (*local*)       0 (*local*)    
  008:   0 (*local*)    

Version needs section '.gnu.version_r' contains 1 entry:
 Addr: 0x00000000000003a8  Offset: 0x000003a8  Link: 4 (.dynstr)
  000000: Version: 1  File: libc.so.6  Cnt: 1
  0x0010:   Name: GLIBC_2.2.5  Flags: none  Version: 2

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Binutils mailing list