0

For this question: version-script and hidden visibility

I saw this comment:

Visibility annotations are preferred to linker scripts as they allow more aggressive optimization by compilers. Scripts are still needed for full trimming of external library interface due to issues in libgcc and ld. – 
yugr
Oct 5, 2018 at 21:32

Sorry, I don't know how to contact yugr directly, but I am really curious about what are the issues in libgcc and ld to make us still need version scripts for full trimming even if the C++ code already have the appropriate visibility annotations and compiled with -fvisibility=hidden?

Is there an simple example?

Thank you.

1
  • 1
    "I don't know how to contact yugr directly" - you can post a comment which mentions him (via @yugr syntax).
    – yugr
    Commented Apr 22, 2023 at 7:31

1 Answer 1

1

-fvisibility=hidden is applied only to symbols in your sources. It will not hide symbols which come from already compiled static libraries or are autogenerated by the linker.

This happened few years ago with libgcc and GNU ld but seems to be fixed in recent versions of tools e.g. on Ubuntu 22 I get

$ g++ -shared -fPIC tmp.cc
$ readelf --dyn-syms -W a.out

Symbol table '.dynsym' contains 6 entries:

   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __cxa_finalize
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMC[...]
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterT[...]
     4: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     5: 00000000000010f9    27 FUNC    GLOBAL DEFAULT   10 _Z3fooiii

As you can see there are no longer spurious exports in shared library interface.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.