Pragma equivalent
#pragma GCC visibility
push (default | protected | hidden | internal)
#pragma GCC
visibility pop
Purpose
Specifies the visibility attribute
for external linkage entities in object files. The external linkage
entities have the visibility attribute that is specified by the -qvisibility option
if they do not get visibility attributes from pragma directives, explicitly
specified attributes, or propagation rules.
Syntax
.-unspecified-.
>>- -q--visibility--=--+-default-----+-------------------------><
+-hidden------+
+-protected---+
'-internal----'
Defaults
-qvisibility=unspecified
Parameters
- unspecified
- Indicates that the affected external linkage entities do not have
visibility attributes. Whether these entities are exported in shared
libraries depends on the specified export list or the one that is
generated by the compiler.
- default
- Indicates that the affected external linkage entities have the
default visibility attribute. These entities are exported in shared
libraries, and they can be preempted.
- protected
- Indicates that the affected external linkage entities have the
protected visibility attribute. These entities are exported in shared
libraries, but they cannot be preempted.
- hidden
- Indicates that the affected external linkage entities have the
hidden visibility attribute. These entities are not exported in shared
libraries, but their addresses can be referenced indirectly through
pointers.
- internal
- Indicates that the affected external linkage entities have the
internal visibility attribute. These entities are not exported in
shared libraries, and their addresses are not available to other modules
in shared libraries.
Restriction: In this
release, the hidden and internal visibility attributes are the same.
The addresses of the entities that are specified with either of these
visibility attributes can be referenced indirectly through pointers.
Usage
The
-qvisibility option
globally sets visibility attributes for external linkage entities
to describe whether and how an entity defined in one module can be
referenced or used in other modules. Entity visibility attributes
affect entities with external linkage only, and cannot increase the
visibility of other entities. Entity preemption occurs when an entity
definition is resolved at link time, but is replaced with another
entity definition at run time.
Note: On the AIX® platform, entity preemption
occurs only when runtime linking is used. For details, see
Linking a library to an application.
Visibility attributes are supported on AIX 6.1 TL8, AIX 7.1
TL2, and higher.
Examples
To set external linkage entities with
the protected visibility attribute in compilation unit
myprogram.c, compile
myprogram.c with the
-qvisibility=protected option.
xlc myprogram.c -qvisibility=protected -c
All
the external linkage entities in the
myprogram.c file have the protected visibility
attribute if they do not get visibility attributes from pragma directives,
explicitly specified attributes, or propagation rules.