HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 14 (of 101)
Chapter 11 Software Development
October 29, 2013
object file a.o:
Linker:
executable file:
exported symbols:
- A (code)
imported symbols:
- B (code)
- C (code)
code of function A
- load objects
- link static parts
- build symbol tables
- search imported
symbols in the
libraries
exported symbols:
- A (code)
- B (code)
imported symbols:
- C (code)
shared library list:
- libXYZ.sl
code of function A
code of function B
object file b.o:
exported symbols:
- B (code)
imported symbols:
- C (code)
code of function B
shared library libXYZ.sl:
exported symbols:
- C (code)
code of function C
When linking an executable program, the object crt0.o must always be linked in first. This is
the startup object which contains code that every executable needs for its initialization (e.g.
loading dld.sl) and clean termination. If a compiler front end is used to link, it adds crt0.o
automatically to the linker command.
If a reference to a symbol cannot be resolved within the binary, it is searched for in the list of
shared libraries passed to the linker. If the symbol is still not be found, an error is reported.
Otherwise it is added to the symbol table of the binary as an imported symbol. Symbols of the
binary can also be exported, this means they can be referenced from shared libraries. Such
symbols are stored in the symbol table as exported symbols. If all imported symbols could be
resolved with the shared libraries, the binary is made executable.
In contrast to an archive library, a shared library is not just a collection of objects. Objects cannot
be extracted from a shared library. It is linked in the same way as an executable, with the
difference that symbols which could not be resolved at link time don't lead to an error. They are
stored in the symbol table as imported symbols and resolving them is left to the dynamic loader
at runtime, which has more resources to search for symbols that are not available at link time,
namely the executable and the other shared libraries linked to it.