-qvisibility (-fvisibility)

Applicable invocations

Table 1. Invocations that accept the given options
Option xlc (Compiling C) xlC (Compiling C++) xlclang (Compiling C) xlclang++ (Compiling C++)
-qvisibility
-fvisibility    
Note: Only typical invocations are listed in this table. You can refer to the full list of compiler invocations for all basic invocations and their equivalent special invocations.

Pragma equivalent

Table 2. Pragma equivalents for two categories of invocations
xlc/xlC and other legacy invocation commands xlclang/xlclang++ invocation commands
#pragma GCC visibility push (default | protected | hidden | internal), #pragma GCC visibility pop
  • -fvisibility: #pragma GCC visibility push (default | protected | hidden), #pragma GCC visibility pop
  • -qvisibility: #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

Read syntax diagramSkip visual syntax diagram
        .-novisibility-------------------.   
>>- -q--+-visibility--=--+-unspecified-+-+---------------------><
                         +-default-----+     
                         +-hidden------+     
                         +-protected---+     
                         '-internal----'     

Read syntax diagramSkip visual syntax diagram
>>- -f--visibility--=--+-default---+---------------------------><
                       +-hidden----+   
                       '-protected-'   

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. )

Clang-based front end beginsWhen -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.
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, AIX 7.2, and higher.

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.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us