HP UX Software Transition Kit (STK) manual Example Program Comparing Shared and Archive Libraries

Models: UX Software Transition Kit (STK)

1 228
Download 228 pages 54.84 Kb
Page 92
Image 92

it was when you linked the final application. Otherwise, when the users of your application run it, the dynamic loader looks for /users/hyperturbo/liblocal.so, fail to find it, and the program aborts.

In default mode, the linker records ./liblocal.so.

This is more of a concern with non-standard libraries-that is, libraries not found in /usr/lib/hpux32 or /usr/lib/hpux64. There is little chance of the standard libraries not being in these directories.

Caution on Using Dynamic Library Searching

If different versions of a library exist on your system, be aware that the dynamic loader may get the wrong version of the library when dynamic library searching is enabled with SHLIB_PATH or +b. For instance, you may want a program to use the PA1.1 libraries found in the /usr/lib/pa1.1 directory; but through a combination of SHLIB_PATH settings and +b options, the dynamic loader ends up loading versions found in /usr/lib instead. If this happens, make sure that SHLIB_PATH and +b are set to avoid such conflicts.

Running setuid Programs

If SHLIB_PATH and LD_LIBRARY_PATH are set for setuid programs, the loader validates the contents of the environment variables SHLIB_PATH and LD_LIBRARY_PATH against the contents of the configuration file/etc/dld.sl.conf. The loader validates the contents only if:

1.The conf file is present

2.The conf file fulfils the following conditions:

The superuser owns the conf file.

Appropriate permissions are granted, that is, the conf file is writable only by the superuser.

The conf file contains a list of absolute shared library search paths.

Spaces are not present in the paths listed. The loader ignores everything on a line that follows a space or # character. You can use the # character to comment out paths in the conf file.

NOTE: The dld provides support for using $ORIGIN string in the embedded paths for setuid programs.

If SHLIB_PATH / LD_LIBRARY_PATH contains any of the paths listed in the conf file, the loader uses the paths in the order they are specified in the environment variables. If the contents of the environment variables and the contents of the conf file do not overlap, the dynamic path lookup is disabled and the search is restricted to the embedded path (RPATH). You can turn off this feature by setting the environment variable _HP_DLDOPTS to -no_setuidpath. If you turn off this feature, setuid programs do not carry out dynamic path searching.

NOTE: The configuration file /etc/dld.sl.conf must contain a list of shared library search paths (delimited by either colon or newline characters). Any relative paths (paths not starting with /) in the path list is ignored by the loader. To avoid redundant searches, ensure that a path appears only once in the file and only once in the option SHLIB_PATH/LD_LIBRARY_PATH. For PA32, this feature is enabled only if the /etc/dld.sl.conf file is present. The default behavior of honoring these environment variables for setuid programs remains unchanged.

Example Program Comparing Shared and Archive Libraries

As an example, suppose two separate programs, prog1 and prog2, use shared libc routines heavily. Suppose that the a.out portion of prog1 is 256Kb in size, while the a.out portion of prog.2 is 128Kb. Assume also that the shared libc is 512Kb in size. Figure 7 (page 93) shows how physical memory might look when both processes run simultaneously. Notice that one copy of libc

92 Creating and Using Libraries

Page 92
Image 92
HP UX Software Transition Kit (STK) manual Example Program Comparing Shared and Archive Libraries, Running setuid Programs