DLL Programmer's Guide for TNS/R Systems

DLL Programmer’s Guide for TNS/R Systems522203-002
1-1
1 DLLs on a TNS/R System
This section explains the TNS/R DLL (dynamic-link library) facility– what DLLs are,
how they work, how they can be used, and the basic workings of the tools that create
them. This facility comprises the linker (ld), the loader (rld), and the portions of the
H-P NonStop™ Kernel (NSK) operating system used in loading libraries. The facility
runs in either the OSS or Guardian environments; and on auxiliary Windows systems,
you can construct, but not load, TNS/R applications that use DLLs.
The Glossary section of this document provides a reference for the terms used herein,
and the first use in the text of each glossary reference is in bold type.
Libraries and Symbols
As used here, a library is a loadable object or code file (or loadfile), that offers
functions and data for use by other loadable code files. In a library, each such function
and data item has its own symbolic name, as defined in its original source. This
symbolic name is known as a symbol, and the function or data offered under this
name is called the symbol definition.
Code that needs a function or data item refers to that function or data by its symbolic
name; such a reference is called a symbolic reference. Thus, a symbolic reference is
the requisition for or the use of the symbol’s definition. A symbolic reference is satisfied
by assigning to it the symbol value, which is the virtual address of the symbol’s
definition. The process of assigning that value is called binding or resolving the
symbolic reference. At load time, for every symbolic reference in every loadfile, the
system finds the program or a library that offers a function or data item having the
same name, and it binds that reference to a corresponding definition.
Figure 1-1 on page 1-2 is an example of how this binding works; while this example is
illustrative, it is not entirely realistic, for instance, in the numbers used for virtual
addresses. The upper portion of this figure shows the situation before the loadfiles are
loaded. A loadfile on the left, called H, which may be a program or a library, contains a
reference to a symbol, Joe. Three libraries are shown on the right; library J is 5000
byte long; library K is 3000 bytes long; and library L is 4000 bytes long. Lib K contains
a definition of Joe, that has an entry point offset 1300 bytes from the start of that
library.
The lower portion of Figure 1-1 shows the situation after the four code files are loaded
in a process. The loader placed the three libraries contiguously starting at some virtual
address, say, 10000. This means that the definition of Joe is now located at virtual
address 16300; therefore, this is the value of Joe. The loader has resolved, or bound,
the reference in H to Joe by replacing the symbol in H with the value of Joe, namely,
16300.
A loadfile exports a symbol when it defines a symbol that can be used by another
loadfile. A loadfile imports a needed symbol when that symbol reference in the
program or DLL is or will be set to the value (address) of a symbol of the same name