Search code examples
linux-kernellinkerldloader

how is ld-linux.so* itself linked and loaded?


enter image description here

Just by curiosity, how is the Linux dynamic linker/loader ld-linux.so* itself linked and loaded?

  1. The above screenshot shows that file and ldd seems to give contradictory result: one says statically linked, the other says dynamically linked.

  2. Then how is the loader itself be loaded?


Solution

    1. ld-linux.so* doesn't depends any other libraries. It is runable by itself when loaded to memory.

    2. ldd is a script, it loads the object file via the loader, and the loader checks whether the object is dynamically or statically linked, try this:

    LD_TRACE_LOADED_OBJECTS=1 /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

    1. file reads the magic number or elf header to figure whether the object is dynamically or statically linked, it may output different value from ldd

    IMO, ld-linux.so is static linked, because it doesn't have an .interp section which all dynamically linked object must have.