Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX 64-bit Porting and Transition Guide: HP 9000 Computers > Chapter 2 Summary of Changes

Run Time Differences

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Applications compiled and linked in 64-bit mode use a run-time dynamic loading model similar to other SVR4 systems. There are two main areas where program start-up changes in 64-bit mode:

  • Dynamic path searching for shared libraries

  • Symbol searching in dependent libraries

It is recommended that you use the standard SVR4 linking option (+std, which is on by default) when linking 64-bit applications. If there are circumstances during the transition when you need 32-bit compatible linking behavior, use the +compat option. This option forces the linker to use 32-bit linking and dynamic loading behavior.

The following table summarizes the dynamic loader differences between 32-bit and 64-bit mode:

Table 2-10 Dynamic Loading Differences

Linker and Loader Functions

32-bit Mode Behavior

64-bit Mode Behavior

+s and +b path_list ordering

Ordering is significant.

Ordering is insignificant by default.

Use +compat to enforce ordering.

Symbol searching in dependent libraries

Depth first search order.

Breadth first search order.

Use +compat to enforce depth first ordering.

Run time path environment variables

No run time environment variables are available by default. If +s is specified, then SHLIB_PATH is available.

LD_LIBRARY_PATH and SHLIB_PATH are available.

Use +noenv or +compat to turn off run-time path environment variables.

+b path_list and -L directories interaction

-L directories recorded as absolute paths in executables.

-L directories are not recorded in executables.

Add all directories specified in -L to +b path_list.

 

For More Information:

Dynamic Path Searching for Shared Libraries

Dynamic path searching is the process that allows the location of shared libraries to be specified at run time. In 32-bit mode, you can enable run-time dynamic path searching of shared libraries in two ways:

  • by linking the program with +s, enabling the program to use the path list defined by the SHLIB_PATH environment variable at run time.

  • by storing a directory path list in the program with the linker option +b path_list.

If +s or +b path_list is enabled, all shared libraries specified with the -llibrary or -l:library linker options are subject to a dynamic path lookup at run time.

In 64-bit mode, the dynamic path searching behavior has changed:

  • The +s dynamic path searching option is enabled by default. It is not enabled by default in 32-bit mode.

  • The LD_LIBRARY_PATH environment variable is available in addition to the SHLIB_PATH environment variable.

  • An embedded run-time path list called RPATH may be stored in the executable. If +b path_list is specified at link time, these directories are added to RPATH. If +b path_list is not specified, the linker creates a default RPATH consisting of:

    1. directories in the -L option (if specified), followed by

    2. directories in the LPATH environment variable (if specified).

  • By default, in 64-bit mode, the linker ignores the ordering of the +b path_list and +s options.

  • At run time, the dynamic loader searches directory paths in the following order:

    • LD_LIBRARY_PATH (if set), followed by

    • SHLIB_PATH (if set), followed by

    • RPATH, followed by

    • the default locations /lib/pa20_64 and /usr/lib/pa20_64.

Examples

The following are examples of specifying library paths in 32-bit and 64-bit mode:

  • Linking to libraries by fully qualifying paths:

    In this example, the program is linked with /opt/myapp/mylib.sl:

    $ cc main.o /opt/myapp/mylib.sl                   Perform 32-bit link. $ cc +DD64 main.o /opt/myapp/mylib.sl   Perform 64-bit link. 

    At run-time, in both 32-bit and 64-bit mode, the dynamic loader only looks in /opt/myapp to find mylib.sl.

  • Linking to libraries using the -llibrary or -l:library options:

    In this example, the +s option is not explicitly enabled at link time. Two versions of a shared library called libfoo.sl exist; a 32-bit version in /usr/lib and a 64-bit version in /usr/lib/pa20_64:

    $ cc main.o -lfoo -o main             Perform 32-bit link. 

    When linked in 32-bit mode, main will abort at run time if libfoo.sl is moved from /usr/lib. This is because the absolute path name of the shared library /usr/lib/libfoo.sl is stored in the executable.

    $ cc +DD64 main.o -lfoo -o main       Perform 64-bit link. 

    When linked in 64-bit mode, main will not abort at run time if libfoo.sl is moved, as long as SHLIB_PATH or LD_LIBRARY_PATH is set and point to libfoo.sl.

  • Linking to libraries using -L and +b path_list:

    The -L option is used by the linker to locate libraries at link time. The +b option is used to embed a library path list in the executable for use at run time.

    Here is the 32-bit mode example:

    $ cc main.o -L. -Wl,+b/var/tmp -lme    Link the program.
    $ mv libme.sl /var/tmp/libme.sl Move libme.sl. $ a.out Run the program.

    In 32-bit mode, the dynamic loader searches paths to resolve external references in the following order:

    1. /var/tmp to find libme.sl found

    2. /var/tmp to find libc.sl not found

    3. /usr/lib/libc.sl found

    Here is the 64-bit mode example:

    $ cc +DD64 main.o -L. -Wl,+b/var/tmp -lme  Link the program.
    $ mv libme.sl /var/tmp/libme.sl Move libme.sl.
    $ a.out Run the program.

    In 64-bit mode, the dynamic loader searches paths to resolve external references in the following order:

    1. LD_LIBRARY_PATH (if set) to find libme.sl not found

    2. SHLIB_PATH (if set) to find libme.sl not found

    3. /var/tmp to find libme.sl found

    4. LD_LIBRARY_PATH (if set) to find libc.sl not found

    5. SHLIB_PATH (if set) to find libc.sl not found

    6. /var/tmp to find libc.sl not found

    7. /usr/lib/pa20_64/libc.sl found

Symbol Searching in Dependent Libraries

In 64-bit mode, the dynamic loader searches shared libraries using a breadth-first search order. Breadth-first symbol searching is used on all SVR4 platforms.

In 32-bit mode, the dynamic loader searches shared libraries using a depth-first search order.

Figure 2-1 “Search Order of Dependent Libraries” shows an example program with shared libraries and compares the two search methods:

Figure 2-1 Search Order of Dependent Libraries

Search Order of Dependent Libraries

The commands to build the libraries and the executable in Figure 2-1 “Search Order of Dependent Libraries” are shown:

ld -b lib2.o -o lib2.sl
ld -b lib3.o -o lib3.sl
ld -b lib1.o -L. -l3 -o lib1.sl
cc main.o -Wl,-L. -l1 -l2 -o main

In 32-bit mode, if a procedure called same_name() is defined in both lib3.sl and lib2.sl, main calls the procedure defined in lib3.sl. In 64-bit mode, main calls the procedure in lib2.sl.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1998 Hewlett-Packard Development Company, L.P.