With static compilation, only the functions of a library which are actually needed by a program are linked to the program. How is that with shared libraries ?
Shared libraries are referenced by the program symbolically, that is, the program will identify, by name, the shared library it was linked with.
Are only the functions actually needed by a program are loaded into memory by the dynamic linker, or is always the total shared library loaded ?
The program will reference specific entry points and data objects in the shared library. The shared library will be mapped into memory as a single large object, but only the pages that are actually referenced will be paged in by the kernel. The total amount of the library that gets loaded will depend on both the density of references, references by other images linked to it, and by the locality of the library's own functionality.
If it is functions, how could I get the actual size of a program including its loaded functions during runtime ?
The best way on Mac and other Unix-based systems is with ps(1).