Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ldd and objdump?

Tags:

I am running these two commands, and I'm getting different output:

$ ldd `which ls`     linux-gate.so.1 =>  (0x00db3000)     libselinux.so.1 => /lib/i386-linux-gnu/libselinux.so.1 (0x00ba2000)     librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x007bf000)     libacl.so.1 => /lib/i386-linux-gnu/libacl.so.1 (0x004ce000)     libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)     libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x00398000)     /lib/ld-linux.so.2 (0x00dea000)     libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00a83000)     libattr.so.1 => /lib/i386-linux-gnu/libattr.so.1 (0x00d3d000) 

and then

objdump -x `which ls` | grep NEEDED   NEEDED               libselinux.so.1   NEEDED               librt.so.1   NEEDED               libacl.so.1   NEEDED               libc.so.6 

What's up with that? I thought they both gave the library dependencies? The reason I care is that I suspect ldd is the correct one, but I'm working on linux on ARM, where there is no ldd from what I can tell...

like image 665
alexgolec Avatar asked Jul 17 '12 14:07

alexgolec


People also ask

What is ldd used for?

What is Ldd. Ldd is a powerful command-line tool that allows users to view an executable file's shared object dependencies. A library refers to one or more pre-compiled resources such as functions, subroutines, classes, or values. Each of these resources is combined to create libraries.

What does ldd output mean?

DESCRIPTION top. ldd prints the shared objects (shared libraries) required by each program or shared object specified on the command line. An example of its use and output is the following: $ ldd /bin/ls linux-vdso.

How do you take ldd?

Q1. How to use the ldd command? Basic usage of ldd is fairly simple - just run the 'ldd' command along with an executable or shared object file name as input. So you can see all shared library dependencies have been produced in output.

Does ldd show transitive dependencies?

According to this answer ldd shows all dynamic libraries required for a given binary to run the application. This includes the transitive dependencies you are asking for.


1 Answers

You can see the difference in the output.

objdump is simply dumping what the object itself lists as libraries containing unresolved symbols.

ldd is listing which libraries ld.so would actually load. And it follows the graph backward, so that you can see what would be loaded by those libraries. Which is how libpthread.so.0 winds up in the ldd output, despite not being in the objdump output.

So ldd is going to give a much, much better picture of what really needs to be available at runtime. But, when resolving compile/link-time problems, objdump is pretty helpful.

like image 115
Aubrey_Jones Avatar answered Sep 27 '22 19:09

Aubrey_Jones