Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a linker flag to force it to load all shared libraries at start time?

Is there a flag or any other directive that I can use to force the Linux Dynamic Linker ld.so to load all shared libraries at once at start of the program instead of lazy binding.

Essentially I want to turn off lazy binding.

Thanks

like image 861
abhi Avatar asked Apr 09 '14 06:04

abhi


People also ask

What happens dynamic linking?

With dynamic linking, external symbols referenced in user code and defined in a shared library are resolved by the loader at load time. When you compile a program that uses shared libraries, they are dynamically linked to your program by default.

How are shared libraries loaded?

Static libraries – are bound to a program statically at compile time. Dynamic or shared libraries – are loaded when a program is launched and loaded into memory and binding occurs at run time.

What is static linking and dynamic linking?

By using dynamic linking, you can upgrade the routines in the shared libraries without relinking. This form of linking is the default and no additional options are needed. Static linking means that the code for all routines called by your program becomes part of the executable file.

What is meant by dynamic linking?

Dynamic linking means that the code for some external routines is located and loaded when the program is first run. When you compile a program that uses shared libraries, the shared libraries are dynamically linked to your program by default.


2 Answers

Setting environment variable LD_BIND_NOW = 1 will do that.

Thanks to @skwllsp for the answer.

like image 80
abhi Avatar answered Oct 07 '22 22:10

abhi


man ld sayes:

-z keyword

now - When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called

http://linux.die.net/man/1/ld

like image 40
Paul E Avatar answered Oct 07 '22 21:10

Paul E