reflect some changes over the last 6 months.

This commit is contained in:
pk 1994-06-09 15:52:17 +00:00
parent 1cb2ed4f0b
commit 730768feb0
1 changed files with 214 additions and 158 deletions

View File

@ -1,3 +1,34 @@
.\"
.\" Copyright (c) 1993 Paul Kranenburg
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by Paul Kranenburg.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: link.5,v 1.2 1994/06/09 15:52:17 pk Exp $
.\"
.Dd October 23, 1993
.Dt LINK 5
.Os
@ -20,10 +51,10 @@ references to external entities. It also records a number of data structures
unique to the dynamic loading and linking process. These include references
to other objects that are required to complete the link-editing process and
indirection tables to facilitate
.Ev Position Independent Code (PIC for short)
to improve sharing of code pages among different processes.
.Em Position Independent Code
(PIC for short) to improve sharing of code pages among different processes.
The collection of data structures described here will be refered to as the
.Ev Run-time Relocation Section (RRS)
.Em Run-time Relocation Section (RRS)
and is embedded in the standard text and data segments of the dynamically
linked program or shared object image as the existing
.Xr a.out
@ -33,12 +64,12 @@ Several utilities cooperate to ensure that the task of getting a program
ready to run can complete successfully in a way that optimizes the use
of system resources. The compiler emits PIC code from which shared libraries
can be build by
.Ev ld.
.Xr ld 1.
The compiler also includes size information of any initialized data items
through the .size assembler directive. PIC code differs from conventional code
in that it accesses data variables through an indirection table, the
Global Offset Table, by convention accessable by the reserved name
.Ev _GLOBAL_OFFSET_TABLE_.
.Em _GLOBAL_OFFSET_TABLE_.
The exact mechanism used for this is machine dependent, usually a machine
register is reserved for the purpose. The rational behind this construct
is to generate code that is independent of the actual load address. Only
@ -55,13 +86,13 @@ when combining PIC object files into an image suitable for mapping into the
process address space. It also collects all symbols that may be needed by the
run-time link-editor and stores these along with the image's text and data bits.
Another reserved symbol,
.Ev _DYNAMIC
.Em _DYNAMIC
is used to indicate the presence of the run-time linker structures. Whenever
_DYNAMIC is relocated to 0, there is no need to invoke the run-time
link-editor. If this symbol is non-zero, it points at a data structure from
which the location of the necessary relocation- and symbol information can
be derived. This is most notably used by the start-up module,
.Ev crt0.
.Em crt0.
The _DYNAMIC structure is conventionally located at the start of the data
segment of the image to which it pertains.
.Pp
@ -73,192 +104,202 @@ names, while the data segments contain the tables that need to be modified by
during the relocation process.
.Pp
The _DYNAMIC symbol references a
.Fa link_dynamic
.Fa _dynamic
structure:
.Bd -literal -offset indent
struct link_dynamic {
int ld_version;
struct ld_debug *ldd;
struct _dynamic {
int d_version;
struct so_debug *d_debug;
union {
struct link_dynamic_2 *ld_2;
} ld_un;
struct ld_entry *ld_entry;
struct section_dispatch_table *d_sdt;
} d_un;
struct ld_entry *d_entry;
};
.Ed
.Bl -tag -width ld_version
.It Fa ld_version
.Bl -tag -width d_version
.It Fa d_version
This field provides for different versions of the dynamic linking
implementation. The current version numbers understood by ld and ld.so are
.Ev LD_VERSION_SUN (3),
.Em LD_VERSION_SUN (3),
which is used by the SunOS 4.x releases, and
.Ev LD_VERSION_BSD (8),
which is currently in use by NetBSD release 0.9a.
.It Fa ld_un
.Em LD_VERSION_BSD (8),
which is currently in use by NetBSD release 0.9B.
.It Fa d_un
Refers to a
.Ev ld_version
.Em d_version
dependent data structure.
.It Fa ldd_debug
.It Fa so_debug
this field provides debuggers with a hook to access symbol tables of shared
objects loaded as a result of the actions of the run-time link-editor.
.El
.Pp
The
.Fa link_dynamic_2
.Fa section_dispatch_table
structure is the main
.Dq dispatcher
table, containing offsets into the image's segments where various symbol
and relocation information is located.
.Bd -literal -offset indent
struct link_dynamic_2 {
struct link_map *ld_loaded;
long ld_need;
long ld_rules;
long ld_got;
long ld_plt;
long ld_rel;
long ld_hash;
long ld_symbols;
long (*ld_stab_hash)();
long ld_buckets;
long ld_strings;
long ld_str_sz;
long ld_text_sz;
long ld_plt_sz;
struct section_dispatch_table {
struct so_map *sdt_loaded;
long sdt_sods;
long sdt_filler1;
long sdt_got;
long sdt_plt;
long sdt_rel;
long sdt_hash;
long sdt_nzlist;
long sdt_filler2;
long sdt_buckets;
long sdt_strings;
long sdt_str_sz;
long sdt_text_sz;
long sdt_plt_sz;
};
.Ed
.Pp
.Bl -tag -width ld_stab_hash
.It Fa ld_loaded
.Bl -tag -width sdt_filler1
.It Fa sdt_loaded
A pointer to the first link map loaded (see below). This field is set by
.Xr ld.so.
.It Fa ld_need
The start of a (linked) list of shared objects needed by
.Ev this
.It Fa sdt_sods
The start of a (linked) list of shared object descriptors needed by
.Em this
object.
.It Fa ld_rules
.It Fa sdt_filler1
Depricated (used by SunOS to specify library search rules).
.It Fa ld_got
.It Fa sdt_got
The location of the Global Offset Table within this image.
.It Fa ld_plt
.It Fa sdt_plt
The location of the Procedure Linkage Table within this image.
.It Fa ld_rel
.It Fa sdt_rel
The location of an array of
.Fa relocation_info
structures (see
.Xr a.out 5)
structures
.Po
see
.Xr a.out 5
.Pc
specifying run-time relocations.
.It Fa ld_hash
.It Fa sdt_hash
The location of the hash table for fast symbol lookup in this object's
symbol table.
.It Fa ld_symbols
.It Fa sdt_nzlist
The location of the symbol table.
.It Fa ld_stab_hash
.It Fa sdt_filler2
Currently unused.
.It Fa ld_buckets
.It Fa sdt_buckets
The number of buckets in
.Fa ld_hash
.It Fa ld_strings
.Fa sdt_hash
.It Fa sdt_strings
The location of the symbol string table that goes with
.Fa ld_symbols.
.It Fa ld_str_sz
.Fa sdt_nzlist.
.It Fa sdt_str_sz
The size of the string table.
.It Fa ld_text_sz
.It Fa sdt_text_sz
The size of the object's text segment.
.It Fa ld_plt_sz
.It Fa sdt_plt_sz
The size of the Procedure Linkage Table.
.El
.Pp
A
.Fa link_object
.Fa sod
structure descibes a shared object that is needed
to complete the link edit process of the object containing it.
A list of such objects (chained through
.Fa lo_next)
A list of such objects
.Po
chained through
.Fa sod_next
.Pc
is pointed at
by the
.Fa ld_need
in the link_dynamic_2 structure.
.Fa sdt_sods
in the section_dispatch_table structure.
.Bd -literal -offset indent
struct link_object {
long lo_name;
u_int lo_library : 1,
lo_unused : 31;
short lo_major;
short lo_minor;
long lo_next;
struct sod {
long sod_name;
u_int sod_library : 1,
sod_unused : 31;
short sod_major;
short sod_minor;
long sod_next;
};
.Ed
.Pp
.Bl -tag -width lo_library
.It Fa lo_name
.Bl -tag -width sod_library
.It Fa sod_name
The offset in the text segment of a string describing this link object.
.It Fa lo_library
.It Fa sod_library
If set,
.Fa lo_name
.Fa sod_name
specifies a library that is to be searched for by ld.so. The path name
is obtained by searching a set of directories (see
.Xr ldconfig)
is obtained by searching a set of directories
.Po
see also
.Xr ldconfig 8
.Pc
for a shared object matching
.Ev lib\&<lo_name>\&.so.n.m.
.Em lib\&<sod_name>\&.so.n.m.
If not set,
.Fa lo_name
.Fa sod_name
should point at a full path name for the desired shared object.
.It Fa lo_major
.It Fa sod_major
Specifies the major version number of the shared object to load.
.It Fa lo_minor
.It Fa sod_minor
Specifies the prefered minor version number of the shared object to load.
.El
.Pp
The run-time link-editor maintains a list of link maps to keep
track of all shared objects loaded into a process' address space.
The run-time link-editor maintains a list of structures called
.Em link maps
to keep track of all shared objects loaded into a process' address space.
These structures are only used at run-time and do not occur within
the text or data segment of an executable or shared library.
.Bd -literal -offset indent
struct link_map {
caddr_t lm_addr;
char *lm_name;
struct link_map *lm_next;
struct link_object *lm_lop;
caddr_t lm_lob;
u_int lm_rwt : 1;
struct link_dynamic *lm_ld;
caddr_t lm_lpd;
struct so_map {
caddr_t som_addr;
char *som_path;
struct so_map *som_next;
struct sod *som_sod;
caddr_t som_sodbase;
u_int som_write : 1;
struct _dynamic *som_dynamic;
caddr_t som_spd;
};
.Bl -tag -width ld_addr
.It Fa lm_addr
.Ed
.Bl -tag -width som_dynamic
.It Fa som_addr
The address at which the shared object associated with this link map has
been loaded.
.It Fa lm_name
.It Fa som_path
The full path name of the loaded object.
.It Fa lm_next
.It Fa som_next
Pointer to the next link map.
.It Fa lm_lop
.It Fa som_sod
The
.Fa link_object
structure that was responsible for this shared object to get loaded.
.It Fa lm_lob
Depricated.
.It Fa lm_rwt
Set if this object's text segment is currently writable.
.It Fa lm_ld
Pointer to this object
.Fa link_dynamic
.Fa sod
structure that was responsible for loading this shared object.
.It Fa som_sodbase
Tossed in later versions the run-time linker.
.It Fa som_write
Set if (some portion of) this object's text segment is currently writable.
.It Fa som_dynamic
Pointer to this object's
.Fa _dynamic
structure.
.It Fa lm_lpd
.It Fa som_spd
Hook for attaching private data maintained by the run-time link-editor.
.El
.Ed
.Pp
Symbol description with size. This is simply an
.Fa nlist
structure with one field (
.Fa nz_size
) added. Used to convey size information on items in the data segment
structure with one field
.Pq Fa nz_size
added. Used to convey size information on items in the data segment
of shared objects. An array of these lives in the shared object's
text segment and is addressed by the
.Fa ld_symbols
.Fa sdt_nzlist
field of
.Fa link_dynamic_2.
.Fa section_dispatch_table.
.Bd -literal -offset indent
struct nzlist {
struct nlist nlist;
@ -274,9 +315,10 @@ struct nzlist {
.Ed
.Bl -tag -width nz_size
.It Fa nlist
(see
.Po
see
.Xr nlist 5
).
.Pc .
.It Fa nz_size
The size of the data represented by this symbol.
.El
@ -284,9 +326,9 @@ The size of the data represented by this symbol.
A hash table is included within the text segment of shared object to
to facilitate quick lookup of symbols during run-time link-editing.
The
.Fa ld_hash
.Fa sdt_hash
field of the
.Fa link_dynamic_2
.Fa section_dispatch_table
structure points at an array of
.Fa rrs_hash
structures:
@ -311,9 +353,9 @@ The
structure is used to keep track of run-time allocated commons
and data items copied from shared objects. These items are kept on linked list
and is exported through the
.Fa ldd_cp
.Fa dd_cc
field in the
.Fa ld_debug
.Fa so_debug
structure (see below) for use by debuggers.
.Bd -literal -offset indent
struct rt_symbol {
@ -321,6 +363,7 @@ struct rt_symbol {
struct rt_symbol *rt_next;
struct rt_symbol *rt_link;
caddr_t rt_srcaddr;
struct so_map *rt_smp;
};
.Ed
.Pp
@ -333,82 +376,90 @@ Virtual address of next rt_symbol.
Next in hash bucket. Used by internally by ld.so.
.It Fa rt_srcaddr
Location of the source of initialized data within a shared object.
.It Fa rt_smp
The shared object which is the original source of the data that this
run-time symbol describes.
.El
.Pp
The
.Fa ld_debug
.Fa so_debug
structure is used by debuggers to gain knowledge of any shared objects
that have been loaded in the process's address space as a result of run-time
link-editing. Since the run-time link-editor runs as a part of process
initialization, a debugger that wishes to access symbols from shared objects
can only do so after the link-editor has been called from crt0.
A dynamically linked binary contains a
.Fa ld_debug
.Fa so_debug
structure which can be located by means of the
.Fa ldd
.Fa d_debug
field in
.Fa link_dynamic.
.Fa _dynamic.
.Bd -literal -offset indent
struct ld_debug {
int ldd_version;
int ldd_in_debugger;
int ldd_sym_loaded;
char *ldd_bp_addr;
int ldd_bp_inst;
struct rt_symbol *ldd_cp;
struct so_debug {
int dd_version;
int dd_in_debugger;
int dd_sym_loaded;
char *dd_bpt_addr;
int dd_bpt_shadow;
struct rt_symbol *dd_cc;
};
.Ed
.Pp
.Bl -tag -width ldd_in_debugger
.It Fa ldd_version
.Bl -tag -width dd_in_debugger
.It Fa dd_version
Version number of this interface.
.It Fa ldd_in_debugger
Set by the debugger to indicate to ld.so that the program is run under
control of a debugger.
.It Fa ldd_sym_loaded
Set by ld.so whenever it adds symbols by loading shared objects.
.It Fa ldd_bp_addr
The address were a breakpoint will be set by the ld.so to divert control to
the debugger. This address is determined by the start-up module,
.Ev crt0.o,
.It Fa dd_in_debugger
Set by the debugger to indicate to the run-time linker that the program is
run under control of a debugger.
.It Fa dd_sym_loaded
Set by the run-time linker whenever it adds symbols by loading shared objects.
.It Fa dd_bpt_addr
The address were a breakpoint will be set by the the run-time linker to
divert control to the debugger. This address is determined by the start-up
module,
.Em crt0.o,
to be some convenient place before the call to _main.
.It Fa ldd_bp_inst
.It Fa dd_bpt_shadow
Contains the original instruction that was at
.Fa ldd_bp_addr.
.Fa dd_bpt_addr.
The debugger is expected to put this instruction back before continuing the
program.
.It Fa ldd_cp
.It Fa dd_cc
A pointer to the linked list of run-time allocated symbols that the debugger
may interested in.
may be interested in.
.El
.Pp
.Bd -literal -offset indent
The
.Fa ld_entry
.Em ld_entry
structure defines a set of service routines within ld.so. See
.Ev libdl.a
.Xr libdl.a
for more information.
.Bd -literal -offset indent
struct ld_entry {
int (*dlopen)();
int (*dlclose)();
int (*dlsym)();
void *(*dlopen)(char *, int);
int (*dlclose)(void *);
void *(*dlsym)(void *, char *);
int (*dlctl)(void *, int, void *);
};
.Ed
.Bd -literal -offset indent
The
.Fa crt_ldso
structure defines the interface between the start-up code in crt0 and ld.so.
.Bd -literal -offset indent
struct crt_ldso {
int crt_ba;
int crt_dzfd;
int crt_ldfd;
struct link_dynamic *crt_dp;
struct _dynamic *crt_dp;
char **crt_ep;
caddr_t crt_bp;
char *crt_prog;
char *crt_ldso;
};
#define CRT_VERSION_SUN 1
#define CRT_VERSION_BSD 2
#define CRT_VERSION_BSD2 2
#define CRT_VERSION_BSD3 3
.Ed
.Bl -tag -width crt_dzfd
.It Fa crt_ba
@ -421,14 +472,19 @@ used to get demand paged zeroed pages. On NetBSD systems it contains -1.
Contains an open file descriptor that was used by crt0 to load ld.so.
.It Fa crt_dp
A pointer to main's
.Fa link_dynamic
.Fa _dynamic
structure.
.It Fa crt_ep
A pointer to the environment strings.
.It Fa crt_bp
The address at which a breakpoint will be placed by ld.so if run by a debugger.
The address at which a breakpoint will be placed by the run-time linker
if the main program is run by a debugger.
See
.Fa ld_debug
.Fa so_debug
.It Fa crt_prog
The name of the main program as determined by crt0 (CRT_VERSION_BSD3 only).
.It Fa crt_ldso
The path of the run-time linker as mapped by crt0 (CRT_VERSION_BSD4 only).
.El
.Pp
The
@ -500,6 +556,6 @@ Next bucket in case of hashing collisions.
.El
.Sh CAVEATS
Only the GNU C compiler currently supports the creation of shared libraries.
Only the (GNU) C compiler currently supports the creation of shared libraries.
Other programming languages can not be used.