-qvisibility (-fvisibility)
Applicable invocations
Option | xlc (Compiling C) | xlC (Compiling C++) | xlclang (Compiling C) | xlclang++ (Compiling C++) |
---|---|---|---|---|
-qvisibility | ✓ | ✓ | ✓ | ✓ |
-fvisibility | ✓ | ✓ |
Category
Pragma equivalent
xlc/xlC and other legacy invocation commands | xlclang/xlclang++ invocation commands |
---|---|
#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
Defaults
xlc/xlC and other legacy invocations | xlclang/xlclang++ |
---|---|
-qvisibility=unspecified | -qnovisibility (All the visibility pragmas and attributes that are specified in the source are ignored. ) |
When -qvisibility=unspecified is set, the default visibility attribute specified on inline definitions in header files causes those definitions to be exported from shared libraries, both for the owning library of the symbol and any library that refers to the inline definition. To solve this issue, the compiler ignores the visibility attribute by default and it is recommended to control shared library exports with an export list file.
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.
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.
Predefined macros
None.
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.
Related information
- -qmkshrobj (-shared)
- -G
- #pragma GCC visibility push, #pragma GCC visibility pop
- Supported GCC pragmas in the Clang-based front end
- Using visibility attributes (IBM extension)
- External linkage
- The visibility variable attribute (IBM extension)
- The visibility function attribute (IBM extension)
- The visibility type attribute (C++ only) (IBM extension)
- The visibility namespace attribute (C++ only) (IBM extension)