Response to comment:
I tried the same stuff on NetBSD machine and there I see the mapping of ld.so as the first step. So this should essentially means that this is implementation dependent whether we will see the dynamic linker in strace or not. Right?
Wrong, at least according to the NetBSD process startup documentation:
Note that when starting a dynamic ELF executable, the ELF loader (also known as the interpreter:
/usr/libexec/ld.elf_so
) is loaded with the executable by the kernel. The ELF loader is started by the kernel and is responsible for starting the executable itself afterwards.
For a better answer, you will have to ask a separate question about this specifically, and with the strace
output included.
how does
ldd
mentions the base address of a library even without loading it?
ldd
calls the dynamic linker, which loads a dynamically-linked program's dynamic dependencies. From the ldd
man page:
In the usual case,
ldd
invokes the standard dynamic linker (seeld.so(8)
) with theLD_TRACE_LOADED_OBJECTS
environment variable set to 1. This causes the dynamic linker to inspect the program's dynamic dependencies, and find (according to the rules described inld.so(8)
) and load the objects that satisfy those dependencies. For each dependency,ldd
displays the location of the matching object and the (hexadecimal) address at which it is loaded. (Thelinux-vdso
andld-linux
shared dependencies are special; seevdso(7)
andld.so(8)
.)
In some cases ldd
will even execute the binary:
Be aware that in some circumstances (e.g., where the program specifies an ELF interpreter other than ld-linux.so), some versions of
ldd
may attempt to obtain the dependency information by attempting to directly execute the program (which may lead to the execution of whatever code is defined in the program's ELF interpreter, and perhaps to execution of the program itself). Thus, you should never employ ldd on an untrusted executable, since this may result in the execution of arbitrary code.
ldd
does indeed result in a program's dynamic dependencies being loaded into virtual memory.