What is the difference between ldd and objdump?

Deadly 提交于 2019-11-29 00:57:20

问题


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


回答1:


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.




回答2:


See Program Library HOWTO, section 3.5. Installing and Using a Shared Library:

Beware: do not run ldd on a program you don't trust. As is clearly stated in the ldd(1) manual, ldd works by (in certain cases) by setting a special environment variable (for ELF objects, LD_TRACE_LOADED_OBJECTS) and then executing the program. It may be possible for an untrusted program to force the ldd user to run arbitrary code (instead of simply showing the ldd information). So, for safety's sake, don't use ldd on programs you don't trust to execute.



来源:https://stackoverflow.com/questions/11524820/what-is-the-difference-between-ldd-and-objdump

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!