|
|
A shared library is similar in function to a normal, non-shared library, except that programs that link with a shared library share the library code during execution, whereas programs that link with a non-shared library get their own copy of each library routine used.
The host shared library is an archive that is used to link-edit user programs with the shared library (see ar(FP)). A host shared library can be treated exactly like a non-shared library and should be included on cc command lines in the usual way (see cc(CP)). Further, all operations that can be done on an archive can also be done on the host shared library.
The target shared library is an executable module that is bound into the user's address space during execution of a program using the shared library. The target shared library contains the code for all the routines in the library and must be fully resolved. The target is brought into memory during execution of a program using the shared library, and subsequent processes that use the shared library share the copy of code already in memory. The text of the target is always shared, but each process gets its own copy of the data.
The user interface to mkshlib consists of command line options and a shared library specification file. The shared library specification file describes the contents of the shared library.
The mkshlib command invokes other tools such as the archiver, ar(CP), the assembler, as(CP), and the link editor, ld(CP). Tools are invoked through the use of execvp( ) (see exec(S)), which searches directories in the user's PATH. Also, prefixes to mkshlib are passed in the same way as prefixes to the cc(CP) command, and invoked tools are given the prefix, where appropriate. For example, i386mkshlib invokes i386ld.
mkshlib recognizes the following command line options:
The shared library specification file contains all the information necessary to build both the host and target shared libraries. The contents and format of the specification file are given by the directives listed below.
All directives that can be followed by multi-line specifications are valid until the next directive or the end of the file.
Branch table specification lines have the following format:
funcname <white space> position
where funcname is the name of the symbol given a branch table entry and position specifies the position of funcname's branch table entry. position can be a single integer or a range of integers of the form position1-position2. Each position must be greater than or equal to one, the same position can not be specified more than once, and every position, from one to the highest given position, must be accounted for.
If a symbol is given more than one branch table entry by associating a range of positions with the symbol or by specifying the same symbol on more than one branch table specification line, then the symbol is defined to have the address of the highest associated branch table entry. All other branch table entries for the symbol are ``empty'' slots and can be replaced by new entries in future versions of the shared library. Only functions should be given branch table entries, and those functions must be external symbols.
This directive must be specified exactly once per shared library specification file.
This directive must be specified exactly once per shared library specification file.
Each name given is assumed to be a path name to a host or an
argument of the form -lX, where
libX.a
is the name of a file in LIBDIR or
LLIBDIR. This behavior is identical to
that of ld, and the
-L option can be used on the command line to specify
other directories in which to locate these archives.
If a host shared library is specified using
#objects noload, any cc command that links
to the shared library being built needs to specify that host also.
The optional * is equivalent to the directive
#hide linker *and causes all external symbols to be made into static symbols.
All symbols specified in #init and #branch
directives are assumed to be external symbols, and
cannot be changed into static symbols using the
#hide directive.
#hide linker * #export linker one two
Initialization specification lines have the following format:
ptr <white space> import
ptr is a pointer to the associated imported symbol,
import, and must be defined in the current specified
object file, object.
The initialization code generated for each such line is of the form:
ptr = &import ;
All initializations for a particular object file must be given
once and multiple specifications of the same object file are not allowed.
If mkshlib is asked to create a host library and a host of that name already exists, mkshlib updates the host using ar -ru. Therefore, always remove the host before rebuilding whenever an object file previously included in the library is removed or renamed.
If the address specified with the #address directive is outside user space, the library build may look successful, but if you try to use it, it might not work.
``Shared libraries'' in the Programming Tools Guide