-fvisibility (-qvisibility)

Pragma equivalent

  • -fvisibility: #pragma GCC visibility push (default | protected | hidden)
  • -qvisibility: #pragma GCC visibility push (default | protected | hidden)

#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 -fvisibility option if they do not get visibility attributes from pragma directives, explicitly specified attributes, or propagation rules.

Syntax

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

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

Defaults

-fvisibility=default or -qvisibility=default

Parameters

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.
The -qvisibility=internal option is not supported; use the -qvisibility=hidden option instead.

Usage

The -fvisibility 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 -fvisibility=protected option.
xlc myprogram.c -fvisibility=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