public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Writing a ldd like utility.
@ 2006-06-01 18:44 vamsi krishna
  2006-06-01 20:16 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: vamsi krishna @ 2006-06-01 18:44 UTC (permalink / raw)
  To: binutils

Hello All,

I need to write some for a program which needs the virtual address
where the shared libraries (I need to enumerate each of them ) are
mapped in the virtual adress space.

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 ?).

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?

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

Thank you for your comments.

Regards,
Vamsi.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Writing a ldd like utility.
  2006-06-01 18:44 Writing a ldd like utility vamsi krishna
@ 2006-06-01 20:16 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2006-06-01 20:16 UTC (permalink / raw)
  To: vamsi krishna; +Cc: binutils

"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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-06-01 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-01 18:44 Writing a ldd like utility vamsi krishna
2006-06-01 20:16 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).