Chapter 2 C and C++ Source-Level Optimizations 57
Software Optimization Guide for AMD64 Processors
25112 Rev. 3.06 September 2005
2.28 Improving Performance in Linux Libraries
Optimization
If interposition is not important to a particular application, then, if using ld in the binutils package,
you can make use of a linker option that results in references to public global routines inside the
library that cannot be overridden.
Application This optimization applies to:
32-bit software
64-bit software
Rationale
Dynamically loadable libraries are a versatile feature of the Linux operating system. They allow one
or more symbols in one library to override the same symbol in another library. Known as
interposition, this ability makes customizations and probing seamless. Interposition is implemented
by means of a procedure linkage table (PLT). The PLT is so flexible that even references to an
overridden symbol inside the library end up referencing the overriding symbol. However, the PLT
imposes a performance penalty by requiring all function calls to public global routines to go through
an extra step that increases the chances of cache misses and branch mispredictions. This is
particularly severe for C++ classes whose methods typically refer to other methods in the same class.
Examples
When using ld, include the following command line option:
-Bsymbolic
If using gcc to build a library, add this option to the command-line:
-Wl,-Bsymbolic