Developer Guide and Reference

Contents

Specifying Symbol Visibility Explicitly (Linux*
and
macOS*
)

This topic applies to C/C++ applications for Linux*
and
macOS*
only.
You can explicitly set the visibility of an individual symbol using the
visibility
attribute on a data or function declaration. For example:
int i __attribute__ ((visibility("default"))); void __attribute__ ((visibility("hidden"))) x () {...} extern void y() __attribute__ ((visibility("protected")));
The
visibility
declaration attribute accepts one of the five keywords:
  • external
  • default
  • protected
  • hidden
  • internal
The value of the
visibility
declaration attribute overrides the default set by the options
-fpic
,
-fvisibility
,
or
-fno-common
.
If you have a number of symbols for which you wish to specify the same
visibility
attribute, you can set the visibility using one of the five command line options:
  • -fvisibility-external=
    file
  • -fvisibility-default=
    file
  • -fvisibility-protected=
    file
  • -fvisibility-hidden=
    file
  • -fvisibility-internal=
    file
where
file
is the pathname of a file containing a list of the symbol names whose visibility you wish to set.
The symbol names in the file are separated by white space (
blanks
,
TAB characters
, or
newlines
). For example, the command line option:
-fvisibility-protected
=
prot.txt
, where file
prot.txt
contains:
a
    
b
c
d
  
e
This sets protected visibility for symbols
a
,
b
,
c
,
d
, and
e
.
This has the same effect as
__attribute__ ((visibility=("protected")))
on the declaration for each of the symbols.
These two ways to explicitly set visibility are mutually exclusive– you may use
__attribute((visibility()))
on the declaration or specify the symbol name in a file, but not both.
You can set the default visibility for symbols using one of the command line options:
  • -fvisibility=external
  • -fvisibility=default
  • -fvisibility=protected
  • -fvisibility=hidden
  • -fvisibility=internal
This option sets the visibility for symbols not specified in a visibility list file and that do not have
__attribute__ ((visibility=()))
in their declaration. For example, the command line options:
-fvisibility=protected -fvisibility-default=prot.txt
, where file
prot.txt
is as previously described, will cause all global symbols except
a
,
b
,
c
,
d
, and
e
to have protected visibility. Those five symbols, however, will have default visibility, and thus will be preemptable.

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804