Linker and Libraries Guide

Default Symbol Lookup Model

For each object added by a basic dlopen(3C), the runtime linker first looks for the symbol in the dynamic executable. The runtime linker then looks in each of the objects provided during the initialization of the process. If the symbol is still not found, the runtime linker continues the search. The runtime linker next looks in the object acquired through the dlopen(3C) and in any of its dependencies.

The default symbol lookup model provides for transitioning into a lazy loading environment. If a symbol can not be found in the presently loaded objects, any pending lazy loaded objects are processed in an attempt to locate the symbol. This loading compensates for objects that have not fully defined their dependencies. However, this compensation can undermine the advantages of a lazy loading.

In the following example, the dynamic executable prog and the shared object have the following dependencies.

$ ldd prog =>        ./
$ ldd =>        ./

If prog acquires the shared object by dlopen(3C), then any symbol required to relocate the shared objects and will first be looked for in prog, followed by, followed by, and finally in In this simple case, think of the shared objects acquired through the dlopen(3C) as if they had been added to the end of the original link-edit of the application. For example, the objects referenced in the previous listing can be expressed diagrammatically as shown in the following figure.

Figure 3–1 A Single dlopen() Request

A single dlopen() request.

Any symbol lookup required by the objects acquired from the dlopen(3C), that is shown as shaded blocks, proceeds from the dynamic executable prog through to the final shared object

This symbol lookup is established by the attributes assigned to the objects as they were loaded. Recall that the dynamic executable and all the dependencies loaded with the executable are assigned global symbol visibility, and that the new objects are assigned world symbol search scope. Therefore, the new objects are able to look for symbols in the original objects. The new objects also form a unique group in which each object has local symbol visibility. Therefore, each object within the group can look for symbols within the other group members.

These new objects do not affect the normal symbol lookup required by either the application or the applications initial dependencies. For example, if requires a function relocation after the previous dlopen(3C) has occurred, the runtime linker's normal search for the relocation symbol is to look in prog and then The runtime linker does not follow through and look in or

This symbol lookup is again a result of the attributes assigned to the objects as they were loaded. The world symbol search scope is assigned to the dynamic executable and all the dependencies loaded with it. This scope does not allow them to look for symbols in the new objects that only offer local symbol visibility.

These symbol search and symbol visibility attributes maintain associations between objects. These associations are based on their introduction into the process address space, and on any dependency relationship between the objects. Assigning the objects associated with a given dlopen(3C) to a unique group ensures that only objects associated with the same dlopen(3C) are allowed to look up symbols within themselves and their related dependencies.

This concept of defining associations between objects becomes more clear in applications that carry out more than one dlopen(3C). For example, suppose the shared object has the following dependency.

$ ldd =>         ./

and the prog application used dlopen(3C) to load this shared object in addition to the shared object The following figure illustrates the symbol lookup releationship between the objects.

Figure 3–2 Multiple dlopen() Requests

Multiple dlopen() requests.

Suppose that both and contain a definition for the symbol foo, and both and contain a relocation that requires this symbol. Because of the association of objects to a unique group, is bound to the definition in, and is bound to the definition in This mechanism is intended to provide the most intuitive binding of objects that are obtained from multiple calls to dlopen(3C).

When objects are used in the scenarios that have so far been described, the order in which each dlopen(3C) occurs has no effect on the resulting symbol binding. However, when objects have common dependencies, the resultant bindings can be affected by the order in which the dlopen(3C) calls are made.

In the following example, the shared objects and have the same common dependency.

$ ldd =>        ./
$ ldd =>        ./

In this example, the prog application will dlopen(3C) each of these shared objects. Because the shared object is a common dependency of both and, is assigned to both of the groups that are associated with the two dlopen(3C) calls. This relationship is shown in the following figure.

Figure 3–3 Multiple dlopen() Requests With A Common Dependency

Multiple dlopen() requests with a common dependency. is available for both and to look up symbols. More importantly, as far as dlopen(3C) ordering is concerned, is also be able to look up symbols in both and

Therefore, if both and contain a definition for the symbol foo, which is required for a relocation, the actual binding that occurs is unpredictable because it is affected by the order of the dlopen(3C) calls. If the functionality of symbol foo differs between the two shared objects in which it is defined, the overall outcome of executing code within might vary depending on the application's dlopen(3C) ordering.