LINK(5)LINK(5)NAMElink - 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 dur‐
ing program execution. These data structures are described with a
link_dynamic structure, as defined in the link.h file. ld always iden‐
tifies 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 functional‐
ity 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 instruc‐
tion that will be executed after the call to ld.so
returns. This location is used as a breakpoint in pro‐
grams that are being executed under the control of a
debugger such as adb(1).
SEE ALSOld(1), mmap(2), a.out(5)BUGS
These interfaces are under development and are subject to rapid change.
17 February 1988 LINK(5)