Shared Libraries with Debuggers, Profilers, and Static Analysis

Debugging of shared libraries is supported by the by the WDB Debugger. See the WDB documentation at: http://www.hp.com/go/wdb

Profiling Shared Libraries with gprof(1)

The gprof tool produces an execution profile about an executable for application programs and shared libraries. See gprof(1) for more information. Use the following steps to profile a shared library:

Set the environment variable LD_PROFILE to the shared library name.

Link the application which links with the library to be profiled to take one of the following actions:

Link with libc.sl.

Export all the symbols explicitly (with the ld +e option).

This is primarily for registration of the exit handler. You can only profile a single shared library. You can profile either the application or a shared library. However, you cannot profile both the application and the shared library together. To profile applications, continue to use the existing gprof method, in which you compile with -Goption, but do not set LD_PROFILE. For example, to profile the shared library test.sl:

Set the environment variable LD_PROFILE to specify your shared library.

$ LD_PROFILE=test.sl $ export LD_PROFILE

If a.out is linked to test.sl, execute a.out. $ a.out

This step creates the file <shared_library>.profile (where shared_library is the name of the shared library specified by the LD_PROFILE environment variable) at run time. This file contains the profile information for the shared library. For this example, the file test.sl.profile is created.

To get the complete profile information about test.sl, run the gprof command: $ gprof test.sl test.sl.profile

The following are the limitations for profiling shared library using gprof:

Local, static, and hidden functions are not profiled.

Shared libraries built with -B symbolic are not profiled.

Any function calls made from library initializers are not collected.

Creating Archive Libraries

1.Compile one or more source files to create object files containing relocatable object code.

2.Combine these object files into a single archive library file with the ar command.

Following are the commands you can use to create an archive library called libunits.a:

$ cc -Aa -c length.c volume.c mass.c

$ ar r libunits.a length.o volume.o mass.o

These steps are described in detail in “Overview of Creating an Archive Library” (page 95). Other topics relevant to archive libraries are:

“Contents of an Archive File” (page 95)

“Example of Creating an Archive Library” (page 96)

94 Creating and Using Libraries