Chapter 3 59
Linker Tasks
Using Linker commands
Nonfatal Shared Library Binding with -B nonfatal
The linker also supports nonfatal binding, which is useful with the -B
immediate option. Like immediate binding, nonfatal immediate binding
causes all required symbols to be bound at program startup. The main
difference from immediate binding is that program execution continues
even if the dynamic loader cannot resolve symbols. Compare this with
immediate binding, where unresolved symbols cause the program to
abort.
To use nonfatal binding, specify the -B nonfatal option along with the
-B immediate option on the linker command line. The order of the
options is not important, nor is the placement of the options on the line.
For example, the following ld command uses nonfatal immediate
binding:
$ ld /opt/langtools/lib/crt0.o prog.o -B nonfatal \
-B immediate -lm -lc
Note that the -B nonfatal modifier does not work with deferred
binding because a symbol must have been bound by the time a program
actually references or calls it. A program attempting to call or access a
nonexistent symbol is a fatal error.
Restricted Shared Library Binding with -B restricted
The linker also supports restricted binding, which is useful with the
-B deferred and -B nonfatal options. The -B restricted option
causes the dynamic loader to restrict the search for symbols to those that
were visible when the library was loaded. If the dynamic loader cannot
find a symbol within the restricted set, a run-time symbol binding error
occurs and the program aborts.
The -B nonfatal modifier alters this behavior slightly: If the dynamic
loader cannot find a symbol in the restricted set, it looks in the global
symbol set (the symbols defined in all libraries) to resolve the symbol. If
it still cannot find the symbol, then a run-time symbol-binding error
occurs and the program aborts.
When is -B restricted most useful? Consider a program that creates
duplicate symbol definitions by either of these methods:
• The program uses shl_load with the BIND_FIRST flag to load a
library that contains symbol definitions that are already defined in a
library that was loaded at program startup.