我如何找出哪些是由程序或其它库所使用的共享对象的功能呢? [英] How do I find out which functions of a shared object are used by a program or an other library?

查看:204
本文介绍了我如何找出哪些是由程序或其它库所使用的共享对象的功能呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何找出一个程序或其他图书馆使用的共享对象的哪些功能?
在这种特殊情况下,我想看看哪些功能/lib/libgcc1_s.so.1由一个其他动态库使用。
由于他们是动态链接,objdump的-d不能解决函数调用的地址。
有没有办法在短期调试运行程序或静态重连的?
谢谢,

How do I find out which functions of a shared object are used by a program or an other library? In this specific case, I would like to see which functions in /lib/libgcc1_s.so.1 are used by an other dynamic library. Since they are dynamically linked, objdump -d doesn't resolve the function call addresses. Is there a way short of running the program in a debugger or relinking statically? Thanks,

卢卡

编辑:

纳米和readelf不会做,我不需要看这些符号是一个共享对象present,但实际上是在链接到它的其他对象使用。

nm and readelf won't do, I don't need to see which symbols are present in a shared object, but which are actually used in an other object that links to it.

推荐答案

纳米如果库未剥去其符号只会工作。然而,纳米-D 可以告诉你一些信息:

nm will only work if the library wasn't stripped of its symbols. However, nm -D could show you some info:

nm -D /lib/libgcc_s.so.1

但还有另一种工具,它可以帮助你: readelf

readelf - 显示有关信息
  ELF文件。

readelf - Displays information about ELF files.

如果你检查手册页,选择 -s 显示在文件的符号表部分中的条目,如果有

And if you check the man pages, option -s: Displays the entries in symbol table section of the file, if it has one.

readelf -s /lib/libgcc_s.so.1

编辑:

嗯,这是不是你与纳米检查对象内部实现符号会出现一个 U 在它前面的标志,但纳米不会告诉你哪个库您的系统上实现了象征。

Well, symbols that are not implemented inside the object you are inspecting with nm will appear with a U flag in front of it, but nm won't tell you which library on your system implements that symbol.

所以,你正在寻找可能可以用 LDD 纳米的混合物来实现。 LDD告诉哪些库您的应用程序与联系,以及纳米告诉哪些符号是不确定的( U 标志),或在本地实现的( T 标志)。

So what you are looking for can probably be achieved with a mixture of ldd and nm. ldd tells which libraries your application is linked with, and nm tells which symbols are undefined (U flag) or implemented locally (T flag).

目标应用列出了所有未定义符号(与纳米)后,应该通过LDD寻找这些符号的报道的所有图书馆迭代(使用nm再次)。如果您发现该符号,它是由T标志pceded $ P $,你发现它。

After listing all the undefined symbols (with nm) on the target application, you should iterate through all libraries reported by ldd in search of those symbols (using nm again). If you find the symbol and it's preceded by the T flag, you found it.

顺便说一句,我只是写了这个单行对于bash 来说明我的想法。它分析命名的应用程序的并试图找到实现报告为未定义的所有符号库。

By the way, I just wrote this one-liner for bash to illustrate my idea. It analyses an application named win and tries to find the libraries that implement all the symbols reported as undefined.

target="win"; for symbol in $(nm -D $target | grep "U " | cut -b12-); do for library in $(ldd $target | cut -d ' ' -f3- | cut -d' ' -f1); do for lib_symbol in $(nm -D $library | grep "T " | cut -b12-); do if [ $symbol == $lib_symbol ]; then echo "Found symbol: $symbol at [$library]"; fi ; done; done; done;

或者,如果你的终端支持色彩:

Or, if your terminal supports colors:

target="win"; for symbol in $(nm -D $target | grep "U " | cut -b12-); do for library in $(ldd $target | cut -d ' ' -f3- | cut -d' ' -f1); do for lib_symbol in $(nm -D $library | grep "T " | cut -b12-); do if [ $symbol == $lib_symbol ]; then echo -e "Found symbol: \e[1;36m$symbol\033[0m at \e[1;34m$library\033[0m"; fi ; done; done; done;

我敢肯定会有人发现的性能改进。

I'm sure someone will find a performance improvement.

输出:

Found symbol: XCreateColormap at [/usr/lib/libX11.so.6]
Found symbol: XCreateWindow at [/usr/lib/libX11.so.6]
Found symbol: XIfEvent at [/usr/lib/libX11.so.6]
Found symbol: XMapWindow at [/usr/lib/libX11.so.6]
Found symbol: XOpenDisplay at [/usr/lib/libX11.so.6]
Found symbol: __libc_start_main at [/lib/tls/i686/cmov/libc.so.6]
Found symbol: __stack_chk_fail at [/lib/tls/i686/cmov/libc.so.6]
Found symbol: glClear at [/usr/lib/mesa/libGL.so.1]
Found symbol: glClearColor at [/usr/lib/mesa/libGL.so.1]
Found symbol: glFlush at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXChooseFBConfig at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXChooseVisual at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXCreateContext at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXCreateNewContext at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXCreateWindow at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXGetVisualFromFBConfig at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXMakeContextCurrent at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXMakeCurrent at [/usr/lib/mesa/libGL.so.1]
Found symbol: glXQueryVersion at [/usr/lib/mesa/libGL.so.1]

这篇关于我如何找出哪些是由程序或其它库所使用的共享对象的功能呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆