Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandatorily Dynamically linked libraries

I learnt from book (Expert C programming : deep C secrets" by Peter Van Der Linden ) that there are specific libraries for which dynamic linking is mandatory ; Which are these libraries ,and why they are mandatorily dynamically linked ? (more specifically on GNU/Linux system)

like image 895
Onkar Mahajan Avatar asked Mar 24 '26 11:03

Onkar Mahajan


1 Answers

Which are these libraries

All UNIX systems guarantee backward compatibility; that is, a binary built on an older system will continue to work and newer system. But this guarantee is only made for binaries which link with system libraries dynamically.

why they are mandatorily dynamically linked

The restriction is in place because user-level programs generally do not make direct system calls, but rather call libc wrapper routines. So a UNIX vendor is free to make incompatible changes to the syscall interface (e.g. to fix a bug), provided the system library is updated as well. Usually such changes only happen when upgrading to new OS release, e.g. from Solaris 2.6 to 2.7.

The picture on Linux is even more complicated than what I described above, because a single version of glibc is comprised of some 200+ separate binaries, which all must match exactly. Linking one such piece in statically, and then running on a system where other pieces do not match will produce unpredictable results; often a crash somewhere in libc.

Executive summary: never link UNIX system libraries statically into your executables, unless you know what you are doing and have a very good reason to do that.

like image 181
Employed Russian Avatar answered Mar 26 '26 01:03

Employed Russian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!