Solved

Understanding ldd output

Posted on 2007-03-17
14
2,588 Views
Last Modified: 2011-10-03
HI,

      Can anyone explain me the output of ldd command. For example, when I run the ldd command on iptables executeable, I understand iptables is using  libdl.so.2 and  libc.so.6 shared libraries. But I am looking for a good explanation on the addresses mentioned just beside each shared objects.

Please explain what that addresses indicate....

#     ldd /sbin/iptables
        libdl.so.2 => /lib/libdl.so.2 (0x40034000)
        libc.so.6 => /lib/i686/libc.so.6 (0x40037000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)


Thanks
0
Comment
Question by:expertblr
  • 6
  • 5
14 Comments
 
LVL 14

Accepted Solution

by:
sjm_ee earned 250 total points
ID: 18739824
The addresses are those at which the shared library will be loaded in the process memory map. Compare with the output of pmap.
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 250 total points
ID: 18740422
For more information about the iptables command (including output), you can always use :

    man iptables
0
 

Author Comment

by:expertblr
ID: 18740741
Thanks.

can anyone explain me with an example on how the address relocation will happen when shared libraries are used.  I did get some links on google, but it is very difficult to understand.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 53

Expert Comment

by:Infinity08
ID: 18740829
This is a quite technical article on the subject :

http://www.securityfocus.com/infocus/1872

Have you already read that ?

It is not an easy subject, so finding an easy way to explain it is not trivial.
0
 

Author Comment

by:expertblr
ID: 18742417
I read that article....Its quite difficult to understand.  I will really appriciate if someone can explain me the concept of address relocation with a simple example.


Thanks
0
 

Author Comment

by:expertblr
ID: 18742436
Hi sjm_ee,


  You've said: The addresses are those at which the shared library will be loaded in the process    memory map.

what if those addresses are already used by some other process?


Thanks.
0
 

Author Comment

by:expertblr
ID: 18746423
any update on this?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18746730
First of all, I just noticed that I mistyped earlier ... it should have been

     man ldd

To find out more about the ldd output of course :)


>> I will really appriciate if someone can explain me the concept of address relocation with a simple example.

I assume you read the "How it works" part of the article I posted ?

The addresses listed in the ldd output are the addresses where the respective libraries can be found in memory (absolute addresses). Or in other words, they are the versions of the libraries that were found at the moment ldd was run.
The libraries are loaded at that (virtual) address by the dynamic loader ld-linux.so.2.

How does ldd work, you might add ? Well, it runs the application in a special mode. This mode only prints out the dynamic libraries used by the application, along with the version of the library it found (using LD_LIBRARY_PATH). Some versions of ldd (like yours) also print out the address in memory where that library can be found.

Does this answer your question ? If not, can you tell me what you don't understand ?
0
 

Author Comment

by:expertblr
ID: 18754477
Thanks infinity.

So that means,  the ldd command on an executable will  show the memory at which the library
is currently loaded, am I right?

so, the address relocation will happen based on the address at which the  shared library is loaded?


Thanks
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18756261
>> so, the address relocation will happen based on the address at which the  shared library is loaded?

Yes.
0
 

Author Comment

by:expertblr
ID: 18777325
Thanks you very much.

One more question:

    Suppose if the shared library is not loaded to memory and if we run ldd comand on an executable (assuming the shared libray of this executable is not in memory)  what will the ldd command  output will show?


0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18778072
The ldd command is gonna start the executable in the special mode I mentioned. The executable is gonna load the missing library in memory, and is gonna output which version it picked, and at what address in memory it placed it.
However, since that library had to be loaded in memory by the application, it's probably gonna be removed from memory again when the ldd command ends. So, the address listed has not much meaning.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question