Expand on shared object's `.init' functions a bit, and mention

`/usr/lib/c++rt.o'.
This commit is contained in:
pk 1997-11-13 22:25:23 +00:00
parent 2516dd1548
commit f58457ccca
2 changed files with 74 additions and 10 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: rtld.1,v 1.5 1997/06/20 20:38:08 pk Exp $
.\" $NetBSD: rtld.1,v 1.6 1997/11/13 22:25:23 pk Exp $
.\"
.\" Copyright (c) 1995 Paul Kranenburg
.\" All rights reserved.
@ -55,7 +55,35 @@ proceeds to resolve external references from both the main program and
all objects loaded. A mechanism is provided for initialisation routines
to be called, on a per-object basis, giving a shared object an opportunity
to perform any extra set-up, before execution of the program proper begins.
This is useful for C++ libraries that contain static constructors.
.Nm
looks for a symbol named
.Em .init
in each object's symbol table. If present, this symbol is assumed to
represent a C-function declared as
.Ft void
.Fn .init "void" ,
which is then called. Similarly, a
.Ft void
.Fn .fini "void"
function is called just before an object is unloaded from the process
address space as a result of calling
.Xr dlclose 3 .
Note that while an object's
.Em .init
is always called, whether the object is loaded automatically at program
startup or programatically by using
.Xr dlopen 3 ,
the
.Em .fini
function is called only on
.Sq last Xr dlclose 3 .
.Pp
This mechanism is exploited by the system-supplied C++ constructor
initialization code located in
.Pa /usr/lib/c++rt.o .
This file should be included in the list of object-code files passed to
.Xr ld 1
when building a shared C++ library.
.Pp
.Nm
is itself a shared object that is initially loaded by the startup module
@ -79,7 +107,7 @@ are needed
see
.Xr link 5
for details
.Pc \&.
.Pc Ns \&.
.Em crt0
passes control to
.Nm rtld Ns 's
@ -100,7 +128,7 @@ utility, in which the full path specification of the shared objects can be
looked up by hashing on the 3-tuple
.Ao
library-name, major-version-number, minor-version-number
.Ac \&.
.Ac Ns \&.
.Pp
.Nm
recognises a number of environment variables that can be used to modify
@ -173,7 +201,11 @@ non-standard filesystem layout.
.El
.Pp
.Sh FILES
/var/run/ld.so.hints
.Bl -tag -width /var/run/ld.so.hintsXXX -compact
.It Pa /var/run/ld.so.hints
library location hints built by
.Xr ldconfig 8
.El
.Pp
.Sh SEE ALSO
.Xr ld 1 ,

View File

@ -1,4 +1,4 @@
.\" $NetBSD: rtld.1,v 1.5 1997/06/20 20:38:08 pk Exp $
.\" $NetBSD: rtld.1,v 1.6 1997/11/13 22:25:23 pk Exp $
.\"
.\" Copyright (c) 1995 Paul Kranenburg
.\" All rights reserved.
@ -55,7 +55,35 @@ proceeds to resolve external references from both the main program and
all objects loaded. A mechanism is provided for initialisation routines
to be called, on a per-object basis, giving a shared object an opportunity
to perform any extra set-up, before execution of the program proper begins.
This is useful for C++ libraries that contain static constructors.
.Nm
looks for a symbol named
.Em .init
in each object's symbol table. If present, this symbol is assumed to
represent a C-function declared as
.Ft void
.Fn .init "void" ,
which is then called. Similarly, a
.Ft void
.Fn .fini "void"
function is called just before an object is unloaded from the process
address space as a result of calling
.Xr dlclose 3 .
Note that while an object's
.Em .init
is always called, whether the object is loaded automatically at program
startup or programatically by using
.Xr dlopen 3 ,
the
.Em .fini
function is called only on
.Sq last Xr dlclose 3 .
.Pp
This mechanism is exploited by the system-supplied C++ constructor
initialization code located in
.Pa /usr/lib/c++rt.o .
This file should be included in the list of object-code files passed to
.Xr ld 1
when building a shared C++ library.
.Pp
.Nm
is itself a shared object that is initially loaded by the startup module
@ -79,7 +107,7 @@ are needed
see
.Xr link 5
for details
.Pc \&.
.Pc Ns \&.
.Em crt0
passes control to
.Nm rtld Ns 's
@ -100,7 +128,7 @@ utility, in which the full path specification of the shared objects can be
looked up by hashing on the 3-tuple
.Ao
library-name, major-version-number, minor-version-number
.Ac \&.
.Ac Ns \&.
.Pp
.Nm
recognises a number of environment variables that can be used to modify
@ -173,7 +201,11 @@ non-standard filesystem layout.
.El
.Pp
.Sh FILES
/var/run/ld.so.hints
.Bl -tag -width /var/run/ld.so.hintsXXX -compact
.It Pa /var/run/ld.so.hints
library location hints built by
.Xr ldconfig 8
.El
.Pp
.Sh SEE ALSO
.Xr ld 1 ,