Writing a ldd like utility.

Ian Lance Taylor ian@airs.com
Thu Jun 1 20:16:00 GMT 2006


"vamsi krishna" <vamsi.krishnak@gmail.com> writes:

> o I can read the link_maps of the dynamic linker get the details of
> where the shared libraries are mapped, but I'am little skeptical about
> its portability (do all the linuxes and unixes have the same way to
> access the link_maps ?).

GNU/Linux always does, but other Unix systems do not.

> o I see the there are some .dynamic sections in the elf binary, so the
> information on where (virtual address) these dynamic shared libraries
> are mapped is put in this section?

No.  The virtual addresses are only known at run time, and therefore
can not be in the binaries.

> o Was wondering how ldd does that ? (does it fork the executable and
> get the link_maps from it?)

On GNU/Linux, ldd is a shell script.  You can see exactly what it
does.  Basically it invokes the dynamic linker with some environment
variables which cause the dynamic linker to print out information
about which shared libraries are loaded where.  Note that on a system
with address space randomization turned on
(/proc/sys/kernel/randomize_va_space != 0) the dynamic libraries will
not be loaded in the same location every time.

Ian



More information about the Binutils mailing list