Overview [ Micro Focus COBOL System Reference, Volume 1 ] MPE/iX 5.0 Documentation
Micro Focus COBOL System Reference, Volume 1
Overview
The Micro Focus COBOL System allows for three types of linking:
* dynamic linking
A dynamically linked program loads a shared library into memory at
run time if any function in the shared object (.so) fileis
referenced. A shared libraryis not stored in any executable, so
only one copy is required. (Available only if your system
supports dynamic linking.)
* static linking
A statically linked program is a standard system executable object
module. The linker pulls in any object files (usually from an
archive) required to satisfy all external reference calls, loads
them into an executable at link time and saves them to file.
* dynamic loading
A dynamically loadable program is either a COBOL intermediate code
(.int) fileor a COBOL generated code (.gnt) file. It is invoked
by a statically linked executing program. At run time, the
statically linked program calls the dynamic loader which loads the
dynamically loadable program from disk into memory and executes
it.
Dynamically or statically linking programs has the advantage that it
enables more than one user to share programs in a multi-user environment.
It also enables programs to call other programs within the same suite,
with the maximum possible speed. It also enables calls to programs
written in languages other than COBOL.
The following sections describe these three types of linking and provide
guidance on when you might choose one over the other.
Dynamic Linking
Dynamic linking is available only if it is supported by your system
(check if the module libcobol.so exists in $COBDIR/coblib). Dynamically
linked code uses shared object (.so) moduleswhich are left on disk until
required at run time. A shared object is an a.out format file produced
by the system linker which, unlike a runnable object, lacks an initial
entry point. Shared object modules can be used as a library which saves
disk space and enables one copy to be shared between several different
processes.
If the appropriate shared object library cannot be found, the equivalent
archive library (.a) is used instead. In this case, the library is
statically linked (see the section Static Linking). The startup code of
any executable module that uses dynamic linking will always be statically
linked.
To execute a dynamically linked program, you enter the program-name and
any parameters at the UNIX prompt, having previously set the
LD_LIBRARY_PATH environment variable. See the appendix Micro Focus
Environment Variables for details.
Dynamic linking provides a number of advantages over static linking.
Because the executable module contains only the name of the shared
library rather than its contents, the size of the executable module is
greatly reduced. Similarly, since the linker is not actually linking in
the library, linking is much faster. The memory used by a shared library
at run time can be shared between more than one run time system or
application.
Static Linking
Statically linked code is in the form of a standard system executable
object module which has all of its code permanently linked into the file.
In this case, the required run-time support libraries or object modules
are linked to your generated application. To execute a statically linked
application, all you need to do is enter its name at the UNIX system
prompt. See the chapter Running for details.
It is possible that static linking could use more memory than a
dynamically loaded program, which would make the size of the available
memory a constraint. This problem would occur only if there were few
copies of the same program being executed at once. If there were many
copies of the same program, then the text portion of the application will
be shared, resulting in less memory usage overall. Additionally, static
linking can result in large executable files, which on some systems may
cause performance problems or memory limitations.
If you want your program to CALL another program which is written in a
different language, the called program must be statically linked either
to the RTS or your executable program.
Dynamic Loading
Dynamically loaded code can be either COBOL intermediate code (.int)
files or COBOL generated code (.gnt) files. In this case, these programs
are executed under the control of the RTS, which dynamically loads the
specified intermediate and/or generated code files. You use the cobrun
command to execute dynamically loadable code. See the chapter Running
for full details.
Dynamic loading of programs is especially suitable for development
environments. This is because it enables you to debug parts of your
program, while the rest of it is running, and to reload the amended part
of your code without needing to reload the whole application.
Dynamically loaded programs should also be used in environments where the
amount of memory available is limited, as this enables you to have full
use of the memory management tools provided by the Micro Focus COBOL
dynamic loader. This enables you to control the amount of memory
required by your application.
Depending on the options you submit to the cob command, you can also
output a generated application program to which the dynamic loader, and
the necessary run-time support modules to load intermediate and generated
code files, are already linked. In this case, it is the run-time support
module linked to the application that controls the execution of the
program, while the dynamic loader linked to the application enables
intermediate and generated code files to be dynamically loaded.
When you are designing a COBOL application program, you will want to do
this in a way which makes the most efficient use of the available memory.
For maximum efficiency, you would generally use a mixture of dynamic and
static modules in your programs. However, if the size of the dynamic
loader is not larger than your dynamic programs, a static linking is
preferable. See the chapter Writing Programs in your COBOL User Guide
for further details.
MPE/iX 5.0 Documentation