When I link executable elf file dynamically it needs libc.so.6 shared library.
When I link executable elf file statically it doesn’t need libc.so.6 shared library (it’s not surprise).
Does it mean, that to assemble executable file with –static, linker includes libc.so.6 in it?
If not – what file does linker include? where can I search it?
As far as I know, linker includes static libraries in statically assembled file.
If you link as static, the linker will link all the needed object (
.o) files from the static libraries (.a). For example, the following command lists the object files which are included in the libc6 library:(the exact path to libc.a of course differs from system to system)
So answer to your question is no, it will not link the whole libc6 library, but only the needed object files. And also, it doesn’t do anything with
libc.so.6, since this is only for dynamic linking. It works with thelibc.a– static version of the library.According to @janneb comment, the smallest unit to be linked is “section”, so it might not even need to link the whole object files.