What is _GLIBCXX_VIBIBITY?

I looked at the source of some of the standard headers included in gcc (in /usr/include/c++/ ) and found the following at the top of each header:

 namespace std _GLIBCXX_VISIBILITY(default) 

What is _GLIBCXX_VISIBILITY(default) ?

+6
source share
1 answer

This is a preprocessor macro. And is defined as:

 #if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY #define _GLIBCXX_VISIBILITY(V) __attribute__ ((__visibility__ (#V))) #else #define _GLIBCXX_VISIBILITY(V) #endif 

So, if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY true, then in your case it will expand to:

 __attribute__ (( __visibility__ ("default"))) 

else if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY false, it will not do anything.

The __visibility__ attribute __visibility__ used to determine the visibility of characters in a DSO file. Using "hidden" instead of "default" can be used to hide characters from objects outside of DSO.

For instance:

 __attribute__ ((__visibility__("default"))) void foo(); __attribute__ ((__visibility__("hidden"))) void bar(); 

The foo() function will be used from outside the DSO, while bar() is mostly private and can only be used inside DSO.

You can read a little more about the __visibility__ attribute here: https://gcc.gnu.org/wiki/Visibility

+11
source

Source: https://habr.com/ru/post/984262/


All Articles