Dexter
Dexter

Reputation: 1337

Dynamic library (.so) : Link time and run time

What is the main difference between using a .so file a link time or using it at run time (dlopen() etc) ?

  1. What kind of validation is performed when used at link time ?
  2. What is the role of the header file that lists the methods exposed out of .so and used in the target binary ?
  3. How does the address space looks in both the cases ?

Upvotes: 1

Views: 1591

Answers (1)

Sergey L.
Sergey L.

Reputation: 22552

  1. At link time the compiler will only check that the symbols are available in the library and will specify which library to link against later (in case you are linking against multiple libraries providing the same symbol)

  2. The header file will only tell the compiler of what function prototypes are available and (depending on the programming language used) how to translate them into symbols. e.g. C++ extern "C".

  3. If you are linking against a library then the linker will create a global address translation table in the executable which will be populated with the symbol addresses at runtime when the library is loaded. If you are opening the library with dlopen then you are responsible of creating variables holding the symbol pointers yourself via dlsym, but it allows you more flexibility like e.g. changing those during runtime, loading plugins or other functions that are unavailable at compile time.

Upvotes: 3

Related Questions