Explanation of ldd output

CyberMuz picture CyberMuz · Aug 21, 2013 · Viewed 9.1k times · Source

Can someone explain to me the output of ldd command? In the following example (on Gentoo system)

$ ldd /bin/date
  linux-vdso.so.1 =>  (0x00007fff6ffff000)
  librt.so.1 => /lib64/librt.so.1 (0x00007f54ba710000)
  libc.so.6 => /lib64/libc.so.6 (0x00007f54ba384000)
  libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f54ba167000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f54ba919000)

what does the first line mean? The "linux-vdso.so.1 => (0x00007fff6ffff000)" The => doesn't point to any shared library file.

Answer

rakib_ picture rakib_ · Aug 21, 2013

The most important part of that output is linux-vdso. VDSO stands for Virtual Dynamic Shared Object - it's an way to export kernel space routines to userspace. The main reason is to reduce the system call overhead. Typically when a system call happens it requires some expensive operations like switching mode from user to kernel, copying data from userspace to kernelspace etc. To reduce these sorts of overhead VDSO is used, just by reading that vdso memory space result could be extracted i.e it's possible to gettimeofday() without doing a real system call!

Note, not all system calls have VDSO support, only system calls like getcpu(), gettimeofday(), time() etc. which is an extremely fast way to get these thing done. Also the memory address linux-vdso.so.1 points is randomized, on different ldd invocation you'll see linux-vdso.so.1 points to different memory location. This has been done as if no one can predict the address up front.