If you create a shared library using the following command line, the modules are inserted into the library in alphabetical order:

$ ld -b -o libabc.so *.o

The potential problem with this ordering is that the routines in a.o and c.o are spaced far apart in the library. Better virtual memory performance can be attained by positioning the modules a.o and c.o together in the shared library, followed by the module b.o. The following command does this:

$ ld -b -o libabc.so a.o c.o b.o

One way to help determine the best order to specify the object files is to gather profile data for the object modules; modules that are frequently called must be grouped together on the command line. Another way is to use the lorder(1) and tsort(1) commands. Used together on a set of object modules, these commands determine how to order the modules so that the linker only needs a single pass to resolve references among the modules. A side-effect of this is that modules that call each other may be positioned closer together than modules that do not. For instance, suppose you have defined the following object modules:

Module

Calls Routines in Module

 

 

a.o

x.o y.o

 

 

b.o

x.o y.o

 

 

d.o

none

 

 

e.o

none

 

 

x.o

d.o

 

 

y.o

d.o

 

 

Then the following command determines the one-pass link order:

$ lorder ?.o tsort

Pipe lorder's output to tsort. a.o

b.o

 

e.o

 

x.o

 

y.o

 

d.o

 

Notice that d.o is now closer to x.o and y.o, which call it. However, this is still not the best information to use because a.o and b.o are separated from x.o and y.o by the module e.o, which is not called by any modules. The actual optimal order may be more like this:

a.o b.o x.o y.o d.o e.o

Again, the use of lorder and tsort is not perfect, but it may give you leads on how to best order the modules. You may want to experiment to see what ordering gives the best performance.

Making Shared Libraries Non-Writable

You may get an additional performance gain by ensuring that no shared libraries have write permissions. Programs that use more than one writable library can experience significantly degraded loading time. The following chmod command gives shared libraries the correct permissions for best load-time performance:

$ chmod 555 libname

Using the +ESlit/+Olit=all Option to cc

The +ESlit compiler option is available only for programs on PA systems. For programs on Itanium-based systems, use the +Olit=all compiler option.

Creating Shared Libraries 107