Dynamic Loading

UNIX normally requires the names of all called programs, and the called programs themselves, to be provided at link time. With Visual COBOL, however, you can run programs without first linking them to system executables; these programs are dynamically loadable. The COBOL run-time system provides a dynamic loader that can load and execute dynamically loadable COBOL programs or subprograms.

The types of executable file that can be dynamically loaded are callable shared objects, .int files and .gnt files. Callable shared objects enable any type of program or subprogram (for example, COBOL, C or C++) to be dynamically loaded. For .int and .gnt files only COBOL programs or subprograms can be dynamically loaded. These files do not require linking to a system executable, although they do need a system executable as a trigger; Visual COBOL provides the cobrun program (cobrun_t for multi-threaded applications), which you can use as a trigger (see the chapter Running for details).

Programs and submodules loaded using dynamic loading do not need to be linked to a system executable, which speeds the compile-to-run process, and gives increased run-time flexibility. For example, you can modify and recompile a dynamically loaded submodule without affecting any other part of the application, and without needing to relink a system executable.

The COBOL system enables each call to a program to be either linked directly to the program, if it is available at link time, or to be linked to the dynamic loader. At run time the dynamic loader searches for the named program and, if necessary, dynamically loads it.

The program name can be provided to the dynamic loader as either a literal or as the value of a data item. The dynamic loader searches for the named program in the following places:

  1. The list of linked programs, subprograms and routines in memory. The list also records the states of the programs, subprograms and routines. The states are:
    • Active - The program or routine (which must be recursive) is still on the call-stack
    • Inactive - The program or routine has been called, control has returned to the calling program, but the called program or routine has not been canceled
    • Initialized - The program or routine is in the system executable, a shared library, or a loaded callable shared object, but has yet to be called
    • Logically cancelled - The program or routine has been called and cancelled, but not yet purged from memory (see the -l (lower case "L") run-time switch).
  2. The file system for a dynamically loadable file for the program.

You can use flags to the cob command to explicitly name the programs that you want to be linked and directly referenced and those that you want to be dynamically loaded. Without explicit instructions, cob takes default actions that depend on how the COBOL source calls the program.