LINK(5)

NAME
link - link editor interfaces

SYNOPSIS
#include <link.h>

DESCRIPTION

Dynamically linked executables created by ld(1) contain data structures used by the dynamic link editor to finish link-editing the program during program execution. These data structures are described with a link_dynamic structure, as defined in the link.h file. ld always identifies the location of this structure in the executable file with the symbol __DYNAMIC. This symbol is ld-defined and if referenced in an executable that does not require dynamic linking will have the value zero.

The program stub linked with ``main'' programs by compiler drivers such as cc(1V) (called crt0) tests the definition of __DYNAMIC to determine whether or not the dynamic link editor should be invoked. Programs supplying a substitute for crt0 must either duplicate this functionality or else require that the programs with which they are linked be linked statically. Otherwise, such replacement crt0's must open and map in the executable /usr/lib/ld.so using mmap(2). Care should be taken to ensure that the expected mapping relationship between the ``text'' and ``data'' segments of the executable is maintained in the same manner that the execve(2V) system call does. The first location following the a.out header of this executable is the entry point to a function that begins the dynamic link-editing process. This function must be called and supplied with two arguments. The first argument is an integer representing the revision level of the argument list, and should have the value ``1''. The second should be a pointer to an argument list structure of the form:

    struct {
    	int	crt_ba;			/* base address of ld.so */
    	int	crt_dzfd;		/* open fd to /dev/zero */
    	int	crt_ldfd;		/* open fd to ld.so */
    	struct	link_dynamic *crt_dp;	/* pointer to program's __DYNAMIC */
    	char	**crt_ep;		/* environment strings */
    	caddr_t	crt_bp;			/* debugger hook */
    }

The members of the structure are:

crt_ba
    The address at which /usr/lib/ld.so has been mapped.

crt_dzfd
    An open file descriptor for /dev/zero. ld.so will close this file descriptor before returning.

crt_ldfd
    The file descriptor used to map /usr/lib/ld.so. ld.so will close this file descriptor before returning.

crt_dp
    A pointer to the label __DYNAMIC in the executable which is calling ld.so.

crt_ep
    A pointer to the environment strings provided to the program.

crt_bp
    A location in the executable which contains an instruction that will be executed after the call to ld.so returns. This location is used as a breakpoint in programs that are being executed under the control of a debugger such as adb(1).

SEE ALSO
ld(1), mmap(2), a.out(5)

BUGS
These interfaces are under development and are subject to rapid change.