Quote:> program.I was of the view that the linux dynamic loader ld-linux.so
> was responsible loads the shared libraries needed by a program and
> prepares the program to run.
It is indeed.
Quote:> But I read one document on the net which
> said something else.It said that when we are using runtime
> linking(that is using dl_* calls) does the loader gets called, and for
> the normal cases its the the exec family of calls that actually makes
> the required arrangements.How far is this true.
I'm not completely sure what you're driving at here. When execve() is
called, the kernel first maps the required executable to memory. It then
determines if the executable is dynamically linked. If dynamic linking is
required it maps in the dynamic loader (which can be specified to be
anything by the executable, though it is normally ld-linux.so on Linux
systems) and invokes its entry point passing information about the
executable. If dynamic linking isn't required the entrypoint of the
executable is invoked directly.
When the dynamic linker receives control it determines the needed libraries
and maps them into memory as required. In addition the dl_* routines exist
to provide a runtime link into the dynamic linker. The library in question,
libdl.so, is really just a set of stubs that call on to the real ld-linux.so
Quote:> And as far as shared libraries are
> concerned,willa single copy of (first copy) always loaded in memory.If
> not then it must be getting loaded when there is a first reference to
I'm not clear what you're referring to. If you're asking if the dynamic
linker maps them into memory when they're first referenced or straight away
the answer is the later. That is, if an executable needs libc.so, libm.so
and libtermcap.so, all of those libraries are mapped into memory before the
executable begins execution.
If you're referring to the presence of the file in physical memory, the
files are mmap()ed so only one copy of the read only areas would exist in
memory at any time, read write pages would be copied on write.
You might like to play with the LD_DEBUG environment variable, the debugging
information provided should make it much clearer how it all works.