10

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

1 Answer 1

4

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

The example is as follows, compile it as part of your shared library:

struct __attribute__((visibility("default"))) A {
    void foo() {}
    void bar();
};

auto pfoo = &A::foo;
auto pbar = &A::bar;

void A::bar() {}

If you build using only -fvisibility=hidden flag then both A::foo and A::bar will be visible in shared library (as shown by objdump -T libYours.so | c++filt). But if you add -fvisibility-inlines-hidden flag then only A::bar remain visible.

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.

So in most situations, -fvisibility-inlines-hidden is implied by -fvisibility=hidden, except for rare cases as above example.

The benefit of -fvisibility-inlines-hidden flag is that it can be almost safely added to build a program where previously all symbols were visible 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 "unless you need to override it for inlines where address identity is important either for the function itself or any function local static data".

And the usage of -fvisibility=hidden requires manual marking with __attribute__((visibility("default"))) of the symbols needed outside of a shared library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.