Efficient use of the ld command

The binder (invoked as the final stage of a compile or directly by the ld command) has functions that are not found in the typical UNIX linker.

This situation can result in longer linking times if the additional power of the operating system binder is not exploited. This section describes some techniques for more efficient use of the binder.

Examples

Following is an example that illustrates efficient use of the ld command:

  1. To prebind a library, use the following command on the archive file:
    # ld -r libfoo.a -o libfooa.o
  2. The compile and bind of the FORTRAN program something.f is as follows:
    # xlf something.f libfooa.o

    Notice that the prebound library is treated as another ordinary input file, not with the usual library identification syntax (-lfoo).

  3. To recompile the module and rebind the executable program after fixing a bug, use the following:
    # xlf something.f a.out
  4. However, if the bug fix had resulted in a call to a different subroutine in the library, the bind would fail. The following Korn shell script tests for a failure return code and recovers:
    # !/usr/bin/ksh
    # Shell script for source file replacement bind
    #
    xlf something.f a.out
    rc=$?
    if [ "$rc" != 0 ]
    then
    echo "New function added ... using libfooa.o"
    xlf something.o libfooa.o
    fi