DLL Programmer's Guide for TNS/R Systems

Finding Symbol Definitions
DLL Programmers Guide for TNS/R Systems522203-002
4-11
The SearchList for a Semi-Globalized Loadfile
Perhaps more surprising, if a DLL references its own global symbol definition, one
might think that this definition would always be used to satisfy this DLL. However, as
we saw earlier in Ambiguity Example 1 on page 4-8, the loader can preempt the
linker’s setting and decide to import that symbol. So, if a DLL is globalized, any of its
references might be satisfied by a symbol of the same name in some other loadfile.
Therefore, in the above example, if F references john in addition to offering it for
export, then because F is globalized, the loader binds F’s reference to A’s definition
instead of F’s.
B’s and F’s programmers can avoid this substitution by declaring both B and F to be
localized. This assures that in resolving B’s imported symbols, the linker and the loader
use B’s localized searchList (in this case: F); it also assures that F uses its own
definition of john. Note, however, that if any other globalized loadfile in the list needs
john, it still gets the definition from A. So, for example, if B is localized and F is
globalized, B uses F’s definition of john, but F uses As.
Ambiguity Caution
The UNIX environment standardizes on globalized import controls, and hence, accepts
symbol ambiguity; but it can be dangerous and is often undesirable, because a symbol
might be resolved in a way that the programmer did not anticipate. Like UNIX, TNS/R
permits ambiguity in the globalized case, and the loader issues no warning about it. On
the other hand, this mechanism ensures that all globalized loadfiles in a process will
consistently use the same definition for a given symbol.
The SearchList for a Semi-Globalized Loadfile
Localizing a DLL prevents a locally referenced and defined symbol from being resolved
by an external definition. But should the DLL need to be globalized to resolve other
symbols, declaring it semi-globalized might solve the problem.
A semi-globalized searchList for a given loadfile is identical to the globalized searchList
except that the given loadfile’s name is ordered at the beginning of the searchList. For
example, in Figure 4-5 on page 4-10, if F is declared semi-globalized, then to resolve
F’s imported symbols the loader will use the searchList: F, Program, UL, A, B, C, H, D,
E, and G. As a result, F uses its own exported symbols; and hence, the loader will bind
F’s reference to john to its own definition of john.
Semi-globalized import exists primarily for compatibility with the conventional UNIX
option -B symbolic. Like localized import, it prevents preemption of definitions.
Localized import provides finer control.
Import Control Summary
This table summarizes the effects of the three import options that you can apply when
linking your loadfile. Both -b globalized and -b semi_globalized (or its synonym
-b symbolic) invoke a sort range that includes every loadfile in the loadList of the
program. On the other hand, -b localized restricts the range to within the loadlist