Posts

Showing posts with the label shared-libraries

Runtime loading of dynamic libraries in Linux

Image
In Linux, libraries which are linked during linking stage of the program, gets loaded during the startup of the program, unless a copy is already present in memory. Another approach provided by Linux operating system is to load/unload the libraries at run time whenever it is needed. API's are provided by Linux for Loading the Library -- dlopen() Looking up for symbols -- dlsym() Handling Errors -- dlerror() Unloading the Library -- dlclose() Header File : #include <dlfcn.h> Note: While building the program, you need to link 'ldl' library: -ldl Flow: 1. Process begins with a call to dlopen API, providing the path of the shared library and the mode. Main two values for this mode are RTLD_NOW, RTLD_LAZY. This informs the dynamic linker when to perform relocations. RTLD_NOW will make all the necessary relocations at the dlopen call time, whereas RTLD_LAZY will perform relocations only when they're needed. dlopen function returns a handle which is...

Different Commands to find out all shared libraries used by application in Linux

Image
'ldd' Linux command is used to print all shared library dependencies. Syntax: ldd <executable_name> Some versions of ldd will execute the application in order to get dependencies information. Safer alternative is to use: objdump -p <executable_name> | grep NEEDED Another way is to use readelf. readelf -d <executable_name> | grep NEEDED Note that libraries depends on other libraries, so you need to find their dependencies.