Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How -fvisibility-inlines-hidden differs from -fvisibility=hidden in gcc

Tags:

c++

gcc

linkage

According to http://gcc.gnu.org/wiki/Visibility,

With -fvisibility=hidden, you are telling GCC that every declaration not explicitly marked with a visibility attribute has a hidden visibility.

And

-fvisibility-inlines-hidden causes all inlined class member functions to have hidden visibility

When I compile a very large project, it seems to me that adding -fvisibility-inlines-hidden together with -fvisibility=hidden can indeed hide more symbols compared to using -fvisibility=hidden along. But I cannot find a minimum example that shows the exact difference where -fvisibility-inlines-hidden take effects. I also tried this example but failed to see the effects of latter.

Can someone show me a minimum example showing that -fvisibility-inlines-hidden are still necessary if I'm already using -fvisibility=hidden ? I'm using GCC 5.3.0

like image 713
flm8620 Avatar asked Dec 24 '19 13:12

flm8620


1 Answers

According to http://gcc.gnu.org/wiki/Visibility

... command line switch: -fvisibility-inlines-hidden. This causes all inlined class member functions to have hidden visibility, causing significant export symbol table size & binary size reductions though not as much as using -fvisibility=hidden. However, -fvisibility-inlines-hidden can be used with no source alterations, unless you need to override it for inlines where address identity is important either for the function itself or any function local static data.

In other words, -fvisibility-inlines-hidden cannot help you hide more symbols if you already use -fvisibility=hidden.

But you can almost safely add -fvisibility-inlines-hidden flag to build a program where all symbols were exported and get some reduction in export symbol table for free, because excluded symbols are anyway inline and so they are available in other modules without export symbol table.

like image 153
Fedor Avatar answered Sep 21 '22 15:09

Fedor