On UNIX, I may use a commandline like:
cc -o executable *.o -zlazyload -lsomelib
with the result that the libraries listed to the right of
-zlazyload are marked with the LAZYLOAD ELF tag in the binary. This may be verified by calling
dump -Lv executable and the result contains e.g.:
**** DYNAMIC SECTION INFORMATION **** .dynamic: [INDEX] Tag Value  POSFLAG_1 LAZYLOAD  NEEDED libsecdb.so.1
In this case,
libsecdb is not loaded at the startup time of the executable, but delayed to the time, when the first function from
libsecdb is called.
This trick may be used to keep the incore representation of the executable smaller if it does not use all features.
Is there a way to achive the same on Linux? The GNU linker seems to have a flag
-zlazy, but my experience is that this is without effect.
The background for this question is that on Solaris, it is simple to link the current Bourne Shell (bosh) using lazy linking and this results in a shell that is nearly as small as
dash when executing shell scripts, but that is still faster than
dash. The shared libraries for the interactive history editor are only linked if the shell is used in interactive mode.