Actors and processes are defined according to the types of libraries they use. This section describes the different library types in the ChorusOS operating system and illustrates the kinds of actors and processes that would use each library type.
There are three types of library in the ChorusOS operating system:
Static library names are suffixed by .a. The static library is a collection of binary object files (.o). The linker concatenates all required binary objects within the static libraries into an executable program file.
Dynamic
Dynamic library names are suffixed by .so and can be linked with a program at runtime. Dynamic linking is supported by a ChorusOS operating system component named the runtime linker (see "Runtime Linker"). There are two two cases in which dynamic linking occurs:
At actor start-up - in order to build the executable, the runtime linker loads and links a list of libraries. These libraries are known as the dependencies of the executable.
During actor execution - with the dynamic linking API, an actor can explicitly load and link to dynamic libraries using the dlopen() function. This facilitates dynamic programming.
Dynamic libraries are loaded at runtime and are not included in the executable. This reduces the size of executable files. Dynamic libraries use relocatable code format. This code is turned into absolute code by the runtime linker.
In the ChorusOS operating system, both user and supervisor actors (but not boot actors) can use dynamic libraries.
Shared
Shared libraries are also suffixed by .so. Like dynamic libraries, shared libraries can be dynamically linked but unlike dynamic libraries, they are not duplicated in physical memory. When two actors, each with its own private copy of data, use the same shared library, only one instance of the library is present in physical memory.
Shared libraries use Position Independent Code (PIC). In PIC, references to global symbols are made indirectly through symbol tables. References to global symbols, as well as local jumps are made relative to the program counter. This code, as a result, can run anywhere in memory without being modified, however, the tables must be relocated first before program execution can begin. Using PIC in shared libraries does not perform as well as the code in dynamic libraries because the global symbol information is accessed through indirect references.
To compile an application in PIC, you must set the following feature in your Imakefile:
FPIC = ON
The FLARGEGOT feature complements the FPIC feature. Setting FLARGEGOT = ON enables support for large tables of global symbols.
Both dynamic and shared library names are suffixed by .so. However, each library type is built in a different way and is readily distinguished. The imake tool does not check that library components are PIC format binary object files. The resulting library may contain .o objects, which are not in PIC format, that can still be dynamically loaded but can no longer be shared.
It is possible to check whether or not a library is shared. To check whether or not the libfoo.so library is shared, for example, run the following GNU command:
% objdump -x libfoo.so | grep TEXTREL |
objdump is located in the chorus_family/tools tree. The specific path includes a family-dependent prefix.
If the library is shared, no output is generated by this command. Only dynamic library object files contain references to TEXTREL.
Actors or processes can be divided into two groups, according to the types of libraries they use.
Relocatable actors and processes
Upon actor start-up, the runtime linker loads the actor and performs the necessary relocations. A relocatable actor or process uses only static libraries.
Dynamic actors/processes
Upon actor start-up, the runtime linker loads the actor or process and performs the necessary relocations. It also loads and links the actor dependencies (the required dynamic libraries).
When you build a process or actor other than an embedded actor, you must specify one of the following macros in your Imakefile:
Relocatable processes/actors:
UserActorTarget
SupActorTarget
CXXUserTarget
CXXSupTarget
Dynamic processes/actors:
DynamicUserTarget
DynamicSupTarget
DynamicCXXUserTarget
DynamicCXXSupTarget
Shared processes/actors:
SharedUserTarget
SharedSupTarget
SharedCXXUserTarget
SharedCXXSupTarget
Each of these rules implicitly calls the libc.a or libc.so libraries. Therefore, when creating the Imakefile for a process or actor, there is no need to think about the libc.a or libc.so libraries because this is taken care of when you select the Imakefile rule. The C++ library is automatically included by specifying CXX in the relevant Imakefile rule.