Optimizing Itanium-Based Applications (May 2011)

14
You can use this option or pragma to obtain the most optimized access sequences for data and code
symbols. Symbols with the given name(s) are specified as having protected export class. If no symbols
are given, then all symbols, including those referenced but not defined in the translation unit, are
specified as having protected export class. This means that these symbols are not preempted and can be
optimized as such. For example, the compiler can bypass the linkage table for both code and data
references. Additionally, the compiler can omit the saving and restoring of gp around calls to protected
symbols, and can generate a pc-relative call. If the target of the call is not local to the load module, the
linker produces an error. These optimizations are always performed for locally-defined symbols
1
unless
the optimizations have been named in a -Bextern option list. -Bprotected enables these
optimizations for symbols that are not locally defined.
When -Bprotected is specified with no symbol list, it also implies -Wl, -aarchive_shared,
causing the linker to prefer an archive library to a shared one if one is available. This results in better
performance because accesses to archived libraries are faster than those to shared libraries.
The #pragma binding protected applies to all globally-scoped symbols
2
following the
pragma prior to the next #pragma binding.
To avoid linker errors when making calls into shared system libraries, include the system header files
for these routines. The symbols are marked properly in the system headers as being preemptible. If the
header files are not included, and therefore these symbols are not marked properly, the linker issues an
error because they are not defined in the load module. This linker error prevents a run-time error, which
would occur due to incorrect optimization such as omission of gp saves and restores around calls to
these symbols. Similar problems can be encountered when linking with applications or third-party
shared libraries, unless they are decorated with the proper pragmas. Library providers should consult
David Gross’s Library Providers’ Guide to Symbol Binding[3] on how to enable use of -Bprotected
in user applications.
For application builds, this option can be used with -exec to obtain fastest data access and call
sequences (see -exec and -minshared).
-Bprotected_data
Marks all data symbols as having protected export class, implying the optimizations to data accesses
discussed under -Bprotected. This option can be used when system header files are not included for
shared library calls made by the application, to obtain a subset of the optimizations available with
-Bprotected. However, header files declaring any shared library data being accessed by the
application must be included. For fastest code, users should add the appropriate header file includes,
and compile with -Bprotected. Alternatively, use -Bprotected_data in combination with
either -Bprotected_def or -exec, to obtain optimized access sequences, if modifying source
code to add header file includes is not an option.
-Bprotected_def
Marks locally (non-tentatively) defined symbols as having protected export class. The optimizations
discussed under -Bprotected are applied to these symbols only. This can be used when system header
files are not included for shared library calls or data accesses. For fastest code, users should add the
appropriate header file includes, and compile with -Bprotected.
This option is a subset of -exec.
-Bhidden[=symbol[,symbol]*]
-Bhidden:filename
1
A locally-defined symbol is a global or static symbol with a definition in the compilation set from which it is
referenced. The compilation set is the translation unit without -ipo, and with –ipo is the collection of translation units
presented to a single linker invocation.
2
A globally-scoped symbol is a symbol that is visible across translation unit boundaries. Examples include simple
globals, static data members, and certain namespace members.